[Top][All Lists]

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

[Emacs-diffs] emacs-26 331d0e5: Fix gensym

From: Mark Oteiza
Subject: [Emacs-diffs] emacs-26 331d0e5: Fix gensym
Date: Mon, 18 Sep 2017 09:01:43 -0400 (EDT)

branch: emacs-26
commit 331d0e520ff5a3599cc9958108a6b6b8cb277ce3
Author: Mark Oteiza <address@hidden>
Commit: Mark Oteiza <address@hidden>

    Fix gensym
    * lisp/subr.el (gensym): Actually implement the default prefix.
    * test/lisp/subr-tests.el (subr-tests--gensym): New test.
 lisp/subr.el            | 2 +-
 test/lisp/subr-tests.el | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 79ae1f4..96b1ac1 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -289,7 +289,7 @@ The name is made by appending `gensym-counter' to PREFIX.
 PREFIX is a string, and defaults to \"g\"."
   (let ((num (prog1 gensym-counter
                (setq gensym-counter (1+ gensym-counter)))))
-    (make-symbol (format "%s%d" prefix num))))
+    (make-symbol (format "%s%d" (or prefix "g") num))))
 (defun ignore (&rest _ignore)
   "Do nothing and return nil.
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index ac9e2df..a68688e 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -300,6 +300,12 @@ cf. Bug#25477."
       (setq res (read-passwd "pass: " 'confirm (mapconcat #'string default 
       (should (string= default res)))))
+(ert-deftest subr-tests--gensym ()
+  "Test `gensym' behavior."
+  (should (equal (symbol-name (let ((gensym-counter 0)) (gensym)))
+                 "g0"))
+  (should (eq (string-to-char (symbol-name (gensym))) ?g))
+  (should (eq (string-to-char (symbol-name (gensym "X"))) ?X)))
 (provide 'subr-tests)
 ;;; subr-tests.el ends here

reply via email to

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