diff options
| author | Eli Zaretskii | 2017-10-20 12:36:12 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-10-20 12:36:12 +0300 |
| commit | fd3d8610b27e26107ba15070aba0d488152f8f4d (patch) | |
| tree | d62498e78ac088c6f992a1f0077951ea9db6ba08 /lisp | |
| parent | 831eafc8ae201881e6449e2ab5d15d594573650b (diff) | |
| download | emacs-fd3d8610b27e26107ba15070aba0d488152f8f4d.tar.gz emacs-fd3d8610b27e26107ba15070aba0d488152f8f4d.zip | |
Make :align-to account for display-line-numbers
These changes also update the various bundled packages to use
new feature, and better support customizations of the line-number
face.
* src/xdisp.c (calc_pixel_width_or_height): Improve commentary.
Make :align-to count from the end of the line-number display when
the offset or the width form reference that of the text area.
(Bug#28855)
* src/indent.c (Fline_number_display_width): Implement support for
the PIXELWISE argument being 'columns'. Update the doc string.
(syms_of_indent): New symbol 'columns'.
* lisp/ruler-mode.el (ruler-mode-window-col, ruler-mode-ruler):
Call line-number-display-width with last argument 'columns'.
* lisp/proced.el (proced-header-line): Call
line-number-display-width with 2nd arg 'columns', which also fixes
a problem when display-line-numbers is nil.
* lisp/emacs-lisp/tabulated-list.el
(tabulated-list-line-number-width): Call line-number-display-width
with 2nd arg 'columns.
(tabulated-list-entry-lnum-width): Remove unneeded defvar.
(tabulated-list-print, tabulated-list-print-entry): No need to
account for the value of tabulated-list-entry-lnum-width.
(tabulated-list--current-lnum-width): New defvar.
(tabulated-list-watch-line-number-width): New function.
(tabulated-list-mode): Bind tabulated-list--current-lnum-width
locally, and set up tabulated-list-watch-line-number-width as
pre-redisplay-functions hook.
* doc/lispref/display.texi (Size of Displayed Text): Document the
'columns' value of the PIXELWISE argument.
(Pixel Specification): Update and improve the documentation of the
supported forms.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/tabulated-list.el | 25 | ||||
| -rw-r--r-- | lisp/proced.el | 3 | ||||
| -rw-r--r-- | lisp/ruler-mode.el | 16 |
3 files changed, 32 insertions, 12 deletions
diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index d1d7c0a8042..73ddadfb805 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el | |||
| @@ -193,10 +193,10 @@ Populated by `tabulated-list-init-header'.") | |||
| 193 | ;; is displayed. | 193 | ;; is displayed. |
| 194 | (if (not display-line-numbers) | 194 | (if (not display-line-numbers) |
| 195 | 0 | 195 | 0 |
| 196 | (let ((cbuf-window (get-buffer-window (current-buffer)))) | 196 | (let ((cbuf-window (get-buffer-window (current-buffer) t))) |
| 197 | (if (window-live-p cbuf-window) | 197 | (if (window-live-p cbuf-window) |
| 198 | (with-selected-window cbuf-window | 198 | (with-selected-window cbuf-window |
| 199 | (+ (line-number-display-width) 2)) | 199 | (line-number-display-width 'columns)) |
| 200 | 4)))) | 200 | 4)))) |
| 201 | 201 | ||
| 202 | (defun tabulated-list-init-header () | 202 | (defun tabulated-list-init-header () |
| @@ -329,8 +329,6 @@ Check the current row, the previous one and the next row." | |||
| 329 | (string-width (if (stringp nt) nt (car nt))))) | 329 | (string-width (if (stringp nt) nt (car nt))))) |
| 330 | tabulated-list--near-rows))) | 330 | tabulated-list--near-rows))) |
| 331 | 331 | ||
| 332 | (defvar tabulated-list-entry-lnum-width nil) | ||
| 333 | |||
| 334 | (defun tabulated-list-print (&optional remember-pos update) | 332 | (defun tabulated-list-print (&optional remember-pos update) |
| 335 | "Populate the current Tabulated List mode buffer. | 333 | "Populate the current Tabulated List mode buffer. |
| 336 | This sorts the `tabulated-list-entries' list if sorting is | 334 | This sorts the `tabulated-list-entries' list if sorting is |
| @@ -373,7 +371,6 @@ changing `tabulated-list-sort-key'." | |||
| 373 | (unless tabulated-list-use-header-line | 371 | (unless tabulated-list-use-header-line |
| 374 | (tabulated-list-print-fake-header))) | 372 | (tabulated-list-print-fake-header))) |
| 375 | ;; Finally, print the resulting list. | 373 | ;; Finally, print the resulting list. |
| 376 | (setq tabulated-list-entry-lnum-width (tabulated-list-line-number-width)) | ||
| 377 | (while entries | 374 | (while entries |
| 378 | (let* ((elt (car entries)) | 375 | (let* ((elt (car entries)) |
| 379 | (tabulated-list--near-rows | 376 | (tabulated-list--near-rows |
| @@ -428,9 +425,8 @@ of column descriptors." | |||
| 428 | (x (max tabulated-list-padding 0)) | 425 | (x (max tabulated-list-padding 0)) |
| 429 | (ncols (length tabulated-list-format)) | 426 | (ncols (length tabulated-list-format)) |
| 430 | (inhibit-read-only t)) | 427 | (inhibit-read-only t)) |
| 431 | (setq x (+ x tabulated-list-entry-lnum-width)) | ||
| 432 | (if (> tabulated-list-padding 0) | 428 | (if (> tabulated-list-padding 0) |
| 433 | (insert (make-string (- x tabulated-list-entry-lnum-width) ?\s))) | 429 | (insert (make-string x ?\s))) |
| 434 | (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). | 430 | (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). |
| 435 | (or (bound-and-true-p tabulated-list--near-rows) | 431 | (or (bound-and-true-p tabulated-list--near-rows) |
| 436 | (list (or (tabulated-list-get-entry (point-at-bol 0)) | 432 | (list (or (tabulated-list-get-entry (point-at-bol 0)) |
| @@ -601,6 +597,14 @@ With a numeric prefix argument N, sort the Nth column." | |||
| 601 | (tabulated-list-init-header) | 597 | (tabulated-list-init-header) |
| 602 | (tabulated-list-print t))) | 598 | (tabulated-list-print t))) |
| 603 | 599 | ||
| 600 | (defvar tabulated-list--current-lnum-width nil) | ||
| 601 | (defun tabulated-list-watch-line-number-width (_window) | ||
| 602 | (if display-line-numbers | ||
| 603 | (let ((lnum-width (tabulated-list-line-number-width))) | ||
| 604 | (when (not (= tabulated-list--current-lnum-width lnum-width)) | ||
| 605 | (setq-local tabulated-list--current-lnum-width lnum-width) | ||
| 606 | (tabulated-list-revert))))) | ||
| 607 | |||
| 604 | ;;; The mode definition: | 608 | ;;; The mode definition: |
| 605 | 609 | ||
| 606 | (define-derived-mode tabulated-list-mode special-mode "Tabulated" | 610 | (define-derived-mode tabulated-list-mode special-mode "Tabulated" |
| @@ -645,7 +649,12 @@ as the ewoc pretty-printer." | |||
| 645 | ;; column of the first entry happens to begin with a R2L letter. | 649 | ;; column of the first entry happens to begin with a R2L letter. |
| 646 | (setq bidi-paragraph-direction 'left-to-right) | 650 | (setq bidi-paragraph-direction 'left-to-right) |
| 647 | ;; This is for if/when they turn on display-line-numbers | 651 | ;; This is for if/when they turn on display-line-numbers |
| 648 | (add-hook 'display-line-numbers-mode-hook #'tabulated-list-revert nil t)) | 652 | (add-hook 'display-line-numbers-mode-hook #'tabulated-list-revert nil t) |
| 653 | ;; This is for if/when they customize the line-number face or when | ||
| 654 | ;; the line-number width needs to change due to scrolling. | ||
| 655 | (setq-local tabulated-list--current-lnum-width 0) | ||
| 656 | (add-hook 'pre-redisplay-functions | ||
| 657 | #'tabulated-list-watch-line-number-width nil t)) | ||
| 649 | 658 | ||
| 650 | (put 'tabulated-list-mode 'mode-class 'special) | 659 | (put 'tabulated-list-mode 'mode-class 'special) |
| 651 | 660 | ||
diff --git a/lisp/proced.el b/lisp/proced.el index c9e851b7e05..aec54b59211 100644 --- a/lisp/proced.el +++ b/lisp/proced.el | |||
| @@ -604,7 +604,8 @@ Important: the match ends just after the marker.") | |||
| 604 | "Return header line for Proced buffer." | 604 | "Return header line for Proced buffer." |
| 605 | (list (propertize " " | 605 | (list (propertize " " |
| 606 | 'display | 606 | 'display |
| 607 | (list 'space :align-to (+ 2 (line-number-display-width)))) | 607 | (list 'space :align-to |
| 608 | (line-number-display-width 'columns))) | ||
| 608 | (if (<= (window-hscroll) (length proced-header-line)) | 609 | (if (<= (window-hscroll) (length proced-header-line)) |
| 609 | (replace-regexp-in-string ;; preserve text properties | 610 | (replace-regexp-in-string ;; preserve text properties |
| 610 | "\\(%\\)" "\\1\\1" | 611 | "\\(%\\)" "\\1\\1" |
diff --git a/lisp/ruler-mode.el b/lisp/ruler-mode.el index 7a23f4d03c0..3d27858d0fe 100644 --- a/lisp/ruler-mode.el +++ b/lisp/ruler-mode.el | |||
| @@ -307,7 +307,12 @@ or remove a tab stop. \\[ruler-mode-toggle-show-tab-stops] or | |||
| 307 | N is a column number relative to selected frame. | 307 | N is a column number relative to selected frame. |
| 308 | If required, account for screen estate taken by `display-line-numbers'." | 308 | If required, account for screen estate taken by `display-line-numbers'." |
| 309 | (if display-line-numbers | 309 | (if display-line-numbers |
| 310 | (setq n (- n (line-number-display-width) 2))) | 310 | ;; FIXME: ruler-mode relies on N being an integer, so if the |
| 311 | ;; 'line-number' face is customized to use a font that is larger | ||
| 312 | ;; or smaller than that of the default face, the alignment might | ||
| 313 | ;; be off by up to half a column, unless the font width is an | ||
| 314 | ;; integral multiple or divisor of the default face's font. | ||
| 315 | (setq n (- n (round (line-number-display-width 'columns))))) | ||
| 311 | (- n | 316 | (- n |
| 312 | (or (car (window-margins)) 0) | 317 | (or (car (window-margins)) 0) |
| 313 | (fringe-columns 'left) | 318 | (fringe-columns 'left) |
| @@ -668,7 +673,12 @@ Optional argument PROPS specifies other text properties to apply." | |||
| 668 | (let* ((w (ruler-mode-text-scaled-window-width)) | 673 | (let* ((w (ruler-mode-text-scaled-window-width)) |
| 669 | (m (window-margins)) | 674 | (m (window-margins)) |
| 670 | (f (window-fringes)) | 675 | (f (window-fringes)) |
| 671 | (i (if display-line-numbers (+ (line-number-display-width) 2) 0)) | 676 | (i (if display-line-numbers |
| 677 | ;; FIXME: ruler-mode relies on I being an integer, so | ||
| 678 | ;; the column numbers might be slightly off if the | ||
| 679 | ;; line-number face is customized. | ||
| 680 | (round (line-number-display-width 'columns)) | ||
| 681 | 0)) | ||
| 672 | (j (ruler-mode-text-scaled-window-hscroll)) | 682 | (j (ruler-mode-text-scaled-window-hscroll)) |
| 673 | ;; Setup the scrollbar, fringes, and margins areas. | 683 | ;; Setup the scrollbar, fringes, and margins areas. |
| 674 | (lf (ruler-mode-space | 684 | (lf (ruler-mode-space |
| @@ -708,7 +718,7 @@ Optional argument PROPS specifies other text properties to apply." | |||
| 708 | ;; line-number display be blank, not filled with | 718 | ;; line-number display be blank, not filled with |
| 709 | ;; ruler-mode-basic-graduation-char. | 719 | ;; ruler-mode-basic-graduation-char. |
| 710 | (if display-line-numbers | 720 | (if display-line-numbers |
| 711 | (let* ((lndw (+ (line-number-display-width) 2)) | 721 | (let* ((lndw (round (line-number-display-width 'columns))) |
| 712 | (s (make-string lndw ?\s))) | 722 | (s (make-string lndw ?\s))) |
| 713 | (concat s (make-string (- w lndw) | 723 | (concat s (make-string (- w lndw) |
| 714 | ruler-mode-basic-graduation-char))) | 724 | ruler-mode-basic-graduation-char))) |