Commit 76a9f03c authored by Juanma Barranquero's avatar Juanma Barranquero

Implement offsets for absolute line numbers

* src/xdisp.c (syms_of_xdisp) <display-line-numbers-offset>:
New variable to add an offset to absolute line numbers.
(syms_of_xdisp) <display-line-numbers>: Mention it in docstring.
(maybe_produce_line_number): Use it.

* doc/emacs/display.texi (Display Custom): Document it.

* etc/NEWS (value): Announce it.

* lisp/frame.el: Add `display-line-numbers-offset' to list of
variables which should trigger redisplay of the current buffer.
parent 4b06250e
Pipeline #3533 failed with stage
in 90 minutes and 1 second
......@@ -1855,6 +1855,13 @@ the variable @code{display-line-numbers-widen} to a non-@code{nil}
value, line numbers will disregard any narrowing and will start at the
first character of the buffer.
@vindex display-line-numbers-offset
If the value of @code{display-line-numbers-offset} is non-zero, it is
added to each absolute line number, and lines are counted from the
beginning of the buffer, as if @code{display-line-numbers-widen} were
non-@code{nil}. It has no effect when set to zero, or when line
numbers are not absolute.
@vindex display-line-numbers-width-start
@vindex display-line-numbers-grow-only
@vindex display-line-numbers-width
......
......@@ -560,11 +560,15 @@ now prompts the user for the directory containing the desktop file.
+++
** display-line-numbers-mode
*** New faces 'line-number-major-tick' and 'line-number-minor-tick',
and customizable variables 'display-line-numbers-major-tick' and
'display-line-numbers-minor-tick' can be used to highlight the line
numbers of lines multiple of certain numbers.
*** New variable `display-line-numbers-offset', when non-zero, adds
an offset to absolute line numbers.
+++
** winner
*** A new variable, 'winner-boring-buffers-regexp', has been added.
......
......@@ -2726,6 +2726,7 @@ See also `toggle-frame-maximized'."
display-line-numbers-widen
display-line-numbers-major-tick
display-line-numbers-minor-tick
display-line-numbers-offset
display-fill-column-indicator
display-fill-column-indicator-column
display-fill-column-indicator-character
......
......@@ -22512,10 +22512,22 @@ maybe_produce_line_number (struct it *it)
ptrdiff_t start_from, bytepos;
ptrdiff_t this_line;
bool first_time = false;
ptrdiff_t beg_byte = display_line_numbers_widen ? BEG_BYTE : BEGV_BYTE;
ptrdiff_t z_byte = display_line_numbers_widen ? Z_BYTE : ZV_BYTE;
ptrdiff_t beg_byte;
ptrdiff_t z_byte;
bool line_numbers_wide;
void *itdata = bidi_shelve_cache ();
if (display_line_numbers_offset
&& !display_line_numbers_widen
&& !EQ (Vdisplay_line_numbers, Qvisual)
&& !EQ (Vdisplay_line_numbers, Qrelative))
line_numbers_wide = true;
else
line_numbers_wide = display_line_numbers_widen;
beg_byte = line_numbers_wide ? BEG_BYTE : BEGV_BYTE;
z_byte = line_numbers_wide ? Z_BYTE : ZV_BYTE;
if (EQ (Vdisplay_line_numbers, Qvisual))
this_line = display_count_lines_visually (it);
else
......@@ -22530,7 +22542,7 @@ maybe_produce_line_number (struct it *it)
numbers, so we cannot use its data if the user wants
line numbers that disregard narrowing, or if the
buffer's narrowing has just changed. */
&& !(display_line_numbers_widen
&& !(line_numbers_wide
&& (BEG_BYTE != BEGV_BYTE || Z_BYTE != ZV_BYTE))
&& !current_buffer->clip_changed)
{
......@@ -22620,6 +22632,8 @@ maybe_produce_line_number (struct it *it)
lnum_offset = it->pt_lnum;
else if (EQ (Vdisplay_line_numbers, Qvisual))
lnum_offset = 0;
else if (display_line_numbers_offset)
lnum_offset -= display_line_numbers_offset;
/* Under 'relative', display the absolute line number for the
current line, unless the user requests otherwise. */
......@@ -34711,12 +34725,18 @@ To add a prefix to continuation lines, use `wrap-prefix'. */);
DEFVAR_LISP ("display-line-numbers", Vdisplay_line_numbers,
doc: /* Non-nil means display line numbers.
If the value is t, display the absolute number of each line of a buffer
shown in a window. Absolute line numbers count from the beginning of
the current narrowing, or from buffer beginning. If the value is
`relative', display for each line not containing the window's point its
relative number instead, i.e. the number of the line relative to the
line showing the window's point.
the current narrowing, or from buffer beginning. The variable
`display-line-numbers-offset', if non-zero, is a signed offset added
to each absolute line number; it also forces line numbers to be counted
from the beginning of the buffer, as if `display-line-numbers-wide'
were non-nil. It has no effect when line numbers are not absolute.
If the value is `relative', display for each line not containing the
window's point its relative number instead, i.e. the number of the line
relative to the line showing the window's point.
In either case, line numbers are displayed at the beginning of each
non-continuation line that displays buffer text, i.e. after each newline
......@@ -34757,6 +34777,15 @@ either `relative' or `visual'. */);
DEFSYM (Qdisplay_line_numbers_widen, "display-line-numbers-widen");
Fmake_variable_buffer_local (Qdisplay_line_numbers_widen);
DEFVAR_INT ("display-line-numbers-offset", display_line_numbers_offset,
doc: /* A signed integer added to each absolute line number.
When this variable is non-zero, line numbers are always counted from
the beginning of the buffer even if `display-line-numbers-widen' is nil.
It has no effect when set to 0, or when line numbers are not absolute. */);
display_line_numbers_offset = 0;
DEFSYM (Qdisplay_line_numbers_offset, "display-line-numbers-offset");
Fmake_variable_buffer_local (Qdisplay_line_numbers_offset);
DEFVAR_BOOL ("display-fill-column-indicator", Vdisplay_fill_column_indicator,
doc: /* Non-nil means display the fill column indicator. */);
Vdisplay_fill_column_indicator = false;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment