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.
This commit is contained in:
parent
1bf0b72eb7
commit
321d4e6155
2 changed files with 13 additions and 15 deletions
18
lisp/subr.el
18
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 ()
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue