aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Kangas2023-02-15 14:41:04 +0100
committerStefan Kangas2023-02-15 14:41:04 +0100
commit142f5683c1042a5344abd51b97fe8e0d0c8cc5f5 (patch)
tree5c66b054ed4cb2317e5fd6caa359bf812748de10 /src
parent571558e460059b3756f592abaaf2a9a67778db66 (diff)
parent7678b7e46f2e394447f39c3a6cf02bc285e5a5a4 (diff)
downloademacs-142f5683c1042a5344abd51b97fe8e0d0c8cc5f5.tar.gz
emacs-142f5683c1042a5344abd51b97fe8e0d0c8cc5f5.zip
Merge from origin/emacs-29
7678b7e46f2 Eglot: check server capability before sending didSave (bu... a3a1ef7bd5e Fix rust-ts-mode type and module highlighting (Bug#61302) 477aa047ee7 rust-ts-mode: Highlight variable reassignments 5206a551c16 Improve backward compatibility of save-restriction accd88d5545 Don't indent template_string contents (bug#61503) d97a3839967 csharp-ts-mode: fontify compiler directives (bug#61512) 420d2cae846 Update to Transient v0.3.7-209-gdab1dfa a3751b5d0c1 ; Raise an error if a VC package checkout is empty 6a32ba8b69c ; Fix the installation of dependencies for VC packages 4eac80fcc39 ; Prepare to update ERC version to 5.5 4f099a72173 ; Remove failing erc-reuse-buffers test 4bb27a5ca93 ; Minor docs copyedits 13bcff3da5c Merge branch 'emacs-29' of git.savannah.gnu.org:/srv/git/... 3d572ae0d50 Rename with/without-narrowing to with/without-restriction d806b0e33cf * lisp/repeat.el: Rename internal function and variable (... dd8b720ee74 ; * etc/NEWS: Fix typos. 909bd04cf5f ; * lisp/calendar/lunar.el: Add comments. (bug#61460) 10f2aedea9a ; * lisp/progmodes/c-ts-mode.el (c-ts-base-mode): delete ... 865758130a1 ; * admin/git-bisect-start: Update failing commits b948d0d7efe Merge branch 'scratch/fix-locked-narrowing' dcb2379a463 Minor improvements to labeled narrowing cc30422825a Fix spurious display of eclipses in Calendar f2114e8d89f Fix indentation for closing bracket in c-ts-mode (bug#61398) f49caaa8925 ; * src/pdumper.c (dump_buffer): Update hash. fe2ea5ddd8d Update to Org 9.6.1-31-gaf1bb1 8280d721d7c * src/.gdbinit (nextcons): Amend $.u.cdr to $.u.s.u.cdr (... eb2b0931cf1 Add lambda_expression to c-ts-common-indent-type-regexp-a... 2da05876edb ; Use the right name when specifying VC packages d4fc7012978 Tolerate missing elpa-packages.eld files 8bc1b7d0b27 Avoid warning about 'load-path' in non-interactive sessions 3d17aee13d9 ; Fix installation of dependencies for VC packages 86ca7df6a34 ; Mention Hunspell private-dictionary misfeature in doc s... 7287b7b53a1 Support webkit2gtk-4.1 048a2dabfc4 ; Fix typo 8f3091defb3 ; Fix typo in buffer.h 4da398d8b57 ; Fix typos 074008ee2d2 ; Fix doc strings in lisp/image/ directory 2d1e43436da ; Improve documentation of hash functions. 900f7e07275 ; Remove extraneous local variables from image-dired-*.el... 4297039bd13 Save and restore the absence of narrowing locks 4f053afe8e7 bug-reference: prevent match-data clobbering (bug#61395) 10af9fbcad1 ; * admin/notes/tree-sitter/starter-guide: Typos. 9ac242ce93d ; Fix recent changes in treesit docs f5789aefc2e Rename LIMIT to DEPTH in tree-sitter functions (bug#61231) b39821fdcef ; Fix incorrect function name in treesit manual 51901736965 Add 'live' property to treesit-node-check (bug#61235) 56960a6558b Update to Transient v0.3.7-205-gb8ad0da 68a6b364d1c Fix 'rmail-summary-output' 67c6ec25590 lisp-mode: add docstring recognition for more common lisp... 417a8ed8b05 ; Improve discoverability of empty file names handling e47cf6ca15a Update to Transient v0.3.7-204-gecff8c2 b04cce02ff4 Fix Scala entry in Eglot's DB of LSP servers 973c1d24c6a ruby-ts-mode: Also don't reindent 'identifier' when insid... a5651c0c403 ruby-ts-mode: Fix indentation inside empty if/unless/case... 2956e54b1dd Add an extensive test for labeled (locked) narrowing 79ce185ad13 Update the documentation about labeled (locked) narrowing a6cd4553d48 Rename two long line optimizations variables 0d73e4aa261 Add specific symbols for narrowings d8438e2bb44 Add 'without-narrowing' macro 97314447e60 Make 'narrowing-lock' and 'narrowing-unlock' internal a4aa32bdfff Fix 'save-restriction' for narrowing locks # Conflicts: # etc/NEWS
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c47
-rw-r--r--src/editfns.c118
-rw-r--r--src/keyboard.c31
-rw-r--r--src/xdisp.c27
4 files changed, 114 insertions, 109 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 38648519ba0..df1f5206668 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5916,40 +5916,41 @@ If nil, these display shortcuts will always remain disabled.
5916There is no reason to change that value except for debugging purposes. */); 5916There is no reason to change that value except for debugging purposes. */);
5917 XSETFASTINT (Vlong_line_threshold, 50000); 5917 XSETFASTINT (Vlong_line_threshold, 50000);
5918 5918
5919 DEFVAR_INT ("long-line-locked-narrowing-region-size", 5919 DEFVAR_INT ("long-line-optimizations-region-size",
5920 long_line_locked_narrowing_region_size, 5920 long_line_optimizations_region_size,
5921 doc: /* Region size for locked narrowing in buffers with long lines. 5921 doc: /* Region size for narrowing in buffers with long lines.
5922 5922
5923This variable has effect only in buffers which contain one or more 5923This variable has effect only in buffers in which
5924lines whose length is above `long-line-threshold', which see. For 5924`long-line-optimizations-p' is non-nil. For performance reasons, in
5925performance reasons, in such buffers, low-level hooks such as 5925such buffers, the `fontification-functions', `pre-command-hook' and
5926`fontification-functions' or `post-command-hook' are executed on a 5926`post-command-hook' hooks are executed on a narrowed buffer around
5927narrowed buffer, with a narrowing locked with `narrowing-lock'. This 5927point, as if they were called in a `with-restriction' form with a label.
5928variable specifies the size of the narrowed region around point. 5928This variable specifies the size of the narrowed region around point.
5929 5929
5930To disable that narrowing, set this variable to 0. 5930To disable that narrowing, set this variable to 0.
5931 5931
5932See also `long-line-locked-narrowing-bol-search-limit'. 5932See also `long-line-optimizations-bol-search-limit'.
5933 5933
5934There is no reason to change that value except for debugging purposes. */); 5934There is no reason to change that value except for debugging purposes. */);
5935 long_line_locked_narrowing_region_size = 500000; 5935 long_line_optimizations_region_size = 500000;
5936 5936
5937 DEFVAR_INT ("long-line-locked-narrowing-bol-search-limit", 5937 DEFVAR_INT ("long-line-optimizations-bol-search-limit",
5938 long_line_locked_narrowing_bol_search_limit, 5938 long_line_optimizations_bol_search_limit,
5939 doc: /* Limit for beginning of line search in buffers with long lines. 5939 doc: /* Limit for beginning of line search in buffers with long lines.
5940 5940
5941This variable has effect only in buffers which contain one or more 5941This variable has effect only in buffers in which
5942lines whose length is above `long-line-threshold', which see. For 5942`long-line-optimizations-p' is non-nil. For performance reasons, in
5943performance reasons, in such buffers, low-level hooks such as 5943such buffers, the `fontification-functions', `pre-command-hook' and
5944`fontification-functions' or `post-command-hook' are executed on a 5944`post-command-hook' hooks are executed on a narrowed buffer around
5945narrowed buffer, with a narrowing locked with `narrowing-lock'. The 5945point, as if they were called in a `with-restriction' form with a label.
5946variable `long-line-locked-narrowing-region-size' specifies the size 5946The variable `long-line-optimizations-region-size' specifies the
5947of the narrowed region around point. This variable, which should be a 5947size of the narrowed region around point. This variable, which should
5948small integer, specifies the number of characters by which that region 5948be a small integer, specifies the number of characters by which that
5949can be extended backwards to make it start at the beginning of a line. 5949region can be extended backwards to make it start at the beginning of
5950a line.
5950 5951
5951There is no reason to change that value except for debugging purposes. */); 5952There is no reason to change that value except for debugging purposes. */);
5952 long_line_locked_narrowing_bol_search_limit = 128; 5953 long_line_optimizations_bol_search_limit = 128;
5953 5954
5954 DEFVAR_INT ("large-hscroll-threshold", large_hscroll_threshold, 5955 DEFVAR_INT ("large-hscroll-threshold", large_hscroll_threshold,
5955 doc: /* Horizontal scroll of truncated lines above which to use redisplay shortcuts. 5956 doc: /* Horizontal scroll of truncated lines above which to use redisplay shortcuts.
diff --git a/src/editfns.c b/src/editfns.c
index 78d2c73ecbf..f83c5c7259b 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2659,7 +2659,11 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
2659 the (uninterned) Qoutermost_narrowing tag and records the narrowing 2659 the (uninterned) Qoutermost_narrowing tag and records the narrowing
2660 bounds that were set by the user and that are visible on display. 2660 bounds that were set by the user and that are visible on display.
2661 This alist is used internally by narrow-to-region, widen, 2661 This alist is used internally by narrow-to-region, widen,
2662 narrowing-lock, narrowing-unlock and save-restriction. */ 2662 internal--lock-narrowing, internal--unlock-narrowing and
2663 save-restriction. For efficiency reasons, an alist is used instead
2664 of a buffer-local variable: otherwise reset_outermost_narrowings,
2665 which is called during each redisplay cycle, would have to loop
2666 through all live buffers. */
2663static Lisp_Object narrowing_locks; 2667static Lisp_Object narrowing_locks;
2664 2668
2665/* Add BUF with its LOCKS in the narrowing_locks alist. */ 2669/* Add BUF with its LOCKS in the narrowing_locks alist. */
@@ -2763,7 +2767,10 @@ unwind_reset_outermost_narrowing (Lisp_Object buf)
2763 In particular, this function is called when redisplay starts, so 2767 In particular, this function is called when redisplay starts, so
2764 that if a Lisp function executed during redisplay calls (redisplay) 2768 that if a Lisp function executed during redisplay calls (redisplay)
2765 while a locked narrowing is in effect, the locked narrowing will 2769 while a locked narrowing is in effect, the locked narrowing will
2766 not be visible on display. */ 2770 not be visible on display.
2771 See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=57207#140 and
2772 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=57207#254 for example
2773 recipes that demonstrate why this is necessary. */
2767void 2774void
2768reset_outermost_narrowings (void) 2775reset_outermost_narrowings (void)
2769{ 2776{
@@ -2792,27 +2799,25 @@ narrowing_locks_save (void)
2792{ 2799{
2793 Lisp_Object buf = Fcurrent_buffer (); 2800 Lisp_Object buf = Fcurrent_buffer ();
2794 Lisp_Object locks = assq_no_quit (buf, narrowing_locks); 2801 Lisp_Object locks = assq_no_quit (buf, narrowing_locks);
2795 if (NILP (locks)) 2802 if (!NILP (locks))
2796 return Qnil; 2803 locks = XCAR (XCDR (locks));
2797 locks = XCAR (XCDR (locks));
2798 return Fcons (buf, Fcopy_sequence (locks)); 2804 return Fcons (buf, Fcopy_sequence (locks));
2799} 2805}
2800 2806
2801static void 2807static void
2802narrowing_locks_restore (Lisp_Object buf_and_saved_locks) 2808narrowing_locks_restore (Lisp_Object buf_and_saved_locks)
2803{ 2809{
2804 if (NILP (buf_and_saved_locks))
2805 return;
2806 Lisp_Object buf = XCAR (buf_and_saved_locks); 2810 Lisp_Object buf = XCAR (buf_and_saved_locks);
2807 Lisp_Object saved_locks = XCDR (buf_and_saved_locks); 2811 Lisp_Object saved_locks = XCDR (buf_and_saved_locks);
2808 narrowing_locks_remove (buf); 2812 narrowing_locks_remove (buf);
2809 narrowing_locks_add (buf, saved_locks); 2813 if (!NILP (saved_locks))
2814 narrowing_locks_add (buf, saved_locks);
2810} 2815}
2811 2816
2812static void 2817static void
2813unwind_narrow_to_region_locked (Lisp_Object tag) 2818unwind_narrow_to_region_locked (Lisp_Object tag)
2814{ 2819{
2815 Fnarrowing_unlock (tag); 2820 Finternal__unlock_narrowing (tag);
2816 Fwiden (); 2821 Fwiden ();
2817} 2822}
2818 2823
@@ -2821,7 +2826,7 @@ void
2821narrow_to_region_locked (Lisp_Object begv, Lisp_Object zv, Lisp_Object tag) 2826narrow_to_region_locked (Lisp_Object begv, Lisp_Object zv, Lisp_Object tag)
2822{ 2827{
2823 Fnarrow_to_region (begv, zv); 2828 Fnarrow_to_region (begv, zv);
2824 Fnarrowing_lock (tag); 2829 Finternal__lock_narrowing (tag);
2825 record_unwind_protect (restore_point_unwind, Fpoint_marker ()); 2830 record_unwind_protect (restore_point_unwind, Fpoint_marker ());
2826 record_unwind_protect (unwind_narrow_to_region_locked, tag); 2831 record_unwind_protect (unwind_narrow_to_region_locked, tag);
2827} 2832}
@@ -2829,10 +2834,12 @@ narrow_to_region_locked (Lisp_Object begv, Lisp_Object zv, Lisp_Object tag)
2829DEFUN ("widen", Fwiden, Swiden, 0, 0, "", 2834DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
2830 doc: /* Remove restrictions (narrowing) from current buffer. 2835 doc: /* Remove restrictions (narrowing) from current buffer.
2831 2836
2832This allows the buffer's full text to be seen and edited, unless 2837This allows the buffer's full text to be seen and edited.
2833restrictions have been locked with `narrowing-lock', which see, in 2838
2834which case the narrowing that was current when `narrowing-lock' was 2839However, when restrictions have been set by `with-restriction' with a
2835called is restored. */) 2840label, `widen' restores the narrowing limits set by `with-restriction'.
2841To gain access to other portions of the buffer, use
2842`without-restriction' with the same label. */)
2836 (void) 2843 (void)
2837{ 2844{
2838 Fset (Qoutermost_narrowing, Qnil); 2845 Fset (Qoutermost_narrowing, Qnil);
@@ -2879,11 +2886,12 @@ When calling from Lisp, pass two arguments START and END:
2879positions (integers or markers) bounding the text that should 2886positions (integers or markers) bounding the text that should
2880remain visible. 2887remain visible.
2881 2888
2882When restrictions have been locked with `narrowing-lock', which see, 2889However, when restrictions have been set by `with-restriction' with a
2883`narrow-to-region' can be used only within the limits of the 2890label, `narrow-to-region' can be used only within the limits of these
2884restrictions that were current when `narrowing-lock' was called. If 2891restrictions. If the START or END arguments are outside these limits,
2885the START or END arguments are outside these limits, the corresponding 2892the corresponding limit set by `with-restriction' is used instead of the
2886limit of the locked restriction is used instead of the argument. */) 2893argument. To gain access to other portions of the buffer, use
2894`without-restriction' with the same label. */)
2887 (Lisp_Object start, Lisp_Object end) 2895 (Lisp_Object start, Lisp_Object end)
2888{ 2896{
2889 EMACS_INT s = fix_position (start), e = fix_position (end); 2897 EMACS_INT s = fix_position (start), e = fix_position (end);
@@ -2912,7 +2920,7 @@ limit of the locked restriction is used instead of the argument. */)
2912 2920
2913 /* Record the accessible range of the buffer when narrow-to-region 2921 /* Record the accessible range of the buffer when narrow-to-region
2914 is called, that is, before applying the narrowing. It is used 2922 is called, that is, before applying the narrowing. It is used
2915 only by narrowing-lock. */ 2923 only by internal--lock-narrowing. */
2916 Fset (Qoutermost_narrowing, list3 (Qoutermost_narrowing, 2924 Fset (Qoutermost_narrowing, list3 (Qoutermost_narrowing,
2917 Fpoint_min_marker (), 2925 Fpoint_min_marker (),
2918 Fpoint_max_marker ())); 2926 Fpoint_max_marker ()));
@@ -2932,31 +2940,18 @@ limit of the locked restriction is used instead of the argument. */)
2932 return Qnil; 2940 return Qnil;
2933} 2941}
2934 2942
2935DEFUN ("narrowing-lock", Fnarrowing_lock, Snarrowing_lock, 1, 1, 0, 2943DEFUN ("internal--lock-narrowing", Finternal__lock_narrowing,
2936 doc: /* Lock the current narrowing with TAG. 2944 Sinternal__lock_narrowing, 1, 1, 0,
2945 doc: /* Lock the current narrowing with LABEL.
2937 2946
2938When restrictions are locked, `narrow-to-region' and `widen' can be 2947This is an internal function used by `with-restriction'. */)
2939used only within the limits of the restrictions that were current when
2940`narrowing-lock' was called, unless the lock is removed by calling
2941`narrowing-unlock' with TAG.
2942
2943Locking restrictions should be used sparingly, after carefully
2944considering the potential adverse effects on the code that will be
2945executed within locked restrictions. It is typically meant to be used
2946around portions of code that would become too slow, and make Emacs
2947unresponsive, if they were executed in a large buffer. For example,
2948restrictions are locked by Emacs around low-level hooks such as
2949`fontification-functions' or `post-command-hook'.
2950
2951Locked restrictions are never visible on display, and can therefore
2952not be used as a stronger variant of normal restrictions. */)
2953 (Lisp_Object tag) 2948 (Lisp_Object tag)
2954{ 2949{
2955 Lisp_Object buf = Fcurrent_buffer (); 2950 Lisp_Object buf = Fcurrent_buffer ();
2956 Lisp_Object outermost_narrowing 2951 Lisp_Object outermost_narrowing
2957 = buffer_local_value (Qoutermost_narrowing, buf); 2952 = buffer_local_value (Qoutermost_narrowing, buf);
2958 /* If narrowing-lock is called without being preceded by 2953 /* If internal--lock-narrowing is ever called without being preceded
2959 narrow-to-region, do nothing. */ 2954 by narrow-to-region, do nothing. */
2960 if (NILP (outermost_narrowing)) 2955 if (NILP (outermost_narrowing))
2961 return Qnil; 2956 return Qnil;
2962 if (NILP (narrowing_lock_peek_tag (buf))) 2957 if (NILP (narrowing_lock_peek_tag (buf)))
@@ -2967,16 +2962,11 @@ not be used as a stronger variant of normal restrictions. */)
2967 return Qnil; 2962 return Qnil;
2968} 2963}
2969 2964
2970DEFUN ("narrowing-unlock", Fnarrowing_unlock, Snarrowing_unlock, 1, 1, 0, 2965DEFUN ("internal--unlock-narrowing", Finternal__unlock_narrowing,
2971 doc: /* Unlock a narrowing locked with (narrowing-lock TAG). 2966 Sinternal__unlock_narrowing, 1, 1, 0,
2967 doc: /* Unlock a narrowing locked with LABEL.
2972 2968
2973Unlocking restrictions locked with `narrowing-lock' should be used 2969This is an internal function used by `without-restriction'. */)
2974sparingly, after carefully considering the reasons why restrictions
2975were locked. Restrictions are typically locked around portions of
2976code that would become too slow, and make Emacs unresponsive, if they
2977were executed in a large buffer. For example, restrictions are locked
2978by Emacs around low-level hooks such as `fontification-functions' or
2979`post-command-hook'. */)
2980 (Lisp_Object tag) 2970 (Lisp_Object tag)
2981{ 2971{
2982 Lisp_Object buf = Fcurrent_buffer (); 2972 Lisp_Object buf = Fcurrent_buffer ();
@@ -2985,8 +2975,8 @@ by Emacs around low-level hooks such as `fontification-functions' or
2985 return Qnil; 2975 return Qnil;
2986} 2976}
2987 2977
2988Lisp_Object 2978static Lisp_Object
2989save_restriction_save (void) 2979save_restriction_save_1 (void)
2990{ 2980{
2991 if (BEGV == BEG && ZV == Z) 2981 if (BEGV == BEG && ZV == Z)
2992 /* The common case that the buffer isn't narrowed. 2982 /* The common case that the buffer isn't narrowed.
@@ -3009,8 +2999,8 @@ save_restriction_save (void)
3009 } 2999 }
3010} 3000}
3011 3001
3012void 3002static void
3013save_restriction_restore (Lisp_Object data) 3003save_restriction_restore_1 (Lisp_Object data)
3014{ 3004{
3015 struct buffer *cur = NULL; 3005 struct buffer *cur = NULL;
3016 struct buffer *buf = (CONSP (data) 3006 struct buffer *buf = (CONSP (data)
@@ -3078,13 +3068,28 @@ save_restriction_restore (Lisp_Object data)
3078 set_buffer_internal (cur); 3068 set_buffer_internal (cur);
3079} 3069}
3080 3070
3071Lisp_Object
3072save_restriction_save (void)
3073{
3074 Lisp_Object restr = save_restriction_save_1 ();
3075 Lisp_Object locks = narrowing_locks_save ();
3076 return Fcons (restr, locks);
3077}
3078
3079void
3080save_restriction_restore (Lisp_Object data)
3081{
3082 narrowing_locks_restore (XCDR (data));
3083 save_restriction_restore_1 (XCAR (data));
3084}
3085
3081DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0, 3086DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0,
3082 doc: /* Execute BODY, saving and restoring current buffer's restrictions. 3087 doc: /* Execute BODY, saving and restoring current buffer's restrictions.
3083The buffer's restrictions make parts of the beginning and end invisible. 3088The buffer's restrictions make parts of the beginning and end invisible.
3084\(They are set up with `narrow-to-region' and eliminated with `widen'.) 3089\(They are set up with `narrow-to-region' and eliminated with `widen'.)
3085This special form, `save-restriction', saves the current buffer's 3090This special form, `save-restriction', saves the current buffer's
3086restrictions, as well as their locks if they have been locked with 3091restrictions, including those that were set by `with-restriction' with a
3087`narrowing-lock', when it is entered, and restores them when it is exited. 3092label argument, when it is entered, and restores them when it is exited.
3088So any `narrow-to-region' within BODY lasts only until the end of the form. 3093So any `narrow-to-region' within BODY lasts only until the end of the form.
3089The old restrictions settings are restored even in case of abnormal exit 3094The old restrictions settings are restored even in case of abnormal exit
3090\(throw or error). 3095\(throw or error).
@@ -3102,7 +3107,6 @@ usage: (save-restriction &rest BODY) */)
3102 specpdl_ref count = SPECPDL_INDEX (); 3107 specpdl_ref count = SPECPDL_INDEX ();
3103 3108
3104 record_unwind_protect (save_restriction_restore, save_restriction_save ()); 3109 record_unwind_protect (save_restriction_restore, save_restriction_save ());
3105 record_unwind_protect (narrowing_locks_restore, narrowing_locks_save ());
3106 val = Fprogn (body); 3110 val = Fprogn (body);
3107 return unbind_to (count, val); 3111 return unbind_to (count, val);
3108} 3112}
@@ -4903,8 +4907,8 @@ it to be non-nil. */);
4903 defsubr (&Sdelete_and_extract_region); 4907 defsubr (&Sdelete_and_extract_region);
4904 defsubr (&Swiden); 4908 defsubr (&Swiden);
4905 defsubr (&Snarrow_to_region); 4909 defsubr (&Snarrow_to_region);
4906 defsubr (&Snarrowing_lock); 4910 defsubr (&Sinternal__lock_narrowing);
4907 defsubr (&Snarrowing_unlock); 4911 defsubr (&Sinternal__unlock_narrowing);
4908 defsubr (&Ssave_restriction); 4912 defsubr (&Ssave_restriction);
4909 defsubr (&Stranspose_regions); 4913 defsubr (&Stranspose_regions);
4910} 4914}
diff --git a/src/keyboard.c b/src/keyboard.c
index 6f0f075e54e..b2816f8270b 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1910,12 +1910,13 @@ safe_run_hooks_maybe_narrowed (Lisp_Object hook, struct window *w)
1910 specbind (Qinhibit_quit, Qt); 1910 specbind (Qinhibit_quit, Qt);
1911 1911
1912 if (current_buffer->long_line_optimizations_p 1912 if (current_buffer->long_line_optimizations_p
1913 && long_line_locked_narrowing_region_size > 0) 1913 && long_line_optimizations_region_size > 0)
1914 { 1914 {
1915 ptrdiff_t begv = get_locked_narrowing_begv (PT); 1915 ptrdiff_t begv = get_locked_narrowing_begv (PT);
1916 ptrdiff_t zv = get_locked_narrowing_zv (PT); 1916 ptrdiff_t zv = get_locked_narrowing_zv (PT);
1917 if (begv != BEG || zv != Z) 1917 if (begv != BEG || zv != Z)
1918 narrow_to_region_locked (make_fixnum (begv), make_fixnum (zv), hook); 1918 narrow_to_region_locked (make_fixnum (begv), make_fixnum (zv),
1919 Qlong_line_optimizations_in_command_hooks);
1919 } 1920 }
1920 1921
1921 run_hook_with_args (2, ((Lisp_Object []) {hook, hook}), 1922 run_hook_with_args (2, ((Lisp_Object []) {hook, hook}),
@@ -12168,6 +12169,8 @@ syms_of_keyboard (void)
12168 /* Hooks to run before and after each command. */ 12169 /* Hooks to run before and after each command. */
12169 DEFSYM (Qpre_command_hook, "pre-command-hook"); 12170 DEFSYM (Qpre_command_hook, "pre-command-hook");
12170 DEFSYM (Qpost_command_hook, "post-command-hook"); 12171 DEFSYM (Qpost_command_hook, "post-command-hook");
12172 DEFSYM (Qlong_line_optimizations_in_command_hooks,
12173 "long-line-optimizations-in-command-hooks");
12171 12174
12172 /* Hook run after the region is selected. */ 12175 /* Hook run after the region is selected. */
12173 DEFSYM (Qpost_select_region_hook, "post-select-region-hook"); 12176 DEFSYM (Qpost_select_region_hook, "post-select-region-hook");
@@ -12728,13 +12731,11 @@ If an unhandled error happens in running this hook, the function in
12728which the error occurred is unconditionally removed, since otherwise 12731which the error occurred is unconditionally removed, since otherwise
12729the error might happen repeatedly and make Emacs nonfunctional. 12732the error might happen repeatedly and make Emacs nonfunctional.
12730 12733
12731Note that, when the current buffer contains one or more lines whose 12734Note that, when `long-line-optimizations-p' is non-nil in the buffer,
12732length is above `long-line-threshold', these hook functions are called 12735these functions are called as if they were in a `with-restriction' form,
12733with the buffer narrowed to a small portion around point (whose size 12736with a `long-line-optimizations-in-command-hooks' label and with the
12734is specified by `long-line-locked-narrowing-region-size'), and the 12737buffer narrowed to a portion around point whose size is specified by
12735narrowing is locked (see `narrowing-lock'), so that these hook 12738`long-line-optimizations-region-size'.
12736functions cannot use `widen' to gain access to other portions of
12737buffer text.
12738 12739
12739See also `post-command-hook'. */); 12740See also `post-command-hook'. */);
12740 Vpre_command_hook = Qnil; 12741 Vpre_command_hook = Qnil;
@@ -12750,13 +12751,11 @@ It is a bad idea to use this hook for expensive processing. If
12750unavoidable, wrap your code in `(while-no-input (redisplay) CODE)' to 12751unavoidable, wrap your code in `(while-no-input (redisplay) CODE)' to
12751avoid making Emacs unresponsive while the user types. 12752avoid making Emacs unresponsive while the user types.
12752 12753
12753Note that, when the current buffer contains one or more lines whose 12754Note that, when `long-line-optimizations-p' is non-nil in the buffer,
12754length is above `long-line-threshold', these hook functions are called 12755these functions are called as if they were in a `with-restriction' form,
12755with the buffer narrowed to a small portion around point (whose size 12756with a `long-line-optimizations-in-command-hooks' label and with the
12756is specified by `long-line-locked-narrowing-region-size'), and the 12757buffer narrowed to a portion around point whose size is specified by
12757narrowing is locked (see `narrowing-lock'), so that these hook 12758`long-line-optimizations-region-size'.
12758functions cannot use `widen' to gain access to other portions of
12759buffer text.
12760 12759
12761See also `pre-command-hook'. */); 12760See also `pre-command-hook'. */);
12762 Vpost_command_hook = Qnil; 12761 Vpost_command_hook = Qnil;
diff --git a/src/xdisp.c b/src/xdisp.c
index 66c2d5e47f0..1cc83cf946c 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3536,11 +3536,11 @@ get_closer_narrowed_begv (struct window *w, ptrdiff_t pos)
3536ptrdiff_t 3536ptrdiff_t
3537get_locked_narrowing_begv (ptrdiff_t pos) 3537get_locked_narrowing_begv (ptrdiff_t pos)
3538{ 3538{
3539 if (long_line_locked_narrowing_region_size <= 0) 3539 if (long_line_optimizations_region_size <= 0)
3540 return BEGV; 3540 return BEGV;
3541 int len = long_line_locked_narrowing_region_size / 2; 3541 int len = long_line_optimizations_region_size / 2;
3542 int begv = max (pos - len, BEGV); 3542 int begv = max (pos - len, BEGV);
3543 int limit = long_line_locked_narrowing_bol_search_limit; 3543 int limit = long_line_optimizations_bol_search_limit;
3544 while (limit > 0) 3544 while (limit > 0)
3545 { 3545 {
3546 if (begv == BEGV || FETCH_BYTE (CHAR_TO_BYTE (begv) - 1) == '\n') 3546 if (begv == BEGV || FETCH_BYTE (CHAR_TO_BYTE (begv) - 1) == '\n')
@@ -3554,9 +3554,9 @@ get_locked_narrowing_begv (ptrdiff_t pos)
3554ptrdiff_t 3554ptrdiff_t
3555get_locked_narrowing_zv (ptrdiff_t pos) 3555get_locked_narrowing_zv (ptrdiff_t pos)
3556{ 3556{
3557 if (long_line_locked_narrowing_region_size <= 0) 3557 if (long_line_optimizations_region_size <= 0)
3558 return ZV; 3558 return ZV;
3559 int len = long_line_locked_narrowing_region_size / 2; 3559 int len = long_line_optimizations_region_size / 2;
3560 return min (pos + len, ZV); 3560 return min (pos + len, ZV);
3561} 3561}
3562 3562
@@ -4394,7 +4394,7 @@ handle_fontified_prop (struct it *it)
4394 eassert (it->end_charpos == ZV); 4394 eassert (it->end_charpos == ZV);
4395 4395
4396 if (current_buffer->long_line_optimizations_p 4396 if (current_buffer->long_line_optimizations_p
4397 && long_line_locked_narrowing_region_size > 0) 4397 && long_line_optimizations_region_size > 0)
4398 { 4398 {
4399 ptrdiff_t begv = it->locked_narrowing_begv; 4399 ptrdiff_t begv = it->locked_narrowing_begv;
4400 ptrdiff_t zv = it->locked_narrowing_zv; 4400 ptrdiff_t zv = it->locked_narrowing_zv;
@@ -4406,7 +4406,7 @@ handle_fontified_prop (struct it *it)
4406 } 4406 }
4407 if (begv != BEG || zv != Z) 4407 if (begv != BEG || zv != Z)
4408 narrow_to_region_locked (make_fixnum (begv), make_fixnum (zv), 4408 narrow_to_region_locked (make_fixnum (begv), make_fixnum (zv),
4409 Qfontification_functions); 4409 Qlong_line_optimizations_in_fontification_functions);
4410 } 4410 }
4411 4411
4412 /* Don't allow Lisp that runs from 'fontification-functions' 4412 /* Don't allow Lisp that runs from 'fontification-functions'
@@ -36313,6 +36313,8 @@ be let-bound around code that needs to disable messages temporarily. */);
36313 DEFSYM (QCfile, ":file"); 36313 DEFSYM (QCfile, ":file");
36314 DEFSYM (Qfontified, "fontified"); 36314 DEFSYM (Qfontified, "fontified");
36315 DEFSYM (Qfontification_functions, "fontification-functions"); 36315 DEFSYM (Qfontification_functions, "fontification-functions");
36316 DEFSYM (Qlong_line_optimizations_in_fontification_functions,
36317 "long-line-optimizations-in-fontification-functions");
36316 36318
36317 /* Name of the symbol which disables Lisp evaluation in 'display' 36319 /* Name of the symbol which disables Lisp evaluation in 'display'
36318 properties. This is used by enriched.el. */ 36320 properties. This is used by enriched.el. */
@@ -36822,12 +36824,11 @@ Each function is called with one argument POS. Functions must
36822fontify a region starting at POS in the current buffer, and give 36824fontify a region starting at POS in the current buffer, and give
36823fontified regions the property `fontified' with a non-nil value. 36825fontified regions the property `fontified' with a non-nil value.
36824 36826
36825Note that, when the buffer contains one or more lines whose length is 36827Note that, when `long-line-optimizations-p' is non-nil in the buffer,
36826above `long-line-threshold', these functions are called with the 36828these functions are called as if they were in a `with-restriction' form,
36827buffer narrowed to a small portion around POS (whose size is specified 36829with a `long-line-optimizations-in-fontification-functions' label and
36828by `long-line-locked-narrowing-region-size'), and the narrowing is 36830with the buffer narrowed to a portion around POS whose size is
36829locked (see `narrowing-lock'), so that these functions cannot use 36831specified by `long-line-optimizations-region-size'. */);
36830`widen' to gain access to other portions of buffer text. */);
36831 Vfontification_functions = Qnil; 36832 Vfontification_functions = Qnil;
36832 Fmake_variable_buffer_local (Qfontification_functions); 36833 Fmake_variable_buffer_local (Qfontification_functions);
36833 36834