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