(nsberror, record_buffer, validate_region,
[bpt/emacs.git] / src / buffer.c
1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995, 1997
3 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <sys/param.h>
26 #include <errno.h>
27
28 extern int errno;
29
30 #ifndef MAXPATHLEN
31 /* in 4.1, param.h fails to define this. */
32 #define MAXPATHLEN 1024
33 #endif /* not MAXPATHLEN */
34
35 #include <config.h>
36 #include "lisp.h"
37 #include "intervals.h"
38 #include "window.h"
39 #include "commands.h"
40 #include "buffer.h"
41 #include "charset.h"
42 #include "region-cache.h"
43 #include "indent.h"
44 #include "blockinput.h"
45 #include "frame.h"
46
47 struct buffer *current_buffer; /* the current buffer */
48
49 /* First buffer in chain of all buffers (in reverse order of creation).
50 Threaded through ->next. */
51
52 struct buffer *all_buffers;
53
54 /* This structure holds the default values of the buffer-local variables
55 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
56 The default value occupies the same slot in this structure
57 as an individual buffer's value occupies in that buffer.
58 Setting the default value also goes through the alist of buffers
59 and stores into each buffer that does not say it has a local value. */
60
61 struct buffer buffer_defaults;
62
63 /* A Lisp_Object pointer to the above, used for staticpro */
64
65 static Lisp_Object Vbuffer_defaults;
66
67 /* This structure marks which slots in a buffer have corresponding
68 default values in buffer_defaults.
69 Each such slot has a nonzero value in this structure.
70 The value has only one nonzero bit.
71
72 When a buffer has its own local value for a slot,
73 the bit for that slot (found in the same slot in this structure)
74 is turned on in the buffer's local_var_flags slot.
75
76 If a slot in this structure is -1, then even though there may
77 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
78 and the corresponding slot in buffer_defaults is not used.
79
80 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
81 but there is a default value which is copied into each buffer.
82
83 If a slot in this structure is negative, then even though there may
84 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
85 and the corresponding slot in buffer_defaults is not used.
86
87 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
88 zero, that is a bug */
89
90 struct buffer buffer_local_flags;
91
92 /* This structure holds the names of symbols whose values may be
93 buffer-local. It is indexed and accessed in the same way as the above. */
94
95 struct buffer buffer_local_symbols;
96 /* A Lisp_Object pointer to the above, used for staticpro */
97 static Lisp_Object Vbuffer_local_symbols;
98
99 /* This structure holds the required types for the values in the
100 buffer-local slots. If a slot contains Qnil, then the
101 corresponding buffer slot may contain a value of any type. If a
102 slot contains an integer, then prospective values' tags must be
103 equal to that integer. When a tag does not match, the function
104 buffer_slot_type_mismatch will signal an error. */
105 struct buffer buffer_local_types;
106
107 /* Flags indicating which built-in buffer-local variables
108 are permanent locals. */
109 static int buffer_permanent_local_flags;
110
111 Lisp_Object Fset_buffer ();
112 void set_buffer_internal ();
113 void set_buffer_internal_1 ();
114 static void call_overlay_mod_hooks ();
115 static void swap_out_buffer_local_variables ();
116 static void reset_buffer_local_variables ();
117
118 /* Alist of all buffer names vs the buffers. */
119 /* This used to be a variable, but is no longer,
120 to prevent lossage due to user rplac'ing this alist or its elements. */
121 Lisp_Object Vbuffer_alist;
122
123 /* Functions to call before and after each text change. */
124 Lisp_Object Vbefore_change_function;
125 Lisp_Object Vafter_change_function;
126 Lisp_Object Vbefore_change_functions;
127 Lisp_Object Vafter_change_functions;
128
129 Lisp_Object Vtransient_mark_mode;
130
131 /* t means ignore all read-only text properties.
132 A list means ignore such a property if its value is a member of the list.
133 Any non-nil value means ignore buffer-read-only. */
134 Lisp_Object Vinhibit_read_only;
135
136 /* List of functions to call that can query about killing a buffer.
137 If any of these functions returns nil, we don't kill it. */
138 Lisp_Object Vkill_buffer_query_functions;
139
140 /* List of functions to call before changing an unmodified buffer. */
141 Lisp_Object Vfirst_change_hook;
142
143 Lisp_Object Qfirst_change_hook;
144 Lisp_Object Qbefore_change_functions;
145 Lisp_Object Qafter_change_functions;
146
147 Lisp_Object Qfundamental_mode, Qmode_class, Qpermanent_local;
148
149 Lisp_Object Qprotected_field;
150
151 Lisp_Object QSFundamental; /* A string "Fundamental" */
152
153 Lisp_Object Qkill_buffer_hook;
154
155 Lisp_Object Qget_file_buffer;
156
157 Lisp_Object Qoverlayp;
158
159 Lisp_Object Qpriority, Qwindow, Qevaporate, Qbefore_string, Qafter_string;
160
161 Lisp_Object Qmodification_hooks;
162 Lisp_Object Qinsert_in_front_hooks;
163 Lisp_Object Qinsert_behind_hooks;
164
165 /* For debugging; temporary. See set_buffer_internal. */
166 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
167
168 void
169 nsberror (spec)
170 Lisp_Object spec;
171 {
172 if (STRINGP (spec))
173 error ("No buffer named %s", XSTRING (spec)->data);
174 error ("Invalid buffer argument");
175 }
176 \f
177 DEFUN ("buffer-live-p", Fbuffer_live_p, Sbuffer_live_p, 1, 1, 0,
178 "Return non-nil if OBJECT is a buffer which has not been killed.\n\
179 Value is nil if OBJECT is not a buffer or if it has been killed.")
180 (object)
181 Lisp_Object object;
182 {
183 return ((BUFFERP (object) && ! NILP (XBUFFER (object)->name))
184 ? Qt : Qnil);
185 }
186
187 DEFUN ("buffer-list", Fbuffer_list, Sbuffer_list, 0, 1, 0,
188 "Return a list of all existing live buffers.\n\
189 If the optional arg FRAME is a frame, we return that frame's buffer list.")
190 (frame)
191 Lisp_Object frame;
192 {
193 Lisp_Object framelist, general;
194 general = Fmapcar (Qcdr, Vbuffer_alist);
195
196 if (FRAMEP (frame))
197 {
198 Lisp_Object tail;
199
200 CHECK_FRAME (frame, 1);
201
202 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list);
203
204 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */
205 tail = framelist;
206 while (! NILP (tail))
207 {
208 general = Fdelq (XCONS (tail)->car, general);
209 tail = XCONS (tail)->cdr;
210 }
211 return nconc2 (framelist, general);
212 }
213
214 return general;
215 }
216
217 /* Like Fassoc, but use Fstring_equal to compare
218 (which ignores text properties),
219 and don't ever QUIT. */
220
221 static Lisp_Object
222 assoc_ignore_text_properties (key, list)
223 register Lisp_Object key;
224 Lisp_Object list;
225 {
226 register Lisp_Object tail;
227 for (tail = list; !NILP (tail); tail = Fcdr (tail))
228 {
229 register Lisp_Object elt, tem;
230 elt = Fcar (tail);
231 tem = Fstring_equal (Fcar (elt), key);
232 if (!NILP (tem))
233 return elt;
234 }
235 return Qnil;
236 }
237
238 DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0,
239 "Return the buffer named NAME (a string).\n\
240 If there is no live buffer named NAME, return nil.\n\
241 NAME may also be a buffer; if so, the value is that buffer.")
242 (name)
243 register Lisp_Object name;
244 {
245 if (BUFFERP (name))
246 return name;
247 CHECK_STRING (name, 0);
248
249 return Fcdr (assoc_ignore_text_properties (name, Vbuffer_alist));
250 }
251
252 DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0,
253 "Return the buffer visiting file FILENAME (a string).\n\
254 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
255 If there is no such live buffer, return nil.\n\
256 See also `find-buffer-visiting'.")
257 (filename)
258 register Lisp_Object filename;
259 {
260 register Lisp_Object tail, buf, tem;
261 Lisp_Object handler;
262
263 CHECK_STRING (filename, 0);
264 filename = Fexpand_file_name (filename, Qnil);
265
266 /* If the file name has special constructs in it,
267 call the corresponding file handler. */
268 handler = Ffind_file_name_handler (filename, Qget_file_buffer);
269 if (!NILP (handler))
270 return call2 (handler, Qget_file_buffer, filename);
271
272 for (tail = Vbuffer_alist; CONSP (tail); tail = XCONS (tail)->cdr)
273 {
274 buf = Fcdr (XCONS (tail)->car);
275 if (!BUFFERP (buf)) continue;
276 if (!STRINGP (XBUFFER (buf)->filename)) continue;
277 tem = Fstring_equal (XBUFFER (buf)->filename, filename);
278 if (!NILP (tem))
279 return buf;
280 }
281 return Qnil;
282 }
283
284 Lisp_Object
285 get_truename_buffer (filename)
286 register Lisp_Object filename;
287 {
288 register Lisp_Object tail, buf, tem;
289
290 for (tail = Vbuffer_alist; CONSP (tail); tail = XCONS (tail)->cdr)
291 {
292 buf = Fcdr (XCONS (tail)->car);
293 if (!BUFFERP (buf)) continue;
294 if (!STRINGP (XBUFFER (buf)->file_truename)) continue;
295 tem = Fstring_equal (XBUFFER (buf)->file_truename, filename);
296 if (!NILP (tem))
297 return buf;
298 }
299 return Qnil;
300 }
301
302 /* Incremented for each buffer created, to assign the buffer number. */
303 int buffer_count;
304
305 DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0,
306 "Return the buffer named NAME, or create such a buffer and return it.\n\
307 A new buffer is created if there is no live buffer named NAME.\n\
308 If NAME starts with a space, the new buffer does not keep undo information.\n\
309 If NAME is a buffer instead of a string, then it is the value returned.\n\
310 The value is never nil.")
311 (name)
312 register Lisp_Object name;
313 {
314 register Lisp_Object buf;
315 register struct buffer *b;
316
317 buf = Fget_buffer (name);
318 if (!NILP (buf))
319 return buf;
320
321 if (XSTRING (name)->size == 0)
322 error ("Empty string for buffer name is not allowed");
323
324 b = (struct buffer *) xmalloc (sizeof (struct buffer));
325
326 b->size = sizeof (struct buffer) / sizeof (EMACS_INT);
327
328 /* An ordinary buffer uses its own struct buffer_text. */
329 b->text = &b->own_text;
330 b->base_buffer = 0;
331
332 BUF_GAP_SIZE (b) = 20;
333 BLOCK_INPUT;
334 /* We allocate extra 1-byte at the tail and keep it always '\0' for
335 anchoring a search. */
336 BUFFER_ALLOC (BUF_BEG_ADDR (b), (BUF_GAP_SIZE (b) + 1));
337 UNBLOCK_INPUT;
338 if (! BUF_BEG_ADDR (b))
339 buffer_memory_full ();
340
341 BUF_PT (b) = 1;
342 BUF_GPT (b) = 1;
343 BUF_BEGV (b) = 1;
344 BUF_ZV (b) = 1;
345 BUF_Z (b) = 1;
346 BUF_MODIFF (b) = 1;
347 BUF_OVERLAY_MODIFF (b) = 1;
348 BUF_SAVE_MODIFF (b) = 1;
349 BUF_INTERVALS (b) = 0;
350 *(BUF_GPT_ADDR (b)) = *(BUF_Z_ADDR (b)) = 0; /* Put an anchor '\0'. */
351
352 b->newline_cache = 0;
353 b->width_run_cache = 0;
354 b->width_table = Qnil;
355
356 /* Put this on the chain of all buffers including killed ones. */
357 b->next = all_buffers;
358 all_buffers = b;
359
360 /* An ordinary buffer normally doesn't need markers
361 to handle BEGV and ZV. */
362 b->pt_marker = Qnil;
363 b->begv_marker = Qnil;
364 b->zv_marker = Qnil;
365
366 name = Fcopy_sequence (name);
367 INITIALIZE_INTERVAL (XSTRING (name), NULL_INTERVAL);
368 b->name = name;
369
370 if (XSTRING (name)->data[0] != ' ')
371 b->undo_list = Qnil;
372 else
373 b->undo_list = Qt;
374
375 reset_buffer (b);
376 reset_buffer_local_variables (b, 1);
377
378 /* Put this in the alist of all live buffers. */
379 XSETBUFFER (buf, b);
380 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
381
382 b->mark = Fmake_marker ();
383 BUF_MARKERS (b) = Qnil;
384 b->name = name;
385 return buf;
386 }
387
388 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, Smake_indirect_buffer, 2, 2,
389 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
390 "Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.\n\
391 BASE-BUFFER should be an existing buffer (or buffer name).\n\
392 NAME should be a string which is not the name of an existing buffer.")
393 (base_buffer, name)
394 register Lisp_Object base_buffer, name;
395 {
396 register Lisp_Object buf;
397 register struct buffer *b;
398
399 buf = Fget_buffer (name);
400 if (!NILP (buf))
401 error ("Buffer name `%s' is in use", XSTRING (name)->data);
402
403 base_buffer = Fget_buffer (base_buffer);
404 if (NILP (base_buffer))
405 error ("No such buffer: `%s'",
406 XSTRING (XBUFFER (base_buffer)->name)->data);
407
408 if (XSTRING (name)->size == 0)
409 error ("Empty string for buffer name is not allowed");
410
411 b = (struct buffer *) xmalloc (sizeof (struct buffer));
412
413 b->size = sizeof (struct buffer) / sizeof (EMACS_INT);
414
415 if (XBUFFER (base_buffer)->base_buffer)
416 b->base_buffer = XBUFFER (base_buffer)->base_buffer;
417 else
418 b->base_buffer = XBUFFER (base_buffer);
419
420 /* Use the base buffer's text object. */
421 b->text = b->base_buffer->text;
422
423 BUF_BEGV (b) = BUF_BEGV (b->base_buffer);
424 BUF_ZV (b) = BUF_ZV (b->base_buffer);
425 BUF_PT (b) = BUF_PT (b->base_buffer);
426
427 b->newline_cache = 0;
428 b->width_run_cache = 0;
429 b->width_table = Qnil;
430
431 /* Put this on the chain of all buffers including killed ones. */
432 b->next = all_buffers;
433 all_buffers = b;
434
435 name = Fcopy_sequence (name);
436 INITIALIZE_INTERVAL (XSTRING (name), NULL_INTERVAL);
437 b->name = name;
438
439 reset_buffer (b);
440 reset_buffer_local_variables (b, 1);
441
442 /* Put this in the alist of all live buffers. */
443 XSETBUFFER (buf, b);
444 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
445
446 b->mark = Fmake_marker ();
447 b->name = name;
448
449 /* Make sure the base buffer has markers for its narrowing. */
450 if (NILP (b->base_buffer->pt_marker))
451 {
452 b->base_buffer->pt_marker = Fmake_marker ();
453 Fset_marker (b->base_buffer->pt_marker,
454 make_number (BUF_PT (b->base_buffer)), base_buffer);
455 }
456 if (NILP (b->base_buffer->begv_marker))
457 {
458 b->base_buffer->begv_marker = Fmake_marker ();
459 Fset_marker (b->base_buffer->begv_marker,
460 make_number (BUF_BEGV (b->base_buffer)), base_buffer);
461 }
462 if (NILP (b->base_buffer->zv_marker))
463 {
464 b->base_buffer->zv_marker = Fmake_marker ();
465 Fset_marker (b->base_buffer->zv_marker,
466 make_number (BUF_ZV (b->base_buffer)), base_buffer);
467 XMARKER (b->base_buffer->zv_marker)->insertion_type = 1;
468 }
469
470 /* Give the indirect buffer markers for its narrowing. */
471 b->pt_marker = Fmake_marker ();
472 Fset_marker (b->pt_marker, make_number (BUF_PT (b)), buf);
473 b->begv_marker = Fmake_marker ();
474 Fset_marker (b->begv_marker, make_number (BUF_BEGV (b)), buf);
475 b->zv_marker = Fmake_marker ();
476 Fset_marker (b->zv_marker, make_number (BUF_ZV (b)), buf);
477
478 XMARKER (b->zv_marker)->insertion_type = 1;
479
480 return buf;
481 }
482
483 /* Reinitialize everything about a buffer except its name and contents
484 and local variables. */
485
486 void
487 reset_buffer (b)
488 register struct buffer *b;
489 {
490 b->filename = Qnil;
491 b->file_truename = Qnil;
492 b->directory = (current_buffer) ? current_buffer->directory : Qnil;
493 b->modtime = 0;
494 XSETFASTINT (b->save_length, 0);
495 b->last_window_start = 1;
496 /* It is more conservative to start out "changed" than "unchanged". */
497 b->clip_changed = 1;
498 b->backed_up = Qnil;
499 b->auto_save_modified = 0;
500 b->auto_save_failure_time = -1;
501 b->auto_save_file_name = Qnil;
502 b->read_only = Qnil;
503 b->overlays_before = Qnil;
504 b->overlays_after = Qnil;
505 XSETFASTINT (b->overlay_center, 1);
506 b->mark_active = Qnil;
507 b->point_before_scroll = Qnil;
508 b->file_format = Qnil;
509 b->last_selected_window = Qnil;
510 XSETINT (b->display_count, 0);
511 b->extra2 = Qnil;
512 b->extra3 = Qnil;
513 }
514
515 /* Reset buffer B's local variables info.
516 Don't use this on a buffer that has already been in use;
517 it does not treat permanent locals consistently.
518 Instead, use Fkill_all_local_variables.
519
520 If PERMANENT_TOO is 1, then we reset permanent built-in
521 buffer-local variables. If PERMANENT_TOO is 0,
522 we preserve those. */
523
524 static void
525 reset_buffer_local_variables (b, permanent_too)
526 register struct buffer *b;
527 int permanent_too;
528 {
529 register int offset;
530 int dont_reset;
531
532 /* Decide which built-in local variables to reset. */
533 if (permanent_too)
534 dont_reset = 0;
535 else
536 dont_reset = buffer_permanent_local_flags;
537
538 /* Reset the major mode to Fundamental, together with all the
539 things that depend on the major mode.
540 default-major-mode is handled at a higher level.
541 We ignore it here. */
542 b->major_mode = Qfundamental_mode;
543 b->keymap = Qnil;
544 b->abbrev_table = Vfundamental_mode_abbrev_table;
545 b->mode_name = QSFundamental;
546 b->minor_modes = Qnil;
547
548 /* If the standard case table has been altered and invalidated,
549 fix up its insides first. */
550 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table)->extras[0])
551 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table)->extras[1])
552 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table)->extras[2])))
553 Fset_standard_case_table (Vascii_downcase_table);
554
555 b->downcase_table = Vascii_downcase_table;
556 b->upcase_table = XCHAR_TABLE (Vascii_downcase_table)->extras[0];
557 b->case_canon_table = XCHAR_TABLE (Vascii_downcase_table)->extras[1];
558 b->case_eqv_table = XCHAR_TABLE (Vascii_downcase_table)->extras[2];
559 b->invisibility_spec = Qt;
560 #ifndef DOS_NT
561 b->buffer_file_type = Qnil;
562 #endif
563
564 #if 0
565 b->sort_table = XSTRING (Vascii_sort_table);
566 b->folding_sort_table = XSTRING (Vascii_folding_sort_table);
567 #endif /* 0 */
568
569 /* Reset all (or most) per-buffer variables to their defaults. */
570 b->local_var_alist = Qnil;
571 b->local_var_flags &= dont_reset;
572
573 /* For each slot that has a default value,
574 copy that into the slot. */
575
576 for (offset = (char *)&buffer_local_flags.name - (char *)&buffer_local_flags;
577 offset < sizeof (struct buffer);
578 offset += sizeof (Lisp_Object)) /* sizeof EMACS_INT == sizeof Lisp_Object */
579 {
580 int flag = XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags));
581 if ((flag > 0
582 /* Don't reset a permanent local. */
583 && ! (dont_reset & flag))
584 || flag == -2)
585 *(Lisp_Object *)(offset + (char *)b)
586 = *(Lisp_Object *)(offset + (char *)&buffer_defaults);
587 }
588 }
589
590 /* We split this away from generate-new-buffer, because rename-buffer
591 and set-visited-file-name ought to be able to use this to really
592 rename the buffer properly. */
593
594 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, Sgenerate_new_buffer_name,
595 1, 2, 0,
596 "Return a string that is the name of no existing buffer based on NAME.\n\
597 If there is no live buffer named NAME, then return NAME.\n\
598 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
599 until an unused name is found, and then return that name.\n\
600 Optional second argument IGNORE specifies a name that is okay to use\n\
601 \(if it is in the sequence to be tried)\n\
602 even if a buffer with that name exists.")
603 (name, ignore)
604 register Lisp_Object name, ignore;
605 {
606 register Lisp_Object gentemp, tem;
607 int count;
608 char number[10];
609
610 CHECK_STRING (name, 0);
611
612 tem = Fget_buffer (name);
613 if (NILP (tem))
614 return name;
615
616 count = 1;
617 while (1)
618 {
619 sprintf (number, "<%d>", ++count);
620 gentemp = concat2 (name, build_string (number));
621 tem = Fstring_equal (gentemp, ignore);
622 if (!NILP (tem))
623 return gentemp;
624 tem = Fget_buffer (gentemp);
625 if (NILP (tem))
626 return gentemp;
627 }
628 }
629
630 \f
631 DEFUN ("buffer-name", Fbuffer_name, Sbuffer_name, 0, 1, 0,
632 "Return the name of BUFFER, as a string.\n\
633 With no argument or nil as argument, return the name of the current buffer.")
634 (buffer)
635 register Lisp_Object buffer;
636 {
637 if (NILP (buffer))
638 return current_buffer->name;
639 CHECK_BUFFER (buffer, 0);
640 return XBUFFER (buffer)->name;
641 }
642
643 DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0,
644 "Return name of file BUFFER is visiting, or nil if none.\n\
645 No argument or nil as argument means use the current buffer.")
646 (buffer)
647 register Lisp_Object buffer;
648 {
649 if (NILP (buffer))
650 return current_buffer->filename;
651 CHECK_BUFFER (buffer, 0);
652 return XBUFFER (buffer)->filename;
653 }
654
655 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, Sbuffer_base_buffer,
656 0, 1, 0,
657 "Return the base buffer of indirect buffer BUFFER.\n\
658 If BUFFER is not indirect, return nil.")
659 (buffer)
660 register Lisp_Object buffer;
661 {
662 struct buffer *base;
663 Lisp_Object base_buffer;
664
665 if (NILP (buffer))
666 base = current_buffer->base_buffer;
667 else
668 {
669 CHECK_BUFFER (buffer, 0);
670 base = XBUFFER (buffer)->base_buffer;
671 }
672
673 if (! base)
674 return Qnil;
675 XSETBUFFER (base_buffer, base);
676 return base_buffer;
677 }
678
679 DEFUN ("buffer-local-variables", Fbuffer_local_variables,
680 Sbuffer_local_variables, 0, 1, 0,
681 "Return an alist of variables that are buffer-local in BUFFER.\n\
682 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
683 For a symbol that is locally unbound, just the symbol appears in the value.\n\
684 Note that storing new VALUEs in these elements doesn't change the variables.\n\
685 No argument or nil as argument means use current buffer as BUFFER.")
686 (buffer)
687 register Lisp_Object buffer;
688 {
689 register struct buffer *buf;
690 register Lisp_Object result;
691
692 if (NILP (buffer))
693 buf = current_buffer;
694 else
695 {
696 CHECK_BUFFER (buffer, 0);
697 buf = XBUFFER (buffer);
698 }
699
700 result = Qnil;
701
702 {
703 register Lisp_Object tail;
704 for (tail = buf->local_var_alist; CONSP (tail); tail = XCONS (tail)->cdr)
705 {
706 Lisp_Object val, elt;
707
708 elt = XCONS (tail)->car;
709
710 /* Reference each variable in the alist in buf.
711 If inquiring about the current buffer, this gets the current values,
712 so store them into the alist so the alist is up to date.
713 If inquiring about some other buffer, this swaps out any values
714 for that buffer, making the alist up to date automatically. */
715 val = find_symbol_value (XCONS (elt)->car);
716 /* Use the current buffer value only if buf is the current buffer. */
717 if (buf != current_buffer)
718 val = XCONS (elt)->cdr;
719
720 /* If symbol is unbound, put just the symbol in the list. */
721 if (EQ (val, Qunbound))
722 result = Fcons (XCONS (elt)->car, result);
723 /* Otherwise, put (symbol . value) in the list. */
724 else
725 result = Fcons (Fcons (XCONS (elt)->car, val), result);
726 }
727 }
728
729 /* Add on all the variables stored in special slots. */
730 {
731 register int offset, mask;
732
733 for (offset = (char *)&buffer_local_symbols.name - (char *)&buffer_local_symbols;
734 offset < sizeof (struct buffer);
735 offset += (sizeof (EMACS_INT))) /* sizeof EMACS_INT == sizeof Lisp_Object */
736 {
737 mask = XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags));
738 if (mask == -1 || (buf->local_var_flags & mask))
739 if (SYMBOLP (*(Lisp_Object *)(offset
740 + (char *)&buffer_local_symbols)))
741 result = Fcons (Fcons (*((Lisp_Object *)
742 (offset + (char *)&buffer_local_symbols)),
743 *(Lisp_Object *)(offset + (char *)buf)),
744 result);
745 }
746 }
747
748 return result;
749 }
750
751 \f
752 DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p,
753 0, 1, 0,
754 "Return t if BUFFER was modified since its file was last read or saved.\n\
755 No argument or nil as argument means use current buffer as BUFFER.")
756 (buffer)
757 register Lisp_Object buffer;
758 {
759 register struct buffer *buf;
760 if (NILP (buffer))
761 buf = current_buffer;
762 else
763 {
764 CHECK_BUFFER (buffer, 0);
765 buf = XBUFFER (buffer);
766 }
767
768 return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil;
769 }
770
771 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p,
772 1, 1, 0,
773 "Mark current buffer as modified or unmodified according to FLAG.\n\
774 A non-nil FLAG means mark the buffer modified.")
775 (flag)
776 register Lisp_Object flag;
777 {
778 register int already;
779 register Lisp_Object fn;
780
781 #ifdef CLASH_DETECTION
782 /* If buffer becoming modified, lock the file.
783 If buffer becoming unmodified, unlock the file. */
784
785 fn = current_buffer->file_truename;
786 if (!NILP (fn))
787 {
788 already = SAVE_MODIFF < MODIFF;
789 if (!already && !NILP (flag))
790 lock_file (fn);
791 else if (already && NILP (flag))
792 unlock_file (fn);
793 }
794 #endif /* CLASH_DETECTION */
795
796 SAVE_MODIFF = NILP (flag) ? MODIFF : 0;
797 update_mode_lines++;
798 return flag;
799 }
800
801 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, Sbuffer_modified_tick,
802 0, 1, 0,
803 "Return BUFFER's tick counter, incremented for each change in text.\n\
804 Each buffer has a tick counter which is incremented each time the text in\n\
805 that buffer is changed. It wraps around occasionally.\n\
806 No argument or nil as argument means use current buffer as BUFFER.")
807 (buffer)
808 register Lisp_Object buffer;
809 {
810 register struct buffer *buf;
811 if (NILP (buffer))
812 buf = current_buffer;
813 else
814 {
815 CHECK_BUFFER (buffer, 0);
816 buf = XBUFFER (buffer);
817 }
818
819 return make_number (BUF_MODIFF (buf));
820 }
821 \f
822 DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2,
823 "sRename buffer (to new name): \nP",
824 "Change current buffer's name to NEWNAME (a string).\n\
825 If second arg UNIQUE is nil or omitted, it is an error if a\n\
826 buffer named NEWNAME already exists.\n\
827 If UNIQUE is non-nil, come up with a new name using\n\
828 `generate-new-buffer-name'.\n\
829 Interactively, you can set UNIQUE with a prefix argument.\n\
830 We return the name we actually gave the buffer.\n\
831 This does not change the name of the visited file (if any).")
832 (newname, unique)
833 register Lisp_Object newname, unique;
834 {
835 register Lisp_Object tem, buf;
836
837 CHECK_STRING (newname, 0);
838
839 if (XSTRING (newname)->size == 0)
840 error ("Empty string is invalid as a buffer name");
841
842 tem = Fget_buffer (newname);
843 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
844 the buffer automatically so you can create another with the original name.
845 It makes UNIQUE equivalent to
846 (rename-buffer (generate-new-buffer-name NEWNAME)). */
847 if (NILP (unique) && XBUFFER (tem) == current_buffer)
848 return current_buffer->name;
849 if (!NILP (tem))
850 {
851 if (!NILP (unique))
852 newname = Fgenerate_new_buffer_name (newname, current_buffer->name);
853 else
854 error ("Buffer name `%s' is in use", XSTRING (newname)->data);
855 }
856
857 current_buffer->name = newname;
858
859 /* Catch redisplay's attention. Unless we do this, the mode lines for
860 any windows displaying current_buffer will stay unchanged. */
861 update_mode_lines++;
862
863 XSETBUFFER (buf, current_buffer);
864 Fsetcar (Frassq (buf, Vbuffer_alist), newname);
865 if (NILP (current_buffer->filename)
866 && !NILP (current_buffer->auto_save_file_name))
867 call0 (intern ("rename-auto-save-file"));
868 /* Refetch since that last call may have done GC. */
869 return current_buffer->name;
870 }
871
872 DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 2, 0,
873 "Return most recently selected buffer other than BUFFER.\n\
874 Buffers not visible in windows are preferred to visible buffers,\n\
875 unless optional second argument VISIBLE-OK is non-nil.\n\
876 If no other buffer exists, the buffer `*scratch*' is returned.\n\
877 If BUFFER is omitted or nil, some interesting buffer is returned.")
878 (buffer, visible_ok)
879 register Lisp_Object buffer, visible_ok;
880 {
881 Lisp_Object Fset_buffer_major_mode ();
882 register Lisp_Object tail, buf, notsogood, tem, pred, add_ons;
883 notsogood = Qnil;
884
885 tail = Vbuffer_alist;
886 pred = frame_buffer_predicate ();
887
888 /* Consider buffers that have been seen in the selected frame
889 before other buffers. */
890
891 tem = frame_buffer_list ();
892 add_ons = Qnil;
893 while (CONSP (tem))
894 {
895 if (BUFFERP (XCONS (tem)->car))
896 add_ons = Fcons (Fcons (Qnil, XCONS (tem)->car), add_ons);
897 tem = XCONS (tem)->cdr;
898 }
899 tail = nconc2 (Fnreverse (add_ons), tail);
900
901 for (; !NILP (tail); tail = Fcdr (tail))
902 {
903 buf = Fcdr (Fcar (tail));
904 if (EQ (buf, buffer))
905 continue;
906 if (XSTRING (XBUFFER (buf)->name)->data[0] == ' ')
907 continue;
908 /* If the selected frame has a buffer_predicate,
909 disregard buffers that don't fit the predicate. */
910 if (!NILP (pred))
911 {
912 tem = call1 (pred, buf);
913 if (NILP (tem))
914 continue;
915 }
916
917 if (NILP (visible_ok))
918 tem = Fget_buffer_window (buf, Qt);
919 else
920 tem = Qnil;
921 if (NILP (tem))
922 return buf;
923 if (NILP (notsogood))
924 notsogood = buf;
925 }
926 if (!NILP (notsogood))
927 return notsogood;
928 buf = Fget_buffer_create (build_string ("*scratch*"));
929 Fset_buffer_major_mode (buf);
930 return buf;
931 }
932 \f
933 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, Sbuffer_disable_undo,
934 0, 1, "",
935 "Make BUFFER stop keeping undo information.\n\
936 No argument or nil as argument means do this for the current buffer.")
937 (buffer)
938 register Lisp_Object buffer;
939 {
940 Lisp_Object real_buffer;
941
942 if (NILP (buffer))
943 XSETBUFFER (real_buffer, current_buffer);
944 else
945 {
946 real_buffer = Fget_buffer (buffer);
947 if (NILP (real_buffer))
948 nsberror (buffer);
949 }
950
951 XBUFFER (real_buffer)->undo_list = Qt;
952
953 return Qnil;
954 }
955
956 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,
957 0, 1, "",
958 "Start keeping undo information for buffer BUFFER.\n\
959 No argument or nil as argument means do this for the current buffer.")
960 (buffer)
961 register Lisp_Object buffer;
962 {
963 Lisp_Object real_buffer;
964
965 if (NILP (buffer))
966 XSETBUFFER (real_buffer, current_buffer);
967 else
968 {
969 real_buffer = Fget_buffer (buffer);
970 if (NILP (real_buffer))
971 nsberror (buffer);
972 }
973
974 if (EQ (XBUFFER (real_buffer)->undo_list, Qt))
975 XBUFFER (real_buffer)->undo_list = Qnil;
976
977 return Qnil;
978 }
979
980 /*
981 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
982 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
983 The buffer being killed will be current while the hook is running.\n\
984 See `kill-buffer'."
985 */
986 DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ",
987 "Kill the buffer BUFFER.\n\
988 The argument may be a buffer or may be the name of a buffer.\n\
989 An argument of nil means kill the current buffer.\n\n\
990 Value is t if the buffer is actually killed, nil if user says no.\n\n\
991 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
992 if not void, is a list of functions to be called, with no arguments,\n\
993 before the buffer is actually killed. The buffer to be killed is current\n\
994 when the hook functions are called.\n\n\
995 Any processes that have this buffer as the `process-buffer' are killed\n\
996 with SIGHUP.")
997 (buffer)
998 Lisp_Object buffer;
999 {
1000 Lisp_Object buf;
1001 register struct buffer *b;
1002 register Lisp_Object tem;
1003 register struct Lisp_Marker *m;
1004 struct gcpro gcpro1, gcpro2;
1005
1006 if (NILP (buffer))
1007 buf = Fcurrent_buffer ();
1008 else
1009 buf = Fget_buffer (buffer);
1010 if (NILP (buf))
1011 nsberror (buffer);
1012
1013 b = XBUFFER (buf);
1014
1015 /* Avoid trouble for buffer already dead. */
1016 if (NILP (b->name))
1017 return Qnil;
1018
1019 /* Query if the buffer is still modified. */
1020 if (INTERACTIVE && !NILP (b->filename)
1021 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
1022 {
1023 GCPRO1 (buf);
1024 tem = do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
1025 XSTRING (b->name)->data));
1026 UNGCPRO;
1027 if (NILP (tem))
1028 return Qnil;
1029 }
1030
1031 /* Run hooks with the buffer to be killed the current buffer. */
1032 {
1033 register Lisp_Object val;
1034 int count = specpdl_ptr - specpdl;
1035 Lisp_Object list;
1036
1037 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1038 set_buffer_internal (b);
1039
1040 /* First run the query functions; if any query is answered no,
1041 don't kill the buffer. */
1042 for (list = Vkill_buffer_query_functions; !NILP (list); list = Fcdr (list))
1043 {
1044 tem = call0 (Fcar (list));
1045 if (NILP (tem))
1046 return unbind_to (count, Qnil);
1047 }
1048
1049 /* Then run the hooks. */
1050 if (!NILP (Vrun_hooks))
1051 call1 (Vrun_hooks, Qkill_buffer_hook);
1052 unbind_to (count, Qnil);
1053 }
1054
1055 /* We have no more questions to ask. Verify that it is valid
1056 to kill the buffer. This must be done after the questions
1057 since anything can happen within do_yes_or_no_p. */
1058
1059 /* Don't kill the minibuffer now current. */
1060 if (EQ (buf, XWINDOW (minibuf_window)->buffer))
1061 return Qnil;
1062
1063 if (NILP (b->name))
1064 return Qnil;
1065
1066 /* When we kill a base buffer, kill all its indirect buffers.
1067 We do it at this stage so nothing terrible happens if they
1068 ask questions or their hooks get errors. */
1069 if (! b->base_buffer)
1070 {
1071 struct buffer *other;
1072
1073 GCPRO1 (buf);
1074
1075 for (other = all_buffers; other; other = other->next)
1076 /* all_buffers contains dead buffers too;
1077 don't re-kill them. */
1078 if (other->base_buffer == b && !NILP (other->name))
1079 {
1080 Lisp_Object buf;
1081 XSETBUFFER (buf, other);
1082 Fkill_buffer (buf);
1083 }
1084
1085 UNGCPRO;
1086 }
1087
1088 /* Make this buffer not be current.
1089 In the process, notice if this is the sole visible buffer
1090 and give up if so. */
1091 if (b == current_buffer)
1092 {
1093 tem = Fother_buffer (buf, Qnil);
1094 Fset_buffer (tem);
1095 if (b == current_buffer)
1096 return Qnil;
1097 }
1098
1099 /* Now there is no question: we can kill the buffer. */
1100
1101 #ifdef CLASH_DETECTION
1102 /* Unlock this buffer's file, if it is locked. */
1103 unlock_buffer (b);
1104 #endif /* CLASH_DETECTION */
1105
1106 kill_buffer_processes (buf);
1107
1108 tem = Vinhibit_quit;
1109 Vinhibit_quit = Qt;
1110 replace_buffer_in_all_windows (buf);
1111 Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist);
1112 frames_discard_buffer (buf);
1113 Vinhibit_quit = tem;
1114
1115 /* Delete any auto-save file, if we saved it in this session. */
1116 if (STRINGP (b->auto_save_file_name)
1117 && b->auto_save_modified != 0
1118 && BUF_SAVE_MODIFF (b) < b->auto_save_modified)
1119 {
1120 Lisp_Object tem;
1121 tem = Fsymbol_value (intern ("delete-auto-save-files"));
1122 if (! NILP (tem))
1123 internal_delete_file (b->auto_save_file_name);
1124 }
1125
1126 if (b->base_buffer)
1127 {
1128 /* Unchain all markers that belong to this indirect buffer.
1129 Don't unchain the markers that belong to the base buffer
1130 or its other indirect buffers. */
1131 for (tem = BUF_MARKERS (b); !NILP (tem); )
1132 {
1133 Lisp_Object next;
1134 m = XMARKER (tem);
1135 next = m->chain;
1136 if (m->buffer == b)
1137 unchain_marker (tem);
1138 tem = next;
1139 }
1140 }
1141 else
1142 {
1143 /* Unchain all markers of this buffer and its indirect buffers.
1144 and leave them pointing nowhere. */
1145 for (tem = BUF_MARKERS (b); !NILP (tem); )
1146 {
1147 m = XMARKER (tem);
1148 m->buffer = 0;
1149 tem = m->chain;
1150 m->chain = Qnil;
1151 }
1152 BUF_MARKERS (b) = Qnil;
1153
1154 #ifdef USE_TEXT_PROPERTIES
1155 BUF_INTERVALS (b) = NULL_INTERVAL;
1156 #endif
1157
1158 /* Perhaps we should explicitly free the interval tree here... */
1159 }
1160
1161 /* Reset the local variables, so that this buffer's local values
1162 won't be protected from GC. They would be protected
1163 if they happened to remain encached in their symbols.
1164 This gets rid of them for certain. */
1165 swap_out_buffer_local_variables (b);
1166 reset_buffer_local_variables (b, 1);
1167
1168 b->name = Qnil;
1169
1170 BLOCK_INPUT;
1171 if (! b->base_buffer)
1172 BUFFER_FREE (BUF_BEG_ADDR (b));
1173
1174 if (b->newline_cache)
1175 {
1176 free_region_cache (b->newline_cache);
1177 b->newline_cache = 0;
1178 }
1179 if (b->width_run_cache)
1180 {
1181 free_region_cache (b->width_run_cache);
1182 b->width_run_cache = 0;
1183 }
1184 b->width_table = Qnil;
1185 UNBLOCK_INPUT;
1186 b->undo_list = Qnil;
1187
1188 return Qt;
1189 }
1190 \f
1191 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1192 we do this each time BUF is selected visibly, the more recently
1193 selected buffers are always closer to the front of the list. This
1194 means that other_buffer is more likely to choose a relevant buffer. */
1195
1196 void
1197 record_buffer (buf)
1198 Lisp_Object buf;
1199 {
1200 register Lisp_Object link, prev;
1201
1202 prev = Qnil;
1203 for (link = Vbuffer_alist; CONSP (link); link = XCONS (link)->cdr)
1204 {
1205 if (EQ (XCONS (XCONS (link)->car)->cdr, buf))
1206 break;
1207 prev = link;
1208 }
1209
1210 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1211 we cannot use Fdelq itself here because it allows quitting. */
1212
1213 if (NILP (prev))
1214 Vbuffer_alist = XCONS (Vbuffer_alist)->cdr;
1215 else
1216 XCONS (prev)->cdr = XCONS (XCONS (prev)->cdr)->cdr;
1217
1218 XCONS (link)->cdr = Vbuffer_alist;
1219 Vbuffer_alist = link;
1220
1221 /* Now move this buffer to the front of frame_buffer_list also. */
1222
1223 prev = Qnil;
1224 for (link = frame_buffer_list (); CONSP (link); link = XCONS (link)->cdr)
1225 {
1226 if (EQ (XCONS (link)->car, buf))
1227 break;
1228 prev = link;
1229 }
1230
1231 /* Effectively do delq. */
1232
1233 if (CONSP (link))
1234 {
1235 if (NILP (prev))
1236 set_frame_buffer_list (XCONS (frame_buffer_list ())->cdr);
1237 else
1238 XCONS (prev)->cdr = XCONS (XCONS (prev)->cdr)->cdr;
1239
1240 XCONS (link)->cdr = frame_buffer_list ();
1241 set_frame_buffer_list (link);
1242 }
1243 else
1244 set_frame_buffer_list (Fcons (buf, frame_buffer_list ()));
1245 }
1246
1247 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0,
1248 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1249 Use this function before selecting the buffer, since it may need to inspect\n\
1250 the current buffer's major mode.")
1251 (buffer)
1252 Lisp_Object buffer;
1253 {
1254 int count;
1255 Lisp_Object function;
1256
1257 function = buffer_defaults.major_mode;
1258 if (NILP (function) && NILP (Fget (current_buffer->major_mode, Qmode_class)))
1259 function = current_buffer->major_mode;
1260
1261 if (NILP (function) || EQ (function, Qfundamental_mode))
1262 return Qnil;
1263
1264 count = specpdl_ptr - specpdl;
1265
1266 /* To select a nonfundamental mode,
1267 select the buffer temporarily and then call the mode function. */
1268
1269 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1270
1271 Fset_buffer (buffer);
1272 call0 (function);
1273
1274 return unbind_to (count, Qnil);
1275 }
1276
1277 DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ",
1278 "Select buffer BUFFER in the current window.\n\
1279 BUFFER may be a buffer or a buffer name.\n\
1280 Optional second arg NORECORD non-nil means\n\
1281 do not put this buffer at the front of the list of recently selected ones.\n\
1282 \n\
1283 WARNING: This is NOT the way to work on another buffer temporarily\n\
1284 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1285 the window-buffer correspondences.")
1286 (buffer, norecord)
1287 Lisp_Object buffer, norecord;
1288 {
1289 register Lisp_Object buf;
1290 Lisp_Object tem;
1291
1292 if (EQ (minibuf_window, selected_window))
1293 error ("Cannot switch buffers in minibuffer window");
1294 tem = Fwindow_dedicated_p (selected_window);
1295 if (!NILP (tem))
1296 error ("Cannot switch buffers in a dedicated window");
1297
1298 if (NILP (buffer))
1299 buf = Fother_buffer (Fcurrent_buffer (), Qnil);
1300 else
1301 {
1302 buf = Fget_buffer (buffer);
1303 if (NILP (buf))
1304 {
1305 buf = Fget_buffer_create (buffer);
1306 Fset_buffer_major_mode (buf);
1307 }
1308 }
1309 Fset_buffer (buf);
1310 if (NILP (norecord))
1311 record_buffer (buf);
1312
1313 Fset_window_buffer (EQ (selected_window, minibuf_window)
1314 ? Fnext_window (minibuf_window, Qnil, Qnil)
1315 : selected_window,
1316 buf);
1317
1318 return buf;
1319 }
1320
1321 DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 3, 0,
1322 "Select buffer BUFFER in some window, preferably a different one.\n\
1323 If BUFFER is nil, then some other buffer is chosen.\n\
1324 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1325 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1326 window even if BUFFER is already visible in the selected window.\n\
1327 This uses the function `display-buffer' as a subroutine; see the documentation\n\
1328 of `display-buffer' for additional customization information.\n\
1329 \n\
1330 Optional third arg NORECORD non-nil means\n\
1331 do not put this buffer at the front of the list of recently selected ones.")
1332 (buffer, other_window, norecord)
1333 Lisp_Object buffer, other_window, norecord;
1334 {
1335 register Lisp_Object buf;
1336 if (NILP (buffer))
1337 buf = Fother_buffer (Fcurrent_buffer (), Qnil);
1338 else
1339 {
1340 buf = Fget_buffer (buffer);
1341 if (NILP (buf))
1342 {
1343 buf = Fget_buffer_create (buffer);
1344 Fset_buffer_major_mode (buf);
1345 }
1346 }
1347 Fset_buffer (buf);
1348 if (NILP (norecord))
1349 record_buffer (buf);
1350 Fselect_window (Fdisplay_buffer (buf, other_window));
1351 return buf;
1352 }
1353
1354 DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,
1355 "Return the current buffer as a Lisp object.")
1356 ()
1357 {
1358 register Lisp_Object buf;
1359 XSETBUFFER (buf, current_buffer);
1360 return buf;
1361 }
1362 \f
1363 /* Set the current buffer to B. */
1364
1365 void
1366 set_buffer_internal (b)
1367 register struct buffer *b;
1368 {
1369 register struct buffer *old_buf;
1370 register Lisp_Object tail, valcontents;
1371 Lisp_Object tem;
1372
1373 if (current_buffer == b)
1374 return;
1375
1376 windows_or_buffers_changed = 1;
1377 set_buffer_internal_1 (b);
1378 }
1379
1380 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1381 This is used by redisplay. */
1382
1383 void
1384 set_buffer_internal_1 (b)
1385 register struct buffer *b;
1386 {
1387 register struct buffer *old_buf;
1388 register Lisp_Object tail, valcontents;
1389 Lisp_Object tem;
1390
1391 if (current_buffer == b)
1392 return;
1393
1394 old_buf = current_buffer;
1395 current_buffer = b;
1396 last_known_column_point = -1; /* invalidate indentation cache */
1397
1398 if (old_buf)
1399 {
1400 /* Put the undo list back in the base buffer, so that it appears
1401 that an indirect buffer shares the undo list of its base. */
1402 if (old_buf->base_buffer)
1403 old_buf->base_buffer->undo_list = old_buf->undo_list;
1404
1405 /* If the old current buffer has markers to record PT, BEGV and ZV
1406 when it is not current, update them now. */
1407 if (! NILP (old_buf->pt_marker))
1408 {
1409 Lisp_Object obuf;
1410 XSETBUFFER (obuf, old_buf);
1411 Fset_marker (old_buf->pt_marker, make_number (BUF_PT (old_buf)),
1412 obuf);
1413 }
1414 if (! NILP (old_buf->begv_marker))
1415 {
1416 Lisp_Object obuf;
1417 XSETBUFFER (obuf, old_buf);
1418 Fset_marker (old_buf->begv_marker, make_number (BUF_BEGV (old_buf)),
1419 obuf);
1420 }
1421 if (! NILP (old_buf->zv_marker))
1422 {
1423 Lisp_Object obuf;
1424 XSETBUFFER (obuf, old_buf);
1425 Fset_marker (old_buf->zv_marker, make_number (BUF_ZV (old_buf)),
1426 obuf);
1427 }
1428 }
1429
1430 /* Get the undo list from the base buffer, so that it appears
1431 that an indirect buffer shares the undo list of its base. */
1432 if (b->base_buffer)
1433 b->undo_list = b->base_buffer->undo_list;
1434
1435 /* If the new current buffer has markers to record PT, BEGV and ZV
1436 when it is not current, fetch them now. */
1437 if (! NILP (b->pt_marker))
1438 BUF_PT (b) = marker_position (b->pt_marker);
1439 if (! NILP (b->begv_marker))
1440 BUF_BEGV (b) = marker_position (b->begv_marker);
1441 if (! NILP (b->zv_marker))
1442 BUF_ZV (b) = marker_position (b->zv_marker);
1443
1444 /* Look down buffer's list of local Lisp variables
1445 to find and update any that forward into C variables. */
1446
1447 for (tail = b->local_var_alist; !NILP (tail); tail = XCONS (tail)->cdr)
1448 {
1449 valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value;
1450 if ((BUFFER_LOCAL_VALUEP (valcontents)
1451 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1452 && (tem = XBUFFER_LOCAL_VALUE (valcontents)->car,
1453 (BOOLFWDP (tem) || INTFWDP (tem) || OBJFWDP (tem))))
1454 /* Just reference the variable
1455 to cause it to become set for this buffer. */
1456 Fsymbol_value (XCONS (XCONS (tail)->car)->car);
1457 }
1458
1459 /* Do the same with any others that were local to the previous buffer */
1460
1461 if (old_buf)
1462 for (tail = old_buf->local_var_alist; !NILP (tail); tail = XCONS (tail)->cdr)
1463 {
1464 valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value;
1465 if ((BUFFER_LOCAL_VALUEP (valcontents)
1466 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1467 && (tem = XBUFFER_LOCAL_VALUE (valcontents)->car,
1468 (BOOLFWDP (tem) || INTFWDP (tem) || OBJFWDP (tem))))
1469 /* Just reference the variable
1470 to cause it to become set for this buffer. */
1471 Fsymbol_value (XCONS (XCONS (tail)->car)->car);
1472 }
1473 }
1474
1475 /* Switch to buffer B temporarily for redisplay purposes.
1476 This avoids certain things that don't need to be done within redisplay. */
1477
1478 void
1479 set_buffer_temp (b)
1480 struct buffer *b;
1481 {
1482 register struct buffer *old_buf;
1483
1484 if (current_buffer == b)
1485 return;
1486
1487 old_buf = current_buffer;
1488 current_buffer = b;
1489
1490 if (old_buf)
1491 {
1492 /* If the old current buffer has markers to record PT, BEGV and ZV
1493 when it is not current, update them now. */
1494 if (! NILP (old_buf->pt_marker))
1495 {
1496 Lisp_Object obuf;
1497 XSETBUFFER (obuf, old_buf);
1498 Fset_marker (old_buf->pt_marker, make_number (BUF_PT (old_buf)),
1499 obuf);
1500 }
1501 if (! NILP (old_buf->begv_marker))
1502 {
1503 Lisp_Object obuf;
1504 XSETBUFFER (obuf, old_buf);
1505 Fset_marker (old_buf->begv_marker, make_number (BUF_BEGV (old_buf)),
1506 obuf);
1507 }
1508 if (! NILP (old_buf->zv_marker))
1509 {
1510 Lisp_Object obuf;
1511 XSETBUFFER (obuf, old_buf);
1512 Fset_marker (old_buf->zv_marker, make_number (BUF_ZV (old_buf)),
1513 obuf);
1514 }
1515 }
1516
1517 /* If the new current buffer has markers to record PT, BEGV and ZV
1518 when it is not current, fetch them now. */
1519 if (! NILP (b->pt_marker))
1520 BUF_PT (b) = marker_position (b->pt_marker);
1521 if (! NILP (b->begv_marker))
1522 BUF_BEGV (b) = marker_position (b->begv_marker);
1523 if (! NILP (b->zv_marker))
1524 BUF_ZV (b) = marker_position (b->zv_marker);
1525 }
1526
1527 DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,
1528 "Make the buffer BUFFER current for editing operations.\n\
1529 BUFFER may be a buffer or the name of an existing buffer.\n\
1530 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1531 This function does not display the buffer, so its effect ends\n\
1532 when the current command terminates.\n\
1533 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1534 (buffer)
1535 register Lisp_Object buffer;
1536 {
1537 register Lisp_Object buf;
1538 buf = Fget_buffer (buffer);
1539 if (NILP (buf))
1540 nsberror (buffer);
1541 if (NILP (XBUFFER (buf)->name))
1542 error ("Selecting deleted buffer");
1543 set_buffer_internal (XBUFFER (buf));
1544 return buf;
1545 }
1546 \f
1547 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only,
1548 Sbarf_if_buffer_read_only, 0, 0, 0,
1549 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1550 ()
1551 {
1552 if (!NILP (current_buffer->read_only)
1553 && NILP (Vinhibit_read_only))
1554 Fsignal (Qbuffer_read_only, (Fcons (Fcurrent_buffer (), Qnil)));
1555 return Qnil;
1556 }
1557
1558 DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",
1559 "Put BUFFER at the end of the list of all buffers.\n\
1560 There it is the least likely candidate for `other-buffer' to return;\n\
1561 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1562 If BUFFER is nil or omitted, bury the current buffer.\n\
1563 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1564 selected window if it is displayed there.")
1565 (buffer)
1566 register Lisp_Object buffer;
1567 {
1568 /* Figure out what buffer we're going to bury. */
1569 if (NILP (buffer))
1570 {
1571 XSETBUFFER (buffer, current_buffer);
1572
1573 /* If we're burying the current buffer, unshow it. */
1574 Fswitch_to_buffer (Fother_buffer (buffer, Qnil), Qnil);
1575 }
1576 else
1577 {
1578 Lisp_Object buf1;
1579
1580 buf1 = Fget_buffer (buffer);
1581 if (NILP (buf1))
1582 nsberror (buffer);
1583 buffer = buf1;
1584 }
1585
1586 /* Move buffer to the end of the buffer list. */
1587 {
1588 register Lisp_Object aelt, link;
1589
1590 aelt = Frassq (buffer, Vbuffer_alist);
1591 link = Fmemq (aelt, Vbuffer_alist);
1592 Vbuffer_alist = Fdelq (aelt, Vbuffer_alist);
1593 XCONS (link)->cdr = Qnil;
1594 Vbuffer_alist = nconc2 (Vbuffer_alist, link);
1595 }
1596
1597 frames_bury_buffer (buffer);
1598
1599 return Qnil;
1600 }
1601 \f
1602 DEFUN ("erase-buffer", Ferase_buffer, Serase_buffer, 0, 0, "*",
1603 "Delete the entire contents of the current buffer.\n\
1604 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1605 so the buffer is truly empty after this.")
1606 ()
1607 {
1608 Fwiden ();
1609 del_range (BEG, Z);
1610 current_buffer->last_window_start = 1;
1611 /* Prevent warnings, or suspension of auto saving, that would happen
1612 if future size is less than past size. Use of erase-buffer
1613 implies that the future text is not really related to the past text. */
1614 XSETFASTINT (current_buffer->save_length, 0);
1615 return Qnil;
1616 }
1617
1618 void
1619 validate_region (b, e)
1620 register Lisp_Object *b, *e;
1621 {
1622 CHECK_NUMBER_COERCE_MARKER (*b, 0);
1623 CHECK_NUMBER_COERCE_MARKER (*e, 1);
1624
1625 if (XINT (*b) > XINT (*e))
1626 {
1627 Lisp_Object tem;
1628 tem = *b; *b = *e; *e = tem;
1629 }
1630
1631 if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e)
1632 && XINT (*e) <= ZV))
1633 args_out_of_range (*b, *e);
1634 }
1635 \f
1636 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, Skill_all_local_variables,
1637 0, 0, 0,
1638 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1639 Most local variable bindings are eliminated so that the default values\n\
1640 become effective once more. Also, the syntax table is set from\n\
1641 `standard-syntax-table', the local keymap is set to nil,\n\
1642 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1643 This function also forces redisplay of the mode line.\n\
1644 \n\
1645 Every function to select a new major mode starts by\n\
1646 calling this function.\n\n\
1647 As a special exception, local variables whose names have\n\
1648 a non-nil `permanent-local' property are not eliminated by this function.\n\
1649 \n\
1650 The first thing this function does is run\n\
1651 the normal hook `change-major-mode-hook'.")
1652 ()
1653 {
1654 register Lisp_Object alist, sym, tem;
1655 Lisp_Object oalist;
1656
1657 if (!NILP (Vrun_hooks))
1658 call1 (Vrun_hooks, intern ("change-major-mode-hook"));
1659 oalist = current_buffer->local_var_alist;
1660
1661 /* Make sure none of the bindings in oalist
1662 remain swapped in, in their symbols. */
1663
1664 swap_out_buffer_local_variables (current_buffer);
1665
1666 /* Actually eliminate all local bindings of this buffer. */
1667
1668 reset_buffer_local_variables (current_buffer, 0);
1669
1670 /* Redisplay mode lines; we are changing major mode. */
1671
1672 update_mode_lines++;
1673
1674 /* Any which are supposed to be permanent,
1675 make local again, with the same values they had. */
1676
1677 for (alist = oalist; !NILP (alist); alist = XCONS (alist)->cdr)
1678 {
1679 sym = XCONS (XCONS (alist)->car)->car;
1680 tem = Fget (sym, Qpermanent_local);
1681 if (! NILP (tem))
1682 {
1683 Fmake_local_variable (sym);
1684 Fset (sym, XCONS (XCONS (alist)->car)->cdr);
1685 }
1686 }
1687
1688 /* Force mode-line redisplay. Useful here because all major mode
1689 commands call this function. */
1690 update_mode_lines++;
1691
1692 return Qnil;
1693 }
1694
1695 /* Make sure no local variables remain set up with buffer B
1696 for their current values. */
1697
1698 static void
1699 swap_out_buffer_local_variables (b)
1700 struct buffer *b;
1701 {
1702 Lisp_Object oalist, alist, sym, tem, buffer;
1703
1704 XSETBUFFER (buffer, b);
1705 oalist = b->local_var_alist;
1706
1707 for (alist = oalist; !NILP (alist); alist = XCONS (alist)->cdr)
1708 {
1709 sym = XCONS (XCONS (alist)->car)->car;
1710
1711 /* Need not do anything if some other buffer's binding is now encached. */
1712 tem = XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->car;
1713 if (XBUFFER (tem) == current_buffer)
1714 {
1715 /* Symbol is set up for this buffer's old local value.
1716 Set it up for the current buffer with the default value. */
1717
1718 tem = XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->cdr;
1719 /* Store the symbol's current value into the alist entry
1720 it is currently set up for. This is so that, if the
1721 local is marked permanent, and we make it local again
1722 later in Fkill_all_local_variables, we don't lose the value. */
1723 XCONS (XCONS (tem)->car)->cdr
1724 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car);
1725 /* Switch to the symbol's default-value alist entry. */
1726 XCONS (tem)->car = tem;
1727 /* Mark it as current for buffer B. */
1728 XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->car
1729 = buffer;
1730 /* Store the current value into any forwarding in the symbol. */
1731 store_symval_forwarding (sym, XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car,
1732 XCONS (tem)->cdr);
1733 }
1734 }
1735 }
1736 \f
1737 /* Find all the overlays in the current buffer that contain position POS.
1738 Return the number found, and store them in a vector in *VEC_PTR.
1739 Store in *LEN_PTR the size allocated for the vector.
1740 Store in *NEXT_PTR the next position after POS where an overlay starts,
1741 or ZV if there are no more overlays.
1742 Store in *PREV_PTR the previous position before POS where an overlay ends,
1743 or BEGV if there are no previous overlays.
1744 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1745
1746 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1747 when this function is called.
1748
1749 If EXTEND is non-zero, we make the vector bigger if necessary.
1750 If EXTEND is zero, we never extend the vector,
1751 and we store only as many overlays as will fit.
1752 But we still return the total number of overlays. */
1753
1754 int
1755 overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr, prev_ptr)
1756 int pos;
1757 int extend;
1758 Lisp_Object **vec_ptr;
1759 int *len_ptr;
1760 int *next_ptr;
1761 int *prev_ptr;
1762 {
1763 Lisp_Object tail, overlay, start, end, result;
1764 int idx = 0;
1765 int len = *len_ptr;
1766 Lisp_Object *vec = *vec_ptr;
1767 int next = ZV;
1768 int prev = BEGV;
1769 int inhibit_storing = 0;
1770
1771 for (tail = current_buffer->overlays_before;
1772 GC_CONSP (tail);
1773 tail = XCONS (tail)->cdr)
1774 {
1775 int startpos, endpos;
1776
1777 overlay = XCONS (tail)->car;
1778
1779 start = OVERLAY_START (overlay);
1780 end = OVERLAY_END (overlay);
1781 endpos = OVERLAY_POSITION (end);
1782 if (endpos < pos)
1783 {
1784 if (prev < endpos)
1785 prev = endpos;
1786 break;
1787 }
1788 if (endpos == pos)
1789 continue;
1790 startpos = OVERLAY_POSITION (start);
1791 if (startpos <= pos)
1792 {
1793 if (idx == len)
1794 {
1795 /* The supplied vector is full.
1796 Either make it bigger, or don't store any more in it. */
1797 if (extend)
1798 {
1799 *len_ptr = len *= 2;
1800 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
1801 *vec_ptr = vec;
1802 }
1803 else
1804 inhibit_storing = 1;
1805 }
1806
1807 if (!inhibit_storing)
1808 vec[idx] = overlay;
1809 /* Keep counting overlays even if we can't return them all. */
1810 idx++;
1811 }
1812 else if (startpos < next)
1813 next = startpos;
1814 }
1815
1816 for (tail = current_buffer->overlays_after;
1817 GC_CONSP (tail);
1818 tail = XCONS (tail)->cdr)
1819 {
1820 int startpos, endpos;
1821
1822 overlay = XCONS (tail)->car;
1823
1824 start = OVERLAY_START (overlay);
1825 end = OVERLAY_END (overlay);
1826 startpos = OVERLAY_POSITION (start);
1827 if (pos < startpos)
1828 {
1829 if (startpos < next)
1830 next = startpos;
1831 break;
1832 }
1833 endpos = OVERLAY_POSITION (end);
1834 if (pos < endpos)
1835 {
1836 if (idx == len)
1837 {
1838 if (extend)
1839 {
1840 *len_ptr = len *= 2;
1841 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
1842 *vec_ptr = vec;
1843 }
1844 else
1845 inhibit_storing = 1;
1846 }
1847
1848 if (!inhibit_storing)
1849 vec[idx] = overlay;
1850 idx++;
1851 }
1852 else if (endpos < pos && endpos > prev)
1853 prev = endpos;
1854 }
1855
1856 if (next_ptr)
1857 *next_ptr = next;
1858 if (prev_ptr)
1859 *prev_ptr = prev;
1860 return idx;
1861 }
1862 \f
1863 /* Find all the overlays in the current buffer that overlap the range BEG-END
1864 or are empty at BEG.
1865
1866 Return the number found, and store them in a vector in *VEC_PTR.
1867 Store in *LEN_PTR the size allocated for the vector.
1868 Store in *NEXT_PTR the next position after POS where an overlay starts,
1869 or ZV if there are no more overlays.
1870 Store in *PREV_PTR the previous position before POS where an overlay ends,
1871 or BEGV if there are no previous overlays.
1872 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1873
1874 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1875 when this function is called.
1876
1877 If EXTEND is non-zero, we make the vector bigger if necessary.
1878 If EXTEND is zero, we never extend the vector,
1879 and we store only as many overlays as will fit.
1880 But we still return the total number of overlays. */
1881
1882 int
1883 overlays_in (beg, end, extend, vec_ptr, len_ptr, next_ptr, prev_ptr)
1884 int beg, end;
1885 int extend;
1886 Lisp_Object **vec_ptr;
1887 int *len_ptr;
1888 int *next_ptr;
1889 int *prev_ptr;
1890 {
1891 Lisp_Object tail, overlay, ostart, oend, result;
1892 int idx = 0;
1893 int len = *len_ptr;
1894 Lisp_Object *vec = *vec_ptr;
1895 int next = ZV;
1896 int prev = BEGV;
1897 int inhibit_storing = 0;
1898
1899 for (tail = current_buffer->overlays_before;
1900 GC_CONSP (tail);
1901 tail = XCONS (tail)->cdr)
1902 {
1903 int startpos, endpos;
1904
1905 overlay = XCONS (tail)->car;
1906
1907 ostart = OVERLAY_START (overlay);
1908 oend = OVERLAY_END (overlay);
1909 endpos = OVERLAY_POSITION (oend);
1910 if (endpos < beg)
1911 {
1912 if (prev < endpos)
1913 prev = endpos;
1914 break;
1915 }
1916 startpos = OVERLAY_POSITION (ostart);
1917 /* Count an interval if it either overlaps the range
1918 or is empty at the start of the range. */
1919 if ((beg < endpos && startpos < end)
1920 || (startpos == endpos && beg == endpos))
1921 {
1922 if (idx == len)
1923 {
1924 /* The supplied vector is full.
1925 Either make it bigger, or don't store any more in it. */
1926 if (extend)
1927 {
1928 *len_ptr = len *= 2;
1929 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
1930 *vec_ptr = vec;
1931 }
1932 else
1933 inhibit_storing = 1;
1934 }
1935
1936 if (!inhibit_storing)
1937 vec[idx] = overlay;
1938 /* Keep counting overlays even if we can't return them all. */
1939 idx++;
1940 }
1941 else if (startpos < next)
1942 next = startpos;
1943 }
1944
1945 for (tail = current_buffer->overlays_after;
1946 GC_CONSP (tail);
1947 tail = XCONS (tail)->cdr)
1948 {
1949 int startpos, endpos;
1950
1951 overlay = XCONS (tail)->car;
1952
1953 ostart = OVERLAY_START (overlay);
1954 oend = OVERLAY_END (overlay);
1955 startpos = OVERLAY_POSITION (ostart);
1956 if (end < startpos)
1957 {
1958 if (startpos < next)
1959 next = startpos;
1960 break;
1961 }
1962 endpos = OVERLAY_POSITION (oend);
1963 /* Count an interval if it either overlaps the range
1964 or is empty at the start of the range. */
1965 if ((beg < endpos && startpos < end)
1966 || (startpos == endpos && beg == endpos))
1967 {
1968 if (idx == len)
1969 {
1970 if (extend)
1971 {
1972 *len_ptr = len *= 2;
1973 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
1974 *vec_ptr = vec;
1975 }
1976 else
1977 inhibit_storing = 1;
1978 }
1979
1980 if (!inhibit_storing)
1981 vec[idx] = overlay;
1982 idx++;
1983 }
1984 else if (endpos < beg && endpos > prev)
1985 prev = endpos;
1986 }
1987
1988 if (next_ptr)
1989 *next_ptr = next;
1990 if (prev_ptr)
1991 *prev_ptr = prev;
1992 return idx;
1993 }
1994 \f
1995 /* Fast function to just test if we're at an overlay boundary. */
1996 int
1997 overlay_touches_p (pos)
1998 int pos;
1999 {
2000 Lisp_Object tail, overlay;
2001
2002 for (tail = current_buffer->overlays_before; GC_CONSP (tail);
2003 tail = XCONS (tail)->cdr)
2004 {
2005 int endpos;
2006
2007 overlay = XCONS (tail)->car;
2008 if (!GC_OVERLAYP (overlay))
2009 abort ();
2010
2011 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2012 if (endpos < pos)
2013 break;
2014 if (endpos == pos || OVERLAY_POSITION (OVERLAY_START (overlay)) == pos)
2015 return 1;
2016 }
2017
2018 for (tail = current_buffer->overlays_after; GC_CONSP (tail);
2019 tail = XCONS (tail)->cdr)
2020 {
2021 int startpos;
2022
2023 overlay = XCONS (tail)->car;
2024 if (!GC_OVERLAYP (overlay))
2025 abort ();
2026
2027 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2028 if (pos < startpos)
2029 break;
2030 if (startpos == pos || OVERLAY_POSITION (OVERLAY_END (overlay)) == pos)
2031 return 1;
2032 }
2033 return 0;
2034 }
2035 \f
2036 struct sortvec
2037 {
2038 Lisp_Object overlay;
2039 int beg, end;
2040 int priority;
2041 };
2042
2043 static int
2044 compare_overlays (s1, s2)
2045 struct sortvec *s1, *s2;
2046 {
2047 if (s1->priority != s2->priority)
2048 return s1->priority - s2->priority;
2049 if (s1->beg != s2->beg)
2050 return s1->beg - s2->beg;
2051 if (s1->end != s2->end)
2052 return s2->end - s1->end;
2053 return 0;
2054 }
2055
2056 /* Sort an array of overlays by priority. The array is modified in place.
2057 The return value is the new size; this may be smaller than the original
2058 size if some of the overlays were invalid or were window-specific. */
2059 int
2060 sort_overlays (overlay_vec, noverlays, w)
2061 Lisp_Object *overlay_vec;
2062 int noverlays;
2063 struct window *w;
2064 {
2065 int i, j;
2066 struct sortvec *sortvec;
2067 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
2068
2069 /* Put the valid and relevant overlays into sortvec. */
2070
2071 for (i = 0, j = 0; i < noverlays; i++)
2072 {
2073 Lisp_Object tem;
2074 Lisp_Object overlay;
2075
2076 overlay = overlay_vec[i];
2077 if (OVERLAY_VALID (overlay)
2078 && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0
2079 && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0)
2080 {
2081 /* If we're interested in a specific window, then ignore
2082 overlays that are limited to some other window. */
2083 if (w)
2084 {
2085 Lisp_Object window;
2086
2087 window = Foverlay_get (overlay, Qwindow);
2088 if (WINDOWP (window) && XWINDOW (window) != w)
2089 continue;
2090 }
2091
2092 /* This overlay is good and counts: put it into sortvec. */
2093 sortvec[j].overlay = overlay;
2094 sortvec[j].beg = OVERLAY_POSITION (OVERLAY_START (overlay));
2095 sortvec[j].end = OVERLAY_POSITION (OVERLAY_END (overlay));
2096 tem = Foverlay_get (overlay, Qpriority);
2097 if (INTEGERP (tem))
2098 sortvec[j].priority = XINT (tem);
2099 else
2100 sortvec[j].priority = 0;
2101 j++;
2102 }
2103 }
2104 noverlays = j;
2105
2106 /* Sort the overlays into the proper order: increasing priority. */
2107
2108 if (noverlays > 1)
2109 qsort (sortvec, noverlays, sizeof (struct sortvec), compare_overlays);
2110
2111 for (i = 0; i < noverlays; i++)
2112 overlay_vec[i] = sortvec[i].overlay;
2113 return (noverlays);
2114 }
2115 \f
2116 struct sortstr
2117 {
2118 Lisp_Object string, string2;
2119 int size;
2120 int priority;
2121 };
2122
2123 struct sortstrlist
2124 {
2125 struct sortstr *buf; /* An array that expands as needed; never freed. */
2126 int size; /* Allocated length of that array. */
2127 int used; /* How much of the array is currently in use. */
2128 int bytes; /* Total length of the strings in buf. */
2129 };
2130
2131 /* Buffers for storing information about the overlays touching a given
2132 position. These could be automatic variables in overlay_strings, but
2133 it's more efficient to hold onto the memory instead of repeatedly
2134 allocating and freeing it. */
2135 static struct sortstrlist overlay_heads, overlay_tails;
2136 static unsigned char *overlay_str_buf;
2137
2138 /* Allocated length of overlay_str_buf. */
2139 static int overlay_str_len;
2140
2141 /* A comparison function suitable for passing to qsort. */
2142 static int
2143 cmp_for_strings (as1, as2)
2144 char *as1, *as2;
2145 {
2146 struct sortstr *s1 = (struct sortstr *)as1;
2147 struct sortstr *s2 = (struct sortstr *)as2;
2148 if (s1->size != s2->size)
2149 return s2->size - s1->size;
2150 if (s1->priority != s2->priority)
2151 return s1->priority - s2->priority;
2152 return 0;
2153 }
2154
2155 static void
2156 record_overlay_string (ssl, str, str2, pri, size)
2157 struct sortstrlist *ssl;
2158 Lisp_Object str, str2, pri;
2159 int size;
2160 {
2161 if (ssl->used == ssl->size)
2162 {
2163 if (ssl->buf)
2164 ssl->size *= 2;
2165 else
2166 ssl->size = 5;
2167 ssl->buf = ((struct sortstr *)
2168 xrealloc (ssl->buf, ssl->size * sizeof (struct sortstr)));
2169 }
2170 ssl->buf[ssl->used].string = str;
2171 ssl->buf[ssl->used].string2 = str2;
2172 ssl->buf[ssl->used].size = size;
2173 ssl->buf[ssl->used].priority = (INTEGERP (pri) ? XINT (pri) : 0);
2174 ssl->used++;
2175 ssl->bytes += XSTRING (str)->size;
2176 if (STRINGP (str2))
2177 ssl->bytes += XSTRING (str2)->size;
2178 }
2179
2180 /* Return the concatenation of the strings associated with overlays that
2181 begin or end at POS, ignoring overlays that are specific to a window
2182 other than W. The strings are concatenated in the appropriate order:
2183 shorter overlays nest inside longer ones, and higher priority inside
2184 lower. Normally all of the after-strings come first, but zero-sized
2185 overlays have their after-strings ride along with the before-strings
2186 because it would look strange to print them inside-out.
2187
2188 Returns the string length, and stores the contents indirectly through
2189 PSTR, if that variable is non-null. The string may be overwritten by
2190 subsequent calls. */
2191
2192 int
2193 overlay_strings (pos, w, pstr)
2194 int pos;
2195 struct window *w;
2196 unsigned char **pstr;
2197 {
2198 Lisp_Object ov, overlay, window, str;
2199 int startpos, endpos;
2200
2201 overlay_heads.used = overlay_heads.bytes = 0;
2202 overlay_tails.used = overlay_tails.bytes = 0;
2203 for (ov = current_buffer->overlays_before; CONSP (ov); ov = XCONS (ov)->cdr)
2204 {
2205 overlay = XCONS (ov)->car;
2206 if (!OVERLAYP (overlay))
2207 abort ();
2208
2209 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2210 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2211 if (endpos < pos)
2212 break;
2213 if (endpos != pos && startpos != pos)
2214 continue;
2215 window = Foverlay_get (overlay, Qwindow);
2216 if (WINDOWP (window) && XWINDOW (window) != w)
2217 continue;
2218 if (startpos == pos
2219 && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)))
2220 record_overlay_string (&overlay_heads, str,
2221 (startpos == endpos
2222 ? Foverlay_get (overlay, Qafter_string)
2223 : Qnil),
2224 Foverlay_get (overlay, Qpriority),
2225 endpos - startpos);
2226 else if (endpos == pos
2227 && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)))
2228 record_overlay_string (&overlay_tails, str, Qnil,
2229 Foverlay_get (overlay, Qpriority),
2230 endpos - startpos);
2231 }
2232 for (ov = current_buffer->overlays_after; CONSP (ov); ov = XCONS (ov)->cdr)
2233 {
2234 overlay = XCONS (ov)->car;
2235 if (!OVERLAYP (overlay))
2236 abort ();
2237
2238 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2239 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2240 if (startpos > pos)
2241 break;
2242 if (endpos != pos && startpos != pos)
2243 continue;
2244 window = Foverlay_get (overlay, Qwindow);
2245 if (WINDOWP (window) && XWINDOW (window) != w)
2246 continue;
2247 if (startpos == pos
2248 && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)))
2249 record_overlay_string (&overlay_heads, str,
2250 (startpos == endpos
2251 ? Foverlay_get (overlay, Qafter_string)
2252 : Qnil),
2253 Foverlay_get (overlay, Qpriority),
2254 endpos - startpos);
2255 else if (endpos == pos
2256 && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)))
2257 record_overlay_string (&overlay_tails, str, Qnil,
2258 Foverlay_get (overlay, Qpriority),
2259 endpos - startpos);
2260 }
2261 if (overlay_tails.used > 1)
2262 qsort (overlay_tails.buf, overlay_tails.used, sizeof (struct sortstr),
2263 cmp_for_strings);
2264 if (overlay_heads.used > 1)
2265 qsort (overlay_heads.buf, overlay_heads.used, sizeof (struct sortstr),
2266 cmp_for_strings);
2267 if (overlay_heads.bytes || overlay_tails.bytes)
2268 {
2269 Lisp_Object tem;
2270 int i;
2271 unsigned char *p;
2272 int total = overlay_heads.bytes + overlay_tails.bytes;
2273
2274 if (total > overlay_str_len)
2275 {
2276 overlay_str_len = total;
2277 overlay_str_buf = (unsigned char *)xrealloc (overlay_str_buf,
2278 total);
2279 }
2280 p = overlay_str_buf;
2281 for (i = overlay_tails.used; --i >= 0;)
2282 {
2283 tem = overlay_tails.buf[i].string;
2284 bcopy (XSTRING (tem)->data, p, XSTRING (tem)->size);
2285 p += XSTRING (tem)->size;
2286 }
2287 for (i = 0; i < overlay_heads.used; ++i)
2288 {
2289 tem = overlay_heads.buf[i].string;
2290 bcopy (XSTRING (tem)->data, p, XSTRING (tem)->size);
2291 p += XSTRING (tem)->size;
2292 tem = overlay_heads.buf[i].string2;
2293 if (STRINGP (tem))
2294 {
2295 bcopy (XSTRING (tem)->data, p, XSTRING (tem)->size);
2296 p += XSTRING (tem)->size;
2297 }
2298 }
2299 if (p != overlay_str_buf + total)
2300 abort ();
2301 if (pstr)
2302 *pstr = overlay_str_buf;
2303 return total;
2304 }
2305 return 0;
2306 }
2307 \f
2308 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2309
2310 void
2311 recenter_overlay_lists (buf, pos)
2312 struct buffer *buf;
2313 int pos;
2314 {
2315 Lisp_Object overlay, tail, next, prev, beg, end;
2316
2317 /* See if anything in overlays_before should move to overlays_after. */
2318
2319 /* We don't strictly need prev in this loop; it should always be nil.
2320 But we use it for symmetry and in case that should cease to be true
2321 with some future change. */
2322 prev = Qnil;
2323 for (tail = buf->overlays_before;
2324 CONSP (tail);
2325 prev = tail, tail = next)
2326 {
2327 next = XCONS (tail)->cdr;
2328 overlay = XCONS (tail)->car;
2329
2330 /* If the overlay is not valid, get rid of it. */
2331 if (!OVERLAY_VALID (overlay))
2332 #if 1
2333 abort ();
2334 #else
2335 {
2336 /* Splice the cons cell TAIL out of overlays_before. */
2337 if (!NILP (prev))
2338 XCONS (prev)->cdr = next;
2339 else
2340 buf->overlays_before = next;
2341 tail = prev;
2342 continue;
2343 }
2344 #endif
2345
2346 beg = OVERLAY_START (overlay);
2347 end = OVERLAY_END (overlay);
2348
2349 if (OVERLAY_POSITION (end) > pos)
2350 {
2351 /* OVERLAY needs to be moved. */
2352 int where = OVERLAY_POSITION (beg);
2353 Lisp_Object other, other_prev;
2354
2355 /* Splice the cons cell TAIL out of overlays_before. */
2356 if (!NILP (prev))
2357 XCONS (prev)->cdr = next;
2358 else
2359 buf->overlays_before = next;
2360
2361 /* Search thru overlays_after for where to put it. */
2362 other_prev = Qnil;
2363 for (other = buf->overlays_after;
2364 CONSP (other);
2365 other_prev = other, other = XCONS (other)->cdr)
2366 {
2367 Lisp_Object otherbeg, otheroverlay, follower;
2368 int win;
2369
2370 otheroverlay = XCONS (other)->car;
2371 if (! OVERLAY_VALID (otheroverlay))
2372 abort ();
2373
2374 otherbeg = OVERLAY_START (otheroverlay);
2375 if (OVERLAY_POSITION (otherbeg) >= where)
2376 break;
2377 }
2378
2379 /* Add TAIL to overlays_after before OTHER. */
2380 XCONS (tail)->cdr = other;
2381 if (!NILP (other_prev))
2382 XCONS (other_prev)->cdr = tail;
2383 else
2384 buf->overlays_after = tail;
2385 tail = prev;
2386 }
2387 else
2388 /* We've reached the things that should stay in overlays_before.
2389 All the rest of overlays_before must end even earlier,
2390 so stop now. */
2391 break;
2392 }
2393
2394 /* See if anything in overlays_after should be in overlays_before. */
2395 prev = Qnil;
2396 for (tail = buf->overlays_after;
2397 CONSP (tail);
2398 prev = tail, tail = next)
2399 {
2400 next = XCONS (tail)->cdr;
2401 overlay = XCONS (tail)->car;
2402
2403 /* If the overlay is not valid, get rid of it. */
2404 if (!OVERLAY_VALID (overlay))
2405 #if 1
2406 abort ();
2407 #else
2408 {
2409 /* Splice the cons cell TAIL out of overlays_after. */
2410 if (!NILP (prev))
2411 XCONS (prev)->cdr = next;
2412 else
2413 buf->overlays_after = next;
2414 tail = prev;
2415 continue;
2416 }
2417 #endif
2418
2419 beg = OVERLAY_START (overlay);
2420 end = OVERLAY_END (overlay);
2421
2422 /* Stop looking, when we know that nothing further
2423 can possibly end before POS. */
2424 if (OVERLAY_POSITION (beg) > pos)
2425 break;
2426
2427 if (OVERLAY_POSITION (end) <= pos)
2428 {
2429 /* OVERLAY needs to be moved. */
2430 int where = OVERLAY_POSITION (end);
2431 Lisp_Object other, other_prev;
2432
2433 /* Splice the cons cell TAIL out of overlays_after. */
2434 if (!NILP (prev))
2435 XCONS (prev)->cdr = next;
2436 else
2437 buf->overlays_after = next;
2438
2439 /* Search thru overlays_before for where to put it. */
2440 other_prev = Qnil;
2441 for (other = buf->overlays_before;
2442 CONSP (other);
2443 other_prev = other, other = XCONS (other)->cdr)
2444 {
2445 Lisp_Object otherend, otheroverlay;
2446 int win;
2447
2448 otheroverlay = XCONS (other)->car;
2449 if (! OVERLAY_VALID (otheroverlay))
2450 abort ();
2451
2452 otherend = OVERLAY_END (otheroverlay);
2453 if (OVERLAY_POSITION (otherend) <= where)
2454 break;
2455 }
2456
2457 /* Add TAIL to overlays_before before OTHER. */
2458 XCONS (tail)->cdr = other;
2459 if (!NILP (other_prev))
2460 XCONS (other_prev)->cdr = tail;
2461 else
2462 buf->overlays_before = tail;
2463 tail = prev;
2464 }
2465 }
2466
2467 XSETFASTINT (buf->overlay_center, pos);
2468 }
2469
2470 void
2471 adjust_overlays_for_insert (pos, length)
2472 int pos;
2473 int length;
2474 {
2475 /* After an insertion, the lists are still sorted properly,
2476 but we may need to update the value of the overlay center. */
2477 if (XFASTINT (current_buffer->overlay_center) >= pos)
2478 XSETFASTINT (current_buffer->overlay_center,
2479 XFASTINT (current_buffer->overlay_center) + length);
2480 }
2481
2482 void
2483 adjust_overlays_for_delete (pos, length)
2484 int pos;
2485 int length;
2486 {
2487 if (XFASTINT (current_buffer->overlay_center) < pos)
2488 /* The deletion was to our right. No change needed; the before- and
2489 after-lists are still consistent. */
2490 ;
2491 else if (XFASTINT (current_buffer->overlay_center) > pos + length)
2492 /* The deletion was to our left. We need to adjust the center value
2493 to account for the change in position, but the lists are consistent
2494 given the new value. */
2495 XSETFASTINT (current_buffer->overlay_center,
2496 XFASTINT (current_buffer->overlay_center) - length);
2497 else
2498 /* We're right in the middle. There might be things on the after-list
2499 that now belong on the before-list. Recentering will move them,
2500 and also update the center point. */
2501 recenter_overlay_lists (current_buffer, pos);
2502 }
2503
2504 /* Fix up overlays that were garbled as a result of permuting markers
2505 in the range START through END. Any overlay with at least one
2506 endpoint in this range will need to be unlinked from the overlay
2507 list and reinserted in its proper place.
2508 Such an overlay might even have negative size at this point.
2509 If so, we'll reverse the endpoints. Can you think of anything
2510 better to do in this situation? */
2511 void
2512 fix_overlays_in_range (start, end)
2513 register int start, end;
2514 {
2515 Lisp_Object tem, overlay;
2516 Lisp_Object before_list, after_list;
2517 Lisp_Object *ptail, *pbefore = &before_list, *pafter = &after_list;
2518 int startpos, endpos;
2519
2520 /* This algorithm shifts links around instead of consing and GCing.
2521 The loop invariant is that before_list (resp. after_list) is a
2522 well-formed list except that its last element, the one that
2523 *pbefore (resp. *pafter) points to, is still uninitialized.
2524 So it's not a bug that before_list isn't initialized, although
2525 it may look strange. */
2526 for (ptail = &current_buffer->overlays_before; CONSP (*ptail);)
2527 {
2528 overlay = XCONS (*ptail)->car;
2529 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2530 if (endpos < start)
2531 break;
2532 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2533 if (endpos < end
2534 || (startpos >= start && startpos < end))
2535 {
2536 /* If the overlay is backwards, fix that now. */
2537 if (startpos > endpos)
2538 {
2539 int tem;
2540 Fset_marker (OVERLAY_START (overlay), make_number (endpos),
2541 Qnil);
2542 Fset_marker (OVERLAY_END (overlay), make_number (startpos),
2543 Qnil);
2544 tem = startpos; startpos = endpos; endpos = tem;
2545 }
2546 /* Add it to the end of the wrong list. Later on,
2547 recenter_overlay_lists will move it to the right place. */
2548 if (endpos < XINT (current_buffer->overlay_center))
2549 {
2550 *pafter = *ptail;
2551 pafter = &XCONS (*ptail)->cdr;
2552 }
2553 else
2554 {
2555 *pbefore = *ptail;
2556 pbefore = &XCONS (*ptail)->cdr;
2557 }
2558 *ptail = XCONS (*ptail)->cdr;
2559 }
2560 else
2561 ptail = &XCONS (*ptail)->cdr;
2562 }
2563 for (ptail = &current_buffer->overlays_after; CONSP (*ptail);)
2564 {
2565 overlay = XCONS (*ptail)->car;
2566 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2567 if (startpos >= end)
2568 break;
2569 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2570 if (startpos >= start
2571 || (endpos >= start && endpos < end))
2572 {
2573 if (startpos > endpos)
2574 {
2575 int tem;
2576 Fset_marker (OVERLAY_START (overlay), make_number (endpos),
2577 Qnil);
2578 Fset_marker (OVERLAY_END (overlay), make_number (startpos),
2579 Qnil);
2580 tem = startpos; startpos = endpos; endpos = tem;
2581 }
2582 if (endpos < XINT (current_buffer->overlay_center))
2583 {
2584 *pafter = *ptail;
2585 pafter = &XCONS (*ptail)->cdr;
2586 }
2587 else
2588 {
2589 *pbefore = *ptail;
2590 pbefore = &XCONS (*ptail)->cdr;
2591 }
2592 *ptail = XCONS (*ptail)->cdr;
2593 }
2594 else
2595 ptail = &XCONS (*ptail)->cdr;
2596 }
2597
2598 /* Splice the constructed (wrong) lists into the buffer's lists,
2599 and let the recenter function make it sane again. */
2600 *pbefore = current_buffer->overlays_before;
2601 current_buffer->overlays_before = before_list;
2602 recenter_overlay_lists (current_buffer,
2603 XINT (current_buffer->overlay_center));
2604
2605 *pafter = current_buffer->overlays_after;
2606 current_buffer->overlays_after = after_list;
2607 recenter_overlay_lists (current_buffer,
2608 XINT (current_buffer->overlay_center));
2609 }
2610
2611 /* We have two types of overlay: the one whose ending marker is
2612 after-insertion-marker (this is the usual case) and the one whose
2613 ending marker is before-insertion-marker. When `overlays_before'
2614 contains overlays of the latter type and the former type in this
2615 order and both overlays end at inserting position, inserting a text
2616 increases only the ending marker of the latter type, which results
2617 in incorrect ordering of `overlays_before'.
2618
2619 This function fixes ordering of overlays in the slot
2620 `overlays_before' of the buffer *BP. Before the insertion, `point'
2621 was at PREV, and now is at POS. */
2622
2623 void
2624 fix_overlays_before (bp, prev, pos)
2625 struct buffer *bp;
2626 int prev, pos;
2627 {
2628 Lisp_Object *tailp = &bp->overlays_before;
2629 Lisp_Object *right_place;
2630 int end;
2631
2632 /* After the insertion, the several overlays may be in incorrect
2633 order. The possibility is that, in the list `overlays_before',
2634 an overlay which ends at POS appears after an overlay which ends
2635 at PREV. Since POS is greater than PREV, we must fix the
2636 ordering of these overlays, by moving overlays ends at POS before
2637 the overlays ends at PREV. */
2638
2639 /* At first, find a place where disordered overlays should be linked
2640 in. It is where an overlay which end before POS exists. (i.e. an
2641 overlay whose ending marker is after-insertion-marker if disorder
2642 exists). */
2643 while (!NILP (*tailp)
2644 && ((end = OVERLAY_POSITION (OVERLAY_END (XCONS (*tailp)->car)))
2645 >= pos))
2646 tailp = &XCONS (*tailp)->cdr;
2647
2648 /* If we don't find such an overlay,
2649 or the found one ends before PREV,
2650 or the found one is the last one in the list,
2651 we don't have to fix anything. */
2652 if (NILP (*tailp)
2653 || end < prev
2654 || NILP (XCONS (*tailp)->cdr))
2655 return;
2656
2657 right_place = tailp;
2658 tailp = &XCONS (*tailp)->cdr;
2659
2660 /* Now, end position of overlays in the list *TAILP should be before
2661 or equal to PREV. In the loop, an overlay which ends at POS is
2662 moved ahead to the place pointed by RIGHT_PLACE. If we found an
2663 overlay which ends before PREV, the remaining overlays are in
2664 correct order. */
2665 while (!NILP (*tailp))
2666 {
2667 end = OVERLAY_POSITION (OVERLAY_END (XCONS (*tailp)->car));
2668
2669 if (end == pos)
2670 { /* This overlay is disordered. */
2671 Lisp_Object found = *tailp;
2672
2673 /* Unlink the found overlay. */
2674 *tailp = XCONS (found)->cdr;
2675 /* Move an overlay at RIGHT_PLACE to the next of the found one. */
2676 XCONS (found)->cdr = *right_place;
2677 /* Link it into the right place. */
2678 *right_place = found;
2679 }
2680 else if (end == prev)
2681 tailp = &XCONS (*tailp)->cdr;
2682 else /* No more disordered overlay. */
2683 break;
2684 }
2685 }
2686 \f
2687 DEFUN ("overlayp", Foverlayp, Soverlayp, 1, 1, 0,
2688 "Return t if OBJECT is an overlay.")
2689 (object)
2690 Lisp_Object object;
2691 {
2692 return (OVERLAYP (object) ? Qt : Qnil);
2693 }
2694
2695 DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 5, 0,
2696 "Create a new overlay with range BEG to END in BUFFER.\n\
2697 If omitted, BUFFER defaults to the current buffer.\n\
2698 BEG and END may be integers or markers.\n\
2699 The fourth arg FRONT-ADVANCE, if non-nil, makes the\n\
2700 front delimiter advance when text is inserted there.\n\
2701 The fifth arg REAR-ADVANCE, if non-nil, makes the\n\
2702 rear delimiter advance when text is inserted there.")
2703 (beg, end, buffer, front_advance, rear_advance)
2704 Lisp_Object beg, end, buffer;
2705 Lisp_Object front_advance, rear_advance;
2706 {
2707 Lisp_Object overlay;
2708 struct buffer *b;
2709
2710 if (NILP (buffer))
2711 XSETBUFFER (buffer, current_buffer);
2712 else
2713 CHECK_BUFFER (buffer, 2);
2714 if (MARKERP (beg)
2715 && ! EQ (Fmarker_buffer (beg), buffer))
2716 error ("Marker points into wrong buffer");
2717 if (MARKERP (end)
2718 && ! EQ (Fmarker_buffer (end), buffer))
2719 error ("Marker points into wrong buffer");
2720
2721 CHECK_NUMBER_COERCE_MARKER (beg, 1);
2722 CHECK_NUMBER_COERCE_MARKER (end, 1);
2723
2724 if (XINT (beg) > XINT (end))
2725 {
2726 Lisp_Object temp;
2727 temp = beg; beg = end; end = temp;
2728 }
2729
2730 b = XBUFFER (buffer);
2731
2732 beg = Fset_marker (Fmake_marker (), beg, buffer);
2733 end = Fset_marker (Fmake_marker (), end, buffer);
2734
2735 if (!NILP (front_advance))
2736 XMARKER (beg)->insertion_type = 1;
2737 if (!NILP (rear_advance))
2738 XMARKER (end)->insertion_type = 1;
2739
2740 overlay = allocate_misc ();
2741 XMISCTYPE (overlay) = Lisp_Misc_Overlay;
2742 XOVERLAY (overlay)->start = beg;
2743 XOVERLAY (overlay)->end = end;
2744 XOVERLAY (overlay)->plist = Qnil;
2745
2746 /* Put the new overlay on the wrong list. */
2747 end = OVERLAY_END (overlay);
2748 if (OVERLAY_POSITION (end) < XINT (b->overlay_center))
2749 b->overlays_after = Fcons (overlay, b->overlays_after);
2750 else
2751 b->overlays_before = Fcons (overlay, b->overlays_before);
2752
2753 /* This puts it in the right list, and in the right order. */
2754 recenter_overlay_lists (b, XINT (b->overlay_center));
2755
2756 /* We don't need to redisplay the region covered by the overlay, because
2757 the overlay has no properties at the moment. */
2758
2759 return overlay;
2760 }
2761 \f
2762 /* Mark a section of BUF as needing redisplay because of overlays changes. */
2763
2764 static void
2765 modify_overlay (buf, start, end)
2766 struct buffer *buf;
2767 int start, end;
2768 {
2769 if (start == end)
2770 return;
2771
2772 if (start > end)
2773 {
2774 int temp = start;
2775 start = end; end = temp;
2776 }
2777
2778 /* If this is a buffer not in the selected window,
2779 we must do other windows. */
2780 if (buf != XBUFFER (XWINDOW (selected_window)->buffer))
2781 windows_or_buffers_changed = 1;
2782 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2783 else if (buf != current_buffer)
2784 windows_or_buffers_changed = 1;
2785 /* If multiple windows show this buffer, we must do other windows. */
2786 else if (buffer_shared > 1)
2787 windows_or_buffers_changed = 1;
2788 else
2789 {
2790 if (unchanged_modified == MODIFF
2791 && overlay_unchanged_modified == OVERLAY_MODIFF)
2792 {
2793 beg_unchanged = start - BEG;
2794 end_unchanged = Z - end;
2795 }
2796 else
2797 {
2798 if (Z - end < end_unchanged)
2799 end_unchanged = Z - end;
2800 if (start - BEG < beg_unchanged)
2801 beg_unchanged = start - BEG;
2802 }
2803 }
2804
2805 ++BUF_OVERLAY_MODIFF (buf);
2806 }
2807
2808 \f\f
2809 Lisp_Object Fdelete_overlay ();
2810
2811 DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0,
2812 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
2813 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
2814 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
2815 buffer.")
2816 (overlay, beg, end, buffer)
2817 Lisp_Object overlay, beg, end, buffer;
2818 {
2819 struct buffer *b, *ob;
2820 Lisp_Object obuffer;
2821 int count = specpdl_ptr - specpdl;
2822
2823 CHECK_OVERLAY (overlay, 0);
2824 if (NILP (buffer))
2825 buffer = Fmarker_buffer (OVERLAY_START (overlay));
2826 if (NILP (buffer))
2827 XSETBUFFER (buffer, current_buffer);
2828 CHECK_BUFFER (buffer, 3);
2829
2830 if (MARKERP (beg)
2831 && ! EQ (Fmarker_buffer (beg), buffer))
2832 error ("Marker points into wrong buffer");
2833 if (MARKERP (end)
2834 && ! EQ (Fmarker_buffer (end), buffer))
2835 error ("Marker points into wrong buffer");
2836
2837 CHECK_NUMBER_COERCE_MARKER (beg, 1);
2838 CHECK_NUMBER_COERCE_MARKER (end, 1);
2839
2840 if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
2841 return Fdelete_overlay (overlay);
2842
2843 if (XINT (beg) > XINT (end))
2844 {
2845 Lisp_Object temp;
2846 temp = beg; beg = end; end = temp;
2847 }
2848
2849 specbind (Qinhibit_quit, Qt);
2850
2851 obuffer = Fmarker_buffer (OVERLAY_START (overlay));
2852 b = XBUFFER (buffer);
2853 ob = XBUFFER (obuffer);
2854
2855 /* If the overlay has changed buffers, do a thorough redisplay. */
2856 if (!EQ (buffer, obuffer))
2857 {
2858 /* Redisplay where the overlay was. */
2859 if (!NILP (obuffer))
2860 {
2861 int o_beg;
2862 int o_end;
2863
2864 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
2865 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
2866
2867 modify_overlay (ob, o_beg, o_end);
2868 }
2869
2870 /* Redisplay where the overlay is going to be. */
2871 modify_overlay (b, XINT (beg), XINT (end));
2872 }
2873 else
2874 /* Redisplay the area the overlay has just left, or just enclosed. */
2875 {
2876 int o_beg, o_end;
2877 int change_beg, change_end;
2878
2879 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
2880 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
2881
2882 if (o_beg == XINT (beg))
2883 modify_overlay (b, o_end, XINT (end));
2884 else if (o_end == XINT (end))
2885 modify_overlay (b, o_beg, XINT (beg));
2886 else
2887 {
2888 if (XINT (beg) < o_beg) o_beg = XINT (beg);
2889 if (XINT (end) > o_end) o_end = XINT (end);
2890 modify_overlay (b, o_beg, o_end);
2891 }
2892 }
2893
2894 if (!NILP (obuffer))
2895 {
2896 ob->overlays_before = Fdelq (overlay, ob->overlays_before);
2897 ob->overlays_after = Fdelq (overlay, ob->overlays_after);
2898 }
2899
2900 Fset_marker (OVERLAY_START (overlay), beg, buffer);
2901 Fset_marker (OVERLAY_END (overlay), end, buffer);
2902
2903 /* Put the overlay on the wrong list. */
2904 end = OVERLAY_END (overlay);
2905 if (OVERLAY_POSITION (end) < XINT (b->overlay_center))
2906 b->overlays_after = Fcons (overlay, b->overlays_after);
2907 else
2908 b->overlays_before = Fcons (overlay, b->overlays_before);
2909
2910 /* This puts it in the right list, and in the right order. */
2911 recenter_overlay_lists (b, XINT (b->overlay_center));
2912
2913 return unbind_to (count, overlay);
2914 }
2915
2916 DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
2917 "Delete the overlay OVERLAY from its buffer.")
2918 (overlay)
2919 Lisp_Object overlay;
2920 {
2921 Lisp_Object buffer;
2922 struct buffer *b;
2923 int count = specpdl_ptr - specpdl;
2924
2925 CHECK_OVERLAY (overlay, 0);
2926
2927 buffer = Fmarker_buffer (OVERLAY_START (overlay));
2928 if (NILP (buffer))
2929 return Qnil;
2930
2931 b = XBUFFER (buffer);
2932
2933 specbind (Qinhibit_quit, Qt);
2934
2935 b->overlays_before = Fdelq (overlay, b->overlays_before);
2936 b->overlays_after = Fdelq (overlay, b->overlays_after);
2937
2938 modify_overlay (b,
2939 marker_position (OVERLAY_START (overlay)),
2940 marker_position (OVERLAY_END (overlay)));
2941
2942 Fset_marker (OVERLAY_START (overlay), Qnil, Qnil);
2943 Fset_marker (OVERLAY_END (overlay), Qnil, Qnil);
2944
2945 return unbind_to (count, Qnil);
2946 }
2947 \f
2948 /* Overlay dissection functions. */
2949
2950 DEFUN ("overlay-start", Foverlay_start, Soverlay_start, 1, 1, 0,
2951 "Return the position at which OVERLAY starts.")
2952 (overlay)
2953 Lisp_Object overlay;
2954 {
2955 CHECK_OVERLAY (overlay, 0);
2956
2957 return (Fmarker_position (OVERLAY_START (overlay)));
2958 }
2959
2960 DEFUN ("overlay-end", Foverlay_end, Soverlay_end, 1, 1, 0,
2961 "Return the position at which OVERLAY ends.")
2962 (overlay)
2963 Lisp_Object overlay;
2964 {
2965 CHECK_OVERLAY (overlay, 0);
2966
2967 return (Fmarker_position (OVERLAY_END (overlay)));
2968 }
2969
2970 DEFUN ("overlay-buffer", Foverlay_buffer, Soverlay_buffer, 1, 1, 0,
2971 "Return the buffer OVERLAY belongs to.")
2972 (overlay)
2973 Lisp_Object overlay;
2974 {
2975 CHECK_OVERLAY (overlay, 0);
2976
2977 return Fmarker_buffer (OVERLAY_START (overlay));
2978 }
2979
2980 DEFUN ("overlay-properties", Foverlay_properties, Soverlay_properties, 1, 1, 0,
2981 "Return a list of the properties on OVERLAY.\n\
2982 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
2983 OVERLAY.")
2984 (overlay)
2985 Lisp_Object overlay;
2986 {
2987 CHECK_OVERLAY (overlay, 0);
2988
2989 return Fcopy_sequence (XOVERLAY (overlay)->plist);
2990 }
2991
2992 \f
2993 DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
2994 "Return a list of the overlays that contain position POS.")
2995 (pos)
2996 Lisp_Object pos;
2997 {
2998 int noverlays;
2999 Lisp_Object *overlay_vec;
3000 int len;
3001 Lisp_Object result;
3002
3003 CHECK_NUMBER_COERCE_MARKER (pos, 0);
3004
3005 len = 10;
3006 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
3007
3008 /* Put all the overlays we want in a vector in overlay_vec.
3009 Store the length in len. */
3010 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3011 (int *) 0, (int *) 0);
3012
3013 /* Make a list of them all. */
3014 result = Flist (noverlays, overlay_vec);
3015
3016 xfree (overlay_vec);
3017 return result;
3018 }
3019
3020 DEFUN ("overlays-in", Foverlays_in, Soverlays_in, 2, 2, 0,
3021 "Return a list of the overlays that overlap the region BEG ... END.\n\
3022 Overlap means that at least one character is contained within the overlay\n\
3023 and also contained within the specified region.\n\
3024 Empty overlays are included in the result if they are located at BEG\n\
3025 or between BEG and END.")
3026 (beg, end)
3027 Lisp_Object beg, end;
3028 {
3029 int noverlays;
3030 Lisp_Object *overlay_vec;
3031 int len;
3032 Lisp_Object result;
3033
3034 CHECK_NUMBER_COERCE_MARKER (beg, 0);
3035 CHECK_NUMBER_COERCE_MARKER (end, 0);
3036
3037 len = 10;
3038 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
3039
3040 /* Put all the overlays we want in a vector in overlay_vec.
3041 Store the length in len. */
3042 noverlays = overlays_in (XINT (beg), XINT (end), 1, &overlay_vec, &len,
3043 (int *) 0, (int *) 0);
3044
3045 /* Make a list of them all. */
3046 result = Flist (noverlays, overlay_vec);
3047
3048 xfree (overlay_vec);
3049 return result;
3050 }
3051
3052 DEFUN ("next-overlay-change", Fnext_overlay_change, Snext_overlay_change,
3053 1, 1, 0,
3054 "Return the next position after POS where an overlay starts or ends.\n\
3055 If there are no more overlay boundaries after POS, return (point-max).")
3056 (pos)
3057 Lisp_Object pos;
3058 {
3059 int noverlays;
3060 int endpos;
3061 Lisp_Object *overlay_vec;
3062 int len;
3063 int i;
3064
3065 CHECK_NUMBER_COERCE_MARKER (pos, 0);
3066
3067 len = 10;
3068 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
3069
3070 /* Put all the overlays we want in a vector in overlay_vec.
3071 Store the length in len.
3072 endpos gets the position where the next overlay starts. */
3073 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3074 &endpos, (int *) 0);
3075
3076 /* If any of these overlays ends before endpos,
3077 use its ending point instead. */
3078 for (i = 0; i < noverlays; i++)
3079 {
3080 Lisp_Object oend;
3081 int oendpos;
3082
3083 oend = OVERLAY_END (overlay_vec[i]);
3084 oendpos = OVERLAY_POSITION (oend);
3085 if (oendpos < endpos)
3086 endpos = oendpos;
3087 }
3088
3089 xfree (overlay_vec);
3090 return make_number (endpos);
3091 }
3092
3093 DEFUN ("previous-overlay-change", Fprevious_overlay_change,
3094 Sprevious_overlay_change, 1, 1, 0,
3095 "Return the previous position before POS where an overlay starts or ends.\n\
3096 If there are no more overlay boundaries before POS, return (point-min).")
3097 (pos)
3098 Lisp_Object pos;
3099 {
3100 int noverlays;
3101 int prevpos;
3102 Lisp_Object *overlay_vec;
3103 int len;
3104 int i;
3105 Lisp_Object tail;
3106
3107 CHECK_NUMBER_COERCE_MARKER (pos, 0);
3108
3109 len = 10;
3110 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
3111
3112 /* At beginning of buffer, we know the answer;
3113 avoid bug subtracting 1 below. */
3114 if (XINT (pos) == BEGV)
3115 return pos;
3116
3117 /* Put all the overlays we want in a vector in overlay_vec.
3118 Store the length in len.
3119 prevpos gets the position of an overlay end. */
3120 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3121 (int *) 0, &prevpos);
3122
3123 /* If any of these overlays starts after prevpos,
3124 maybe use its starting point instead. */
3125 for (i = 0; i < noverlays; i++)
3126 {
3127 Lisp_Object ostart;
3128 int ostartpos;
3129
3130 ostart = OVERLAY_START (overlay_vec[i]);
3131 ostartpos = OVERLAY_POSITION (ostart);
3132 if (ostartpos > prevpos && ostartpos < XINT (pos))
3133 prevpos = ostartpos;
3134 }
3135
3136 /* If any overlay ends at pos, consider its starting point too. */
3137 for (tail = current_buffer->overlays_before;
3138 GC_CONSP (tail);
3139 tail = XCONS (tail)->cdr)
3140 {
3141 Lisp_Object overlay, ostart;
3142 int ostartpos;
3143
3144 overlay = XCONS (tail)->car;
3145
3146 ostart = OVERLAY_START (overlay);
3147 ostartpos = OVERLAY_POSITION (ostart);
3148 if (ostartpos > prevpos && ostartpos < XINT (pos))
3149 prevpos = ostartpos;
3150 }
3151
3152 xfree (overlay_vec);
3153 return make_number (prevpos);
3154 }
3155 \f
3156 /* These functions are for debugging overlays. */
3157
3158 DEFUN ("overlay-lists", Foverlay_lists, Soverlay_lists, 0, 0, 0,
3159 "Return a pair of lists giving all the overlays of the current buffer.\n\
3160 The car has all the overlays before the overlay center;\n\
3161 the cdr has all the overlays after the overlay center.\n\
3162 Recentering overlays moves overlays between these lists.\n\
3163 The lists you get are copies, so that changing them has no effect.\n\
3164 However, the overlays you get are the real objects that the buffer uses.")
3165 ()
3166 {
3167 Lisp_Object before, after;
3168 before = current_buffer->overlays_before;
3169 if (CONSP (before))
3170 before = Fcopy_sequence (before);
3171 after = current_buffer->overlays_after;
3172 if (CONSP (after))
3173 after = Fcopy_sequence (after);
3174
3175 return Fcons (before, after);
3176 }
3177
3178 DEFUN ("overlay-recenter", Foverlay_recenter, Soverlay_recenter, 1, 1, 0,
3179 "Recenter the overlays of the current buffer around position POS.")
3180 (pos)
3181 Lisp_Object pos;
3182 {
3183 CHECK_NUMBER_COERCE_MARKER (pos, 0);
3184
3185 recenter_overlay_lists (current_buffer, XINT (pos));
3186 return Qnil;
3187 }
3188 \f
3189 DEFUN ("overlay-get", Foverlay_get, Soverlay_get, 2, 2, 0,
3190 "Get the property of overlay OVERLAY with property name PROP.")
3191 (overlay, prop)
3192 Lisp_Object overlay, prop;
3193 {
3194 Lisp_Object plist, fallback;
3195
3196 CHECK_OVERLAY (overlay, 0);
3197
3198 fallback = Qnil;
3199
3200 for (plist = XOVERLAY (overlay)->plist;
3201 CONSP (plist) && CONSP (XCONS (plist)->cdr);
3202 plist = XCONS (XCONS (plist)->cdr)->cdr)
3203 {
3204 if (EQ (XCONS (plist)->car, prop))
3205 return XCONS (XCONS (plist)->cdr)->car;
3206 else if (EQ (XCONS (plist)->car, Qcategory))
3207 {
3208 Lisp_Object tem;
3209 tem = Fcar (Fcdr (plist));
3210 if (SYMBOLP (tem))
3211 fallback = Fget (tem, prop);
3212 }
3213 }
3214
3215 return fallback;
3216 }
3217
3218 DEFUN ("overlay-put", Foverlay_put, Soverlay_put, 3, 3, 0,
3219 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
3220 (overlay, prop, value)
3221 Lisp_Object overlay, prop, value;
3222 {
3223 Lisp_Object tail, buffer;
3224 int changed;
3225
3226 CHECK_OVERLAY (overlay, 0);
3227
3228 buffer = Fmarker_buffer (OVERLAY_START (overlay));
3229
3230 for (tail = XOVERLAY (overlay)->plist;
3231 CONSP (tail) && CONSP (XCONS (tail)->cdr);
3232 tail = XCONS (XCONS (tail)->cdr)->cdr)
3233 if (EQ (XCONS (tail)->car, prop))
3234 {
3235 changed = !EQ (XCONS (XCONS (tail)->cdr)->car, value);
3236 XCONS (XCONS (tail)->cdr)->car = value;
3237 goto found;
3238 }
3239 /* It wasn't in the list, so add it to the front. */
3240 changed = !NILP (value);
3241 XOVERLAY (overlay)->plist
3242 = Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist));
3243 found:
3244 if (! NILP (buffer))
3245 {
3246 if (changed)
3247 modify_overlay (XBUFFER (buffer),
3248 marker_position (OVERLAY_START (overlay)),
3249 marker_position (OVERLAY_END (overlay)));
3250 if (EQ (prop, Qevaporate) && ! NILP (value)
3251 && (OVERLAY_POSITION (OVERLAY_START (overlay))
3252 == OVERLAY_POSITION (OVERLAY_END (overlay))))
3253 Fdelete_overlay (overlay);
3254 }
3255 return value;
3256 }
3257 \f
3258 /* Subroutine of report_overlay_modification. */
3259
3260 /* Lisp vector holding overlay hook functions to call.
3261 Vector elements come in pairs.
3262 Each even-index element is a list of hook functions.
3263 The following odd-index element is the overlay they came from.
3264
3265 Before the buffer change, we fill in this vector
3266 as we call overlay hook functions.
3267 After the buffer change, we get the functions to call from this vector.
3268 This way we always call the same functions before and after the change. */
3269 static Lisp_Object last_overlay_modification_hooks;
3270
3271 /* Number of elements actually used in last_overlay_modification_hooks. */
3272 static int last_overlay_modification_hooks_used;
3273
3274 /* Add one functionlist/overlay pair
3275 to the end of last_overlay_modification_hooks. */
3276
3277 static void
3278 add_overlay_mod_hooklist (functionlist, overlay)
3279 Lisp_Object functionlist, overlay;
3280 {
3281 int oldsize = XVECTOR (last_overlay_modification_hooks)->size;
3282
3283 if (last_overlay_modification_hooks_used == oldsize)
3284 {
3285 Lisp_Object old;
3286 old = last_overlay_modification_hooks;
3287 last_overlay_modification_hooks
3288 = Fmake_vector (make_number (oldsize * 2), Qnil);
3289 bcopy (XVECTOR (old)->contents,
3290 XVECTOR (last_overlay_modification_hooks)->contents,
3291 sizeof (Lisp_Object) * oldsize);
3292 }
3293 XVECTOR (last_overlay_modification_hooks)->contents[last_overlay_modification_hooks_used++] = functionlist;
3294 XVECTOR (last_overlay_modification_hooks)->contents[last_overlay_modification_hooks_used++] = overlay;
3295 }
3296 \f
3297 /* Run the modification-hooks of overlays that include
3298 any part of the text in START to END.
3299 If this change is an insertion, also
3300 run the insert-before-hooks of overlay starting at END,
3301 and the insert-after-hooks of overlay ending at START.
3302
3303 This is called both before and after the modification.
3304 AFTER is nonzero when we call after the modification.
3305
3306 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3307 When AFTER is nonzero, they are the start position,
3308 the position after the inserted new text,
3309 and the length of deleted or replaced old text. */
3310
3311 void
3312 report_overlay_modification (start, end, after, arg1, arg2, arg3)
3313 Lisp_Object start, end;
3314 int after;
3315 Lisp_Object arg1, arg2, arg3;
3316 {
3317 Lisp_Object prop, overlay, tail;
3318 /* 1 if this change is an insertion. */
3319 int insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end));
3320 int tail_copied;
3321 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3322
3323 overlay = Qnil;
3324 tail = Qnil;
3325 GCPRO5 (overlay, tail, arg1, arg2, arg3);
3326
3327 if (after)
3328 {
3329 /* Call the functions recorded in last_overlay_modification_hooks
3330 rather than scanning the overlays again.
3331 First copy the vector contents, in case some of these hooks
3332 do subsequent modification of the buffer. */
3333 int size = last_overlay_modification_hooks_used;
3334 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object));
3335 int i;
3336
3337 bcopy (XVECTOR (last_overlay_modification_hooks)->contents,
3338 copy, size * sizeof (Lisp_Object));
3339 gcpro1.var = copy;
3340 gcpro1.nvars = size;
3341
3342 for (i = 0; i < size;)
3343 {
3344 Lisp_Object prop, overlay;
3345 prop = copy[i++];
3346 overlay = copy[i++];
3347 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
3348 }
3349 UNGCPRO;
3350 return;
3351 }
3352
3353 /* We are being called before a change.
3354 Scan the overlays to find the functions to call. */
3355 last_overlay_modification_hooks_used = 0;
3356 tail_copied = 0;
3357 for (tail = current_buffer->overlays_before;
3358 CONSP (tail);
3359 tail = XCONS (tail)->cdr)
3360 {
3361 int startpos, endpos;
3362 Lisp_Object ostart, oend;
3363
3364 overlay = XCONS (tail)->car;
3365
3366 ostart = OVERLAY_START (overlay);
3367 oend = OVERLAY_END (overlay);
3368 endpos = OVERLAY_POSITION (oend);
3369 if (XFASTINT (start) > endpos)
3370 break;
3371 startpos = OVERLAY_POSITION (ostart);
3372 if (insertion && (XFASTINT (start) == startpos
3373 || XFASTINT (end) == startpos))
3374 {
3375 prop = Foverlay_get (overlay, Qinsert_in_front_hooks);
3376 if (!NILP (prop))
3377 {
3378 /* Copy TAIL in case the hook recenters the overlay lists. */
3379 if (!tail_copied)
3380 tail = Fcopy_sequence (tail);
3381 tail_copied = 1;
3382 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
3383 }
3384 }
3385 if (insertion && (XFASTINT (start) == endpos
3386 || XFASTINT (end) == endpos))
3387 {
3388 prop = Foverlay_get (overlay, Qinsert_behind_hooks);
3389 if (!NILP (prop))
3390 {
3391 if (!tail_copied)
3392 tail = Fcopy_sequence (tail);
3393 tail_copied = 1;
3394 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
3395 }
3396 }
3397 /* Test for intersecting intervals. This does the right thing
3398 for both insertion and deletion. */
3399 if (XFASTINT (end) > startpos && XFASTINT (start) < endpos)
3400 {
3401 prop = Foverlay_get (overlay, Qmodification_hooks);
3402 if (!NILP (prop))
3403 {
3404 if (!tail_copied)
3405 tail = Fcopy_sequence (tail);
3406 tail_copied = 1;
3407 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
3408 }
3409 }
3410 }
3411
3412 tail_copied = 0;
3413 for (tail = current_buffer->overlays_after;
3414 CONSP (tail);
3415 tail = XCONS (tail)->cdr)
3416 {
3417 int startpos, endpos;
3418 Lisp_Object ostart, oend;
3419
3420 overlay = XCONS (tail)->car;
3421
3422 ostart = OVERLAY_START (overlay);
3423 oend = OVERLAY_END (overlay);
3424 startpos = OVERLAY_POSITION (ostart);
3425 endpos = OVERLAY_POSITION (oend);
3426 if (XFASTINT (end) < startpos)
3427 break;
3428 if (insertion && (XFASTINT (start) == startpos
3429 || XFASTINT (end) == startpos))
3430 {
3431 prop = Foverlay_get (overlay, Qinsert_in_front_hooks);
3432 if (!NILP (prop))
3433 {
3434 if (!tail_copied)
3435 tail = Fcopy_sequence (tail);
3436 tail_copied = 1;
3437 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
3438 }
3439 }
3440 if (insertion && (XFASTINT (start) == endpos
3441 || XFASTINT (end) == endpos))
3442 {
3443 prop = Foverlay_get (overlay, Qinsert_behind_hooks);
3444 if (!NILP (prop))
3445 {
3446 if (!tail_copied)
3447 tail = Fcopy_sequence (tail);
3448 tail_copied = 1;
3449 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
3450 }
3451 }
3452 /* Test for intersecting intervals. This does the right thing
3453 for both insertion and deletion. */
3454 if (XFASTINT (end) > startpos && XFASTINT (start) < endpos)
3455 {
3456 prop = Foverlay_get (overlay, Qmodification_hooks);
3457 if (!NILP (prop))
3458 {
3459 if (!tail_copied)
3460 tail = Fcopy_sequence (tail);
3461 tail_copied = 1;
3462 call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3);
3463 }
3464 }
3465 }
3466
3467 UNGCPRO;
3468 }
3469
3470 static void
3471 call_overlay_mod_hooks (list, overlay, after, arg1, arg2, arg3)
3472 Lisp_Object list, overlay;
3473 int after;
3474 Lisp_Object arg1, arg2, arg3;
3475 {
3476 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3477
3478 GCPRO4 (list, arg1, arg2, arg3);
3479 if (! after)
3480 add_overlay_mod_hooklist (list, overlay);
3481
3482 while (!NILP (list))
3483 {
3484 if (NILP (arg3))
3485 call4 (Fcar (list), overlay, after ? Qt : Qnil, arg1, arg2);
3486 else
3487 call5 (Fcar (list), overlay, after ? Qt : Qnil, arg1, arg2, arg3);
3488 list = Fcdr (list);
3489 }
3490 UNGCPRO;
3491 }
3492
3493 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3494 property is set. */
3495 void
3496 evaporate_overlays (pos)
3497 int pos;
3498 {
3499 Lisp_Object tail, overlay, hit_list;
3500
3501 hit_list = Qnil;
3502 if (pos <= XFASTINT (current_buffer->overlay_center))
3503 for (tail = current_buffer->overlays_before; CONSP (tail);
3504 tail = XCONS (tail)->cdr)
3505 {
3506 int endpos;
3507 overlay = XCONS (tail)->car;
3508 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
3509 if (endpos < pos)
3510 break;
3511 if (endpos == pos && OVERLAY_POSITION (OVERLAY_START (overlay)) == pos
3512 && ! NILP (Foverlay_get (overlay, Qevaporate)))
3513 hit_list = Fcons (overlay, hit_list);
3514 }
3515 else
3516 for (tail = current_buffer->overlays_after; CONSP (tail);
3517 tail = XCONS (tail)->cdr)
3518 {
3519 int startpos;
3520 overlay = XCONS (tail)->car;
3521 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
3522 if (startpos > pos)
3523 break;
3524 if (startpos == pos && OVERLAY_POSITION (OVERLAY_END (overlay)) == pos
3525 && ! NILP (Foverlay_get (overlay, Qevaporate)))
3526 hit_list = Fcons (overlay, hit_list);
3527 }
3528 for (; CONSP (hit_list); hit_list = XCONS (hit_list)->cdr)
3529 Fdelete_overlay (XCONS (hit_list)->car);
3530 }
3531 \f
3532 /* Somebody has tried to store a value with an unacceptable type
3533 into the buffer-local slot with offset OFFSET. */
3534 void
3535 buffer_slot_type_mismatch (offset)
3536 int offset;
3537 {
3538 Lisp_Object sym;
3539 char *type_name;
3540 sym = *(Lisp_Object *)(offset + (char *)&buffer_local_symbols);
3541 switch (XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_types)))
3542 {
3543 case Lisp_Int: type_name = "integers"; break;
3544 case Lisp_String: type_name = "strings"; break;
3545 case Lisp_Symbol: type_name = "symbols"; break;
3546 default:
3547 abort ();
3548 }
3549
3550 error ("only %s should be stored in the buffer-local variable %s",
3551 type_name, XSYMBOL (sym)->name->data);
3552 }
3553 \f
3554 init_buffer_once ()
3555 {
3556 register Lisp_Object tem;
3557
3558 buffer_permanent_local_flags = 0;
3559
3560 /* Make sure all markable slots in buffer_defaults
3561 are initialized reasonably, so mark_buffer won't choke. */
3562 reset_buffer (&buffer_defaults);
3563 reset_buffer_local_variables (&buffer_defaults, 1);
3564 reset_buffer (&buffer_local_symbols);
3565 reset_buffer_local_variables (&buffer_local_symbols, 1);
3566 /* Prevent GC from getting confused. */
3567 buffer_defaults.text = &buffer_defaults.own_text;
3568 buffer_local_symbols.text = &buffer_local_symbols.own_text;
3569 #ifdef USE_TEXT_PROPERTIES
3570 BUF_INTERVALS (&buffer_defaults) = 0;
3571 BUF_INTERVALS (&buffer_local_symbols) = 0;
3572 #endif
3573 XSETBUFFER (Vbuffer_defaults, &buffer_defaults);
3574 XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols);
3575
3576 /* Set up the default values of various buffer slots. */
3577 /* Must do these before making the first buffer! */
3578
3579 /* real setup is done in loaddefs.el */
3580 buffer_defaults.mode_line_format = build_string ("%-");
3581 buffer_defaults.abbrev_mode = Qnil;
3582 buffer_defaults.overwrite_mode = Qnil;
3583 buffer_defaults.case_fold_search = Qt;
3584 buffer_defaults.auto_fill_function = Qnil;
3585 buffer_defaults.selective_display = Qnil;
3586 #ifndef old
3587 buffer_defaults.selective_display_ellipses = Qt;
3588 #endif
3589 buffer_defaults.abbrev_table = Qnil;
3590 buffer_defaults.display_table = Qnil;
3591 buffer_defaults.undo_list = Qnil;
3592 buffer_defaults.mark_active = Qnil;
3593 buffer_defaults.file_format = Qnil;
3594 buffer_defaults.overlays_before = Qnil;
3595 buffer_defaults.overlays_after = Qnil;
3596 XSETFASTINT (buffer_defaults.overlay_center, BEG);
3597
3598 XSETFASTINT (buffer_defaults.tab_width, 8);
3599 buffer_defaults.truncate_lines = Qnil;
3600 buffer_defaults.ctl_arrow = Qt;
3601 buffer_defaults.direction_reversed = Qnil;
3602
3603 #ifdef DOS_NT
3604 buffer_defaults.buffer_file_type = Qnil; /* TEXT */
3605 #endif
3606 buffer_defaults.enable_multibyte_characters = Qt;
3607 buffer_defaults.buffer_file_coding_system = Qnil;
3608 XSETFASTINT (buffer_defaults.fill_column, 70);
3609 XSETFASTINT (buffer_defaults.left_margin, 0);
3610 buffer_defaults.cache_long_line_scans = Qnil;
3611 buffer_defaults.file_truename = Qnil;
3612 XSETFASTINT (buffer_defaults.display_count, 0);
3613
3614 /* Assign the local-flags to the slots that have default values.
3615 The local flag is a bit that is used in the buffer
3616 to say that it has its own local value for the slot.
3617 The local flag bits are in the local_var_flags slot of the buffer. */
3618
3619 /* Nothing can work if this isn't true */
3620 if (sizeof (EMACS_INT) != sizeof (Lisp_Object)) abort ();
3621
3622 /* 0 means not a lisp var, -1 means always local, else mask */
3623 bzero (&buffer_local_flags, sizeof buffer_local_flags);
3624 XSETINT (buffer_local_flags.filename, -1);
3625 XSETINT (buffer_local_flags.directory, -1);
3626 XSETINT (buffer_local_flags.backed_up, -1);
3627 XSETINT (buffer_local_flags.save_length, -1);
3628 XSETINT (buffer_local_flags.auto_save_file_name, -1);
3629 XSETINT (buffer_local_flags.read_only, -1);
3630 XSETINT (buffer_local_flags.major_mode, -1);
3631 XSETINT (buffer_local_flags.mode_name, -1);
3632 XSETINT (buffer_local_flags.undo_list, -1);
3633 XSETINT (buffer_local_flags.mark_active, -1);
3634 XSETINT (buffer_local_flags.point_before_scroll, -1);
3635 XSETINT (buffer_local_flags.file_truename, -1);
3636 XSETINT (buffer_local_flags.invisibility_spec, -1);
3637 XSETINT (buffer_local_flags.file_format, -1);
3638 XSETINT (buffer_local_flags.display_count, -1);
3639
3640 XSETFASTINT (buffer_local_flags.mode_line_format, 1);
3641 XSETFASTINT (buffer_local_flags.abbrev_mode, 2);
3642 XSETFASTINT (buffer_local_flags.overwrite_mode, 4);
3643 XSETFASTINT (buffer_local_flags.case_fold_search, 8);
3644 XSETFASTINT (buffer_local_flags.auto_fill_function, 0x10);
3645 XSETFASTINT (buffer_local_flags.selective_display, 0x20);
3646 #ifndef old
3647 XSETFASTINT (buffer_local_flags.selective_display_ellipses, 0x40);
3648 #endif
3649 XSETFASTINT (buffer_local_flags.tab_width, 0x80);
3650 XSETFASTINT (buffer_local_flags.truncate_lines, 0x100);
3651 XSETFASTINT (buffer_local_flags.ctl_arrow, 0x200);
3652 XSETFASTINT (buffer_local_flags.fill_column, 0x400);
3653 XSETFASTINT (buffer_local_flags.left_margin, 0x800);
3654 XSETFASTINT (buffer_local_flags.abbrev_table, 0x1000);
3655 XSETFASTINT (buffer_local_flags.display_table, 0x2000);
3656 #ifdef DOS_NT
3657 XSETFASTINT (buffer_local_flags.buffer_file_type, 0x4000);
3658 /* Make this one a permanent local. */
3659 buffer_permanent_local_flags |= 0x4000;
3660 #endif
3661 XSETFASTINT (buffer_local_flags.syntax_table, 0x8000);
3662 XSETFASTINT (buffer_local_flags.cache_long_line_scans, 0x10000);
3663 XSETFASTINT (buffer_local_flags.category_table, 0x20000);
3664 XSETFASTINT (buffer_local_flags.direction_reversed, 0x40000);
3665 XSETFASTINT (buffer_local_flags.enable_multibyte_characters, 0x80000);
3666 /* Make this one a permanent local. */
3667 buffer_permanent_local_flags |= 0x80000;
3668 XSETFASTINT (buffer_local_flags.buffer_file_coding_system, 0x100000);
3669 /* Make this one a permanent local. */
3670 buffer_permanent_local_flags |= 0x100000;
3671
3672 Vbuffer_alist = Qnil;
3673 current_buffer = 0;
3674 all_buffers = 0;
3675
3676 QSFundamental = build_string ("Fundamental");
3677
3678 Qfundamental_mode = intern ("fundamental-mode");
3679 buffer_defaults.major_mode = Qfundamental_mode;
3680
3681 Qmode_class = intern ("mode-class");
3682
3683 Qprotected_field = intern ("protected-field");
3684
3685 Qpermanent_local = intern ("permanent-local");
3686
3687 Qkill_buffer_hook = intern ("kill-buffer-hook");
3688
3689 Vprin1_to_string_buffer = Fget_buffer_create (build_string (" prin1"));
3690
3691 /* super-magic invisible buffer */
3692 Vbuffer_alist = Qnil;
3693
3694 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3695 }
3696
3697 init_buffer ()
3698 {
3699 char buf[MAXPATHLEN+1];
3700 char *pwd;
3701 struct stat dotstat, pwdstat;
3702 Lisp_Object temp;
3703 int rc;
3704
3705 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3706
3707 /* If PWD is accurate, use it instead of calling getwd. This is faster
3708 when PWD is right, and may avoid a fatal error. */
3709 if ((pwd = getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd)
3710 && stat (pwd, &pwdstat) == 0
3711 && stat (".", &dotstat) == 0
3712 && dotstat.st_ino == pwdstat.st_ino
3713 && dotstat.st_dev == pwdstat.st_dev
3714 && strlen (pwd) < MAXPATHLEN)
3715 strcpy (buf, pwd);
3716 #ifdef HAVE_GETCWD
3717 else if (getcwd (buf, MAXPATHLEN+1) == 0)
3718 fatal ("`getcwd' failed: %s\n", strerror (errno));
3719 #else
3720 else if (getwd (buf) == 0)
3721 fatal ("`getwd' failed: %s\n", buf);
3722 #endif
3723
3724 #ifndef VMS
3725 /* Maybe this should really use some standard subroutine
3726 whose definition is filename syntax dependent. */
3727 rc = strlen (buf);
3728 if (!(IS_DIRECTORY_SEP (buf[rc - 1])))
3729 {
3730 buf[rc] = DIRECTORY_SEP;
3731 buf[rc + 1] = '\0';
3732 }
3733 #endif /* not VMS */
3734
3735 current_buffer->directory = build_string (buf);
3736
3737 /* Add /: to the front of the name
3738 if it would otherwise be treated as magic. */
3739 temp = Ffind_file_name_handler (current_buffer->directory, Qt);
3740 if (! NILP (temp)
3741 /* If the default dir is just /, TEMP is non-nil
3742 because of the ange-ftp completion handler.
3743 However, it is not necessary to turn / into /:/.
3744 So avoid doing that. */
3745 && strcmp ("/", XSTRING (current_buffer->directory)->data))
3746 current_buffer->directory
3747 = concat2 (build_string ("/:"), current_buffer->directory);
3748
3749 temp = get_minibuffer (0);
3750 XBUFFER (temp)->directory = current_buffer->directory;
3751 }
3752
3753 /* initialize the buffer routines */
3754 syms_of_buffer ()
3755 {
3756 extern Lisp_Object Qdisabled;
3757
3758 staticpro (&last_overlay_modification_hooks);
3759 last_overlay_modification_hooks
3760 = Fmake_vector (make_number (10), Qnil);
3761
3762 staticpro (&Vbuffer_defaults);
3763 staticpro (&Vbuffer_local_symbols);
3764 staticpro (&Qfundamental_mode);
3765 staticpro (&Qmode_class);
3766 staticpro (&QSFundamental);
3767 staticpro (&Vbuffer_alist);
3768 staticpro (&Qprotected_field);
3769 staticpro (&Qpermanent_local);
3770 staticpro (&Qkill_buffer_hook);
3771 Qoverlayp = intern ("overlayp");
3772 staticpro (&Qoverlayp);
3773 Qevaporate = intern ("evaporate");
3774 staticpro (&Qevaporate);
3775 Qmodification_hooks = intern ("modification-hooks");
3776 staticpro (&Qmodification_hooks);
3777 Qinsert_in_front_hooks = intern ("insert-in-front-hooks");
3778 staticpro (&Qinsert_in_front_hooks);
3779 Qinsert_behind_hooks = intern ("insert-behind-hooks");
3780 staticpro (&Qinsert_behind_hooks);
3781 Qget_file_buffer = intern ("get-file-buffer");
3782 staticpro (&Qget_file_buffer);
3783 Qpriority = intern ("priority");
3784 staticpro (&Qpriority);
3785 Qwindow = intern ("window");
3786 staticpro (&Qwindow);
3787 Qbefore_string = intern ("before-string");
3788 staticpro (&Qbefore_string);
3789 Qafter_string = intern ("after-string");
3790 staticpro (&Qafter_string);
3791 Qfirst_change_hook = intern ("first-change-hook");
3792 staticpro (&Qfirst_change_hook);
3793 Qbefore_change_functions = intern ("before-change-functions");
3794 staticpro (&Qbefore_change_functions);
3795 Qafter_change_functions = intern ("after-change-functions");
3796 staticpro (&Qafter_change_functions);
3797
3798 Fput (Qprotected_field, Qerror_conditions,
3799 Fcons (Qprotected_field, Fcons (Qerror, Qnil)));
3800 Fput (Qprotected_field, Qerror_message,
3801 build_string ("Attempt to modify a protected field"));
3802
3803 /* All these use DEFVAR_LISP_NOPRO because the slots in
3804 buffer_defaults will all be marked via Vbuffer_defaults. */
3805
3806 DEFVAR_LISP_NOPRO ("default-mode-line-format",
3807 &buffer_defaults.mode_line_format,
3808 "Default value of `mode-line-format' for buffers that don't override it.\n\
3809 This is the same as (default-value 'mode-line-format).");
3810
3811 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
3812 &buffer_defaults.abbrev_mode,
3813 "Default value of `abbrev-mode' for buffers that do not override it.\n\
3814 This is the same as (default-value 'abbrev-mode).");
3815
3816 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
3817 &buffer_defaults.ctl_arrow,
3818 "Default value of `ctl-arrow' for buffers that do not override it.\n\
3819 This is the same as (default-value 'ctl-arrow).");
3820
3821 DEFVAR_LISP_NOPRO ("default-direction-reversed",
3822 &buffer_defaults.direction_reversed,
3823 "Default value of `direction_reversed' for buffers that do not override it.\n\
3824 This is the same as (default-value 'direction-reversed).");
3825
3826 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
3827 &buffer_defaults.enable_multibyte_characters,
3828 "Default value of `enable-multibyte-characters' for buffers not overriding it.\n\
3829 This is the same as (default-value 'enable-multibyte-characters).");
3830
3831 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
3832 &buffer_defaults.buffer_file_coding_system,
3833 "Default value of `buffer-file-coding-system' for buffers not overriding it.\n\
3834 This is the same as (default-value 'buffer-file-coding-system).");
3835
3836 DEFVAR_LISP_NOPRO ("default-truncate-lines",
3837 &buffer_defaults.truncate_lines,
3838 "Default value of `truncate-lines' for buffers that do not override it.\n\
3839 This is the same as (default-value 'truncate-lines).");
3840
3841 DEFVAR_LISP_NOPRO ("default-fill-column",
3842 &buffer_defaults.fill_column,
3843 "Default value of `fill-column' for buffers that do not override it.\n\
3844 This is the same as (default-value 'fill-column).");
3845
3846 DEFVAR_LISP_NOPRO ("default-left-margin",
3847 &buffer_defaults.left_margin,
3848 "Default value of `left-margin' for buffers that do not override it.\n\
3849 This is the same as (default-value 'left-margin).");
3850
3851 DEFVAR_LISP_NOPRO ("default-tab-width",
3852 &buffer_defaults.tab_width,
3853 "Default value of `tab-width' for buffers that do not override it.\n\
3854 This is the same as (default-value 'tab-width).");
3855
3856 DEFVAR_LISP_NOPRO ("default-case-fold-search",
3857 &buffer_defaults.case_fold_search,
3858 "Default value of `case-fold-search' for buffers that don't override it.\n\
3859 This is the same as (default-value 'case-fold-search).");
3860
3861 #ifdef DOS_NT
3862 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
3863 &buffer_defaults.buffer_file_type,
3864 "Default file type for buffers that do not override it.\n\
3865 This is the same as (default-value 'buffer-file-type).\n\
3866 The file type is nil for text, t for binary.");
3867 #endif
3868
3869 DEFVAR_PER_BUFFER ("mode-line-format", &current_buffer->mode_line_format,
3870 Qnil, 0);
3871
3872 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
3873 But make-docfile finds it!
3874 DEFVAR_PER_BUFFER ("mode-line-format", &current_buffer->mode_line_format,
3875 Qnil,
3876 "Template for displaying mode line for current buffer.\n\
3877 Each buffer has its own value of this variable.\n\
3878 Value may be a string, a symbol or a list or cons cell.\n\
3879 For a symbol, its value is used (but it is ignored if t or nil).\n\
3880 A string appearing directly as the value of a symbol is processed verbatim\n\
3881 in that the %-constructs below are not recognized.\n\
3882 For a list whose car is a symbol, the symbol's value is taken,\n\
3883 and if that is non-nil, the cadr of the list is processed recursively.\n\
3884 Otherwise, the caddr of the list (if there is one) is processed.\n\
3885 For a list whose car is a string or list, each element is processed\n\
3886 recursively and the results are effectively concatenated.\n\
3887 For a list whose car is an integer, the cdr of the list is processed\n\
3888 and padded (if the number is positive) or truncated (if negative)\n\
3889 to the width specified by that number.\n\
3890 A string is printed verbatim in the mode line except for %-constructs:\n\
3891 (%-constructs are allowed when the string is the entire mode-line-format\n\
3892 or when it is found in a cons-cell or a list)\n\
3893 %b -- print buffer name. %f -- print visited file name.\n\
3894 %F -- print frame name.\n\
3895 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
3896 % means buffer is read-only and * means it is modified.\n\
3897 For a modified read-only buffer, %* gives % and %+ gives *.\n\
3898 %s -- print process status. %l -- print the current line number.\n\
3899 %c -- print the current column number (this makes editing slower).\n\
3900 To make the column number update correctly in all cases,\n\
3901 `column-number-mode' must be non-nil.\n\
3902 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
3903 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
3904 or print Bottom or All.\n\
3905 %n -- print Narrow if appropriate.\n\
3906 %t -- print T if file is text, B if binary.\n\
3907 %[ -- print one [ for each recursive editing level. %] similar.\n\
3908 %% -- print %. %- -- print infinitely many dashes.\n\
3909 Decimal digits after the % specify field width to which to pad.");
3910 */
3911
3912 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults.major_mode,
3913 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
3914 nil here means use current buffer's major mode.");
3915
3916 DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode,
3917 make_number (Lisp_Symbol),
3918 "Symbol for current buffer's major mode.");
3919
3920 DEFVAR_PER_BUFFER ("mode-name", &current_buffer->mode_name,
3921 make_number (Lisp_String),
3922 "Pretty name of current buffer's major mode (a string).");
3923
3924 DEFVAR_PER_BUFFER ("abbrev-mode", &current_buffer->abbrev_mode, Qnil,
3925 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
3926 Automatically becomes buffer-local when set in any fashion.");
3927
3928 DEFVAR_PER_BUFFER ("case-fold-search", &current_buffer->case_fold_search,
3929 Qnil,
3930 "*Non-nil if searches should ignore case.\n\
3931 Automatically becomes buffer-local when set in any fashion.");
3932
3933 DEFVAR_PER_BUFFER ("fill-column", &current_buffer->fill_column,
3934 make_number (Lisp_Int),
3935 "*Column beyond which automatic line-wrapping should happen.\n\
3936 Automatically becomes buffer-local when set in any fashion.");
3937
3938 DEFVAR_PER_BUFFER ("left-margin", &current_buffer->left_margin,
3939 make_number (Lisp_Int),
3940 "*Column for the default indent-line-function to indent to.\n\
3941 Linefeed indents to this column in Fundamental mode.\n\
3942 Automatically becomes buffer-local when set in any fashion.");
3943
3944 DEFVAR_PER_BUFFER ("tab-width", &current_buffer->tab_width,
3945 make_number (Lisp_Int),
3946 "*Distance between tab stops (for display of tab characters), in columns.\n\
3947 Automatically becomes buffer-local when set in any fashion.");
3948
3949 DEFVAR_PER_BUFFER ("ctl-arrow", &current_buffer->ctl_arrow, Qnil,
3950 "*Non-nil means display control chars with uparrow.\n\
3951 A value of nil means use backslash and octal digits.\n\
3952 Automatically becomes buffer-local when set in any fashion.\n\
3953 This variable does not apply to characters whose display is specified\n\
3954 in the current display table (if there is one).");
3955
3956 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
3957 &current_buffer->enable_multibyte_characters, Qnil,
3958 "*Non-nil means the buffer contents are regarded as multi-byte form\n\
3959 of characters, not a binary code. This affects the display, file I/O,\n\
3960 and behaviors of various editing commands.");
3961
3962 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
3963 &current_buffer->buffer_file_coding_system, Qnil,
3964 "Coding system to be used for encoding the buffer contents on saving.\n\
3965 If it is nil, the buffer is saved without any code conversion unless\n\
3966 some coding system is specified in file-coding-system-alist\n\
3967 for the buffer file.\n\
3968 \n\
3969 This variable is never applied to a way of decoding\n\
3970 a file while reading it.");
3971
3972 DEFVAR_PER_BUFFER ("direction-reversed", &current_buffer->direction_reversed,
3973 Qnil,
3974 "*Non-nil means lines in the buffer are displayed right to left.");
3975
3976 DEFVAR_PER_BUFFER ("truncate-lines", &current_buffer->truncate_lines, Qnil,
3977 "*Non-nil means do not display continuation lines;\n\
3978 give each line of text one screen line.\n\
3979 Automatically becomes buffer-local when set in any fashion.\n\
3980 \n\
3981 Note that this is overridden by the variable\n\
3982 `truncate-partial-width-windows' if that variable is non-nil\n\
3983 and this buffer is not full-frame width.");
3984
3985 #ifdef DOS_NT
3986 DEFVAR_PER_BUFFER ("buffer-file-type", &current_buffer->buffer_file_type,
3987 Qnil,
3988 "Non-nil if the visited file is a binary file.\n\
3989 This variable is meaningful on MS-DOG and Windows NT.\n\
3990 On those systems, it is automatically local in every buffer.\n\
3991 On other systems, this variable is normally always nil.");
3992 #endif
3993
3994 DEFVAR_PER_BUFFER ("default-directory", &current_buffer->directory,
3995 make_number (Lisp_String),
3996 "Name of default directory of current buffer. Should end with slash.\n\
3997 Each buffer has its own value of this variable.");
3998
3999 DEFVAR_PER_BUFFER ("auto-fill-function", &current_buffer->auto_fill_function,
4000 Qnil,
4001 "Function called (if non-nil) to perform auto-fill.\n\
4002 It is called after self-inserting a space or newline.\n\
4003 Each buffer has its own value of this variable.\n\
4004 NOTE: This variable is not a hook;\n\
4005 its value may not be a list of functions.");
4006
4007 DEFVAR_PER_BUFFER ("buffer-file-name", &current_buffer->filename,
4008 make_number (Lisp_String),
4009 "Name of file visited in current buffer, or nil if not visiting a file.\n\
4010 Each buffer has its own value of this variable.");
4011
4012 DEFVAR_PER_BUFFER ("buffer-file-truename", &current_buffer->file_truename,
4013 make_number (Lisp_String),
4014 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
4015 The truename of a file is calculated by `file-truename'\n\
4016 and then abbreviated with `abbreviate-file-name'.\n\
4017 Each buffer has its own value of this variable.");
4018
4019 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
4020 &current_buffer->auto_save_file_name,
4021 make_number (Lisp_String),
4022 "Name of file for auto-saving current buffer,\n\
4023 or nil if buffer should not be auto-saved.\n\
4024 Each buffer has its own value of this variable.");
4025
4026 DEFVAR_PER_BUFFER ("buffer-read-only", &current_buffer->read_only, Qnil,
4027 "Non-nil if this buffer is read-only.\n\
4028 Each buffer has its own value of this variable.");
4029
4030 DEFVAR_PER_BUFFER ("buffer-backed-up", &current_buffer->backed_up, Qnil,
4031 "Non-nil if this buffer's file has been backed up.\n\
4032 Backing up is done before the first time the file is saved.\n\
4033 Each buffer has its own value of this variable.");
4034
4035 DEFVAR_PER_BUFFER ("buffer-saved-size", &current_buffer->save_length,
4036 make_number (Lisp_Int),
4037 "Length of current buffer when last read in, saved or auto-saved.\n\
4038 0 initially.\n\
4039 Each buffer has its own value of this variable.");
4040
4041 DEFVAR_PER_BUFFER ("selective-display", &current_buffer->selective_display,
4042 Qnil,
4043 "Non-nil enables selective display:\n\
4044 Integer N as value means display only lines\n\
4045 that start with less than n columns of space.\n\
4046 A value of t means, after a ^M, all the rest of the line is invisible.\n\
4047 Then ^M's in the file are written into files as newlines.\n\n\
4048 Automatically becomes buffer-local when set in any fashion.");
4049
4050 #ifndef old
4051 DEFVAR_PER_BUFFER ("selective-display-ellipses",
4052 &current_buffer->selective_display_ellipses,
4053 Qnil,
4054 "t means display ... on previous line when a line is invisible.\n\
4055 Automatically becomes buffer-local when set in any fashion.");
4056 #endif
4057
4058 DEFVAR_PER_BUFFER ("overwrite-mode", &current_buffer->overwrite_mode, Qnil,
4059 "Non-nil if self-insertion should replace existing text.\n\
4060 The value should be one of `overwrite-mode-textual',\n\
4061 `overwrite-mode-binary', or nil.\n\
4062 If it is `overwrite-mode-textual', self-insertion still\n\
4063 inserts at the end of a line, and inserts when point is before a tab,\n\
4064 until the tab is filled in.\n\
4065 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
4066 Automatically becomes buffer-local when set in any fashion.");
4067
4068 #if 0 /* The doc string is too long for some compilers,
4069 but make-docfile can find it in this comment. */
4070 DEFVAR_PER_BUFFER ("buffer-display-table", &current_buffer->display_table,
4071 Qnil,
4072 "Display table that controls display of the contents of current buffer.\n\
4073 Automatically becomes buffer-local when set in any fashion.\n\
4074 The display table is a char-table created with `make-display-table'.\n\
4075 The ordinary char-table elements control how to display each possible text\n\
4076 character. Each value should be a vector of characters or nil;\n\
4077 nil means display the character in the default fashion.\n\
4078 There are six extra slots to control the display of\n\
4079 the end of a truncated screen line (extra-slot 0, a single character);\n\
4080 the end of a continued line (extra-slot 1, a single character);\n\
4081 the escape character used to display character codes in octal\n\
4082 (extra-slot 2, a single character);\n\
4083 the character used as an arrow for control characters (extra-slot 3,\n\
4084 a single character);\n\
4085 the decoration indicating the presence of invisible lines (extra-slot 4,\n\
4086 a vector of characters);\n\
4087 the character used to draw the border between side-by-side windows\n\
4088 (extra-slot 5, a single character).\n\
4089 See also the functions `display-table-slot' and `set-display-table-slot'.\n\
4090 If this variable is nil, the value of `standard-display-table' is used.\n\
4091 Each window can have its own, overriding display table.");
4092 #endif
4093 DEFVAR_PER_BUFFER ("buffer-display-table", &current_buffer->display_table,
4094 Qnil, 0);
4095
4096 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
4097 "Don't ask.");
4098 */
4099 DEFVAR_LISP ("before-change-function", &Vbefore_change_function,
4100 "If non-nil, a function to call before each text change (obsolete).\n\
4101 Two arguments are passed to the function: the positions of\n\
4102 the beginning and end of the range of old text to be changed.\n\
4103 \(For an insertion, the beginning and end are at the same place.)\n\
4104 No information is given about the length of the text after the change.\n\
4105 \n\
4106 Buffer changes made while executing the `before-change-function'\n\
4107 don't call any before-change or after-change functions.\n\
4108 That's because these variables are temporarily set to nil.\n\
4109 As a result, a hook function cannot straightforwardly alter the value of\n\
4110 these variables. See the Emacs Lisp manual for a way of\n\
4111 accomplishing an equivalent result by using other variables.\n\n\
4112 This variable is obsolete; use `before-change-functions' instead.");
4113 Vbefore_change_function = Qnil;
4114
4115 DEFVAR_LISP ("after-change-function", &Vafter_change_function,
4116 "If non-nil, a Function to call after each text change (obsolete).\n\
4117 Three arguments are passed to the function: the positions of\n\
4118 the beginning and end of the range of changed text,\n\
4119 and the length of the pre-change text replaced by that range.\n\
4120 \(For an insertion, the pre-change length is zero;\n\
4121 for a deletion, that length is the number of bytes deleted,\n\
4122 and the post-change beginning and end are at the same place.)\n\
4123 \n\
4124 Buffer changes made while executing the `after-change-function'\n\
4125 don't call any before-change or after-change functions.\n\
4126 That's because these variables are temporarily set to nil.\n\
4127 As a result, a hook function cannot straightforwardly alter the value of\n\
4128 these variables. See the Emacs Lisp manual for a way of\n\
4129 accomplishing an equivalent result by using other variables.\n\n\
4130 This variable is obsolete; use `after-change-functions' instead.");
4131 Vafter_change_function = Qnil;
4132
4133 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions,
4134 "List of functions to call before each text change.\n\
4135 Two arguments are passed to each function: the positions of\n\
4136 the beginning and end of the range of old text to be changed.\n\
4137 \(For an insertion, the beginning and end are at the same place.)\n\
4138 No information is given about the length of the text after the change.\n\
4139 \n\
4140 Buffer changes made while executing the `before-change-functions'\n\
4141 don't call any before-change or after-change functions.\n\
4142 That's because these variables are temporarily set to nil.\n\
4143 As a result, a hook function cannot straightforwardly alter the value of\n\
4144 these variables. See the Emacs Lisp manual for a way of\n\
4145 accomplishing an equivalent result by using other variables.");
4146 Vbefore_change_functions = Qnil;
4147
4148 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions,
4149 "List of function to call after each text change.\n\
4150 Three arguments are passed to each function: the positions of\n\
4151 the beginning and end of the range of changed text,\n\
4152 and the length in bytes of the pre-change text replaced by that range.\n\
4153 \(For an insertion, the pre-change length is zero;\n\
4154 for a deletion, that length is the number of bytes deleted,\n\
4155 and the post-change beginning and end are at the same place.)\n\
4156 \n\
4157 Buffer changes made while executing the `after-change-functions'\n\
4158 don't call any before-change or after-change functions.\n\
4159 That's because these variables are temporarily set to nil.\n\
4160 As a result, a hook function cannot straightforwardly alter the value of\n\
4161 these variables. See the Emacs Lisp manual for a way of\n\
4162 accomplishing an equivalent result by using other variables.");
4163
4164 Vafter_change_functions = Qnil;
4165
4166 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook,
4167 "A list of functions to call before changing a buffer which is unmodified.\n\
4168 The functions are run using the `run-hooks' function.");
4169 Vfirst_change_hook = Qnil;
4170
4171 #if 0 /* The doc string is too long for some compilers,
4172 but make-docfile can find it in this comment. */
4173 DEFVAR_PER_BUFFER ("buffer-undo-list", &current_buffer->undo_list, Qnil,
4174 "List of undo entries in current buffer.\n\
4175 Recent changes come first; older changes follow newer.\n\
4176 \n\
4177 An entry (BEG . END) represents an insertion which begins at\n\
4178 position BEG and ends at position END.\n\
4179 \n\
4180 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
4181 from (abs POSITION). If POSITION is positive, point was at the front\n\
4182 of the text being deleted; if negative, point was at the end.\n\
4183 \n\
4184 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
4185 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
4186 of the visited file's modification time, as of that time. If the\n\
4187 modification time of the most recent save is different, this entry is\n\
4188 obsolete.\n\
4189 \n\
4190 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
4191 was modified between BEG and END. PROPERTY is the property name,\n\
4192 and VALUE is the old value.\n\
4193 \n\
4194 An entry (MARKER . DISTANCE) indicates that the marker MARKER\n\
4195 was adjusted in position by the offset DISTANCE (an integer).\n\
4196 \n\
4197 An entry of the form POSITION indicates that point was at the buffer\n\
4198 location given by the integer. Undoing an entry of this form places\n\
4199 point at POSITION.\n\
4200 \n\
4201 nil marks undo boundaries. The undo command treats the changes\n\
4202 between two undo boundaries as a single step to be undone.\n\
4203 \n\
4204 If the value of the variable is t, undo information is not recorded.");
4205 #endif
4206 DEFVAR_PER_BUFFER ("buffer-undo-list", &current_buffer->undo_list, Qnil,
4207 0);
4208
4209 DEFVAR_PER_BUFFER ("mark-active", &current_buffer->mark_active, Qnil,
4210 "Non-nil means the mark and region are currently active in this buffer.\n\
4211 Automatically local in all buffers.");
4212
4213 DEFVAR_PER_BUFFER ("cache-long-line-scans", &current_buffer->cache_long_line_scans, Qnil,
4214 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
4215 This variable is buffer-local, in all buffers.\n\
4216 \n\
4217 Normally, the line-motion functions work by scanning the buffer for\n\
4218 newlines. Columnar operations (like move-to-column and\n\
4219 compute-motion) also work by scanning the buffer, summing character\n\
4220 widths as they go. This works well for ordinary text, but if the\n\
4221 buffer's lines are very long (say, more than 500 characters), these\n\
4222 motion functions will take longer to execute. Emacs may also take\n\
4223 longer to update the display.\n\
4224 \n\
4225 If cache-long-line-scans is non-nil, these motion functions cache the\n\
4226 results of their scans, and consult the cache to avoid rescanning\n\
4227 regions of the buffer until the text is modified. The caches are most\n\
4228 beneficial when they prevent the most searching---that is, when the\n\
4229 buffer contains long lines and large regions of characters with the\n\
4230 same, fixed screen width.\n\
4231 \n\
4232 When cache-long-line-scans is non-nil, processing short lines will\n\
4233 become slightly slower (because of the overhead of consulting the\n\
4234 cache), and the caches will use memory roughly proportional to the\n\
4235 number of newlines and characters whose screen width varies.\n\
4236 \n\
4237 The caches require no explicit maintenance; their accuracy is\n\
4238 maintained internally by the Emacs primitives. Enabling or disabling\n\
4239 the cache should not affect the behavior of any of the motion\n\
4240 functions; it should only affect their performance.");
4241
4242 DEFVAR_PER_BUFFER ("point-before-scroll", &current_buffer->point_before_scroll, Qnil,
4243 "Value of point before the last series of scroll operations, or nil.");
4244
4245 DEFVAR_PER_BUFFER ("buffer-file-format", &current_buffer->file_format, Qnil,
4246 "List of formats to use when saving this buffer.\n\
4247 Formats are defined by `format-alist'. This variable is\n\
4248 set when a file is visited. Automatically local in all buffers.");
4249
4250 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
4251 &current_buffer->invisibility_spec, Qnil,
4252 "Invisibility spec of this buffer.\n\
4253 The default is t, which means that text is invisible\n\
4254 if it has a non-nil `invisible' property.\n\
4255 If the value is a list, a text character is invisible if its `invisible'\n\
4256 property is an element in that list.\n\
4257 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
4258 then characters with property value PROP are invisible,\n\
4259 and they have an ellipsis as well if ELLIPSIS is non-nil.");
4260
4261 DEFVAR_PER_BUFFER ("buffer-display-count",
4262 &current_buffer->display_count, Qnil,
4263 "A number incremented each time the buffer is displayed in a window.");
4264
4265 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode,
4266 "*Non-nil means deactivate the mark when the buffer contents change.\n\
4267 Non-nil also enables highlighting of the region whenever the mark is active.\n\
4268 The variable `highlight-nonselected-windows' controls whether to highlight\n\
4269 all windows or just the selected window.");
4270 Vtransient_mark_mode = Qnil;
4271
4272 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only,
4273 "*Non-nil means disregard read-only status of buffers or characters.\n\
4274 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
4275 text properties. If the value is a list, disregard `buffer-read-only'\n\
4276 and disregard a `read-only' text property if the property value\n\
4277 is a member of the list.");
4278 Vinhibit_read_only = Qnil;
4279
4280 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions,
4281 "List of functions called with no args to query before killing a buffer.");
4282 Vkill_buffer_query_functions = Qnil;
4283
4284 defsubr (&Sbuffer_live_p);
4285 defsubr (&Sbuffer_list);
4286 defsubr (&Sget_buffer);
4287 defsubr (&Sget_file_buffer);
4288 defsubr (&Sget_buffer_create);
4289 defsubr (&Smake_indirect_buffer);
4290 defsubr (&Sgenerate_new_buffer_name);
4291 defsubr (&Sbuffer_name);
4292 /*defsubr (&Sbuffer_number);*/
4293 defsubr (&Sbuffer_file_name);
4294 defsubr (&Sbuffer_base_buffer);
4295 defsubr (&Sbuffer_local_variables);
4296 defsubr (&Sbuffer_modified_p);
4297 defsubr (&Sset_buffer_modified_p);
4298 defsubr (&Sbuffer_modified_tick);
4299 defsubr (&Srename_buffer);
4300 defsubr (&Sother_buffer);
4301 defsubr (&Sbuffer_disable_undo);
4302 defsubr (&Sbuffer_enable_undo);
4303 defsubr (&Skill_buffer);
4304 defsubr (&Serase_buffer);
4305 defsubr (&Sset_buffer_major_mode);
4306 defsubr (&Sswitch_to_buffer);
4307 defsubr (&Spop_to_buffer);
4308 defsubr (&Scurrent_buffer);
4309 defsubr (&Sset_buffer);
4310 defsubr (&Sbarf_if_buffer_read_only);
4311 defsubr (&Sbury_buffer);
4312 defsubr (&Skill_all_local_variables);
4313
4314 defsubr (&Soverlayp);
4315 defsubr (&Smake_overlay);
4316 defsubr (&Sdelete_overlay);
4317 defsubr (&Smove_overlay);
4318 defsubr (&Soverlay_start);
4319 defsubr (&Soverlay_end);
4320 defsubr (&Soverlay_buffer);
4321 defsubr (&Soverlay_properties);
4322 defsubr (&Soverlays_at);
4323 defsubr (&Soverlays_in);
4324 defsubr (&Snext_overlay_change);
4325 defsubr (&Sprevious_overlay_change);
4326 defsubr (&Soverlay_recenter);
4327 defsubr (&Soverlay_lists);
4328 defsubr (&Soverlay_get);
4329 defsubr (&Soverlay_put);
4330 }
4331
4332 keys_of_buffer ()
4333 {
4334 initial_define_key (control_x_map, 'b', "switch-to-buffer");
4335 initial_define_key (control_x_map, 'k', "kill-buffer");
4336
4337 /* This must not be in syms_of_buffer, because Qdisabled is not
4338 initialized when that function gets called. */
4339 Fput (intern ("erase-buffer"), Qdisabled, Qt);
4340 }