aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c22
1 files changed, 19 insertions, 3 deletions
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.
838Otherwise modify name by appending `<NUMBER>', incrementing NUMBER 838Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
839\(starting at 2) until an unused name is found, and then return that name. 839\(starting at 2) until an unused name is found, and then return that name.
840Optional second argument IGNORE specifies a name that is okay to use (if 840Optional second argument IGNORE specifies a name that is okay to use (if
841it is in the sequence to be tried) even if a buffer with that name exists. */) 841it is in the sequence to be tried) even if a buffer with that name exists.
842
843If NAME begins with a space (i.e., a buffer that is not normally
844visible to users), then if buffer NAME already exists a random number
845is first appended to NAME, to speed up finding a non-existent buffer. */)
842 (register Lisp_Object name, Lisp_Object ignore) 846 (register Lisp_Object name, Lisp_Object ignore)
843{ 847{
844 register Lisp_Object gentemp, tem; 848 register Lisp_Object gentemp, tem, tem2;
845 ptrdiff_t count; 849 ptrdiff_t count;
846 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"]; 850 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
847 851
@@ -854,11 +858,23 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
854 if (NILP (tem)) 858 if (NILP (tem))
855 return name; 859 return name;
856 860
861 if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */
862 {
863 /* Note fileio.c:make_temp_name does random differently. */
864 sprintf (number, "-%"pD"d", Frandom (make_number (999999)));
865 tem2 = concat2 (name, build_string (number));
866 tem = Fget_buffer (tem2);
867 if (NILP (tem))
868 return tem2;
869 }
870 else
871 tem2 = name;
872
857 count = 1; 873 count = 1;
858 while (1) 874 while (1)
859 { 875 {
860 sprintf (number, "<%"pD"d>", ++count); 876 sprintf (number, "<%"pD"d>", ++count);
861 gentemp = concat2 (name, build_string (number)); 877 gentemp = concat2 (tem2, build_string (number));
862 tem = Fstring_equal (gentemp, ignore); 878 tem = Fstring_equal (gentemp, ignore);
863 if (!NILP (tem)) 879 if (!NILP (tem))
864 return gentemp; 880 return gentemp;