aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2023-02-03 16:45:56 +0200
committerEli Zaretskii2023-02-03 16:45:56 +0200
commit35e238cae8b017486dd2d2a52d0b31af6a167689 (patch)
tree782505f3ec75fb556cf15a17a941e779a574e181
parentc3f58a66514b2c1b0d2441c9cf37d94d64bef224 (diff)
downloademacs-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.texi46
-rw-r--r--doc/lispref/modes.texi67
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/display-line-numbers.el49
-rw-r--r--src/buffer.c4
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
5286used with @code{:align-to} to specify a position relative to the left 5286used with @code{:align-to} to specify a position relative to the left
5287edge, center, or right edge of the text area. When the window 5287edge, center, or right edge of the text area. When the window
5288displays line numbers, the @code{left} and the @code{center} positions 5288displays line numbers, and @code{:align-to} is used in display
5289are offset to account for the screen space taken by the line-number 5289properties of buffer text (as opposed to header line, see below), the
5290display. 5290@code{left} and the @code{center} positions are offset to account for
5291the 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
5293used with @code{:align-to} to specify that the position is relative to 5294used 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
5305to the left edge of the text area. For example, @samp{:align-to 0} in a 5306relative to the left edge of the text area. For example,
5306header-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.
5307the window displays line numbers, the text is considered to start where 5308When the window displays line numbers, the text is considered to start
5308the space used for line-number display ends. 5309where 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
5311product of the values of @var{num} and @var{expr}. For example, 5312product 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,
5317expressions. The form @code{(- @var{expr} ...)} negates or subtracts 5318expressions. The form @code{(- @var{expr} ...)} negates or subtracts
5318the value of the expressions. 5319the 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
5325specifications is not automatically realigned when
5326@code{display-line-numbers-mode} is turned on and off, or when the
5327width of line numbers on display changes. To arrange for the
5328header-line text alignment to be updated, thus keeping the header-line
5329text aligned with the buffer text, turn on the
5330@code{header-line-indent-mode} in the buffer and use its two
5331variables, @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
5345This will keep the text @samp{Column} on the header line aligned with
5346column 10 of buffer text, regardless of whether
5347@code{display-line-numbers-mode} is on or off, and also when
5348line-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
2578is the same as for @code{mode-line-format} (@pxref{Mode Line Data}). 2578is the same as for @code{mode-line-format} (@pxref{Mode Line Data}).
2579It is normally @code{nil}, so that ordinary buffers have no header 2579It is normally @code{nil}, so that ordinary buffers have no header
2580line. 2580line.
2581@end defvar
2582
2583If @code{display-line-numbers-mode} is turned on in a buffer
2584(@pxref{Display Custom, display-line-numbers-mode,, emacs, The GNU
2585Emacs Manual}), the buffer text is indented on display by the amount
2586of screen space needed to show the line numbers. By contrast, text of
2587the header line is not automatically indented, because a header line
2588never displays a line number, and because the text of the header line
2589is not necessarily directly related to buffer text below it. If a
2590Lisp 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
2593should turn on the minor mode @code{header-line-indent-mode}.
2594
2595@deffn Command header-line-indent-mode
2596This buffer-local minor mode tracks the changes of the width of the
2597line-number display on screen (which may vary depending on the range
2598of line numbers shown in the window), and allows Lisp programs to
2599arrange that header-line text is always aligned with buffer text when
2600the line-number width changes. Such Lisp programs should turn on this
2601mode in the buffer, and use the variables @code{header-line-indent}
2602and @code{header-line-indent-width} in the @code{header-line-format}
2603to 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
2583If @code{display-line-numbers-mode} is used, and you want the header 2607This variable's value is a whitespace string whose width is kept equal
2584line to be indented by the same amount as the buffer contents, you can 2608to the current width of line-numbers on display, provided that
2585use 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
2586keeps the @code{header-line-indent} variable updated, so that you can 2610window. The number of spaces is calculated under the assumption that
2587say something like: 2611the face of the header-line text uses the same font, including size,
2612as the frame's default font; if that assumption is false, use
2613@code{header-line-indent-width}, described below, instead. This
2614variable is intended to be used in simple situations where the
2615header-line text needs to be indented as a whole to be realigned with
2616buffer text, by prepending this variable's value to the actual
2617header-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
2594This can be useful if you're displaying columnar data, and the header 2625@noindent
2595line should align with that data in the buffer. 2626where @code{my-header-line} is the format string that produces the
2627actual text of the header line, will make sure the header-line text
2628is always indented like the buffer text below it.
2629@end defvar
2630
2631@defvar header-line-indent-width
2632This variable's value is kept updated to provide the current width, in
2633units of the frame's canonical character width, used for displaying
2634the line numbers, provided that @code{header-line-indent-mode} is
2635turned on in the buffer shown in the window. It can be used for
2636aligning the header-line text with the buffer text when
2637@code{header-line-indent} is not flexible enough. For example, if the
2638header line uses a font whose metrics is different from the default
2639face's font, your Lisp program can calculate the width of line-number
2640display in pixels, by multiplying the value of this variable by the
2641value returned by @code{frame-char-width} (@pxref{Frame Font}), and
2642then use the result to align header-line text using the
2643@code{:align-to} display property spec (@pxref{Specified Space}) in
2644pixels 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
diff --git a/etc/NEWS b/etc/NEWS
index e3cbeb84d30..2d15e39036a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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'.
3949This is meant to be used in modes that have a header line that should 3949This is meant to be used by Lisp programs that show a header line
3950be kept aligned with the buffer contents when the user switches 3950which should be kept aligned with the buffer contents when the user
3951'display-line-numbers-mode' on or off. 3951switches 'display-line-numbers-mode' on or off, and when the width of
3952line-number display changes. See the "(elisp) Header Lines" node in
3953the 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.
116This is used in `header-line-indent-mode', and buffers that have 116This is intended to be used in `header-line-format', and requires
117this switched on should have a `header-line-format' that look like: 117the `header-line-indent-mode' to be turned on, in order for the width
118of this string to be kept updated when the line-number width changes
119on display. An example of a `header-line-format' that uses this
120variable might look like this:
118 121
119 (\"\" header-line-indent THE-REST...) 122 (\"\" header-line-indent THE-REST...)
120 123
124where THE-REST is the format string which produces the actual text
125of the header-line.
121Also see `header-line-indent-width'.") 126Also 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.
126This is updated when `header-line-indent-mode' is switched on. 131This is measured in units of the frame's canonical columns.
127 132This is updated when `header-line-indent-mode' is switched on,
133and is intended for use in `:align-to' display specifications
134that are part of `header-line-format', when portions of header-line
135text should be aligned to respective parts of buffer text.
128Also see `header-line-indent'.") 136Also 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.
159This means that the header line will be kept indented so that it 167This minor mode should be turned on in buffers which dispay header-line
160has blank space that's as wide as the displayed line numbers in 168that needs to be aligned with buffer text when `display-line-numbers-mode'
161the buffer. 169is turned on in the buffer.
162 170
163Buffers that have this switched on should have a 171Buffers that have this switched on should have a `header-line-format'
164`header-line-format' that look like: 172that uses the `header-line-indent' or the `header-line-indent-width'
173variables, which this mode will keep up-to-date with the current
174display of line numbers. For example, a `header-line-format' that
175looks like this:
165 176
166 (\"\" header-line-indent THE-REST...) 177 (\"\" header-line-indent THE-REST...)
167 178
168The `header-line-indent-width' variable is also kept updated, and 179will make sure the text produced by THE-REST (which should be
169has the width of `header-line-format'. This can be used, for 180a header-line format string) is always indented to be aligned on
170instance, in `:align-to' specs, like: 181display with the first column of buffer text.
182
183The `header-line-indent-width' variable is also kept updated,
184and can be used, for instance, in `:align-to' specs as part
185of `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))" 189See 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. */);
5081The header line appears, optionally, at the top of a window; the mode 5081The header line appears, optionally, at the top of a window; the mode
5082line appears at the bottom. 5082line appears at the bottom.
5083 5083
5084Also see `header-line-indent-mode' if `display-line-number-mode' is 5084Also see `header-line-indent-mode' if `display-line-numbers-mode' is
5085used. */); 5085turned 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,