diff options
| author | Eli Zaretskii | 2023-02-03 16:45:56 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2023-02-03 16:45:56 +0200 |
| commit | 35e238cae8b017486dd2d2a52d0b31af6a167689 (patch) | |
| tree | 782505f3ec75fb556cf15a17a941e779a574e181 | |
| parent | c3f58a66514b2c1b0d2441c9cf37d94d64bef224 (diff) | |
| download | emacs-35e238cae8b017486dd2d2a52d0b31af6a167689.tar.gz emacs-35e238cae8b017486dd2d2a52d0b31af6a167689.zip | |
Improve documentation of 'header-line-indent-mode'
* doc/lispref/modes.texi (Header Lines): Rewrite the documentation
of 'header-line-indent-mode' and its two variables. Fix the
example.
* doc/lispref/display.texi (Pixel Specification): More accurate
description of what happens with :align-to in header-lines.
Improve indexing. (Bug#61239)
* src/buffer.c (syms_of_buffer) <header-line-format>:
* lisp/display-line-numbers.el (header-line-indent)
(header-line-indent-width, header-line-indent-mode): Doc fixes.
* etc/NEWS: Enhance the announcement of 'header-line-indent-mode'.
| -rw-r--r-- | doc/lispref/display.texi | 46 | ||||
| -rw-r--r-- | doc/lispref/modes.texi | 67 | ||||
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/display-line-numbers.el | 49 | ||||
| -rw-r--r-- | src/buffer.c | 4 |
5 files changed, 136 insertions, 38 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 5a9a9f95f7b..c5374e1481a 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -5285,9 +5285,10 @@ space taken by the line-number display. | |||
| 5285 | The @code{left}, @code{center}, and @code{right} positions can be | 5285 | The @code{left}, @code{center}, and @code{right} positions can be |
| 5286 | used with @code{:align-to} to specify a position relative to the left | 5286 | used with @code{:align-to} to specify a position relative to the left |
| 5287 | edge, center, or right edge of the text area. When the window | 5287 | edge, center, or right edge of the text area. When the window |
| 5288 | displays line numbers, the @code{left} and the @code{center} positions | 5288 | displays line numbers, and @code{:align-to} is used in display |
| 5289 | are offset to account for the screen space taken by the line-number | 5289 | properties of buffer text (as opposed to header line, see below), the |
| 5290 | display. | 5290 | @code{left} and the @code{center} positions are offset to account for |
| 5291 | the screen space taken by the line-number display. | ||
| 5291 | 5292 | ||
| 5292 | Any of the above window elements (except @code{text}) can also be | 5293 | Any of the above window elements (except @code{text}) can also be |
| 5293 | used with @code{:align-to} to specify that the position is relative to | 5294 | used with @code{:align-to} to specify that the position is relative to |
| @@ -5301,11 +5302,11 @@ the left-margin, use | |||
| 5301 | :align-to (+ left-margin (0.5 . left-margin)) | 5302 | :align-to (+ left-margin (0.5 . left-margin)) |
| 5302 | @end example | 5303 | @end example |
| 5303 | 5304 | ||
| 5304 | If no specific base offset is set for alignment, it is always relative | 5305 | If no specific base offset is set for alignment, it is always |
| 5305 | to the left edge of the text area. For example, @samp{:align-to 0} in a | 5306 | relative to the left edge of the text area. For example, |
| 5306 | header-line aligns with the first text column in the text area. When | 5307 | @samp{:align-to 0} aligns with the first text column in the text area. |
| 5307 | the window displays line numbers, the text is considered to start where | 5308 | When the window displays line numbers, the text is considered to start |
| 5308 | the space used for line-number display ends. | 5309 | where the space used for line-number display ends. |
| 5309 | 5310 | ||
| 5310 | A value of the form @code{(@var{num} . @var{expr})} stands for the | 5311 | A value of the form @code{(@var{num} . @var{expr})} stands for the |
| 5311 | product of the values of @var{num} and @var{expr}. For example, | 5312 | product of the values of @var{num} and @var{expr}. For example, |
| @@ -5317,6 +5318,35 @@ product of the values of @var{num} and @var{expr}. For example, | |||
| 5317 | expressions. The form @code{(- @var{expr} ...)} negates or subtracts | 5318 | expressions. The form @code{(- @var{expr} ...)} negates or subtracts |
| 5318 | the value of the expressions. | 5319 | the value of the expressions. |
| 5319 | 5320 | ||
| 5321 | @vindex header-line-format@r{, and } :align-to | ||
| 5322 | @cindex aligning header line, when line numbers are displayed | ||
| 5323 | @cindex header line alignment when line numbers are displayed | ||
| 5324 | Text shown in the header line that uses @code{:align-to} display | ||
| 5325 | specifications is not automatically realigned when | ||
| 5326 | @code{display-line-numbers-mode} is turned on and off, or when the | ||
| 5327 | width of line numbers on display changes. To arrange for the | ||
| 5328 | header-line text alignment to be updated, thus keeping the header-line | ||
| 5329 | text aligned with the buffer text, turn on the | ||
| 5330 | @code{header-line-indent-mode} in the buffer and use its two | ||
| 5331 | variables, @code{header-line-indent} and | ||
| 5332 | @code{header-line-indent-width}, in the display specification. | ||
| 5333 | @xref{Header Lines}. Here's a simple example: | ||
| 5334 | |||
| 5335 | @lisp | ||
| 5336 | (setq header-line-format | ||
| 5337 | (concat (propertize " " | ||
| 5338 | 'display | ||
| 5339 | '(space :align-to | ||
| 5340 | (+ header-line-indent-width 10))) | ||
| 5341 | "Column")) | ||
| 5342 | @end lisp | ||
| 5343 | |||
| 5344 | @noindent | ||
| 5345 | This will keep the text @samp{Column} on the header line aligned with | ||
| 5346 | column 10 of buffer text, regardless of whether | ||
| 5347 | @code{display-line-numbers-mode} is on or off, and also when | ||
| 5348 | line-number display changes its width. | ||
| 5349 | |||
| 5320 | @node Other Display Specs | 5350 | @node Other Display Specs |
| 5321 | @subsection Other Display Specifications | 5351 | @subsection Other Display Specifications |
| 5322 | 5352 | ||
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index fe5eb8a1b8d..750c4b47894 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi | |||
| @@ -2578,21 +2578,70 @@ header line, for windows displaying the buffer. The format of the value | |||
| 2578 | is the same as for @code{mode-line-format} (@pxref{Mode Line Data}). | 2578 | is the same as for @code{mode-line-format} (@pxref{Mode Line Data}). |
| 2579 | It is normally @code{nil}, so that ordinary buffers have no header | 2579 | It is normally @code{nil}, so that ordinary buffers have no header |
| 2580 | line. | 2580 | line. |
| 2581 | @end defvar | ||
| 2582 | |||
| 2583 | If @code{display-line-numbers-mode} is turned on in a buffer | ||
| 2584 | (@pxref{Display Custom, display-line-numbers-mode,, emacs, The GNU | ||
| 2585 | Emacs Manual}), the buffer text is indented on display by the amount | ||
| 2586 | of screen space needed to show the line numbers. By contrast, text of | ||
| 2587 | the header line is not automatically indented, because a header line | ||
| 2588 | never displays a line number, and because the text of the header line | ||
| 2589 | is not necessarily directly related to buffer text below it. If a | ||
| 2590 | Lisp program needs the header-line text to be aligned with buffer text | ||
| 2591 | (for example, if the buffer displays columnar data, like | ||
| 2592 | @code{tabulated-list-mode} does, @pxref{Tabulated List Mode}), it | ||
| 2593 | should turn on the minor mode @code{header-line-indent-mode}. | ||
| 2594 | |||
| 2595 | @deffn Command header-line-indent-mode | ||
| 2596 | This buffer-local minor mode tracks the changes of the width of the | ||
| 2597 | line-number display on screen (which may vary depending on the range | ||
| 2598 | of line numbers shown in the window), and allows Lisp programs to | ||
| 2599 | arrange that header-line text is always aligned with buffer text when | ||
| 2600 | the line-number width changes. Such Lisp programs should turn on this | ||
| 2601 | mode in the buffer, and use the variables @code{header-line-indent} | ||
| 2602 | and @code{header-line-indent-width} in the @code{header-line-format} | ||
| 2603 | to ensure it is adjusted to the text indentation at all times. | ||
| 2604 | @end deffn | ||
| 2581 | 2605 | ||
| 2582 | @findex header-line-indent-mode | 2606 | @defvar header-line-indent |
| 2583 | If @code{display-line-numbers-mode} is used, and you want the header | 2607 | This variable's value is a whitespace string whose width is kept equal |
| 2584 | line to be indented by the same amount as the buffer contents, you can | 2608 | to the current width of line-numbers on display, provided that |
| 2585 | use the @code{header-line-indent-mode} minor mode. This minor mode | 2609 | @code{header-line-indent-mode} is turned on in the buffer shown in the |
| 2586 | keeps the @code{header-line-indent} variable updated, so that you can | 2610 | window. The number of spaces is calculated under the assumption that |
| 2587 | say something like: | 2611 | the face of the header-line text uses the same font, including size, |
| 2612 | as the frame's default font; if that assumption is false, use | ||
| 2613 | @code{header-line-indent-width}, described below, instead. This | ||
| 2614 | variable is intended to be used in simple situations where the | ||
| 2615 | header-line text needs to be indented as a whole to be realigned with | ||
| 2616 | buffer text, by prepending this variable's value to the actual | ||
| 2617 | header-line text. For example, the following definition of | ||
| 2618 | @code{header-line-format}: | ||
| 2588 | 2619 | ||
| 2589 | @lisp | 2620 | @lisp |
| 2590 | (setq header-line-format | 2621 | (setq header-line-format |
| 2591 | `("" header-line-format ,my-header-line)) | 2622 | `("" header-line-indent ,my-header-line)) |
| 2592 | @end lisp | 2623 | @end lisp |
| 2593 | 2624 | ||
| 2594 | This can be useful if you're displaying columnar data, and the header | 2625 | @noindent |
| 2595 | line should align with that data in the buffer. | 2626 | where @code{my-header-line} is the format string that produces the |
| 2627 | actual text of the header line, will make sure the header-line text | ||
| 2628 | is always indented like the buffer text below it. | ||
| 2629 | @end defvar | ||
| 2630 | |||
| 2631 | @defvar header-line-indent-width | ||
| 2632 | This variable's value is kept updated to provide the current width, in | ||
| 2633 | units of the frame's canonical character width, used for displaying | ||
| 2634 | the line numbers, provided that @code{header-line-indent-mode} is | ||
| 2635 | turned on in the buffer shown in the window. It can be used for | ||
| 2636 | aligning the header-line text with the buffer text when | ||
| 2637 | @code{header-line-indent} is not flexible enough. For example, if the | ||
| 2638 | header line uses a font whose metrics is different from the default | ||
| 2639 | face's font, your Lisp program can calculate the width of line-number | ||
| 2640 | display in pixels, by multiplying the value of this variable by the | ||
| 2641 | value returned by @code{frame-char-width} (@pxref{Frame Font}), and | ||
| 2642 | then use the result to align header-line text using the | ||
| 2643 | @code{:align-to} display property spec (@pxref{Specified Space}) in | ||
| 2644 | pixels on the relevant parts of @code{header-line-frormat}. | ||
| 2596 | @end defvar | 2645 | @end defvar |
| 2597 | 2646 | ||
| 2598 | @defun window-header-line-height &optional window | 2647 | @defun window-header-line-height &optional window |
| @@ -3946,9 +3946,11 @@ This argument can be used to override values of print-related settings. | |||
| 3946 | 3946 | ||
| 3947 | +++ | 3947 | +++ |
| 3948 | ** New minor mode 'header-line-indent-mode'. | 3948 | ** New minor mode 'header-line-indent-mode'. |
| 3949 | This is meant to be used in modes that have a header line that should | 3949 | This is meant to be used by Lisp programs that show a header line |
| 3950 | be kept aligned with the buffer contents when the user switches | 3950 | which should be kept aligned with the buffer contents when the user |
| 3951 | 'display-line-numbers-mode' on or off. | 3951 | switches 'display-line-numbers-mode' on or off, and when the width of |
| 3952 | line-number display changes. See the "(elisp) Header Lines" node in | ||
| 3953 | the Emacs Lisp Reference manual for more information. | ||
| 3952 | 3954 | ||
| 3953 | +++ | 3955 | +++ |
| 3954 | ** New global minor mode 'lost-selection-mode'. | 3956 | ** New global minor mode 'lost-selection-mode'. |
diff --git a/lisp/display-line-numbers.el b/lisp/display-line-numbers.el index 37cf7ade46e..89e9cec6fcd 100644 --- a/lisp/display-line-numbers.el +++ b/lisp/display-line-numbers.el | |||
| @@ -112,19 +112,27 @@ the mode is on, set `display-line-numbers' directly." | |||
| 112 | 112 | ||
| 113 | ;;;###autoload | 113 | ;;;###autoload |
| 114 | (defvar header-line-indent "" | 114 | (defvar header-line-indent "" |
| 115 | "String to indent at the start if the header line. | 115 | "String of spaces to indent the beginning of header-line due to line numbers. |
| 116 | This is used in `header-line-indent-mode', and buffers that have | 116 | This is intended to be used in `header-line-format', and requires |
| 117 | this switched on should have a `header-line-format' that look like: | 117 | the `header-line-indent-mode' to be turned on, in order for the width |
| 118 | of this string to be kept updated when the line-number width changes | ||
| 119 | on display. An example of a `header-line-format' that uses this | ||
| 120 | variable might look like this: | ||
| 118 | 121 | ||
| 119 | (\"\" header-line-indent THE-REST...) | 122 | (\"\" header-line-indent THE-REST...) |
| 120 | 123 | ||
| 124 | where THE-REST is the format string which produces the actual text | ||
| 125 | of the header-line. | ||
| 121 | Also see `header-line-indent-width'.") | 126 | Also see `header-line-indent-width'.") |
| 122 | 127 | ||
| 123 | ;;;###autoload | 128 | ;;;###autoload |
| 124 | (defvar header-line-indent-width 0 | 129 | (defvar header-line-indent-width 0 |
| 125 | "The width of the current line numbers displayed. | 130 | "The width of the current line number display in the window. |
| 126 | This is updated when `header-line-indent-mode' is switched on. | 131 | This is measured in units of the frame's canonical columns. |
| 127 | 132 | This is updated when `header-line-indent-mode' is switched on, | |
| 133 | and is intended for use in `:align-to' display specifications | ||
| 134 | that are part of `header-line-format', when portions of header-line | ||
| 135 | text should be aligned to respective parts of buffer text. | ||
| 128 | Also see `header-line-indent'.") | 136 | Also see `header-line-indent'.") |
| 129 | 137 | ||
| 130 | (defun header-line-indent--line-number-width () | 138 | (defun header-line-indent--line-number-width () |
| @@ -155,21 +163,30 @@ Also see `header-line-indent'.") | |||
| 155 | 163 | ||
| 156 | ;;;###autoload | 164 | ;;;###autoload |
| 157 | (define-minor-mode header-line-indent-mode | 165 | (define-minor-mode header-line-indent-mode |
| 158 | "Mode to indent the header line in `display-line-numbers-mode' buffers. | 166 | "Minor mode to help with alignment of header line when line numbers are shown. |
| 159 | This means that the header line will be kept indented so that it | 167 | This minor mode should be turned on in buffers which dispay header-line |
| 160 | has blank space that's as wide as the displayed line numbers in | 168 | that needs to be aligned with buffer text when `display-line-numbers-mode' |
| 161 | the buffer. | 169 | is turned on in the buffer. |
| 162 | 170 | ||
| 163 | Buffers that have this switched on should have a | 171 | Buffers that have this switched on should have a `header-line-format' |
| 164 | `header-line-format' that look like: | 172 | that uses the `header-line-indent' or the `header-line-indent-width' |
| 173 | variables, which this mode will keep up-to-date with the current | ||
| 174 | display of line numbers. For example, a `header-line-format' that | ||
| 175 | looks like this: | ||
| 165 | 176 | ||
| 166 | (\"\" header-line-indent THE-REST...) | 177 | (\"\" header-line-indent THE-REST...) |
| 167 | 178 | ||
| 168 | The `header-line-indent-width' variable is also kept updated, and | 179 | will make sure the text produced by THE-REST (which should be |
| 169 | has the width of `header-line-format'. This can be used, for | 180 | a header-line format string) is always indented to be aligned on |
| 170 | instance, in `:align-to' specs, like: | 181 | display with the first column of buffer text. |
| 182 | |||
| 183 | The `header-line-indent-width' variable is also kept updated, | ||
| 184 | and can be used, for instance, in `:align-to' specs as part | ||
| 185 | of `header-line-format', like this: | ||
| 186 | |||
| 187 | (space :align-to (+ header-line-indent-width 10)) | ||
| 171 | 188 | ||
| 172 | (space :align-to (+ header-line-indent-width 10))" | 189 | See also `line-number-display-width'." |
| 173 | :lighter nil | 190 | :lighter nil |
| 174 | (if header-line-indent-mode | 191 | (if header-line-indent-mode |
| 175 | (progn | 192 | (progn |
diff --git a/src/buffer.c b/src/buffer.c index 88ca69b0dd8..38648519ba0 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -5081,8 +5081,8 @@ the mode line appears at the bottom. */); | |||
| 5081 | The header line appears, optionally, at the top of a window; the mode | 5081 | The header line appears, optionally, at the top of a window; the mode |
| 5082 | line appears at the bottom. | 5082 | line appears at the bottom. |
| 5083 | 5083 | ||
| 5084 | Also see `header-line-indent-mode' if `display-line-number-mode' is | 5084 | Also see `header-line-indent-mode' if `display-line-numbers-mode' is |
| 5085 | used. */); | 5085 | turned on and header-line text should be aligned with buffer text. */); |
| 5086 | 5086 | ||
| 5087 | DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format), | 5087 | DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format), |
| 5088 | Qnil, | 5088 | Qnil, |