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
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)
{
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. */
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
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;