bug#28648: Make mode-line number display consistent when both line and col numbers are shown.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#28648: Make mode-line number display consistent when both line and col numbers are shown.

Bob Weiner
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:
  
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.")

Reply | Threaded
Open this post in threaded view
|

bug#28648: Acknowledgement (Make mode-line number display consistent when both line and col numbers are shown.)

Bob Weiner
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 (10K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

bug#28648: Acknowledgement (Make mode-line number display consistent when both line and col numbers are shown.)

Lars Ingebrigtsen
Robert Weiner <[hidden email]> 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