aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory Heytings2023-07-06 17:04:53 +0000
committerGregory Heytings2023-07-06 17:14:17 +0000
commitb741dc7fcde0c601a01470655ceaeeef854ac32e (patch)
treee51a18878cf3197c5afa29ad5a5b6ee186a9a97a
parent9b38773a20b43e2354ddf036ffa28e397537da3f (diff)
downloademacs-b741dc7fcde0c601a01470655ceaeeef854ac32e.tar.gz
emacs-b741dc7fcde0c601a01470655ceaeeef854ac32e.zip
Add internal function to enter a labeled restriction
* src/editfns.c (Finternal__labeled_narrow_to_region): New function. A specific function is necessary to avoid unnecessary slowdowns when 'narrow-to-region'/'widen' are called in a loop. (Fnarrow_to_region): Remove the call to Fset, which has been moved into Finternal__labeled_narrow_to_region. (labeled_narrow_to_region): Use the new function. (syms_of_editfns): Add the symbol of the new function. * lisp/subr.el (internal--with-restriction): Use the new function.
-rw-r--r--lisp/subr.el5
-rw-r--r--src/editfns.c29
2 files changed, 23 insertions, 11 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 85adef5b689..0b397b7bebf 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3980,8 +3980,9 @@ same LABEL argument.
3980(defun internal--with-restriction (start end body &optional label) 3980(defun internal--with-restriction (start end body &optional label)
3981 "Helper function for `with-restriction', which see." 3981 "Helper function for `with-restriction', which see."
3982 (save-restriction 3982 (save-restriction
3983 (narrow-to-region start end) 3983 (if label
3984 (if label (internal--label-restriction label)) 3984 (internal--labeled-narrow-to-region start end label)
3985 (narrow-to-region start end))
3985 (funcall body))) 3986 (funcall body)))
3986 3987
3987(defmacro without-restriction (&rest rest) 3988(defmacro without-restriction (&rest rest)
diff --git a/src/editfns.c b/src/editfns.c
index a1e48daf6c6..49c5c1f7b2f 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2868,8 +2868,7 @@ void
2868labeled_narrow_to_region (Lisp_Object begv, Lisp_Object zv, 2868labeled_narrow_to_region (Lisp_Object begv, Lisp_Object zv,
2869 Lisp_Object label) 2869 Lisp_Object label)
2870{ 2870{
2871 Fnarrow_to_region (begv, zv); 2871 Finternal__labeled_narrow_to_region (begv, zv, label);
2872 Finternal__label_restriction (label);
2873 record_unwind_protect (restore_point_unwind, Fpoint_marker ()); 2872 record_unwind_protect (restore_point_unwind, Fpoint_marker ());
2874 record_unwind_protect (unwind_labeled_narrow_to_region, label); 2873 record_unwind_protect (unwind_labeled_narrow_to_region, label);
2875} 2874}
@@ -2967,13 +2966,6 @@ argument. To gain access to other portions of the buffer, use
2967 if (e > zv_charpos) e = zv_charpos; 2966 if (e > zv_charpos) e = zv_charpos;
2968 } 2967 }
2969 2968
2970 /* Record the accessible range of the buffer when narrow-to-region
2971 is called, that is, before applying the narrowing. That
2972 information is used only by internal--label-restriction. */
2973 Fset (Qoutermost_restriction, list3 (Qoutermost_restriction,
2974 Fpoint_min_marker (),
2975 Fpoint_max_marker ()));
2976
2977 if (BEGV != s || ZV != e) 2969 if (BEGV != s || ZV != e)
2978 current_buffer->clip_changed = 1; 2970 current_buffer->clip_changed = 1;
2979 2971
@@ -3011,6 +3003,24 @@ This is an internal function used by `with-restriction'. */)
3011 return Qnil; 3003 return Qnil;
3012} 3004}
3013 3005
3006DEFUN ("internal--labeled-narrow-to-region", Finternal__labeled_narrow_to_region,
3007 Sinternal__labeled_narrow_to_region, 3, 3, 0,
3008 doc: /* Restrict editing to START-END, and label the restriction with LABEL.
3009
3010This is an internal function used by `with-restriction'. */)
3011 (Lisp_Object start, Lisp_Object end, Lisp_Object label)
3012{
3013 /* Record the accessible range of the buffer when narrow-to-region
3014 is called, that is, before applying the narrowing. That
3015 information is used only by internal--label-restriction. */
3016 Fset (Qoutermost_restriction, list3 (Qoutermost_restriction,
3017 Fpoint_min_marker (),
3018 Fpoint_max_marker ()));
3019 Fnarrow_to_region (start, end);
3020 Finternal__label_restriction (label);
3021 return Qnil;
3022}
3023
3014DEFUN ("internal--unlabel-restriction", Finternal__unlabel_restriction, 3024DEFUN ("internal--unlabel-restriction", Finternal__unlabel_restriction,
3015 Sinternal__unlabel_restriction, 1, 1, 0, 3025 Sinternal__unlabel_restriction, 1, 1, 0,
3016 doc: /* If the current restriction is labeled with LABEL, remove its label. 3026 doc: /* If the current restriction is labeled with LABEL, remove its label.
@@ -4964,6 +4974,7 @@ it to be non-nil. */);
4964 defsubr (&Swiden); 4974 defsubr (&Swiden);
4965 defsubr (&Snarrow_to_region); 4975 defsubr (&Snarrow_to_region);
4966 defsubr (&Sinternal__label_restriction); 4976 defsubr (&Sinternal__label_restriction);
4977 defsubr (&Sinternal__labeled_narrow_to_region);
4967 defsubr (&Sinternal__unlabel_restriction); 4978 defsubr (&Sinternal__unlabel_restriction);
4968 defsubr (&Ssave_restriction); 4979 defsubr (&Ssave_restriction);
4969 defsubr (&Stranspose_regions); 4980 defsubr (&Stranspose_regions);