]> git.eshelyaron.com Git - emacs.git/commitdiff
Use cl-with-gensyms in a few more cases
authorStefan Kangas <stefankangas@gmail.com>
Mon, 24 Feb 2025 22:02:20 +0000 (23:02 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 26 Feb 2025 09:37:23 +0000 (10:37 +0100)
* doc/misc/cl.texi (Macro Bindings):
* lisp/emacs-lisp/comp.el (comp--with-sp):
* lisp/emacs-lisp/subr-x.el (with-buffer-unmodified-if-unchanged):
* lisp/eshell/em-extpipe.el (eshell-extpipe--or-with-catch):
* lisp/international/mule-cmds.el (with-locale-environment):
* lisp/kmacro.el (kmacro-menu--marks-exist-p):
* test/lisp/emacs-lisp/cl-extra-tests.el (cl-lib-test-remprop):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-deduplicate):
* test/lisp/emacs-lisp/ert-tests.el (ert-test-special-operator-p):
* test/lisp/kmacro-tests.el (kmacro-tests-should-insert)
(kmacro-tests-should-match-message):
* test/lisp/replace-tests.el (replace-tests-with-undo): Use
cl-with-gensyms instead of bare gensym call.

(cherry picked from commit 1a22bc0fd672e2c71955faf81ff2cfd1c0c76be9)

doc/misc/cl.texi
lisp/emacs-lisp/comp.el
lisp/emacs-lisp/subr-x.el
lisp/eshell/em-extpipe.el
lisp/international/mule-cmds.el
lisp/kmacro.el
test/lisp/emacs-lisp/cl-extra-tests.el
test/lisp/emacs-lisp/edebug-tests.el
test/lisp/emacs-lisp/ert-tests.el
test/lisp/kmacro-tests.el
test/lisp/replace-tests.el

