diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index 26b19eb44fb..5c6aea19697 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -20749,33 +20749,44 @@ 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 | /* Count the number of screen lines in window W between character | 20752 | /* Count the number of screen lines in window IT->w between character |
| 20753 | position CHARPOS and the line showing that window's point. */ | 20753 | position IT_CHARPOS(*IT) and the line showing that window's point. */ |
| 20754 | static ptrdiff_t | 20754 | static ptrdiff_t |
| 20755 | display_count_lines_visually (struct window *w, struct text_pos pos) | 20755 | display_count_lines_visually (struct it *it) |
| 20756 | { | 20756 | { |
| 20757 | struct it tem_it; | 20757 | struct it tem_it; |
| 20758 | ptrdiff_t to; | 20758 | ptrdiff_t to; |
| 20759 | struct text_pos from; | 20759 | struct text_pos from; |
| 20760 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 20761 | 20760 | ||
| 20762 | if (CHARPOS (pos) <= PT) | 20761 | /* If we already calculated a relative line number, use that. This |
| 20763 | { | 20762 | trick relies on the fact that visual lines (a.k.a. "glyph rows") |
| 20764 | from = pos; | 20763 | are laid out sequentially, one by one, for each sequence of calls |
| 20765 | to = PT; | 20764 | to display_line or other similar function that follows a call to |
| 20766 | } | 20765 | init_iterator. */ |
| 20766 | if (it->lnum_bytepos > 0) | ||
| 20767 | return it->lnum + 1; | ||
| 20767 | else | 20768 | else |
| 20768 | { | 20769 | { |
| 20769 | SET_TEXT_POS (from, PT, PT_BYTE); | 20770 | ptrdiff_t count = SPECPDL_INDEX (); |
| 20770 | to = CHARPOS (pos); | 20771 | |
| 20772 | if (IT_CHARPOS (*it) <= PT) | ||
| 20773 | { | ||
| 20774 | from = it->current.pos; | ||
| 20775 | to = PT; | ||
| 20776 | } | ||
| 20777 | else | ||
| 20778 | { | ||
| 20779 | SET_TEXT_POS (from, PT, PT_BYTE); | ||
| 20780 | to = IT_CHARPOS (*it); | ||
| 20781 | } | ||
| 20782 | start_display (&tem_it, it->w, from); | ||
| 20783 | /* Need to disable visual mode temporarily, since otherwise the | ||
| 20784 | call to move_it_to will cause infinite recursion. */ | ||
| 20785 | specbind (Qdisplay_line_numbers, Qrelative); | ||
| 20786 | move_it_to (&tem_it, to, -1, -1, -1, MOVE_TO_POS); | ||
| 20787 | unbind_to (count, Qnil); | ||
| 20788 | return IT_CHARPOS (*it) <= PT ? -tem_it.vpos : tem_it.vpos; | ||
| 20771 | } | 20789 | } |
| 20772 | start_display (&tem_it, w, from); | ||
| 20773 | /* Need to disable visual mode temporarily, since otherwise the call | ||
| 20774 | to move_it_to will cause infionite recursion. */ | ||
| 20775 | specbind (Qdisplay_line_numbers, Qrelative); | ||
| 20776 | move_it_to (&tem_it, to, -1, -1, -1, MOVE_TO_POS); | ||
| 20777 | unbind_to (count, Qnil); | ||
| 20778 | return CHARPOS (pos) <= PT ? -tem_it.vpos : tem_it.vpos; | ||
| 20779 | } | 20790 | } |
| 20780 | 20791 | ||
| 20781 | /* Produce the line-number glyphs for the current glyph_row. If | 20792 | /* Produce the line-number glyphs for the current glyph_row. If |
| @@ -20791,7 +20802,7 @@ maybe_produce_line_number (struct it *it) | |||
| 20791 | void *itdata = bidi_shelve_cache (); | 20802 | void *itdata = bidi_shelve_cache (); |
| 20792 | 20803 | ||
| 20793 | if (EQ (Vdisplay_line_numbers, Qvisual)) | 20804 | if (EQ (Vdisplay_line_numbers, Qvisual)) |
| 20794 | this_line = display_count_lines_visually (it->w, it->current.pos); | 20805 | this_line = display_count_lines_visually (it); |
| 20795 | else | 20806 | else |
| 20796 | { | 20807 | { |
| 20797 | if (!last_line) | 20808 | if (!last_line) |
| @@ -20819,13 +20830,13 @@ maybe_produce_line_number (struct it *it) | |||
| 20819 | &bytepos); | 20830 | &bytepos); |
| 20820 | eassert (this_line > 0 || (this_line == 0 && start_from == BEGV_BYTE)); | 20831 | eassert (this_line > 0 || (this_line == 0 && start_from == BEGV_BYTE)); |
| 20821 | eassert (bytepos == IT_BYTEPOS (*it)); | 20832 | eassert (bytepos == IT_BYTEPOS (*it)); |
| 20833 | } | ||
| 20822 | 20834 | ||
| 20823 | /* Record the line number information. */ | 20835 | /* Record the line number information. */ |
| 20824 | if (this_line != last_line || !last_line) | 20836 | if (this_line != last_line || !it->lnum_bytepos) |
| 20825 | { | 20837 | { |
| 20826 | it->lnum = this_line; | 20838 | it->lnum = this_line; |
| 20827 | it->lnum_bytepos = IT_BYTEPOS (*it); | 20839 | it->lnum_bytepos = IT_BYTEPOS (*it); |
| 20828 | } | ||
| 20829 | } | 20840 | } |
| 20830 | 20841 | ||
| 20831 | /* Produce the glyphs for the line number. */ | 20842 | /* Produce the glyphs for the line number. */ |