summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorGregory Heytings <gregory@heytings.org>2023-02-09 01:09:10 +0000
committerGregory Heytings <gregory@heytings.org>2023-02-09 02:44:41 +0100
commitd8438e2bb44f448d1a0653321a8f262a1b6a3f2b (patch)
tree4b17d4c6f1da355d9a5867cd1ddb690ddcbc2ea0 /lisp/subr.el
parent97314447e609e673be060bcdf0f244f396a70a3a (diff)
downloademacs-d8438e2bb44f448d1a0653321a8f262a1b6a3f2b.tar.gz
Add 'without-narrowing' macro
* lisp/subr.el (without-narrowing): New macro, companion (and almost identical) to 'with-narrowing'.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el27
1 files changed, 23 insertions, 4 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 5cc0c94ba48..af3f1f1abd5 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3952,18 +3952,37 @@ 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)
+\(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 (internal--lock-narrowing tag))
+ (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.
+
+\(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
+ (progn
+ (if label (internal--unlock-narrowing label))
+ (widen)
(funcall body))))
(defun find-tag-default-bounds ()