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; 3+ 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] 3+ 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; 3+ 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] 3+ 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; 3+ 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] 3+ messages in thread

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

Thread overview: 3+ 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

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.