index 862b8f4a1c41a5919a193fabbd383e5b7808b12b..b4c1f29f47f82b2f0a9431674f5697d077f0710f 100644 (file)
@@ -1370,7 +1370,7 @@ expansion of another macro:
 
 @example
 (cl-defmacro my-dolist ((x list) &rest body)
-  (let ((var (cl-gensym)))
+  (cl-with-gensyms (var)
     (list 'cl-loop 'for var 'on list 'do
           (cl-list* 'cl-symbol-macrolet
                     (list (list x (list 'car var)))
index bd80a3890b007dd3d9f79ec9104c8027443cad84..8b57f48b7de57e0e9ca2890c48f46157024604bb 100644 (file)
@@ -953,7 +953,7 @@ Points to the next slot to be filled.")
 Restore the original value afterwards."
   (declare (debug (form body))
            (indent defun))
-  (let ((sym (gensym)))
+  (cl-with-gensyms (sym)
     `(let ((,sym (comp--sp)))
        (setf (comp--sp) ,sp)
        (progn ,@body)
index 368d7c106e398ea3b273f1d4e354fe40a4ba7a16..13f39f396182fc9bddbb74e2c8e5ae895158e995 100644 (file)
@@ -543,8 +543,7 @@ as changes in text properties, `buffer-file-coding-system', buffer
 multibyteness, etc. -- will not be noticed, and the buffer will still
 be marked unmodified, effectively ignoring those changes."
   (declare (debug t) (indent 0))
-  (let ((hash (gensym))
-        (buffer (gensym)))
+  (cl-with-gensyms (hash buffer)
     `(let ((,hash (and (not (buffer-modified-p))
                        (buffer-hash)))
            (,buffer (current-buffer)))
index 6a061dad89e8e5441acb308d7a5ddc42ceec81d6..c5170fed8302c550e1716c9fb95ad26441560e81 100644 (file)
@@ -69,7 +69,7 @@ again."
 
 If `eshell-incomplete' is thrown during the evaluation of a
 disjunct, that disjunct yields nil."
-  (let ((result (gensym)))
+  (cl-with-gensyms (result)
     `(let (,result)
        (or ,@(cl-loop for disjunct in disjuncts collect
                       `(if (catch 'eshell-incomplete
index 0cbc434a47843303f1c1e5c1712323fe005a3c1c..f6f3f56417ebe0e1f8f8b3d6a651d03c2d3cebf4 100644 (file)
@@ -2669,7 +2669,7 @@ but this macro does not by itself perform redisplay.  If BODY needs to
 display something with LOCALE-NAME's settings, include a call
 to `redraw-frame' in BODY."
   (declare (indent 1) (debug (sexp def-body)))
-  (let ((current (gensym)))
+  (cl-with-gensyms (current)
     `(let ((,current current-locale-environment))
        (unwind-protect
            (progn
index 53029fdc19511631bd71dfc0bf218522a8565b00..faf21e8245219cce52e506d5fc663489d8ad0483 100644 (file)
@@ -1681,7 +1681,7 @@ line after applying FUNCTION."
 
 (defun kmacro-menu--marks-exist-p ()
   "Return non-nil if markers exist for any table entries."
-  (let ((tag (gensym)))
+  (cl-with-gensyms (tag)
     (catch tag
       (kmacro-menu--map-ids (lambda (id)
                               (when (alist-get (kmacro-menu--id-position id)
index 41753194c1b2d17c7233e5c336a3bec3b58a1ada..20d1e532a6f91c5bf0277a5d625af21e6ee7c46e 100644 (file)
@@ -23,7 +23,7 @@
 (require 'ert)
 
 (ert-deftest cl-lib-test-remprop ()
-  (let ((x (cl-gensym)))
+  (cl-with-gensyms (x)
     (should (equal (symbol-plist x) '()))
     ;; Remove nonexistent property on empty plist.
     (cl-remprop x 'b)
index 02eadd34c8df99ce87a2b654b72cfeb3fe4178cf..7daacea7925a428a0728c08399c6f4cb6cc2e8e5 100644 (file)
@@ -321,8 +321,7 @@ NAME should be a string and NAMES-AND-NUMBERS an alist which can
 be used by this macro to retain state.  If NAME for example is
 \"symbol\" then the first and subsequent uses of this macro will
 evaluate to \"symbol\", \"symbol-1\", \"symbol-2\", etc."
-  (let ((g-name (gensym))
-        (g-duplicate (gensym)))
+  (cl-with-gensyms (g-name g-duplicate)
     `(let* ((,g-name ,name)
             (,g-duplicate (assoc ,g-name ,names-and-numbers)))
        (if (null ,g-duplicate)
index 75b40d0db11f48b2aa06d236eeae1bea18ba497c..c729028279af96ecad25c00bb9972a23e02a6769 100644 (file)
@@ -617,7 +617,7 @@ This macro is used to test if macroexpansion in `should' works."
   (should (ert--special-operator-p 'if))
   (should-not (ert--special-operator-p 'car))
   (should-not (ert--special-operator-p 'ert--special-operator-p))
-  (let ((b (cl-gensym)))
+  (cl-with-gensyms (b)
     (should-not (ert--special-operator-p b))
     (fset b 'if)
     (should (ert--special-operator-p b))))
index 356700bbcb0cb26f3ec36a18c424b16f4d0ada03..f43dedcdd743764a9c1f1aa84cf392b195c3e37b 100644 (file)
@@ -24,6 +24,7 @@
 ;;; Code:
 
 (require 'kmacro)
+(require 'cl-lib)
 (require 'seq)
 (require 'ert)
 (require 'ert-x)
@@ -157,8 +158,7 @@ Execute BODY, then check that the string VALUE was inserted
 into the current buffer at point."
   (declare (debug (stringp body))
            (indent 1))
-  (let ((g-p (cl-gensym))
-        (g-bsize (cl-gensym)))
+  (cl-with-gensyms (g-p g-bsize)
     `(let ((,g-p (point))
            (,g-bsize (buffer-size)))
        ,@body
@@ -172,7 +172,7 @@ VALUE and any text written to *Messages* during the execution,
 cause the current test to fail."
   (declare (debug (form body))
            (indent 1))
-  (let ((g-captured-messages (cl-gensym)))
+  (cl-with-gensyms (g-captured-messages)
     `(ert-with-message-capture ,g-captured-messages
        ,@body
        (should (string-match-p ,value ,g-captured-messages)))))
index 07a065626f3364cb241057563286d97014be565d..288e8865dc5566a882f52c6527e787e9e562c428 100644 (file)
@@ -528,8 +528,7 @@ then replace 3 matches of FROM with TO, and undo the last replacement.
 
 Return the last evalled form in BODY."
   (declare (indent 5) (debug (stringp stringp stringp form characterp body)))
-  (let ((text (gensym "text"))
-        (count (gensym "count")))
+  (cl-with-gensyms (text count)
     `(let* ((,text ,input)
             (,count 0)
             (inhibit-message t))