diff options
| author | Gregory Heytings | 2023-03-28 23:06:56 +0000 |
|---|---|---|
| committer | Gregory Heytings | 2023-03-29 01:12:39 +0200 |
| commit | afc2c6c13cb2ebb50a6c31fca5552f9b98b4af95 (patch) | |
| tree | 762b7f83fd30c7a60355f8bacf890bf8c1674148 /src | |
| parent | 7e26a5c774e7c71782d89abe1d4be125d8422a4b (diff) | |
| download | emacs-afc2c6c13cb2ebb50a6c31fca5552f9b98b4af95.tar.gz emacs-afc2c6c13cb2ebb50a6c31fca5552f9b98b4af95.zip | |
Improve accuracy of cursor motion commands in long lines
* src/xdisp.c (get_nearby_bol_pos): New function.
(get_small_narrowing_begv): Use it. This makes cursor motion
commands much more accurate in the first 500K characters of each
long line.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index c752f6712ab..454cbbbf6d5 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -3608,11 +3608,30 @@ get_medium_narrowing_zv (struct window *w, ptrdiff_t pos) | |||
| 3608 | return min ((pos / len + 1) * len, ZV); | 3608 | return min ((pos / len + 1) * len, ZV); |
| 3609 | } | 3609 | } |
| 3610 | 3610 | ||
| 3611 | static ptrdiff_t | ||
| 3612 | get_nearby_bol_pos (ptrdiff_t pos) | ||
| 3613 | { | ||
| 3614 | ptrdiff_t start, pos_bytepos, cur, next, found, bol = 0; | ||
| 3615 | start = pos - 500000 < BEGV ? BEGV : pos - 500000; | ||
| 3616 | pos_bytepos = CHAR_TO_BYTE (pos); | ||
| 3617 | for (cur = start; cur < pos; cur = next) | ||
| 3618 | { | ||
| 3619 | next = find_newline1 (cur, CHAR_TO_BYTE (cur), pos, pos_bytepos, | ||
| 3620 | 1, &found, NULL, false); | ||
| 3621 | if (found) | ||
| 3622 | bol = next; | ||
| 3623 | else | ||
| 3624 | break; | ||
| 3625 | } | ||
| 3626 | return bol; | ||
| 3627 | } | ||
| 3628 | |||
| 3611 | ptrdiff_t | 3629 | ptrdiff_t |
| 3612 | get_small_narrowing_begv (struct window *w, ptrdiff_t pos) | 3630 | get_small_narrowing_begv (struct window *w, ptrdiff_t pos) |
| 3613 | { | 3631 | { |
| 3614 | int len = get_narrowed_width (w); | 3632 | int len = get_narrowed_width (w); |
| 3615 | return max ((pos / len - 1) * len, BEGV); | 3633 | int bol_pos = get_nearby_bol_pos (pos); |
| 3634 | return max (bol_pos + ((pos - bol_pos) / len - 1) * len, BEGV); | ||
| 3616 | } | 3635 | } |
| 3617 | 3636 | ||
| 3618 | ptrdiff_t | 3637 | ptrdiff_t |
| @@ -3653,7 +3672,7 @@ unwind_narrowed_begv (Lisp_Object point_min) | |||
| 3653 | 3672 | ||
| 3654 | #define SET_WITH_NARROWED_BEGV(IT,DST,EXPR,BV) \ | 3673 | #define SET_WITH_NARROWED_BEGV(IT,DST,EXPR,BV) \ |
| 3655 | do { \ | 3674 | do { \ |
| 3656 | if (IT->medium_narrowing_begv) \ | 3675 | if (IT->medium_narrowing_begv) \ |
| 3657 | { \ | 3676 | { \ |
| 3658 | specpdl_ref count = SPECPDL_INDEX (); \ | 3677 | specpdl_ref count = SPECPDL_INDEX (); \ |
| 3659 | record_unwind_protect (unwind_narrowed_begv, Fpoint_min ()); \ | 3678 | record_unwind_protect (unwind_narrowed_begv, Fpoint_min ()); \ |