aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/buffer.c b/src/buffer.c
index f81dca8388d..68575d845f0 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -93,6 +93,7 @@ static Lisp_Object Vbuffer_local_symbols;
93int check_protected_fields; 93int check_protected_fields;
94 94
95Lisp_Object Fset_buffer (); 95Lisp_Object Fset_buffer ();
96void set_buffer_internal ();
96 97
97/* Alist of all buffer names vs the buffers. */ 98/* Alist of all buffer names vs the buffers. */
98/* This used to be a variable, but is no longer, 99/* This used to be a variable, but is no longer,
@@ -306,12 +307,16 @@ reset_buffer_local_variables(b)
306 *(Lisp_Object *)(offset + (char *)&buffer_defaults); 307 *(Lisp_Object *)(offset + (char *)&buffer_defaults);
307} 308}
308 309
309DEFUN ("generate-new-buffer", Fgenerate_new_buffer, Sgenerate_new_buffer, 310/* We split this away from generate-new-buffer, because rename-buffer
311 and set-visited-file-name ought to be able to use this to really
312 rename the buffer properly. */
313
314DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, Sgenerate_new_buffer_name,
310 1, 1, 0, 315 1, 1, 0,
311 "Create and return a buffer with a name based on NAME.\n\ 316 "Return a string that is the name of no existing buffer based on NAME.\n\
312If there is no live buffer named NAME, then one is created.\n\ 317If there is no live buffer named NAME, then return NAME.\n\
313Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\ 318Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
314until an unused name is found, and then create a buffer.") 319until an unused name is found, and then return that name.")
315 (name) 320 (name)
316 register Lisp_Object name; 321 register Lisp_Object name;
317{ 322{
@@ -323,7 +328,7 @@ until an unused name is found, and then create a buffer.")
323 328
324 tem = Fget_buffer (name); 329 tem = Fget_buffer (name);
325 if (NULL (tem)) 330 if (NULL (tem))
326 return Fget_buffer_create (name); 331 return name;
327 332
328 count = 1; 333 count = 1;
329 while (1) 334 while (1)
@@ -332,14 +337,14 @@ until an unused name is found, and then create a buffer.")
332 gentemp = concat2 (name, build_string (number)); 337 gentemp = concat2 (name, build_string (number));
333 tem = Fget_buffer (gentemp); 338 tem = Fget_buffer (gentemp);
334 if (NULL (tem)) 339 if (NULL (tem))
335 return Fget_buffer_create (gentemp); 340 return gentemp;
336 } 341 }
337} 342}
338 343
339 344
340DEFUN ("buffer-name", Fbuffer_name, Sbuffer_name, 0, 1, 0, 345DEFUN ("buffer-name", Fbuffer_name, Sbuffer_name, 0, 1, 0,
341 "Return the name of BUFFER, as a string.\n\ 346 "Return the name of BUFFER, as a string.\n\
342Wyth no argument or nil as argument, return the name of the current buffer.") 347With no argument or nil as argument, return the name of the current buffer.")
343 (buffer) 348 (buffer)
344 register Lisp_Object buffer; 349 register Lisp_Object buffer;
345{ 350{
@@ -490,27 +495,38 @@ No argument or nil as argument means use current buffer as BUFFER.")
490 return make_number (BUF_MODIFF (buf)); 495 return make_number (BUF_MODIFF (buf));
491} 496}
492 497
493DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 1, 498DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2,
494 "sRename buffer (to new name): ", 499 "sRename buffer (to new name): ",
495 "Change current buffer's name to NEWNAME (a string).\n\ 500 "Change current buffer's name to NEWNAME (a string).\n\
496It is an error if a buffer named NEWNAME already exists.\n\ 501If second arg DISTINGUISH is nil or omitted, it is an error if a\n\
502buffer named NEWNAME already exists.\n\
503If DISTINGUISH is non-nil, come up with a new name using\n\
504`generate-new-buffer-name'.\n\
505Return the name we actually gave the buffer.\n\
497This does not change the name of the visited file (if any).") 506This does not change the name of the visited file (if any).")
498 (name) 507 (name, distinguish)
499 register Lisp_Object name; 508 register Lisp_Object name, distinguish;
500{ 509{
501 register Lisp_Object tem, buf; 510 register Lisp_Object tem, buf;
502 511
503 CHECK_STRING (name, 0); 512 CHECK_STRING (name, 0);
504 tem = Fget_buffer (name); 513 tem = Fget_buffer (name);
514 if (XBUFFER (tem) == current_buffer)
515 return current_buffer->name;
505 if (!NULL (tem)) 516 if (!NULL (tem))
506 error ("Buffer name \"%s\" is in use", XSTRING (name)->data); 517 {
518 if (!NULL (distinguish))
519 name = Fgenerate_new_buffer_name (name);
520 else
521 error ("Buffer name \"%s\" is in use", XSTRING (name)->data);
522 }
507 523
508 current_buffer->name = name; 524 current_buffer->name = name;
509 XSET (buf, Lisp_Buffer, current_buffer); 525 XSET (buf, Lisp_Buffer, current_buffer);
510 Fsetcar (Frassq (buf, Vbuffer_alist), name); 526 Fsetcar (Frassq (buf, Vbuffer_alist), name);
511 if (NULL (current_buffer->filename) && !NULL (current_buffer->auto_save_file_name)) 527 if (NULL (current_buffer->filename) && !NULL (current_buffer->auto_save_file_name))
512 call0 (intern ("rename-auto-save-file")); 528 call0 (intern ("rename-auto-save-file"));
513 return Qnil; 529 return name;
514} 530}
515 531
516DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 1, 0, 532DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 1, 0,
@@ -1104,7 +1120,10 @@ a non-nil `permanent-local' property are not eliminated by this function.")
1104 sym = XCONS (XCONS (alist)->car)->car; 1120 sym = XCONS (XCONS (alist)->car)->car;
1105 tem = Fget (sym, Qpermanent_local); 1121 tem = Fget (sym, Qpermanent_local);
1106 if (! NULL (tem)) 1122 if (! NULL (tem))
1107 Fmake_local_variable (sym, XCONS (XCONS (alist)->car)->cdr); 1123 {
1124 Fmake_local_variable (sym);
1125 Fset (sym, XCONS (XCONS (alist)->car)->cdr);
1126 }
1108 } 1127 }
1109 1128
1110 /* Force mode-line redisplay. Useful here because all major mode 1129 /* Force mode-line redisplay. Useful here because all major mode
@@ -1515,7 +1534,7 @@ See `add-field'.");
1515/*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol, 1534/*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
1516 "Don't ask."); 1535 "Don't ask.");
1517*/ 1536*/
1518 DEFVAR_LISP ("bgfore-change-function", &Vbefore_change_function, 1537 DEFVAR_LISP ("before-change-function", &Vbefore_change_function,
1519 "Function to call before each text change.\n\ 1538 "Function to call before each text change.\n\
1520Two arguments are passed to the function: the positions of\n\ 1539Two arguments are passed to the function: the positions of\n\
1521the beginning and end of the range of old text to be changed.\n\ 1540the beginning and end of the range of old text to be changed.\n\
@@ -1572,7 +1591,7 @@ If the value of the variable is t, undo information is not recorded.\n\
1572 defsubr (&Sget_buffer); 1591 defsubr (&Sget_buffer);
1573 defsubr (&Sget_file_buffer); 1592 defsubr (&Sget_file_buffer);
1574 defsubr (&Sget_buffer_create); 1593 defsubr (&Sget_buffer_create);
1575 defsubr (&Sgenerate_new_buffer); 1594 defsubr (&Sgenerate_new_buffer_name);
1576 defsubr (&Sbuffer_name); 1595 defsubr (&Sbuffer_name);
1577/*defsubr (&Sbuffer_number);*/ 1596/*defsubr (&Sbuffer_number);*/
1578 defsubr (&Sbuffer_file_name); 1597 defsubr (&Sbuffer_file_name);