all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
@ 2017-09-29 15:59 Robert Weiner
       [not found] ` <handler.28648.B.15067008305588.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Robert Weiner @ 2017-09-29 15:59 UTC (permalink / raw)
  To: 28648

[-- Attachment #1: Type: text/plain, Size: 4387 bytes --]

When mode-line line numbers are on by themselves, L<line-num> appears.
When mode-line column numbers are on by themselves, C<col-num> appears.
When both are on, (<line-num>,<col-num>) appears.

The latter is inconsistent and always forces the user to remember which is
the line and which is the column number.  Fixing this is simple, simply
remove the parentheses which are no longer needed and add the prefix
character to each number for:  L<line-num>,C<col-num>.  This makes the
display perfectly consistent, easier to read and does not take up any more
character space.

Based on some discussion on the emacs-devel list here:

https://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00976.html
​​

this new patch solves both the consistency problem and the need for easy
alteration of the available line and column formats.  It extracts the line
and col format strings into a new variable so they can be easily changed.
Any change to that variable is immediately reflected in the modeline.

​​
Patch to
​​
Emacs 25.3 included below.  For Emacs 26,
​I believe there is one additional​
​​
l
​​
i
​​
n
​​
e
​​ that will need updating.  It is an easy manual addition.

​​
Eli, woul
​​
d you
​consider this ​
​change
f​
or Emacs 26?  It would be nice to have the consisten
​​
cy
​ and for other users to benefit​
.
​​
​

​​
*** bindings-orig.el 2017-09-29 11:55:31.000000000 -0400
--- bindings.el 2017-09-29 11:55:31.000000000 -0400
***************
*** 350,355 ****
--- 350,363 ----
      map) "\
  Keymap to display on column and line numbers.")

+ (defvar mode-line-column-line-number-formats
+   '((line-and-column . " L%l,C%c")
+     (line            . " L%l")
+     (column          . " C%c"))
+   "Alist of (symbol . format-string) pairs for mode-line numbering
display.
+ SYMBOL may be one of: line-and-column, line or column.
+ FORMAT-STRING may contain %l for the line number and %c for the column
number.")
+
  (defvar mode-line-position
    `((-3 ,(propertize
    "%p"
***************
*** 368,392 ****
  mouse-1: Display Line and Column Mode Menu")))
      (line-number-mode
       ((column-number-mode
!        (10 ,(propertize
!      " (%l,%c)"
!      'local-map mode-line-column-line-number-mode-map
!      'mouse-face 'mode-line-highlight
!      'help-echo "Line number and Column number\n\
! mouse-1: Display Line and Column Mode Menu"))
!        (6 ,(propertize
!     " L%l"
!     'local-map mode-line-column-line-number-mode-map
!     'mouse-face 'mode-line-highlight
!     'help-echo "Line Number\n\
! mouse-1: Display Line and Column Mode Menu"))))
       ((column-number-mode
!        (5 ,(propertize
!     " C%c"
!     'local-map mode-line-column-line-number-mode-map
!     'mouse-face 'mode-line-highlight
!     'help-echo "Column number\n\
! mouse-1: Display Line and Column Mode Menu"))))))
    "Mode line construct for displaying the position in the buffer.
  Normally displays the buffer percentage and, optionally, the
  buffer size, the line number and the column number.")
--- 376,400 ----
  mouse-1: Display Line and Column Mode Menu")))
      (line-number-mode
       ((column-number-mode
!        (10 (:eval (propertize
!    (or (cdr (assq 'line-and-column mode-line-column-line-number-formats))
" ")
!    'local-map mode-line-column-line-number-mode-map
!    'mouse-face 'mode-line-highlight
!    'help-echo "Line number and Column number\n\
! mouse-1: Display Line and Column Mode Menu")))
!        (6 (:eval (propertize
!   (or (cdr (assq 'line mode-line-column-line-number-formats)) " ")
!   'local-map mode-line-column-line-number-mode-map
!   'mouse-face 'mode-line-highlight
!   'help-echo "Line Number\n\
! mouse-1: Display Line and Column Mode Menu")))))
       ((column-number-mode
!        (5 (:eval (propertize
!   (or (cdr (assq 'column mode-line-column-line-number-formats)) " ")
!   'local-map mode-line-column-line-number-mode-map
!   'mouse-face 'mode-line-highlight
!   'help-echo "Column number\n\
! mouse-1: Display Line and Column Mode Menu")))))))
    "Mode line construct for displaying the position in the buffer.
  Normally displays the buffer percentage and, optionally, the
  buffer size, the line number and the column number.")

[-- Attachment #2: Type: text/html, Size: 12744 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 17:06 ` Eli Zaretskii
@ 2017-09-29 17:45   ` Robert Weiner
  2017-09-29 18:20     ` Eli Zaretskii
  2017-09-29 17:49   ` John Wiegley
  1 sibling, 1 reply; 14+ messages in thread
From: Robert Weiner @ 2017-09-29 17:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Richard Stallman, 28648

[-- Attachment #1: Type: text/plain, Size: 2004 bytes --]

On Fri, Sep 29, 2017 at 1:06 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Robert Weiner <rsw@gnu.org>
> > Date: Thu, 28 Sep 2017 17:56:50 -0400
> >
> > When mode-line line numbers are on by themselves, L<line-num> appears.
> > When mode-line column numbers are on by themselves, C<col-num> appears.
> > When both are on, (<line-num>,<col-num>) appears.
> >
> > The latter is inconsistent and always forces the user to remember which
> is the line and which is the column
> > number. Fixing this is simple, simply remove the parentheses which are
> no longer needed and add the prefix
> > character to each number for: L<line-num>,C<col-num>. This makes the
> display perfectly consistent, easier
> > to read and does not take up any more character space.
>
> We had "Ln Cn" kind of display in Emacs 21 and before, and we changed
> that to the current display in Emacs 22.1 (the change itself is from
> Aug 2002).


​Was there any particular rationale for this?

I offered my rationale for this change above; can't we debate the merits
rather than that we changed it long ago?

  Does it really make sense to go back after 15 years?
>
> If you personally dislike the default display, you can always
> customize mode-line-format in your sessions, can't you?
>

​As I noted, this is way too hard with the current code.  My patch makes
such personal changes easy, so in the worst case, you could apply it but
leave the display format strings the same.  I already have this installed
for my use.  The issue is making Emacs do something better and easier to
understand for a broad array of users.  Maybe you could just ask people to
chime in with which format they prefer: (<num>,<num>) or L<num>,C<num> or
even (L<num>,C<num>).


> > Eli, would you change this for Emacs 26? It would be nice to have the
> consistency.
>
> Well, we used to like the current "inconsistency" better.
>

​I assume that is in jest.  If not, please explain.

Bob
​

[-- Attachment #2: Type: text/html, Size: 3727 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 17:49   ` John Wiegley
@ 2017-09-29 18:17     ` Robert Weiner
  2017-09-29 19:15       ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Robert Weiner @ 2017-09-29 18:17 UTC (permalink / raw)
  To: Eli Zaretskii, Robert Weiner; +Cc: 28648

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

On Fri, Sep 29, 2017 at 1:49 PM, John Wiegley <johnw@gnu.org> wrote:

> >>>>> "EZ" == Eli Zaretskii <eliz@gnu.org> writes:
>
> But you're right, the mode line can always be customized, so I'm not
> feeling
> too strongly about this.
>

​Customizing mode-line-format won't help as the string to be modified is
embedded in the sub-variable, mode-line-position, which is a standard
variable not a customizable option.  So doesn't that mean there is no way
for a non-programming user to change the line-col display format and have
that change persist across Emacs releases without replicating the whole
definition of mode-line-position?

Bob

[-- Attachment #2: Type: text/html, Size: 1534 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 18:16           ` Eli Zaretskii
@ 2017-09-29 18:20             ` Robert Weiner
  0 siblings, 0 replies; 14+ messages in thread
From: Robert Weiner @ 2017-09-29 18:20 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Colin Baxter, Jose Arroyo, John Wiegley, 28648

[-- Attachment #1: Type: text/plain, Size: 614 bytes --]

On Fri, Sep 29, 2017 at 2:16 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > From: "John Wiegley" <johnw@gnu.org>
> > Date: Fri, 29 Sep 2017 10:35:14 -0700
> > Cc: Colin Baxter <m43cap@yandex.com>, Jose Arroyo <
> jose.m.arroyo.se@gmail.com>,
> >       rswgnu@gmail.com, emacs-devel <emacs-devel@gnu.org>
> >
> > It think the new default should be:
> >
> >     Lnn
> >     Cnn
> >     Lnn Cnn
>
> That's what we had before Emacs 22.1.
>

​I am fine with that, though having the more modular code in the patch I
submitted would also allow users to change the format easily as desired.

Bob
​

[-- Attachment #2: Type: text/html, Size: 1727 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 17:45   ` bug#28648: " Robert Weiner
@ 2017-09-29 18:20     ` Eli Zaretskii
  2017-09-29 18:48       ` Robert Weiner
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2017-09-29 18:20 UTC (permalink / raw)
  To: rswgnu; +Cc: rms, 28648

> From: Robert Weiner <rsw@gnu.org>
> Date: Fri, 29 Sep 2017 13:45:01 -0400
> Cc: 28648@debbugs.gnu.org, Richard Stallman <rms@gnu.org>
> 
>  We had "Ln Cn" kind of display in Emacs 21 and before, and we changed
>  that to the current display in Emacs 22.1 (the change itself is from
>  Aug 2002).
> 
> ​Was there any particular rationale for this?

Yes: the "Ln Cn" display was deemed "quite annoying to look at".
Sounds familiar? ;-)

You can read the entire thread here:

  http://lists.gnu.org/archive/html/emacs-devel/2002-08/msg00451.html

(most of it is not about this particular change).

> I offered my rationale for this change above; can't we debate the merits rather than that we changed it long
> ago?

It just sounds strange to me to go back on a change, when no one AFAIR
complained about that change.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 18:20     ` Eli Zaretskii
@ 2017-09-29 18:48       ` Robert Weiner
  2017-09-29 21:55         ` Richard Stallman
  0 siblings, 1 reply; 14+ messages in thread
From: Robert Weiner @ 2017-09-29 18:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Richard Stallman, 28648

[-- Attachment #1: Type: text/plain, Size: 1229 bytes --]

On Fri, Sep 29, 2017 at 2:20 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Robert Weiner <rsw@gnu.org>
> > Date: Fri, 29 Sep 2017 13:45:01 -0400
> > Cc: 28648@debbugs.gnu.org, Richard Stallman <rms@gnu.org>
> >
> >  We had "Ln Cn" kind of display in Emacs 21 and before, and we changed
> >  that to the current display in Emacs 22.1 (the change itself is from
> >  Aug 2002).
> >
> > ​Was there any particular rationale for this?
>
> Yes: the "Ln Cn" display was deemed "quite annoying to look at".
> Sounds familiar? ;-)
>

​One person said that and there were differing opinions.  RMS agreed to the
change but it is unclear which parts he really wanted.  Richard, did you
really want the display of L and C removed when both are shown or was there
some other aspect to this change that you wanted?  The better question is
what do you think now?
​​​

> ​​
>
> ​​
> You can read the entire thread here:
> ​​
>
> ​​
>   http://lists.gnu.org/archive/html/emacs-devel/2002-08/msg00451.html


​Thanks for the pointer.  The thread does not suggest that the change was
based on any universal or even consensus opinion, thus it should be open to
debate again.

Bob

[-- Attachment #2: Type: text/html, Size: 2991 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 18:17     ` bug#28648: " Robert Weiner
@ 2017-09-29 19:15       ` Eli Zaretskii
  2017-09-29 19:23         ` Robert Weiner
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2017-09-29 19:15 UTC (permalink / raw)
  To: rswgnu; +Cc: rswgnu, 28648

> From: Robert Weiner <rsw@gnu.org>
> Date: Fri, 29 Sep 2017 14:17:54 -0400
> Cc: 28648@debbugs.gnu.org
> 
>  But you're right, the mode line can always be customized, so I'm not feeling
>  too strongly about this.
> 
> ​Customizing mode-line-format won't help as the string to be modified is embedded in the sub-variable,
> mode-line-position, which is a standard variable not a customizable option. So doesn't that mean there is no
> way for a non-programming user to change the line-col display format and have that change persist across
> Emacs releases without replicating the whole definition of mode-line-position?

If you are asking for an optional feature that would display these
indicators as we did 15 years ago, I'm okay with adding it.  (We
already have quite a few optional variations on similar themes, but
one more cannot do too much harm, I guess.)

My interpretation of what you said originally was that you want to
unconditionally revert to pre-22 behavior, which is quite a different
request.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 19:15       ` Eli Zaretskii
@ 2017-09-29 19:23         ` Robert Weiner
  2017-09-29 20:08           ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Robert Weiner @ 2017-09-29 19:23 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 28648

[-- Attachment #1: Type: text/plain, Size: 1058 bytes --]

On Fri, Sep 29, 2017 at 3:15 PM, Eli Zaretskii <eliz@gnu.org> wrote:

>
> If you are asking for an optional feature that would display these
> indicators as we did 15 years ago, I'm okay with adding it.  (We
> already have quite a few optional variations on similar themes, but
> one more cannot do too much harm, I guess.)
>

​Can you explain how that would work?  How would you modify the line and
col display format?  Do you mean applying my patch but leaving the default
format strings as they are now?
​

>
> My interpretation of what you said originally was that you want to
> unconditionally revert to pre-22 behavior, which is quite a different
> request.
>

​We have two separate issues here:

1. The default line and col display format: I was suggesting the change for
consistency sake.​  If it could be made an easy-to-trigger option on the
popup menu that controls this display, I could support that.

2. The ability to easily change the line and col display format strings: My
patch solves that issue.

Bob

[-- Attachment #2: Type: text/html, Size: 2451 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 19:23         ` Robert Weiner
@ 2017-09-29 20:08           ` Eli Zaretskii
  2017-09-29 20:15             ` Robert Weiner
  2017-09-30  3:03             ` Drew Adams
  0 siblings, 2 replies; 14+ messages in thread
From: Eli Zaretskii @ 2017-09-29 20:08 UTC (permalink / raw)
  To: rswgnu; +Cc: 28648

> From: Robert Weiner <rsw@gnu.org>
> Date: Fri, 29 Sep 2017 15:23:30 -0400
> Cc: 28648@debbugs.gnu.org
> 
>  If you are asking for an optional feature that would display these
>  indicators as we did 15 years ago, I'm okay with adding it. (We
>  already have quite a few optional variations on similar themes, but
>  one more cannot do too much harm, I guess.)
> 
> ​Can you explain how that would work? How would you modify the line and col display format?

By providing a defcustom which will arrange for mode-line-format to
have the right stuff, I suppose.

> ​We have two separate issues here:
> 
> 1. The default line and col display format: I was suggesting the change for consistency sake.​ If it could be
> made an easy-to-trigger option on the popup menu that controls this display, I could support that.
> 
> 2. The ability to easily change the line and col display format strings: My patch solves that issue.

Your patch makes the change unconditional for everyone.  I don't think
we should do that, especially since we once went in the opposite
direction.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 20:08           ` Eli Zaretskii
@ 2017-09-29 20:15             ` Robert Weiner
  2017-09-30  3:03             ` Drew Adams
  1 sibling, 0 replies; 14+ messages in thread
From: Robert Weiner @ 2017-09-29 20:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 28648

[-- Attachment #1: Type: text/plain, Size: 1561 bytes --]

On Fri, Sep 29, 2017 at 4:08 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Robert Weiner <rsw@gnu.org>
> > Date: Fri, 29 Sep 2017 15:23:30 -0400
> > Cc: 28648@debbugs.gnu.org
> >
> >  If you are asking for an optional feature that would display these
> >  indicators as we did 15 years ago, I'm okay with adding it. (We
> >  already have quite a few optional variations on similar themes, but
> >  one more cannot do too much harm, I guess.)
> >
> > ​Can you explain how that would work? How would you modify the line and
> col display format?
>
> By providing a defcustom which will arrange for mode-line-format to
> have the right stuff, I suppose.
>

​Just change the patch to use a defcustom instead of the defvar for the
line and col format strings.
​

>
> > ​We have two separate issues here:
> >
> > 1. The default line and col display format: I was suggesting the change
> for consistency sake.​ If it could be
> > made an easy-to-trigger option on the popup menu that controls this
> display, I could support that.
> >
> > 2. The ability to easily change the line and col display format strings:
> My patch solves that issue.
>
> Your patch makes the change unconditional for everyone.  I don't think
> we should do that, especially since we once went in the opposite
> direction.
>

​Ok, then just modify the one line-and-col string to be as it presently is
in Emacs (that's the only one that was modified) and users will not see a
change unless they customize the format strings.

Bob
​

[-- Attachment #2: Type: text/html, Size: 2842 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 18:48       ` Robert Weiner
@ 2017-09-29 21:55         ` Richard Stallman
  0 siblings, 0 replies; 14+ messages in thread
From: Richard Stallman @ 2017-09-29 21:55 UTC (permalink / raw)
  To: rswgnu; +Cc: 28648

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > ​One person said that and there were differing opinions.  RMS agreed to the
  > change but it is unclear which parts he really wanted.  Richard, did you
  > really want the display of L and C removed when both are shown or was there
  > some other aspect to this change that you wanted?  The better question is
  > what do you think now?

I don't have any opinion now about this question.

-- 
Dr Richard Stallman
President, Free Software Foundation (gnu.org, fsf.org)
Internet Hall-of-Famer (internethalloffame.org)
Skype: No way! See stallman.org/skype.html.






^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Make mode-line number display consistent when both line and col numbers are shown.
  2017-09-29 20:08           ` Eli Zaretskii
  2017-09-29 20:15             ` Robert Weiner
@ 2017-09-30  3:03             ` Drew Adams
  1 sibling, 0 replies; 14+ messages in thread
From: Drew Adams @ 2017-09-30  3:03 UTC (permalink / raw)
  To: Eli Zaretskii, rswgnu; +Cc: 28648

Apologies (again) for not reading the thread.

FYI, my library `modeline-posn.el' modifies the default value of
`mode-line-position' to allow for some features and customizing.

(I'm guessing that whatever changes you're making to the vanilla
value will complicate things for me a bit, but that's life.)

You _might_ want to take a look at `modeline-posn.el', to see
if it or parts of it might help.

It has, for example, option `modelinepos-style', which lets
you show info about the size of the active region in the
mode-line-position part of the mode-line.  You can choose
any of these:

 * "_ ch, _ l" (or "_ rows, _ cols", if a rectangle is selected)

 * "_ chars"

 * "_ bytes"

 * the result of a custom format string and any args it expects

(There are some other features too, such as using a different
face on the region info when the current command is acting on
the active region.  For example, a command such as `query-replace'
acts differently when the region is active - when it is, the
face changes to avert you to this fact.)

The code is here, if you're interested:
https://www.emacswiki.org/emacs/download/modeline-posn.el

A description is here:
https://www.emacswiki.org/emacs/ModeLinePosition





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Acknowledgement (Make mode-line number display consistent when both line and col numbers are shown.)
       [not found] ` <handler.28648.B.15067008305588.ack@debbugs.gnu.org>
@ 2017-10-19 20:32   ` Robert Weiner
  2020-09-15 15:09     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 14+ messages in thread
From: Robert Weiner @ 2017-10-19 20:32 UTC (permalink / raw)
  To: 28648


[-- Attachment #1.1: Type: text/plain, Size: 168 bytes --]

Attached is my full solution for this problem.  Anyone is welcome to
integrate any parts useful directly into Emacs.
For now, it works as a loadable Lisp library.

Bob

[-- Attachment #1.2: Type: text/html, Size: 561 bytes --]

[-- Attachment #2: rsw-linecol.el --]
[-- Type: application/octet-stream, Size: 8145 bytes --]

;;; rsw-linecol.el --- User-editable mode-line column and line number display formats
;;
;; Keywords:     convenience, tools
;;
;; Author:       Robert Weiner
;; E-mail:       rsw@gnu.org
;;
;; Last-mod:     11-Oct-17 at 12:52:46 by Bob Weiner
;;
;; Copyright (C) 2017  The Free Software Foundation, Inc.
;; Licensed under the GNU General Public License, version 3.
;;
;; This file is not part of Emacs.  It requires Emacs 25 or above.
;; It is derived from GNU Emacs bindings.el.

;;; Commentary:
;;
;;    1. GNU Emacs buries the formatting of mode-line line and column
;;    numbers in a way that makes it virtually impossible for a user
;;    to change this formatting.  This library fixes that with a new
;;    variable, `mode-line-column-line-number-formats', which may be
;;    modified to alter the mode-line column and line number display.
;;
;;    2. It also changes the default display when both line and column
;;    numbers are displayed to include 'L' and 'C' prefixes.
;;
;;    3. For Emacs 26 and above, it also adds the submenu "Buffer Line
;;    Numbers for All Lines" to the mode-line popup menu "Toggle Line
;;    and Column Number Display" menu, so all line and column numbering
;;    options can be controlled from the mode-line.
;;
;;    To use, simply add the following lines to your Emacs initialization
;;    file, removing any features you don't want to enable:
;;            (add-hook 'after-init-hook
;;                      (lambda ()
;;                        (require 'rsw-linecol)
;;                        (line-number-mode 1) ; Enable mode-line line number display
;;                        (column-number-mode 1) ; Enable mode-line column number display
;;                        (column-number-zero-based-mode 1) ; Number first column from 0
;;                        (size-indication-mode 1) ; Display buffer size after scroll percentage
;;
;;                        ;; Emacs 26 and above: Display line numbers at the left of every buffer line
;;                        (global-display-line-numbers-mode 1)
;;                        ))

;;; Code:

;;; ************************************************************************
;;; Requirements
;;; ************************************************************************

;; Ensure Emacs version is sufficient for usage of this library.
(if (string-lessp emacs-version "25.0")
    (error "(rsw-linecol): This requires GNU Emacs 25 or greater; you have %s" emacs-version))

;;; ************************************************************************
;;; Public variables
;;; ************************************************************************

(makunbound 'mode-line-column-line-number-formats)
(defvar mode-line-column-line-number-formats
  '((line-and-column0 . " L%l,C%c")
    (line-and-column1 . " L%l,C%C")
    (line             . " L%l")
    (column0          . " C%c")
    (column1          . " C%C"))
  "Alist of (symbol . format-string) pairs for mode-line line and column numbering display.
Symbol may be one of: line-and-column, line or column.
Format-string may contain %l for line numbers.  Use %c for zero-based
column numbers or %C for 1-based column numbers.")

(defcustom column-number-indicator-zero-based t
  "When non-nil, mode line displays column numbers zero-based.

This variable has effect only when Column Number mode is turned on,
which displays column numbers in the mode line.
If the value is non-nil, the displayed column numbers start from
zero, otherwise they start from one."
  :type 'boolean
  :group 'mode-line
  :version "26.1")

(define-minor-mode column-number-zero-based-mode
  "Toggle numbering of the first column number starting at zero when optional prefix ARG is positive or at one, otherwise.
If called from Lisp, enable the mode if ARG is omitted or nil."
  :global t
  :group 'mode-line
  :variable column-number-indicator-zero-based)

(makunbound 'mode-line-column-line-number-mode-map)
(defvar mode-line-column-line-number-mode-map
  (let ((map (make-sparse-keymap))
	(menu-map (make-sparse-keymap "Toggle Line and Column Number Display")))
    (if (boundp 'menu-bar-showhide-line-numbers-menu) ;; GNU Emacs 26 or above
	(bindings--define-key menu-map [display-line-numbers]
	  `(menu-item "Buffer Line Numbers for All Lines" ,menu-bar-showhide-line-numbers-menu)))
    (bindings--define-key menu-map [size-indication-mode]
      '(menu-item "Mode-line Size Indication" size-indication-mode
		  :help "Toggle displaying a size indication in the mode-line"
		  :button (:toggle . size-indication-mode)))
    (bindings--define-key menu-map [column-number-zero-based-mode]
      '(menu-item "Column Numbers Start at 0" column-number-zero-based-mode
		  :help "Toggle whether first column is labeled 0 or 1 in the mode-line"
		  :button (:toggle . column-number-indicator-zero-based)))
    (bindings--define-key menu-map [column-number-mode]
      '(menu-item "Mode-line Column Numbers" column-number-mode
		  :help "Toggle displaying column numbers in the mode-line"
		  :button (:toggle . column-number-mode)))
    (bindings--define-key menu-map [line-number-mode]
      '(menu-item "Mode-line Line Numbers" line-number-mode
		  :help "Toggle displaying line numbers in the mode-line"
		  :button (:toggle . line-number-mode)))
    (define-key map [mode-line down-mouse-1] menu-map)
    map) "\
Keymap to display on column and line numbers.")

(defcustom mode-line-percent-position '(-3 "%p")
  "Specification of \"percentage offset\" of window through buffer.
This option specifies both the field width and the type of offset
displayed in `mode-line-position', a component of the default
`mode-line-format'."
  :type `(radio
          (const :tag "nil:  No offset is displayed" nil)
          (const :tag "\"%o\": Proportion of \"travel\" of the window through the buffer"
                 (-3 "%o"))
          (const :tag "\"%p\": Percentage offset of top of window"
                 (-3 "%p"))
          (const :tag "\"%P\": Percentage offset of bottom of window"
                 (-3 "%P"))
          (const :tag "\"%q\": Offsets of both top and bottom of window"
                 (6 "%q")))
  :version "26.1"
  :group 'mode-line)
(put 'mode-line-percent-position 'risky-local-variable t)

(makunbound 'mode-line-position)
(defvar mode-line-position
  `((:propertize
     mode-line-percent-position
     local-map ,mode-line-column-line-number-mode-map
     mouse-face mode-line-highlight
     ;; XXX needs better description
     help-echo "Size indication mode\n\
mouse-1: Display Line and Column Mode Menu")
    (size-indication-mode
     (8 ,(propertize
	  " of %I"
	  'local-map mode-line-column-line-number-mode-map
	  'mouse-face 'mode-line-highlight
	  ;; XXX needs better description
	  'help-echo "Size indication mode\n\
mouse-1: Display Line and Column Mode Menu")))
    (line-number-mode
     ((column-number-mode
       (10 (:eval (propertize
		   (or (cdr (assq (if column-number-indicator-zero-based
				      'line-and-column0
				    'line-and-column1)
				  mode-line-column-line-number-formats)) " ")
		   'local-map mode-line-column-line-number-mode-map
		   'mouse-face 'mode-line-highlight
		   'help-echo "Line number and Column number\n\
mouse-1: Display Line and Column Mode Menu")))
       (6 (:eval (propertize
		  (or (cdr (assq 'line mode-line-column-line-number-formats)) " ")
		  'local-map mode-line-column-line-number-mode-map
		  'mouse-face 'mode-line-highlight
		  'help-echo "Line Number\n\
mouse-1: Display Line and Column Mode Menu")))))
     ((column-number-mode
       (5 (:eval (propertize
		  (or (cdr (assq (if column-number-indicator-zero-based
				     'column0
				   'column1)
				 mode-line-column-line-number-formats)) " ")
		  'local-map mode-line-column-line-number-mode-map
		  'mouse-face 'mode-line-highlight
		  'help-echo "Column number\n\
mouse-1: Display Line and Column Mode Menu")))))))
  "Mode line construct for displaying the position in the buffer.
Normally displays the buffer percentage and, optionally, the
buffer size, the line number and the column number.")
(put 'mode-line-position 'risky-local-variable t)

(provide 'rsw-linecol)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#28648: Acknowledgement (Make mode-line number display consistent when both line and col numbers are shown.)
  2017-10-19 20:32   ` bug#28648: Acknowledgement (Make mode-line number display consistent when both line and col numbers are shown.) Robert Weiner
@ 2020-09-15 15:09     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 14+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-15 15:09 UTC (permalink / raw)
  To: Robert Weiner; +Cc: rswgnu, 28648

Robert Weiner <rsw@gnu.org> writes:

> Attached is my full solution for this problem.  Anyone is welcome to integrate any
> parts useful directly into Emacs.
> For now, it works as a loadable Lisp library.
>
> Bob
> ;;; rsw-linecol.el --- User-editable mode-line column and line number display formats
> ;;
> ;; Keywords:     convenience, tools

[...]

> (defvar mode-line-column-line-number-formats
>   '((line-and-column0 . " L%l,C%c")
>     (line-and-column1 . " L%l,C%C")
>     (line             . " L%l")
>     (column0          . " C%c")
>     (column1          . " C%C"))

This was a lot of code, and I think a greater degree of customisability
than is warranted.  I've taken some of these ideas and cooked them down
into two variables: mode-line-position-line-format and
mode-line-position-column-format -- and pushed to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-09-15 15:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-29 15:59 bug#28648: Make mode-line number display consistent when both line and col numbers are shown Robert Weiner
     [not found] ` <handler.28648.B.15067008305588.ack@debbugs.gnu.org>
2017-10-19 20:32   ` bug#28648: Acknowledgement (Make mode-line number display consistent when both line and col numbers are shown.) Robert Weiner
2020-09-15 15:09     ` Lars Ingebrigtsen
  -- strict thread matches above, loose matches on Subject: below --
2017-09-28 21:56 Make mode-line number display consistent when both line and col numbers are shown Robert Weiner
2017-09-29  7:02 ` Colin Baxter
2017-09-29  8:25   ` Jose Arroyo
2017-09-29  9:22     ` Colin Baxter
2017-09-29 13:26       ` Robert Weiner
2017-09-29 17:35         ` John Wiegley
2017-09-29 18:16           ` Eli Zaretskii
2017-09-29 18:20             ` bug#28648: " Robert Weiner
2017-09-29 17:06 ` Eli Zaretskii
2017-09-29 17:45   ` bug#28648: " Robert Weiner
2017-09-29 18:20     ` Eli Zaretskii
2017-09-29 18:48       ` Robert Weiner
2017-09-29 21:55         ` Richard Stallman
2017-09-29 17:49   ` John Wiegley
2017-09-29 18:17     ` bug#28648: " Robert Weiner
2017-09-29 19:15       ` Eli Zaretskii
2017-09-29 19:23         ` Robert Weiner
2017-09-29 20:08           ` Eli Zaretskii
2017-09-29 20:15             ` Robert Weiner
2017-09-30  3:03             ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.