aboutsummaryrefslogtreecommitdiff
path: root/compat-29.el
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-02-13 22:17:22 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-02-13 22:20:12 +0100
commitc81ff6a92f74a4ca47da05db46f6b3f69882271e (patch)
tree6a4d92bf797f568ac0d32a6a6e6fe0b94c56b30a /compat-29.el
parentb2930079f10a843f70a7cb2e4ce0772a5e959180 (diff)
compat-29: with-narrowing -> with-restriction, without-restriction
Diffstat (limited to 'compat-29.el')
-rw-r--r--compat-29.el31
1 files changed, 23 insertions, 8 deletions
diff --git a/compat-29.el b/compat-29.el
index 9cf4a76..d394f09 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -294,22 +294,37 @@ in order to restore the state of the local variables set via this macro.
"Delete the current line."
(delete-region (pos-bol) (pos-bol 2)))
-(compat-defmacro with-narrowing (start end &rest rest) ;; <compat-tests:with-narrowing>
+(compat-defmacro with-restriction (start end &rest rest) ;; <compat-tests:with-restriction>
"Execute BODY with restrictions set to START and END.
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.
+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-restriction' with the
+same LABEL argument.
-\(fn START END [:locked TAG] BODY)"
+\(fn START END [:label LABEL] BODY)"
`(save-restriction
(narrow-to-region ,start ,end)
;; Locking is ignored
- ,@(if (eq (car rest) :locked) (cddr rest) rest)))
+ ,@(if (eq (car rest) :label) (cddr rest) rest)))
+
+(compat-defmacro without-restriction (&rest rest) ;; <compat-tests:without-restriction>
+ "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-restriction' with the same LABEL argument
+are lifted.
+
+\(fn [:label LABEL] BODY)"
+ `(save-restriction
+ (widen)
+ ;; Locking is ignored
+ ,@(if (eq (car rest) :label) (cddr rest) rest)))
(compat-defmacro with-memoization (place &rest code) ;; <compat-tests:with-memoization>
"Return the value of CODE and stash it in PLACE.