Support displaying zero as the number of the current line
authorEli Zaretskii <eliz@gnu.org>
Fri, 30 Jun 2017 13:37:57 +0000 (16:37 +0300)
committerEli Zaretskii <eliz@gnu.org>
Fri, 30 Jun 2017 13:37:57 +0000 (16:37 +0300)
* src/xdisp.c (syms_of_xdisp)
<display-line-numbers-current-absolute>: New variable.
<display-line-numbers>: Doc fix.
(maybe_produce_line_number): Support nil value of
display-line-numbers-current-absolute.

* lisp/cus-start.el (standard): Add customization form for
display-line-numbers-current-absolute.

* etc/NEWS: Document recently introduced features.

etc/NEWS
lisp/cus-start.el
src/xdisp.c

index e201d88a098fda2e4dacdf57cecddd2ff102a060..9f4c3bbb3e09ff790efda127873e0c3faf98e833 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -384,8 +384,18 @@ buffer-local variable 'display-line-numbers' to activate this optional
 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.
index 599e7e57f3240807aa9ac74d4a3524e72a2202c0..ed17113c78426dc35af0b3fda4405fde8c1eede8 100644 (file)
@@ -602,6 +602,13 @@ since it could result in memory overflow and make Emacs crash."
                                            :value 2
                                            :format "%v"))
                                  "26.1")
+             (display-line-numbers-current-absolute
+                                 (choice
+                                  (const :tag "Display actual number of current line"
+                                         :value t)
+                                  (const :tag "Display zero as number of current line"
+                                         :value nil))
+                                  "26.1")
             ;; xfaces.c
             (scalable-fonts-allowed display boolean "22.1")
             ;; xfns.c
index 5c6aea19697230a38a505a8c45d80d6bf94f828c..7851487e74e69026edd5ddf402415f3217f1b176 100644 (file)
@@ -20874,7 +20874,13 @@ maybe_produce_line_number (struct it *it)
             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;
@@ -20889,11 +20895,12 @@ maybe_produce_line_number (struct it *it)
     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
@@ -32557,8 +32564,10 @@ 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.
-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);
@@ -32575,6 +32584,13 @@ Any other value is treated as nil.  */);
   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;