emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/improved-locked-narrowing 321d4e6155: Minor improvements for loc


From: Gregory Heytings
Subject: feature/improved-locked-narrowing 321d4e6155: Minor improvements for locked narrowing
Date: Sat, 26 Nov 2022 17:39:04 -0500 (EST)

branch: feature/improved-locked-narrowing
commit 321d4e61551a0f6dfb1abfc0b54e6177735bde58
Author: Gregory Heytings <gregory@heytings.org>
Commit: Gregory Heytings <gregory@heytings.org>

    Minor improvements for locked narrowing
    
    * src/editfns.c (narrowing_lock_pop): Clarify comment, replace
    assertion by return.
    (narrowing_locks_restore): Add comments.
    
    * lisp/subr.el (with-narrowing, internal--with-narrowing):
    Simplify, use a single helper function with an optional argument.
---
 lisp/subr.el  | 18 +++++-------------
 src/editfns.c | 10 ++++++++--
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index b83805e898..3d5efec761 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3948,24 +3948,16 @@ detailed description.
 
 \(fn START END [:locked TAG] BODY)"
   (if (eq (car rest) :locked)
-      `(with-narrowing-1 ,start ,end ,(cadr rest)
-                         (lambda () ,@(cddr rest)))
-    `(with-narrowing-2 ,start ,end
-                       (lambda () ,@rest))))
+      `(internal--with-narrowing ,start ,end (lambda () ,@(cddr rest))
+                                 ,(cadr rest))
+    `(internal--with-narrowing ,start ,end (lambda () ,@rest))))
 
-(defun with-narrowing-1 (start end tag body)
-  "Helper function for `with-narrowing', which see."
-  (save-restriction
-    (progn
-      (narrow-to-region start end)
-      (narrowing-lock tag)
-      (funcall body))))
-
-(defun with-narrowing-2 (start end body)
+(defun internal--with-narrowing (start end body &optional tag)
   "Helper function for `with-narrowing', which see."
   (save-restriction
     (progn
       (narrow-to-region start end)
+      (if tag (narrowing-lock tag))
       (funcall body))))
 
 (defun find-tag-default-bounds ()
diff --git a/src/editfns.c b/src/editfns.c
index 5bfb0b86d1..e99a007a70 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2712,12 +2712,14 @@ narrowing_lock_push (Lisp_Object buf, Lisp_Object lock)
                                          XCAR (XCDR (buffer_locks)))));
 }
 
-/* Remove the innermost lock in BUF from the narrowing_lock alist.  */
+/* Remove the innermost lock in BUF from the narrowing_lock alist.
+   Do nothing if BUF is not in narrowing_lock.  */
 static void
 narrowing_lock_pop (Lisp_Object buf)
 {
   Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks);
-  eassert (! NILP (buffer_locks));
+  if (NILP (buffer_locks))
+    return;
   if (EQ (narrowing_lock_peek_tag (buf), Qoutermost_narrowing))
     narrowing_locks = Fdelq (Fassoc (buf, narrowing_locks, Qnil),
                             narrowing_locks);
@@ -2779,8 +2781,12 @@ narrowing_locks_restore (Lisp_Object buf_and_saved_locks)
   if (NILP (buf_and_saved_locks))
     return;
   Lisp_Object buf = XCAR (buf_and_saved_locks);
+  /* This cannot fail when buf_and_saved_locks was returned by
+     narrowing_locks_save.  */
   eassert (BUFFERP (buf));
   Lisp_Object saved_locks = XCDR (buf_and_saved_locks);
+  /* This cannot fail when buf_and_saved_locks was returned by
+     narrowing_locks_save.  */
   eassert (! NILP (saved_locks));
   Lisp_Object current_locks = assq_no_quit (buf, narrowing_locks);
   if (! NILP (current_locks))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]