1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 02:31:03 -08:00

Use cl-with-gensyms in a few more cases

* 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.
This commit is contained in:
Stefan Kangas 2025-02-24 23:02:20 +01:00
parent 7bb53815d2
commit 1a22bc0fd6
11 changed files with 13 additions and 16 deletions

View file

@ -1370,7 +1370,7 @@ expansion of another macro:
@example @example
(cl-defmacro my-dolist ((x list) &rest body) (cl-defmacro my-dolist ((x list) &rest body)
(let ((var (cl-gensym))) (cl-with-gensyms (var)
(list 'cl-loop 'for var 'on list 'do (list 'cl-loop 'for var 'on list 'do
(cl-list* 'cl-symbol-macrolet (cl-list* 'cl-symbol-macrolet
(list (list x (list 'car var))) (list (list x (list 'car var)))

View file

@ -953,7 +953,7 @@ Points to the next slot to be filled.")
Restore the original value afterwards." Restore the original value afterwards."
(declare (debug (form body)) (declare (debug (form body))
(indent defun)) (indent defun))
(let ((sym (gensym))) (cl-with-gensyms (sym)
`(let ((,sym (comp--sp))) `(let ((,sym (comp--sp)))
(setf (comp--sp) ,sp) (setf (comp--sp) ,sp)
(progn ,@body) (progn ,@body)

View file

@ -551,8 +551,7 @@ as changes in text properties, `buffer-file-coding-system', buffer
multibyteness, etc. -- will not be noticed, and the buffer will still multibyteness, etc. -- will not be noticed, and the buffer will still
be marked unmodified, effectively ignoring those changes." be marked unmodified, effectively ignoring those changes."
(declare (debug t) (indent 0)) (declare (debug t) (indent 0))
(let ((hash (gensym)) (cl-with-gensyms (hash buffer)
(buffer (gensym)))
`(let ((,hash (and (not (buffer-modified-p)) `(let ((,hash (and (not (buffer-modified-p))
(buffer-hash))) (buffer-hash)))
(,buffer (current-buffer))) (,buffer (current-buffer)))

View file

@ -69,7 +69,7 @@ again."
If `eshell-incomplete' is thrown during the evaluation of a If `eshell-incomplete' is thrown during the evaluation of a
disjunct, that disjunct yields nil." disjunct, that disjunct yields nil."
(let ((result (gensym))) (cl-with-gensyms (result)
`(let (,result) `(let (,result)
(or ,@(cl-loop for disjunct in disjuncts collect (or ,@(cl-loop for disjunct in disjuncts collect
`(if (catch 'eshell-incomplete `(if (catch 'eshell-incomplete

View file

@ -2668,7 +2668,7 @@ but this macro does not by itself perform redisplay. If BODY needs to
display something with LOCALE-NAME's settings, include a call display something with LOCALE-NAME's settings, include a call
to `redraw-frame' in BODY." to `redraw-frame' in BODY."
(declare (indent 1) (debug (sexp def-body))) (declare (indent 1) (debug (sexp def-body)))
(let ((current (gensym))) (cl-with-gensyms (current)
`(let ((,current current-locale-environment)) `(let ((,current current-locale-environment))
(unwind-protect (unwind-protect
(progn (progn

View file

@ -1678,7 +1678,7 @@ line after applying FUNCTION."
(defun kmacro-menu--marks-exist-p () (defun kmacro-menu--marks-exist-p ()
"Return non-nil if markers exist for any table entries." "Return non-nil if markers exist for any table entries."
(let ((tag (gensym))) (cl-with-gensyms (tag)
(catch tag (catch tag
(kmacro-menu--map-ids (lambda (id) (kmacro-menu--map-ids (lambda (id)
(when (alist-get (kmacro-menu--id-position id) (when (alist-get (kmacro-menu--id-position id)

View file

@ -23,7 +23,7 @@
(require 'ert) (require 'ert)
(ert-deftest cl-lib-test-remprop () (ert-deftest cl-lib-test-remprop ()
(let ((x (cl-gensym))) (cl-with-gensyms (x)
(should (equal (symbol-plist x) '())) (should (equal (symbol-plist x) '()))
;; Remove nonexistent property on empty plist. ;; Remove nonexistent property on empty plist.
(cl-remprop x 'b) (cl-remprop x 'b)

View 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 be used by this macro to retain state. If NAME for example is
\"symbol\" then the first and subsequent uses of this macro will \"symbol\" then the first and subsequent uses of this macro will
evaluate to \"symbol\", \"symbol-1\", \"symbol-2\", etc." evaluate to \"symbol\", \"symbol-1\", \"symbol-2\", etc."
(let ((g-name (gensym)) (cl-with-gensyms (g-name g-duplicate)
(g-duplicate (gensym)))
`(let* ((,g-name ,name) `(let* ((,g-name ,name)
(,g-duplicate (assoc ,g-name ,names-and-numbers))) (,g-duplicate (assoc ,g-name ,names-and-numbers)))
(if (null ,g-duplicate) (if (null ,g-duplicate)

View file

@ -617,7 +617,7 @@ This macro is used to test if macroexpansion in `should' works."
(should (ert--special-operator-p 'if)) (should (ert--special-operator-p 'if))
(should-not (ert--special-operator-p 'car)) (should-not (ert--special-operator-p 'car))
(should-not (ert--special-operator-p 'ert--special-operator-p)) (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)) (should-not (ert--special-operator-p b))
(fset b 'if) (fset b 'if)
(should (ert--special-operator-p b)))) (should (ert--special-operator-p b))))

View file

@ -24,6 +24,7 @@
;;; Code: ;;; Code:
(require 'kmacro) (require 'kmacro)
(require 'cl-lib)
(require 'seq) (require 'seq)
(require 'ert) (require 'ert)
(require 'ert-x) (require 'ert-x)
@ -157,8 +158,7 @@ Execute BODY, then check that the string VALUE was inserted
into the current buffer at point." into the current buffer at point."
(declare (debug (stringp body)) (declare (debug (stringp body))
(indent 1)) (indent 1))
(let ((g-p (cl-gensym)) (cl-with-gensyms (g-p g-bsize)
(g-bsize (cl-gensym)))
`(let ((,g-p (point)) `(let ((,g-p (point))
(,g-bsize (buffer-size))) (,g-bsize (buffer-size)))
,@body ,@body
@ -172,7 +172,7 @@ VALUE and any text written to *Messages* during the execution,
cause the current test to fail." cause the current test to fail."
(declare (debug (form body)) (declare (debug (form body))
(indent 1)) (indent 1))
(let ((g-captured-messages (cl-gensym))) (cl-with-gensyms (g-captured-messages)
`(ert-with-message-capture ,g-captured-messages `(ert-with-message-capture ,g-captured-messages
,@body ,@body
(should (string-match-p ,value ,g-captured-messages))))) (should (string-match-p ,value ,g-captured-messages)))))

View 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." Return the last evalled form in BODY."
(declare (indent 5) (debug (stringp stringp stringp form characterp body))) (declare (indent 5) (debug (stringp stringp stringp form characterp body)))
(let ((text (gensym "text")) (cl-with-gensyms (text count)
(count (gensym "count")))
`(let* ((,text ,input) `(let* ((,text ,input)
(,count 0) (,count 0)
(inhibit-message t)) (inhibit-message t))