aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGregory Heytings2022-07-25 20:27:17 +0000
committerGregory Heytings2022-07-25 22:31:00 +0200
commitcd41ce8c6c107901a499bf55dd2b0383befd37af (patch)
tree2501ff3f80fc1cd13b374cc0e230f3c98364473f /src
parent280b8c96ccaeb95548adda78466ef2b1c3cf4546 (diff)
downloademacs-cd41ce8c6c107901a499bf55dd2b0383befd37af.tar.gz
emacs-cd41ce8c6c107901a499bf55dd2b0383befd37af.zip
Improvement for long lines in buffers with font locking.
* src/xdisp.c (get_narrowed_width): Factored out from 'get_narrowed_len'. (get_narrowed_len): Updated to use 'get_narrowed_width'. (get_closer_narrowed_begv): New function. (SET_WITH_NARROWED_BEGV): Add parameter to the macro. (back_to_previous_line_start): Use the new function. (get_visually_first_element, move_it_vertically_backward): Update the calls to the macro. * src/dispextern.h: Prototype of 'get_closer_narrowed_begv'. Fix the prototypes of 'get_narrowed_begv' and 'get_narrowed_zv'.
Diffstat (limited to 'src')
-rw-r--r--src/dispextern.h5
-rw-r--r--src/xdisp.c37
2 files changed, 30 insertions, 12 deletions
diff --git a/src/dispextern.h b/src/dispextern.h
index bafa98161d0..2772e8cda8d 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3404,8 +3404,9 @@ void mark_window_display_accurate (Lisp_Object, bool);
3404void redisplay_preserve_echo_area (int); 3404void redisplay_preserve_echo_area (int);
3405void init_iterator (struct it *, struct window *, ptrdiff_t, 3405void init_iterator (struct it *, struct window *, ptrdiff_t,
3406 ptrdiff_t, struct glyph_row *, enum face_id); 3406 ptrdiff_t, struct glyph_row *, enum face_id);
3407ptrdiff_t get_narrowed_begv (struct window *w); 3407ptrdiff_t get_narrowed_begv (struct window *);
3408ptrdiff_t get_narrowed_zv (struct window *w); 3408ptrdiff_t get_narrowed_zv (struct window *);
3409ptrdiff_t get_closer_narrowed_begv (struct window *, ptrdiff_t);
3409void init_iterator_to_row_start (struct it *, struct window *, 3410void init_iterator_to_row_start (struct it *, struct window *,
3410 struct glyph_row *); 3411 struct glyph_row *);
3411void start_display (struct it *, struct window *, struct text_pos); 3412void start_display (struct it *, struct window *, struct text_pos);
diff --git a/src/xdisp.c b/src/xdisp.c
index add14a084fc..bd3beef134f 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3502,14 +3502,20 @@ init_iterator (struct it *it, struct window *w,
3502 long lines. */ 3502 long lines. */
3503 3503
3504static int 3504static int
3505get_narrowed_len (struct window *w) 3505get_narrowed_width (struct window *w)
3506{ 3506{
3507 int fact; 3507 int fact;
3508 /* In a character-only terminal, only one font size is used, so we 3508 /* In a character-only terminal, only one font size is used, so we
3509 can use a smaller factor. */ 3509 can use a smaller factor. */
3510 fact = EQ (Fterminal_live_p (Qnil), Qt) ? 2 : 3; 3510 fact = EQ (Fterminal_live_p (Qnil), Qt) ? 2 : 3;
3511 return fact * (window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS) * 3511 return fact * window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS);
3512 window_body_height (w, WINDOW_BODY_IN_CANONICAL_CHARS)); 3512}
3513
3514static int
3515get_narrowed_len (struct window *w)
3516{
3517 return get_narrowed_width (w) *
3518 window_body_height (w, WINDOW_BODY_IN_CANONICAL_CHARS);
3513} 3519}
3514 3520
3515ptrdiff_t 3521ptrdiff_t
@@ -3528,6 +3534,13 @@ get_narrowed_zv (struct window *w)
3528 return min ((window_point (w) / len + 1) * len, ZV); 3534 return min ((window_point (w) / len + 1) * len, ZV);
3529} 3535}
3530 3536
3537ptrdiff_t
3538get_closer_narrowed_begv (struct window *w, ptrdiff_t pos)
3539{
3540 int len = get_narrowed_width (w);
3541 return max ((pos / len - 1) * len, BEGV);
3542}
3543
3531static void 3544static void
3532unwind_narrowed_begv (Lisp_Object point_min) 3545unwind_narrowed_begv (Lisp_Object point_min)
3533{ 3546{
@@ -3541,15 +3554,15 @@ unwind_narrowed_zv (Lisp_Object point_max)
3541} 3554}
3542 3555
3543/* Set DST to EXPR. When IT indicates that BEGV should temporarily be 3556/* Set DST to EXPR. When IT indicates that BEGV should temporarily be
3544 updated to optimize display, evaluate EXPR with an updated BEGV. */ 3557 updated to optimize display, evaluate EXPR with BEGV set to BV. */
3545 3558
3546#define SET_WITH_NARROWED_BEGV(IT,DST,EXPR) \ 3559#define SET_WITH_NARROWED_BEGV(IT,DST,EXPR,BV) \
3547 do { \ 3560 do { \
3548 if (IT->narrowed_begv) \ 3561 if (IT->narrowed_begv) \
3549 { \ 3562 { \
3550 specpdl_ref count = SPECPDL_INDEX (); \ 3563 specpdl_ref count = SPECPDL_INDEX (); \
3551 record_unwind_protect (unwind_narrowed_begv, Fpoint_min ()); \ 3564 record_unwind_protect (unwind_narrowed_begv, Fpoint_min ()); \
3552 SET_BUF_BEGV (current_buffer, IT->narrowed_begv); \ 3565 SET_BUF_BEGV (current_buffer, BV); \
3553 DST = EXPR; \ 3566 DST = EXPR; \
3554 unbind_to (count, Qnil); \ 3567 unbind_to (count, Qnil); \
3555 } \ 3568 } \
@@ -7067,7 +7080,8 @@ back_to_previous_line_start (struct it *it)
7067 7080
7068 dec_both (&cp, &bp); 7081 dec_both (&cp, &bp);
7069 SET_WITH_NARROWED_BEGV (it, IT_CHARPOS (*it), 7082 SET_WITH_NARROWED_BEGV (it, IT_CHARPOS (*it),
7070 find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it))); 7083 find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it)),
7084 get_closer_narrowed_begv (it->w, IT_CHARPOS (*it)));
7071} 7085}
7072 7086
7073 7087
@@ -8706,7 +8720,8 @@ get_visually_first_element (struct it *it)
8706 8720
8707 SET_WITH_NARROWED_BEGV (it, bob, 8721 SET_WITH_NARROWED_BEGV (it, bob,
8708 string_p ? 0 : 8722 string_p ? 0 :
8709 IT_BYTEPOS (*it) < BEGV ? obegv : BEGV); 8723 IT_BYTEPOS (*it) < BEGV ? obegv : BEGV,
8724 it->narrowed_begv);
8710 8725
8711 if (STRINGP (it->string)) 8726 if (STRINGP (it->string))
8712 { 8727 {
@@ -8749,7 +8764,8 @@ get_visually_first_element (struct it *it)
8749 SET_WITH_NARROWED_BEGV (it, it->bidi_it.charpos, 8764 SET_WITH_NARROWED_BEGV (it, it->bidi_it.charpos,
8750 find_newline_no_quit (IT_CHARPOS (*it), 8765 find_newline_no_quit (IT_CHARPOS (*it),
8751 IT_BYTEPOS (*it), -1, 8766 IT_BYTEPOS (*it), -1,
8752 &it->bidi_it.bytepos)); 8767 &it->bidi_it.bytepos),
8768 it->narrowed_begv);
8753 bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true); 8769 bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true);
8754 do 8770 do
8755 { 8771 {
@@ -10668,7 +10684,8 @@ move_it_vertically_backward (struct it *it, int dy)
10668 10684
10669 dec_both (&cp, &bp); 10685 dec_both (&cp, &bp);
10670 SET_WITH_NARROWED_BEGV (it, cp, 10686 SET_WITH_NARROWED_BEGV (it, cp,
10671 find_newline_no_quit (cp, bp, -1, NULL)); 10687 find_newline_no_quit (cp, bp, -1, NULL),
10688 it->narrowed_begv);
10672 move_it_to (it, cp, -1, -1, -1, MOVE_TO_POS); 10689 move_it_to (it, cp, -1, -1, -1, MOVE_TO_POS);
10673 } 10690 }
10674 bidi_unshelve_cache (it3data, true); 10691 bidi_unshelve_cache (it3data, true);