diff options
author | Andrea Corallo <akrl@sdf.org> | 2023-02-17 11:14:38 +0100 |
---|---|---|
committer | Andrea Corallo <akrl@sdf.org> | 2023-02-17 11:14:38 +0100 |
commit | d6e4f2437202f13bec85d68c003700d06aa343e6 (patch) | |
tree | c8cffc88721cc9a82b5565189d42c91effa296ec /lisp/subr.el | |
parent | ce4a066ed1ea07f651f439132017db8ceb32779c (diff) | |
parent | a555abc56d5270cebe94f904189526d7ac433a94 (diff) | |
download | emacs-d6e4f2437202f13bec85d68c003700d06aa343e6.tar.gz |
Merge 'emacs-29' into 'feature/inhibit-native-comp-cleanup'
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index db33483f509..a0a22072a18 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3946,30 +3946,51 @@ See also `locate-user-emacs-file'.") "Return non-nil if the current buffer is narrowed." (/= (- (point-max) (point-min)) (buffer-size))) -(defmacro with-narrowing (start end &rest rest) +(defmacro with-restriction (start end &rest rest) "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)" - (if (eq (car rest) :locked) - `(internal--with-narrowing ,start ,end (lambda () ,@(cddr rest)) +\(fn START END [:label LABEL] BODY)" + (if (eq (car rest) :label) + `(internal--with-restriction ,start ,end (lambda () ,@(cddr rest)) ,(cadr rest)) - `(internal--with-narrowing ,start ,end (lambda () ,@rest)))) + `(internal--with-restriction ,start ,end (lambda () ,@rest)))) -(defun internal--with-narrowing (start end body &optional tag) - "Helper function for `with-narrowing', which see." +(defun internal--with-restriction (start end body &optional label) + "Helper function for `with-restriction', 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-restriction (&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-restriction' with the same LABEL argument +are lifted. + +\(fn [:label LABEL] BODY)" + (if (eq (car rest) :label) + `(internal--without-restriction (lambda () ,@(cddr rest)) + ,(cadr rest)) + `(internal--without-restriction (lambda () ,@rest)))) + +(defun internal--without-restriction (body &optional label) + "Helper function for `without-restriction', 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. |