From 331d0e520ff5a3599cc9958108a6b6b8cb277ce3 Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Mon, 18 Sep 2017 09:00:45 -0400 Subject: [PATCH] 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 79ae1f4830d..96b1ac19b4b 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 ac9e2df603c..a68688eba7a 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 -- 2.39.5