emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/line-numbers 7a762fb 8/9: Support displaying zero


From: Eli Zaretskii
Subject: [Emacs-diffs] scratch/line-numbers 7a762fb 8/9: Support displaying zero as the number of the current line
Date: Fri, 30 Jun 2017 10:41:21 -0400 (EDT)

branch: scratch/line-numbers
commit 7a762fbbfc1c05be8de3d253251f5e7b32da2c73
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Support displaying zero as the number of the current line
    
    * 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          | 14 ++++++++++++--
 lisp/cus-start.el |  7 +++++++
 src/xdisp.c       | 26 +++++++++++++++++++++-----
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index e201d88..9f4c3bb 100644
--- 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.
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 599e7e5..ed17113 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -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
diff --git a/src/xdisp.c b/src/xdisp.c
index 5c6aea1..7851487 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -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;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]