display. If set to t, Emacs will display the number of each line
before the line. If set to 'relative', Emacs will display the line
number relative to the line showing point, with that line's number
-displayed as absolute. The default is nil, which doesn't display the
-line numbers.
+displayed as absolute. If set to 'visual', Emacs will display a
+relative number for every screen line, i.e. it will count screen lines
+rather than buffer lines. The default is nil, which doesn't display
+the line numbers.
+
+In 'relative' and 'visual' modes, the variable
+'display-line-numbers-current-absolute' controls what number is
+displayed for the line showing point. By default, this variable's
+value is t, which means display the absolute line number for the line
+showing point. Customizing this variable to a nil value will cause
+Emacs to show zero instead, which preserves horizontal space of the
+window in large buffers.
Line numbers are not displayed at all in minibuffer windows and in
tooltips, as they are not useful there.
matrix. */
ptrdiff_t max_lnum;
- if (EQ (Vdisplay_line_numbers, Qvisual))
+ if (NILP (Vdisplay_line_numbers_current_absolute)
+ && (EQ (Vdisplay_line_numbers, Qrelative)
+ || EQ (Vdisplay_line_numbers, Qvisual)))
+ /* We subtract one more because the current line is always
+ zero in this mode. */
+ max_lnum = it->w->desired_matrix->nrows - 2;
+ else if (EQ (Vdisplay_line_numbers, Qvisual))
max_lnum = it->pt_lnum + it->w->desired_matrix->nrows - 1;
else
max_lnum = this_line + it->w->desired_matrix->nrows - 1 - it->vpos;
lnum_offset = 0;
/* Under 'relative', display the absolute line number for the
- current line, as displaying zero gives zero useful information. */
+ current line, unless the user requests otherwise. */
ptrdiff_t lnum_to_display = eabs (this_line - lnum_offset);
if ((EQ (Vdisplay_line_numbers, Qrelative)
|| EQ (Vdisplay_line_numbers, Qvisual))
- && lnum_to_display == 0)
+ && lnum_to_display == 0
+ && !NILP (Vdisplay_line_numbers_current_absolute))
lnum_to_display = it->pt_lnum + 1;
/* In L2R rows we need to append the blank separator, in R2L
rows we need to prepend it. But this function is usually
DEFVAR_LISP ("display-line-numbers", Vdisplay_line_numbers,
doc: /* Non-nil means display line numbers.
-Line numbers are displayed before each non-continuation line, i.e.
-after each newline that comes from buffer text. */);
+By default, line numbers are displayed before each non-continuation
+line that displays buffer text, i.e. after each newline that came
+from buffer text. However, if the value is `visual', every screen
+line will have a number. */);
Vdisplay_line_numbers = Qnil;
DEFSYM (Qdisplay_line_numbers, "display-line-numbers");
Fmake_variable_buffer_local (Qdisplay_line_numbers);
DEFSYM (Qdisplay_line_number_width, "display-line-number-width");
Fmake_variable_buffer_local (Qdisplay_line_number_width);
+ DEFVAR_LISP ("display-line-numbers-current-absolute",
+ Vdisplay_line_numbers_current_absolute,
+ doc: /* Non-nil means display absolute number of current line.
+This variable has effect only when `display-line-numbers' is
+either `relative' or `visual'. */);
+ Vdisplay_line_numbers_current_absolute = Qt;
+
DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay,
doc: /* Non-nil means don't eval Lisp during redisplay. */);
inhibit_eval_during_redisplay = false;