diff options
author | Gregory Heytings <gregory@heytings.org> | 2022-11-27 22:19:41 +0100 |
---|---|---|
committer | Gregory Heytings <gregory@heytings.org> | 2022-11-27 22:19:41 +0100 |
commit | 849223fba1ef899f90a6edff05bce24b90fbb043 (patch) | |
tree | b5ab707f2da7d13ba2cb10c8af441547152c83ef /src/xdisp.c | |
parent | 89a10ffcc49c5832619649b7876cc339fa9d0dcf (diff) | |
parent | 18fa159fa91b515f2281b83648961fdc5e21aca7 (diff) | |
download | emacs-849223fba1ef899f90a6edff05bce24b90fbb043.tar.gz |
Merge branch 'feature/improved-locked-narrowing'
Diffstat (limited to 'src/xdisp.c')
-rw-r--r-- | src/xdisp.c | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index 5dcf21dc4ce..0002c3d611c 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3533,6 +3533,33 @@ get_closer_narrowed_begv (struct window *w, ptrdiff_t pos) return max ((pos / len - 1) * len, BEGV); } +ptrdiff_t +get_locked_narrowing_begv (ptrdiff_t pos) +{ + if (long_line_locked_narrowing_region_size == 0) + return BEGV; + int len = long_line_locked_narrowing_region_size / 2; + int begv = max (pos - len, BEGV); + int limit = long_line_locked_narrowing_bol_search_limit; + while (limit) + { + if (begv == BEGV || FETCH_BYTE (CHAR_TO_BYTE (begv) - 1) == '\n') + return begv; + begv--; + limit--; + } + return begv; +} + +ptrdiff_t +get_locked_narrowing_zv (ptrdiff_t pos) +{ + if (long_line_locked_narrowing_region_size == 0) + return ZV; + int len = long_line_locked_narrowing_region_size / 2; + return min (pos + len, ZV); +} + static void unwind_narrowed_begv (Lisp_Object point_min) { @@ -4368,16 +4395,16 @@ handle_fontified_prop (struct it *it) if (current_buffer->long_line_optimizations_p) { - ptrdiff_t begv = it->narrowed_begv; - ptrdiff_t zv = it->narrowed_zv; + ptrdiff_t begv = it->locked_narrowing_begv; + ptrdiff_t zv = it->locked_narrowing_zv; ptrdiff_t charpos = IT_CHARPOS (*it); if (charpos < begv || charpos > zv) { - begv = get_narrowed_begv (it->w, charpos); - zv = get_narrowed_zv (it->w, charpos); + begv = get_locked_narrowing_begv (charpos); + zv = get_locked_narrowing_zv (charpos); } - narrow_to_region_internal (make_fixnum (begv), make_fixnum (zv), true); - specbind (Qrestrictions_locked, Qt); + narrow_to_region_locked (make_fixnum (begv), make_fixnum (zv), + Qfontification_functions); } /* Don't allow Lisp that runs from 'fontification-functions' @@ -7435,12 +7462,20 @@ reseat (struct it *it, struct text_pos pos, bool force_p) { it->narrowed_begv = get_narrowed_begv (it->w, window_point (it->w)); it->narrowed_zv = get_narrowed_zv (it->w, window_point (it->w)); + it->locked_narrowing_begv + = get_locked_narrowing_begv (window_point (it->w)); + it->locked_narrowing_zv + = get_locked_narrowing_zv (window_point (it->w)); } else if ((pos.charpos < it->narrowed_begv || pos.charpos > it->narrowed_zv) && (!redisplaying_p || it->line_wrap == TRUNCATE)) { it->narrowed_begv = get_narrowed_begv (it->w, pos.charpos); it->narrowed_zv = get_narrowed_zv (it->w, pos.charpos); + it->locked_narrowing_begv + = get_locked_narrowing_begv (window_point (it->w)); + it->locked_narrowing_zv + = get_locked_narrowing_zv (window_point (it->w)); } } @@ -16266,7 +16301,6 @@ do { if (! polling_stopped_here) stop_polling (); \ do { if (polling_stopped_here) start_polling (); \ polling_stopped_here = false; } while (false) - /* Perhaps in the future avoid recentering windows if it is not necessary; currently that causes some problems. */ @@ -16352,6 +16386,8 @@ redisplay_internal (void) FOR_EACH_FRAME (tail, frame) XFRAME (frame)->already_hscrolled_p = false; + reset_outermost_narrowings (); + retry: /* Remember the currently selected window. */ sw = w; @@ -36711,10 +36747,11 @@ fontify a region starting at POS in the current buffer, and give fontified regions the property `fontified' with a non-nil value. Note that, when the buffer contains one or more lines whose length is -above `long-line-threshold', these functions are called with the buffer -narrowed to a small portion around POS, and the narrowing is locked (see -`narrow-to-region'), so that these functions cannot use `widen' to gain -access to other portions of buffer text. */); +above `long-line-threshold', these functions are called with the +buffer narrowed to a small portion around POS (whose size is specified +by `long-line-locked-narrowing-region-size'), and the narrowing is +locked (see `narrowing-lock'), so that these functions cannot use +`widen' to gain access to other portions of buffer text. */); Vfontification_functions = Qnil; Fmake_variable_buffer_local (Qfontification_functions); |