5

I'm used to have display of the number of selected characters in the mode line when there is an active selection (in vim).

Is it possible to achieve this in emacs?

I managed to display the column index besides the line index, which is something... But not quite enough. I also looked at the mode line format documentation, but without success.

I also found smart mode line but I think that it doesn't offer the feature as of now.

  • 1
    "Is it possible to achieve [feature] in emacs?" Yes. Here's some elisp to start you off: (abs (- (point) (mark))) Also take a look at M-x describe-variable RET mode-line-format RET. – nanny Nov 18 '14 at 21:57
  • thanks for the hint! Yes I can see I can modify the modeline with setq-default mode-line-format however the abs is just not appearing. I tried adding (:eval and then it shows *invalid* – Emmanuel Touzery Nov 18 '14 at 22:10
8

Use library Mode-Line Position (modeline-posn.el).

It shows you the size of the selection (active region) in the mode line, using the region face. It optionally tells you also the number of selected characters or characters and lines, etc.

  • That's it thanks! Does require me to turn on size-indication-mode (which might be a good thing, must get used to it). Will try this first, will probably stick to it. – Emmanuel Touzery Nov 18 '14 at 22:24
1

The following code could be a good start for you.

(setq mode-line-format '("%e" (:eval (number-to-string (abs (- (point) (mark)))))))

This sets the mode line to display the number of selected characters. It only updates after some events, e.g. C-l.

To finish this off you'd just want to add the specified form to an existing mode-line-format variable.

  • ahh so it's the number-to-string that I was missing when I got "invalid".. good to know! I'll try the ready-made script for now.. Thank you! – Emmanuel Touzery Nov 18 '14 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.