summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorGregory Heytings <gregory@heytings.org>2022-08-20 16:06:15 +0000
committerGregory Heytings <gregory@heytings.org>2022-08-20 18:08:41 +0200
commit2727af3fd448e39f79e130c42286e85a51bf7a40 (patch)
tree38eb7298fda62f15457f8cc0a5d42c53020bd795 /lisp/subr.el
parent07c04da01016cd81e064a06b2449892eff7c8da0 (diff)
downloademacs-2727af3fd448e39f79e130c42286e85a51bf7a40.tar.gz
emacs-2727af3fd448e39f79e130c42286e85a51bf7a40.tar.bz2
emacs-2727af3fd448e39f79e130c42286e85a51bf7a40.zip
Improved locked narrowing.
* src/editfns.c (Fnarrowing_lock, Fnarrowing_unlock, narrow_to_region_locked, unwind_narrow_to_region_locked): New functions. (Fnarrow_to_region, Fwiden): Adapt, and make it possible to use these functions within the bounds of the locked narrowing. (syms_of_editfns): Change the name of the variable, make it buffer-local, and add the two Snarrowing_lock and Snarrowing_unlock subroutines. * src/lisp.h: Prototype of 'narrow_to_region_locked'. * src/xdisp.c (handle_fontified_prop): * src/keyboard.c (safe_run_hooks_maybe_narrowed): Use 'narrow_to_region_locked'. * lisp/subr.el (with-locked-narrowing): New macro.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el14
1 files changed, 14 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index cd6a9be099c..35c8e086e3a 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3914,6 +3914,20 @@ See also `locate-user-emacs-file'.")
"Return non-nil if the current buffer is narrowed."
(/= (- (point-max) (point-min)) (buffer-size)))
+(defmacro with-locked-narrowing (start end tag &rest body)
+ "Execute BODY with restrictions set to START and END and locked with TAG.
+
+Inside BODY, `narrow-to-region' and `widen' can be used only
+within the START and END limits, unless the restrictions are
+unlocked by calling `narrowing-unlock' with TAG."
+ `(unwind-protect
+ (progn
+ (narrow-to-region ,start ,end)
+ (narrowing-lock ,tag)
+ ,@body)
+ (narrowing-unlock ,tag)
+ (widen)))
+
(defun find-tag-default-bounds ()
"Determine the boundaries of the default tag, based on text at point.
Return a cons cell with the beginning and end of the found tag.