aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorGregory Heytings2022-11-27 22:19:41 +0100
committerGregory Heytings2022-11-27 22:19:41 +0100
commit849223fba1ef899f90a6edff05bce24b90fbb043 (patch)
treeb5ab707f2da7d13ba2cb10c8af441547152c83ef /lisp
parent89a10ffcc49c5832619649b7876cc339fa9d0dcf (diff)
parent18fa159fa91b515f2281b83648961fdc5e21aca7 (diff)
downloademacs-849223fba1ef899f90a6edff05bce24b90fbb043.tar.gz
emacs-849223fba1ef899f90a6edff05bce24b90fbb043.zip
Merge branch 'feature/improved-locked-narrowing'
Diffstat (limited to 'lisp')
-rw-r--r--lisp/subr.el25
1 files changed, 25 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 4f671de918b..cfce5b18c55 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3936,6 +3936,31 @@ See also `locate-user-emacs-file'.")
3936 "Return non-nil if the current buffer is narrowed." 3936 "Return non-nil if the current buffer is narrowed."
3937 (/= (- (point-max) (point-min)) (buffer-size))) 3937 (/= (- (point-max) (point-min)) (buffer-size)))
3938 3938
3939(defmacro with-narrowing (start end &rest rest)
3940 "Execute BODY with restrictions set to START and END.
3941
3942The current restrictions, if any, are restored upon return.
3943
3944With the optional :locked TAG argument, inside BODY,
3945`narrow-to-region' and `widen' can be used only within the START
3946and END limits, unless the restrictions are unlocked by calling
3947`narrowing-unlock' with TAG. See `narrowing-lock' for a more
3948detailed description.
3949
3950\(fn START END [:locked TAG] BODY)"
3951 (if (eq (car rest) :locked)
3952 `(internal--with-narrowing ,start ,end (lambda () ,@(cddr rest))
3953 ,(cadr rest))
3954 `(internal--with-narrowing ,start ,end (lambda () ,@rest))))
3955
3956(defun internal--with-narrowing (start end body &optional tag)
3957 "Helper function for `with-narrowing', which see."
3958 (save-restriction
3959 (progn
3960 (narrow-to-region start end)
3961 (if tag (narrowing-lock tag))
3962 (funcall body))))
3963
3939(defun find-tag-default-bounds () 3964(defun find-tag-default-bounds ()
3940 "Determine the boundaries of the default tag, based on text at point. 3965 "Determine the boundaries of the default tag, based on text at point.
3941Return a cons cell with the beginning and end of the found tag. 3966Return a cons cell with the beginning and end of the found tag.