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