aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Oteiza2017-09-12 11:08:00 -0400
committerMark Oteiza2017-09-12 11:08:00 -0400
commit35c893ddaf21b93677850a69709b59630bb0feb7 (patch)
tree4b4a6f9755609940a542acbe639aefa295beb8d9
parent2ae46b4c0dabfea80883a294dff16e0eb7182d30 (diff)
downloademacs-35c893ddaf21b93677850a69709b59630bb0feb7.tar.gz
emacs-35c893ddaf21b93677850a69709b59630bb0feb7.zip
Move gensym to core Elisp
* doc/lispref/symbols.texi (Creating Symbols): Mention gensym right after make-symbol. * etc/NEWS: Mention. * lisp/emacs-lisp/cl-macs.el (cl--gensym-counter): Alias to gensym-counter. (cl-gensym): Alias to gensym. * lisp/emacs-lisp/cl.el: Remove gensym from list of aliases. * lisp/emacs-lisp/edebug.el (edebug-make-enter-wrapper): * lisp/emacs-lisp/ert-x.el (ert-with-message-capture): (ert--expand-should-1, ert--expand-should): (ert--should-error-handle-error): * lisp/emacs-lisp/generator.el (cps--gensym): * lisp/emacs-lisp/gv.el (setf): * lisp/emacs-lisp/inline.el (inline--do-letlisteval): * lisp/emacs-lisp/pcase.el (pcase--make-docstring, pcase-dolist): (pcase--funcall, pcase--u1): Use gensym. * lisp/subr.el (gensym-counter): New variable. (gensym): New function, assimilated from cl-lib.
-rw-r--r--doc/lispref/symbols.texi7
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/emacs-lisp/cl-macs.el11
-rw-r--r--lisp/emacs-lisp/cl.el1
-rw-r--r--lisp/emacs-lisp/edebug.el2
-rw-r--r--lisp/emacs-lisp/ert-x.el2
-rw-r--r--lisp/emacs-lisp/ert.el18
-rw-r--r--lisp/emacs-lisp/generator.el5
-rw-r--r--lisp/emacs-lisp/gv.el4
-rw-r--r--lisp/emacs-lisp/inline.el2
-rw-r--r--lisp/emacs-lisp/pcase.el8
-rw-r--r--lisp/subr.el14
12 files changed, 45 insertions, 32 deletions
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index e6ea8a1cc09..2d9ec6fda30 100644
--- a/doc/lispref/symbols.texi
+++ b/doc/lispref/symbols.texi
@@ -273,6 +273,13 @@ distinct uninterned symbol whose name is also @samp{foo}.
273@end example 273@end example
274@end defun 274@end defun
275 275
276@defun gensym &optional prefix
277This function returns a symbol using @code{make-symbol}, whose name is
278made by appending @code{gensym-counter} to @var{prefix}. The prefix
279defaults to @code{"G"}. If @var{prefix} is a number, it replaces the
280value of the counter.
281@end defun
282
276@defun intern name &optional obarray 283@defun intern name &optional obarray
277This function returns the interned symbol whose name is @var{name}. If 284This function returns the interned symbol whose name is @var{name}. If
278there is no such symbol in the obarray @var{obarray}, @code{intern} 285there is no such symbol in the obarray @var{obarray}, @code{intern}
diff --git a/etc/NEWS b/etc/NEWS
index 3f1df23ec30..af29b29264d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1525,6 +1525,9 @@ It avoids unnecessary consing (and garbage collection).
1525+++ 1525+++
1526** 'car' and 'cdr' compositions 'cXXXr' and 'cXXXXr' are now part of Elisp. 1526** 'car' and 'cdr' compositions 'cXXXr' and 'cXXXXr' are now part of Elisp.
1527 1527
1528+++
1529** 'gensym' is now part of Elisp.
1530
1528--- 1531---
1529** 'if-let*', 'when-let*', and 'and-let*' are new in subr-x.el. 1532** 'if-let*', 'when-let*', and 'and-let*' are new in subr-x.el.
1530The incumbent 'if-let' and 'when-let' are now aliases. 1533The incumbent 'if-let' and 'when-let' are now aliases.
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 3405c92e8d4..eee5953882d 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -161,16 +161,9 @@ whether X is known at compile time, macroexpand it completely in
161 161
162;;; Symbols. 162;;; Symbols.
163 163
164(defvar cl--gensym-counter 0) 164(defvaralias 'cl--gensym-counter 'gensym-counter)
165;;;###autoload 165;;;###autoload
166(defun cl-gensym (&optional prefix) 166(cl--defalias 'cl-gensym 'gensym)
167 "Generate a new uninterned symbol.
168The name is made by appending a number to PREFIX, default \"G\"."
169 (let ((pfix (if (stringp prefix) prefix "G"))
170 (num (if (integerp prefix) prefix
171 (prog1 cl--gensym-counter
172 (setq cl--gensym-counter (1+ cl--gensym-counter))))))
173 (make-symbol (format "%s%d" pfix num))))
174 167
175(defvar cl--gentemp-counter 0) 168(defvar cl--gentemp-counter 0)
176;;;###autoload 169;;;###autoload
diff --git a/lisp/emacs-lisp/cl.el b/lisp/emacs-lisp/cl.el
index 73eb9a4e866..306237ca38f 100644
--- a/lisp/emacs-lisp/cl.el
+++ b/lisp/emacs-lisp/cl.el
@@ -250,7 +250,6 @@
250 eval-when 250 eval-when
251 destructuring-bind 251 destructuring-bind
252 gentemp 252 gentemp
253 gensym
254 pairlis 253 pairlis
255 acons 254 acons
256 subst 255 subst
diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index c6ef8d7a99c..3190346497d 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -1193,7 +1193,7 @@ circular objects. Let `read' read everything else."
1193 ;; Uses the dynamically bound vars edebug-def-name and edebug-def-args. 1193 ;; Uses the dynamically bound vars edebug-def-name and edebug-def-args.
1194 ;; Do this after parsing since that may find a name. 1194 ;; Do this after parsing since that may find a name.
1195 (setq edebug-def-name 1195 (setq edebug-def-name
1196 (or edebug-def-name edebug-old-def-name (cl-gensym "edebug-anon"))) 1196 (or edebug-def-name edebug-old-def-name (gensym "edebug-anon")))
1197 `(edebug-enter 1197 `(edebug-enter
1198 (quote ,edebug-def-name) 1198 (quote ,edebug-def-name)
1199 ,(if edebug-inside-func 1199 ,(if edebug-inside-func
diff --git a/lisp/emacs-lisp/ert-x.el b/lisp/emacs-lisp/ert-x.el
index 4cf9d9609e9..1413b9cd0bf 100644
--- a/lisp/emacs-lisp/ert-x.el
+++ b/lisp/emacs-lisp/ert-x.el
@@ -295,7 +295,7 @@ This is useful for separating the issuance of messages by the
295code under test from the behavior of the *Messages* buffer." 295code under test from the behavior of the *Messages* buffer."
296 (declare (debug (symbolp body)) 296 (declare (debug (symbolp body))
297 (indent 1)) 297 (indent 1))
298 (let ((g-advice (cl-gensym))) 298 (let ((g-advice (gensym)))
299 `(let* ((,var "") 299 `(let* ((,var "")
300 (,g-advice (lambda (func &rest args) 300 (,g-advice (lambda (func &rest args)
301 (if (or (null args) (equal (car args) "")) 301 (if (or (null args) (equal (car args) ""))
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 9cc764d78e0..579e5e0aadc 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -298,8 +298,8 @@ It should only be stopped when ran from inside ert--run-test-internal."
298 (error `(signal ',(car err) ',(cdr err)))))) 298 (error `(signal ',(car err) ',(cdr err))))))
299 (cond 299 (cond
300 ((or (atom form) (ert--special-operator-p (car form))) 300 ((or (atom form) (ert--special-operator-p (car form)))
301 (let ((value (cl-gensym "value-"))) 301 (let ((value (gensym "value-")))
302 `(let ((,value (cl-gensym "ert-form-evaluation-aborted-"))) 302 `(let ((,value (gensym "ert-form-evaluation-aborted-")))
303 ,(funcall inner-expander 303 ,(funcall inner-expander
304 `(setq ,value ,form) 304 `(setq ,value ,form)
305 `(list ',whole :form ',form :value ,value) 305 `(list ',whole :form ',form :value ,value)
@@ -312,10 +312,10 @@ It should only be stopped when ran from inside ert--run-test-internal."
312 (and (consp fn-name) 312 (and (consp fn-name)
313 (eql (car fn-name) 'lambda) 313 (eql (car fn-name) 'lambda)
314 (listp (cdr fn-name))))) 314 (listp (cdr fn-name)))))
315 (let ((fn (cl-gensym "fn-")) 315 (let ((fn (gensym "fn-"))
316 (args (cl-gensym "args-")) 316 (args (gensym "args-"))
317 (value (cl-gensym "value-")) 317 (value (gensym "value-"))
318 (default-value (cl-gensym "ert-form-evaluation-aborted-"))) 318 (default-value (gensym "ert-form-evaluation-aborted-")))
319 `(let* ((,fn (function ,fn-name)) 319 `(let* ((,fn (function ,fn-name))
320 (,args (condition-case err 320 (,args (condition-case err
321 (let ((signal-hook-function #'ert--should-signal-hook)) 321 (let ((signal-hook-function #'ert--should-signal-hook))
@@ -357,7 +357,7 @@ FORM-DESCRIPTION-FORM before it has called INNER-FORM."
357 (ert--expand-should-1 357 (ert--expand-should-1
358 whole form 358 whole form
359 (lambda (inner-form form-description-form value-var) 359 (lambda (inner-form form-description-form value-var)
360 (let ((form-description (cl-gensym "form-description-"))) 360 (let ((form-description (gensym "form-description-")))
361 `(let (,form-description) 361 `(let (,form-description)
362 ,(funcall inner-expander 362 ,(funcall inner-expander
363 `(unwind-protect 363 `(unwind-protect
@@ -435,8 +435,8 @@ failed."
435 `(should-error ,form ,@keys) 435 `(should-error ,form ,@keys)
436 form 436 form
437 (lambda (inner-form form-description-form value-var) 437 (lambda (inner-form form-description-form value-var)
438 (let ((errorp (cl-gensym "errorp")) 438 (let ((errorp (gensym "errorp"))
439 (form-description-fn (cl-gensym "form-description-fn-"))) 439 (form-description-fn (gensym "form-description-fn-")))
440 `(let ((,errorp nil) 440 `(let ((,errorp nil)
441 (,form-description-fn (lambda () ,form-description-form))) 441 (,form-description-fn (lambda () ,form-description-form)))
442 (condition-case -condition- 442 (condition-case -condition-
diff --git a/lisp/emacs-lisp/generator.el b/lisp/emacs-lisp/generator.el
index c96b400809b..fe5d2d0728f 100644
--- a/lisp/emacs-lisp/generator.el
+++ b/lisp/emacs-lisp/generator.el
@@ -86,10 +86,7 @@
86(defvar cps--cleanup-function nil) 86(defvar cps--cleanup-function nil)
87 87
88(defmacro cps--gensym (fmt &rest args) 88(defmacro cps--gensym (fmt &rest args)
89 ;; Change this function to use `cl-gensym' if you want the generated 89 `(gensym (format ,fmt ,@args)))
90 ;; code to be easier to read and debug.
91 ;; (cl-gensym (apply #'format fmt args))
92 `(progn (ignore ,@args) (make-symbol ,fmt)))
93 90
94(defvar cps--dynamic-wrappers '(identity) 91(defvar cps--dynamic-wrappers '(identity)
95 "List of transformer functions to apply to atomic forms we 92 "List of transformer functions to apply to atomic forms we
diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index a8b8974cb4f..42b1c216956 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -431,7 +431,7 @@ The return value is the last VAL in the list.
431 ;; code is large, but otherwise results in more efficient code. 431 ;; code is large, but otherwise results in more efficient code.
432 `(if ,test ,(gv-get then do) 432 `(if ,test ,(gv-get then do)
433 ,@(macroexp-unprogn (gv-get (macroexp-progn else) do))) 433 ,@(macroexp-unprogn (gv-get (macroexp-progn else) do)))
434 (let ((v (make-symbol "v"))) 434 (let ((v (gensym "v")))
435 (macroexp-let2 nil 435 (macroexp-let2 nil
436 gv `(if ,test ,(gv-letplace (getter setter) then 436 gv `(if ,test ,(gv-letplace (getter setter) then
437 `(cons (lambda () ,getter) 437 `(cons (lambda () ,getter)
@@ -456,7 +456,7 @@ The return value is the last VAL in the list.
456 (gv-get (macroexp-progn (cdr branch)) do))) 456 (gv-get (macroexp-progn (cdr branch)) do)))
457 (gv-get (car branch) do))) 457 (gv-get (car branch) do)))
458 branches)) 458 branches))
459 (let ((v (make-symbol "v"))) 459 (let ((v (gensym "v")))
460 (macroexp-let2 nil 460 (macroexp-let2 nil
461 gv `(cond 461 gv `(cond
462 ,@(mapcar 462 ,@(mapcar
diff --git a/lisp/emacs-lisp/inline.el b/lisp/emacs-lisp/inline.el
index ce46f66aef8..cf8e2f22d88 100644
--- a/lisp/emacs-lisp/inline.el
+++ b/lisp/emacs-lisp/inline.el
@@ -218,7 +218,7 @@ After VARS is handled, BODY is evaluated in the new environment."
218 `(let* ((,bsym ()) 218 `(let* ((,bsym ())
219 (,listvar (mapcar (lambda (e) 219 (,listvar (mapcar (lambda (e)
220 (if (macroexp-copyable-p e) e 220 (if (macroexp-copyable-p e) e
221 (let ((v (make-symbol "v"))) 221 (let ((v (gensym "v")))
222 (push (list v e) ,bsym) 222 (push (list v e) ,bsym)
223 v))) 223 v)))
224 ,listvar))) 224 ,listvar)))
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index 253b60e7534..5935845743d 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -213,7 +213,7 @@ Emacs Lisp manual for more information and examples."
213(defmacro pcase-exhaustive (exp &rest cases) 213(defmacro pcase-exhaustive (exp &rest cases)
214 "The exhaustive version of `pcase' (which see)." 214 "The exhaustive version of `pcase' (which see)."
215 (declare (indent 1) (debug pcase)) 215 (declare (indent 1) (debug pcase))
216 (let* ((x (make-symbol "x")) 216 (let* ((x (gensym "x"))
217 (pcase--dontwarn-upats (cons x pcase--dontwarn-upats))) 217 (pcase--dontwarn-upats (cons x pcase--dontwarn-upats)))
218 (pcase--expand 218 (pcase--expand
219 ;; FIXME: Could we add the FILE:LINE data in the error message? 219 ;; FIXME: Could we add the FILE:LINE data in the error message?
@@ -304,7 +304,7 @@ any kind of error."
304 (declare (indent 1) (debug ((pcase-PAT form) body))) 304 (declare (indent 1) (debug ((pcase-PAT form) body)))
305 (if (pcase--trivial-upat-p (car spec)) 305 (if (pcase--trivial-upat-p (car spec))
306 `(dolist ,spec ,@body) 306 `(dolist ,spec ,@body)
307 (let ((tmpvar (make-symbol "x"))) 307 (let ((tmpvar (gensym "x")))
308 `(dolist (,tmpvar ,@(cdr spec)) 308 `(dolist (,tmpvar ,@(cdr spec))
309 (pcase-let* ((,(car spec) ,tmpvar)) 309 (pcase-let* ((,(car spec) ,tmpvar))
310 ,@body))))) 310 ,@body)))))
@@ -715,7 +715,7 @@ MATCH is the pattern that needs to be matched, of the form:
715 (call (progn 715 (call (progn
716 (when (memq arg vs) 716 (when (memq arg vs)
717 ;; `arg' is shadowed by `env'. 717 ;; `arg' is shadowed by `env'.
718 (let ((newsym (make-symbol "x"))) 718 (let ((newsym (gensym "x")))
719 (push (list newsym arg) env) 719 (push (list newsym arg) env)
720 (setq arg newsym))) 720 (setq arg newsym)))
721 (if (functionp fun) 721 (if (functionp fun)
@@ -842,7 +842,7 @@ Otherwise, it defers to REST which is a list of branches of the form
842 ;; A upat of the form (app FUN PAT) 842 ;; A upat of the form (app FUN PAT)
843 (pcase--mark-used sym) 843 (pcase--mark-used sym)
844 (let* ((fun (nth 1 upat)) 844 (let* ((fun (nth 1 upat))
845 (nsym (make-symbol "x")) 845 (nsym (gensym "x"))
846 (body 846 (body
847 ;; We don't change `matches' to reuse the newly computed value, 847 ;; We don't change `matches' to reuse the newly computed value,
848 ;; because we assume there shouldn't be such redundancy in there. 848 ;; because we assume there shouldn't be such redundancy in there.
diff --git a/lisp/subr.el b/lisp/subr.el
index 2ad52f6a638..ebb8b53b502 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -280,6 +280,20 @@ without silencing all errors."
280 280
281;;;; Basic Lisp functions. 281;;;; Basic Lisp functions.
282 282
283(defvar gensym-counter 0
284 "Number used to construct the name of the next symbol created by `gensym'.")
285
286(defun gensym (&optional prefix)
287 "Return a new uninterned symbol.
288The name is made by appending `gensym-counter' to PREFIX.
289PREFIX can be a string, and defaults to \"G\".
290If PREFIX is a number, it replaces the value of `gensym-counter'."
291 (let ((pfix (if (stringp prefix) prefix "G"))
292 (num (if (integerp prefix) prefix
293 (prog1 gensym-counter
294 (setq gensym-counter (1+ gensym-counter))))))
295 (make-symbol (format "%s%d" pfix num))))
296
283(defun ignore (&rest _ignore) 297(defun ignore (&rest _ignore)
284 "Do nothing and return nil. 298 "Do nothing and return nil.
285This function accepts any number of arguments, but ignores them." 299This function accepts any number of arguments, but ignores them."