diff options
| author | Eli Zaretskii | 2017-07-06 20:22:16 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-07-06 20:22:16 +0300 |
| commit | 25bc3911615d1160d47287c023545c6e0587739f (patch) | |
| tree | c32eaa3034c93867ae3c820731057505f8fc3f52 /src | |
| parent | d5f8a3d03f6c0c98f3280d55a2d88ddb40aa1f3e (diff) | |
| download | emacs-25bc3911615d1160d47287c023545c6e0587739f.tar.gz emacs-25bc3911615d1160d47287c023545c6e0587739f.zip | |
Implement line numbers that disregard narrowing
* src/xdisp.c (display_count_lines_logically): New function,
counts line numbers disregarding narrowing. Suggested by Andy
Moreton <andrewjmoreton@gmail.com>.
(maybe_produce_line_number): Call display_count_lines_logically
instead of display_count_lines. Adapt BEGV, ZV, etc. to
display-line-numbers-widen.
(syms_of_xdisp) <display-line-numbers-widen>: New buffer-local
variable.
* lisp/cus-start.el (standard): Provide a customization form for
display-line-numbers-widen.
* lisp/frame.el: Add display-line-numbers-widen,
display-line-numbers-current-absolute, and
display-line-number-width to the list of variables that should
trigger redisplay of the current buffer.
* doc/emacs/display.texi (Display Custom): Document
display-line-numbers-widen.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index 312ee10f280..92ce1451867 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -20749,6 +20749,24 @@ find_row_edges (struct it *it, struct glyph_row *row, | |||
| 20749 | row->maxpos = it->current.pos; | 20749 | row->maxpos = it->current.pos; |
| 20750 | } | 20750 | } |
| 20751 | 20751 | ||
| 20752 | /* Like display_count_lines, but capable of counting outside of the | ||
| 20753 | current narrowed region. */ | ||
| 20754 | static ptrdiff_t | ||
| 20755 | display_count_lines_logically (ptrdiff_t start_byte, ptrdiff_t limit_byte, | ||
| 20756 | ptrdiff_t count, ptrdiff_t *byte_pos_ptr) | ||
| 20757 | { | ||
| 20758 | if (!display_line_numbers_widen || (BEGV == BEG && ZV == Z)) | ||
| 20759 | return display_count_lines (start_byte, limit_byte, count, byte_pos_ptr); | ||
| 20760 | |||
| 20761 | ptrdiff_t val; | ||
| 20762 | ptrdiff_t pdl_count = SPECPDL_INDEX (); | ||
| 20763 | record_unwind_protect (save_restriction_restore, save_restriction_save ()); | ||
| 20764 | Fwiden (); | ||
| 20765 | val = display_count_lines (start_byte, limit_byte, count, byte_pos_ptr); | ||
| 20766 | unbind_to (pdl_count, Qnil); | ||
| 20767 | return val; | ||
| 20768 | } | ||
| 20769 | |||
| 20752 | /* Count the number of screen lines in window IT->w between character | 20770 | /* Count the number of screen lines in window IT->w between character |
| 20753 | position IT_CHARPOS(*IT) and the line showing that window's point. */ | 20771 | position IT_CHARPOS(*IT) and the line showing that window's point. */ |
| 20754 | static ptrdiff_t | 20772 | static ptrdiff_t |
| @@ -20806,6 +20824,9 @@ maybe_produce_line_number (struct it *it) | |||
| 20806 | ptrdiff_t start_from, bytepos; | 20824 | ptrdiff_t start_from, bytepos; |
| 20807 | ptrdiff_t this_line; | 20825 | ptrdiff_t this_line; |
| 20808 | bool first_time = false; | 20826 | bool first_time = false; |
| 20827 | ptrdiff_t beg = display_line_numbers_widen ? BEG : BEGV; | ||
| 20828 | ptrdiff_t beg_byte = display_line_numbers_widen ? BEG_BYTE : BEGV_BYTE; | ||
| 20829 | ptrdiff_t z_byte = display_line_numbers_widen ? Z_BYTE : ZV_BYTE; | ||
| 20809 | void *itdata = bidi_shelve_cache (); | 20830 | void *itdata = bidi_shelve_cache (); |
| 20810 | 20831 | ||
| 20811 | if (EQ (Vdisplay_line_numbers, Qvisual)) | 20832 | if (EQ (Vdisplay_line_numbers, Qvisual)) |
| @@ -20815,7 +20836,7 @@ maybe_produce_line_number (struct it *it) | |||
| 20815 | if (!last_line) | 20836 | if (!last_line) |
| 20816 | { | 20837 | { |
| 20817 | /* FIXME: Maybe reuse the data in it->w->base_line_number. */ | 20838 | /* FIXME: Maybe reuse the data in it->w->base_line_number. */ |
| 20818 | start_from = BEGV; | 20839 | start_from = beg; |
| 20819 | if (!it->lnum_bytepos) | 20840 | if (!it->lnum_bytepos) |
| 20820 | first_time = true; | 20841 | first_time = true; |
| 20821 | } | 20842 | } |
| @@ -20825,17 +20846,17 @@ maybe_produce_line_number (struct it *it) | |||
| 20825 | /* Paranoia: what if someone changes the narrowing since the | 20846 | /* Paranoia: what if someone changes the narrowing since the |
| 20826 | last time display_line was called? Shouldn't really happen, | 20847 | last time display_line was called? Shouldn't really happen, |
| 20827 | but who knows what some crazy Lisp invoked by :eval could do? */ | 20848 | but who knows what some crazy Lisp invoked by :eval could do? */ |
| 20828 | if (!(BEGV_BYTE <= start_from && start_from < ZV_BYTE)) | 20849 | if (!(beg_byte <= start_from && start_from < z_byte)) |
| 20829 | { | 20850 | { |
| 20830 | last_line = 0; | 20851 | last_line = 0; |
| 20831 | start_from = BEGV_BYTE; | 20852 | start_from = beg_byte; |
| 20832 | } | 20853 | } |
| 20833 | 20854 | ||
| 20834 | this_line = | 20855 | this_line = |
| 20835 | last_line + display_count_lines (start_from, | 20856 | last_line + display_count_lines_logically (start_from, |
| 20836 | IT_BYTEPOS (*it), IT_CHARPOS (*it), | 20857 | IT_BYTEPOS (*it), |
| 20837 | &bytepos); | 20858 | IT_CHARPOS (*it), &bytepos); |
| 20838 | eassert (this_line > 0 || (this_line == 0 && start_from == BEGV_BYTE)); | 20859 | eassert (this_line > 0 || (this_line == 0 && start_from == beg_byte)); |
| 20839 | eassert (bytepos == IT_BYTEPOS (*it)); | 20860 | eassert (bytepos == IT_BYTEPOS (*it)); |
| 20840 | } | 20861 | } |
| 20841 | 20862 | ||
| @@ -20863,11 +20884,11 @@ maybe_produce_line_number (struct it *it) | |||
| 20863 | ptrdiff_t ignored; | 20884 | ptrdiff_t ignored; |
| 20864 | if (PT_BYTE > it->lnum_bytepos && !EQ (Vdisplay_line_numbers, Qvisual)) | 20885 | if (PT_BYTE > it->lnum_bytepos && !EQ (Vdisplay_line_numbers, Qvisual)) |
| 20865 | it->pt_lnum = | 20886 | it->pt_lnum = |
| 20866 | this_line + display_count_lines (it->lnum_bytepos, PT_BYTE, PT, | 20887 | this_line + display_count_lines_logically (it->lnum_bytepos, PT_BYTE, |
| 20867 | &ignored); | 20888 | PT, &ignored); |
| 20868 | else | 20889 | else |
| 20869 | it->pt_lnum = display_count_lines (BEGV_BYTE, PT_BYTE, PT, | 20890 | it->pt_lnum = display_count_lines_logically (beg_byte, PT_BYTE, PT, |
| 20870 | &ignored); | 20891 | &ignored); |
| 20871 | } | 20892 | } |
| 20872 | /* Compute the required width if needed. */ | 20893 | /* Compute the required width if needed. */ |
| 20873 | if (!it->lnum_width) | 20894 | if (!it->lnum_width) |
| @@ -32604,6 +32625,12 @@ This variable has effect only when `display-line-numbers' is | |||
| 32604 | either `relative' or `visual'. */); | 32625 | either `relative' or `visual'. */); |
| 32605 | Vdisplay_line_numbers_current_absolute = Qt; | 32626 | Vdisplay_line_numbers_current_absolute = Qt; |
| 32606 | 32627 | ||
| 32628 | DEFVAR_BOOL ("display-line-numbers-widen", display_line_numbers_widen, | ||
| 32629 | doc: /* Non-nil means display line numbers disregarding any narrowing. */); | ||
| 32630 | display_line_numbers_widen = false; | ||
| 32631 | DEFSYM (Qdisplay_line_numbers_widen, "display-line-numbers-widen"); | ||
| 32632 | Fmake_variable_buffer_local (Qdisplay_line_numbers_widen); | ||
| 32633 | |||
| 32607 | DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay, | 32634 | DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay, |
| 32608 | doc: /* Non-nil means don't eval Lisp during redisplay. */); | 32635 | doc: /* Non-nil means don't eval Lisp during redisplay. */); |
| 32609 | inhibit_eval_during_redisplay = false; | 32636 | inhibit_eval_during_redisplay = false; |