summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorGregory Heytings <gregory@heytings.org>2023-02-13 11:44:37 +0100
committerGregory Heytings <gregory@heytings.org>2023-02-13 11:44:37 +0100
commitb948d0d7efe4c73a34485238d6a4e1bb5f0cac9e (patch)
tree3c1fc837f7094c21d1d35f1e66c657020908ea7f /lisp/subr.el
parentcc30422825a5acf460d026bfe912b327b70dedcf (diff)
parentdcb2379a463678bdadd05ee39d61e7da84c71c5e (diff)
downloademacs-b948d0d7efe4c73a34485238d6a4e1bb5f0cac9e.tar.gz
Merge branch 'scratch/fix-locked-narrowing'
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el47
1 files changed, 34 insertions, 13 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 9e6388987df..58a8e85b61d 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3946,25 +3946,46 @@ See also `locate-user-emacs-file'.")
The current restrictions, if any, are restored upon return.
-With the optional :locked TAG argument, 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. See `narrowing-lock' for a more
-detailed description.
-
-\(fn START END [:locked TAG] BODY)"
- (if (eq (car rest) :locked)
+When the optional :label LABEL argument is present, in which
+LABEL is a symbol, inside BODY, `narrow-to-region' and `widen'
+can be used only within the START and END limits. To gain access
+to other portions of the buffer, use `without-narrowing' with the
+same LABEL argument.
+
+\(fn START END [:label LABEL] BODY)"
+ (if (eq (car rest) :label)
`(internal--with-narrowing ,start ,end (lambda () ,@(cddr rest))
,(cadr rest))
`(internal--with-narrowing ,start ,end (lambda () ,@rest))))
-(defun internal--with-narrowing (start end body &optional tag)
+(defun internal--with-narrowing (start end body &optional label)
"Helper function for `with-narrowing', which see."
(save-restriction
- (progn
- (narrow-to-region start end)
- (if tag (narrowing-lock tag))
- (funcall body))))
+ (narrow-to-region start end)
+ (if label (internal--lock-narrowing label))
+ (funcall body)))
+
+(defmacro without-narrowing (&rest rest)
+ "Execute BODY without restrictions.
+
+The current restrictions, if any, are restored upon return.
+
+When the optional :label LABEL argument is present, the
+restrictions set by `with-narrowing' with the same LABEL argument
+are lifted.
+
+\(fn [:label LABEL] BODY)"
+ (if (eq (car rest) :label)
+ `(internal--without-narrowing (lambda () ,@(cddr rest))
+ ,(cadr rest))
+ `(internal--without-narrowing (lambda () ,@rest))))
+
+(defun internal--without-narrowing (body &optional label)
+ "Helper function for `without-narrowing', which see."
+ (save-restriction
+ (if label (internal--unlock-narrowing label))
+ (widen)
+ (funcall body)))
(defun find-tag-default-bounds ()
"Determine the boundaries of the default tag, based on text at point.