emacs-diffs
[Top][All Lists]
Advanced

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

master c287a0fdc7e 3/5: Simplify 'with-restriction' and 'without-restric


From: Gregory Heytings
Subject: master c287a0fdc7e 3/5: Simplify 'with-restriction' and 'without-restriction'
Date: Wed, 16 Aug 2023 12:07:12 -0400 (EDT)

branch: master
commit c287a0fdc7e3f70d819ef8efd1d7922b33df164c
Author: Gregory Heytings <gregory@heytings.org>
Commit: Gregory Heytings <gregory@heytings.org>

    Simplify 'with-restriction' and 'without-restriction'
    
    * lisp/subr.el (with-restriction, without-restriction): Merge the
    bodies of the 'internal--with-restriction' and
    'internal--without-restriction' function into the macros.  The
    result is more efficient than a funcall.
    (internal--with-restriction, internal--without-restriction):
    Remove.
    Suggested by Mattias EngdegÄrd.
---
 lisp/subr.el | 28 ++++++----------------------
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 08e6f816dee..616f0a8dfb6 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4116,17 +4116,10 @@ buffer, use `without-restriction' with the same LABEL 
argument.
 \(fn START END [:label LABEL] BODY)"
   (declare (indent 2) (debug t))
   (if (eq (car rest) :label)
-      `(internal--with-restriction ,start ,end (lambda () ,@(cddr rest))
-                                 ,(cadr rest))
-    `(internal--with-restriction ,start ,end (lambda () ,@rest))))
-
-(defun internal--with-restriction (start end body &optional label)
-  "Helper function for `with-restriction', which see."
-  (save-restriction
-    (if label
-        (internal--labeled-narrow-to-region start end label)
-      (narrow-to-region start end))
-    (funcall body)))
+      `(save-restriction
+         (internal--labeled-narrow-to-region ,start ,end ,(cadr rest))
+         ,@(cddr rest))
+    `(save-restriction (narrow-to-region ,start ,end) ,@rest)))
 
 (defmacro without-restriction (&rest rest)
   "Execute BODY without restrictions.
@@ -4139,17 +4132,8 @@ by `with-restriction' with the same LABEL argument are 
lifted.
 \(fn [:label LABEL] BODY)"
   (declare (indent 0) (debug t))
   (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--labeled-widen label)
-      (widen))
-    (funcall body)))
+      `(save-restriction (internal--labeled-widen ,(cadr rest)) ,@(cddr rest))
+    `(save-restriction (widen) ,@rest)))
 
 (defun find-tag-default-bounds ()
   "Determine the boundaries of the default tag, based on text at point.



reply via email to

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