(Qbuffer_file_type): Var deleted.
[bpt/emacs.git] / src / buffer.c
CommitLineData
1ab256cb 1/* Buffer manipulation primitives for GNU Emacs.
4158c17d 2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994
c922bc55 3 Free Software Foundation, Inc.
1ab256cb
RM
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
c922bc55 9the Free Software Foundation; either version 2, or (at your option)
1ab256cb
RM
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
19the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21
2381d133
JB
22#include <sys/types.h>
23#include <sys/stat.h>
1ab256cb
RM
24#include <sys/param.h>
25
26#ifndef MAXPATHLEN
27/* in 4.1, param.h fails to define this. */
28#define MAXPATHLEN 1024
29#endif /* not MAXPATHLEN */
30
18160b98 31#include <config.h>
1ab256cb 32#include "lisp.h"
21cf4cf8 33#include "intervals.h"
1ab256cb
RM
34#include "window.h"
35#include "commands.h"
36#include "buffer.h"
1ab256cb 37#include "indent.h"
d014bf88 38#include "blockinput.h"
1ab256cb
RM
39
40struct buffer *current_buffer; /* the current buffer */
41
42/* First buffer in chain of all buffers (in reverse order of creation).
43 Threaded through ->next. */
44
45struct buffer *all_buffers;
46
47/* This structure holds the default values of the buffer-local variables
48 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
49 The default value occupies the same slot in this structure
50 as an individual buffer's value occupies in that buffer.
51 Setting the default value also goes through the alist of buffers
52 and stores into each buffer that does not say it has a local value. */
53
54struct buffer buffer_defaults;
55
56/* A Lisp_Object pointer to the above, used for staticpro */
57
58static Lisp_Object Vbuffer_defaults;
59
60/* This structure marks which slots in a buffer have corresponding
61 default values in buffer_defaults.
62 Each such slot has a nonzero value in this structure.
63 The value has only one nonzero bit.
64
65 When a buffer has its own local value for a slot,
66 the bit for that slot (found in the same slot in this structure)
67 is turned on in the buffer's local_var_flags slot.
68
69 If a slot in this structure is -1, then even though there may
70 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
71 and the corresponding slot in buffer_defaults is not used.
72
73 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
74 but there is a default value which is copied into each buffer.
75
76 If a slot in this structure is negative, then even though there may
77 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
78 and the corresponding slot in buffer_defaults is not used.
79
80 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
81 zero, that is a bug */
82
83struct buffer buffer_local_flags;
84
85/* This structure holds the names of symbols whose values may be
86 buffer-local. It is indexed and accessed in the same way as the above. */
87
88struct buffer buffer_local_symbols;
89/* A Lisp_Object pointer to the above, used for staticpro */
90static Lisp_Object Vbuffer_local_symbols;
91
0fa3ba92
JB
92/* This structure holds the required types for the values in the
93 buffer-local slots. If a slot contains Qnil, then the
94 corresponding buffer slot may contain a value of any type. If a
95 slot contains an integer, then prospective values' tags must be
96 equal to that integer. When a tag does not match, the function
97 buffer_slot_type_mismatch will signal an error. */
98struct buffer buffer_local_types;
99
1ab256cb 100Lisp_Object Fset_buffer ();
01050cb5 101void set_buffer_internal ();
173f2a64 102static void call_overlay_mod_hooks ();
1ab256cb
RM
103
104/* Alist of all buffer names vs the buffers. */
105/* This used to be a variable, but is no longer,
106 to prevent lossage due to user rplac'ing this alist or its elements. */
107Lisp_Object Vbuffer_alist;
108
109/* Functions to call before and after each text change. */
110Lisp_Object Vbefore_change_function;
111Lisp_Object Vafter_change_function;
5f079267
RS
112Lisp_Object Vbefore_change_functions;
113Lisp_Object Vafter_change_functions;
1ab256cb 114
c48f61ef
RS
115Lisp_Object Vtransient_mark_mode;
116
a96b68f1
RS
117/* t means ignore all read-only text properties.
118 A list means ignore such a property if its value is a member of the list.
119 Any non-nil value means ignore buffer-read-only. */
120Lisp_Object Vinhibit_read_only;
121
dcdffbf6
RS
122/* List of functions to call that can query about killing a buffer.
123 If any of these functions returns nil, we don't kill it. */
124Lisp_Object Vkill_buffer_query_functions;
125
dbc4e1c1
JB
126/* List of functions to call before changing an unmodified buffer. */
127Lisp_Object Vfirst_change_hook;
128Lisp_Object Qfirst_change_hook;
1ab256cb
RM
129
130Lisp_Object Qfundamental_mode, Qmode_class, Qpermanent_local;
131
132Lisp_Object Qprotected_field;
133
134Lisp_Object QSFundamental; /* A string "Fundamental" */
135
136Lisp_Object Qkill_buffer_hook;
137
5fe0b67e
RS
138Lisp_Object Qget_file_buffer;
139
52f8ec73
JB
140Lisp_Object Qoverlayp;
141
5985d248
KH
142Lisp_Object Qpriority, Qwindow;
143
294d215f
RS
144Lisp_Object Qmodification_hooks;
145Lisp_Object Qinsert_in_front_hooks;
146Lisp_Object Qinsert_behind_hooks;
147
1ab256cb
RM
148/* For debugging; temporary. See set_buffer_internal. */
149/* Lisp_Object Qlisp_mode, Vcheck_symbol; */
150
151nsberror (spec)
152 Lisp_Object spec;
153{
154 if (XTYPE (spec) == Lisp_String)
155 error ("No buffer named %s", XSTRING (spec)->data);
156 error ("Invalid buffer argument");
157}
158\f
159DEFUN ("buffer-list", Fbuffer_list, Sbuffer_list, 0, 0, 0,
160 "Return a list of all existing live buffers.")
161 ()
162{
163 return Fmapcar (Qcdr, Vbuffer_alist);
164}
165
166DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0,
167 "Return the buffer named NAME (a string).\n\
168If there is no live buffer named NAME, return nil.\n\
169NAME may also be a buffer; if so, the value is that buffer.")
170 (name)
171 register Lisp_Object name;
172{
173 if (XTYPE (name) == Lisp_Buffer)
174 return name;
175 CHECK_STRING (name, 0);
176
177 return Fcdr (Fassoc (name, Vbuffer_alist));
178}
179
180DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0,
181 "Return the buffer visiting file FILENAME (a string).\n\
92194d02 182The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
1ab256cb
RM
183If there is no such live buffer, return nil.")
184 (filename)
185 register Lisp_Object filename;
186{
187 register Lisp_Object tail, buf, tem;
5fe0b67e
RS
188 Lisp_Object handler;
189
1ab256cb
RM
190 CHECK_STRING (filename, 0);
191 filename = Fexpand_file_name (filename, Qnil);
192
5fe0b67e
RS
193 /* If the file name has special constructs in it,
194 call the corresponding file handler. */
a617e913 195 handler = Ffind_file_name_handler (filename, Qget_file_buffer);
5fe0b67e
RS
196 if (!NILP (handler))
197 return call2 (handler, Qget_file_buffer, filename);
198
1ab256cb
RM
199 for (tail = Vbuffer_alist; CONSP (tail); tail = XCONS (tail)->cdr)
200 {
201 buf = Fcdr (XCONS (tail)->car);
202 if (XTYPE (buf) != Lisp_Buffer) continue;
203 if (XTYPE (XBUFFER (buf)->filename) != Lisp_String) continue;
204 tem = Fstring_equal (XBUFFER (buf)->filename, filename);
265a9e55 205 if (!NILP (tem))
1ab256cb
RM
206 return buf;
207 }
208 return Qnil;
209}
210
211/* Incremented for each buffer created, to assign the buffer number. */
212int buffer_count;
213
214DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0,
215 "Return the buffer named NAME, or create such a buffer and return it.\n\
216A new buffer is created if there is no live buffer named NAME.\n\
b44895bc 217If NAME starts with a space, the new buffer does not keep undo information.\n\
1ab256cb
RM
218If NAME is a buffer instead of a string, then it is the value returned.\n\
219The value is never nil.")
220 (name)
221 register Lisp_Object name;
222{
223 register Lisp_Object buf, function, tem;
224 int count = specpdl_ptr - specpdl;
225 register struct buffer *b;
226
227 buf = Fget_buffer (name);
265a9e55 228 if (!NILP (buf))
1ab256cb
RM
229 return buf;
230
31cd83e9
KH
231 if (XSTRING (name)->size == 0)
232 error ("Empty string for buffer name is not allowed");
233
9ac0d9e0 234 b = (struct buffer *) xmalloc (sizeof (struct buffer));
1ab256cb
RM
235
236 BUF_GAP_SIZE (b) = 20;
9ac0d9e0 237 BLOCK_INPUT;
1ab256cb 238 BUFFER_ALLOC (BUF_BEG_ADDR (b), BUF_GAP_SIZE (b));
9ac0d9e0 239 UNBLOCK_INPUT;
1ab256cb
RM
240 if (! BUF_BEG_ADDR (b))
241 memory_full ();
242
243 BUF_PT (b) = 1;
244 BUF_GPT (b) = 1;
245 BUF_BEGV (b) = 1;
246 BUF_ZV (b) = 1;
247 BUF_Z (b) = 1;
248 BUF_MODIFF (b) = 1;
249
250 /* Put this on the chain of all buffers including killed ones. */
251 b->next = all_buffers;
252 all_buffers = b;
253
254 b->mark = Fmake_marker ();
255 /*b->number = make_number (++buffer_count);*/
256 b->name = name;
257 if (XSTRING (name)->data[0] != ' ')
258 b->undo_list = Qnil;
259 else
260 b->undo_list = Qt;
261
262 reset_buffer (b);
263
264 /* Put this in the alist of all live buffers. */
265 XSET (buf, Lisp_Buffer, b);
266 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
267
268 b->mark = Fmake_marker ();
269 b->markers = Qnil;
270 b->name = name;
271
272 function = buffer_defaults.major_mode;
265a9e55 273 if (NILP (function))
1ab256cb
RM
274 {
275 tem = Fget (current_buffer->major_mode, Qmode_class);
276 if (EQ (tem, Qnil))
277 function = current_buffer->major_mode;
278 }
279
265a9e55 280 if (NILP (function) || EQ (function, Qfundamental_mode))
1ab256cb
RM
281 return buf;
282
283 /* To select a nonfundamental mode,
284 select the buffer temporarily and then call the mode function. */
285
286 record_unwind_protect (save_excursion_restore, save_excursion_save ());
287
288 Fset_buffer (buf);
289 call0 (function);
290
291 return unbind_to (count, buf);
292}
293
294/* Reinitialize everything about a buffer except its name and contents. */
295
296void
297reset_buffer (b)
298 register struct buffer *b;
299{
300 b->filename = Qnil;
301 b->directory = (current_buffer) ? current_buffer->directory : Qnil;
302 b->modtime = 0;
303 b->save_modified = 1;
291026b5 304 XFASTINT (b->save_length) = 0;
1ab256cb
RM
305 b->last_window_start = 1;
306 b->backed_up = Qnil;
307 b->auto_save_modified = 0;
84f6bcba 308 b->auto_save_failure_time = -1;
1ab256cb
RM
309 b->auto_save_file_name = Qnil;
310 b->read_only = Qnil;
2eec3b4e
RS
311 b->overlays_before = Qnil;
312 b->overlays_after = Qnil;
313 XFASTINT (b->overlay_center) = 1;
dfda7a7f 314 b->mark_active = Qnil;
33f7013e
JA
315
316 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
317 INITIALIZE_INTERVAL (b, NULL_INTERVAL);
318
1ab256cb
RM
319 reset_buffer_local_variables(b);
320}
321
c48f61ef 322reset_buffer_local_variables (b)
1ab256cb
RM
323 register struct buffer *b;
324{
325 register int offset;
326
327 /* Reset the major mode to Fundamental, together with all the
328 things that depend on the major mode.
329 default-major-mode is handled at a higher level.
330 We ignore it here. */
331 b->major_mode = Qfundamental_mode;
332 b->keymap = Qnil;
333 b->abbrev_table = Vfundamental_mode_abbrev_table;
334 b->mode_name = QSFundamental;
335 b->minor_modes = Qnil;
336 b->downcase_table = Vascii_downcase_table;
337 b->upcase_table = Vascii_upcase_table;
e9edf33c
RS
338 b->case_canon_table = Vascii_canon_table;
339 b->case_eqv_table = Vascii_eqv_table;
1ab256cb
RM
340#if 0
341 b->sort_table = XSTRING (Vascii_sort_table);
342 b->folding_sort_table = XSTRING (Vascii_folding_sort_table);
343#endif /* 0 */
344
345 /* Reset all per-buffer variables to their defaults. */
346 b->local_var_alist = Qnil;
347 b->local_var_flags = 0;
348
349 /* For each slot that has a default value,
350 copy that into the slot. */
351
352 for (offset = (char *)&buffer_local_flags.name - (char *)&buffer_local_flags;
353 offset < sizeof (struct buffer);
354 offset += sizeof (Lisp_Object)) /* sizeof int == sizeof Lisp_Object */
355 if (*(int *)(offset + (char *) &buffer_local_flags) > 0
356 || *(int *)(offset + (char *) &buffer_local_flags) == -2)
357 *(Lisp_Object *)(offset + (char *)b) =
358 *(Lisp_Object *)(offset + (char *)&buffer_defaults);
359}
360
01050cb5
RM
361/* We split this away from generate-new-buffer, because rename-buffer
362 and set-visited-file-name ought to be able to use this to really
363 rename the buffer properly. */
364
365DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, Sgenerate_new_buffer_name,
c273e647 366 1, 2, 0,
01050cb5
RM
367 "Return a string that is the name of no existing buffer based on NAME.\n\
368If there is no live buffer named NAME, then return NAME.\n\
1ab256cb 369Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
c273e647 370until an unused name is found, and then return that name.\n\
03bdd54c 371Optional second argument IGNORE specifies a name that is okay to use\n\
c273e647 372\(if it is in the sequence to be tried)\n\
e8b3a22d 373even if a buffer with that name exists.")
c273e647
RS
374 (name, ignore)
375 register Lisp_Object name, ignore;
1ab256cb
RM
376{
377 register Lisp_Object gentemp, tem;
378 int count;
379 char number[10];
380
381 CHECK_STRING (name, 0);
382
383 tem = Fget_buffer (name);
265a9e55 384 if (NILP (tem))
01050cb5 385 return name;
1ab256cb
RM
386
387 count = 1;
388 while (1)
389 {
390 sprintf (number, "<%d>", ++count);
391 gentemp = concat2 (name, build_string (number));
638e4fc3 392 tem = Fstring_equal (gentemp, ignore);
c273e647
RS
393 if (!NILP (tem))
394 return gentemp;
1ab256cb 395 tem = Fget_buffer (gentemp);
265a9e55 396 if (NILP (tem))
01050cb5 397 return gentemp;
1ab256cb
RM
398 }
399}
400
401\f
402DEFUN ("buffer-name", Fbuffer_name, Sbuffer_name, 0, 1, 0,
403 "Return the name of BUFFER, as a string.\n\
01050cb5 404With no argument or nil as argument, return the name of the current buffer.")
1ab256cb
RM
405 (buffer)
406 register Lisp_Object buffer;
407{
265a9e55 408 if (NILP (buffer))
1ab256cb
RM
409 return current_buffer->name;
410 CHECK_BUFFER (buffer, 0);
411 return XBUFFER (buffer)->name;
412}
413
414DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0,
415 "Return name of file BUFFER is visiting, or nil if none.\n\
416No argument or nil as argument means use the current buffer.")
417 (buffer)
418 register Lisp_Object buffer;
419{
265a9e55 420 if (NILP (buffer))
1ab256cb
RM
421 return current_buffer->filename;
422 CHECK_BUFFER (buffer, 0);
423 return XBUFFER (buffer)->filename;
424}
425
426DEFUN ("buffer-local-variables", Fbuffer_local_variables,
427 Sbuffer_local_variables, 0, 1, 0,
428 "Return an alist of variables that are buffer-local in BUFFER.\n\
553defa4
RS
429Most elements look like (SYMBOL . VALUE), describing one variable.\n\
430For a symbol that is locally unbound, just the symbol appears in the value.\n\
1ab256cb
RM
431Note that storing new VALUEs in these elements doesn't change the variables.\n\
432No argument or nil as argument means use current buffer as BUFFER.")
433 (buffer)
434 register Lisp_Object buffer;
435{
436 register struct buffer *buf;
553defa4 437 register Lisp_Object result;
1ab256cb 438
265a9e55 439 if (NILP (buffer))
1ab256cb
RM
440 buf = current_buffer;
441 else
442 {
443 CHECK_BUFFER (buffer, 0);
444 buf = XBUFFER (buffer);
445 }
446
553defa4
RS
447 result = Qnil;
448
1ab256cb
RM
449 {
450 /* Reference each variable in the alist in our current buffer.
451 If inquiring about the current buffer, this gets the current values,
452 so store them into the alist so the alist is up to date.
453 If inquiring about some other buffer, this swaps out any values
454 for that buffer, making the alist up to date automatically. */
553defa4
RS
455 register Lisp_Object tail;
456 for (tail = buf->local_var_alist; CONSP (tail); tail = XCONS (tail)->cdr)
1ab256cb 457 {
553defa4
RS
458 Lisp_Object val, elt;
459
460 elt = XCONS (tail)->car;
461
1ab256cb 462 if (buf == current_buffer)
553defa4
RS
463 val = find_symbol_value (XCONS (elt)->car);
464 else
465 val = XCONS (elt)->cdr;
466
467 /* If symbol is unbound, put just the symbol in the list. */
468 if (EQ (val, Qunbound))
469 result = Fcons (XCONS (elt)->car, result);
470 /* Otherwise, put (symbol . value) in the list. */
471 else
472 result = Fcons (Fcons (XCONS (elt)->car, val), result);
1ab256cb
RM
473 }
474 }
475
1ab256cb
RM
476 /* Add on all the variables stored in special slots. */
477 {
478 register int offset, mask;
479
480 for (offset = (char *)&buffer_local_symbols.name - (char *)&buffer_local_symbols;
481 offset < sizeof (struct buffer);
482 offset += (sizeof (int))) /* sizeof int == sizeof Lisp_Object */
483 {
484 mask = *(int *)(offset + (char *) &buffer_local_flags);
485 if (mask == -1 || (buf->local_var_flags & mask))
486 if (XTYPE (*(Lisp_Object *)(offset + (char *)&buffer_local_symbols))
487 == Lisp_Symbol)
553defa4
RS
488 result = Fcons (Fcons (*(Lisp_Object *)(offset + (char *)&buffer_local_symbols),
489 *(Lisp_Object *)(offset + (char *)buf)),
490 result);
1ab256cb
RM
491 }
492 }
553defa4
RS
493
494 return result;
1ab256cb
RM
495}
496
497\f
498DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p,
499 0, 1, 0,
500 "Return t if BUFFER was modified since its file was last read or saved.\n\
501No argument or nil as argument means use current buffer as BUFFER.")
502 (buffer)
503 register Lisp_Object buffer;
504{
505 register struct buffer *buf;
265a9e55 506 if (NILP (buffer))
1ab256cb
RM
507 buf = current_buffer;
508 else
509 {
510 CHECK_BUFFER (buffer, 0);
511 buf = XBUFFER (buffer);
512 }
513
514 return buf->save_modified < BUF_MODIFF (buf) ? Qt : Qnil;
515}
516
517DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p,
518 1, 1, 0,
519 "Mark current buffer as modified or unmodified according to FLAG.\n\
520A non-nil FLAG means mark the buffer modified.")
521 (flag)
522 register Lisp_Object flag;
523{
524 register int already;
525 register Lisp_Object fn;
526
527#ifdef CLASH_DETECTION
528 /* If buffer becoming modified, lock the file.
529 If buffer becoming unmodified, unlock the file. */
530
531 fn = current_buffer->filename;
265a9e55 532 if (!NILP (fn))
1ab256cb
RM
533 {
534 already = current_buffer->save_modified < MODIFF;
265a9e55 535 if (!already && !NILP (flag))
1ab256cb 536 lock_file (fn);
265a9e55 537 else if (already && NILP (flag))
1ab256cb
RM
538 unlock_file (fn);
539 }
540#endif /* CLASH_DETECTION */
541
265a9e55 542 current_buffer->save_modified = NILP (flag) ? MODIFF : 0;
1ab256cb
RM
543 update_mode_lines++;
544 return flag;
545}
546
547DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, Sbuffer_modified_tick,
548 0, 1, 0,
549 "Return BUFFER's tick counter, incremented for each change in text.\n\
550Each buffer has a tick counter which is incremented each time the text in\n\
551that buffer is changed. It wraps around occasionally.\n\
552No argument or nil as argument means use current buffer as BUFFER.")
553 (buffer)
554 register Lisp_Object buffer;
555{
556 register struct buffer *buf;
265a9e55 557 if (NILP (buffer))
1ab256cb
RM
558 buf = current_buffer;
559 else
560 {
561 CHECK_BUFFER (buffer, 0);
562 buf = XBUFFER (buffer);
563 }
564
565 return make_number (BUF_MODIFF (buf));
566}
567\f
01050cb5 568DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2,
4c7e5f09 569 "sRename buffer (to new name): \nP",
1ab256cb 570 "Change current buffer's name to NEWNAME (a string).\n\
3bd779aa 571If second arg UNIQUE is nil or omitted, it is an error if a\n\
01050cb5 572buffer named NEWNAME already exists.\n\
3bd779aa 573If UNIQUE is non-nil, come up with a new name using\n\
01050cb5 574`generate-new-buffer-name'.\n\
3bd779aa
RS
575Interactively, you can set UNIQUE with a prefix argument.\n\
576We return the name we actually gave the buffer.\n\
1ab256cb 577This does not change the name of the visited file (if any).")
3bd779aa
RS
578 (name, unique)
579 register Lisp_Object name, unique;
1ab256cb
RM
580{
581 register Lisp_Object tem, buf;
582
583 CHECK_STRING (name, 0);
584 tem = Fget_buffer (name);
c059b5ea
RM
585 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
586 the buffer automatically so you can create another with the original name.
587 It makes UNIQUE equivalent to
588 (rename-buffer (generate-new-buffer-name NAME)). */
589 if (NILP (unique) && XBUFFER (tem) == current_buffer)
01050cb5 590 return current_buffer->name;
265a9e55 591 if (!NILP (tem))
01050cb5 592 {
3bd779aa 593 if (!NILP (unique))
c273e647 594 name = Fgenerate_new_buffer_name (name, current_buffer->name);
01050cb5
RM
595 else
596 error ("Buffer name \"%s\" is in use", XSTRING (name)->data);
597 }
1ab256cb
RM
598
599 current_buffer->name = name;
76f590d7
JB
600
601 /* Catch redisplay's attention. Unless we do this, the mode lines for
602 any windows displaying current_buffer will stay unchanged. */
603 update_mode_lines++;
604
1ab256cb
RM
605 XSET (buf, Lisp_Buffer, current_buffer);
606 Fsetcar (Frassq (buf, Vbuffer_alist), name);
265a9e55 607 if (NILP (current_buffer->filename) && !NILP (current_buffer->auto_save_file_name))
1ab256cb 608 call0 (intern ("rename-auto-save-file"));
01050cb5 609 return name;
1ab256cb
RM
610}
611
a0ebb746 612DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 2, 0,
1ab256cb 613 "Return most recently selected buffer other than BUFFER.\n\
a0ebb746
JB
614Buffers not visible in windows are preferred to visible buffers,\n\
615unless optional second argument VISIBLE-OK is non-nil.\n\
1ab256cb
RM
616If no other buffer exists, the buffer `*scratch*' is returned.\n\
617If BUFFER is omitted or nil, some interesting buffer is returned.")
a0ebb746
JB
618 (buffer, visible_ok)
619 register Lisp_Object buffer, visible_ok;
1ab256cb
RM
620{
621 register Lisp_Object tail, buf, notsogood, tem;
622 notsogood = Qnil;
623
265a9e55 624 for (tail = Vbuffer_alist; !NILP (tail); tail = Fcdr (tail))
1ab256cb
RM
625 {
626 buf = Fcdr (Fcar (tail));
627 if (EQ (buf, buffer))
628 continue;
629 if (XSTRING (XBUFFER (buf)->name)->data[0] == ' ')
630 continue;
a0ebb746 631 if (NILP (visible_ok))
db732e5a 632 tem = Fget_buffer_window (buf, Qt);
a0ebb746
JB
633 else
634 tem = Qnil;
265a9e55 635 if (NILP (tem))
1ab256cb 636 return buf;
265a9e55 637 if (NILP (notsogood))
1ab256cb
RM
638 notsogood = buf;
639 }
265a9e55 640 if (!NILP (notsogood))
1ab256cb
RM
641 return notsogood;
642 return Fget_buffer_create (build_string ("*scratch*"));
643}
644\f
5b8bcf48 645DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, Sbuffer_disable_undo, 0, 1,
1ab256cb 6460,
5b8bcf48
RS
647 "Make BUFFER stop keeping undo information.\n\
648No argument or nil as argument means do this for the current buffer.")
ffd56f97
JB
649 (buffer)
650 register Lisp_Object buffer;
1ab256cb 651{
ffd56f97
JB
652 Lisp_Object real_buffer;
653
654 if (NILP (buffer))
655 XSET (real_buffer, Lisp_Buffer, current_buffer);
656 else
657 {
658 real_buffer = Fget_buffer (buffer);
659 if (NILP (real_buffer))
660 nsberror (buffer);
661 }
662
663 XBUFFER (real_buffer)->undo_list = Qt;
664
1ab256cb
RM
665 return Qnil;
666}
667
668DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,
669 0, 1, "",
670 "Start keeping undo information for buffer BUFFER.\n\
671No argument or nil as argument means do this for the current buffer.")
ffd56f97
JB
672 (buffer)
673 register Lisp_Object buffer;
1ab256cb 674{
ffd56f97 675 Lisp_Object real_buffer;
1ab256cb 676
ffd56f97
JB
677 if (NILP (buffer))
678 XSET (real_buffer, Lisp_Buffer, current_buffer);
1ab256cb
RM
679 else
680 {
ffd56f97
JB
681 real_buffer = Fget_buffer (buffer);
682 if (NILP (real_buffer))
683 nsberror (buffer);
1ab256cb
RM
684 }
685
ffd56f97
JB
686 if (EQ (XBUFFER (real_buffer)->undo_list, Qt))
687 XBUFFER (real_buffer)->undo_list = Qnil;
1ab256cb
RM
688
689 return Qnil;
690}
691
692/*
693 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
694Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
695The buffer being killed will be current while the hook is running.\n\
696See `kill-buffer'."
697 */
698DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ",
699 "Kill the buffer BUFFER.\n\
700The argument may be a buffer or may be the name of a buffer.\n\
701An argument of nil means kill the current buffer.\n\n\
702Value is t if the buffer is actually killed, nil if user says no.\n\n\
703The value of `kill-buffer-hook' (which may be local to that buffer),\n\
704if not void, is a list of functions to be called, with no arguments,\n\
705before the buffer is actually killed. The buffer to be killed is current\n\
706when the hook functions are called.\n\n\
707Any processes that have this buffer as the `process-buffer' are killed\n\
708with `delete-process'.")
709 (bufname)
710 Lisp_Object bufname;
711{
712 Lisp_Object buf;
713 register struct buffer *b;
714 register Lisp_Object tem;
715 register struct Lisp_Marker *m;
716 struct gcpro gcpro1, gcpro2;
717
265a9e55 718 if (NILP (bufname))
1ab256cb
RM
719 buf = Fcurrent_buffer ();
720 else
721 buf = Fget_buffer (bufname);
265a9e55 722 if (NILP (buf))
1ab256cb
RM
723 nsberror (bufname);
724
725 b = XBUFFER (buf);
726
727 /* Query if the buffer is still modified. */
265a9e55 728 if (INTERACTIVE && !NILP (b->filename)
1ab256cb
RM
729 && BUF_MODIFF (b) > b->save_modified)
730 {
731 GCPRO2 (buf, bufname);
732 tem = do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
733 XSTRING (b->name)->data));
734 UNGCPRO;
265a9e55 735 if (NILP (tem))
1ab256cb
RM
736 return Qnil;
737 }
738
dcdffbf6 739 /* Run hooks with the buffer to be killed the current buffer. */
1ab256cb
RM
740 {
741 register Lisp_Object val;
742 int count = specpdl_ptr - specpdl;
dcdffbf6 743 Lisp_Object list;
1ab256cb
RM
744
745 record_unwind_protect (save_excursion_restore, save_excursion_save ());
746 set_buffer_internal (b);
dcdffbf6
RS
747
748 /* First run the query functions; if any query is answered no,
749 don't kill the buffer. */
750 for (list = Vkill_buffer_query_functions; !NILP (list); list = Fcdr (list))
751 {
752 tem = call0 (Fcar (list));
753 if (NILP (tem))
754 return unbind_to (count, Qnil);
755 }
756
757 /* Then run the hooks. */
fd186f07
RS
758 if (!NILP (Vrun_hooks))
759 call1 (Vrun_hooks, Qkill_buffer_hook);
1ab256cb
RM
760 unbind_to (count, Qnil);
761 }
762
763 /* We have no more questions to ask. Verify that it is valid
764 to kill the buffer. This must be done after the questions
765 since anything can happen within do_yes_or_no_p. */
766
767 /* Don't kill the minibuffer now current. */
768 if (EQ (buf, XWINDOW (minibuf_window)->buffer))
769 return Qnil;
770
265a9e55 771 if (NILP (b->name))
1ab256cb
RM
772 return Qnil;
773
774 /* Make this buffer not be current.
775 In the process, notice if this is the sole visible buffer
776 and give up if so. */
777 if (b == current_buffer)
778 {
172a9c1f 779 tem = Fother_buffer (buf, Qnil);
1ab256cb
RM
780 Fset_buffer (tem);
781 if (b == current_buffer)
782 return Qnil;
783 }
784
785 /* Now there is no question: we can kill the buffer. */
786
787#ifdef CLASH_DETECTION
788 /* Unlock this buffer's file, if it is locked. */
789 unlock_buffer (b);
790#endif /* CLASH_DETECTION */
791
1ab256cb 792 kill_buffer_processes (buf);
1ab256cb
RM
793
794 tem = Vinhibit_quit;
795 Vinhibit_quit = Qt;
796 Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist);
797 Freplace_buffer_in_windows (buf);
798 Vinhibit_quit = tem;
799
800 /* Delete any auto-save file. */
801 if (XTYPE (b->auto_save_file_name) == Lisp_String)
802 {
803 Lisp_Object tem;
804 tem = Fsymbol_value (intern ("delete-auto-save-files"));
265a9e55 805 if (! NILP (tem))
1ab256cb
RM
806 unlink (XSTRING (b->auto_save_file_name)->data);
807 }
808
809 /* Unchain all markers of this buffer
810 and leave them pointing nowhere. */
811 for (tem = b->markers; !EQ (tem, Qnil); )
812 {
813 m = XMARKER (tem);
814 m->buffer = 0;
815 tem = m->chain;
816 m->chain = Qnil;
817 }
818 b->markers = Qnil;
819
33f7013e
JA
820 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
821 INITIALIZE_INTERVAL (b, NULL_INTERVAL);
822 /* Perhaps we should explicitly free the interval tree here... */
823
1ab256cb 824 b->name = Qnil;
9ac0d9e0 825 BLOCK_INPUT;
1ab256cb 826 BUFFER_FREE (BUF_BEG_ADDR (b));
9ac0d9e0 827 UNBLOCK_INPUT;
1ab256cb
RM
828 b->undo_list = Qnil;
829
830 return Qt;
831}
832\f
36a8c287
JB
833/* Move the assoc for buffer BUF to the front of buffer-alist. Since
834 we do this each time BUF is selected visibly, the more recently
835 selected buffers are always closer to the front of the list. This
836 means that other_buffer is more likely to choose a relevant buffer. */
1ab256cb
RM
837
838record_buffer (buf)
839 Lisp_Object buf;
840{
841 register Lisp_Object link, prev;
842
843 prev = Qnil;
844 for (link = Vbuffer_alist; CONSP (link); link = XCONS (link)->cdr)
845 {
846 if (EQ (XCONS (XCONS (link)->car)->cdr, buf))
847 break;
848 prev = link;
849 }
850
36a8c287
JB
851 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
852 we cannot use Fdelq itself here because it allows quitting. */
1ab256cb 853
265a9e55 854 if (NILP (prev))
1ab256cb
RM
855 Vbuffer_alist = XCONS (Vbuffer_alist)->cdr;
856 else
857 XCONS (prev)->cdr = XCONS (XCONS (prev)->cdr)->cdr;
858
859 XCONS(link)->cdr = Vbuffer_alist;
860 Vbuffer_alist = link;
861}
862
863DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ",
864 "Select buffer BUFFER in the current window.\n\
865BUFFER may be a buffer or a buffer name.\n\
866Optional second arg NORECORD non-nil means\n\
867do not put this buffer at the front of the list of recently selected ones.\n\
868\n\
869WARNING: This is NOT the way to work on another buffer temporarily\n\
870within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
871the window-buffer correspondences.")
872 (bufname, norecord)
873 Lisp_Object bufname, norecord;
874{
875 register Lisp_Object buf;
876 Lisp_Object tem;
877
878 if (EQ (minibuf_window, selected_window))
879 error ("Cannot switch buffers in minibuffer window");
880 tem = Fwindow_dedicated_p (selected_window);
265a9e55 881 if (!NILP (tem))
1ab256cb
RM
882 error ("Cannot switch buffers in a dedicated window");
883
265a9e55 884 if (NILP (bufname))
172a9c1f 885 buf = Fother_buffer (Fcurrent_buffer (), Qnil);
1ab256cb
RM
886 else
887 buf = Fget_buffer_create (bufname);
888 Fset_buffer (buf);
265a9e55 889 if (NILP (norecord))
1ab256cb
RM
890 record_buffer (buf);
891
892 Fset_window_buffer (EQ (selected_window, minibuf_window)
5fcd022d
JB
893 ? Fnext_window (minibuf_window, Qnil, Qnil)
894 : selected_window,
1ab256cb
RM
895 buf);
896
e8b3a22d 897 return buf;
1ab256cb
RM
898}
899
900DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 2, 0,
901 "Select buffer BUFFER in some window, preferably a different one.\n\
902If BUFFER is nil, then some other buffer is chosen.\n\
903If `pop-up-windows' is non-nil, windows can be split to do this.\n\
904If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
905window even if BUFFER is already visible in the selected window.")
906 (bufname, other)
907 Lisp_Object bufname, other;
908{
909 register Lisp_Object buf;
265a9e55 910 if (NILP (bufname))
172a9c1f 911 buf = Fother_buffer (Fcurrent_buffer (), Qnil);
1ab256cb
RM
912 else
913 buf = Fget_buffer_create (bufname);
914 Fset_buffer (buf);
915 record_buffer (buf);
916 Fselect_window (Fdisplay_buffer (buf, other));
e8b3a22d 917 return buf;
1ab256cb
RM
918}
919
920DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,
921 "Return the current buffer as a Lisp object.")
922 ()
923{
924 register Lisp_Object buf;
925 XSET (buf, Lisp_Buffer, current_buffer);
926 return buf;
927}
928\f
929/* Set the current buffer to b */
930
931void
932set_buffer_internal (b)
933 register struct buffer *b;
934{
935 register struct buffer *old_buf;
936 register Lisp_Object tail, valcontents;
937 enum Lisp_Type tem;
938
939 if (current_buffer == b)
940 return;
941
942 windows_or_buffers_changed = 1;
943 old_buf = current_buffer;
944 current_buffer = b;
945 last_known_column_point = -1; /* invalidate indentation cache */
946
947 /* Look down buffer's list of local Lisp variables
948 to find and update any that forward into C variables. */
949
265a9e55 950 for (tail = b->local_var_alist; !NILP (tail); tail = XCONS (tail)->cdr)
1ab256cb
RM
951 {
952 valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value;
953 if ((XTYPE (valcontents) == Lisp_Buffer_Local_Value
954 || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value)
955 && (tem = XTYPE (XCONS (valcontents)->car),
956 (tem == Lisp_Boolfwd || tem == Lisp_Intfwd
957 || tem == Lisp_Objfwd)))
958 /* Just reference the variable
959 to cause it to become set for this buffer. */
960 Fsymbol_value (XCONS (XCONS (tail)->car)->car);
961 }
962
963 /* Do the same with any others that were local to the previous buffer */
964
965 if (old_buf)
265a9e55 966 for (tail = old_buf->local_var_alist; !NILP (tail); tail = XCONS (tail)->cdr)
1ab256cb
RM
967 {
968 valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value;
969 if ((XTYPE (valcontents) == Lisp_Buffer_Local_Value
970 || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value)
971 && (tem = XTYPE (XCONS (valcontents)->car),
972 (tem == Lisp_Boolfwd || tem == Lisp_Intfwd
973 || tem == Lisp_Objfwd)))
974 /* Just reference the variable
975 to cause it to become set for this buffer. */
976 Fsymbol_value (XCONS (XCONS (tail)->car)->car);
977 }
978}
979
980DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,
981 "Make the buffer BUFFER current for editing operations.\n\
982BUFFER may be a buffer or the name of an existing buffer.\n\
983See also `save-excursion' when you want to make a buffer current temporarily.\n\
984This function does not display the buffer, so its effect ends\n\
985when the current command terminates.\n\
986Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
987 (bufname)
988 register Lisp_Object bufname;
989{
990 register Lisp_Object buffer;
991 buffer = Fget_buffer (bufname);
265a9e55 992 if (NILP (buffer))
1ab256cb 993 nsberror (bufname);
265a9e55 994 if (NILP (XBUFFER (buffer)->name))
1ab256cb
RM
995 error ("Selecting deleted buffer");
996 set_buffer_internal (XBUFFER (buffer));
997 return buffer;
998}
999\f
1000DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only,
1001 Sbarf_if_buffer_read_only, 0, 0, 0,
1002 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1003 ()
1004{
a96b68f1
RS
1005 if (!NILP (current_buffer->read_only)
1006 && NILP (Vinhibit_read_only))
1ab256cb
RM
1007 Fsignal (Qbuffer_read_only, (Fcons (Fcurrent_buffer (), Qnil)));
1008 return Qnil;
1009}
1010
1011DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",
1012 "Put BUFFER at the end of the list of all buffers.\n\
1013There it is the least likely candidate for `other-buffer' to return;\n\
528415e7 1014thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
a5611885
JB
1015If BUFFER is nil or omitted, bury the current buffer.\n\
1016Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1017selected window if it is displayed there.")
1ab256cb
RM
1018 (buf)
1019 register Lisp_Object buf;
1020{
b271272a 1021 /* Figure out what buffer we're going to bury. */
265a9e55 1022 if (NILP (buf))
a5611885
JB
1023 {
1024 XSET (buf, Lisp_Buffer, current_buffer);
1025
1026 /* If we're burying the current buffer, unshow it. */
5fcd022d 1027 Fswitch_to_buffer (Fother_buffer (buf, Qnil), Qnil);
a5611885 1028 }
1ab256cb
RM
1029 else
1030 {
1031 Lisp_Object buf1;
1032
1033 buf1 = Fget_buffer (buf);
265a9e55 1034 if (NILP (buf1))
1ab256cb
RM
1035 nsberror (buf);
1036 buf = buf1;
b271272a
JB
1037 }
1038
a5611885 1039 /* Move buf to the end of the buffer list. */
b271272a
JB
1040 {
1041 register Lisp_Object aelt, link;
1042
1043 aelt = Frassq (buf, Vbuffer_alist);
1044 link = Fmemq (aelt, Vbuffer_alist);
1045 Vbuffer_alist = Fdelq (aelt, Vbuffer_alist);
1046 XCONS (link)->cdr = Qnil;
1047 Vbuffer_alist = nconc2 (Vbuffer_alist, link);
1048 }
1ab256cb 1049
1ab256cb
RM
1050 return Qnil;
1051}
1052\f
c922bc55 1053DEFUN ("erase-buffer", Ferase_buffer, Serase_buffer, 0, 0, "*",
1ab256cb 1054 "Delete the entire contents of the current buffer.\n\
2950a20e 1055Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1ab256cb
RM
1056so the buffer is truly empty after this.")
1057 ()
1058{
1059 Fwiden ();
1060 del_range (BEG, Z);
1061 current_buffer->last_window_start = 1;
1062 /* Prevent warnings, or suspension of auto saving, that would happen
1063 if future size is less than past size. Use of erase-buffer
1064 implies that the future text is not really related to the past text. */
1065 XFASTINT (current_buffer->save_length) = 0;
1066 return Qnil;
1067}
1068
1069validate_region (b, e)
1070 register Lisp_Object *b, *e;
1071{
1072 register int i;
1073
1074 CHECK_NUMBER_COERCE_MARKER (*b, 0);
1075 CHECK_NUMBER_COERCE_MARKER (*e, 1);
1076
1077 if (XINT (*b) > XINT (*e))
1078 {
1079 i = XFASTINT (*b); /* This is legit even if *b is < 0 */
1080 *b = *e;
1081 XFASTINT (*e) = i; /* because this is all we do with i. */
1082 }
1083
1084 if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e)
1085 && XINT (*e) <= ZV))
1086 args_out_of_range (*b, *e);
1087}
1088\f
9f31d21b 1089static Lisp_Object
1ab256cb
RM
1090list_buffers_1 (files)
1091 Lisp_Object files;
1092{
1093 register Lisp_Object tail, tem, buf;
1094 Lisp_Object col1, col2, col3, minspace;
1095 register struct buffer *old = current_buffer, *b;
718cde7d 1096 Lisp_Object desired_point;
1ab256cb
RM
1097 Lisp_Object other_file_symbol;
1098
718cde7d 1099 desired_point = Qnil;
1ab256cb
RM
1100 other_file_symbol = intern ("list-buffers-directory");
1101
1102 XFASTINT (col1) = 19;
1103 XFASTINT (col2) = 25;
1104 XFASTINT (col3) = 40;
1105 XFASTINT (minspace) = 1;
1106
1107 Fset_buffer (Vstandard_output);
1ab256cb
RM
1108 Fbuffer_disable_undo (Vstandard_output);
1109 current_buffer->read_only = Qnil;
1110
1111 write_string ("\
1112 MR Buffer Size Mode File\n\
1113 -- ------ ---- ---- ----\n", -1);
1114
265a9e55 1115 for (tail = Vbuffer_alist; !NILP (tail); tail = Fcdr (tail))
1ab256cb
RM
1116 {
1117 buf = Fcdr (Fcar (tail));
1118 b = XBUFFER (buf);
1119 /* Don't mention the minibuffers. */
1120 if (XSTRING (b->name)->data[0] == ' ')
1121 continue;
1122 /* Optionally don't mention buffers that lack files. */
265a9e55 1123 if (!NILP (files) && NILP (b->filename))
1ab256cb
RM
1124 continue;
1125 /* Identify the current buffer. */
1126 if (b == old)
718cde7d 1127 XFASTINT (desired_point) = point;
1ab256cb
RM
1128 write_string (b == old ? "." : " ", -1);
1129 /* Identify modified buffers */
1130 write_string (BUF_MODIFF (b) > b->save_modified ? "*" : " ", -1);
265a9e55 1131 write_string (NILP (b->read_only) ? " " : "% ", -1);
1ab256cb
RM
1132 Fprinc (b->name, Qnil);
1133 Findent_to (col1, make_number (2));
1134 XFASTINT (tem) = BUF_Z (b) - BUF_BEG (b);
1135 Fprin1 (tem, Qnil);
1136 Findent_to (col2, minspace);
1137 Fprinc (b->mode_name, Qnil);
1138 Findent_to (col3, minspace);
1139
265a9e55 1140 if (!NILP (b->filename))
1ab256cb
RM
1141 Fprinc (b->filename, Qnil);
1142 else
1143 {
1144 /* No visited file; check local value of list-buffers-directory. */
1145 Lisp_Object tem;
1146 set_buffer_internal (b);
1147 tem = Fboundp (other_file_symbol);
265a9e55 1148 if (!NILP (tem))
1ab256cb
RM
1149 {
1150 tem = Fsymbol_value (other_file_symbol);
1151 Fset_buffer (Vstandard_output);
1152 if (XTYPE (tem) == Lisp_String)
1153 Fprinc (tem, Qnil);
1154 }
1155 else
1156 Fset_buffer (Vstandard_output);
1157 }
1158 write_string ("\n", -1);
1159 }
1160
9f31d21b
KH
1161 tail = intern ("Buffer-menu-mode");
1162 if ((tem = Ffboundp (tail), !NILP (tem)))
1163 call0 (tail);
1ab256cb 1164 set_buffer_internal (old);
718cde7d 1165 return desired_point;
1ab256cb
RM
1166}
1167
1168DEFUN ("list-buffers", Flist_buffers, Slist_buffers, 0, 1, "P",
1169 "Display a list of names of existing buffers.\n\
1170The list is displayed in a buffer named `*Buffer List*'.\n\
1171Note that buffers with names starting with spaces are omitted.\n\
1172Non-null optional arg FILES-ONLY means mention only file buffers.\n\
1173\n\
1174The M column contains a * for buffers that are modified.\n\
1175The R column contains a % for buffers that are read-only.")
1176 (files)
1177 Lisp_Object files;
1178{
e87f38ef
JB
1179 Lisp_Object desired_point;
1180
fd2dab90
RS
1181 desired_point
1182 = internal_with_output_to_temp_buffer ("*Buffer List*",
1183 list_buffers_1, files);
e87f38ef 1184
718cde7d
JB
1185 if (NUMBERP (desired_point))
1186 {
1187 int count = specpdl_ptr - specpdl;
1188 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
1189 Fset_buffer (build_string ("*Buffer List*"));
1190 SET_PT (XINT (desired_point));
1191 return unbind_to (count, Qnil);
1192 }
fd2dab90 1193 return Qnil;
1ab256cb
RM
1194}
1195
1196DEFUN ("kill-all-local-variables", Fkill_all_local_variables, Skill_all_local_variables,
1197 0, 0, 0,
1198 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1199Most local variable bindings are eliminated so that the default values\n\
1200become effective once more. Also, the syntax table is set from\n\
1201`standard-syntax-table', the local keymap is set to nil,\n\
1202and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1203This function also forces redisplay of the mode line.\n\
1204\n\
1205Every function to select a new major mode starts by\n\
1206calling this function.\n\n\
1207As a special exception, local variables whose names have\n\
c5a15222
RS
1208a non-nil `permanent-local' property are not eliminated by this function.\n\
1209\n\
1210The first thing this function does is run\n\
1211the normal hook `change-major-mode-hook'.")
1ab256cb
RM
1212 ()
1213{
1214 register Lisp_Object alist, sym, tem;
1215 Lisp_Object oalist;
7410477a 1216
fd186f07
RS
1217 if (!NILP (Vrun_hooks))
1218 call1 (Vrun_hooks, intern ("change-major-mode-hook"));
1ab256cb
RM
1219 oalist = current_buffer->local_var_alist;
1220
1221 /* Make sure no local variables remain set up with this buffer
1222 for their current values. */
1223
265a9e55 1224 for (alist = oalist; !NILP (alist); alist = XCONS (alist)->cdr)
1ab256cb
RM
1225 {
1226 sym = XCONS (XCONS (alist)->car)->car;
1227
1228 /* Need not do anything if some other buffer's binding is now encached. */
1229 tem = XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->car;
1230 if (XBUFFER (tem) == current_buffer)
1231 {
1232 /* Symbol is set up for this buffer's old local value.
1233 Set it up for the current buffer with the default value. */
1234
1235 tem = XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->cdr;
542143d7
RS
1236 /* Store the symbol's current value into the alist entry
1237 it is currently set up for. This is so that, if the
1238 local is marked permanent, and we make it local again below,
1239 we don't lose the value. */
2735b685
RS
1240 XCONS (XCONS (tem)->car)->cdr
1241 = do_symval_forwarding (XCONS (XSYMBOL (sym)->value)->car);
542143d7 1242 /* Switch to the symbol's default-value alist entry. */
1ab256cb 1243 XCONS (tem)->car = tem;
542143d7 1244 /* Mark it as current for the current buffer. */
1ab256cb 1245 XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->car = Fcurrent_buffer ();
542143d7 1246 /* Store the current value into any forwarding in the symbol. */
1ab256cb
RM
1247 store_symval_forwarding (sym, XCONS (XSYMBOL (sym)->value)->car,
1248 XCONS (tem)->cdr);
1249 }
1250 }
1251
1252 /* Actually eliminate all local bindings of this buffer. */
1253
1254 reset_buffer_local_variables (current_buffer);
1255
1256 /* Redisplay mode lines; we are changing major mode. */
1257
1258 update_mode_lines++;
1259
1260 /* Any which are supposed to be permanent,
1261 make local again, with the same values they had. */
1262
265a9e55 1263 for (alist = oalist; !NILP (alist); alist = XCONS (alist)->cdr)
1ab256cb
RM
1264 {
1265 sym = XCONS (XCONS (alist)->car)->car;
1266 tem = Fget (sym, Qpermanent_local);
265a9e55 1267 if (! NILP (tem))
01050cb5
RM
1268 {
1269 Fmake_local_variable (sym);
1270 Fset (sym, XCONS (XCONS (alist)->car)->cdr);
1271 }
1ab256cb
RM
1272 }
1273
1274 /* Force mode-line redisplay. Useful here because all major mode
1275 commands call this function. */
1276 update_mode_lines++;
1277
1278 return Qnil;
1279}
1280\f
2eec3b4e
RS
1281/* Find all the overlays in the current buffer that contain position POS.
1282 Return the number found, and store them in a vector in *VEC_PTR.
1283 Store in *LEN_PTR the size allocated for the vector.
52f8ec73
JB
1284 Store in *NEXT_PTR the next position after POS where an overlay starts,
1285 or ZV if there are no more overlays.
2eec3b4e
RS
1286
1287 *VEC_PTR and *LEN_PTR should contain a valid vector and size
61d54cd5
RS
1288 when this function is called.
1289
1290 If EXTEND is non-zero, we make the vector bigger if necessary.
1291 If EXTEND is zero, we never extend the vector,
1292 and we store only as many overlays as will fit.
1293 But we still return the total number of overlays. */
2eec3b4e
RS
1294
1295int
61d54cd5 1296overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr)
2eec3b4e 1297 int pos;
61d54cd5 1298 int extend;
2eec3b4e
RS
1299 Lisp_Object **vec_ptr;
1300 int *len_ptr;
1301 int *next_ptr;
1ab256cb 1302{
2eec3b4e
RS
1303 Lisp_Object tail, overlay, start, end, result;
1304 int idx = 0;
1305 int len = *len_ptr;
1306 Lisp_Object *vec = *vec_ptr;
1307 int next = ZV;
61d54cd5
RS
1308 int inhibit_storing = 0;
1309
2eec3b4e 1310 for (tail = current_buffer->overlays_before;
4a44b14c 1311 XGCTYPE (tail) == Lisp_Cons;
2eec3b4e
RS
1312 tail = XCONS (tail)->cdr)
1313 {
52f8ec73
JB
1314 int startpos;
1315
2eec3b4e 1316 overlay = XCONS (tail)->car;
3ccf510a 1317 if (XGCTYPE (overlay) != Lisp_Overlay)
52f8ec73 1318 abort ();
1ab256cb 1319
2eec3b4e
RS
1320 start = OVERLAY_START (overlay);
1321 end = OVERLAY_END (overlay);
1322 if (OVERLAY_POSITION (end) <= pos)
1323 break;
1324 startpos = OVERLAY_POSITION (start);
1325 if (startpos <= pos)
1326 {
1327 if (idx == len)
1328 {
61d54cd5
RS
1329 /* The supplied vector is full.
1330 Either make it bigger, or don't store any more in it. */
1331 if (extend)
1332 {
1333 *len_ptr = len *= 2;
1334 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
1335 *vec_ptr = vec;
1336 }
1337 else
1338 inhibit_storing = 1;
2eec3b4e 1339 }
61d54cd5
RS
1340
1341 if (!inhibit_storing)
1342 vec[idx] = overlay;
1343 /* Keep counting overlays even if we can't return them all. */
1344 idx++;
2eec3b4e
RS
1345 }
1346 else if (startpos < next)
1347 next = startpos;
1348 }
1349
1350 for (tail = current_buffer->overlays_after;
4a44b14c 1351 XGCTYPE (tail) == Lisp_Cons;
2eec3b4e 1352 tail = XCONS (tail)->cdr)
1ab256cb 1353 {
52f8ec73
JB
1354 int startpos;
1355
2eec3b4e 1356 overlay = XCONS (tail)->car;
3ccf510a 1357 if (XGCTYPE (overlay) != Lisp_Overlay)
52f8ec73 1358 abort ();
2eec3b4e
RS
1359
1360 start = OVERLAY_START (overlay);
1361 end = OVERLAY_END (overlay);
1362 startpos = OVERLAY_POSITION (start);
52f8ec73 1363 if (pos < startpos)
2eec3b4e
RS
1364 {
1365 if (startpos < next)
1366 next = startpos;
1367 break;
1368 }
52f8ec73 1369 if (pos < OVERLAY_POSITION (end))
2eec3b4e
RS
1370 {
1371 if (idx == len)
1372 {
61d54cd5
RS
1373 if (extend)
1374 {
1375 *len_ptr = len *= 2;
1376 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
1377 *vec_ptr = vec;
1378 }
1379 else
1380 inhibit_storing = 1;
2eec3b4e 1381 }
61d54cd5
RS
1382
1383 if (!inhibit_storing)
1384 vec[idx] = overlay;
1385 idx++;
2eec3b4e 1386 }
1ab256cb
RM
1387 }
1388
2eec3b4e
RS
1389 *next_ptr = next;
1390 return idx;
1391}
1392\f
5985d248
KH
1393struct sortvec
1394{
1395 Lisp_Object overlay;
1396 int beg, end;
1397 int priority;
1398};
1399
1400static int
1401compare_overlays (s1, s2)
1402 struct sortvec *s1, *s2;
1403{
1404 if (s1->priority != s2->priority)
1405 return s1->priority - s2->priority;
1406 if (s1->beg != s2->beg)
1407 return s1->beg - s2->beg;
1408 if (s1->end != s2->end)
1409 return s2->end - s1->end;
1410 return 0;
1411}
1412
1413/* Sort an array of overlays by priority. The array is modified in place.
1414 The return value is the new size; this may be smaller than the original
1415 size if some of the overlays were invalid or were window-specific. */
1416int
1417sort_overlays (overlay_vec, noverlays, w)
1418 Lisp_Object *overlay_vec;
1419 int noverlays;
1420 struct window *w;
1421{
1422 int i, j;
1423 struct sortvec *sortvec;
1424 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
1425
1426 /* Put the valid and relevant overlays into sortvec. */
1427
1428 for (i = 0, j = 0; i < noverlays; i++)
1429 {
0fa767e7 1430 Lisp_Object tem;
c99fc30f 1431 Lisp_Object overlay;
5985d248 1432
c99fc30f 1433 overlay = overlay_vec[i];
5985d248
KH
1434 if (OVERLAY_VALID (overlay)
1435 && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0
1436 && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0)
1437 {
0fa767e7
KH
1438 /* If we're interested in a specific window, then ignore
1439 overlays that are limited to some other window. */
1440 if (w)
5985d248 1441 {
0fa767e7
KH
1442 Lisp_Object window;
1443
1444 window = Foverlay_get (overlay, Qwindow);
1445 if (XTYPE (window) == Lisp_Window && XWINDOW (window) != w)
1446 continue;
5985d248 1447 }
0fa767e7
KH
1448
1449 /* This overlay is good and counts: put it into sortvec. */
1450 sortvec[j].overlay = overlay;
1451 sortvec[j].beg = OVERLAY_POSITION (OVERLAY_START (overlay));
1452 sortvec[j].end = OVERLAY_POSITION (OVERLAY_END (overlay));
1453 tem = Foverlay_get (overlay, Qpriority);
1454 if (INTEGERP (tem))
1455 sortvec[j].priority = XINT (tem);
1456 else
1457 sortvec[j].priority = 0;
1458 j++;
5985d248
KH
1459 }
1460 }
1461 noverlays = j;
1462
1463 /* Sort the overlays into the proper order: increasing priority. */
1464
1465 if (noverlays > 1)
1466 qsort (sortvec, noverlays, sizeof (struct sortvec), compare_overlays);
1467
1468 for (i = 0; i < noverlays; i++)
1469 overlay_vec[i] = sortvec[i].overlay;
1470 return (noverlays);
1471}
1472\f
5c4f68f1 1473/* Shift overlays in BUF's overlay lists, to center the lists at POS. */
1ab256cb 1474
2eec3b4e 1475void
5c4f68f1
JB
1476recenter_overlay_lists (buf, pos)
1477 struct buffer *buf;
2eec3b4e
RS
1478 int pos;
1479{
1480 Lisp_Object overlay, tail, next, prev, beg, end;
1481
1482 /* See if anything in overlays_before should move to overlays_after. */
1483
1484 /* We don't strictly need prev in this loop; it should always be nil.
1485 But we use it for symmetry and in case that should cease to be true
1486 with some future change. */
1487 prev = Qnil;
5c4f68f1 1488 for (tail = buf->overlays_before;
2eec3b4e
RS
1489 CONSP (tail);
1490 prev = tail, tail = next)
1ab256cb 1491 {
2eec3b4e
RS
1492 next = XCONS (tail)->cdr;
1493 overlay = XCONS (tail)->car;
1494
1495 /* If the overlay is not valid, get rid of it. */
1496 if (!OVERLAY_VALID (overlay))
52f8ec73
JB
1497#if 1
1498 abort ();
1499#else
2eec3b4e
RS
1500 {
1501 /* Splice the cons cell TAIL out of overlays_before. */
1502 if (!NILP (prev))
1503 XCONS (prev)->cdr = next;
1504 else
5c4f68f1 1505 buf->overlays_before = next;
2eec3b4e
RS
1506 tail = prev;
1507 continue;
1508 }
52f8ec73 1509#endif
1ab256cb 1510
2eec3b4e
RS
1511 beg = OVERLAY_START (overlay);
1512 end = OVERLAY_END (overlay);
1ab256cb 1513
2eec3b4e 1514 if (OVERLAY_POSITION (end) > pos)
1ab256cb 1515 {
2eec3b4e
RS
1516 /* OVERLAY needs to be moved. */
1517 int where = OVERLAY_POSITION (beg);
1518 Lisp_Object other, other_prev;
1519
1520 /* Splice the cons cell TAIL out of overlays_before. */
1521 if (!NILP (prev))
1522 XCONS (prev)->cdr = next;
1523 else
5c4f68f1 1524 buf->overlays_before = next;
2eec3b4e
RS
1525
1526 /* Search thru overlays_after for where to put it. */
1527 other_prev = Qnil;
5c4f68f1 1528 for (other = buf->overlays_after;
2eec3b4e
RS
1529 CONSP (other);
1530 other_prev = other, other = XCONS (other)->cdr)
1ab256cb 1531 {
2eec3b4e
RS
1532 Lisp_Object otherbeg, otheroverlay, follower;
1533 int win;
1534
1535 otheroverlay = XCONS (other)->car;
1536 if (! OVERLAY_VALID (otheroverlay))
52f8ec73 1537 abort ();
2eec3b4e
RS
1538
1539 otherbeg = OVERLAY_START (otheroverlay);
1540 if (OVERLAY_POSITION (otherbeg) >= where)
1541 break;
1ab256cb 1542 }
2eec3b4e
RS
1543
1544 /* Add TAIL to overlays_after before OTHER. */
1545 XCONS (tail)->cdr = other;
1546 if (!NILP (other_prev))
1547 XCONS (other_prev)->cdr = tail;
1ab256cb 1548 else
5c4f68f1 1549 buf->overlays_after = tail;
2eec3b4e 1550 tail = prev;
1ab256cb 1551 }
2eec3b4e
RS
1552 else
1553 /* We've reached the things that should stay in overlays_before.
1554 All the rest of overlays_before must end even earlier,
1555 so stop now. */
1556 break;
1557 }
1558
1559 /* See if anything in overlays_after should be in overlays_before. */
1560 prev = Qnil;
5c4f68f1 1561 for (tail = buf->overlays_after;
2eec3b4e
RS
1562 CONSP (tail);
1563 prev = tail, tail = next)
1564 {
1565 next = XCONS (tail)->cdr;
1566 overlay = XCONS (tail)->car;
1567
1568 /* If the overlay is not valid, get rid of it. */
1569 if (!OVERLAY_VALID (overlay))
52f8ec73
JB
1570#if 1
1571 abort ();
1572#else
2eec3b4e
RS
1573 {
1574 /* Splice the cons cell TAIL out of overlays_after. */
1575 if (!NILP (prev))
1576 XCONS (prev)->cdr = next;
1577 else
5c4f68f1 1578 buf->overlays_after = next;
2eec3b4e
RS
1579 tail = prev;
1580 continue;
1581 }
52f8ec73 1582#endif
2eec3b4e
RS
1583
1584 beg = OVERLAY_START (overlay);
1585 end = OVERLAY_END (overlay);
1586
1587 /* Stop looking, when we know that nothing further
1588 can possibly end before POS. */
1589 if (OVERLAY_POSITION (beg) > pos)
1590 break;
1591
1592 if (OVERLAY_POSITION (end) <= pos)
1593 {
1594 /* OVERLAY needs to be moved. */
1595 int where = OVERLAY_POSITION (end);
1596 Lisp_Object other, other_prev;
1597
1598 /* Splice the cons cell TAIL out of overlays_after. */
1599 if (!NILP (prev))
1600 XCONS (prev)->cdr = next;
1601 else
5c4f68f1 1602 buf->overlays_after = next;
2eec3b4e
RS
1603
1604 /* Search thru overlays_before for where to put it. */
1605 other_prev = Qnil;
5c4f68f1 1606 for (other = buf->overlays_before;
2eec3b4e
RS
1607 CONSP (other);
1608 other_prev = other, other = XCONS (other)->cdr)
1609 {
1610 Lisp_Object otherend, otheroverlay;
1611 int win;
1612
1613 otheroverlay = XCONS (other)->car;
1614 if (! OVERLAY_VALID (otheroverlay))
52f8ec73 1615 abort ();
2eec3b4e
RS
1616
1617 otherend = OVERLAY_END (otheroverlay);
1618 if (OVERLAY_POSITION (otherend) <= where)
1619 break;
1620 }
1621
1622 /* Add TAIL to overlays_before before OTHER. */
1623 XCONS (tail)->cdr = other;
1624 if (!NILP (other_prev))
1625 XCONS (other_prev)->cdr = tail;
1626 else
5c4f68f1 1627 buf->overlays_before = tail;
2eec3b4e
RS
1628 tail = prev;
1629 }
1630 }
1631
5c4f68f1 1632 XFASTINT (buf->overlay_center) = pos;
2eec3b4e
RS
1633}
1634\f
52f8ec73
JB
1635DEFUN ("overlayp", Foverlayp, Soverlayp, 1, 1, 0,
1636 "Return t if OBJECT is an overlay.")
1637 (object)
1638 Lisp_Object object;
1639{
1640 return (OVERLAYP (object) ? Qt : Qnil);
1641}
1642
5c4f68f1
JB
1643DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 3, 0,
1644 "Create a new overlay with range BEG to END in BUFFER.\n\
1645If omitted, BUFFER defaults to the current buffer.\n\
2eec3b4e 1646BEG and END may be integers or markers.")
5c4f68f1
JB
1647 (beg, end, buffer)
1648 Lisp_Object beg, end, buffer;
2eec3b4e
RS
1649{
1650 Lisp_Object overlay;
5c4f68f1 1651 struct buffer *b;
2eec3b4e 1652
5c4f68f1
JB
1653 if (NILP (buffer))
1654 XSET (buffer, Lisp_Buffer, current_buffer);
883047b9
JB
1655 else
1656 CHECK_BUFFER (buffer, 2);
1657 if (MARKERP (beg)
1658 && ! EQ (Fmarker_buffer (beg), buffer))
1659 error ("Marker points into wrong buffer");
1660 if (MARKERP (end)
1661 && ! EQ (Fmarker_buffer (end), buffer))
1662 error ("Marker points into wrong buffer");
2eec3b4e 1663
883047b9
JB
1664 CHECK_NUMBER_COERCE_MARKER (beg, 1);
1665 CHECK_NUMBER_COERCE_MARKER (end, 1);
5c4f68f1 1666
883047b9 1667 if (XINT (beg) > XINT (end))
5c4f68f1 1668 {
c99fc30f
KH
1669 Lisp_Object temp;
1670 temp = beg; beg = end; end = temp;
5c4f68f1 1671 }
883047b9
JB
1672
1673 b = XBUFFER (buffer);
1674
1675 beg = Fset_marker (Fmake_marker (), beg, buffer);
1676 end = Fset_marker (Fmake_marker (), end, buffer);
5c4f68f1
JB
1677
1678 overlay = Fcons (Fcons (beg, end), Qnil);
52f8ec73 1679 XSETTYPE (overlay, Lisp_Overlay);
2eec3b4e
RS
1680
1681 /* Put the new overlay on the wrong list. */
1682 end = OVERLAY_END (overlay);
5c4f68f1
JB
1683 if (OVERLAY_POSITION (end) < XINT (b->overlay_center))
1684 b->overlays_after = Fcons (overlay, b->overlays_after);
2eec3b4e 1685 else
5c4f68f1 1686 b->overlays_before = Fcons (overlay, b->overlays_before);
2eec3b4e
RS
1687
1688 /* This puts it in the right list, and in the right order. */
5c4f68f1 1689 recenter_overlay_lists (b, XINT (b->overlay_center));
2eec3b4e 1690
b61982dd
JB
1691 /* We don't need to redisplay the region covered by the overlay, because
1692 the overlay has no properties at the moment. */
1693
2eec3b4e
RS
1694 return overlay;
1695}
1696
5c4f68f1
JB
1697DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0,
1698 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
3ece337a
JB
1699If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
1700If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
1701buffer.")
5c4f68f1
JB
1702 (overlay, beg, end, buffer)
1703 Lisp_Object overlay, beg, end, buffer;
2eec3b4e 1704{
0a4469c9
RS
1705 struct buffer *b, *ob;
1706 Lisp_Object obuffer;
1707 int count = specpdl_ptr - specpdl;
5c4f68f1 1708
52f8ec73 1709 CHECK_OVERLAY (overlay, 0);
5c4f68f1
JB
1710 if (NILP (buffer))
1711 buffer = Fmarker_buffer (OVERLAY_START (overlay));
3ece337a
JB
1712 if (NILP (buffer))
1713 XSET (buffer, Lisp_Buffer, current_buffer);
5c4f68f1 1714 CHECK_BUFFER (buffer, 3);
883047b9
JB
1715
1716 if (MARKERP (beg)
1717 && ! EQ (Fmarker_buffer (beg), buffer))
1718 error ("Marker points into wrong buffer");
1719 if (MARKERP (end)
1720 && ! EQ (Fmarker_buffer (end), buffer))
1721 error ("Marker points into wrong buffer");
1722
b61982dd
JB
1723 CHECK_NUMBER_COERCE_MARKER (beg, 1);
1724 CHECK_NUMBER_COERCE_MARKER (end, 1);
1725
0a4469c9
RS
1726 specbind (Qinhibit_quit, Qt);
1727
b61982dd
JB
1728 if (XINT (beg) > XINT (end))
1729 {
c99fc30f
KH
1730 Lisp_Object temp;
1731 temp = beg; beg = end; end = temp;
b61982dd
JB
1732 }
1733
0a4469c9 1734 obuffer = Fmarker_buffer (OVERLAY_START (overlay));
5c4f68f1 1735 b = XBUFFER (buffer);
0a4469c9 1736 ob = XBUFFER (obuffer);
2eec3b4e 1737
c82ed728 1738 /* If the overlay has changed buffers, do a thorough redisplay. */
0a4469c9 1739 if (!EQ (buffer, obuffer))
c82ed728
JB
1740 windows_or_buffers_changed = 1;
1741 else
1742 /* Redisplay the area the overlay has just left, or just enclosed. */
1743 {
be8b1c6b
RS
1744 Lisp_Object o_beg;
1745 Lisp_Object o_end;
c82ed728
JB
1746 int change_beg, change_end;
1747
be8b1c6b
RS
1748 o_beg = OVERLAY_START (overlay);
1749 o_end = OVERLAY_END (overlay);
c82ed728
JB
1750 o_beg = OVERLAY_POSITION (o_beg);
1751 o_end = OVERLAY_POSITION (o_end);
1752
1753 if (XINT (o_beg) == XINT (beg))
1754 redisplay_region (b, XINT (o_end), XINT (end));
1755 else if (XINT (o_end) == XINT (end))
1756 redisplay_region (b, XINT (o_beg), XINT (beg));
1757 else
1758 {
1759 if (XINT (beg) < XINT (o_beg)) o_beg = beg;
1760 if (XINT (end) > XINT (o_end)) o_end = end;
1761 redisplay_region (b, XINT (o_beg), XINT (o_end));
1762 }
1763 }
b61982dd 1764
0a4469c9
RS
1765 if (!NILP (obuffer))
1766 {
1767 ob->overlays_before = Fdelq (overlay, ob->overlays_before);
1768 ob->overlays_after = Fdelq (overlay, ob->overlays_after);
1769 }
5c4f68f1
JB
1770
1771 Fset_marker (OVERLAY_START (overlay), beg, buffer);
1772 Fset_marker (OVERLAY_END (overlay), end, buffer);
2eec3b4e
RS
1773
1774 /* Put the overlay on the wrong list. */
1775 end = OVERLAY_END (overlay);
5c4f68f1
JB
1776 if (OVERLAY_POSITION (end) < XINT (b->overlay_center))
1777 b->overlays_after = Fcons (overlay, b->overlays_after);
2eec3b4e 1778 else
5c4f68f1 1779 b->overlays_before = Fcons (overlay, b->overlays_before);
2eec3b4e
RS
1780
1781 /* This puts it in the right list, and in the right order. */
5c4f68f1 1782 recenter_overlay_lists (b, XINT (b->overlay_center));
2eec3b4e 1783
0a4469c9 1784 return unbind_to (count, overlay);
2eec3b4e
RS
1785}
1786
1787DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
5c4f68f1 1788 "Delete the overlay OVERLAY from its buffer.")
2eec3b4e 1789 (overlay)
5c4f68f1 1790 Lisp_Object overlay;
2eec3b4e 1791{
0a4469c9 1792 Lisp_Object buffer;
5c4f68f1 1793 struct buffer *b;
0a4469c9 1794 int count = specpdl_ptr - specpdl;
5c4f68f1 1795
52f8ec73
JB
1796 CHECK_OVERLAY (overlay, 0);
1797
0a4469c9
RS
1798 buffer = Fmarker_buffer (OVERLAY_START (overlay));
1799 if (NILP (buffer))
1800 return Qnil;
1801
1802 b = XBUFFER (buffer);
1803
1804 specbind (Qinhibit_quit, Qt);
5c4f68f1
JB
1805
1806 b->overlays_before = Fdelq (overlay, b->overlays_before);
1807 b->overlays_after = Fdelq (overlay, b->overlays_after);
1808
b61982dd 1809 redisplay_region (b,
a927f5c9
RS
1810 marker_position (OVERLAY_START (overlay)),
1811 marker_position (OVERLAY_END (overlay)));
b61982dd 1812
3ece337a
JB
1813 Fset_marker (OVERLAY_START (overlay), Qnil, Qnil);
1814 Fset_marker (OVERLAY_END (overlay), Qnil, Qnil);
1815
0a4469c9 1816 return unbind_to (count, Qnil);
2eec3b4e
RS
1817}
1818\f
8ebafa8d
JB
1819/* Overlay dissection functions. */
1820
1821DEFUN ("overlay-start", Foverlay_start, Soverlay_start, 1, 1, 0,
1822 "Return the position at which OVERLAY starts.")
1823 (overlay)
1824 Lisp_Object overlay;
1825{
1826 CHECK_OVERLAY (overlay, 0);
1827
1828 return (Fmarker_position (OVERLAY_START (overlay)));
1829}
1830
1831DEFUN ("overlay-end", Foverlay_end, Soverlay_end, 1, 1, 0,
1832 "Return the position at which OVERLAY ends.")
1833 (overlay)
1834 Lisp_Object overlay;
1835{
1836 CHECK_OVERLAY (overlay, 0);
1837
1838 return (Fmarker_position (OVERLAY_END (overlay)));
1839}
1840
1841DEFUN ("overlay-buffer", Foverlay_buffer, Soverlay_buffer, 1, 1, 0,
1842 "Return the buffer OVERLAY belongs to.")
1843 (overlay)
1844 Lisp_Object overlay;
1845{
1846 CHECK_OVERLAY (overlay, 0);
1847
1848 return Fmarker_buffer (OVERLAY_START (overlay));
1849}
1850
1851DEFUN ("overlay-properties", Foverlay_properties, Soverlay_properties, 1, 1, 0,
1852 "Return a list of the properties on OVERLAY.\n\
1853This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
1854OVERLAY.")
1855 (overlay)
1856 Lisp_Object overlay;
1857{
1858 CHECK_OVERLAY (overlay, 0);
1859
1860 return Fcopy_sequence (Fcdr_safe (XCONS (overlay)->cdr));
1861}
1862
1863\f
2eec3b4e 1864DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
eb8c3be9 1865 "Return a list of the overlays that contain position POS.")
2eec3b4e
RS
1866 (pos)
1867 Lisp_Object pos;
1868{
1869 int noverlays;
1870 int endpos;
1871 Lisp_Object *overlay_vec;
1872 int len;
1873 Lisp_Object result;
1874
1875 CHECK_NUMBER_COERCE_MARKER (pos, 0);
1876
1877 len = 10;
1878 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
1879
1880 /* Put all the overlays we want in a vector in overlay_vec.
1881 Store the length in len. */
61d54cd5 1882 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, &endpos);
2eec3b4e
RS
1883
1884 /* Make a list of them all. */
1885 result = Flist (noverlays, overlay_vec);
1886
9ac0d9e0 1887 xfree (overlay_vec);
2eec3b4e
RS
1888 return result;
1889}
1890
1891DEFUN ("next-overlay-change", Fnext_overlay_change, Snext_overlay_change,
1892 1, 1, 0,
1893 "Return the next position after POS where an overlay starts or ends.")
1894 (pos)
1895 Lisp_Object pos;
1896{
1897 int noverlays;
1898 int endpos;
1899 Lisp_Object *overlay_vec;
1900 int len;
1901 Lisp_Object result;
1902 int i;
1903
1904 CHECK_NUMBER_COERCE_MARKER (pos, 0);
1905
1906 len = 10;
1907 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
1908
1909 /* Put all the overlays we want in a vector in overlay_vec.
1910 Store the length in len.
1911 endpos gets the position where the next overlay starts. */
61d54cd5 1912 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, &endpos);
2eec3b4e
RS
1913
1914 /* If any of these overlays ends before endpos,
1915 use its ending point instead. */
1916 for (i = 0; i < noverlays; i++)
1917 {
1918 Lisp_Object oend;
1919 int oendpos;
1920
1921 oend = OVERLAY_END (overlay_vec[i]);
1922 oendpos = OVERLAY_POSITION (oend);
1923 if (oendpos < endpos)
1924 endpos = oendpos;
1ab256cb
RM
1925 }
1926
9ac0d9e0 1927 xfree (overlay_vec);
2eec3b4e
RS
1928 return make_number (endpos);
1929}
1930\f
1931/* These functions are for debugging overlays. */
1932
1933DEFUN ("overlay-lists", Foverlay_lists, Soverlay_lists, 0, 0, 0,
1934 "Return a pair of lists giving all the overlays of the current buffer.\n\
1935The car has all the overlays before the overlay center;\n\
1936the cdr has all the overlays before the overlay center.\n\
1937Recentering overlays moves overlays between these lists.\n\
1938The lists you get are copies, so that changing them has no effect.\n\
1939However, the overlays you get are the real objects that the buffer uses.")
1940 ()
1941{
1942 Lisp_Object before, after;
1943 before = current_buffer->overlays_before;
1944 if (CONSP (before))
1945 before = Fcopy_sequence (before);
1946 after = current_buffer->overlays_after;
1947 if (CONSP (after))
1948 after = Fcopy_sequence (after);
1949
1950 return Fcons (before, after);
1951}
1952
1953DEFUN ("overlay-recenter", Foverlay_recenter, Soverlay_recenter, 1, 1, 0,
1954 "Recenter the overlays of the current buffer around position POS.")
1955 (pos)
1956 Lisp_Object pos;
1957{
1958 CHECK_NUMBER_COERCE_MARKER (pos, 0);
1959
5c4f68f1 1960 recenter_overlay_lists (current_buffer, XINT (pos));
2eec3b4e
RS
1961 return Qnil;
1962}
1963\f
1964DEFUN ("overlay-get", Foverlay_get, Soverlay_get, 2, 2, 0,
1965 "Get the property of overlay OVERLAY with property name NAME.")
1966 (overlay, prop)
1967 Lisp_Object overlay, prop;
1968{
1969 Lisp_Object plist;
52f8ec73
JB
1970
1971 CHECK_OVERLAY (overlay, 0);
1972
1973 for (plist = Fcdr_safe (XCONS (overlay)->cdr);
2eec3b4e
RS
1974 CONSP (plist) && CONSP (XCONS (plist)->cdr);
1975 plist = XCONS (XCONS (plist)->cdr)->cdr)
1976 {
1977 if (EQ (XCONS (plist)->car, prop))
1978 return XCONS (XCONS (plist)->cdr)->car;
1979 }
52f8ec73
JB
1980
1981 return Qnil;
2eec3b4e
RS
1982}
1983
1984DEFUN ("overlay-put", Foverlay_put, Soverlay_put, 3, 3, 0,
1985 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
1986 (overlay, prop, value)
1987 Lisp_Object overlay, prop, value;
1988{
1989 Lisp_Object plist, tail;
1990
52f8ec73 1991 CHECK_OVERLAY (overlay, 0);
b61982dd 1992
25d16451
RS
1993 tail = Fmarker_buffer (OVERLAY_START (overlay));
1994 if (! NILP (tail))
1995 redisplay_region (XMARKER (OVERLAY_START (overlay))->buffer,
1996 marker_position (OVERLAY_START (overlay)),
1997 marker_position (OVERLAY_END (overlay)));
b61982dd 1998
52f8ec73 1999 plist = Fcdr_safe (XCONS (overlay)->cdr);
2eec3b4e
RS
2000
2001 for (tail = plist;
2002 CONSP (tail) && CONSP (XCONS (tail)->cdr);
2003 tail = XCONS (XCONS (tail)->cdr)->cdr)
2004 {
2005 if (EQ (XCONS (tail)->car, prop))
2006 return XCONS (XCONS (tail)->cdr)->car = value;
2007 }
2008
2009 if (! CONSP (XCONS (overlay)->cdr))
2010 XCONS (overlay)->cdr = Fcons (Qnil, Qnil);
2011
2012 XCONS (XCONS (overlay)->cdr)->cdr
2013 = Fcons (prop, Fcons (value, plist));
2014
2015 return value;
1ab256cb
RM
2016}
2017\f
173f2a64
RS
2018/* Run the modification-hooks of overlays that include
2019 any part of the text in START to END.
2020 Run the insert-before-hooks of overlay starting at END,
2021 and the insert-after-hooks of overlay ending at START. */
2022
2023void
2024verify_overlay_modification (start, end)
2025 Lisp_Object start, end;
2026{
2027 Lisp_Object prop, overlay, tail;
2028 int insertion = EQ (start, end);
2029
2030 for (tail = current_buffer->overlays_before;
2031 CONSP (tail);
2032 tail = XCONS (tail)->cdr)
2033 {
2034 int startpos, endpos;
be8b1c6b 2035 Lisp_Object ostart, oend;
173f2a64
RS
2036
2037 overlay = XCONS (tail)->car;
2038
2039 ostart = OVERLAY_START (overlay);
2040 oend = OVERLAY_END (overlay);
2041 endpos = OVERLAY_POSITION (oend);
2042 if (XFASTINT (start) > endpos)
2043 break;
2044 startpos = OVERLAY_POSITION (ostart);
2045 if (XFASTINT (end) == startpos && insertion)
2046 {
2047 prop = Foverlay_get (overlay, Qinsert_in_front_hooks);
5fb5aa33
RS
2048 if (!NILP (prop))
2049 {
2050 /* Copy TAIL in case the hook recenters the overlay lists. */
2051 tail = Fcopy_sequence (tail);
2052 call_overlay_mod_hooks (prop, overlay, start, end);
2053 }
173f2a64
RS
2054 }
2055 if (XFASTINT (start) == endpos && insertion)
2056 {
2057 prop = Foverlay_get (overlay, Qinsert_behind_hooks);
5fb5aa33
RS
2058 if (!NILP (prop))
2059 {
2060 tail = Fcopy_sequence (tail);
2061 call_overlay_mod_hooks (prop, overlay, start, end);
2062 }
173f2a64 2063 }
3bd13e92
KH
2064 /* Test for intersecting intervals. This does the right thing
2065 for both insertion and deletion. */
2066 if (XFASTINT (end) > startpos && XFASTINT (start) < endpos)
173f2a64
RS
2067 {
2068 prop = Foverlay_get (overlay, Qmodification_hooks);
5fb5aa33
RS
2069 if (!NILP (prop))
2070 {
2071 tail = Fcopy_sequence (tail);
2072 call_overlay_mod_hooks (prop, overlay, start, end);
2073 }
173f2a64
RS
2074 }
2075 }
2076
2077 for (tail = current_buffer->overlays_after;
2078 CONSP (tail);
2079 tail = XCONS (tail)->cdr)
2080 {
2081 int startpos, endpos;
be8b1c6b 2082 Lisp_Object ostart, oend;
173f2a64
RS
2083
2084 overlay = XCONS (tail)->car;
2085
2086 ostart = OVERLAY_START (overlay);
2087 oend = OVERLAY_END (overlay);
2088 startpos = OVERLAY_POSITION (ostart);
cdf0b096 2089 endpos = OVERLAY_POSITION (oend);
173f2a64
RS
2090 if (XFASTINT (end) < startpos)
2091 break;
2092 if (XFASTINT (end) == startpos && insertion)
2093 {
2094 prop = Foverlay_get (overlay, Qinsert_in_front_hooks);
5fb5aa33
RS
2095 if (!NILP (prop))
2096 {
2097 tail = Fcopy_sequence (tail);
2098 call_overlay_mod_hooks (prop, overlay, start, end);
2099 }
173f2a64
RS
2100 }
2101 if (XFASTINT (start) == endpos && insertion)
2102 {
2103 prop = Foverlay_get (overlay, Qinsert_behind_hooks);
5fb5aa33
RS
2104 if (!NILP (prop))
2105 {
2106 tail = Fcopy_sequence (tail);
2107 call_overlay_mod_hooks (prop, overlay, start, end);
2108 }
173f2a64 2109 }
3bd13e92
KH
2110 /* Test for intersecting intervals. This does the right thing
2111 for both insertion and deletion. */
2112 if (XFASTINT (end) > startpos && XFASTINT (start) < endpos)
173f2a64
RS
2113 {
2114 prop = Foverlay_get (overlay, Qmodification_hooks);
5fb5aa33
RS
2115 if (!NILP (prop))
2116 {
2117 tail = Fcopy_sequence (tail);
2118 call_overlay_mod_hooks (prop, overlay, start, end);
2119 }
173f2a64
RS
2120 }
2121 }
2122}
2123
2124static void
2125call_overlay_mod_hooks (list, overlay, start, end)
2126 Lisp_Object list, overlay, start, end;
2127{
2128 struct gcpro gcpro1;
2129 GCPRO1 (list);
2130 while (!NILP (list))
2131 {
2132 call3 (Fcar (list), overlay, start, end);
2133 list = Fcdr (list);
2134 }
2135 UNGCPRO;
2136}
2137\f
0fa3ba92
JB
2138/* Somebody has tried to store NEWVAL into the buffer-local slot with
2139 offset XUINT (valcontents), and NEWVAL has an unacceptable type. */
2140void
2141buffer_slot_type_mismatch (valcontents, newval)
2142 Lisp_Object valcontents, newval;
2143{
2144 unsigned int offset = XUINT (valcontents);
5fcd022d 2145 unsigned char *symbol_name =
0fa3ba92
JB
2146 (XSYMBOL (*(Lisp_Object *)(offset + (char *)&buffer_local_symbols))
2147 ->name->data);
2148 char *type_name;
2149
2150 switch (XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_types)))
2151 {
2152 case Lisp_Int: type_name = "integers"; break;
2153 case Lisp_String: type_name = "strings"; break;
2154 case Lisp_Marker: type_name = "markers"; break;
2155 case Lisp_Symbol: type_name = "symbols"; break;
2156 case Lisp_Cons: type_name = "lists"; break;
5fcd022d 2157 case Lisp_Vector: type_name = "vectors"; break;
0fa3ba92
JB
2158 default:
2159 abort ();
2160 }
2161
2162 error ("only %s should be stored in the buffer-local variable %s",
2163 type_name, symbol_name);
2164}
2165\f
1ab256cb
RM
2166init_buffer_once ()
2167{
2168 register Lisp_Object tem;
2169
2170 /* Make sure all markable slots in buffer_defaults
2171 are initialized reasonably, so mark_buffer won't choke. */
2172 reset_buffer (&buffer_defaults);
2173 reset_buffer (&buffer_local_symbols);
2174 XSET (Vbuffer_defaults, Lisp_Buffer, &buffer_defaults);
2175 XSET (Vbuffer_local_symbols, Lisp_Buffer, &buffer_local_symbols);
2176
2177 /* Set up the default values of various buffer slots. */
2178 /* Must do these before making the first buffer! */
2179
2180 /* real setup is done in loaddefs.el */
2181 buffer_defaults.mode_line_format = build_string ("%-");
2182 buffer_defaults.abbrev_mode = Qnil;
2183 buffer_defaults.overwrite_mode = Qnil;
2184 buffer_defaults.case_fold_search = Qt;
2185 buffer_defaults.auto_fill_function = Qnil;
2186 buffer_defaults.selective_display = Qnil;
2187#ifndef old
2188 buffer_defaults.selective_display_ellipses = Qt;
2189#endif
2190 buffer_defaults.abbrev_table = Qnil;
2191 buffer_defaults.display_table = Qnil;
1ab256cb 2192 buffer_defaults.undo_list = Qnil;
c48f61ef 2193 buffer_defaults.mark_active = Qnil;
2eec3b4e
RS
2194 buffer_defaults.overlays_before = Qnil;
2195 buffer_defaults.overlays_after = Qnil;
2196 XFASTINT (buffer_defaults.overlay_center) = 1;
1ab256cb
RM
2197
2198 XFASTINT (buffer_defaults.tab_width) = 8;
2199 buffer_defaults.truncate_lines = Qnil;
2200 buffer_defaults.ctl_arrow = Qt;
2201
54ad07d3 2202#ifdef MSDOS
0776cb1b 2203 buffer_defaults.buffer_file_type = Qnil; /* TEXT */
54ad07d3 2204#endif
1ab256cb
RM
2205 XFASTINT (buffer_defaults.fill_column) = 70;
2206 XFASTINT (buffer_defaults.left_margin) = 0;
2207
2208 /* Assign the local-flags to the slots that have default values.
2209 The local flag is a bit that is used in the buffer
2210 to say that it has its own local value for the slot.
2211 The local flag bits are in the local_var_flags slot of the buffer. */
2212
2213 /* Nothing can work if this isn't true */
2214 if (sizeof (int) != sizeof (Lisp_Object)) abort ();
2215
2216 /* 0 means not a lisp var, -1 means always local, else mask */
2217 bzero (&buffer_local_flags, sizeof buffer_local_flags);
2218 XFASTINT (buffer_local_flags.filename) = -1;
2219 XFASTINT (buffer_local_flags.directory) = -1;
2220 XFASTINT (buffer_local_flags.backed_up) = -1;
2221 XFASTINT (buffer_local_flags.save_length) = -1;
2222 XFASTINT (buffer_local_flags.auto_save_file_name) = -1;
2223 XFASTINT (buffer_local_flags.read_only) = -1;
2224 XFASTINT (buffer_local_flags.major_mode) = -1;
2225 XFASTINT (buffer_local_flags.mode_name) = -1;
2226 XFASTINT (buffer_local_flags.undo_list) = -1;
c48f61ef 2227 XFASTINT (buffer_local_flags.mark_active) = -1;
1ab256cb
RM
2228
2229 XFASTINT (buffer_local_flags.mode_line_format) = 1;
2230 XFASTINT (buffer_local_flags.abbrev_mode) = 2;
2231 XFASTINT (buffer_local_flags.overwrite_mode) = 4;
2232 XFASTINT (buffer_local_flags.case_fold_search) = 8;
2233 XFASTINT (buffer_local_flags.auto_fill_function) = 0x10;
2234 XFASTINT (buffer_local_flags.selective_display) = 0x20;
2235#ifndef old
2236 XFASTINT (buffer_local_flags.selective_display_ellipses) = 0x40;
2237#endif
2238 XFASTINT (buffer_local_flags.tab_width) = 0x80;
2239 XFASTINT (buffer_local_flags.truncate_lines) = 0x100;
2240 XFASTINT (buffer_local_flags.ctl_arrow) = 0x200;
2241 XFASTINT (buffer_local_flags.fill_column) = 0x400;
2242 XFASTINT (buffer_local_flags.left_margin) = 0x800;
2243 XFASTINT (buffer_local_flags.abbrev_table) = 0x1000;
2244 XFASTINT (buffer_local_flags.display_table) = 0x2000;
1ab256cb 2245 XFASTINT (buffer_local_flags.syntax_table) = 0x8000;
54ad07d3
RS
2246#ifdef MSDOS
2247 XFASTINT (buffer_local_flags.buffer_file_type) = 0x4000;
2248#endif
1ab256cb
RM
2249
2250 Vbuffer_alist = Qnil;
2251 current_buffer = 0;
2252 all_buffers = 0;
2253
2254 QSFundamental = build_string ("Fundamental");
2255
2256 Qfundamental_mode = intern ("fundamental-mode");
2257 buffer_defaults.major_mode = Qfundamental_mode;
2258
2259 Qmode_class = intern ("mode-class");
2260
2261 Qprotected_field = intern ("protected-field");
2262
2263 Qpermanent_local = intern ("permanent-local");
2264
2265 Qkill_buffer_hook = intern ("kill-buffer-hook");
2266
2267 Vprin1_to_string_buffer = Fget_buffer_create (build_string (" prin1"));
2268 /* super-magic invisible buffer */
2269 Vbuffer_alist = Qnil;
2270
ffd56f97 2271 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
1ab256cb
RM
2272}
2273
2274init_buffer ()
2275{
2276 char buf[MAXPATHLEN+1];
2381d133
JB
2277 char *pwd;
2278 struct stat dotstat, pwdstat;
136351b7 2279 Lisp_Object temp;
1ab256cb
RM
2280
2281 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
2381d133
JB
2282
2283 /* If PWD is accurate, use it instead of calling getwd. This is faster
2284 when PWD is right, and may avoid a fatal error. */
2285 if ((pwd = getenv ("PWD")) != 0 && *pwd == '/'
2286 && stat (pwd, &pwdstat) == 0
2287 && stat (".", &dotstat) == 0
2288 && dotstat.st_ino == pwdstat.st_ino
2289 && dotstat.st_dev == pwdstat.st_dev
2290 && strlen (pwd) < MAXPATHLEN)
2291 strcpy (buf, pwd);
2292 else if (getwd (buf) == 0)
1ab256cb
RM
2293 fatal ("`getwd' failed: %s.\n", buf);
2294
2295#ifndef VMS
2296 /* Maybe this should really use some standard subroutine
2297 whose definition is filename syntax dependent. */
2298 if (buf[strlen (buf) - 1] != '/')
2299 strcat (buf, "/");
2300#endif /* not VMS */
2301 current_buffer->directory = build_string (buf);
136351b7
RS
2302
2303 temp = get_minibuffer (0);
2304 XBUFFER (temp)->directory = current_buffer->directory;
1ab256cb
RM
2305}
2306
2307/* initialize the buffer routines */
2308syms_of_buffer ()
2309{
188d4d11
RM
2310 extern Lisp_Object Qdisabled;
2311
1ab256cb
RM
2312 staticpro (&Vbuffer_defaults);
2313 staticpro (&Vbuffer_local_symbols);
2314 staticpro (&Qfundamental_mode);
2315 staticpro (&Qmode_class);
2316 staticpro (&QSFundamental);
2317 staticpro (&Vbuffer_alist);
2318 staticpro (&Qprotected_field);
2319 staticpro (&Qpermanent_local);
2320 staticpro (&Qkill_buffer_hook);
52f8ec73 2321 staticpro (&Qoverlayp);
294d215f
RS
2322 staticpro (&Qmodification_hooks);
2323 Qmodification_hooks = intern ("modification-hooks");
2324 staticpro (&Qinsert_in_front_hooks);
2325 Qinsert_in_front_hooks = intern ("insert-in-front-hooks");
2326 staticpro (&Qinsert_behind_hooks);
2327 Qinsert_behind_hooks = intern ("insert-behind-hooks");
5fe0b67e
RS
2328 staticpro (&Qget_file_buffer);
2329 Qget_file_buffer = intern ("get-file-buffer");
5985d248
KH
2330 Qpriority = intern ("priority");
2331 staticpro (&Qpriority);
2332 Qwindow = intern ("window");
2333 staticpro (&Qwindow);
52f8ec73
JB
2334
2335 Qoverlayp = intern ("overlayp");
1ab256cb
RM
2336
2337 Fput (Qprotected_field, Qerror_conditions,
2338 Fcons (Qprotected_field, Fcons (Qerror, Qnil)));
2339 Fput (Qprotected_field, Qerror_message,
2340 build_string ("Attempt to modify a protected field"));
2341
2342 /* All these use DEFVAR_LISP_NOPRO because the slots in
2343 buffer_defaults will all be marked via Vbuffer_defaults. */
2344
2345 DEFVAR_LISP_NOPRO ("default-mode-line-format",
2346 &buffer_defaults.mode_line_format,
2347 "Default value of `mode-line-format' for buffers that don't override it.\n\
2348This is the same as (default-value 'mode-line-format).");
2349
2350 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
2351 &buffer_defaults.abbrev_mode,
2352 "Default value of `abbrev-mode' for buffers that do not override it.\n\
2353This is the same as (default-value 'abbrev-mode).");
2354
2355 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
2356 &buffer_defaults.ctl_arrow,
2357 "Default value of `ctl-arrow' for buffers that do not override it.\n\
2358This is the same as (default-value 'ctl-arrow).");
2359
2360 DEFVAR_LISP_NOPRO ("default-truncate-lines",
2361 &buffer_defaults.truncate_lines,
2362 "Default value of `truncate-lines' for buffers that do not override it.\n\
2363This is the same as (default-value 'truncate-lines).");
2364
2365 DEFVAR_LISP_NOPRO ("default-fill-column",
2366 &buffer_defaults.fill_column,
2367 "Default value of `fill-column' for buffers that do not override it.\n\
2368This is the same as (default-value 'fill-column).");
2369
2370 DEFVAR_LISP_NOPRO ("default-left-margin",
2371 &buffer_defaults.left_margin,
2372 "Default value of `left-margin' for buffers that do not override it.\n\
2373This is the same as (default-value 'left-margin).");
2374
2375 DEFVAR_LISP_NOPRO ("default-tab-width",
2376 &buffer_defaults.tab_width,
2377 "Default value of `tab-width' for buffers that do not override it.\n\
2378This is the same as (default-value 'tab-width).");
2379
2380 DEFVAR_LISP_NOPRO ("default-case-fold-search",
2381 &buffer_defaults.case_fold_search,
2382 "Default value of `case-fold-search' for buffers that don't override it.\n\
2383This is the same as (default-value 'case-fold-search).");
2384
54ad07d3
RS
2385#ifdef MSDOS
2386 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
2387 &buffer_defaults.buffer_file_type,
2388 "Default file type for buffers that do not override it.\n\
2389This is the same as (default-value 'buffer-file-type).\n\
2390The file type is nil for text, t for binary.");
2391#endif
2392
0fa3ba92
JB
2393 DEFVAR_PER_BUFFER ("mode-line-format", &current_buffer->mode_line_format,
2394 Qnil, 0);
1ab256cb
RM
2395
2396/* This doc string is too long for cpp; cpp dies if it isn't in a comment.
2397 But make-docfile finds it!
2398 DEFVAR_PER_BUFFER ("mode-line-format", &current_buffer->mode_line_format,
bec44fd6 2399 Qnil,
1ab256cb
RM
2400 "Template for displaying mode line for current buffer.\n\
2401Each buffer has its own value of this variable.\n\
2402Value may be a string, a symbol or a list or cons cell.\n\
2403For a symbol, its value is used (but it is ignored if t or nil).\n\
2404 A string appearing directly as the value of a symbol is processed verbatim\n\
2405 in that the %-constructs below are not recognized.\n\
2406For a list whose car is a symbol, the symbol's value is taken,\n\
2407 and if that is non-nil, the cadr of the list is processed recursively.\n\
2408 Otherwise, the caddr of the list (if there is one) is processed.\n\
2409For a list whose car is a string or list, each element is processed\n\
2410 recursively and the results are effectively concatenated.\n\
2411For a list whose car is an integer, the cdr of the list is processed\n\
2412 and padded (if the number is positive) or truncated (if negative)\n\
2413 to the width specified by that number.\n\
2414A string is printed verbatim in the mode line except for %-constructs:\n\
2415 (%-constructs are allowed when the string is the entire mode-line-format\n\
2416 or when it is found in a cons-cell or a list)\n\
2417 %b -- print buffer name. %f -- print visited file name.\n\
2418 %* -- print *, % or hyphen. %m -- print value of mode-name (obsolete).\n\
a97c374a 2419 %s -- print process status. %l -- print the current line number.\n\
dd24e6a6 2420 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
9d130ffc 2421 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
dd24e6a6 2422 or print Bottom or All.\n\
1ab256cb 2423 %n -- print Narrow if appropriate.\n\
54ad07d3 2424 %t -- print T if files is text, B if binary.\n\
1ab256cb
RM
2425 %[ -- print one [ for each recursive editing level. %] similar.\n\
2426 %% -- print %. %- -- print infinitely many dashes.\n\
2427Decimal digits after the % specify field width to which to pad.");
2428*/
2429
2430 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults.major_mode,
2431 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
2432nil here means use current buffer's major mode.");
2433
2434 DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode,
0fa3ba92 2435 make_number (Lisp_Symbol),
1ab256cb
RM
2436 "Symbol for current buffer's major mode.");
2437
2438 DEFVAR_PER_BUFFER ("mode-name", &current_buffer->mode_name,
0fa3ba92 2439 make_number (Lisp_String),
1ab256cb
RM
2440 "Pretty name of current buffer's major mode (a string).");
2441
0fa3ba92 2442 DEFVAR_PER_BUFFER ("abbrev-mode", &current_buffer->abbrev_mode, Qnil,
1ab256cb
RM
2443 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
2444Automatically becomes buffer-local when set in any fashion.");
2445
2446 DEFVAR_PER_BUFFER ("case-fold-search", &current_buffer->case_fold_search,
0fa3ba92 2447 Qnil,
1ab256cb
RM
2448 "*Non-nil if searches should ignore case.\n\
2449Automatically becomes buffer-local when set in any fashion.");
2450
2451 DEFVAR_PER_BUFFER ("fill-column", &current_buffer->fill_column,
0fa3ba92 2452 make_number (Lisp_Int),
1ab256cb
RM
2453 "*Column beyond which automatic line-wrapping should happen.\n\
2454Automatically becomes buffer-local when set in any fashion.");
2455
2456 DEFVAR_PER_BUFFER ("left-margin", &current_buffer->left_margin,
0fa3ba92 2457 make_number (Lisp_Int),
1ab256cb
RM
2458 "*Column for the default indent-line-function to indent to.\n\
2459Linefeed indents to this column in Fundamental mode.\n\
2460Automatically becomes buffer-local when set in any fashion.");
2461
2462 DEFVAR_PER_BUFFER ("tab-width", &current_buffer->tab_width,
0fa3ba92 2463 make_number (Lisp_Int),
1ab256cb
RM
2464 "*Distance between tab stops (for display of tab characters), in columns.\n\
2465Automatically becomes buffer-local when set in any fashion.");
2466
0fa3ba92 2467 DEFVAR_PER_BUFFER ("ctl-arrow", &current_buffer->ctl_arrow, Qnil,
1ab256cb
RM
2468 "*Non-nil means display control chars with uparrow.\n\
2469Nil means use backslash and octal digits.\n\
2470Automatically becomes buffer-local when set in any fashion.\n\
2471This variable does not apply to characters whose display is specified\n\
2472in the current display table (if there is one).");
2473
0fa3ba92 2474 DEFVAR_PER_BUFFER ("truncate-lines", &current_buffer->truncate_lines, Qnil,
1ab256cb
RM
2475 "*Non-nil means do not display continuation lines;\n\
2476give each line of text one screen line.\n\
2477Automatically becomes buffer-local when set in any fashion.\n\
2478\n\
2479Note that this is overridden by the variable\n\
2480`truncate-partial-width-windows' if that variable is non-nil\n\
502b9b64 2481and this buffer is not full-frame width.");
1ab256cb 2482
54ad07d3
RS
2483#ifdef MSDOS
2484 DEFVAR_PER_BUFFER ("buffer-file-type", &current_buffer->buffer_file_type,
2485 Qnil,
2486 "*If visited file is text, nil; otherwise, t.");
2487#endif
2488
1ab256cb 2489 DEFVAR_PER_BUFFER ("default-directory", &current_buffer->directory,
0fa3ba92 2490 make_number (Lisp_String),
1ab256cb
RM
2491 "Name of default directory of current buffer. Should end with slash.\n\
2492Each buffer has its own value of this variable.");
2493
2494 DEFVAR_PER_BUFFER ("auto-fill-function", &current_buffer->auto_fill_function,
0fa3ba92 2495 Qnil,
1ab256cb
RM
2496 "Function called (if non-nil) to perform auto-fill.\n\
2497It is called after self-inserting a space at a column beyond `fill-column'.\n\
2498Each buffer has its own value of this variable.\n\
2499NOTE: This variable is not an ordinary hook;\n\
2500It may not be a list of functions.");
2501
2502 DEFVAR_PER_BUFFER ("buffer-file-name", &current_buffer->filename,
0fa3ba92 2503 make_number (Lisp_String),
1ab256cb
RM
2504 "Name of file visited in current buffer, or nil if not visiting a file.\n\
2505Each buffer has its own value of this variable.");
2506
2507 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
3f5fcd47 2508 &current_buffer->auto_save_file_name,
0fa3ba92 2509 make_number (Lisp_String),
1ab256cb
RM
2510 "Name of file for auto-saving current buffer,\n\
2511or nil if buffer should not be auto-saved.\n\
2512Each buffer has its own value of this variable.");
2513
0fa3ba92 2514 DEFVAR_PER_BUFFER ("buffer-read-only", &current_buffer->read_only, Qnil,
1ab256cb
RM
2515 "Non-nil if this buffer is read-only.\n\
2516Each buffer has its own value of this variable.");
2517
0fa3ba92 2518 DEFVAR_PER_BUFFER ("buffer-backed-up", &current_buffer->backed_up, Qnil,
1ab256cb
RM
2519 "Non-nil if this buffer's file has been backed up.\n\
2520Backing up is done before the first time the file is saved.\n\
2521Each buffer has its own value of this variable.");
2522
2523 DEFVAR_PER_BUFFER ("buffer-saved-size", &current_buffer->save_length,
0fa3ba92 2524 make_number (Lisp_Int),
1ab256cb
RM
2525 "Length of current buffer when last read in, saved or auto-saved.\n\
25260 initially.\n\
2527Each buffer has its own value of this variable.");
2528
2529 DEFVAR_PER_BUFFER ("selective-display", &current_buffer->selective_display,
0fa3ba92 2530 Qnil,
1ab256cb
RM
2531 "Non-nil enables selective display:\n\
2532Integer N as value means display only lines\n\
2533 that start with less than n columns of space.\n\
2534A value of t means, after a ^M, all the rest of the line is invisible.\n\
2535 Then ^M's in the file are written into files as newlines.\n\n\
2536Automatically becomes buffer-local when set in any fashion.");
2537
2538#ifndef old
2539 DEFVAR_PER_BUFFER ("selective-display-ellipses",
2540 &current_buffer->selective_display_ellipses,
0fa3ba92 2541 Qnil,
1ab256cb
RM
2542 "t means display ... on previous line when a line is invisible.\n\
2543Automatically becomes buffer-local when set in any fashion.");
2544#endif
2545
0fa3ba92 2546 DEFVAR_PER_BUFFER ("overwrite-mode", &current_buffer->overwrite_mode, Qnil,
1ab256cb 2547 "Non-nil if self-insertion should replace existing text.\n\
6bbb0d4a
JB
2548If non-nil and not `overwrite-mode-binary', self-insertion still\n\
2549inserts at the end of a line, and inserts when point is before a tab,\n\
2e94b813 2550until the tab is filled in.\n\
6bbb0d4a 2551If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
1ab256cb
RM
2552Automatically becomes buffer-local when set in any fashion.");
2553
54939090
RS
2554#if 0 /* The doc string is too long for some compilers,
2555 but make-docfile can find it in this comment. */
1ab256cb 2556 DEFVAR_PER_BUFFER ("buffer-display-table", &current_buffer->display_table,
5d305367 2557 Qnil,
1ab256cb
RM
2558 "Display table that controls display of the contents of current buffer.\n\
2559Automatically becomes buffer-local when set in any fashion.\n\
2560The display table is a vector created with `make-display-table'.\n\
2561The first 256 elements control how to display each possible text character.\n\
6158b3b0 2562Each value should be a vector of characters or nil;\n\
1ab256cb 2563nil means display the character in the default fashion.\n\
6158b3b0
JB
2564The remaining five elements control the display of\n\
2565 the end of a truncated screen line (element 256, a single character);\n\
2566 the end of a continued line (element 257, a single character);\n\
2567 the escape character used to display character codes in octal\n\
2568 (element 258, a single character);\n\
2569 the character used as an arrow for control characters (element 259,\n\
2570 a single character);\n\
2571 the decoration indicating the presence of invisible lines (element 260,\n\
2572 a vector of characters).\n\
1ab256cb
RM
2573If this variable is nil, the value of `standard-display-table' is used.\n\
2574Each window can have its own, overriding display table.");
54939090
RS
2575#endif
2576 DEFVAR_PER_BUFFER ("buffer-display-table", &current_buffer->display_table,
de15914a 2577 Qnil, 0);
1ab256cb 2578
1ab256cb
RM
2579/*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
2580 "Don't ask.");
2581*/
01050cb5 2582 DEFVAR_LISP ("before-change-function", &Vbefore_change_function,
1ab256cb
RM
2583 "Function to call before each text change.\n\
2584Two arguments are passed to the function: the positions of\n\
2585the beginning and end of the range of old text to be changed.\n\
2586\(For an insertion, the beginning and end are at the same place.)\n\
2587No information is given about the length of the text after the change.\n\
1ab256cb 2588\n\
5f079267 2589Buffer changes made while executing the `before-change-function'\n\
b86344d0
RS
2590don't call any before-change or after-change functions.\n\
2591That's because these variables are temporarily set to nil.\n\
2592As a result, a hook function cannot straightforwardly alter the value of\n\
2593these variables. See the Emacs Lisp manual for a way of\n\
2594accomplishing an equivalent result by using other variables.")
1ab256cb
RM
2595 Vbefore_change_function = Qnil;
2596
2597 DEFVAR_LISP ("after-change-function", &Vafter_change_function,
2598 "Function to call after each text change.\n\
2599Three arguments are passed to the function: the positions of\n\
2600the beginning and end of the range of changed text,\n\
2601and the length of the pre-change text replaced by that range.\n\
2602\(For an insertion, the pre-change length is zero;\n\
2603for a deletion, that length is the number of characters deleted,\n\
2604and the post-change beginning and end are at the same place.)\n\
2605\n\
5f079267 2606Buffer changes made while executing the `after-change-function'\n\
b86344d0
RS
2607don't call any before-change or after-change functions.\n\
2608That's because these variables are temporarily set to nil.\n\
2609As a result, a hook function cannot straightforwardly alter the value of\n\
2610these variables. See the Emacs Lisp manual for a way of\n\
2611accomplishing an equivalent result by using other variables.")
1ab256cb
RM
2612 Vafter_change_function = Qnil;
2613
5f079267
RS
2614 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions,
2615 "List of functions to call before each text change.\n\
2616Two arguments are passed to each function: the positions of\n\
2617the beginning and end of the range of old text to be changed.\n\
2618\(For an insertion, the beginning and end are at the same place.)\n\
2619No information is given about the length of the text after the change.\n\
5f079267
RS
2620\n\
2621Buffer changes made while executing the `before-change-functions'\n\
b86344d0
RS
2622don't call any before-change or after-change functions.\n\
2623That's because these variables are temporarily set to nil.\n\
2624As a result, a hook function cannot straightforwardly alter the value of\n\
2625these variables. See the Emacs Lisp manual for a way of\n\
2626accomplishing an equivalent result by using other variables.")
5f079267
RS
2627 Vbefore_change_functions = Qnil;
2628
2629 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions,
2630 "List of function to call after each text change.\n\
2631Three arguments are passed to each function: the positions of\n\
2632the beginning and end of the range of changed text,\n\
2633and the length of the pre-change text replaced by that range.\n\
2634\(For an insertion, the pre-change length is zero;\n\
2635for a deletion, that length is the number of characters deleted,\n\
2636and the post-change beginning and end are at the same place.)\n\
2637\n\
2638Buffer changes made while executing the `after-change-functions'\n\
b86344d0
RS
2639don't call any before-change or after-change functions.\n\
2640That's because these variables are temporarily set to nil.\n\
2641As a result, a hook function cannot straightforwardly alter the value of\n\
2642these variables. See the Emacs Lisp manual for a way of\n\
2643accomplishing an equivalent result by using other variables.")
2644
5f079267
RS
2645 Vafter_change_functions = Qnil;
2646
dbc4e1c1
JB
2647 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook,
2648 "A list of functions to call before changing a buffer which is unmodified.\n\
2649The functions are run using the `run-hooks' function.");
2650 Vfirst_change_hook = Qnil;
2651 Qfirst_change_hook = intern ("first-change-hook");
2652 staticpro (&Qfirst_change_hook);
1ab256cb 2653
54939090
RS
2654#if 0 /* The doc string is too long for some compilers,
2655 but make-docfile can find it in this comment. */
3f5fcd47 2656 DEFVAR_PER_BUFFER ("buffer-undo-list", &current_buffer->undo_list, Qnil,
1ab256cb
RM
2657 "List of undo entries in current buffer.\n\
2658Recent changes come first; older changes follow newer.\n\
2659\n\
2660An entry (START . END) represents an insertion which begins at\n\
2661position START and ends at position END.\n\
2662\n\
2663An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
2664from (abs POSITION). If POSITION is positive, point was at the front\n\
2665of the text being deleted; if negative, point was at the end.\n\
2666\n\
2667An entry (t HIGHWORD LOWWORD) indicates that the buffer had been\n\
2668previously unmodified. HIGHWORD and LOWWORD are the high and low\n\
266916-bit words of the buffer's modification count at the time. If the\n\
2670modification count of the most recent save is different, this entry is\n\
2671obsolete.\n\
2672\n\
483c1fd3
RS
2673An entry (nil PROP VAL BEG . END) indicates that a text property\n\
2674was modified between BEG and END. PROP is the property name,\n\
2675and VAL is the old value.\n\
2676\n\
bec44fd6
JB
2677An entry of the form POSITION indicates that point was at the buffer\n\
2678location given by the integer. Undoing an entry of this form places\n\
2679point at POSITION.\n\
2680\n\
1ab256cb
RM
2681nil marks undo boundaries. The undo command treats the changes\n\
2682between two undo boundaries as a single step to be undone.\n\
2683\n\
bec44fd6 2684If the value of the variable is t, undo information is not recorded.");
54939090
RS
2685#endif
2686 DEFVAR_PER_BUFFER ("buffer-undo-list", &current_buffer->undo_list, Qnil,
de15914a 2687 0);
1ab256cb 2688
c48f61ef
RS
2689 DEFVAR_PER_BUFFER ("mark-active", &current_buffer->mark_active, Qnil,
2690 "Non-nil means the mark and region are currently active in this buffer.\n\
2691Automatically local in all buffers.");
2692
2693 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode,
2694 "*Non-nil means deactivate the mark when the buffer contents change.");
2695 Vtransient_mark_mode = Qnil;
2696
0a4469c9 2697 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only,
a96b68f1
RS
2698 "*Non-nil means disregard read-only status of buffers or characters.\n\
2699If the value is t, disregard `buffer-read-only' and all `read-only'\n\
2700text properties. If the value is a list, disregard `buffer-read-only'\n\
2701and disregard a `read-only' text property if the property value\n\
2702is a member of the list.");
2703 Vinhibit_read_only = Qnil;
2704
dcdffbf6
RS
2705 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions,
2706 "List of functions called with no args to query before killing a buffer.");
2707 Vkill_buffer_query_functions = Qnil;
2708
1ab256cb
RM
2709 defsubr (&Sbuffer_list);
2710 defsubr (&Sget_buffer);
2711 defsubr (&Sget_file_buffer);
2712 defsubr (&Sget_buffer_create);
01050cb5 2713 defsubr (&Sgenerate_new_buffer_name);
1ab256cb
RM
2714 defsubr (&Sbuffer_name);
2715/*defsubr (&Sbuffer_number);*/
2716 defsubr (&Sbuffer_file_name);
2717 defsubr (&Sbuffer_local_variables);
2718 defsubr (&Sbuffer_modified_p);
2719 defsubr (&Sset_buffer_modified_p);
2720 defsubr (&Sbuffer_modified_tick);
2721 defsubr (&Srename_buffer);
2722 defsubr (&Sother_buffer);
2723 defsubr (&Sbuffer_disable_undo);
2724 defsubr (&Sbuffer_enable_undo);
2725 defsubr (&Skill_buffer);
2726 defsubr (&Serase_buffer);
2727 defsubr (&Sswitch_to_buffer);
2728 defsubr (&Spop_to_buffer);
2729 defsubr (&Scurrent_buffer);
2730 defsubr (&Sset_buffer);
2731 defsubr (&Sbarf_if_buffer_read_only);
2732 defsubr (&Sbury_buffer);
2733 defsubr (&Slist_buffers);
2734 defsubr (&Skill_all_local_variables);
2eec3b4e 2735
52f8ec73 2736 defsubr (&Soverlayp);
2eec3b4e
RS
2737 defsubr (&Smake_overlay);
2738 defsubr (&Sdelete_overlay);
2739 defsubr (&Smove_overlay);
8ebafa8d
JB
2740 defsubr (&Soverlay_start);
2741 defsubr (&Soverlay_end);
2742 defsubr (&Soverlay_buffer);
2743 defsubr (&Soverlay_properties);
2eec3b4e
RS
2744 defsubr (&Soverlays_at);
2745 defsubr (&Snext_overlay_change);
2746 defsubr (&Soverlay_recenter);
2747 defsubr (&Soverlay_lists);
2748 defsubr (&Soverlay_get);
2749 defsubr (&Soverlay_put);
1ab256cb
RM
2750}
2751
2752keys_of_buffer ()
2753{
2754 initial_define_key (control_x_map, 'b', "switch-to-buffer");
2755 initial_define_key (control_x_map, 'k', "kill-buffer");
2756 initial_define_key (control_x_map, Ctl ('B'), "list-buffers");
4158c17d
RM
2757
2758 /* This must not be in syms_of_buffer, because Qdisabled is not
2759 initialized when that function gets called. */
2760 Fput (intern ("erase-buffer"), Qdisabled, Qt);
1ab256cb 2761}