diff options
| author | Juanma Barranquero | 2019-10-09 12:49:39 +0200 |
|---|---|---|
| committer | Juanma Barranquero | 2019-10-09 12:49:39 +0200 |
| commit | 76a9f03ca629d3e5a596c3aa7f62a4649ac2ae8a (patch) | |
| tree | b6751a7a1b7b184e28e66f20395d65c984daaf57 | |
| parent | 4b06250ef1fe98a766938862912383d2ee051dfb (diff) | |
| download | emacs-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.
| -rw-r--r-- | doc/emacs/display.texi | 7 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/frame.el | 1 | ||||
| -rw-r--r-- | src/xdisp.c | 43 |
4 files changed, 48 insertions, 7 deletions
diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi index 406feb8c127..cb37ef448e8 100644 --- a/doc/emacs/display.texi +++ b/doc/emacs/display.texi | |||
| @@ -1855,6 +1855,13 @@ the variable @code{display-line-numbers-widen} to a non-@code{nil} | |||
| 1855 | value, line numbers will disregard any narrowing and will start at the | 1855 | value, line numbers will disregard any narrowing and will start at the |
| 1856 | first character of the buffer. | 1856 | first character of the buffer. |
| 1857 | 1857 | ||
| 1858 | @vindex display-line-numbers-offset | ||
| 1859 | If the value of @code{display-line-numbers-offset} is non-zero, it is | ||
| 1860 | added to each absolute line number, and lines are counted from the | ||
| 1861 | beginning of the buffer, as if @code{display-line-numbers-widen} were | ||
| 1862 | non-@code{nil}. It has no effect when set to zero, or when line | ||
| 1863 | numbers are not absolute. | ||
| 1864 | |||
| 1858 | @vindex display-line-numbers-width-start | 1865 | @vindex display-line-numbers-width-start |
| 1859 | @vindex display-line-numbers-grow-only | 1866 | @vindex display-line-numbers-grow-only |
| 1860 | @vindex display-line-numbers-width | 1867 | @vindex display-line-numbers-width |
| @@ -560,11 +560,15 @@ now prompts the user for the directory containing the desktop file. | |||
| 560 | 560 | ||
| 561 | +++ | 561 | +++ |
| 562 | ** display-line-numbers-mode | 562 | ** display-line-numbers-mode |
| 563 | |||
| 563 | *** New faces 'line-number-major-tick' and 'line-number-minor-tick', | 564 | *** New faces 'line-number-major-tick' and 'line-number-minor-tick', |
| 564 | and customizable variables 'display-line-numbers-major-tick' and | 565 | and customizable variables 'display-line-numbers-major-tick' and |
| 565 | 'display-line-numbers-minor-tick' can be used to highlight the line | 566 | 'display-line-numbers-minor-tick' can be used to highlight the line |
| 566 | numbers of lines multiple of certain numbers. | 567 | numbers of lines multiple of certain numbers. |
| 567 | 568 | ||
| 569 | *** New variable `display-line-numbers-offset', when non-zero, adds | ||
| 570 | an offset to absolute line numbers. | ||
| 571 | |||
| 568 | +++ | 572 | +++ |
| 569 | ** winner | 573 | ** winner |
| 570 | *** A new variable, 'winner-boring-buffers-regexp', has been added. | 574 | *** A new variable, 'winner-boring-buffers-regexp', has been added. |
diff --git a/lisp/frame.el b/lisp/frame.el index 51b3b621ff4..018c2f578e4 100644 --- a/lisp/frame.el +++ b/lisp/frame.el | |||
| @@ -2726,6 +2726,7 @@ See also `toggle-frame-maximized'." | |||
| 2726 | display-line-numbers-widen | 2726 | display-line-numbers-widen |
| 2727 | display-line-numbers-major-tick | 2727 | display-line-numbers-major-tick |
| 2728 | display-line-numbers-minor-tick | 2728 | display-line-numbers-minor-tick |
| 2729 | display-line-numbers-offset | ||
| 2729 | display-fill-column-indicator | 2730 | display-fill-column-indicator |
| 2730 | display-fill-column-indicator-column | 2731 | display-fill-column-indicator-column |
| 2731 | display-fill-column-indicator-character | 2732 | display-fill-column-indicator-character |
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 | |||
| 34714 | If the value is t, display the absolute number of each line of a buffer | 34729 | If the value is t, display the absolute number of each line of a buffer |
| 34715 | shown in a window. Absolute line numbers count from the beginning of | 34730 | shown in a window. Absolute line numbers count from the beginning of |
| 34716 | the current narrowing, or from buffer beginning. If the value is | 34731 | the 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 |
| 34718 | relative number instead, i.e. the number of the line relative to the | 34733 | to each absolute line number; it also forces line numbers to be counted |
| 34719 | line showing the window's point. | 34734 | from the beginning of the buffer, as if `display-line-numbers-wide' |
| 34735 | were non-nil. It has no effect when line numbers are not absolute. | ||
| 34736 | |||
| 34737 | If the value is `relative', display for each line not containing the | ||
| 34738 | window's point its relative number instead, i.e. the number of the line | ||
| 34739 | relative to the line showing the window's point. | ||
| 34720 | 34740 | ||
| 34721 | In either case, line numbers are displayed at the beginning of each | 34741 | In either case, line numbers are displayed at the beginning of each |
| 34722 | non-continuation line that displays buffer text, i.e. after each newline | 34742 | non-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. | ||
| 34782 | When this variable is non-zero, line numbers are always counted from | ||
| 34783 | the beginning of the buffer even if `display-line-numbers-widen' is nil. | ||
| 34784 | It 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; |