summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/buffer.c22
-rw-r--r--src/lisp.h1
3 files changed, 26 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e3993981317..805b189ae83 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2012-07-03 Glenn Morris <rgm@gnu.org>
+
+ * lisp.h (Frandom): Make it visible to C.
+ * buffer.c (Fgenerate_new_buffer_name): Speed up finding a new
+ buffer for invisible buffers. (Bug#1229)
+
2012-07-03 Dmitry Antipov <dmantipov@yandex.ru>
Fix block vector allocation code to allow VECTOR_BLOCK_SIZE
diff --git a/src/buffer.c b/src/buffer.c
index 08118baa3d7..83f0eb153c5 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -838,10 +838,14 @@ If there is no live buffer named NAME, then return NAME.
Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
\(starting at 2) until an unused name is found, and then return that name.
Optional second argument IGNORE specifies a name that is okay to use (if
-it is in the sequence to be tried) even if a buffer with that name exists. */)
+it is in the sequence to be tried) even if a buffer with that name exists.
+
+If NAME begins with a space (i.e., a buffer that is not normally
+visible to users), then if buffer NAME already exists a random number
+is first appended to NAME, to speed up finding a non-existent buffer. */)
(register Lisp_Object name, Lisp_Object ignore)
{
- register Lisp_Object gentemp, tem;
+ register Lisp_Object gentemp, tem, tem2;
ptrdiff_t count;
char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
@@ -854,11 +858,23 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
if (NILP (tem))
return name;
+ if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */
+ {
+ /* Note fileio.c:make_temp_name does random differently. */
+ sprintf (number, "-%"pD"d", Frandom (make_number (999999)));
+ tem2 = concat2 (name, build_string (number));
+ tem = Fget_buffer (tem2);
+ if (NILP (tem))
+ return tem2;
+ }
+ else
+ tem2 = name;
+
count = 1;
while (1)
{
sprintf (number, "<%"pD"d>", ++count);
- gentemp = concat2 (name, build_string (number));
+ gentemp = concat2 (tem2, build_string (number));
tem = Fstring_equal (gentemp, ignore);
if (!NILP (tem))
return gentemp;
diff --git a/src/lisp.h b/src/lisp.h
index 8cec1600692..2059e2a3fbd 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2473,6 +2473,7 @@ EXFUN (Fputhash, 3);
EXFUN (Fremhash, 2);
EXFUN (Fidentity, 1);
+EXFUN (Frandom, 1);
EXFUN (Flength, 1);
EXFUN (Fappend, MANY);
EXFUN (Fconcat, MANY);