From 5dc65c10ca1a2504699ad5374fedb127960946c8 Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Mon, 1 Aug 2022 15:52:12 +0000 Subject: [PATCH] Various improvements to long lines handling. * src/xdisp.c (get_visually_first_element, (move_it_vertically_backward): Do not go back too far with bidi. (get_narrowed_begv): Do not return 0 anymore instead of BEGV. (handle_fontified_prop): Simplify accordingly. * src/keyboard.c (safe_run_hooks_maybe_narrowed): Simplify accordingly. * src/composite.c (find_automatic_composition): Ditto. --- src/composite.c | 2 +- src/keyboard.c | 9 +++------ src/xdisp.c | 11 ++++------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/composite.c b/src/composite.c index 0f90b92a785..e721fe8c81f 100644 --- a/src/composite.c +++ b/src/composite.c @@ -1600,7 +1600,7 @@ find_automatic_composition (ptrdiff_t pos, ptrdiff_t limit, ptrdiff_t backlim, /* In buffers with very long lines, this function becomes very slow. Pretend that the buffer is narrowed to make it fast. */ narrowed_begv = get_narrowed_begv (w, window_point (w)); - if (narrowed_begv && pos > narrowed_begv) + if (pos > narrowed_begv) head = narrowed_begv; tail = ZV; stop = GPT; diff --git a/src/keyboard.c b/src/keyboard.c index 094119340e1..a730dfe4fda 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1907,12 +1907,9 @@ safe_run_hooks_maybe_narrowed (Lisp_Object hook, struct window *w) specbind (Qinhibit_quit, Qt); if (current_buffer->long_line_optimizations_p) - { - ptrdiff_t begv = get_narrowed_begv (w, PT); - ptrdiff_t zv = get_narrowed_zv (w, PT); - if (!begv) begv = BEGV; - Fnarrow_to_region (make_fixnum (begv), make_fixnum (zv), Qt); - } + Fnarrow_to_region (make_fixnum (get_narrowed_begv (w, PT)), + make_fixnum (get_narrowed_zv (w, PT)), + Qt); run_hook_with_args (2, ((Lisp_Object []) {hook, hook}), safe_run_hook_funcall); unbind_to (count, Qnil); diff --git a/src/xdisp.c b/src/xdisp.c index c6fc05b8b4a..c4abe6e9855 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3507,9 +3507,7 @@ ptrdiff_t get_narrowed_begv (struct window *w, ptrdiff_t pos) { int len = get_narrowed_len (w); - ptrdiff_t begv; - begv = max ((pos / len - 1) * len, BEGV); - return begv == BEGV ? 0 : begv; + return max ((pos / len - 1) * len, BEGV); } ptrdiff_t @@ -4394,13 +4392,12 @@ handle_fontified_prop (struct it *it) if (current_buffer->long_line_optimizations_p) { - ptrdiff_t begv = it->narrowed_begv ? it->narrowed_begv : BEGV; + ptrdiff_t begv = it->narrowed_begv; ptrdiff_t zv = it->narrowed_zv; ptrdiff_t charpos = IT_CHARPOS (*it); if (charpos < begv || charpos > zv) { begv = get_narrowed_begv (it->w, charpos); - if (!begv) begv = BEGV; zv = get_narrowed_zv (it->w, charpos); } Fnarrow_to_region (make_fixnum (begv), make_fixnum (zv), Qt); @@ -8894,7 +8891,7 @@ get_visually_first_element (struct it *it) find_newline_no_quit (IT_CHARPOS (*it), IT_BYTEPOS (*it), -1, &it->bidi_it.bytepos), - it->narrowed_begv); + get_closer_narrowed_begv (it->w, IT_CHARPOS (*it))); bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true); do { @@ -10784,7 +10781,7 @@ move_it_vertically_backward (struct it *it, int dy) dec_both (&cp, &bp); SET_WITH_NARROWED_BEGV (it, cp, find_newline_no_quit (cp, bp, -1, NULL), - it->narrowed_begv); + get_closer_narrowed_begv (it->w, IT_CHARPOS (*it))); move_it_to (it, cp, -1, -1, -1, MOVE_TO_POS); } bidi_unshelve_cache (it3data, true); -- 2.39.2