aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuanma Barranquero2019-10-09 12:49:39 +0200
committerJuanma Barranquero2019-10-09 12:49:39 +0200
commit76a9f03ca629d3e5a596c3aa7f62a4649ac2ae8a (patch)
treeb6751a7a1b7b184e28e66f20395d65c984daaf57 /src
parent4b06250ef1fe98a766938862912383d2ee051dfb (diff)
downloademacs-76a9f03ca629d3e5a596c3aa7f62a4649ac2ae8a.tar.gz
emacs-76a9f03ca629d3e5a596c3aa7f62a4649ac2ae8a.zip
Implement offsets for absolute line numbers
* src/xdisp.c (syms_of_xdisp) <display-line-numbers-offset>: New variable to add an offset to absolute line numbers. (syms_of_xdisp) <display-line-numbers>: Mention it in docstring. (maybe_produce_line_number): Use it. * doc/emacs/display.texi (Display Custom): Document it. * etc/NEWS (value): Announce it. * lisp/frame.el: Add `display-line-numbers-offset' to list of variables which should trigger redisplay of the current buffer.
Diffstat (limited to 'src')
-rw-r--r--src/xdisp.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/xdisp.c b/src/xdisp.c
index 52275a11b86..893ce9269c1 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -22512,10 +22512,22 @@ maybe_produce_line_number (struct it *it)
22512 ptrdiff_t start_from, bytepos; 22512 ptrdiff_t start_from, bytepos;
22513 ptrdiff_t this_line; 22513 ptrdiff_t this_line;
22514 bool first_time = false; 22514 bool first_time = false;
22515 ptrdiff_t beg_byte = display_line_numbers_widen ? BEG_BYTE : BEGV_BYTE; 22515 ptrdiff_t beg_byte;
22516 ptrdiff_t z_byte = display_line_numbers_widen ? Z_BYTE : ZV_BYTE; 22516 ptrdiff_t z_byte;
22517 bool line_numbers_wide;
22517 void *itdata = bidi_shelve_cache (); 22518 void *itdata = bidi_shelve_cache ();
22518 22519
22520 if (display_line_numbers_offset
22521 && !display_line_numbers_widen
22522 && !EQ (Vdisplay_line_numbers, Qvisual)
22523 && !EQ (Vdisplay_line_numbers, Qrelative))
22524 line_numbers_wide = true;
22525 else
22526 line_numbers_wide = display_line_numbers_widen;
22527
22528 beg_byte = line_numbers_wide ? BEG_BYTE : BEGV_BYTE;
22529 z_byte = line_numbers_wide ? Z_BYTE : ZV_BYTE;
22530
22519 if (EQ (Vdisplay_line_numbers, Qvisual)) 22531 if (EQ (Vdisplay_line_numbers, Qvisual))
22520 this_line = display_count_lines_visually (it); 22532 this_line = display_count_lines_visually (it);
22521 else 22533 else
@@ -22530,7 +22542,7 @@ maybe_produce_line_number (struct it *it)
22530 numbers, so we cannot use its data if the user wants 22542 numbers, so we cannot use its data if the user wants
22531 line numbers that disregard narrowing, or if the 22543 line numbers that disregard narrowing, or if the
22532 buffer's narrowing has just changed. */ 22544 buffer's narrowing has just changed. */
22533 && !(display_line_numbers_widen 22545 && !(line_numbers_wide
22534 && (BEG_BYTE != BEGV_BYTE || Z_BYTE != ZV_BYTE)) 22546 && (BEG_BYTE != BEGV_BYTE || Z_BYTE != ZV_BYTE))
22535 && !current_buffer->clip_changed) 22547 && !current_buffer->clip_changed)
22536 { 22548 {
@@ -22620,6 +22632,8 @@ maybe_produce_line_number (struct it *it)
22620 lnum_offset = it->pt_lnum; 22632 lnum_offset = it->pt_lnum;
22621 else if (EQ (Vdisplay_line_numbers, Qvisual)) 22633 else if (EQ (Vdisplay_line_numbers, Qvisual))
22622 lnum_offset = 0; 22634 lnum_offset = 0;
22635 else if (display_line_numbers_offset)
22636 lnum_offset -= display_line_numbers_offset;
22623 22637
22624 /* Under 'relative', display the absolute line number for the 22638 /* Under 'relative', display the absolute line number for the
22625 current line, unless the user requests otherwise. */ 22639 current line, unless the user requests otherwise. */
@@ -34711,12 +34725,18 @@ To add a prefix to continuation lines, use `wrap-prefix'. */);
34711 34725
34712 DEFVAR_LISP ("display-line-numbers", Vdisplay_line_numbers, 34726 DEFVAR_LISP ("display-line-numbers", Vdisplay_line_numbers,
34713 doc: /* Non-nil means display line numbers. 34727 doc: /* Non-nil means display line numbers.
34728
34714If the value is t, display the absolute number of each line of a buffer 34729If the value is t, display the absolute number of each line of a buffer
34715shown in a window. Absolute line numbers count from the beginning of 34730shown in a window. Absolute line numbers count from the beginning of
34716the current narrowing, or from buffer beginning. If the value is 34731the current narrowing, or from buffer beginning. The variable
34717`relative', display for each line not containing the window's point its 34732`display-line-numbers-offset', if non-zero, is a signed offset added
34718relative number instead, i.e. the number of the line relative to the 34733to each absolute line number; it also forces line numbers to be counted
34719line showing the window's point. 34734from the beginning of the buffer, as if `display-line-numbers-wide'
34735were non-nil. It has no effect when line numbers are not absolute.
34736
34737If the value is `relative', display for each line not containing the
34738window's point its relative number instead, i.e. the number of the line
34739relative to the line showing the window's point.
34720 34740
34721In either case, line numbers are displayed at the beginning of each 34741In either case, line numbers are displayed at the beginning of each
34722non-continuation line that displays buffer text, i.e. after each newline 34742non-continuation line that displays buffer text, i.e. after each newline
@@ -34757,6 +34777,15 @@ either `relative' or `visual'. */);
34757 DEFSYM (Qdisplay_line_numbers_widen, "display-line-numbers-widen"); 34777 DEFSYM (Qdisplay_line_numbers_widen, "display-line-numbers-widen");
34758 Fmake_variable_buffer_local (Qdisplay_line_numbers_widen); 34778 Fmake_variable_buffer_local (Qdisplay_line_numbers_widen);
34759 34779
34780 DEFVAR_INT ("display-line-numbers-offset", display_line_numbers_offset,
34781 doc: /* A signed integer added to each absolute line number.
34782When this variable is non-zero, line numbers are always counted from
34783the beginning of the buffer even if `display-line-numbers-widen' is nil.
34784It has no effect when set to 0, or when line numbers are not absolute. */);
34785 display_line_numbers_offset = 0;
34786 DEFSYM (Qdisplay_line_numbers_offset, "display-line-numbers-offset");
34787 Fmake_variable_buffer_local (Qdisplay_line_numbers_offset);
34788
34760 DEFVAR_BOOL ("display-fill-column-indicator", Vdisplay_fill_column_indicator, 34789 DEFVAR_BOOL ("display-fill-column-indicator", Vdisplay_fill_column_indicator,
34761 doc: /* Non-nil means display the fill column indicator. */); 34790 doc: /* Non-nil means display the fill column indicator. */);
34762 Vdisplay_fill_column_indicator = false; 34791 Vdisplay_fill_column_indicator = false;