diff options
| author | Michael R. Mauger | 2017-07-24 22:15:04 -0400 |
|---|---|---|
| committer | Michael R. Mauger | 2017-07-24 22:15:04 -0400 |
| commit | df1a71272e5cdd10b511e2ffd702ca50ddd8a773 (patch) | |
| tree | 9b9ac725394ee80891e2bff57b6407d0e491e71a /src/xdisp.c | |
| parent | eb27fc4d49e8c914cd0e6a8a2d02159601542141 (diff) | |
| parent | 32daa3cb54523006c88717cbeac87964cd687a1b (diff) | |
| download | emacs-df1a71272e5cdd10b511e2ffd702ca50ddd8a773.tar.gz emacs-df1a71272e5cdd10b511e2ffd702ca50ddd8a773.zip | |
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'src/xdisp.c')
| -rw-r--r-- | src/xdisp.c | 620 |
1 files changed, 583 insertions, 37 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index 1c316fa4932..422912e57a6 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -290,6 +290,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 290 | #include <stdio.h> | 290 | #include <stdio.h> |
| 291 | #include <stdlib.h> | 291 | #include <stdlib.h> |
| 292 | #include <limits.h> | 292 | #include <limits.h> |
| 293 | #include <math.h> | ||
| 293 | 294 | ||
| 294 | #include "lisp.h" | 295 | #include "lisp.h" |
| 295 | #include "atimer.h" | 296 | #include "atimer.h" |
| @@ -324,7 +325,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 324 | #define FRAME_X_OUTPUT(f) ((f)->output_data.x) | 325 | #define FRAME_X_OUTPUT(f) ((f)->output_data.x) |
| 325 | #endif | 326 | #endif |
| 326 | 327 | ||
| 327 | #define INFINITY 10000000 | 328 | #define DISP_INFINITY 10000000 |
| 328 | 329 | ||
| 329 | /* Holds the list (error). */ | 330 | /* Holds the list (error). */ |
| 330 | static Lisp_Object list_of_error; | 331 | static Lisp_Object list_of_error; |
| @@ -832,6 +833,8 @@ static bool cursor_row_fully_visible_p (struct window *, bool, bool); | |||
| 832 | static bool update_menu_bar (struct frame *, bool, bool); | 833 | static bool update_menu_bar (struct frame *, bool, bool); |
| 833 | static bool try_window_reusing_current_matrix (struct window *); | 834 | static bool try_window_reusing_current_matrix (struct window *); |
| 834 | static int try_window_id (struct window *); | 835 | static int try_window_id (struct window *); |
| 836 | static void maybe_produce_line_number (struct it *); | ||
| 837 | static bool should_produce_line_number (struct it *); | ||
| 835 | static bool display_line (struct it *, int); | 838 | static bool display_line (struct it *, int); |
| 836 | static int display_mode_lines (struct window *); | 839 | static int display_mode_lines (struct window *); |
| 837 | static int display_mode_line (struct window *, enum face_id, Lisp_Object); | 840 | static int display_mode_line (struct window *, enum face_id, Lisp_Object); |
| @@ -843,6 +846,8 @@ static const char *decode_mode_spec (struct window *, int, int, Lisp_Object *); | |||
| 843 | static void display_menu_bar (struct window *); | 846 | static void display_menu_bar (struct window *); |
| 844 | static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t, | 847 | static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t, |
| 845 | ptrdiff_t *); | 848 | ptrdiff_t *); |
| 849 | static void pint2str (register char *, register int, register ptrdiff_t); | ||
| 850 | |||
| 846 | static int display_string (const char *, Lisp_Object, Lisp_Object, | 851 | static int display_string (const char *, Lisp_Object, Lisp_Object, |
| 847 | ptrdiff_t, ptrdiff_t, struct it *, int, int, int, int); | 852 | ptrdiff_t, ptrdiff_t, struct it *, int, int, int, int); |
| 848 | static void compute_line_metrics (struct it *); | 853 | static void compute_line_metrics (struct it *); |
| @@ -1321,6 +1326,15 @@ pos_visible_p (struct window *w, ptrdiff_t charpos, int *x, int *y, | |||
| 1321 | if (charpos >= 0 && CHARPOS (top) > charpos) | 1326 | if (charpos >= 0 && CHARPOS (top) > charpos) |
| 1322 | return visible_p; | 1327 | return visible_p; |
| 1323 | 1328 | ||
| 1329 | /* Some Lisp hook could call us in the middle of redisplaying this | ||
| 1330 | very window. If, by some bad luck, we are retrying redisplay | ||
| 1331 | because we found that the mode-line height and/or header-line | ||
| 1332 | height needs to be updated, the assignment of mode_line_height | ||
| 1333 | and header_line_height below could disrupt that, due to the | ||
| 1334 | selected/nonselected window dance during mode-line display, and | ||
| 1335 | we could infloop. Avoid that. */ | ||
| 1336 | int prev_mode_line_height = w->mode_line_height; | ||
| 1337 | int prev_header_line_height = w->header_line_height; | ||
| 1324 | /* Compute exact mode line heights. */ | 1338 | /* Compute exact mode line heights. */ |
| 1325 | if (window_wants_mode_line (w)) | 1339 | if (window_wants_mode_line (w)) |
| 1326 | { | 1340 | { |
| @@ -1667,6 +1681,10 @@ pos_visible_p (struct window *w, ptrdiff_t charpos, int *x, int *y, | |||
| 1667 | fprintf (stderr, "-pv pt=%d vs=%d\n", charpos, w->vscroll); | 1681 | fprintf (stderr, "-pv pt=%d vs=%d\n", charpos, w->vscroll); |
| 1668 | #endif | 1682 | #endif |
| 1669 | 1683 | ||
| 1684 | /* Restore potentially overwritten values. */ | ||
| 1685 | w->mode_line_height = prev_mode_line_height; | ||
| 1686 | w->header_line_height = prev_header_line_height; | ||
| 1687 | |||
| 1670 | return visible_p; | 1688 | return visible_p; |
| 1671 | } | 1689 | } |
| 1672 | 1690 | ||
| @@ -6764,7 +6782,7 @@ reseat_to_string (struct it *it, const char *s, Lisp_Object string, | |||
| 6764 | FIELD_WIDTH < 0 means infinite field width. This is useful for | 6782 | FIELD_WIDTH < 0 means infinite field width. This is useful for |
| 6765 | padding with `-' at the end of a mode line. */ | 6783 | padding with `-' at the end of a mode line. */ |
| 6766 | if (field_width < 0) | 6784 | if (field_width < 0) |
| 6767 | field_width = INFINITY; | 6785 | field_width = DISP_INFINITY; |
| 6768 | /* Implementation note: We deliberately don't enlarge | 6786 | /* Implementation note: We deliberately don't enlarge |
| 6769 | it->bidi_it.string.schars here to fit it->end_charpos, because | 6787 | it->bidi_it.string.schars here to fit it->end_charpos, because |
| 6770 | the bidi iterator cannot produce characters out of thin air. */ | 6788 | the bidi iterator cannot produce characters out of thin air. */ |
| @@ -8613,6 +8631,7 @@ move_it_in_display_line_to (struct it *it, | |||
| 8613 | ptrdiff_t closest_pos UNINIT; | 8631 | ptrdiff_t closest_pos UNINIT; |
| 8614 | ptrdiff_t prev_pos = IT_CHARPOS (*it); | 8632 | ptrdiff_t prev_pos = IT_CHARPOS (*it); |
| 8615 | bool saw_smaller_pos = prev_pos < to_charpos; | 8633 | bool saw_smaller_pos = prev_pos < to_charpos; |
| 8634 | bool line_number_pending = false; | ||
| 8616 | 8635 | ||
| 8617 | /* Don't produce glyphs in produce_glyphs. */ | 8636 | /* Don't produce glyphs in produce_glyphs. */ |
| 8618 | saved_glyph_row = it->glyph_row; | 8637 | saved_glyph_row = it->glyph_row; |
| @@ -8661,9 +8680,20 @@ move_it_in_display_line_to (struct it *it, | |||
| 8661 | || (it->method == GET_FROM_DISPLAY_VECTOR \ | 8680 | || (it->method == GET_FROM_DISPLAY_VECTOR \ |
| 8662 | && it->dpvec + it->current.dpvec_index + 1 >= it->dpend))) | 8681 | && it->dpvec + it->current.dpvec_index + 1 >= it->dpend))) |
| 8663 | 8682 | ||
| 8664 | /* If there's a line-/wrap-prefix, handle it. */ | 8683 | if (it->hpos == 0) |
| 8665 | if (it->hpos == 0 && it->method == GET_FROM_BUFFER) | 8684 | { |
| 8666 | handle_line_prefix (it); | 8685 | /* If line numbers are being displayed, produce a line number. */ |
| 8686 | if (should_produce_line_number (it)) | ||
| 8687 | { | ||
| 8688 | if (it->current_x == it->first_visible_x) | ||
| 8689 | maybe_produce_line_number (it); | ||
| 8690 | else | ||
| 8691 | line_number_pending = true; | ||
| 8692 | } | ||
| 8693 | /* If there's a line-/wrap-prefix, handle it. */ | ||
| 8694 | if (it->method == GET_FROM_BUFFER) | ||
| 8695 | handle_line_prefix (it); | ||
| 8696 | } | ||
| 8667 | 8697 | ||
| 8668 | if (IT_CHARPOS (*it) < CHARPOS (this_line_min_pos)) | 8698 | if (IT_CHARPOS (*it) < CHARPOS (this_line_min_pos)) |
| 8669 | SET_TEXT_POS (this_line_min_pos, IT_CHARPOS (*it), IT_BYTEPOS (*it)); | 8699 | SET_TEXT_POS (this_line_min_pos, IT_CHARPOS (*it), IT_BYTEPOS (*it)); |
| @@ -9030,6 +9060,15 @@ move_it_in_display_line_to (struct it *it, | |||
| 9030 | 9060 | ||
| 9031 | if (new_x > it->first_visible_x) | 9061 | if (new_x > it->first_visible_x) |
| 9032 | { | 9062 | { |
| 9063 | /* If we have reached the visible portion of the | ||
| 9064 | screen line, produce the line number if needed. */ | ||
| 9065 | if (line_number_pending) | ||
| 9066 | { | ||
| 9067 | line_number_pending = false; | ||
| 9068 | it->current_x = it->first_visible_x; | ||
| 9069 | maybe_produce_line_number (it); | ||
| 9070 | it->current_x += new_x - it->first_visible_x; | ||
| 9071 | } | ||
| 9033 | /* Glyph is visible. Increment number of glyphs that | 9072 | /* Glyph is visible. Increment number of glyphs that |
| 9034 | would be displayed. */ | 9073 | would be displayed. */ |
| 9035 | ++it->hpos; | 9074 | ++it->hpos; |
| @@ -13069,6 +13108,43 @@ hscroll_window_tree (Lisp_Object window) | |||
| 13069 | } | 13108 | } |
| 13070 | bool row_r2l_p = cursor_row->reversed_p; | 13109 | bool row_r2l_p = cursor_row->reversed_p; |
| 13071 | bool hscl = hscrolling_current_line_p (w); | 13110 | bool hscl = hscrolling_current_line_p (w); |
| 13111 | int x_offset = 0; | ||
| 13112 | /* When line numbers are displayed, we need to account for | ||
| 13113 | the horizontal space they consume. */ | ||
| 13114 | if (!NILP (Vdisplay_line_numbers)) | ||
| 13115 | { | ||
| 13116 | struct glyph *g; | ||
| 13117 | if (!row_r2l_p) | ||
| 13118 | { | ||
| 13119 | for (g = cursor_row->glyphs[TEXT_AREA]; | ||
| 13120 | g < cursor_row->glyphs[TEXT_AREA] | ||
| 13121 | + cursor_row->used[TEXT_AREA]; | ||
| 13122 | g++) | ||
| 13123 | { | ||
| 13124 | if (!(NILP (g->object) && g->charpos < 0)) | ||
| 13125 | break; | ||
| 13126 | x_offset += g->pixel_width; | ||
| 13127 | } | ||
| 13128 | } | ||
| 13129 | else | ||
| 13130 | { | ||
| 13131 | for (g = cursor_row->glyphs[TEXT_AREA] | ||
| 13132 | + cursor_row->used[TEXT_AREA]; | ||
| 13133 | g > cursor_row->glyphs[TEXT_AREA]; | ||
| 13134 | g--) | ||
| 13135 | { | ||
| 13136 | if (!(NILP ((g - 1)->object) && (g - 1)->charpos < 0)) | ||
| 13137 | break; | ||
| 13138 | x_offset += (g - 1)->pixel_width; | ||
| 13139 | } | ||
| 13140 | } | ||
| 13141 | } | ||
| 13142 | if (cursor_row->truncated_on_left_p) | ||
| 13143 | { | ||
| 13144 | /* On TTY frames, don't count the left truncation glyph. */ | ||
| 13145 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | ||
| 13146 | x_offset -= (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)); | ||
| 13147 | } | ||
| 13072 | 13148 | ||
| 13073 | text_area_width = window_box_width (w, TEXT_AREA); | 13149 | text_area_width = window_box_width (w, TEXT_AREA); |
| 13074 | 13150 | ||
| @@ -13101,7 +13177,7 @@ hscroll_window_tree (Lisp_Object window) | |||
| 13101 | inside the left margin and the window is already | 13177 | inside the left margin and the window is already |
| 13102 | hscrolled. */ | 13178 | hscrolled. */ |
| 13103 | && ((!row_r2l_p | 13179 | && ((!row_r2l_p |
| 13104 | && ((w->hscroll && w->cursor.x <= h_margin) | 13180 | && ((w->hscroll && w->cursor.x <= h_margin + x_offset) |
| 13105 | || (cursor_row->enabled_p | 13181 | || (cursor_row->enabled_p |
| 13106 | && cursor_row->truncated_on_right_p | 13182 | && cursor_row->truncated_on_right_p |
| 13107 | && (w->cursor.x >= text_area_width - h_margin)))) | 13183 | && (w->cursor.x >= text_area_width - h_margin)))) |
| @@ -13119,7 +13195,8 @@ hscroll_window_tree (Lisp_Object window) | |||
| 13119 | && cursor_row->truncated_on_right_p | 13195 | && cursor_row->truncated_on_right_p |
| 13120 | && w->cursor.x <= h_margin) | 13196 | && w->cursor.x <= h_margin) |
| 13121 | || (w->hscroll | 13197 | || (w->hscroll |
| 13122 | && (w->cursor.x >= text_area_width - h_margin)))) | 13198 | && (w->cursor.x >= (text_area_width - h_margin |
| 13199 | - x_offset))))) | ||
| 13123 | /* This last condition is needed when moving | 13200 | /* This last condition is needed when moving |
| 13124 | vertically from an hscrolled line to a short line | 13201 | vertically from an hscrolled line to a short line |
| 13125 | that doesn't need to be hscrolled. If we omit | 13202 | that doesn't need to be hscrolled. If we omit |
| @@ -13150,7 +13227,7 @@ hscroll_window_tree (Lisp_Object window) | |||
| 13150 | if (hscl) | 13227 | if (hscl) |
| 13151 | it.first_visible_x = window_hscroll_limited (w, it.f) | 13228 | it.first_visible_x = window_hscroll_limited (w, it.f) |
| 13152 | * FRAME_COLUMN_WIDTH (it.f); | 13229 | * FRAME_COLUMN_WIDTH (it.f); |
| 13153 | it.last_visible_x = INFINITY; | 13230 | it.last_visible_x = DISP_INFINITY; |
| 13154 | move_it_in_display_line_to (&it, pt, -1, MOVE_TO_POS); | 13231 | move_it_in_display_line_to (&it, pt, -1, MOVE_TO_POS); |
| 13155 | /* If the line ends in an overlay string with a newline, | 13232 | /* If the line ends in an overlay string with a newline, |
| 13156 | we might infloop, because displaying the window will | 13233 | we might infloop, because displaying the window will |
| @@ -14796,15 +14873,12 @@ set_cursor_from_row (struct window *w, struct glyph_row *row, | |||
| 14796 | while (glyph > end + 1 | 14873 | while (glyph > end + 1 |
| 14797 | && NILP (glyph->object) | 14874 | && NILP (glyph->object) |
| 14798 | && glyph->charpos < 0) | 14875 | && glyph->charpos < 0) |
| 14799 | { | 14876 | --glyph; |
| 14800 | --glyph; | ||
| 14801 | x -= glyph->pixel_width; | ||
| 14802 | } | ||
| 14803 | if (NILP (glyph->object) && glyph->charpos < 0) | 14877 | if (NILP (glyph->object) && glyph->charpos < 0) |
| 14804 | --glyph; | 14878 | --glyph; |
| 14805 | /* By default, in reversed rows we put the cursor on the | 14879 | /* By default, in reversed rows we put the cursor on the |
| 14806 | rightmost (first in the reading order) glyph. */ | 14880 | rightmost (first in the reading order) glyph. */ |
| 14807 | for (g = end + 1; g < glyph; g++) | 14881 | for (x = 0, g = end + 1; g < glyph; g++) |
| 14808 | x += g->pixel_width; | 14882 | x += g->pixel_width; |
| 14809 | while (end < glyph | 14883 | while (end < glyph |
| 14810 | && NILP ((end + 1)->object) | 14884 | && NILP ((end + 1)->object) |
| @@ -15835,7 +15909,7 @@ compute_window_start_on_continuation_line (struct window *w) | |||
| 15835 | So, we're looking for the display line start with the | 15909 | So, we're looking for the display line start with the |
| 15836 | minimum distance from the old window start. */ | 15910 | minimum distance from the old window start. */ |
| 15837 | pos_before_pt = pos = it.current.pos; | 15911 | pos_before_pt = pos = it.current.pos; |
| 15838 | min_distance = INFINITY; | 15912 | min_distance = DISP_INFINITY; |
| 15839 | while ((distance = eabs (CHARPOS (start_pos) - IT_CHARPOS (it))), | 15913 | while ((distance = eabs (CHARPOS (start_pos) - IT_CHARPOS (it))), |
| 15840 | distance < min_distance) | 15914 | distance < min_distance) |
| 15841 | { | 15915 | { |
| @@ -15941,6 +16015,17 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, | |||
| 15941 | && !windows_or_buffers_changed | 16015 | && !windows_or_buffers_changed |
| 15942 | && !f->cursor_type_changed | 16016 | && !f->cursor_type_changed |
| 15943 | && NILP (Vshow_trailing_whitespace) | 16017 | && NILP (Vshow_trailing_whitespace) |
| 16018 | /* When display-line-numbers is in relative mode, moving point | ||
| 16019 | requires to redraw the entire window. */ | ||
| 16020 | && !EQ (Vdisplay_line_numbers, Qrelative) | ||
| 16021 | && !EQ (Vdisplay_line_numbers, Qvisual) | ||
| 16022 | /* When the current line number should be displayed in a | ||
| 16023 | distinct face, moving point cannot be handled in optimized | ||
| 16024 | way as below. */ | ||
| 16025 | && !(!NILP (Vdisplay_line_numbers) | ||
| 16026 | && NILP (Finternal_lisp_face_equal_p (Qline_number, | ||
| 16027 | Qline_number_current_line, | ||
| 16028 | w->frame))) | ||
| 15944 | /* This code is not used for mini-buffer for the sake of the case | 16029 | /* This code is not used for mini-buffer for the sake of the case |
| 15945 | of redisplaying to replace an echo area message; since in | 16030 | of redisplaying to replace an echo area message; since in |
| 15946 | that case the mini-buffer contents per se are usually | 16031 | that case the mini-buffer contents per se are usually |
| @@ -16788,10 +16873,15 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) | |||
| 16788 | XBUFFER (w->contents)->text->redisplay = false; | 16873 | XBUFFER (w->contents)->text->redisplay = false; |
| 16789 | safe__call1 (true, Vpre_redisplay_function, Fcons (window, Qnil)); | 16874 | safe__call1 (true, Vpre_redisplay_function, Fcons (window, Qnil)); |
| 16790 | 16875 | ||
| 16791 | if (w->redisplay || XBUFFER (w->contents)->text->redisplay) | 16876 | if (w->redisplay || XBUFFER (w->contents)->text->redisplay |
| 16877 | || ((EQ (Vdisplay_line_numbers, Qrelative) | ||
| 16878 | || EQ (Vdisplay_line_numbers, Qvisual)) | ||
| 16879 | && row != MATRIX_FIRST_TEXT_ROW (w->desired_matrix))) | ||
| 16792 | { | 16880 | { |
| 16793 | /* pre-redisplay-function made changes (e.g. move the region) | 16881 | /* Either pre-redisplay-function made changes (e.g. move |
| 16794 | that require another round of redisplay. */ | 16882 | the region), or we moved point in a window that is |
| 16883 | under display-line-numbers = relative mode. We need | ||
| 16884 | another round of redisplay. */ | ||
| 16795 | clear_glyph_matrix (w->desired_matrix); | 16885 | clear_glyph_matrix (w->desired_matrix); |
| 16796 | if (!try_window (window, startp, 0)) | 16886 | if (!try_window (window, startp, 0)) |
| 16797 | goto need_larger_matrices; | 16887 | goto need_larger_matrices; |
| @@ -17592,15 +17682,21 @@ try_window_reusing_current_matrix (struct window *w) | |||
| 17592 | if (w->vscroll || MATRIX_ROW_PARTIALLY_VISIBLE_P (w, start_row)) | 17682 | if (w->vscroll || MATRIX_ROW_PARTIALLY_VISIBLE_P (w, start_row)) |
| 17593 | return false; | 17683 | return false; |
| 17594 | 17684 | ||
| 17685 | /* Clear the desired matrix for the display below. */ | ||
| 17686 | clear_glyph_matrix (w->desired_matrix); | ||
| 17687 | |||
| 17688 | /* Give up if line numbers are being displayed, because reusing the | ||
| 17689 | current matrix might use the wrong width for line-number | ||
| 17690 | display. */ | ||
| 17691 | if (!NILP (Vdisplay_line_numbers)) | ||
| 17692 | return false; | ||
| 17693 | |||
| 17595 | /* The variable new_start now holds the new window start. The old | 17694 | /* The variable new_start now holds the new window start. The old |
| 17596 | start `start' can be determined from the current matrix. */ | 17695 | start `start' can be determined from the current matrix. */ |
| 17597 | SET_TEXT_POS_FROM_MARKER (new_start, w->start); | 17696 | SET_TEXT_POS_FROM_MARKER (new_start, w->start); |
| 17598 | start = start_row->minpos; | 17697 | start = start_row->minpos; |
| 17599 | start_vpos = MATRIX_ROW_VPOS (start_row, w->current_matrix); | 17698 | start_vpos = MATRIX_ROW_VPOS (start_row, w->current_matrix); |
| 17600 | 17699 | ||
| 17601 | /* Clear the desired matrix for the display below. */ | ||
| 17602 | clear_glyph_matrix (w->desired_matrix); | ||
| 17603 | |||
| 17604 | if (CHARPOS (new_start) <= CHARPOS (start)) | 17700 | if (CHARPOS (new_start) <= CHARPOS (start)) |
| 17605 | { | 17701 | { |
| 17606 | /* Don't use this method if the display starts with an ellipsis | 17702 | /* Don't use this method if the display starts with an ellipsis |
| @@ -18423,6 +18519,16 @@ try_window_id (struct window *w) | |||
| 18423 | if (!NILP (BVAR (XBUFFER (w->contents), extra_line_spacing))) | 18519 | if (!NILP (BVAR (XBUFFER (w->contents), extra_line_spacing))) |
| 18424 | GIVE_UP (23); | 18520 | GIVE_UP (23); |
| 18425 | 18521 | ||
| 18522 | /* Give up if display-line-numbers is in relative mode, or when the | ||
| 18523 | current line's number needs to be displayed in a distinct face. */ | ||
| 18524 | if (EQ (Vdisplay_line_numbers, Qrelative) | ||
| 18525 | || EQ (Vdisplay_line_numbers, Qvisual) | ||
| 18526 | || (!NILP (Vdisplay_line_numbers) | ||
| 18527 | && NILP (Finternal_lisp_face_equal_p (Qline_number, | ||
| 18528 | Qline_number_current_line, | ||
| 18529 | w->frame)))) | ||
| 18530 | GIVE_UP (24); | ||
| 18531 | |||
| 18426 | /* Make sure beg_unchanged and end_unchanged are up to date. Do it | 18532 | /* Make sure beg_unchanged and end_unchanged are up to date. Do it |
| 18427 | only if buffer has really changed. The reason is that the gap is | 18533 | only if buffer has really changed. The reason is that the gap is |
| 18428 | initially at Z for freshly visited files. The code below would | 18534 | initially at Z for freshly visited files. The code below would |
| @@ -19070,7 +19176,7 @@ dump_glyph (struct glyph_row *row, struct glyph *glyph, int area) | |||
| 19070 | || glyph->type == GLYPHLESS_GLYPH) | 19176 | || glyph->type == GLYPHLESS_GLYPH) |
| 19071 | { | 19177 | { |
| 19072 | fprintf (stderr, | 19178 | fprintf (stderr, |
| 19073 | " %5"pD"d %c %9"pI"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n", | 19179 | " %5"pD"d %c %9"pD"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n", |
| 19074 | glyph - row->glyphs[TEXT_AREA], | 19180 | glyph - row->glyphs[TEXT_AREA], |
| 19075 | (glyph->type == CHAR_GLYPH | 19181 | (glyph->type == CHAR_GLYPH |
| 19076 | ? 'C' | 19182 | ? 'C' |
| @@ -19095,7 +19201,7 @@ dump_glyph (struct glyph_row *row, struct glyph *glyph, int area) | |||
| 19095 | else if (glyph->type == STRETCH_GLYPH) | 19201 | else if (glyph->type == STRETCH_GLYPH) |
| 19096 | { | 19202 | { |
| 19097 | fprintf (stderr, | 19203 | fprintf (stderr, |
| 19098 | " %5"pD"d %c %9"pI"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n", | 19204 | " %5"pD"d %c %9"pD"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n", |
| 19099 | glyph - row->glyphs[TEXT_AREA], | 19205 | glyph - row->glyphs[TEXT_AREA], |
| 19100 | 'S', | 19206 | 'S', |
| 19101 | glyph->charpos, | 19207 | glyph->charpos, |
| @@ -19116,7 +19222,7 @@ dump_glyph (struct glyph_row *row, struct glyph *glyph, int area) | |||
| 19116 | else if (glyph->type == IMAGE_GLYPH) | 19222 | else if (glyph->type == IMAGE_GLYPH) |
| 19117 | { | 19223 | { |
| 19118 | fprintf (stderr, | 19224 | fprintf (stderr, |
| 19119 | " %5"pD"d %c %9"pI"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n", | 19225 | " %5"pD"d %c %9"pD"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n", |
| 19120 | glyph - row->glyphs[TEXT_AREA], | 19226 | glyph - row->glyphs[TEXT_AREA], |
| 19121 | 'I', | 19227 | 'I', |
| 19122 | glyph->charpos, | 19228 | glyph->charpos, |
| @@ -19137,7 +19243,7 @@ dump_glyph (struct glyph_row *row, struct glyph *glyph, int area) | |||
| 19137 | else if (glyph->type == COMPOSITE_GLYPH) | 19243 | else if (glyph->type == COMPOSITE_GLYPH) |
| 19138 | { | 19244 | { |
| 19139 | fprintf (stderr, | 19245 | fprintf (stderr, |
| 19140 | " %5"pD"d %c %9"pI"d %c %3d 0x%06x", | 19246 | " %5"pD"d %c %9"pD"d %c %3d 0x%06x", |
| 19141 | glyph - row->glyphs[TEXT_AREA], | 19247 | glyph - row->glyphs[TEXT_AREA], |
| 19142 | '+', | 19248 | '+', |
| 19143 | glyph->charpos, | 19249 | glyph->charpos, |
| @@ -19198,7 +19304,7 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs) | |||
| 19198 | fprintf (stderr, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n"); | 19304 | fprintf (stderr, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n"); |
| 19199 | fprintf (stderr, "==============================================================================\n"); | 19305 | fprintf (stderr, "==============================================================================\n"); |
| 19200 | 19306 | ||
| 19201 | fprintf (stderr, "%3d %9"pI"d %9"pI"d %4d %1.1d%1.1d%1.1d%1.1d\ | 19307 | fprintf (stderr, "%3d %9"pD"d %9"pD"d %4d %1.1d%1.1d%1.1d%1.1d\ |
| 19202 | %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n", | 19308 | %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n", |
| 19203 | vpos, | 19309 | vpos, |
| 19204 | MATRIX_ROW_START_CHARPOS (row), | 19310 | MATRIX_ROW_START_CHARPOS (row), |
| @@ -19227,7 +19333,7 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs) | |||
| 19227 | fprintf (stderr, " %9"pD"d %9"pD"d\t%5d\n", row->start.overlay_string_index, | 19333 | fprintf (stderr, " %9"pD"d %9"pD"d\t%5d\n", row->start.overlay_string_index, |
| 19228 | row->end.overlay_string_index, | 19334 | row->end.overlay_string_index, |
| 19229 | row->continuation_lines_width); | 19335 | row->continuation_lines_width); |
| 19230 | fprintf (stderr, " %9"pI"d %9"pI"d\n", | 19336 | fprintf (stderr, " %9"pD"d %9"pD"d\n", |
| 19231 | CHARPOS (row->start.string_pos), | 19337 | CHARPOS (row->start.string_pos), |
| 19232 | CHARPOS (row->end.string_pos)); | 19338 | CHARPOS (row->end.string_pos)); |
| 19233 | fprintf (stderr, " %9d %9d\n", row->start.dpvec_index, | 19339 | fprintf (stderr, " %9d %9d\n", row->start.dpvec_index, |
| @@ -19304,7 +19410,7 @@ with numeric argument, its value is passed as the GLYPHS flag. */) | |||
| 19304 | struct window *w = XWINDOW (selected_window); | 19410 | struct window *w = XWINDOW (selected_window); |
| 19305 | struct buffer *buffer = XBUFFER (w->contents); | 19411 | struct buffer *buffer = XBUFFER (w->contents); |
| 19306 | 19412 | ||
| 19307 | fprintf (stderr, "PT = %"pI"d, BEGV = %"pI"d. ZV = %"pI"d\n", | 19413 | fprintf (stderr, "PT = %"pD"d, BEGV = %"pD"d. ZV = %"pD"d\n", |
| 19308 | BUF_PT (buffer), BUF_BEGV (buffer), BUF_ZV (buffer)); | 19414 | BUF_PT (buffer), BUF_BEGV (buffer), BUF_ZV (buffer)); |
| 19309 | fprintf (stderr, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n", | 19415 | fprintf (stderr, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n", |
| 19310 | w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos); | 19416 | w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos); |
| @@ -20669,6 +20775,366 @@ find_row_edges (struct it *it, struct glyph_row *row, | |||
| 20669 | row->maxpos = it->current.pos; | 20775 | row->maxpos = it->current.pos; |
| 20670 | } | 20776 | } |
| 20671 | 20777 | ||
| 20778 | /* Like display_count_lines, but capable of counting outside of the | ||
| 20779 | current narrowed region. */ | ||
| 20780 | static ptrdiff_t | ||
| 20781 | display_count_lines_logically (ptrdiff_t start_byte, ptrdiff_t limit_byte, | ||
| 20782 | ptrdiff_t count, ptrdiff_t *byte_pos_ptr) | ||
| 20783 | { | ||
| 20784 | if (!display_line_numbers_widen || (BEGV == BEG && ZV == Z)) | ||
| 20785 | return display_count_lines (start_byte, limit_byte, count, byte_pos_ptr); | ||
| 20786 | |||
| 20787 | ptrdiff_t val; | ||
| 20788 | ptrdiff_t pdl_count = SPECPDL_INDEX (); | ||
| 20789 | record_unwind_protect (save_restriction_restore, save_restriction_save ()); | ||
| 20790 | Fwiden (); | ||
| 20791 | val = display_count_lines (start_byte, limit_byte, count, byte_pos_ptr); | ||
| 20792 | unbind_to (pdl_count, Qnil); | ||
| 20793 | return val; | ||
| 20794 | } | ||
| 20795 | |||
| 20796 | /* Count the number of screen lines in window IT->w between character | ||
| 20797 | position IT_CHARPOS(*IT) and the line showing that window's point. */ | ||
| 20798 | static ptrdiff_t | ||
| 20799 | display_count_lines_visually (struct it *it) | ||
| 20800 | { | ||
| 20801 | struct it tem_it; | ||
| 20802 | ptrdiff_t to; | ||
| 20803 | struct text_pos from; | ||
| 20804 | |||
| 20805 | /* If we already calculated a relative line number, use that. This | ||
| 20806 | trick relies on the fact that visual lines (a.k.a. "glyph rows") | ||
| 20807 | are laid out sequentially, one by one, for each sequence of calls | ||
| 20808 | to display_line or other similar function that follows a call to | ||
| 20809 | init_iterator. */ | ||
| 20810 | if (it->lnum_bytepos > 0) | ||
| 20811 | return it->lnum + 1; | ||
| 20812 | else | ||
| 20813 | { | ||
| 20814 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 20815 | |||
| 20816 | if (IT_CHARPOS (*it) <= PT) | ||
| 20817 | { | ||
| 20818 | from = it->current.pos; | ||
| 20819 | to = PT; | ||
| 20820 | } | ||
| 20821 | else | ||
| 20822 | { | ||
| 20823 | SET_TEXT_POS (from, PT, PT_BYTE); | ||
| 20824 | to = IT_CHARPOS (*it); | ||
| 20825 | } | ||
| 20826 | start_display (&tem_it, it->w, from); | ||
| 20827 | /* Need to disable visual mode temporarily, since otherwise the | ||
| 20828 | call to move_it_to will cause infinite recursion. */ | ||
| 20829 | specbind (Qdisplay_line_numbers, Qrelative); | ||
| 20830 | /* Some redisplay optimizations could invoke us very far from | ||
| 20831 | PT, which will make the caller painfully slow. There should | ||
| 20832 | be no need to go too far beyond the window's bottom, as any | ||
| 20833 | such optimization will fail to show point anyway. */ | ||
| 20834 | move_it_to (&tem_it, to, -1, | ||
| 20835 | tem_it.last_visible_y | ||
| 20836 | + (SCROLL_LIMIT + 10) * FRAME_LINE_HEIGHT (tem_it.f), | ||
| 20837 | -1, MOVE_TO_POS | MOVE_TO_Y); | ||
| 20838 | unbind_to (count, Qnil); | ||
| 20839 | return IT_CHARPOS (*it) <= PT ? -tem_it.vpos : tem_it.vpos; | ||
| 20840 | } | ||
| 20841 | } | ||
| 20842 | |||
| 20843 | /* Produce the line-number glyphs for the current glyph_row. If | ||
| 20844 | IT->glyph_row is non-NULL, populate the row with the produced | ||
| 20845 | glyphs. */ | ||
| 20846 | static void | ||
| 20847 | maybe_produce_line_number (struct it *it) | ||
| 20848 | { | ||
| 20849 | ptrdiff_t last_line = it->lnum; | ||
| 20850 | ptrdiff_t start_from, bytepos; | ||
| 20851 | ptrdiff_t this_line; | ||
| 20852 | bool first_time = false; | ||
| 20853 | ptrdiff_t beg_byte = display_line_numbers_widen ? BEG_BYTE : BEGV_BYTE; | ||
| 20854 | ptrdiff_t z_byte = display_line_numbers_widen ? Z_BYTE : ZV_BYTE; | ||
| 20855 | void *itdata = bidi_shelve_cache (); | ||
| 20856 | |||
| 20857 | if (EQ (Vdisplay_line_numbers, Qvisual)) | ||
| 20858 | this_line = display_count_lines_visually (it); | ||
| 20859 | else | ||
| 20860 | { | ||
| 20861 | if (!last_line) | ||
| 20862 | { | ||
| 20863 | /* If possible, reuse data cached by line-number-mode. */ | ||
| 20864 | if (it->w->base_line_number > 0 | ||
| 20865 | && it->w->base_line_pos > 0 | ||
| 20866 | && it->w->base_line_pos <= IT_CHARPOS (*it) | ||
| 20867 | /* line-number-mode always displays narrowed line | ||
| 20868 | numbers, so we cannot use its data if the user wants | ||
| 20869 | line numbers that disregard narrowing. */ | ||
| 20870 | && !(display_line_numbers_widen | ||
| 20871 | && (BEG_BYTE != BEGV_BYTE || Z_BYTE != ZV_BYTE))) | ||
| 20872 | { | ||
| 20873 | start_from = CHAR_TO_BYTE (it->w->base_line_pos); | ||
| 20874 | last_line = it->w->base_line_number - 1; | ||
| 20875 | } | ||
| 20876 | else | ||
| 20877 | start_from = beg_byte; | ||
| 20878 | if (!it->lnum_bytepos) | ||
| 20879 | first_time = true; | ||
| 20880 | } | ||
| 20881 | else | ||
| 20882 | start_from = it->lnum_bytepos; | ||
| 20883 | |||
| 20884 | /* Paranoia: what if someone changes the narrowing since the | ||
| 20885 | last time display_line was called? Shouldn't really happen, | ||
| 20886 | but who knows what some crazy Lisp invoked by :eval could do? */ | ||
| 20887 | if (!(beg_byte <= start_from && start_from <= z_byte)) | ||
| 20888 | { | ||
| 20889 | last_line = 0; | ||
| 20890 | start_from = beg_byte; | ||
| 20891 | } | ||
| 20892 | |||
| 20893 | this_line = | ||
| 20894 | last_line + display_count_lines_logically (start_from, | ||
| 20895 | IT_BYTEPOS (*it), | ||
| 20896 | IT_CHARPOS (*it), &bytepos); | ||
| 20897 | eassert (this_line > 0 || (this_line == 0 && start_from == beg_byte)); | ||
| 20898 | eassert (bytepos == IT_BYTEPOS (*it)); | ||
| 20899 | } | ||
| 20900 | |||
| 20901 | /* Record the line number information. */ | ||
| 20902 | if (this_line != last_line || !it->lnum_bytepos) | ||
| 20903 | { | ||
| 20904 | it->lnum = this_line; | ||
| 20905 | it->lnum_bytepos = IT_BYTEPOS (*it); | ||
| 20906 | } | ||
| 20907 | |||
| 20908 | /* Produce the glyphs for the line number. */ | ||
| 20909 | struct it tem_it; | ||
| 20910 | char lnum_buf[INT_STRLEN_BOUND (ptrdiff_t) + 1]; | ||
| 20911 | bool beyond_zv = IT_BYTEPOS (*it) >= ZV_BYTE ? true : false; | ||
| 20912 | ptrdiff_t lnum_offset = -1; /* to produce 1-based line numbers */ | ||
| 20913 | int lnum_face_id = merge_faces (it->f, Qline_number, 0, DEFAULT_FACE_ID); | ||
| 20914 | int current_lnum_face_id | ||
| 20915 | = merge_faces (it->f, Qline_number_current_line, 0, DEFAULT_FACE_ID); | ||
| 20916 | /* Compute point's line number if needed. */ | ||
| 20917 | if ((EQ (Vdisplay_line_numbers, Qrelative) | ||
| 20918 | || EQ (Vdisplay_line_numbers, Qvisual) | ||
| 20919 | || lnum_face_id != current_lnum_face_id) | ||
| 20920 | && !it->pt_lnum) | ||
| 20921 | { | ||
| 20922 | ptrdiff_t ignored; | ||
| 20923 | if (PT_BYTE > it->lnum_bytepos && !EQ (Vdisplay_line_numbers, Qvisual)) | ||
| 20924 | it->pt_lnum = | ||
| 20925 | this_line + display_count_lines_logically (it->lnum_bytepos, PT_BYTE, | ||
| 20926 | PT, &ignored); | ||
| 20927 | else | ||
| 20928 | it->pt_lnum = display_count_lines_logically (beg_byte, PT_BYTE, PT, | ||
| 20929 | &ignored); | ||
| 20930 | } | ||
| 20931 | /* Compute the required width if needed. */ | ||
| 20932 | if (!it->lnum_width) | ||
| 20933 | { | ||
| 20934 | if (NATNUMP (Vdisplay_line_numbers_width)) | ||
| 20935 | it->lnum_width = XFASTINT (Vdisplay_line_numbers_width); | ||
| 20936 | |||
| 20937 | /* Max line number to be displayed cannot be more than the one | ||
| 20938 | corresponding to the last row of the desired matrix. */ | ||
| 20939 | ptrdiff_t max_lnum; | ||
| 20940 | |||
| 20941 | if (NILP (Vdisplay_line_numbers_current_absolute) | ||
| 20942 | && (EQ (Vdisplay_line_numbers, Qrelative) | ||
| 20943 | || EQ (Vdisplay_line_numbers, Qvisual))) | ||
| 20944 | /* We subtract one more because the current line is always | ||
| 20945 | zero in this mode. */ | ||
| 20946 | max_lnum = it->w->desired_matrix->nrows - 2; | ||
| 20947 | else if (EQ (Vdisplay_line_numbers, Qvisual)) | ||
| 20948 | max_lnum = it->pt_lnum + it->w->desired_matrix->nrows - 1; | ||
| 20949 | else | ||
| 20950 | max_lnum = this_line + it->w->desired_matrix->nrows - 1 - it->vpos; | ||
| 20951 | max_lnum = max (1, max_lnum); | ||
| 20952 | it->lnum_width = max (it->lnum_width, log10 (max_lnum) + 1); | ||
| 20953 | eassert (it->lnum_width > 0); | ||
| 20954 | } | ||
| 20955 | if (EQ (Vdisplay_line_numbers, Qrelative)) | ||
| 20956 | lnum_offset = it->pt_lnum; | ||
| 20957 | else if (EQ (Vdisplay_line_numbers, Qvisual)) | ||
| 20958 | lnum_offset = 0; | ||
| 20959 | |||
| 20960 | /* Under 'relative', display the absolute line number for the | ||
| 20961 | current line, unless the user requests otherwise. */ | ||
| 20962 | ptrdiff_t lnum_to_display = eabs (this_line - lnum_offset); | ||
| 20963 | if ((EQ (Vdisplay_line_numbers, Qrelative) | ||
| 20964 | || EQ (Vdisplay_line_numbers, Qvisual)) | ||
| 20965 | && lnum_to_display == 0 | ||
| 20966 | && !NILP (Vdisplay_line_numbers_current_absolute)) | ||
| 20967 | lnum_to_display = it->pt_lnum + 1; | ||
| 20968 | /* In L2R rows we need to append the blank separator, in R2L | ||
| 20969 | rows we need to prepend it. But this function is usually | ||
| 20970 | called when no display elements were produced from the | ||
| 20971 | following line, so the paragraph direction might be unknown. | ||
| 20972 | Therefore we cheat and add 2 blanks, one on either side. */ | ||
| 20973 | pint2str (lnum_buf, it->lnum_width + 1, lnum_to_display); | ||
| 20974 | strcat (lnum_buf, " "); | ||
| 20975 | |||
| 20976 | /* Setup for producing the glyphs. */ | ||
| 20977 | init_iterator (&tem_it, it->w, -1, -1, &scratch_glyph_row, | ||
| 20978 | /* FIXME: Use specialized face. */ | ||
| 20979 | DEFAULT_FACE_ID); | ||
| 20980 | scratch_glyph_row.reversed_p = false; | ||
| 20981 | scratch_glyph_row.used[TEXT_AREA] = 0; | ||
| 20982 | SET_TEXT_POS (tem_it.position, 0, 0); | ||
| 20983 | tem_it.avoid_cursor_p = true; | ||
| 20984 | tem_it.bidi_p = true; | ||
| 20985 | tem_it.bidi_it.type = WEAK_EN; | ||
| 20986 | /* According to UAX#9, EN goes up 2 levels in L2R paragraph and | ||
| 20987 | 1 level in R2L paragraphs. Emulate that, assuming we are in | ||
| 20988 | an L2R paragraph. */ | ||
| 20989 | tem_it.bidi_it.resolved_level = 2; | ||
| 20990 | |||
| 20991 | /* Produce glyphs for the line number in a scratch glyph_row. */ | ||
| 20992 | int n_glyphs_before; | ||
| 20993 | for (const char *p = lnum_buf; *p; p++) | ||
| 20994 | { | ||
| 20995 | /* For continuation lines and lines after ZV, instead of a line | ||
| 20996 | number, produce a blank prefix of the same width. Use the | ||
| 20997 | default face for the blank field beyond ZV. */ | ||
| 20998 | if (beyond_zv) | ||
| 20999 | tem_it.face_id = it->base_face_id; | ||
| 21000 | else if (lnum_face_id != current_lnum_face_id | ||
| 21001 | && (EQ (Vdisplay_line_numbers, Qvisual) | ||
| 21002 | ? this_line == 0 | ||
| 21003 | : this_line == it->pt_lnum)) | ||
| 21004 | tem_it.face_id = current_lnum_face_id; | ||
| 21005 | else | ||
| 21006 | tem_it.face_id = lnum_face_id; | ||
| 21007 | if (beyond_zv | ||
| 21008 | /* Don't display the same line number more than once. */ | ||
| 21009 | || (!EQ (Vdisplay_line_numbers, Qvisual) | ||
| 21010 | && (it->continuation_lines_width > 0 | ||
| 21011 | || (this_line == last_line && !first_time)))) | ||
| 21012 | tem_it.c = tem_it.char_to_display = ' '; | ||
| 21013 | else | ||
| 21014 | tem_it.c = tem_it.char_to_display = *p; | ||
| 21015 | tem_it.len = 1; | ||
| 21016 | n_glyphs_before = scratch_glyph_row.used[TEXT_AREA]; | ||
| 21017 | /* Make sure these glyphs will have a "position" of -1. */ | ||
| 21018 | SET_TEXT_POS (tem_it.position, -1, -1); | ||
| 21019 | PRODUCE_GLYPHS (&tem_it); | ||
| 21020 | |||
| 21021 | /* Stop producing glyphs if we don't have enough space on | ||
| 21022 | this line. FIXME: should we refrain from producing the | ||
| 21023 | line number at all in that case? */ | ||
| 21024 | if (tem_it.current_x > tem_it.last_visible_x) | ||
| 21025 | { | ||
| 21026 | scratch_glyph_row.used[TEXT_AREA] = n_glyphs_before; | ||
| 21027 | break; | ||
| 21028 | } | ||
| 21029 | } | ||
| 21030 | |||
| 21031 | /* Record the width in pixels we need for the line number display. */ | ||
| 21032 | it->lnum_pixel_width = tem_it.current_x; | ||
| 21033 | /* Copy the produced glyphs into IT's glyph_row. */ | ||
| 21034 | struct glyph *g = scratch_glyph_row.glyphs[TEXT_AREA]; | ||
| 21035 | struct glyph *e = g + scratch_glyph_row.used[TEXT_AREA]; | ||
| 21036 | struct glyph *p = it->glyph_row ? it->glyph_row->glyphs[TEXT_AREA] : NULL; | ||
| 21037 | short *u = it->glyph_row ? &it->glyph_row->used[TEXT_AREA] : NULL; | ||
| 21038 | |||
| 21039 | eassert (it->glyph_row == NULL || it->glyph_row->used[TEXT_AREA] == 0); | ||
| 21040 | |||
| 21041 | for ( ; g < e; g++) | ||
| 21042 | { | ||
| 21043 | it->current_x += g->pixel_width; | ||
| 21044 | /* The following is important when this function is called | ||
| 21045 | from move_it_in_display_line_to: HPOS is incremented only | ||
| 21046 | when we are in the visible portion of the glyph row. */ | ||
| 21047 | if (it->current_x > it->first_visible_x) | ||
| 21048 | it->hpos++; | ||
| 21049 | if (p) | ||
| 21050 | { | ||
| 21051 | *p++ = *g; | ||
| 21052 | (*u)++; | ||
| 21053 | } | ||
| 21054 | } | ||
| 21055 | |||
| 21056 | /* Update IT's metrics due to glyphs produced for line numbers. */ | ||
| 21057 | if (it->glyph_row) | ||
| 21058 | { | ||
| 21059 | struct glyph_row *row = it->glyph_row; | ||
| 21060 | |||
| 21061 | it->max_ascent = max (row->ascent, tem_it.max_ascent); | ||
| 21062 | it->max_descent = max (row->height - row->ascent, tem_it.max_descent); | ||
| 21063 | it->max_phys_ascent = max (row->phys_ascent, tem_it.max_phys_ascent); | ||
| 21064 | it->max_phys_descent = max (row->phys_height - row->phys_ascent, | ||
| 21065 | tem_it.max_phys_descent); | ||
| 21066 | } | ||
| 21067 | else | ||
| 21068 | { | ||
| 21069 | it->max_ascent = max (it->max_ascent, tem_it.max_ascent); | ||
| 21070 | it->max_descent = max (it->max_descent, tem_it.max_descent); | ||
| 21071 | it->max_phys_ascent = max (it->max_phys_ascent, tem_it.max_phys_ascent); | ||
| 21072 | it->max_phys_descent = max (it->max_phys_descent, tem_it.max_phys_descent); | ||
| 21073 | } | ||
| 21074 | |||
| 21075 | bidi_unshelve_cache (itdata, false); | ||
| 21076 | } | ||
| 21077 | |||
| 21078 | /* Return true if this glyph row needs a line number to be produced | ||
| 21079 | for it. */ | ||
| 21080 | static bool | ||
| 21081 | should_produce_line_number (struct it *it) | ||
| 21082 | { | ||
| 21083 | if (NILP (Vdisplay_line_numbers)) | ||
| 21084 | return false; | ||
| 21085 | |||
| 21086 | /* Don't display line numbers in minibuffer windows. */ | ||
| 21087 | if (MINI_WINDOW_P (it->w)) | ||
| 21088 | return false; | ||
| 21089 | |||
| 21090 | #ifdef HAVE_WINDOW_SYSTEM | ||
| 21091 | /* Don't display line number in tooltip frames. */ | ||
| 21092 | if (FRAMEP (tip_frame) && EQ (WINDOW_FRAME (it->w), tip_frame)) | ||
| 21093 | return false; | ||
| 21094 | #endif | ||
| 21095 | |||
| 21096 | /* If the character at current position has a non-nil special | ||
| 21097 | property, disable line numbers for this row. This is for | ||
| 21098 | packages such as company-mode, which need this for their tricky | ||
| 21099 | layout, where line numbers get in the way. */ | ||
| 21100 | Lisp_Object val = Fget_char_property (make_number (IT_CHARPOS (*it)), | ||
| 21101 | Qdisplay_line_numbers_disable, | ||
| 21102 | it->window); | ||
| 21103 | /* For ZV, we need to also look in empty overlays at that point, | ||
| 21104 | because get-char-property always returns nil for ZV, except if | ||
| 21105 | the property is in 'default-text-properties'. */ | ||
| 21106 | if (NILP (val) && IT_CHARPOS (*it) >= ZV) | ||
| 21107 | val = disable_line_numbers_overlay_at_eob (); | ||
| 21108 | return NILP (val) ? true : false; | ||
| 21109 | } | ||
| 21110 | |||
| 21111 | /* Return true if ROW has no glyphs except those inserted by the | ||
| 21112 | display engine. This is needed for indicate-empty-lines and | ||
| 21113 | similar features when the glyph row starts with glyphs which didn't | ||
| 21114 | come from buffer or string. */ | ||
| 21115 | static bool | ||
| 21116 | row_text_area_empty (struct glyph_row *row) | ||
| 21117 | { | ||
| 21118 | if (!row->reversed_p) | ||
| 21119 | { | ||
| 21120 | for (struct glyph *g = row->glyphs[TEXT_AREA]; | ||
| 21121 | g < row->glyphs[TEXT_AREA] + row->used[TEXT_AREA]; | ||
| 21122 | g++) | ||
| 21123 | if (!NILP (g->object) || g->charpos > 0) | ||
| 21124 | return false; | ||
| 21125 | } | ||
| 21126 | else | ||
| 21127 | { | ||
| 21128 | for (struct glyph *g = row->glyphs[TEXT_AREA] + row->used[TEXT_AREA] - 1; | ||
| 21129 | g > row->glyphs[TEXT_AREA]; | ||
| 21130 | g--) | ||
| 21131 | if (!NILP ((g - 1)->object) || (g - 1)->charpos > 0) | ||
| 21132 | return false; | ||
| 21133 | } | ||
| 21134 | |||
| 21135 | return true; | ||
| 21136 | } | ||
| 21137 | |||
| 20672 | /* Construct the glyph row IT->glyph_row in the desired matrix of | 21138 | /* Construct the glyph row IT->glyph_row in the desired matrix of |
| 20673 | IT->w from text at the current position of IT. See dispextern.h | 21139 | IT->w from text at the current position of IT. See dispextern.h |
| 20674 | for an overview of struct it. Value is true if | 21140 | for an overview of struct it. Value is true if |
| @@ -20739,6 +21205,8 @@ display_line (struct it *it, int cursor_vpos) | |||
| 20739 | (window_hscroll_limited (it->w, it->f) - it->w->min_hscroll) | 21205 | (window_hscroll_limited (it->w, it->f) - it->w->min_hscroll) |
| 20740 | * FRAME_COLUMN_WIDTH (it->f); | 21206 | * FRAME_COLUMN_WIDTH (it->f); |
| 20741 | 21207 | ||
| 21208 | bool line_number_needed = should_produce_line_number (it); | ||
| 21209 | |||
| 20742 | /* Move over display elements that are not visible because we are | 21210 | /* Move over display elements that are not visible because we are |
| 20743 | hscrolled. This may stop at an x-position < first_visible_x | 21211 | hscrolled. This may stop at an x-position < first_visible_x |
| 20744 | if the first glyph is partially visible or if we hit a line end. */ | 21212 | if the first glyph is partially visible or if we hit a line end. */ |
| @@ -20774,9 +21242,17 @@ display_line (struct it *it, int cursor_vpos) | |||
| 20774 | are hscrolled to the left of the left edge of the window. */ | 21242 | are hscrolled to the left of the left edge of the window. */ |
| 20775 | min_pos = CHARPOS (this_line_min_pos); | 21243 | min_pos = CHARPOS (this_line_min_pos); |
| 20776 | min_bpos = BYTEPOS (this_line_min_pos); | 21244 | min_bpos = BYTEPOS (this_line_min_pos); |
| 21245 | |||
| 21246 | /* Produce line number, if needed. */ | ||
| 21247 | if (line_number_needed) | ||
| 21248 | maybe_produce_line_number (it); | ||
| 20777 | } | 21249 | } |
| 20778 | else if (it->area == TEXT_AREA) | 21250 | else if (it->area == TEXT_AREA) |
| 20779 | { | 21251 | { |
| 21252 | /* Line numbers should precede the line-prefix or wrap-prefix. */ | ||
| 21253 | if (line_number_needed) | ||
| 21254 | maybe_produce_line_number (it); | ||
| 21255 | |||
| 20780 | /* We only do this when not calling move_it_in_display_line_to | 21256 | /* We only do this when not calling move_it_in_display_line_to |
| 20781 | above, because that function calls itself handle_line_prefix. */ | 21257 | above, because that function calls itself handle_line_prefix. */ |
| 20782 | handle_line_prefix (it); | 21258 | handle_line_prefix (it); |
| @@ -20838,6 +21314,7 @@ display_line (struct it *it, int cursor_vpos) | |||
| 20838 | buffer reached. */ | 21314 | buffer reached. */ |
| 20839 | if (!get_next_display_element (it)) | 21315 | if (!get_next_display_element (it)) |
| 20840 | { | 21316 | { |
| 21317 | bool row_has_glyphs = false; | ||
| 20841 | /* Maybe add a space at the end of this line that is used to | 21318 | /* Maybe add a space at the end of this line that is used to |
| 20842 | display the cursor there under X. Set the charpos of the | 21319 | display the cursor there under X. Set the charpos of the |
| 20843 | first glyph of blank lines not corresponding to any text | 21320 | first glyph of blank lines not corresponding to any text |
| @@ -20846,14 +21323,17 @@ display_line (struct it *it, int cursor_vpos) | |||
| 20846 | row->exact_window_width_line_p = true; | 21323 | row->exact_window_width_line_p = true; |
| 20847 | else if ((append_space_for_newline (it, true) | 21324 | else if ((append_space_for_newline (it, true) |
| 20848 | && row->used[TEXT_AREA] == 1) | 21325 | && row->used[TEXT_AREA] == 1) |
| 20849 | || row->used[TEXT_AREA] == 0) | 21326 | || row->used[TEXT_AREA] == 0 |
| 21327 | || (row_has_glyphs = row_text_area_empty (row))) | ||
| 20850 | { | 21328 | { |
| 20851 | row->glyphs[TEXT_AREA]->charpos = -1; | 21329 | row->glyphs[TEXT_AREA]->charpos = -1; |
| 20852 | row->displays_text_p = false; | 21330 | /* Don't reset the displays_text_p flag if we are |
| 21331 | displaying line numbers or line-prefix. */ | ||
| 21332 | if (!row_has_glyphs) | ||
| 21333 | row->displays_text_p = false; | ||
| 20853 | 21334 | ||
| 20854 | if (!NILP (BVAR (XBUFFER (it->w->contents), indicate_empty_lines)) | 21335 | if (!NILP (BVAR (XBUFFER (it->w->contents), indicate_empty_lines)) |
| 20855 | && (!MINI_WINDOW_P (it->w) | 21336 | && (!MINI_WINDOW_P (it->w))) |
| 20856 | || (minibuf_level && EQ (it->window, minibuf_window)))) | ||
| 20857 | row->indicate_empty_line_p = true; | 21337 | row->indicate_empty_line_p = true; |
| 20858 | } | 21338 | } |
| 20859 | 21339 | ||
| @@ -20935,6 +21415,10 @@ display_line (struct it *it, int cursor_vpos) | |||
| 20935 | process the prefix now. */ | 21415 | process the prefix now. */ |
| 20936 | if (it->area == TEXT_AREA && pending_handle_line_prefix) | 21416 | if (it->area == TEXT_AREA && pending_handle_line_prefix) |
| 20937 | { | 21417 | { |
| 21418 | /* Line numbers should precede the line-prefix or wrap-prefix. */ | ||
| 21419 | if (line_number_needed) | ||
| 21420 | maybe_produce_line_number (it); | ||
| 21421 | |||
| 20938 | pending_handle_line_prefix = false; | 21422 | pending_handle_line_prefix = false; |
| 20939 | handle_line_prefix (it); | 21423 | handle_line_prefix (it); |
| 20940 | } | 21424 | } |
| @@ -22006,7 +22490,7 @@ Value is the new character position of point. */) | |||
| 22006 | reach point, in order to start from its X coordinate. So we | 22490 | reach point, in order to start from its X coordinate. So we |
| 22007 | need to disregard the window's horizontal extent in that case. */ | 22491 | need to disregard the window's horizontal extent in that case. */ |
| 22008 | if (it.line_wrap == TRUNCATE) | 22492 | if (it.line_wrap == TRUNCATE) |
| 22009 | it.last_visible_x = INFINITY; | 22493 | it.last_visible_x = DISP_INFINITY; |
| 22010 | 22494 | ||
| 22011 | if (it.cmp_it.id < 0 | 22495 | if (it.cmp_it.id < 0 |
| 22012 | && it.method == GET_FROM_STRING | 22496 | && it.method == GET_FROM_STRING |
| @@ -22099,7 +22583,7 @@ Value is the new character position of point. */) | |||
| 22099 | { | 22583 | { |
| 22100 | start_display (&it, w, pt); | 22584 | start_display (&it, w, pt); |
| 22101 | if (it.line_wrap == TRUNCATE) | 22585 | if (it.line_wrap == TRUNCATE) |
| 22102 | it.last_visible_x = INFINITY; | 22586 | it.last_visible_x = DISP_INFINITY; |
| 22103 | reseat_at_previous_visible_line_start (&it); | 22587 | reseat_at_previous_visible_line_start (&it); |
| 22104 | it.current_x = it.current_y = it.hpos = 0; | 22588 | it.current_x = it.current_y = it.hpos = 0; |
| 22105 | if (pt_vpos != 0) | 22589 | if (pt_vpos != 0) |
| @@ -22859,7 +23343,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision, | |||
| 22859 | props = oprops; | 23343 | props = oprops; |
| 22860 | } | 23344 | } |
| 22861 | 23345 | ||
| 22862 | aelt = Fassoc (elt, mode_line_proptrans_alist); | 23346 | aelt = Fassoc (elt, mode_line_proptrans_alist, Qnil); |
| 22863 | if (! NILP (aelt) && !NILP (Fequal (props, XCDR (aelt)))) | 23347 | if (! NILP (aelt) && !NILP (Fequal (props, XCDR (aelt)))) |
| 22864 | { | 23348 | { |
| 22865 | /* AELT is what we want. Move it to the front | 23349 | /* AELT is what we want. Move it to the front |
| @@ -27616,6 +28100,10 @@ x_produce_glyphs (struct it *it) | |||
| 27616 | { | 28100 | { |
| 27617 | int tab_width = it->tab_width * font->space_width; | 28101 | int tab_width = it->tab_width * font->space_width; |
| 27618 | int x = it->current_x + it->continuation_lines_width; | 28102 | int x = it->current_x + it->continuation_lines_width; |
| 28103 | int x0 = x; | ||
| 28104 | /* Adjust for line numbers, if needed. */ | ||
| 28105 | if (!NILP (Vdisplay_line_numbers) && x0 >= it->lnum_pixel_width) | ||
| 28106 | x -= it->lnum_pixel_width; | ||
| 27619 | int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; | 28107 | int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; |
| 27620 | 28108 | ||
| 27621 | /* If the distance from the current position to the next tab | 28109 | /* If the distance from the current position to the next tab |
| @@ -27623,8 +28111,12 @@ x_produce_glyphs (struct it *it) | |||
| 27623 | tab stop after that. */ | 28111 | tab stop after that. */ |
| 27624 | if (next_tab_x - x < font->space_width) | 28112 | if (next_tab_x - x < font->space_width) |
| 27625 | next_tab_x += tab_width; | 28113 | next_tab_x += tab_width; |
| 28114 | if (!NILP (Vdisplay_line_numbers) && x0 >= it->lnum_pixel_width) | ||
| 28115 | next_tab_x += (it->lnum_pixel_width | ||
| 28116 | - ((it->w->hscroll * font->space_width) | ||
| 28117 | % tab_width)); | ||
| 27626 | 28118 | ||
| 27627 | it->pixel_width = next_tab_x - x; | 28119 | it->pixel_width = next_tab_x - x0; |
| 27628 | it->nglyphs = 1; | 28120 | it->nglyphs = 1; |
| 27629 | if (FONT_TOO_HIGH (font)) | 28121 | if (FONT_TOO_HIGH (font)) |
| 27630 | { | 28122 | { |
| @@ -28325,7 +28817,7 @@ set_frame_cursor_types (struct frame *f, Lisp_Object arg) | |||
| 28325 | 28817 | ||
| 28326 | /* By default, set up the blink-off state depending on the on-state. */ | 28818 | /* By default, set up the blink-off state depending on the on-state. */ |
| 28327 | 28819 | ||
| 28328 | tem = Fassoc (arg, Vblink_cursor_alist); | 28820 | tem = Fassoc (arg, Vblink_cursor_alist, Qnil); |
| 28329 | if (!NILP (tem)) | 28821 | if (!NILP (tem)) |
| 28330 | { | 28822 | { |
| 28331 | FRAME_BLINK_OFF_CURSOR (f) | 28823 | FRAME_BLINK_OFF_CURSOR (f) |
| @@ -28463,7 +28955,7 @@ get_window_cursor_type (struct window *w, struct glyph *glyph, int *width, | |||
| 28463 | /* Cursor is blinked off, so determine how to "toggle" it. */ | 28955 | /* Cursor is blinked off, so determine how to "toggle" it. */ |
| 28464 | 28956 | ||
| 28465 | /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */ | 28957 | /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */ |
| 28466 | if ((alt_cursor = Fassoc (BVAR (b, cursor_type), Vblink_cursor_alist), !NILP (alt_cursor))) | 28958 | if ((alt_cursor = Fassoc (BVAR (b, cursor_type), Vblink_cursor_alist, Qnil), !NILP (alt_cursor))) |
| 28467 | return get_specified_cursor_type (XCDR (alt_cursor), width); | 28959 | return get_specified_cursor_type (XCDR (alt_cursor), width); |
| 28468 | 28960 | ||
| 28469 | /* Then see if frame has specified a specific blink off cursor type. */ | 28961 | /* Then see if frame has specified a specific blink off cursor type. */ |
| @@ -31708,6 +32200,12 @@ They are still logged to the *Messages* buffer. */); | |||
| 31708 | /* Name of the face used to highlight trailing whitespace. */ | 32200 | /* Name of the face used to highlight trailing whitespace. */ |
| 31709 | DEFSYM (Qtrailing_whitespace, "trailing-whitespace"); | 32201 | DEFSYM (Qtrailing_whitespace, "trailing-whitespace"); |
| 31710 | 32202 | ||
| 32203 | /* Names of the faces used to display line numbers. */ | ||
| 32204 | DEFSYM (Qline_number, "line-number"); | ||
| 32205 | DEFSYM (Qline_number_current_line, "line-number-current-line"); | ||
| 32206 | /* Name of a text property which disables line-number display. */ | ||
| 32207 | DEFSYM (Qdisplay_line_numbers_disable, "display-line-numbers-disable"); | ||
| 32208 | |||
| 31711 | /* Name and number of the face used to highlight escape glyphs. */ | 32209 | /* Name and number of the face used to highlight escape glyphs. */ |
| 31712 | DEFSYM (Qescape_glyph, "escape-glyph"); | 32210 | DEFSYM (Qescape_glyph, "escape-glyph"); |
| 31713 | 32211 | ||
| @@ -32215,6 +32713,54 @@ To add a prefix to continuation lines, use `wrap-prefix'. */); | |||
| 32215 | DEFSYM (Qline_prefix, "line-prefix"); | 32713 | DEFSYM (Qline_prefix, "line-prefix"); |
| 32216 | Fmake_variable_buffer_local (Qline_prefix); | 32714 | Fmake_variable_buffer_local (Qline_prefix); |
| 32217 | 32715 | ||
| 32716 | DEFVAR_LISP ("display-line-numbers", Vdisplay_line_numbers, | ||
| 32717 | doc: /* Non-nil means display line numbers. | ||
| 32718 | If the value is t, display the absolute number of each line of a buffer | ||
| 32719 | shown in a window. Absolute line numbers count from the beginning of | ||
| 32720 | the current narrowing, or from buffer beginning. If the value is | ||
| 32721 | `relative', display for each line not containing the window's point its | ||
| 32722 | relative number instead, i.e. the number of the line relative to the | ||
| 32723 | line showing the window's point. | ||
| 32724 | |||
| 32725 | In either case, line numbers are displayed at the beginning of each | ||
| 32726 | non-continuation line that displays buffer text, i.e. after each newline | ||
| 32727 | character that comes from the buffer. The value `visual' is like | ||
| 32728 | `relative' but counts screen lines instead of buffer lines. In practice | ||
| 32729 | this means that continuation lines count as well when calculating the | ||
| 32730 | relative number of a line. | ||
| 32731 | |||
| 32732 | Lisp programs can disable display of a line number of a particular | ||
| 32733 | buffer line by putting the `display-line-numbers-disable' text property | ||
| 32734 | or overlay property on the first visible character of that line. */); | ||
| 32735 | Vdisplay_line_numbers = Qnil; | ||
| 32736 | DEFSYM (Qdisplay_line_numbers, "display-line-numbers"); | ||
| 32737 | Fmake_variable_buffer_local (Qdisplay_line_numbers); | ||
| 32738 | DEFSYM (Qrelative, "relative"); | ||
| 32739 | DEFSYM (Qvisual, "visual"); | ||
| 32740 | |||
| 32741 | DEFVAR_LISP ("display-line-numbers-width", Vdisplay_line_numbers_width, | ||
| 32742 | doc: /* Minimum width of space reserved for line number display. | ||
| 32743 | A positive number means reserve that many columns for line numbers, | ||
| 32744 | even if the actual number needs less space. | ||
| 32745 | The default value of nil means compute the space dynamically. | ||
| 32746 | Any other value is treated as nil. */); | ||
| 32747 | Vdisplay_line_numbers_width = Qnil; | ||
| 32748 | DEFSYM (Qdisplay_line_numbers_width, "display-line-numbers-width"); | ||
| 32749 | Fmake_variable_buffer_local (Qdisplay_line_numbers_width); | ||
| 32750 | |||
| 32751 | DEFVAR_LISP ("display-line-numbers-current-absolute", | ||
| 32752 | Vdisplay_line_numbers_current_absolute, | ||
| 32753 | doc: /* Non-nil means display absolute number of current line. | ||
| 32754 | This variable has effect only when `display-line-numbers' is | ||
| 32755 | either `relative' or `visual'. */); | ||
| 32756 | Vdisplay_line_numbers_current_absolute = Qt; | ||
| 32757 | |||
| 32758 | DEFVAR_BOOL ("display-line-numbers-widen", display_line_numbers_widen, | ||
| 32759 | doc: /* Non-nil means display line numbers disregarding any narrowing. */); | ||
| 32760 | display_line_numbers_widen = false; | ||
| 32761 | DEFSYM (Qdisplay_line_numbers_widen, "display-line-numbers-widen"); | ||
| 32762 | Fmake_variable_buffer_local (Qdisplay_line_numbers_widen); | ||
| 32763 | |||
| 32218 | DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay, | 32764 | DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay, |
| 32219 | doc: /* Non-nil means don't eval Lisp during redisplay. */); | 32765 | doc: /* Non-nil means don't eval Lisp during redisplay. */); |
| 32220 | inhibit_eval_during_redisplay = false; | 32766 | inhibit_eval_during_redisplay = false; |