aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2017-06-30 16:37:57 +0300
committerEli Zaretskii2017-06-30 16:37:57 +0300
commit7a762fbbfc1c05be8de3d253251f5e7b32da2c73 (patch)
tree6025b799826bec0371bd0a38d1bb4f536b773e4a
parent0e4f2e01af1f4c51b958057d86e28c04cdefddb4 (diff)
downloademacs-7a762fbbfc1c05be8de3d253251f5e7b32da2c73.tar.gz
emacs-7a762fbbfc1c05be8de3d253251f5e7b32da2c73.zip
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.
-rw-r--r--etc/NEWS14
-rw-r--r--lisp/cus-start.el7
-rw-r--r--src/xdisp.c26
3 files changed, 40 insertions, 7 deletions
diff --git a/etc/NEWS b/etc/NEWS
index e201d88a098..9f4c3bbb3e0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -384,8 +384,18 @@ buffer-local variable 'display-line-numbers' to activate this optional
384display. If set to t, Emacs will display the number of each line 384display. If set to t, Emacs will display the number of each line
385before the line. If set to 'relative', Emacs will display the line 385before the line. If set to 'relative', Emacs will display the line
386number relative to the line showing point, with that line's number 386number relative to the line showing point, with that line's number
387displayed as absolute. The default is nil, which doesn't display the 387displayed as absolute. If set to 'visual', Emacs will display a
388line numbers. 388relative number for every screen line, i.e. it will count screen lines
389rather than buffer lines. The default is nil, which doesn't display
390the line numbers.
391
392In 'relative' and 'visual' modes, the variable
393'display-line-numbers-current-absolute' controls what number is
394displayed for the line showing point. By default, this variable's
395value is t, which means display the absolute line number for the line
396showing point. Customizing this variable to a nil value will cause
397Emacs to show zero instead, which preserves horizontal space of the
398window in large buffers.
389 399
390Line numbers are not displayed at all in minibuffer windows and in 400Line numbers are not displayed at all in minibuffer windows and in
391tooltips, as they are not useful there. 401tooltips, as they are not useful there.
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 599e7e57f32..ed17113c784 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."
602 :value 2 602 :value 2
603 :format "%v")) 603 :format "%v"))
604 "26.1") 604 "26.1")
605 (display-line-numbers-current-absolute
606 (choice
607 (const :tag "Display actual number of current line"
608 :value t)
609 (const :tag "Display zero as number of current line"
610 :value nil))
611 "26.1")
605 ;; xfaces.c 612 ;; xfaces.c
606 (scalable-fonts-allowed display boolean "22.1") 613 (scalable-fonts-allowed display boolean "22.1")
607 ;; xfns.c 614 ;; xfns.c
diff --git a/src/xdisp.c b/src/xdisp.c
index 5c6aea19697..7851487e74e 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -20874,7 +20874,13 @@ maybe_produce_line_number (struct it *it)
20874 matrix. */ 20874 matrix. */
20875 ptrdiff_t max_lnum; 20875 ptrdiff_t max_lnum;
20876 20876
20877 if (EQ (Vdisplay_line_numbers, Qvisual)) 20877 if (NILP (Vdisplay_line_numbers_current_absolute)
20878 && (EQ (Vdisplay_line_numbers, Qrelative)
20879 || EQ (Vdisplay_line_numbers, Qvisual)))
20880 /* We subtract one more because the current line is always
20881 zero in this mode. */
20882 max_lnum = it->w->desired_matrix->nrows - 2;
20883 else if (EQ (Vdisplay_line_numbers, Qvisual))
20878 max_lnum = it->pt_lnum + it->w->desired_matrix->nrows - 1; 20884 max_lnum = it->pt_lnum + it->w->desired_matrix->nrows - 1;
20879 else 20885 else
20880 max_lnum = this_line + it->w->desired_matrix->nrows - 1 - it->vpos; 20886 max_lnum = this_line + it->w->desired_matrix->nrows - 1 - it->vpos;
@@ -20889,11 +20895,12 @@ maybe_produce_line_number (struct it *it)
20889 lnum_offset = 0; 20895 lnum_offset = 0;
20890 20896
20891 /* Under 'relative', display the absolute line number for the 20897 /* Under 'relative', display the absolute line number for the
20892 current line, as displaying zero gives zero useful information. */ 20898 current line, unless the user requests otherwise. */
20893 ptrdiff_t lnum_to_display = eabs (this_line - lnum_offset); 20899 ptrdiff_t lnum_to_display = eabs (this_line - lnum_offset);
20894 if ((EQ (Vdisplay_line_numbers, Qrelative) 20900 if ((EQ (Vdisplay_line_numbers, Qrelative)
20895 || EQ (Vdisplay_line_numbers, Qvisual)) 20901 || EQ (Vdisplay_line_numbers, Qvisual))
20896 && lnum_to_display == 0) 20902 && lnum_to_display == 0
20903 && !NILP (Vdisplay_line_numbers_current_absolute))
20897 lnum_to_display = it->pt_lnum + 1; 20904 lnum_to_display = it->pt_lnum + 1;
20898 /* In L2R rows we need to append the blank separator, in R2L 20905 /* In L2R rows we need to append the blank separator, in R2L
20899 rows we need to prepend it. But this function is usually 20906 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'. */);
32557 32564
32558 DEFVAR_LISP ("display-line-numbers", Vdisplay_line_numbers, 32565 DEFVAR_LISP ("display-line-numbers", Vdisplay_line_numbers,
32559 doc: /* Non-nil means display line numbers. 32566 doc: /* Non-nil means display line numbers.
32560Line numbers are displayed before each non-continuation line, i.e. 32567By default, line numbers are displayed before each non-continuation
32561after each newline that comes from buffer text. */); 32568line that displays buffer text, i.e. after each newline that came
32569from buffer text. However, if the value is `visual', every screen
32570line will have a number. */);
32562 Vdisplay_line_numbers = Qnil; 32571 Vdisplay_line_numbers = Qnil;
32563 DEFSYM (Qdisplay_line_numbers, "display-line-numbers"); 32572 DEFSYM (Qdisplay_line_numbers, "display-line-numbers");
32564 Fmake_variable_buffer_local (Qdisplay_line_numbers); 32573 Fmake_variable_buffer_local (Qdisplay_line_numbers);
@@ -32575,6 +32584,13 @@ Any other value is treated as nil. */);
32575 DEFSYM (Qdisplay_line_number_width, "display-line-number-width"); 32584 DEFSYM (Qdisplay_line_number_width, "display-line-number-width");
32576 Fmake_variable_buffer_local (Qdisplay_line_number_width); 32585 Fmake_variable_buffer_local (Qdisplay_line_number_width);
32577 32586
32587 DEFVAR_LISP ("display-line-numbers-current-absolute",
32588 Vdisplay_line_numbers_current_absolute,
32589 doc: /* Non-nil means display absolute number of current line.
32590This variable has effect only when `display-line-numbers' is
32591either `relative' or `visual'. */);
32592 Vdisplay_line_numbers_current_absolute = Qt;
32593
32578 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay, 32594 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay,
32579 doc: /* Non-nil means don't eval Lisp during redisplay. */); 32595 doc: /* Non-nil means don't eval Lisp during redisplay. */);
32580 inhibit_eval_during_redisplay = false; 32596 inhibit_eval_during_redisplay = false;