diff --git a/src/alloc.c b/src/alloc.c index 2cee646256..89372c11b5 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3632,6 +3632,32 @@ Its value is void, and its function definition and property list are nil. */) return val; } +static Lisp_Object default_gensym_prefix; + +DEFUN ("gensym", Fgensym, Sgensym, 0, 1, 0, + doc: /* Return a new uninterned symbol. +The name is made by concatenating PREFIX with a counter value. +PREFIX is a string and defaults to "g". +There is no provision for resetting the counter. */) + (Lisp_Object prefix) +{ + static int gensym_counter = 0; + + Lisp_Object suffix, name; + int len; + char buf[INT_STRLEN_BOUND (EMACS_INT)]; + + if (NILP (prefix)) + prefix = default_gensym_prefix; + CHECK_STRING (prefix); + + EMACS_INT count = gensym_counter++; + len = sprintf (buf, "%"pI"d", count); + suffix = make_string (buf, len); + name = concat2 (prefix, suffix); + return Fmake_symbol (name); +} + /*********************************************************************** @@ -7515,6 +7541,8 @@ The time is in seconds as a floating point value. */); DEFVAR_INT ("gcs-done", gcs_done, doc: /* Accumulated number of garbage collections done. */); + default_gensym_prefix = build_pure_c_string ("g"); + defsubr (&Scons); defsubr (&Slist); defsubr (&Svector); @@ -7527,6 +7555,7 @@ The time is in seconds as a floating point value. */); defsubr (&Smake_string); defsubr (&Smake_bool_vector); defsubr (&Smake_symbol); + defsubr (&Sgensym); defsubr (&Smake_marker); defsubr (&Smake_finalizer); defsubr (&Spurecopy);