This page describes library modeline-posn.el, which provides extensions to the standard Emacs variable
‘mode-line-position’ for Emacs 22 and later. That variable governs the behavior of minor modes
‘size-indication-mode’, which show/hide the current line number, column number, and buffer size, respectively, in the mode line.
The following extensions are provided by library
1. Whenever the current column is greater than
‘modelinepos-column-limit’, the column-number indication in the mode-line is highlighted in face
‘font-lock-function-name-face’. This lets you know when you’ve gone past a certain number of characters in any line. You can customize user option
‘modelinepos-column-limit’, and you can bind it to different values in different modes.
2. In TransientMarkMode, when the region is active, the size indicated is that of the region, not the buffer. This portion of the mode-line is then highlighted with face
‘modelinepos-empty-region-flag’ determines whether to also indicate an empty active region.)
3. The region highlighting in the mode-line is changed to a different face when you invoke a command that behaves specially for an active region. Currently, this applies to replacement commands such as
‘query-replace’. If you use library Isearch+ then it also applies to Isearch and to replacement commands invoked from Isearch.
For #2: When the region is active, the mode line displays some information that you can customize — see option
‘modelinepos-style’. Customization choices for this include: (a) the number of chars, (b) the number of chars and number of lines, and (c) anything else you might want. Choice (b) is the default.
For (c), you provide a
‘format’ expression as separate components: the format string and the sexp arguments to be evaluated and plugged into the string. The number of sexp args depends on the format string that you use: one for each `
Choice (c) is provided so that you can choose alternative formatting styles. For example, instead of `
256 ch, 13 l’, you could show `
(256 chars, 13 lines)’. But (c) can really show information at all. It need not have anything to do with the region, but it is nevertheless shown when the region is active.
‘modelinepos-empty-region-flag’ determines whether to show the active-region indication when the active region is empty. By default it is
‘t’, meaning indicate an empty active region.
For #3: Certain standard Emacs commands restrict their scope to the region when it is active. Some of these are handled here by highlighting the region indication in the mode line specially (using face
‘modelinepos-region-acting-on’ instead of face
‘modelinepos-region’). The region-restricted commands defined in standard library `
replace.el’ are handled this way.
If you also use library Isearch+ (isearch+.el) then (for Emacs 24.3+) Isearch commands too can optionally be restricted to the active region, and they too are handled by the special mode-line highlighting. This includes `M-%’ and `C-M-%’ during Isearch, which invoke query-replacement. Not only is the Isearch region indicated in the mode line, but the query-replacement command is invoked from Isearch with that region active, so it too is limited to that scope.
Here are some screenshots to show the effect.
‘modelinepos-column-limit’ = 70, past and not past the limit
Region highlighting and limits
Region highlighting and limits during Isearch restricted to region
This is really handy. Thanks! One request for enhancement: add a customization variable to allow us to use a face other than
‘font-lock-function-name-face’. My modeline is blue and my
‘font-lock-function-name-face’ is also blue, so that particular face isn’t a good choice for me. --AmitPatel
Thanks! – AmitPatel
Sorry, but I think that if you want something like that it should be as an extension of
‘column-number-mode’. Showing point as an option makes sense regardless of whether the region is active.
Of course, as soon as point is shown someone will also want to see mark…
If you want to do this kind of thing, just take a look at the code in modeline-posn.el, in particular the redefinition of
‘mode-line-position’. The parts to tweak are those for
‘column-number-mode’ (one or both, depending on what you want). HTH – DrewAdams
Thank you for the pointers! I shall try and let you know. – priyadarshan