summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorStefan Kangas <stefankangas@gmail.com>2023-02-15 14:41:04 +0100
committerStefan Kangas <stefankangas@gmail.com>2023-02-15 14:41:04 +0100
commit142f5683c1042a5344abd51b97fe8e0d0c8cc5f5 (patch)
tree5c66b054ed4cb2317e5fd6caa359bf812748de10 /lisp/subr.el
parent571558e460059b3756f592abaaf2a9a67778db66 (diff)
parent7678b7e46f2e394447f39c3a6cf02bc285e5a5a4 (diff)
downloademacs-142f5683c1042a5344abd51b97fe8e0d0c8cc5f5.tar.gz
Merge from origin/emacs-29
7678b7e46f2 Eglot: check server capability before sending didSave (bu... a3a1ef7bd5e Fix rust-ts-mode type and module highlighting (Bug#61302) 477aa047ee7 rust-ts-mode: Highlight variable reassignments 5206a551c16 Improve backward compatibility of save-restriction accd88d5545 Don't indent template_string contents (bug#61503) d97a3839967 csharp-ts-mode: fontify compiler directives (bug#61512) 420d2cae846 Update to Transient v0.3.7-209-gdab1dfa a3751b5d0c1 ; Raise an error if a VC package checkout is empty 6a32ba8b69c ; Fix the installation of dependencies for VC packages 4eac80fcc39 ; Prepare to update ERC version to 5.5 4f099a72173 ; Remove failing erc-reuse-buffers test 4bb27a5ca93 ; Minor docs copyedits 13bcff3da5c Merge branch 'emacs-29' of git.savannah.gnu.org:/srv/git/... 3d572ae0d50 Rename with/without-narrowing to with/without-restriction d806b0e33cf * lisp/repeat.el: Rename internal function and variable (... dd8b720ee74 ; * etc/NEWS: Fix typos. 909bd04cf5f ; * lisp/calendar/lunar.el: Add comments. (bug#61460) 10f2aedea9a ; * lisp/progmodes/c-ts-mode.el (c-ts-base-mode): delete ... 865758130a1 ; * admin/git-bisect-start: Update failing commits b948d0d7efe Merge branch 'scratch/fix-locked-narrowing' dcb2379a463 Minor improvements to labeled narrowing cc30422825a Fix spurious display of eclipses in Calendar f2114e8d89f Fix indentation for closing bracket in c-ts-mode (bug#61398) f49caaa8925 ; * src/pdumper.c (dump_buffer): Update hash. fe2ea5ddd8d Update to Org 9.6.1-31-gaf1bb1 8280d721d7c * src/.gdbinit (nextcons): Amend $.u.cdr to $.u.s.u.cdr (... eb2b0931cf1 Add lambda_expression to c-ts-common-indent-type-regexp-a... 2da05876edb ; Use the right name when specifying VC packages d4fc7012978 Tolerate missing elpa-packages.eld files 8bc1b7d0b27 Avoid warning about 'load-path' in non-interactive sessions 3d17aee13d9 ; Fix installation of dependencies for VC packages 86ca7df6a34 ; Mention Hunspell private-dictionary misfeature in doc s... 7287b7b53a1 Support webkit2gtk-4.1 048a2dabfc4 ; Fix typo 8f3091defb3 ; Fix typo in buffer.h 4da398d8b57 ; Fix typos 074008ee2d2 ; Fix doc strings in lisp/image/ directory 2d1e43436da ; Improve documentation of hash functions. 900f7e07275 ; Remove extraneous local variables from image-dired-*.el... 4297039bd13 Save and restore the absence of narrowing locks 4f053afe8e7 bug-reference: prevent match-data clobbering (bug#61395) 10af9fbcad1 ; * admin/notes/tree-sitter/starter-guide: Typos. 9ac242ce93d ; Fix recent changes in treesit docs f5789aefc2e Rename LIMIT to DEPTH in tree-sitter functions (bug#61231) b39821fdcef ; Fix incorrect function name in treesit manual 51901736965 Add 'live' property to treesit-node-check (bug#61235) 56960a6558b Update to Transient v0.3.7-205-gb8ad0da 68a6b364d1c Fix 'rmail-summary-output' 67c6ec25590 lisp-mode: add docstring recognition for more common lisp... 417a8ed8b05 ; Improve discoverability of empty file names handling e47cf6ca15a Update to Transient v0.3.7-204-gecff8c2 b04cce02ff4 Fix Scala entry in Eglot's DB of LSP servers 973c1d24c6a ruby-ts-mode: Also don't reindent 'identifier' when insid... a5651c0c403 ruby-ts-mode: Fix indentation inside empty if/unless/case... 2956e54b1dd Add an extensive test for labeled (locked) narrowing 79ce185ad13 Update the documentation about labeled (locked) narrowing a6cd4553d48 Rename two long line optimizations variables 0d73e4aa261 Add specific symbols for narrowings d8438e2bb44 Add 'without-narrowing' macro 97314447e60 Make 'narrowing-lock' and 'narrowing-unlock' internal a4aa32bdfff Fix 'save-restriction' for narrowing locks # Conflicts: # etc/NEWS
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el53
1 files changed, 37 insertions, 16 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index a5fc566cc74..a1397fa6781 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3963,30 +3963,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.