1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985,86,87,88,89,93,94,95,97,98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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)
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.
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. */
24 #include <sys/types.h>
26 #include <sys/param.h>
32 /* in 4.1, param.h fails to define this. */
33 #define MAXPATHLEN 1024
34 #endif /* not MAXPATHLEN */
40 #include "intervals.h"
45 #include "region-cache.h"
47 #include "blockinput.h"
50 struct buffer
*current_buffer
; /* the current buffer */
52 /* First buffer in chain of all buffers (in reverse order of creation).
53 Threaded through ->next. */
55 struct buffer
*all_buffers
;
57 /* This structure holds the default values of the buffer-local variables
58 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
59 The default value occupies the same slot in this structure
60 as an individual buffer's value occupies in that buffer.
61 Setting the default value also goes through the alist of buffers
62 and stores into each buffer that does not say it has a local value. */
64 struct buffer buffer_defaults
;
66 /* A Lisp_Object pointer to the above, used for staticpro */
68 static Lisp_Object Vbuffer_defaults
;
70 /* This structure marks which slots in a buffer have corresponding
71 default values in buffer_defaults.
72 Each such slot has a nonzero value in this structure.
73 The value has only one nonzero bit.
75 When a buffer has its own local value for a slot,
76 the entry for that slot (found in the same slot in this structure)
77 is turned on in the buffer's local_flags array.
79 If a slot in this structure is -1, then even though there may
80 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
81 and the corresponding slot in buffer_defaults is not used.
83 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
84 but there is a default value which is copied into each buffer.
86 If a slot in this structure is negative, then even though there may
87 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
88 and the corresponding slot in buffer_defaults is not used.
90 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
91 zero, that is a bug */
93 struct buffer buffer_local_flags
;
95 /* This structure holds the names of symbols whose values may be
96 buffer-local. It is indexed and accessed in the same way as the above. */
98 struct buffer buffer_local_symbols
;
99 /* A Lisp_Object pointer to the above, used for staticpro */
100 static Lisp_Object Vbuffer_local_symbols
;
102 /* This structure holds the required types for the values in the
103 buffer-local slots. If a slot contains Qnil, then the
104 corresponding buffer slot may contain a value of any type. If a
105 slot contains an integer, then prospective values' tags must be
106 equal to that integer (except nil is always allowed).
107 When a tag does not match, the function
108 buffer_slot_type_mismatch will signal an error.
110 If a slot here contains -1, the corresponding variable is read-only. */
111 struct buffer buffer_local_types
;
113 /* Flags indicating which built-in buffer-local variables
114 are permanent locals. */
115 static char buffer_permanent_local_flags
[MAX_PER_BUFFER_VARS
];
117 /* Number of per-buffer variables used. */
119 int last_per_buffer_idx
;
121 Lisp_Object
Fset_buffer ();
122 void set_buffer_internal ();
123 void set_buffer_internal_1 ();
124 static void call_overlay_mod_hooks ();
125 static void swap_out_buffer_local_variables ();
126 static void reset_buffer_local_variables ();
128 /* Alist of all buffer names vs the buffers. */
129 /* This used to be a variable, but is no longer,
130 to prevent lossage due to user rplac'ing this alist or its elements. */
131 Lisp_Object Vbuffer_alist
;
133 /* Functions to call before and after each text change. */
134 Lisp_Object Vbefore_change_function
;
135 Lisp_Object Vafter_change_function
;
136 Lisp_Object Vbefore_change_functions
;
137 Lisp_Object Vafter_change_functions
;
139 Lisp_Object Vtransient_mark_mode
;
141 /* t means ignore all read-only text properties.
142 A list means ignore such a property if its value is a member of the list.
143 Any non-nil value means ignore buffer-read-only. */
144 Lisp_Object Vinhibit_read_only
;
146 /* List of functions to call that can query about killing a buffer.
147 If any of these functions returns nil, we don't kill it. */
148 Lisp_Object Vkill_buffer_query_functions
;
150 /* List of functions to call before changing an unmodified buffer. */
151 Lisp_Object Vfirst_change_hook
;
153 Lisp_Object Qfirst_change_hook
;
154 Lisp_Object Qbefore_change_functions
;
155 Lisp_Object Qafter_change_functions
;
157 /* If nonzero, all modification hooks are suppressed. */
158 int inhibit_modification_hooks
;
160 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
162 Lisp_Object Qprotected_field
;
164 Lisp_Object QSFundamental
; /* A string "Fundamental" */
166 Lisp_Object Qkill_buffer_hook
;
168 Lisp_Object Qget_file_buffer
;
170 Lisp_Object Qoverlayp
;
172 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
174 Lisp_Object Qmodification_hooks
;
175 Lisp_Object Qinsert_in_front_hooks
;
176 Lisp_Object Qinsert_behind_hooks
;
178 /* For debugging; temporary. See set_buffer_internal. */
179 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
186 error ("No buffer named %s", XSTRING (spec
)->data
);
187 error ("Invalid buffer argument");
190 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
191 "Return non-nil if OBJECT is a buffer which has not been killed.\n\
192 Value is nil if OBJECT is not a buffer or if it has been killed.")
196 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
200 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
201 "Return a list of all existing live buffers.\n\
202 If the optional arg FRAME is a frame, we return that frame's buffer list.")
206 Lisp_Object framelist
, general
;
207 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
213 CHECK_FRAME (frame
, 1);
215 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
217 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */
219 while (! NILP (tail
))
221 general
= Fdelq (XCAR (tail
), general
);
224 return nconc2 (framelist
, general
);
230 /* Like Fassoc, but use Fstring_equal to compare
231 (which ignores text properties),
232 and don't ever QUIT. */
235 assoc_ignore_text_properties (key
, list
)
236 register Lisp_Object key
;
239 register Lisp_Object tail
;
240 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
242 register Lisp_Object elt
, tem
;
244 tem
= Fstring_equal (Fcar (elt
), key
);
251 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
252 "Return the buffer named NAME (a string).\n\
253 If there is no live buffer named NAME, return nil.\n\
254 NAME may also be a buffer; if so, the value is that buffer.")
256 register Lisp_Object name
;
260 CHECK_STRING (name
, 0);
262 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
265 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
266 "Return the buffer visiting file FILENAME (a string).\n\
267 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
268 If there is no such live buffer, return nil.\n\
269 See also `find-buffer-visiting'.")
271 register Lisp_Object filename
;
273 register Lisp_Object tail
, buf
, tem
;
276 CHECK_STRING (filename
, 0);
277 filename
= Fexpand_file_name (filename
, Qnil
);
279 /* If the file name has special constructs in it,
280 call the corresponding file handler. */
281 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
283 return call2 (handler
, Qget_file_buffer
, filename
);
285 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
287 buf
= Fcdr (XCAR (tail
));
288 if (!BUFFERP (buf
)) continue;
289 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
290 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
298 get_truename_buffer (filename
)
299 register Lisp_Object filename
;
301 register Lisp_Object tail
, buf
, tem
;
303 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
305 buf
= Fcdr (XCAR (tail
));
306 if (!BUFFERP (buf
)) continue;
307 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
308 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
315 /* Incremented for each buffer created, to assign the buffer number. */
318 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
319 "Return the buffer named NAME, or create such a buffer and return it.\n\
320 A new buffer is created if there is no live buffer named NAME.\n\
321 If NAME starts with a space, the new buffer does not keep undo information.\n\
322 If NAME is a buffer instead of a string, then it is the value returned.\n\
323 The value is never nil.")
325 register Lisp_Object name
;
327 register Lisp_Object buf
;
328 register struct buffer
*b
;
330 buf
= Fget_buffer (name
);
334 if (XSTRING (name
)->size
== 0)
335 error ("Empty string for buffer name is not allowed");
337 b
= (struct buffer
*) allocate_buffer ();
339 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
341 /* An ordinary buffer uses its own struct buffer_text. */
342 b
->text
= &b
->own_text
;
345 BUF_GAP_SIZE (b
) = 20;
347 /* We allocate extra 1-byte at the tail and keep it always '\0' for
348 anchoring a search. */
349 BUFFER_ALLOC (BUF_BEG_ADDR (b
), (BUF_GAP_SIZE (b
) + 1));
351 if (! BUF_BEG_ADDR (b
))
352 buffer_memory_full ();
360 BUF_GPT_BYTE (b
) = 1;
361 BUF_BEGV_BYTE (b
) = 1;
365 BUF_OVERLAY_MODIFF (b
) = 1;
366 BUF_SAVE_MODIFF (b
) = 1;
367 BUF_INTERVALS (b
) = 0;
368 BUF_UNCHANGED_MODIFIED (b
) = 1;
369 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = 1;
370 BUF_END_UNCHANGED (b
) = 0;
371 BUF_BEG_UNCHANGED (b
) = 0;
372 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
374 b
->newline_cache
= 0;
375 b
->width_run_cache
= 0;
376 b
->width_table
= Qnil
;
377 b
->prevent_redisplay_optimizations_p
= 1;
379 /* Put this on the chain of all buffers including killed ones. */
380 b
->next
= all_buffers
;
383 /* An ordinary buffer normally doesn't need markers
384 to handle BEGV and ZV. */
386 b
->begv_marker
= Qnil
;
389 name
= Fcopy_sequence (name
);
390 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
393 if (XSTRING (name
)->data
[0] != ' ')
399 reset_buffer_local_variables (b
, 1);
401 /* Put this in the alist of all live buffers. */
403 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
405 b
->mark
= Fmake_marker ();
406 BUF_MARKERS (b
) = Qnil
;
412 /* Clone per-buffer values of buffer FROM.
414 Buffer TO gets the same per-buffer values as FROM, with the
415 following exceptions: (1) TO's name is left untouched, (2) markers
416 are copied and made to refer to TO, and (3) overlay lists are
420 clone_per_buffer_values (from
, to
)
421 struct buffer
*from
, *to
;
423 Lisp_Object to_buffer
;
426 XSETBUFFER (to_buffer
, to
);
428 for (offset
= PER_BUFFER_VAR_OFFSET (name
) + sizeof (Lisp_Object
);
430 offset
+= sizeof (Lisp_Object
))
434 obj
= PER_BUFFER_VALUE (from
, offset
);
437 struct Lisp_Marker
*m
= XMARKER (obj
);
438 obj
= Fmake_marker ();
439 XMARKER (obj
)->insertion_type
= m
->insertion_type
;
440 set_marker_both (obj
, to_buffer
, m
->charpos
, m
->bytepos
);
443 PER_BUFFER_VALUE (to
, offset
) = obj
;
446 to
->overlays_after
= Fcopy_sequence (from
->overlays_after
);
447 to
->overlays_before
= Fcopy_sequence (to
->overlays_before
);
448 bcopy (from
->local_flags
, to
->local_flags
, sizeof to
->local_flags
);
452 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
,
454 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
455 "Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.\n\
456 BASE-BUFFER should be an existing buffer (or buffer name).\n\
457 NAME should be a string which is not the name of an existing buffer.\n\
458 Optional argument CLONE non-nil means preserve BASE-BUFFER's state,\n\
459 such as major and minor modes, in the indirect buffer.\n\
460 CLONE nil means the indirect buffer's state is reset to default values.")
461 (base_buffer
, name
, clone
)
462 Lisp_Object base_buffer
, name
, clone
;
467 buf
= Fget_buffer (name
);
469 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
471 base_buffer
= Fget_buffer (base_buffer
);
472 if (NILP (base_buffer
))
473 error ("No such buffer: `%s'",
474 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
476 if (XSTRING (name
)->size
== 0)
477 error ("Empty string for buffer name is not allowed");
479 b
= (struct buffer
*) allocate_buffer ();
480 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
482 if (XBUFFER (base_buffer
)->base_buffer
)
483 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
485 b
->base_buffer
= XBUFFER (base_buffer
);
487 /* Use the base buffer's text object. */
488 b
->text
= b
->base_buffer
->text
;
490 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
491 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
492 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
493 BUF_BEGV_BYTE (b
) = BUF_BEGV_BYTE (b
->base_buffer
);
494 BUF_ZV_BYTE (b
) = BUF_ZV_BYTE (b
->base_buffer
);
495 BUF_PT_BYTE (b
) = BUF_PT_BYTE (b
->base_buffer
);
497 b
->newline_cache
= 0;
498 b
->width_run_cache
= 0;
499 b
->width_table
= Qnil
;
501 /* Put this on the chain of all buffers including killed ones. */
502 b
->next
= all_buffers
;
505 name
= Fcopy_sequence (name
);
506 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
510 reset_buffer_local_variables (b
, 1);
512 /* Put this in the alist of all live buffers. */
514 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
516 b
->mark
= Fmake_marker ();
519 /* The multibyte status belongs to the base buffer. */
520 b
->enable_multibyte_characters
= b
->base_buffer
->enable_multibyte_characters
;
522 /* Make sure the base buffer has markers for its narrowing. */
523 if (NILP (b
->base_buffer
->pt_marker
))
525 b
->base_buffer
->pt_marker
= Fmake_marker ();
526 set_marker_both (b
->base_buffer
->pt_marker
, base_buffer
,
527 BUF_PT (b
->base_buffer
),
528 BUF_PT_BYTE (b
->base_buffer
));
530 if (NILP (b
->base_buffer
->begv_marker
))
532 b
->base_buffer
->begv_marker
= Fmake_marker ();
533 set_marker_both (b
->base_buffer
->begv_marker
, base_buffer
,
534 BUF_BEGV (b
->base_buffer
),
535 BUF_BEGV_BYTE (b
->base_buffer
));
537 if (NILP (b
->base_buffer
->zv_marker
))
539 b
->base_buffer
->zv_marker
= Fmake_marker ();
540 set_marker_both (b
->base_buffer
->zv_marker
, base_buffer
,
541 BUF_ZV (b
->base_buffer
),
542 BUF_ZV_BYTE (b
->base_buffer
));
543 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
548 /* Give the indirect buffer markers for its narrowing. */
549 b
->pt_marker
= Fmake_marker ();
550 set_marker_both (b
->pt_marker
, buf
, BUF_PT (b
), BUF_PT_BYTE (b
));
551 b
->begv_marker
= Fmake_marker ();
552 set_marker_both (b
->begv_marker
, buf
, BUF_BEGV (b
), BUF_BEGV_BYTE (b
));
553 b
->zv_marker
= Fmake_marker ();
554 set_marker_both (b
->zv_marker
, buf
, BUF_ZV (b
), BUF_ZV_BYTE (b
));
555 XMARKER (b
->zv_marker
)->insertion_type
= 1;
558 clone_per_buffer_values (b
->base_buffer
, b
);
563 /* Reinitialize everything about a buffer except its name and contents
564 and local variables. */
568 register struct buffer
*b
;
571 b
->file_truename
= Qnil
;
572 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
574 XSETFASTINT (b
->save_length
, 0);
575 b
->last_window_start
= 1;
576 /* It is more conservative to start out "changed" than "unchanged". */
578 b
->prevent_redisplay_optimizations_p
= 1;
580 b
->auto_save_modified
= 0;
581 b
->auto_save_failure_time
= -1;
582 b
->auto_save_file_name
= Qnil
;
584 b
->overlays_before
= Qnil
;
585 b
->overlays_after
= Qnil
;
586 XSETFASTINT (b
->overlay_center
, 1);
587 b
->mark_active
= Qnil
;
588 b
->point_before_scroll
= Qnil
;
589 b
->file_format
= Qnil
;
590 b
->last_selected_window
= Qnil
;
591 XSETINT (b
->display_count
, 0);
592 b
->display_time
= Qnil
;
593 b
->enable_multibyte_characters
= buffer_defaults
.enable_multibyte_characters
;
594 b
->cursor_type
= buffer_defaults
.cursor_type
;
595 b
->extra_line_spacing
= buffer_defaults
.extra_line_spacing
;
598 /* Reset buffer B's local variables info.
599 Don't use this on a buffer that has already been in use;
600 it does not treat permanent locals consistently.
601 Instead, use Fkill_all_local_variables.
603 If PERMANENT_TOO is 1, then we reset permanent built-in
604 buffer-local variables. If PERMANENT_TOO is 0,
605 we preserve those. */
608 reset_buffer_local_variables (b
, permanent_too
)
609 register struct buffer
*b
;
615 /* Reset the major mode to Fundamental, together with all the
616 things that depend on the major mode.
617 default-major-mode is handled at a higher level.
618 We ignore it here. */
619 b
->major_mode
= Qfundamental_mode
;
621 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
622 b
->mode_name
= QSFundamental
;
623 b
->minor_modes
= Qnil
;
625 /* If the standard case table has been altered and invalidated,
626 fix up its insides first. */
627 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
628 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
629 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
630 Fset_standard_case_table (Vascii_downcase_table
);
632 b
->downcase_table
= Vascii_downcase_table
;
633 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
634 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
635 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
636 b
->invisibility_spec
= Qt
;
638 b
->buffer_file_type
= Qnil
;
642 b
->sort_table
= XSTRING (Vascii_sort_table
);
643 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
646 /* Reset all (or most) per-buffer variables to their defaults. */
647 b
->local_var_alist
= Qnil
;
648 for (i
= 0; i
< last_per_buffer_idx
; ++i
)
649 if (permanent_too
|| buffer_permanent_local_flags
[i
] == 0)
650 SET_PER_BUFFER_VALUE_P (b
, i
, 0);
652 /* For each slot that has a default value,
653 copy that into the slot. */
655 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
657 offset
+= sizeof (Lisp_Object
))
659 int idx
= PER_BUFFER_IDX (offset
);
662 || buffer_permanent_local_flags
[idx
] == 0))
663 /* Is -2 used anywhere? */
665 PER_BUFFER_VALUE (b
, offset
) = PER_BUFFER_DEFAULT (offset
);
669 /* We split this away from generate-new-buffer, because rename-buffer
670 and set-visited-file-name ought to be able to use this to really
671 rename the buffer properly. */
673 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
675 "Return a string that is the name of no existing buffer based on NAME.\n\
676 If there is no live buffer named NAME, then return NAME.\n\
677 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
678 until an unused name is found, and then return that name.\n\
679 Optional second argument IGNORE specifies a name that is okay to use\n\
680 \(if it is in the sequence to be tried)\n\
681 even if a buffer with that name exists.")
683 register Lisp_Object name
, ignore
;
685 register Lisp_Object gentemp
, tem
;
689 CHECK_STRING (name
, 0);
691 tem
= Fget_buffer (name
);
698 sprintf (number
, "<%d>", ++count
);
699 gentemp
= concat2 (name
, build_string (number
));
700 tem
= Fstring_equal (gentemp
, ignore
);
703 tem
= Fget_buffer (gentemp
);
710 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
711 "Return the name of BUFFER, as a string.\n\
712 With no argument or nil as argument, return the name of the current buffer.")
714 register Lisp_Object buffer
;
717 return current_buffer
->name
;
718 CHECK_BUFFER (buffer
, 0);
719 return XBUFFER (buffer
)->name
;
722 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
723 "Return name of file BUFFER is visiting, or nil if none.\n\
724 No argument or nil as argument means use the current buffer.")
726 register Lisp_Object buffer
;
729 return current_buffer
->filename
;
730 CHECK_BUFFER (buffer
, 0);
731 return XBUFFER (buffer
)->filename
;
734 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
736 "Return the base buffer of indirect buffer BUFFER.\n\
737 If BUFFER is not indirect, return nil.")
739 register Lisp_Object buffer
;
742 Lisp_Object base_buffer
;
745 base
= current_buffer
->base_buffer
;
748 CHECK_BUFFER (buffer
, 0);
749 base
= XBUFFER (buffer
)->base_buffer
;
754 XSETBUFFER (base_buffer
, base
);
758 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
759 Sbuffer_local_variables
, 0, 1, 0,
760 "Return an alist of variables that are buffer-local in BUFFER.\n\
761 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
762 For a symbol that is locally unbound, just the symbol appears in the value.\n\
763 Note that storing new VALUEs in these elements doesn't change the variables.\n\
764 No argument or nil as argument means use current buffer as BUFFER.")
766 register Lisp_Object buffer
;
768 register struct buffer
*buf
;
769 register Lisp_Object result
;
772 buf
= current_buffer
;
775 CHECK_BUFFER (buffer
, 0);
776 buf
= XBUFFER (buffer
);
782 register Lisp_Object tail
;
783 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
785 Lisp_Object val
, elt
;
789 /* Reference each variable in the alist in buf.
790 If inquiring about the current buffer, this gets the current values,
791 so store them into the alist so the alist is up to date.
792 If inquiring about some other buffer, this swaps out any values
793 for that buffer, making the alist up to date automatically. */
794 val
= find_symbol_value (XCAR (elt
));
795 /* Use the current buffer value only if buf is the current buffer. */
796 if (buf
!= current_buffer
)
799 /* If symbol is unbound, put just the symbol in the list. */
800 if (EQ (val
, Qunbound
))
801 result
= Fcons (XCAR (elt
), result
);
802 /* Otherwise, put (symbol . value) in the list. */
804 result
= Fcons (Fcons (XCAR (elt
), val
), result
);
808 /* Add on all the variables stored in special slots. */
812 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
813 offset
< sizeof (struct buffer
);
814 /* sizeof EMACS_INT == sizeof Lisp_Object */
815 offset
+= (sizeof (EMACS_INT
)))
817 idx
= PER_BUFFER_IDX (offset
);
818 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
819 && SYMBOLP (PER_BUFFER_SYMBOL (offset
)))
820 result
= Fcons (Fcons (PER_BUFFER_SYMBOL (offset
),
821 PER_BUFFER_VALUE (buf
, offset
)),
830 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
832 "Return t if BUFFER was modified since its file was last read or saved.\n\
833 No argument or nil as argument means use current buffer as BUFFER.")
835 register Lisp_Object buffer
;
837 register struct buffer
*buf
;
839 buf
= current_buffer
;
842 CHECK_BUFFER (buffer
, 0);
843 buf
= XBUFFER (buffer
);
846 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
849 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
851 "Mark current buffer as modified or unmodified according to FLAG.\n\
852 A non-nil FLAG means mark the buffer modified.")
854 register Lisp_Object flag
;
856 register int already
;
857 register Lisp_Object fn
;
858 Lisp_Object buffer
, window
;
860 #ifdef CLASH_DETECTION
861 /* If buffer becoming modified, lock the file.
862 If buffer becoming unmodified, unlock the file. */
864 fn
= current_buffer
->file_truename
;
865 /* Test buffer-file-name so that binding it to nil is effective. */
866 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
868 already
= SAVE_MODIFF
< MODIFF
;
869 if (!already
&& !NILP (flag
))
871 else if (already
&& NILP (flag
))
874 #endif /* CLASH_DETECTION */
876 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
878 /* Set update_mode_lines only if buffer is displayed in some window.
879 Packages like jit-lock or lazy-lock preserve a buffer's modified
880 state by recording/restoring the state around blocks of code.
881 Setting update_mode_lines makes redisplay consider all windows
882 (on all frames). Stealth fontification of buffers not displayed
883 would incur additional redisplay costs if we'd set
884 update_modes_lines unconditionally.
886 Ideally, I think there should be another mechanism for fontifying
887 buffers without "modifying" buffers, or redisplay should be
888 smarter about updating the `*' in mode lines. --gerd */
889 XSETBUFFER (buffer
, current_buffer
);
890 window
= Fget_buffer_window (buffer
, Qt
);
891 if (WINDOWP (window
))
897 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p
,
898 Srestore_buffer_modified_p
, 1, 1, 0,
899 "Like `set-buffer-modified-p', with a differences concerning redisplay.\n\
900 It is not ensured that mode lines will be updated to show the modified\n\
901 state of the current buffer. Use with care.")
905 #ifdef CLASH_DETECTION
908 /* If buffer becoming modified, lock the file.
909 If buffer becoming unmodified, unlock the file. */
911 fn
= current_buffer
->file_truename
;
912 /* Test buffer-file-name so that binding it to nil is effective. */
913 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
915 int already
= SAVE_MODIFF
< MODIFF
;
916 if (!already
&& !NILP (flag
))
918 else if (already
&& NILP (flag
))
921 #endif /* CLASH_DETECTION */
923 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
927 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
929 "Return BUFFER's tick counter, incremented for each change in text.\n\
930 Each buffer has a tick counter which is incremented each time the text in\n\
931 that buffer is changed. It wraps around occasionally.\n\
932 No argument or nil as argument means use current buffer as BUFFER.")
934 register Lisp_Object buffer
;
936 register struct buffer
*buf
;
938 buf
= current_buffer
;
941 CHECK_BUFFER (buffer
, 0);
942 buf
= XBUFFER (buffer
);
945 return make_number (BUF_MODIFF (buf
));
948 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
949 "sRename buffer (to new name): \nP",
950 "Change current buffer's name to NEWNAME (a string).\n\
951 If second arg UNIQUE is nil or omitted, it is an error if a\n\
952 buffer named NEWNAME already exists.\n\
953 If UNIQUE is non-nil, come up with a new name using\n\
954 `generate-new-buffer-name'.\n\
955 Interactively, you can set UNIQUE with a prefix argument.\n\
956 We return the name we actually gave the buffer.\n\
957 This does not change the name of the visited file (if any).")
959 register Lisp_Object newname
, unique
;
961 register Lisp_Object tem
, buf
;
963 CHECK_STRING (newname
, 0);
965 if (XSTRING (newname
)->size
== 0)
966 error ("Empty string is invalid as a buffer name");
968 tem
= Fget_buffer (newname
);
971 /* Don't short-circuit if UNIQUE is t. That is a useful way to
972 rename the buffer automatically so you can create another
973 with the original name. It makes UNIQUE equivalent to
974 (rename-buffer (generate-new-buffer-name NEWNAME)). */
975 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
976 return current_buffer
->name
;
978 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
980 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
983 current_buffer
->name
= newname
;
985 /* Catch redisplay's attention. Unless we do this, the mode lines for
986 any windows displaying current_buffer will stay unchanged. */
989 XSETBUFFER (buf
, current_buffer
);
990 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
991 if (NILP (current_buffer
->filename
)
992 && !NILP (current_buffer
->auto_save_file_name
))
993 call0 (intern ("rename-auto-save-file"));
994 /* Refetch since that last call may have done GC. */
995 return current_buffer
->name
;
998 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 3, 0,
999 "Return most recently selected buffer other than BUFFER.\n\
1000 Buffers not visible in windows are preferred to visible buffers,\n\
1001 unless optional second argument VISIBLE-OK is non-nil.\n\
1002 If the optional third argument FRAME is non-nil, use that frame's\n\
1003 buffer list instead of the selected frame's buffer list.\n\
1004 If no other buffer exists, the buffer `*scratch*' is returned.\n\
1005 If BUFFER is omitted or nil, some interesting buffer is returned.")
1006 (buffer
, visible_ok
, frame
)
1007 register Lisp_Object buffer
, visible_ok
, frame
;
1009 Lisp_Object
Fset_buffer_major_mode ();
1010 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
1014 frame
= selected_frame
;
1016 tail
= Vbuffer_alist
;
1017 pred
= frame_buffer_predicate (frame
);
1019 /* Consider buffers that have been seen in the selected frame
1020 before other buffers. */
1022 tem
= frame_buffer_list (frame
);
1026 if (BUFFERP (XCAR (tem
)))
1027 add_ons
= Fcons (Fcons (Qnil
, XCAR (tem
)), add_ons
);
1030 tail
= nconc2 (Fnreverse (add_ons
), tail
);
1032 for (; !NILP (tail
); tail
= Fcdr (tail
))
1034 buf
= Fcdr (Fcar (tail
));
1035 if (EQ (buf
, buffer
))
1037 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
1039 /* If the selected frame has a buffer_predicate,
1040 disregard buffers that don't fit the predicate. */
1043 tem
= call1 (pred
, buf
);
1048 if (NILP (visible_ok
))
1049 tem
= Fget_buffer_window (buf
, Qt
);
1054 if (NILP (notsogood
))
1057 if (!NILP (notsogood
))
1059 buf
= Fget_buffer (build_string ("*scratch*"));
1062 buf
= Fget_buffer_create (build_string ("*scratch*"));
1063 Fset_buffer_major_mode (buf
);
1068 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
,
1070 "Make BUFFER stop keeping undo information.\n\
1071 No argument or nil as argument means do this for the current buffer.")
1073 register Lisp_Object buffer
;
1075 Lisp_Object real_buffer
;
1078 XSETBUFFER (real_buffer
, current_buffer
);
1081 real_buffer
= Fget_buffer (buffer
);
1082 if (NILP (real_buffer
))
1086 XBUFFER (real_buffer
)->undo_list
= Qt
;
1091 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
1093 "Start keeping undo information for buffer BUFFER.\n\
1094 No argument or nil as argument means do this for the current buffer.")
1096 register Lisp_Object buffer
;
1098 Lisp_Object real_buffer
;
1101 XSETBUFFER (real_buffer
, current_buffer
);
1104 real_buffer
= Fget_buffer (buffer
);
1105 if (NILP (real_buffer
))
1109 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
1110 XBUFFER (real_buffer
)->undo_list
= Qnil
;
1116 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
1117 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1118 The buffer being killed will be current while the hook is running.\n\
1121 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
1122 "Kill the buffer BUFFER.\n\
1123 The argument may be a buffer or may be the name of a buffer.\n\
1124 An argument of nil means kill the current buffer.\n\n\
1125 Value is t if the buffer is actually killed, nil if user says no.\n\n\
1126 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
1127 if not void, is a list of functions to be called, with no arguments,\n\
1128 before the buffer is actually killed. The buffer to be killed is current\n\
1129 when the hook functions are called.\n\n\
1130 Any processes that have this buffer as the `process-buffer' are killed\n\
1136 register struct buffer
*b
;
1137 register Lisp_Object tem
;
1138 register struct Lisp_Marker
*m
;
1139 struct gcpro gcpro1
;
1142 buf
= Fcurrent_buffer ();
1144 buf
= Fget_buffer (buffer
);
1150 /* Avoid trouble for buffer already dead. */
1154 /* Query if the buffer is still modified. */
1155 if (INTERACTIVE
&& !NILP (b
->filename
)
1156 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1159 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
1160 XSTRING (b
->name
)->data
));
1166 /* Run hooks with the buffer to be killed the current buffer. */
1168 int count
= specpdl_ptr
- specpdl
;
1171 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1172 set_buffer_internal (b
);
1174 /* First run the query functions; if any query is answered no,
1175 don't kill the buffer. */
1176 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
1178 tem
= call0 (Fcar (list
));
1180 return unbind_to (count
, Qnil
);
1183 /* Then run the hooks. */
1184 if (!NILP (Vrun_hooks
))
1185 call1 (Vrun_hooks
, Qkill_buffer_hook
);
1186 unbind_to (count
, Qnil
);
1189 /* We have no more questions to ask. Verify that it is valid
1190 to kill the buffer. This must be done after the questions
1191 since anything can happen within do_yes_or_no_p. */
1193 /* Don't kill the minibuffer now current. */
1194 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1200 /* When we kill a base buffer, kill all its indirect buffers.
1201 We do it at this stage so nothing terrible happens if they
1202 ask questions or their hooks get errors. */
1203 if (! b
->base_buffer
)
1205 struct buffer
*other
;
1209 for (other
= all_buffers
; other
; other
= other
->next
)
1210 /* all_buffers contains dead buffers too;
1211 don't re-kill them. */
1212 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1215 XSETBUFFER (buf
, other
);
1222 /* Make this buffer not be current.
1223 In the process, notice if this is the sole visible buffer
1224 and give up if so. */
1225 if (b
== current_buffer
)
1227 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1229 if (b
== current_buffer
)
1233 /* Now there is no question: we can kill the buffer. */
1235 #ifdef CLASH_DETECTION
1236 /* Unlock this buffer's file, if it is locked. */
1238 #endif /* CLASH_DETECTION */
1240 kill_buffer_processes (buf
);
1242 tem
= Vinhibit_quit
;
1244 replace_buffer_in_all_windows (buf
);
1245 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1246 frames_discard_buffer (buf
);
1247 Vinhibit_quit
= tem
;
1249 /* Delete any auto-save file, if we saved it in this session. */
1250 if (STRINGP (b
->auto_save_file_name
)
1251 && b
->auto_save_modified
!= 0
1252 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
)
1255 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1257 internal_delete_file (b
->auto_save_file_name
);
1262 /* Unchain all markers that belong to this indirect buffer.
1263 Don't unchain the markers that belong to the base buffer
1264 or its other indirect buffers. */
1265 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1271 unchain_marker (tem
);
1277 /* Unchain all markers of this buffer and its indirect buffers.
1278 and leave them pointing nowhere. */
1279 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1286 BUF_MARKERS (b
) = Qnil
;
1287 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1289 /* Perhaps we should explicitly free the interval tree here... */
1292 /* Reset the local variables, so that this buffer's local values
1293 won't be protected from GC. They would be protected
1294 if they happened to remain encached in their symbols.
1295 This gets rid of them for certain. */
1296 swap_out_buffer_local_variables (b
);
1297 reset_buffer_local_variables (b
, 1);
1302 if (! b
->base_buffer
)
1303 BUFFER_FREE (BUF_BEG_ADDR (b
));
1305 if (b
->newline_cache
)
1307 free_region_cache (b
->newline_cache
);
1308 b
->newline_cache
= 0;
1310 if (b
->width_run_cache
)
1312 free_region_cache (b
->width_run_cache
);
1313 b
->width_run_cache
= 0;
1315 b
->width_table
= Qnil
;
1317 b
->undo_list
= Qnil
;
1322 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1323 we do this each time BUF is selected visibly, the more recently
1324 selected buffers are always closer to the front of the list. This
1325 means that other_buffer is more likely to choose a relevant buffer. */
1331 register Lisp_Object link
, prev
;
1333 frame
= selected_frame
;
1336 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCDR (link
))
1338 if (EQ (XCDR (XCAR (link
)), buf
))
1343 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1344 we cannot use Fdelq itself here because it allows quitting. */
1347 Vbuffer_alist
= XCDR (Vbuffer_alist
);
1349 XCDR (prev
) = XCDR (XCDR (prev
));
1351 XCDR (link
) = Vbuffer_alist
;
1352 Vbuffer_alist
= link
;
1354 /* Now move this buffer to the front of frame_buffer_list also. */
1357 for (link
= frame_buffer_list (frame
); CONSP (link
);
1360 if (EQ (XCAR (link
), buf
))
1365 /* Effectively do delq. */
1370 set_frame_buffer_list (frame
,
1371 XCDR (frame_buffer_list (frame
)));
1373 XCDR (prev
) = XCDR (XCDR (prev
));
1375 XCDR (link
) = frame_buffer_list (frame
);
1376 set_frame_buffer_list (frame
, link
);
1379 set_frame_buffer_list (frame
, Fcons (buf
, frame_buffer_list (frame
)));
1382 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1383 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1384 Use this function before selecting the buffer, since it may need to inspect\n\
1385 the current buffer's major mode.")
1390 Lisp_Object function
;
1392 function
= buffer_defaults
.major_mode
;
1393 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1394 function
= current_buffer
->major_mode
;
1396 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1399 count
= specpdl_ptr
- specpdl
;
1401 /* To select a nonfundamental mode,
1402 select the buffer temporarily and then call the mode function. */
1404 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1406 Fset_buffer (buffer
);
1409 return unbind_to (count
, Qnil
);
1412 /* If switching buffers in WINDOW would be an error, return
1413 a C string saying what the error would be. */
1416 no_switch_window (window
)
1420 if (EQ (minibuf_window
, window
))
1421 return "Cannot switch buffers in minibuffer window";
1422 tem
= Fwindow_dedicated_p (window
);
1424 return "Cannot switch buffers in a dedicated window";
1428 /* Switch to buffer BUFFER in the selected window.
1429 If NORECORD is non-nil, don't call record_buffer. */
1432 switch_to_buffer_1 (buffer
, norecord
)
1433 Lisp_Object buffer
, norecord
;
1435 register Lisp_Object buf
;
1438 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1441 buf
= Fget_buffer (buffer
);
1444 buf
= Fget_buffer_create (buffer
);
1445 Fset_buffer_major_mode (buf
);
1449 if (NILP (norecord
))
1450 record_buffer (buf
);
1452 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1453 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1460 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1461 "Select buffer BUFFER in the current window.\n\
1462 BUFFER may be a buffer or a buffer name.\n\
1463 Optional second arg NORECORD non-nil means\n\
1464 do not put this buffer at the front of the list of recently selected ones.\n\
1466 WARNING: This is NOT the way to work on another buffer temporarily\n\
1467 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1468 the window-buffer correspondences.")
1470 Lisp_Object buffer
, norecord
;
1474 err
= no_switch_window (selected_window
);
1475 if (err
) error (err
);
1477 return switch_to_buffer_1 (buffer
, norecord
);
1480 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1481 "Select buffer BUFFER in some window, preferably a different one.\n\
1482 If BUFFER is nil, then some other buffer is chosen.\n\
1483 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1484 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1485 window even if BUFFER is already visible in the selected window.\n\
1486 This uses the function `display-buffer' as a subroutine; see the documentation\n\
1487 of `display-buffer' for additional customization information.\n\
1489 Optional third arg NORECORD non-nil means\n\
1490 do not put this buffer at the front of the list of recently selected ones.")
1491 (buffer
, other_window
, norecord
)
1492 Lisp_Object buffer
, other_window
, norecord
;
1494 register Lisp_Object buf
;
1496 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1499 buf
= Fget_buffer (buffer
);
1502 buf
= Fget_buffer_create (buffer
);
1503 Fset_buffer_major_mode (buf
);
1507 if (NILP (norecord
))
1508 record_buffer (buf
);
1509 Fselect_window (Fdisplay_buffer (buf
, other_window
, Qnil
));
1513 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1514 "Return the current buffer as a Lisp object.")
1517 register Lisp_Object buf
;
1518 XSETBUFFER (buf
, current_buffer
);
1522 /* Set the current buffer to B.
1524 We previously set windows_or_buffers_changed here to invalidate
1525 global unchanged information in beg_unchanged and end_unchanged.
1526 This is no longer necessary because we now compute unchanged
1527 information on a buffer-basis. Every action affecting other
1528 windows than the selected one requires a select_window at some
1529 time, and that increments windows_or_buffers_changed. */
1532 set_buffer_internal (b
)
1533 register struct buffer
*b
;
1535 if (current_buffer
!= b
)
1536 set_buffer_internal_1 (b
);
1539 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1540 This is used by redisplay. */
1543 set_buffer_internal_1 (b
)
1544 register struct buffer
*b
;
1546 register struct buffer
*old_buf
;
1547 register Lisp_Object tail
, valcontents
;
1550 if (current_buffer
== b
)
1553 old_buf
= current_buffer
;
1555 last_known_column_point
= -1; /* invalidate indentation cache */
1559 /* Put the undo list back in the base buffer, so that it appears
1560 that an indirect buffer shares the undo list of its base. */
1561 if (old_buf
->base_buffer
)
1562 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1564 /* If the old current buffer has markers to record PT, BEGV and ZV
1565 when it is not current, update them now. */
1566 if (! NILP (old_buf
->pt_marker
))
1569 XSETBUFFER (obuf
, old_buf
);
1570 set_marker_both (old_buf
->pt_marker
, obuf
,
1571 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1573 if (! NILP (old_buf
->begv_marker
))
1576 XSETBUFFER (obuf
, old_buf
);
1577 set_marker_both (old_buf
->begv_marker
, obuf
,
1578 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1580 if (! NILP (old_buf
->zv_marker
))
1583 XSETBUFFER (obuf
, old_buf
);
1584 set_marker_both (old_buf
->zv_marker
, obuf
,
1585 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1589 /* Get the undo list from the base buffer, so that it appears
1590 that an indirect buffer shares the undo list of its base. */
1592 b
->undo_list
= b
->base_buffer
->undo_list
;
1594 /* If the new current buffer has markers to record PT, BEGV and ZV
1595 when it is not current, fetch them now. */
1596 if (! NILP (b
->pt_marker
))
1598 BUF_PT (b
) = marker_position (b
->pt_marker
);
1599 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1601 if (! NILP (b
->begv_marker
))
1603 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1604 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1606 if (! NILP (b
->zv_marker
))
1608 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1609 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1612 /* Look down buffer's list of local Lisp variables
1613 to find and update any that forward into C variables. */
1615 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCDR (tail
))
1617 valcontents
= XSYMBOL (XCAR (XCAR (tail
)))->value
;
1618 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1619 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1620 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1621 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1622 /* Just reference the variable
1623 to cause it to become set for this buffer. */
1624 Fsymbol_value (XCAR (XCAR (tail
)));
1627 /* Do the same with any others that were local to the previous buffer */
1630 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCDR (tail
))
1632 valcontents
= XSYMBOL (XCAR (XCAR (tail
)))->value
;
1633 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1634 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1635 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1636 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1637 /* Just reference the variable
1638 to cause it to become set for this buffer. */
1639 Fsymbol_value (XCAR (XCAR (tail
)));
1643 /* Switch to buffer B temporarily for redisplay purposes.
1644 This avoids certain things that don't need to be done within redisplay. */
1650 register struct buffer
*old_buf
;
1652 if (current_buffer
== b
)
1655 old_buf
= current_buffer
;
1660 /* If the old current buffer has markers to record PT, BEGV and ZV
1661 when it is not current, update them now. */
1662 if (! NILP (old_buf
->pt_marker
))
1665 XSETBUFFER (obuf
, old_buf
);
1666 set_marker_both (old_buf
->pt_marker
, obuf
,
1667 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1669 if (! NILP (old_buf
->begv_marker
))
1672 XSETBUFFER (obuf
, old_buf
);
1673 set_marker_both (old_buf
->begv_marker
, obuf
,
1674 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1676 if (! NILP (old_buf
->zv_marker
))
1679 XSETBUFFER (obuf
, old_buf
);
1680 set_marker_both (old_buf
->zv_marker
, obuf
,
1681 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1685 /* If the new current buffer has markers to record PT, BEGV and ZV
1686 when it is not current, fetch them now. */
1687 if (! NILP (b
->pt_marker
))
1689 BUF_PT (b
) = marker_position (b
->pt_marker
);
1690 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1692 if (! NILP (b
->begv_marker
))
1694 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1695 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1697 if (! NILP (b
->zv_marker
))
1699 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1700 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1704 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1705 "Make the buffer BUFFER current for editing operations.\n\
1706 BUFFER may be a buffer or the name of an existing buffer.\n\
1707 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1708 This function does not display the buffer, so its effect ends\n\
1709 when the current command terminates.\n\
1710 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1712 register Lisp_Object buffer
;
1714 register Lisp_Object buf
;
1715 buf
= Fget_buffer (buffer
);
1718 if (NILP (XBUFFER (buf
)->name
))
1719 error ("Selecting deleted buffer");
1720 set_buffer_internal (XBUFFER (buf
));
1724 /* Set the current buffer to BUFFER provided it is alive. */
1727 set_buffer_if_live (buffer
)
1730 if (! NILP (XBUFFER (buffer
)->name
))
1731 Fset_buffer (buffer
);
1735 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1736 Sbarf_if_buffer_read_only
, 0, 0, 0,
1737 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1740 if (!NILP (current_buffer
->read_only
)
1741 && NILP (Vinhibit_read_only
))
1742 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1746 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1747 "Put BUFFER at the end of the list of all buffers.\n\
1748 There it is the least likely candidate for `other-buffer' to return;\n\
1749 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1750 If BUFFER is nil or omitted, bury the current buffer.\n\
1751 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1752 selected window if it is displayed there.")
1754 register Lisp_Object buffer
;
1756 /* Figure out what buffer we're going to bury. */
1759 XSETBUFFER (buffer
, current_buffer
);
1761 /* If we're burying the current buffer, unshow it. */
1762 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
, Qnil
), Qnil
);
1768 buf1
= Fget_buffer (buffer
);
1774 /* Move buffer to the end of the buffer list. Do nothing if the
1775 buffer is killed. */
1776 if (!NILP (XBUFFER (buffer
)->name
))
1778 Lisp_Object aelt
, link
;
1780 aelt
= Frassq (buffer
, Vbuffer_alist
);
1781 link
= Fmemq (aelt
, Vbuffer_alist
);
1782 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1784 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1786 frames_bury_buffer (buffer
);
1792 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1793 "Delete the entire contents of the current buffer.\n\
1794 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1795 so the buffer is truly empty after this.")
1802 current_buffer
->last_window_start
= 1;
1803 /* Prevent warnings, or suspension of auto saving, that would happen
1804 if future size is less than past size. Use of erase-buffer
1805 implies that the future text is not really related to the past text. */
1806 XSETFASTINT (current_buffer
->save_length
, 0);
1811 validate_region (b
, e
)
1812 register Lisp_Object
*b
, *e
;
1814 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1815 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1817 if (XINT (*b
) > XINT (*e
))
1820 tem
= *b
; *b
= *e
; *e
= tem
;
1823 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1824 && XINT (*e
) <= ZV
))
1825 args_out_of_range (*b
, *e
);
1828 /* Advance BYTE_POS up to a character boundary
1829 and return the adjusted position. */
1832 advance_to_char_boundary (byte_pos
)
1837 if (byte_pos
== BEG
)
1838 /* Beginning of buffer is always a character boundary. */
1841 c
= FETCH_BYTE (byte_pos
);
1842 if (! CHAR_HEAD_P (c
))
1844 /* We should advance BYTE_POS only when C is a constituent of a
1845 multibyte sequence. */
1846 int orig_byte_pos
= byte_pos
;
1851 c
= FETCH_BYTE (byte_pos
);
1853 while (! CHAR_HEAD_P (c
) && byte_pos
> BEG
);
1855 if (byte_pos
< orig_byte_pos
)
1856 byte_pos
= orig_byte_pos
;
1857 /* If C is a constituent of a multibyte sequence, BYTE_POS was
1858 surely advance to the correct character boundary. If C is
1859 not, BYTE_POS was unchanged. */
1865 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte
, Sset_buffer_multibyte
,
1867 "Set the multibyte flag of the current buffer to FLAG.\n\
1868 If FLAG is t, this makes the buffer a multibyte buffer.\n\
1869 If FLAG is nil, this makes the buffer a single-byte buffer.\n\
1870 The buffer contents remain unchanged as a sequence of bytes\n\
1871 but the contents viewed as characters do change.")
1875 Lisp_Object tail
, markers
;
1876 struct buffer
*other
;
1877 int undo_enabled_p
= !EQ (current_buffer
->undo_list
, Qt
);
1878 int begv
= BEGV
, zv
= ZV
;
1879 int narrowed
= (BEG
!= begv
|| Z
!= zv
);
1881 if (current_buffer
->base_buffer
)
1882 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
1884 /* Do nothing if nothing actually changes. */
1885 if (NILP (flag
) == NILP (current_buffer
->enable_multibyte_characters
))
1888 /* It would be better to update the list,
1889 but this is good enough for now. */
1891 current_buffer
->undo_list
= Qt
;
1893 /* If the cached position is for this buffer, clear it out. */
1894 clear_charpos_cache (current_buffer
);
1904 /* Do this first, so it can use CHAR_TO_BYTE
1905 to calculate the old correspondences. */
1906 set_intervals_multibyte (0);
1908 current_buffer
->enable_multibyte_characters
= Qnil
;
1914 TEMP_SET_PT_BOTH (PT_BYTE
, PT_BYTE
);
1916 tail
= BUF_MARKERS (current_buffer
);
1917 while (! NILP (tail
))
1919 XMARKER (tail
)->charpos
= XMARKER (tail
)->bytepos
;
1920 tail
= XMARKER (tail
)->chain
;
1923 /* Convert multibyte form of 8-bit characters to unibyte. */
1938 if (MULTIBYTE_STR_AS_UNIBYTE_P (p
, bytes
))
1939 p
+= bytes
, pos
+= bytes
;
1942 c
= STRING_CHAR (p
, stop
- pos
);
1943 /* Delete all bytes for this 8-bit character but the
1944 last one, and change the last one to the charcter
1947 del_range_2 (pos
, pos
, pos
+ bytes
, pos
+ bytes
, 0);
1959 Fnarrow_to_region (make_number (begv
), make_number (zv
));
1967 /* Be sure not to have a multibyte sequence striding over the GAP.
1968 Ex: We change this: "...abc\201 _GAP_ \241def..."
1969 to: "...abc _GAP_ \201\241def..." */
1971 if (GPT_BYTE
> 1 && GPT_BYTE
< Z_BYTE
1972 && ! CHAR_HEAD_P (*(GAP_END_ADDR
)))
1974 unsigned char *p
= GPT_ADDR
- 1;
1976 while (! CHAR_HEAD_P (*p
) && p
> BEG_ADDR
) p
--;
1977 if (BASE_LEADING_CODE_P (*p
))
1979 int new_gpt
= GPT_BYTE
- (GPT_ADDR
- p
);
1981 move_gap_both (new_gpt
, new_gpt
);
1985 /* Make the buffer contents valid as multibyte by converting
1986 8-bit characters to multibyte form. */
2002 if (UNIBYTE_STR_AS_MULTIBYTE_P (p
, stop
- pos
, bytes
))
2003 p
+= bytes
, pos
+= bytes
;
2006 unsigned char tmp
[MAX_MULTIBYTE_LENGTH
];
2008 bytes
= CHAR_STRING (*p
, tmp
);
2010 TEMP_SET_PT_BOTH (pos
+ 1, pos
+ 1);
2012 insert_1_both (tmp
+ 1, bytes
, bytes
, 1, 0, 0);
2013 /* Now the gap is after the just inserted data. */
2030 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2032 /* Do this first, so that chars_in_text asks the right question.
2033 set_intervals_multibyte needs it too. */
2034 current_buffer
->enable_multibyte_characters
= Qt
;
2036 GPT_BYTE
= advance_to_char_boundary (GPT_BYTE
);
2037 GPT
= chars_in_text (BEG_ADDR
, GPT_BYTE
- BEG_BYTE
) + BEG
;
2039 Z
= chars_in_text (GAP_END_ADDR
, Z_BYTE
- GPT_BYTE
) + GPT
;
2041 BEGV_BYTE
= advance_to_char_boundary (BEGV_BYTE
);
2042 if (BEGV_BYTE
> GPT_BYTE
)
2043 BEGV
= chars_in_text (GAP_END_ADDR
, BEGV_BYTE
- GPT_BYTE
) + GPT
;
2045 BEGV
= chars_in_text (BEG_ADDR
, BEGV_BYTE
- BEG_BYTE
) + BEG
;
2047 ZV_BYTE
= advance_to_char_boundary (ZV_BYTE
);
2048 if (ZV_BYTE
> GPT_BYTE
)
2049 ZV
= chars_in_text (GAP_END_ADDR
, ZV_BYTE
- GPT_BYTE
) + GPT
;
2051 ZV
= chars_in_text (BEG_ADDR
, ZV_BYTE
- BEG_BYTE
) + BEG
;
2054 int pt_byte
= advance_to_char_boundary (PT_BYTE
);
2057 if (pt_byte
> GPT_BYTE
)
2058 pt
= chars_in_text (GAP_END_ADDR
, pt_byte
- GPT_BYTE
) + GPT
;
2060 pt
= chars_in_text (BEG_ADDR
, pt_byte
- BEG_BYTE
) + BEG
;
2061 TEMP_SET_PT_BOTH (pt
, pt_byte
);
2064 tail
= markers
= BUF_MARKERS (current_buffer
);
2066 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
2067 getting confused by the markers that have not yet been updated.
2068 It is also a signal that it should never create a marker. */
2069 BUF_MARKERS (current_buffer
) = Qnil
;
2071 while (! NILP (tail
))
2073 XMARKER (tail
)->bytepos
2074 = advance_to_char_boundary (XMARKER (tail
)->bytepos
);
2075 XMARKER (tail
)->charpos
= BYTE_TO_CHAR (XMARKER (tail
)->bytepos
);
2077 tail
= XMARKER (tail
)->chain
;
2080 /* Make sure no markers were put on the chain
2081 while the chain value was incorrect. */
2082 if (! EQ (BUF_MARKERS (current_buffer
), Qnil
))
2085 BUF_MARKERS (current_buffer
) = markers
;
2087 /* Do this last, so it can calculate the new correspondences
2088 between chars and bytes. */
2089 set_intervals_multibyte (1);
2093 current_buffer
->undo_list
= Qnil
;
2095 /* Changing the multibyteness of a buffer means that all windows
2096 showing that buffer must be updated thoroughly. */
2097 current_buffer
->prevent_redisplay_optimizations_p
= 1;
2098 ++windows_or_buffers_changed
;
2100 /* Copy this buffer's new multibyte status
2101 into all of its indirect buffers. */
2102 for (other
= all_buffers
; other
; other
= other
->next
)
2103 if (other
->base_buffer
== current_buffer
&& !NILP (other
->name
))
2105 other
->enable_multibyte_characters
2106 = current_buffer
->enable_multibyte_characters
;
2107 other
->prevent_redisplay_optimizations_p
= 1;
2113 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
2115 "Switch to Fundamental mode by killing current buffer's local variables.\n\
2116 Most local variable bindings are eliminated so that the default values\n\
2117 become effective once more. Also, the syntax table is set from\n\
2118 `standard-syntax-table', the local keymap is set to nil,\n\
2119 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
2120 This function also forces redisplay of the mode line.\n\
2122 Every function to select a new major mode starts by\n\
2123 calling this function.\n\n\
2124 As a special exception, local variables whose names have\n\
2125 a non-nil `permanent-local' property are not eliminated by this function.\n\
2127 The first thing this function does is run\n\
2128 the normal hook `change-major-mode-hook'.")
2131 register Lisp_Object alist
, sym
, tem
;
2134 if (!NILP (Vrun_hooks
))
2135 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
2136 oalist
= current_buffer
->local_var_alist
;
2138 /* Make sure none of the bindings in oalist
2139 remain swapped in, in their symbols. */
2141 swap_out_buffer_local_variables (current_buffer
);
2143 /* Actually eliminate all local bindings of this buffer. */
2145 reset_buffer_local_variables (current_buffer
, 0);
2147 /* Redisplay mode lines; we are changing major mode. */
2149 update_mode_lines
++;
2151 /* Any which are supposed to be permanent,
2152 make local again, with the same values they had. */
2154 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
2156 sym
= XCAR (XCAR (alist
));
2157 tem
= Fget (sym
, Qpermanent_local
);
2160 Fmake_local_variable (sym
);
2161 Fset (sym
, XCDR (XCAR (alist
)));
2165 /* Force mode-line redisplay. Useful here because all major mode
2166 commands call this function. */
2167 update_mode_lines
++;
2172 /* Make sure no local variables remain set up with buffer B
2173 for their current values. */
2176 swap_out_buffer_local_variables (b
)
2179 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
2181 XSETBUFFER (buffer
, b
);
2182 oalist
= b
->local_var_alist
;
2184 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
2186 sym
= XCAR (XCAR (alist
));
2188 /* Need not do anything if some other buffer's binding is now encached. */
2189 tem
= XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->buffer
;
2190 if (BUFFERP (tem
) && XBUFFER (tem
) == current_buffer
)
2192 /* Symbol is set up for this buffer's old local value.
2193 Set it up for the current buffer with the default value. */
2195 tem
= XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
;
2196 /* Store the symbol's current value into the alist entry
2197 it is currently set up for. This is so that, if the
2198 local is marked permanent, and we make it local again
2199 later in Fkill_all_local_variables, we don't lose the value. */
2201 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->realvalue
);
2202 /* Switch to the symbol's default-value alist entry. */
2204 /* Mark it as current for buffer B. */
2205 XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->buffer
= buffer
;
2206 /* Store the current value into any forwarding in the symbol. */
2207 store_symval_forwarding (sym
,
2208 XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->realvalue
,
2214 /* Find all the overlays in the current buffer that contain position POS.
2215 Return the number found, and store them in a vector in *VEC_PTR.
2216 Store in *LEN_PTR the size allocated for the vector.
2217 Store in *NEXT_PTR the next position after POS where an overlay starts,
2218 or ZV if there are no more overlays.
2219 Store in *PREV_PTR the previous position before POS where an overlay ends,
2220 or where an overlay starts which ends at or after POS;
2221 or BEGV if there are no such overlays.
2222 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2224 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2225 when this function is called.
2227 If EXTEND is non-zero, we make the vector bigger if necessary.
2228 If EXTEND is zero, we never extend the vector,
2229 and we store only as many overlays as will fit.
2230 But we still return the total number of overlays. */
2233 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2236 Lisp_Object
**vec_ptr
;
2241 Lisp_Object tail
, overlay
, start
, end
;
2244 Lisp_Object
*vec
= *vec_ptr
;
2247 int inhibit_storing
= 0;
2249 for (tail
= current_buffer
->overlays_before
;
2253 int startpos
, endpos
;
2255 overlay
= XCAR (tail
);
2257 start
= OVERLAY_START (overlay
);
2258 end
= OVERLAY_END (overlay
);
2259 endpos
= OVERLAY_POSITION (end
);
2266 startpos
= OVERLAY_POSITION (start
);
2267 /* This one ends at or after POS
2268 so its start counts for PREV_PTR if it's before POS. */
2269 if (prev
< startpos
&& startpos
< pos
)
2273 if (startpos
<= pos
)
2277 /* The supplied vector is full.
2278 Either make it bigger, or don't store any more in it. */
2281 /* Make it work with an initial len == 0. */
2286 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2290 inhibit_storing
= 1;
2293 if (!inhibit_storing
)
2295 /* Keep counting overlays even if we can't return them all. */
2298 else if (startpos
< next
)
2302 for (tail
= current_buffer
->overlays_after
;
2306 int startpos
, endpos
;
2308 overlay
= XCAR (tail
);
2310 start
= OVERLAY_START (overlay
);
2311 end
= OVERLAY_END (overlay
);
2312 startpos
= OVERLAY_POSITION (start
);
2315 if (startpos
< next
)
2319 endpos
= OVERLAY_POSITION (end
);
2326 *len_ptr
= len
*= 2;
2329 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2333 inhibit_storing
= 1;
2336 if (!inhibit_storing
)
2340 if (startpos
< pos
&& startpos
> prev
)
2343 else if (endpos
< pos
&& endpos
> prev
)
2345 else if (endpos
== pos
&& startpos
> prev
)
2356 /* Find all the overlays in the current buffer that overlap the range BEG-END
2357 or are empty at BEG.
2359 Return the number found, and store them in a vector in *VEC_PTR.
2360 Store in *LEN_PTR the size allocated for the vector.
2361 Store in *NEXT_PTR the next position after POS where an overlay starts,
2362 or ZV if there are no more overlays.
2363 Store in *PREV_PTR the previous position before POS where an overlay ends,
2364 or BEGV if there are no previous overlays.
2365 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2367 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2368 when this function is called.
2370 If EXTEND is non-zero, we make the vector bigger if necessary.
2371 If EXTEND is zero, we never extend the vector,
2372 and we store only as many overlays as will fit.
2373 But we still return the total number of overlays. */
2376 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2379 Lisp_Object
**vec_ptr
;
2384 Lisp_Object tail
, overlay
, ostart
, oend
;
2387 Lisp_Object
*vec
= *vec_ptr
;
2390 int inhibit_storing
= 0;
2392 for (tail
= current_buffer
->overlays_before
;
2396 int startpos
, endpos
;
2398 overlay
= XCAR (tail
);
2400 ostart
= OVERLAY_START (overlay
);
2401 oend
= OVERLAY_END (overlay
);
2402 endpos
= OVERLAY_POSITION (oend
);
2409 startpos
= OVERLAY_POSITION (ostart
);
2410 /* Count an interval if it either overlaps the range
2411 or is empty at the start of the range. */
2412 if ((beg
< endpos
&& startpos
< end
)
2413 || (startpos
== endpos
&& beg
== endpos
))
2417 /* The supplied vector is full.
2418 Either make it bigger, or don't store any more in it. */
2421 *len_ptr
= len
*= 2;
2422 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2426 inhibit_storing
= 1;
2429 if (!inhibit_storing
)
2431 /* Keep counting overlays even if we can't return them all. */
2434 else if (startpos
< next
)
2438 for (tail
= current_buffer
->overlays_after
;
2442 int startpos
, endpos
;
2444 overlay
= XCAR (tail
);
2446 ostart
= OVERLAY_START (overlay
);
2447 oend
= OVERLAY_END (overlay
);
2448 startpos
= OVERLAY_POSITION (ostart
);
2451 if (startpos
< next
)
2455 endpos
= OVERLAY_POSITION (oend
);
2456 /* Count an interval if it either overlaps the range
2457 or is empty at the start of the range. */
2458 if ((beg
< endpos
&& startpos
< end
)
2459 || (startpos
== endpos
&& beg
== endpos
))
2465 *len_ptr
= len
*= 2;
2466 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2470 inhibit_storing
= 1;
2473 if (!inhibit_storing
)
2477 else if (endpos
< beg
&& endpos
> prev
)
2488 /* Fast function to just test if we're at an overlay boundary. */
2490 overlay_touches_p (pos
)
2493 Lisp_Object tail
, overlay
;
2495 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
2500 overlay
= XCAR (tail
);
2501 if (!GC_OVERLAYP (overlay
))
2504 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2507 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2511 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
2516 overlay
= XCAR (tail
);
2517 if (!GC_OVERLAYP (overlay
))
2520 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2523 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2531 Lisp_Object overlay
;
2537 compare_overlays (v1
, v2
)
2538 const void *v1
, *v2
;
2540 const struct sortvec
*s1
= (const struct sortvec
*) v1
;
2541 const struct sortvec
*s2
= (const struct sortvec
*) v2
;
2542 if (s1
->priority
!= s2
->priority
)
2543 return s1
->priority
- s2
->priority
;
2544 if (s1
->beg
!= s2
->beg
)
2545 return s1
->beg
- s2
->beg
;
2546 if (s1
->end
!= s2
->end
)
2547 return s2
->end
- s1
->end
;
2551 /* Sort an array of overlays by priority. The array is modified in place.
2552 The return value is the new size; this may be smaller than the original
2553 size if some of the overlays were invalid or were window-specific. */
2555 sort_overlays (overlay_vec
, noverlays
, w
)
2556 Lisp_Object
*overlay_vec
;
2561 struct sortvec
*sortvec
;
2562 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2564 /* Put the valid and relevant overlays into sortvec. */
2566 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2569 Lisp_Object overlay
;
2571 overlay
= overlay_vec
[i
];
2572 if (OVERLAY_VALID (overlay
)
2573 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2574 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2576 /* If we're interested in a specific window, then ignore
2577 overlays that are limited to some other window. */
2582 window
= Foverlay_get (overlay
, Qwindow
);
2583 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2587 /* This overlay is good and counts: put it into sortvec. */
2588 sortvec
[j
].overlay
= overlay
;
2589 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2590 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2591 tem
= Foverlay_get (overlay
, Qpriority
);
2593 sortvec
[j
].priority
= XINT (tem
);
2595 sortvec
[j
].priority
= 0;
2601 /* Sort the overlays into the proper order: increasing priority. */
2604 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2606 for (i
= 0; i
< noverlays
; i
++)
2607 overlay_vec
[i
] = sortvec
[i
].overlay
;
2613 Lisp_Object string
, string2
;
2620 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2621 int size
; /* Allocated length of that array. */
2622 int used
; /* How much of the array is currently in use. */
2623 int bytes
; /* Total length of the strings in buf. */
2626 /* Buffers for storing information about the overlays touching a given
2627 position. These could be automatic variables in overlay_strings, but
2628 it's more efficient to hold onto the memory instead of repeatedly
2629 allocating and freeing it. */
2630 static struct sortstrlist overlay_heads
, overlay_tails
;
2631 static unsigned char *overlay_str_buf
;
2633 /* Allocated length of overlay_str_buf. */
2634 static int overlay_str_len
;
2636 /* A comparison function suitable for passing to qsort. */
2638 cmp_for_strings (as1
, as2
)
2641 struct sortstr
*s1
= (struct sortstr
*)as1
;
2642 struct sortstr
*s2
= (struct sortstr
*)as2
;
2643 if (s1
->size
!= s2
->size
)
2644 return s2
->size
- s1
->size
;
2645 if (s1
->priority
!= s2
->priority
)
2646 return s1
->priority
- s2
->priority
;
2651 record_overlay_string (ssl
, str
, str2
, pri
, size
)
2652 struct sortstrlist
*ssl
;
2653 Lisp_Object str
, str2
, pri
;
2658 if (ssl
->used
== ssl
->size
)
2664 ssl
->buf
= ((struct sortstr
*)
2665 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2667 ssl
->buf
[ssl
->used
].string
= str
;
2668 ssl
->buf
[ssl
->used
].string2
= str2
;
2669 ssl
->buf
[ssl
->used
].size
= size
;
2670 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2673 if (NILP (current_buffer
->enable_multibyte_characters
))
2674 nbytes
= XSTRING (str
)->size
;
2675 else if (! STRING_MULTIBYTE (str
))
2676 nbytes
= count_size_as_multibyte (XSTRING (str
)->data
,
2677 STRING_BYTES (XSTRING (str
)));
2679 nbytes
= STRING_BYTES (XSTRING (str
));
2681 ssl
->bytes
+= nbytes
;
2685 if (NILP (current_buffer
->enable_multibyte_characters
))
2686 nbytes
= XSTRING (str2
)->size
;
2687 else if (! STRING_MULTIBYTE (str2
))
2688 nbytes
= count_size_as_multibyte (XSTRING (str2
)->data
,
2689 STRING_BYTES (XSTRING (str2
)));
2691 nbytes
= STRING_BYTES (XSTRING (str2
));
2693 ssl
->bytes
+= nbytes
;
2697 /* Return the concatenation of the strings associated with overlays that
2698 begin or end at POS, ignoring overlays that are specific to a window
2699 other than W. The strings are concatenated in the appropriate order:
2700 shorter overlays nest inside longer ones, and higher priority inside
2701 lower. Normally all of the after-strings come first, but zero-sized
2702 overlays have their after-strings ride along with the before-strings
2703 because it would look strange to print them inside-out.
2705 Returns the string length, and stores the contents indirectly through
2706 PSTR, if that variable is non-null. The string may be overwritten by
2707 subsequent calls. */
2710 overlay_strings (pos
, w
, pstr
)
2713 unsigned char **pstr
;
2715 Lisp_Object ov
, overlay
, window
, str
;
2716 int startpos
, endpos
;
2717 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
2719 overlay_heads
.used
= overlay_heads
.bytes
= 0;
2720 overlay_tails
.used
= overlay_tails
.bytes
= 0;
2721 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
2723 overlay
= XCAR (ov
);
2724 if (!OVERLAYP (overlay
))
2727 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2728 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2731 if (endpos
!= pos
&& startpos
!= pos
)
2733 window
= Foverlay_get (overlay
, Qwindow
);
2734 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2737 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2738 record_overlay_string (&overlay_heads
, str
,
2740 ? Foverlay_get (overlay
, Qafter_string
)
2742 Foverlay_get (overlay
, Qpriority
),
2744 else if (endpos
== pos
2745 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2746 record_overlay_string (&overlay_tails
, str
, Qnil
,
2747 Foverlay_get (overlay
, Qpriority
),
2750 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
2752 overlay
= XCAR (ov
);
2753 if (!OVERLAYP (overlay
))
2756 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2757 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2760 if (endpos
!= pos
&& startpos
!= pos
)
2762 window
= Foverlay_get (overlay
, Qwindow
);
2763 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2766 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2767 record_overlay_string (&overlay_heads
, str
,
2769 ? Foverlay_get (overlay
, Qafter_string
)
2771 Foverlay_get (overlay
, Qpriority
),
2773 else if (endpos
== pos
2774 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2775 record_overlay_string (&overlay_tails
, str
, Qnil
,
2776 Foverlay_get (overlay
, Qpriority
),
2779 if (overlay_tails
.used
> 1)
2780 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
2782 if (overlay_heads
.used
> 1)
2783 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
2785 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
2790 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
2792 if (total
> overlay_str_len
)
2794 overlay_str_len
= total
;
2795 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
2798 p
= overlay_str_buf
;
2799 for (i
= overlay_tails
.used
; --i
>= 0;)
2802 tem
= overlay_tails
.buf
[i
].string
;
2803 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2804 STRING_BYTES (XSTRING (tem
)),
2805 STRING_MULTIBYTE (tem
), multibyte
);
2808 for (i
= 0; i
< overlay_heads
.used
; ++i
)
2811 tem
= overlay_heads
.buf
[i
].string
;
2812 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2813 STRING_BYTES (XSTRING (tem
)),
2814 STRING_MULTIBYTE (tem
), multibyte
);
2816 tem
= overlay_heads
.buf
[i
].string2
;
2819 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2820 STRING_BYTES (XSTRING (tem
)),
2821 STRING_MULTIBYTE (tem
), multibyte
);
2825 if (p
!= overlay_str_buf
+ total
)
2828 *pstr
= overlay_str_buf
;
2834 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2837 recenter_overlay_lists (buf
, pos
)
2841 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
2843 /* See if anything in overlays_before should move to overlays_after. */
2845 /* We don't strictly need prev in this loop; it should always be nil.
2846 But we use it for symmetry and in case that should cease to be true
2847 with some future change. */
2849 for (tail
= buf
->overlays_before
;
2851 prev
= tail
, tail
= next
)
2854 overlay
= XCAR (tail
);
2856 /* If the overlay is not valid, get rid of it. */
2857 if (!OVERLAY_VALID (overlay
))
2862 /* Splice the cons cell TAIL out of overlays_before. */
2866 buf
->overlays_before
= next
;
2872 beg
= OVERLAY_START (overlay
);
2873 end
= OVERLAY_END (overlay
);
2875 if (OVERLAY_POSITION (end
) > pos
)
2877 /* OVERLAY needs to be moved. */
2878 int where
= OVERLAY_POSITION (beg
);
2879 Lisp_Object other
, other_prev
;
2881 /* Splice the cons cell TAIL out of overlays_before. */
2885 buf
->overlays_before
= next
;
2887 /* Search thru overlays_after for where to put it. */
2889 for (other
= buf
->overlays_after
;
2891 other_prev
= other
, other
= XCDR (other
))
2893 Lisp_Object otherbeg
, otheroverlay
;
2895 otheroverlay
= XCAR (other
);
2896 if (! OVERLAY_VALID (otheroverlay
))
2899 otherbeg
= OVERLAY_START (otheroverlay
);
2900 if (OVERLAY_POSITION (otherbeg
) >= where
)
2904 /* Add TAIL to overlays_after before OTHER. */
2905 XCDR (tail
) = other
;
2906 if (!NILP (other_prev
))
2907 XCDR (other_prev
) = tail
;
2909 buf
->overlays_after
= tail
;
2913 /* We've reached the things that should stay in overlays_before.
2914 All the rest of overlays_before must end even earlier,
2919 /* See if anything in overlays_after should be in overlays_before. */
2921 for (tail
= buf
->overlays_after
;
2923 prev
= tail
, tail
= next
)
2926 overlay
= XCAR (tail
);
2928 /* If the overlay is not valid, get rid of it. */
2929 if (!OVERLAY_VALID (overlay
))
2934 /* Splice the cons cell TAIL out of overlays_after. */
2938 buf
->overlays_after
= next
;
2944 beg
= OVERLAY_START (overlay
);
2945 end
= OVERLAY_END (overlay
);
2947 /* Stop looking, when we know that nothing further
2948 can possibly end before POS. */
2949 if (OVERLAY_POSITION (beg
) > pos
)
2952 if (OVERLAY_POSITION (end
) <= pos
)
2954 /* OVERLAY needs to be moved. */
2955 int where
= OVERLAY_POSITION (end
);
2956 Lisp_Object other
, other_prev
;
2958 /* Splice the cons cell TAIL out of overlays_after. */
2962 buf
->overlays_after
= next
;
2964 /* Search thru overlays_before for where to put it. */
2966 for (other
= buf
->overlays_before
;
2968 other_prev
= other
, other
= XCDR (other
))
2970 Lisp_Object otherend
, otheroverlay
;
2972 otheroverlay
= XCAR (other
);
2973 if (! OVERLAY_VALID (otheroverlay
))
2976 otherend
= OVERLAY_END (otheroverlay
);
2977 if (OVERLAY_POSITION (otherend
) <= where
)
2981 /* Add TAIL to overlays_before before OTHER. */
2982 XCDR (tail
) = other
;
2983 if (!NILP (other_prev
))
2984 XCDR (other_prev
) = tail
;
2986 buf
->overlays_before
= tail
;
2991 XSETFASTINT (buf
->overlay_center
, pos
);
2995 adjust_overlays_for_insert (pos
, length
)
2999 /* After an insertion, the lists are still sorted properly,
3000 but we may need to update the value of the overlay center. */
3001 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
3002 XSETFASTINT (current_buffer
->overlay_center
,
3003 XFASTINT (current_buffer
->overlay_center
) + length
);
3007 adjust_overlays_for_delete (pos
, length
)
3011 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
3012 /* The deletion was to our right. No change needed; the before- and
3013 after-lists are still consistent. */
3015 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
3016 /* The deletion was to our left. We need to adjust the center value
3017 to account for the change in position, but the lists are consistent
3018 given the new value. */
3019 XSETFASTINT (current_buffer
->overlay_center
,
3020 XFASTINT (current_buffer
->overlay_center
) - length
);
3022 /* We're right in the middle. There might be things on the after-list
3023 that now belong on the before-list. Recentering will move them,
3024 and also update the center point. */
3025 recenter_overlay_lists (current_buffer
, pos
);
3028 /* Fix up overlays that were garbled as a result of permuting markers
3029 in the range START through END. Any overlay with at least one
3030 endpoint in this range will need to be unlinked from the overlay
3031 list and reinserted in its proper place.
3032 Such an overlay might even have negative size at this point.
3033 If so, we'll reverse the endpoints. Can you think of anything
3034 better to do in this situation? */
3036 fix_overlays_in_range (start
, end
)
3037 register int start
, end
;
3039 Lisp_Object overlay
;
3040 Lisp_Object before_list
, after_list
;
3041 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
3042 int startpos
, endpos
;
3044 /* This algorithm shifts links around instead of consing and GCing.
3045 The loop invariant is that before_list (resp. after_list) is a
3046 well-formed list except that its last element, the one that
3047 *pbefore (resp. *pafter) points to, is still uninitialized.
3048 So it's not a bug that before_list isn't initialized, although
3049 it may look strange. */
3050 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
3052 overlay
= XCAR (*ptail
);
3053 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3056 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3058 || (startpos
>= start
&& startpos
< end
))
3060 /* If the overlay is backwards, fix that now. */
3061 if (startpos
> endpos
)
3064 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
3066 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
3068 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
3070 /* Add it to the end of the wrong list. Later on,
3071 recenter_overlay_lists will move it to the right place. */
3072 if (endpos
< XINT (current_buffer
->overlay_center
))
3075 pafter
= &XCDR (*ptail
);
3080 pbefore
= &XCDR (*ptail
);
3082 *ptail
= XCDR (*ptail
);
3085 ptail
= &XCDR (*ptail
);
3087 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
3089 overlay
= XCAR (*ptail
);
3090 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3091 if (startpos
>= end
)
3093 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3094 if (startpos
>= start
3095 || (endpos
>= start
&& endpos
< end
))
3097 if (startpos
> endpos
)
3100 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
3102 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
3104 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
3106 if (endpos
< XINT (current_buffer
->overlay_center
))
3109 pafter
= &XCDR (*ptail
);
3114 pbefore
= &XCDR (*ptail
);
3116 *ptail
= XCDR (*ptail
);
3119 ptail
= &XCDR (*ptail
);
3122 /* Splice the constructed (wrong) lists into the buffer's lists,
3123 and let the recenter function make it sane again. */
3124 *pbefore
= current_buffer
->overlays_before
;
3125 current_buffer
->overlays_before
= before_list
;
3126 recenter_overlay_lists (current_buffer
,
3127 XINT (current_buffer
->overlay_center
));
3129 *pafter
= current_buffer
->overlays_after
;
3130 current_buffer
->overlays_after
= after_list
;
3131 recenter_overlay_lists (current_buffer
,
3132 XINT (current_buffer
->overlay_center
));
3135 /* We have two types of overlay: the one whose ending marker is
3136 after-insertion-marker (this is the usual case) and the one whose
3137 ending marker is before-insertion-marker. When `overlays_before'
3138 contains overlays of the latter type and the former type in this
3139 order and both overlays end at inserting position, inserting a text
3140 increases only the ending marker of the latter type, which results
3141 in incorrect ordering of `overlays_before'.
3143 This function fixes ordering of overlays in the slot
3144 `overlays_before' of the buffer *BP. Before the insertion, `point'
3145 was at PREV, and now is at POS. */
3148 fix_overlays_before (bp
, prev
, pos
)
3152 Lisp_Object
*tailp
= &bp
->overlays_before
;
3153 Lisp_Object
*right_place
;
3156 /* After the insertion, the several overlays may be in incorrect
3157 order. The possibility is that, in the list `overlays_before',
3158 an overlay which ends at POS appears after an overlay which ends
3159 at PREV. Since POS is greater than PREV, we must fix the
3160 ordering of these overlays, by moving overlays ends at POS before
3161 the overlays ends at PREV. */
3163 /* At first, find a place where disordered overlays should be linked
3164 in. It is where an overlay which end before POS exists. (i.e. an
3165 overlay whose ending marker is after-insertion-marker if disorder
3167 while (!NILP (*tailp
)
3168 && ((end
= OVERLAY_POSITION (OVERLAY_END (XCAR (*tailp
))))
3170 tailp
= &XCDR (*tailp
);
3172 /* If we don't find such an overlay,
3173 or the found one ends before PREV,
3174 or the found one is the last one in the list,
3175 we don't have to fix anything. */
3178 || NILP (XCDR (*tailp
)))
3181 right_place
= tailp
;
3182 tailp
= &XCDR (*tailp
);
3184 /* Now, end position of overlays in the list *TAILP should be before
3185 or equal to PREV. In the loop, an overlay which ends at POS is
3186 moved ahead to the place pointed by RIGHT_PLACE. If we found an
3187 overlay which ends before PREV, the remaining overlays are in
3189 while (!NILP (*tailp
))
3191 end
= OVERLAY_POSITION (OVERLAY_END (XCAR (*tailp
)));
3194 { /* This overlay is disordered. */
3195 Lisp_Object found
= *tailp
;
3197 /* Unlink the found overlay. */
3198 *tailp
= XCDR (found
);
3199 /* Move an overlay at RIGHT_PLACE to the next of the found one. */
3200 XCDR (found
) = *right_place
;
3201 /* Link it into the right place. */
3202 *right_place
= found
;
3204 else if (end
== prev
)
3205 tailp
= &XCDR (*tailp
);
3206 else /* No more disordered overlay. */
3211 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
3212 "Return t if OBJECT is an overlay.")
3216 return (OVERLAYP (object
) ? Qt
: Qnil
);
3219 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
3220 "Create a new overlay with range BEG to END in BUFFER.\n\
3221 If omitted, BUFFER defaults to the current buffer.\n\
3222 BEG and END may be integers or markers.\n\
3223 The fourth arg FRONT-ADVANCE, if non-nil, makes the\n\
3224 front delimiter advance when text is inserted there.\n\
3225 The fifth arg REAR-ADVANCE, if non-nil, makes the\n\
3226 rear delimiter advance when text is inserted there.")
3227 (beg
, end
, buffer
, front_advance
, rear_advance
)
3228 Lisp_Object beg
, end
, buffer
;
3229 Lisp_Object front_advance
, rear_advance
;
3231 Lisp_Object overlay
;
3235 XSETBUFFER (buffer
, current_buffer
);
3237 CHECK_BUFFER (buffer
, 2);
3239 && ! EQ (Fmarker_buffer (beg
), buffer
))
3240 error ("Marker points into wrong buffer");
3242 && ! EQ (Fmarker_buffer (end
), buffer
))
3243 error ("Marker points into wrong buffer");
3245 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
3246 CHECK_NUMBER_COERCE_MARKER (end
, 1);
3248 if (XINT (beg
) > XINT (end
))
3251 temp
= beg
; beg
= end
; end
= temp
;
3254 b
= XBUFFER (buffer
);
3256 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
3257 end
= Fset_marker (Fmake_marker (), end
, buffer
);
3259 if (!NILP (front_advance
))
3260 XMARKER (beg
)->insertion_type
= 1;
3261 if (!NILP (rear_advance
))
3262 XMARKER (end
)->insertion_type
= 1;
3264 overlay
= allocate_misc ();
3265 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
3266 XOVERLAY (overlay
)->start
= beg
;
3267 XOVERLAY (overlay
)->end
= end
;
3268 XOVERLAY (overlay
)->plist
= Qnil
;
3270 /* Put the new overlay on the wrong list. */
3271 end
= OVERLAY_END (overlay
);
3272 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
3273 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
3275 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
3277 /* This puts it in the right list, and in the right order. */
3278 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
3280 /* We don't need to redisplay the region covered by the overlay, because
3281 the overlay has no properties at the moment. */
3286 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3289 modify_overlay (buf
, start
, end
)
3299 start
= end
; end
= temp
;
3302 BUF_COMPUTE_UNCHANGED (buf
, start
, end
);
3304 /* If this is a buffer not in the selected window,
3305 we must do other windows. */
3306 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
3307 windows_or_buffers_changed
= 1;
3308 /* If multiple windows show this buffer, we must do other windows. */
3309 else if (buffer_shared
> 1)
3310 windows_or_buffers_changed
= 1;
3312 ++BUF_OVERLAY_MODIFF (buf
);
3316 Lisp_Object
Fdelete_overlay ();
3318 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
3319 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
3320 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
3321 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
3323 (overlay
, beg
, end
, buffer
)
3324 Lisp_Object overlay
, beg
, end
, buffer
;
3326 struct buffer
*b
, *ob
;
3327 Lisp_Object obuffer
;
3328 int count
= specpdl_ptr
- specpdl
;
3330 CHECK_OVERLAY (overlay
, 0);
3332 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3334 XSETBUFFER (buffer
, current_buffer
);
3335 CHECK_BUFFER (buffer
, 3);
3338 && ! EQ (Fmarker_buffer (beg
), buffer
))
3339 error ("Marker points into wrong buffer");
3341 && ! EQ (Fmarker_buffer (end
), buffer
))
3342 error ("Marker points into wrong buffer");
3344 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
3345 CHECK_NUMBER_COERCE_MARKER (end
, 1);
3347 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3348 return Fdelete_overlay (overlay
);
3350 if (XINT (beg
) > XINT (end
))
3353 temp
= beg
; beg
= end
; end
= temp
;
3356 specbind (Qinhibit_quit
, Qt
);
3358 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3359 b
= XBUFFER (buffer
);
3360 ob
= BUFFERP (obuffer
) ? XBUFFER (obuffer
) : (struct buffer
*) 0;
3362 /* If the overlay has changed buffers, do a thorough redisplay. */
3363 if (!EQ (buffer
, obuffer
))
3365 /* Redisplay where the overlay was. */
3366 if (!NILP (obuffer
))
3371 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3372 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3374 modify_overlay (ob
, o_beg
, o_end
);
3377 /* Redisplay where the overlay is going to be. */
3378 modify_overlay (b
, XINT (beg
), XINT (end
));
3381 /* Redisplay the area the overlay has just left, or just enclosed. */
3385 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3386 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3388 if (o_beg
== XINT (beg
))
3389 modify_overlay (b
, o_end
, XINT (end
));
3390 else if (o_end
== XINT (end
))
3391 modify_overlay (b
, o_beg
, XINT (beg
));
3394 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
3395 if (XINT (end
) > o_end
) o_end
= XINT (end
);
3396 modify_overlay (b
, o_beg
, o_end
);
3400 if (!NILP (obuffer
))
3402 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
3403 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
3406 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
3407 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
3409 /* Put the overlay on the wrong list. */
3410 end
= OVERLAY_END (overlay
);
3411 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
3412 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
3414 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
3416 /* This puts it in the right list, and in the right order. */
3417 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
3419 return unbind_to (count
, overlay
);
3422 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
3423 "Delete the overlay OVERLAY from its buffer.")
3425 Lisp_Object overlay
;
3429 int count
= specpdl_ptr
- specpdl
;
3431 CHECK_OVERLAY (overlay
, 0);
3433 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3437 b
= XBUFFER (buffer
);
3439 specbind (Qinhibit_quit
, Qt
);
3441 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
3442 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
3445 marker_position (OVERLAY_START (overlay
)),
3446 marker_position (OVERLAY_END (overlay
)));
3448 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
3449 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
3451 return unbind_to (count
, Qnil
);
3454 /* Overlay dissection functions. */
3456 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3457 "Return the position at which OVERLAY starts.")
3459 Lisp_Object overlay
;
3461 CHECK_OVERLAY (overlay
, 0);
3463 return (Fmarker_position (OVERLAY_START (overlay
)));
3466 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3467 "Return the position at which OVERLAY ends.")
3469 Lisp_Object overlay
;
3471 CHECK_OVERLAY (overlay
, 0);
3473 return (Fmarker_position (OVERLAY_END (overlay
)));
3476 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3477 "Return the buffer OVERLAY belongs to.")
3479 Lisp_Object overlay
;
3481 CHECK_OVERLAY (overlay
, 0);
3483 return Fmarker_buffer (OVERLAY_START (overlay
));
3486 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3487 "Return a list of the properties on OVERLAY.\n\
3488 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
3491 Lisp_Object overlay
;
3493 CHECK_OVERLAY (overlay
, 0);
3495 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3499 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3500 "Return a list of the overlays that contain position POS.")
3505 Lisp_Object
*overlay_vec
;
3509 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3512 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3514 /* Put all the overlays we want in a vector in overlay_vec.
3515 Store the length in len. */
3516 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3517 (int *) 0, (int *) 0);
3519 /* Make a list of them all. */
3520 result
= Flist (noverlays
, overlay_vec
);
3522 xfree (overlay_vec
);
3526 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3527 "Return a list of the overlays that overlap the region BEG ... END.\n\
3528 Overlap means that at least one character is contained within the overlay\n\
3529 and also contained within the specified region.\n\
3530 Empty overlays are included in the result if they are located at BEG\n\
3531 or between BEG and END.")
3533 Lisp_Object beg
, end
;
3536 Lisp_Object
*overlay_vec
;
3540 CHECK_NUMBER_COERCE_MARKER (beg
, 0);
3541 CHECK_NUMBER_COERCE_MARKER (end
, 0);
3544 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3546 /* Put all the overlays we want in a vector in overlay_vec.
3547 Store the length in len. */
3548 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3549 (int *) 0, (int *) 0);
3551 /* Make a list of them all. */
3552 result
= Flist (noverlays
, overlay_vec
);
3554 xfree (overlay_vec
);
3558 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3560 "Return the next position after POS where an overlay starts or ends.\n\
3561 If there are no more overlay boundaries after POS, return (point-max).")
3567 Lisp_Object
*overlay_vec
;
3571 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3574 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3576 /* Put all the overlays we want in a vector in overlay_vec.
3577 Store the length in len.
3578 endpos gets the position where the next overlay starts. */
3579 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3580 &endpos
, (int *) 0);
3582 /* If any of these overlays ends before endpos,
3583 use its ending point instead. */
3584 for (i
= 0; i
< noverlays
; i
++)
3589 oend
= OVERLAY_END (overlay_vec
[i
]);
3590 oendpos
= OVERLAY_POSITION (oend
);
3591 if (oendpos
< endpos
)
3595 xfree (overlay_vec
);
3596 return make_number (endpos
);
3599 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
3600 Sprevious_overlay_change
, 1, 1, 0,
3601 "Return the previous position before POS where an overlay starts or ends.\n\
3602 If there are no more overlay boundaries before POS, return (point-min).")
3608 Lisp_Object
*overlay_vec
;
3611 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3614 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3616 /* At beginning of buffer, we know the answer;
3617 avoid bug subtracting 1 below. */
3618 if (XINT (pos
) == BEGV
)
3621 /* Put all the overlays we want in a vector in overlay_vec.
3622 Store the length in len.
3623 prevpos gets the position of the previous change. */
3624 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3625 (int *) 0, &prevpos
);
3627 xfree (overlay_vec
);
3628 return make_number (prevpos
);
3631 /* These functions are for debugging overlays. */
3633 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
3634 "Return a pair of lists giving all the overlays of the current buffer.\n\
3635 The car has all the overlays before the overlay center;\n\
3636 the cdr has all the overlays after the overlay center.\n\
3637 Recentering overlays moves overlays between these lists.\n\
3638 The lists you get are copies, so that changing them has no effect.\n\
3639 However, the overlays you get are the real objects that the buffer uses.")
3642 Lisp_Object before
, after
;
3643 before
= current_buffer
->overlays_before
;
3645 before
= Fcopy_sequence (before
);
3646 after
= current_buffer
->overlays_after
;
3648 after
= Fcopy_sequence (after
);
3650 return Fcons (before
, after
);
3653 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
3654 "Recenter the overlays of the current buffer around position POS.")
3658 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3660 recenter_overlay_lists (current_buffer
, XINT (pos
));
3664 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
3665 "Get the property of overlay OVERLAY with property name PROP.")
3667 Lisp_Object overlay
, prop
;
3669 Lisp_Object plist
, fallback
;
3671 CHECK_OVERLAY (overlay
, 0);
3675 for (plist
= XOVERLAY (overlay
)->plist
;
3676 CONSP (plist
) && CONSP (XCDR (plist
));
3677 plist
= XCDR (XCDR (plist
)))
3679 if (EQ (XCAR (plist
), prop
))
3680 return XCAR (XCDR (plist
));
3681 else if (EQ (XCAR (plist
), Qcategory
))
3684 tem
= Fcar (Fcdr (plist
));
3686 fallback
= Fget (tem
, prop
);
3693 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
3694 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
3695 (overlay
, prop
, value
)
3696 Lisp_Object overlay
, prop
, value
;
3698 Lisp_Object tail
, buffer
;
3701 CHECK_OVERLAY (overlay
, 0);
3703 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3705 for (tail
= XOVERLAY (overlay
)->plist
;
3706 CONSP (tail
) && CONSP (XCDR (tail
));
3707 tail
= XCDR (XCDR (tail
)))
3708 if (EQ (XCAR (tail
), prop
))
3710 changed
= !EQ (XCAR (XCDR (tail
)), value
);
3711 XCAR (XCDR (tail
)) = value
;
3714 /* It wasn't in the list, so add it to the front. */
3715 changed
= !NILP (value
);
3716 XOVERLAY (overlay
)->plist
3717 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
3719 if (! NILP (buffer
))
3722 modify_overlay (XBUFFER (buffer
),
3723 marker_position (OVERLAY_START (overlay
)),
3724 marker_position (OVERLAY_END (overlay
)));
3725 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
3726 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
3727 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
3728 Fdelete_overlay (overlay
);
3733 /* Subroutine of report_overlay_modification. */
3735 /* Lisp vector holding overlay hook functions to call.
3736 Vector elements come in pairs.
3737 Each even-index element is a list of hook functions.
3738 The following odd-index element is the overlay they came from.
3740 Before the buffer change, we fill in this vector
3741 as we call overlay hook functions.
3742 After the buffer change, we get the functions to call from this vector.
3743 This way we always call the same functions before and after the change. */
3744 static Lisp_Object last_overlay_modification_hooks
;
3746 /* Number of elements actually used in last_overlay_modification_hooks. */
3747 static int last_overlay_modification_hooks_used
;
3749 /* Add one functionlist/overlay pair
3750 to the end of last_overlay_modification_hooks. */
3753 add_overlay_mod_hooklist (functionlist
, overlay
)
3754 Lisp_Object functionlist
, overlay
;
3756 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
3758 if (last_overlay_modification_hooks_used
== oldsize
)
3761 old
= last_overlay_modification_hooks
;
3762 last_overlay_modification_hooks
3763 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
3764 bcopy (XVECTOR (old
)->contents
,
3765 XVECTOR (last_overlay_modification_hooks
)->contents
,
3766 sizeof (Lisp_Object
) * oldsize
);
3768 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = functionlist
;
3769 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = overlay
;
3772 /* Run the modification-hooks of overlays that include
3773 any part of the text in START to END.
3774 If this change is an insertion, also
3775 run the insert-before-hooks of overlay starting at END,
3776 and the insert-after-hooks of overlay ending at START.
3778 This is called both before and after the modification.
3779 AFTER is nonzero when we call after the modification.
3781 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3782 When AFTER is nonzero, they are the start position,
3783 the position after the inserted new text,
3784 and the length of deleted or replaced old text. */
3787 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
3788 Lisp_Object start
, end
;
3790 Lisp_Object arg1
, arg2
, arg3
;
3792 Lisp_Object prop
, overlay
, tail
;
3793 /* 1 if this change is an insertion. */
3794 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
3796 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
3800 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
3804 /* Call the functions recorded in last_overlay_modification_hooks
3805 rather than scanning the overlays again.
3806 First copy the vector contents, in case some of these hooks
3807 do subsequent modification of the buffer. */
3808 int size
= last_overlay_modification_hooks_used
;
3809 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
3812 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
3813 copy
, size
* sizeof (Lisp_Object
));
3815 gcpro1
.nvars
= size
;
3817 for (i
= 0; i
< size
;)
3819 Lisp_Object prop
, overlay
;
3821 overlay
= copy
[i
++];
3822 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3828 /* We are being called before a change.
3829 Scan the overlays to find the functions to call. */
3830 last_overlay_modification_hooks_used
= 0;
3832 for (tail
= current_buffer
->overlays_before
;
3836 int startpos
, endpos
;
3837 Lisp_Object ostart
, oend
;
3839 overlay
= XCAR (tail
);
3841 ostart
= OVERLAY_START (overlay
);
3842 oend
= OVERLAY_END (overlay
);
3843 endpos
= OVERLAY_POSITION (oend
);
3844 if (XFASTINT (start
) > endpos
)
3846 startpos
= OVERLAY_POSITION (ostart
);
3847 if (insertion
&& (XFASTINT (start
) == startpos
3848 || XFASTINT (end
) == startpos
))
3850 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3853 /* Copy TAIL in case the hook recenters the overlay lists. */
3855 tail
= Fcopy_sequence (tail
);
3857 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3860 if (insertion
&& (XFASTINT (start
) == endpos
3861 || XFASTINT (end
) == endpos
))
3863 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3867 tail
= Fcopy_sequence (tail
);
3869 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3872 /* Test for intersecting intervals. This does the right thing
3873 for both insertion and deletion. */
3874 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3876 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3880 tail
= Fcopy_sequence (tail
);
3882 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3888 for (tail
= current_buffer
->overlays_after
;
3892 int startpos
, endpos
;
3893 Lisp_Object ostart
, oend
;
3895 overlay
= XCAR (tail
);
3897 ostart
= OVERLAY_START (overlay
);
3898 oend
= OVERLAY_END (overlay
);
3899 startpos
= OVERLAY_POSITION (ostart
);
3900 endpos
= OVERLAY_POSITION (oend
);
3901 if (XFASTINT (end
) < startpos
)
3903 if (insertion
&& (XFASTINT (start
) == startpos
3904 || XFASTINT (end
) == startpos
))
3906 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3910 tail
= Fcopy_sequence (tail
);
3912 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3915 if (insertion
&& (XFASTINT (start
) == endpos
3916 || XFASTINT (end
) == endpos
))
3918 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3922 tail
= Fcopy_sequence (tail
);
3924 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3927 /* Test for intersecting intervals. This does the right thing
3928 for both insertion and deletion. */
3929 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3931 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3935 tail
= Fcopy_sequence (tail
);
3937 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3946 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
3947 Lisp_Object list
, overlay
;
3949 Lisp_Object arg1
, arg2
, arg3
;
3951 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3953 GCPRO4 (list
, arg1
, arg2
, arg3
);
3955 add_overlay_mod_hooklist (list
, overlay
);
3957 while (!NILP (list
))
3960 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
3962 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
3968 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3971 evaporate_overlays (pos
)
3974 Lisp_Object tail
, overlay
, hit_list
;
3977 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
3978 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
3982 overlay
= XCAR (tail
);
3983 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3986 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
3987 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3988 hit_list
= Fcons (overlay
, hit_list
);
3991 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
3995 overlay
= XCAR (tail
);
3996 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3999 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
4000 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4001 hit_list
= Fcons (overlay
, hit_list
);
4003 for (; CONSP (hit_list
); hit_list
= XCDR (hit_list
))
4004 Fdelete_overlay (XCAR (hit_list
));
4007 /* Somebody has tried to store a value with an unacceptable type
4008 in the slot with offset OFFSET. */
4011 buffer_slot_type_mismatch (offset
)
4017 switch (XINT (PER_BUFFER_TYPE (offset
)))
4020 type_name
= "integers";
4024 type_name
= "strings";
4028 type_name
= "symbols";
4035 sym
= PER_BUFFER_SYMBOL (offset
);
4036 error ("Only %s should be stored in the buffer-local variable %s",
4037 type_name
, XSYMBOL (sym
)->name
->data
);
4046 bzero (buffer_permanent_local_flags
, sizeof buffer_permanent_local_flags
);
4048 /* Make sure all markable slots in buffer_defaults
4049 are initialized reasonably, so mark_buffer won't choke. */
4050 reset_buffer (&buffer_defaults
);
4051 reset_buffer_local_variables (&buffer_defaults
, 1);
4052 reset_buffer (&buffer_local_symbols
);
4053 reset_buffer_local_variables (&buffer_local_symbols
, 1);
4054 /* Prevent GC from getting confused. */
4055 buffer_defaults
.text
= &buffer_defaults
.own_text
;
4056 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
4057 BUF_INTERVALS (&buffer_defaults
) = 0;
4058 BUF_INTERVALS (&buffer_local_symbols
) = 0;
4059 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
4060 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
4062 /* Set up the default values of various buffer slots. */
4063 /* Must do these before making the first buffer! */
4065 /* real setup is done in bindings.el */
4066 buffer_defaults
.mode_line_format
= build_string ("%-");
4067 buffer_defaults
.header_line_format
= Qnil
;
4068 buffer_defaults
.abbrev_mode
= Qnil
;
4069 buffer_defaults
.overwrite_mode
= Qnil
;
4070 buffer_defaults
.case_fold_search
= Qt
;
4071 buffer_defaults
.auto_fill_function
= Qnil
;
4072 buffer_defaults
.selective_display
= Qnil
;
4074 buffer_defaults
.selective_display_ellipses
= Qt
;
4076 buffer_defaults
.abbrev_table
= Qnil
;
4077 buffer_defaults
.display_table
= Qnil
;
4078 buffer_defaults
.undo_list
= Qnil
;
4079 buffer_defaults
.mark_active
= Qnil
;
4080 buffer_defaults
.file_format
= Qnil
;
4081 buffer_defaults
.overlays_before
= Qnil
;
4082 buffer_defaults
.overlays_after
= Qnil
;
4083 XSETFASTINT (buffer_defaults
.overlay_center
, BEG
);
4085 XSETFASTINT (buffer_defaults
.tab_width
, 8);
4086 buffer_defaults
.truncate_lines
= Qnil
;
4087 buffer_defaults
.ctl_arrow
= Qt
;
4088 buffer_defaults
.direction_reversed
= Qnil
;
4089 buffer_defaults
.cursor_type
= Qt
;
4090 buffer_defaults
.extra_line_spacing
= Qnil
;
4093 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
4095 buffer_defaults
.enable_multibyte_characters
= Qt
;
4096 buffer_defaults
.buffer_file_coding_system
= Qnil
;
4097 XSETFASTINT (buffer_defaults
.fill_column
, 70);
4098 XSETFASTINT (buffer_defaults
.left_margin
, 0);
4099 buffer_defaults
.cache_long_line_scans
= Qnil
;
4100 buffer_defaults
.file_truename
= Qnil
;
4101 XSETFASTINT (buffer_defaults
.display_count
, 0);
4102 buffer_defaults
.indicate_empty_lines
= Qnil
;
4103 buffer_defaults
.scroll_up_aggressively
= Qnil
;
4104 buffer_defaults
.scroll_down_aggressively
= Qnil
;
4105 buffer_defaults
.display_time
= Qnil
;
4107 /* Assign the local-flags to the slots that have default values.
4108 The local flag is a bit that is used in the buffer
4109 to say that it has its own local value for the slot.
4110 The local flag bits are in the local_var_flags slot of the buffer. */
4112 /* Nothing can work if this isn't true */
4113 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
4115 /* 0 means not a lisp var, -1 means always local, else mask */
4116 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
4117 XSETINT (buffer_local_flags
.filename
, -1);
4118 XSETINT (buffer_local_flags
.directory
, -1);
4119 XSETINT (buffer_local_flags
.backed_up
, -1);
4120 XSETINT (buffer_local_flags
.save_length
, -1);
4121 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
4122 XSETINT (buffer_local_flags
.read_only
, -1);
4123 XSETINT (buffer_local_flags
.major_mode
, -1);
4124 XSETINT (buffer_local_flags
.mode_name
, -1);
4125 XSETINT (buffer_local_flags
.undo_list
, -1);
4126 XSETINT (buffer_local_flags
.mark_active
, -1);
4127 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
4128 XSETINT (buffer_local_flags
.file_truename
, -1);
4129 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
4130 XSETINT (buffer_local_flags
.file_format
, -1);
4131 XSETINT (buffer_local_flags
.display_count
, -1);
4132 XSETINT (buffer_local_flags
.display_time
, -1);
4133 XSETINT (buffer_local_flags
.enable_multibyte_characters
, -1);
4136 XSETFASTINT (buffer_local_flags
.mode_line_format
, idx
); ++idx
;
4137 XSETFASTINT (buffer_local_flags
.abbrev_mode
, idx
); ++idx
;
4138 XSETFASTINT (buffer_local_flags
.overwrite_mode
, idx
); ++idx
;
4139 XSETFASTINT (buffer_local_flags
.case_fold_search
, idx
); ++idx
;
4140 XSETFASTINT (buffer_local_flags
.auto_fill_function
, idx
); ++idx
;
4141 XSETFASTINT (buffer_local_flags
.selective_display
, idx
); ++idx
;
4143 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, idx
); ++idx
;
4145 XSETFASTINT (buffer_local_flags
.tab_width
, idx
); ++idx
;
4146 XSETFASTINT (buffer_local_flags
.truncate_lines
, idx
); ++idx
;
4147 XSETFASTINT (buffer_local_flags
.ctl_arrow
, idx
); ++idx
;
4148 XSETFASTINT (buffer_local_flags
.fill_column
, idx
); ++idx
;
4149 XSETFASTINT (buffer_local_flags
.left_margin
, idx
); ++idx
;
4150 XSETFASTINT (buffer_local_flags
.abbrev_table
, idx
); ++idx
;
4151 XSETFASTINT (buffer_local_flags
.display_table
, idx
); ++idx
;
4153 XSETFASTINT (buffer_local_flags
.buffer_file_type
, idx
);
4154 /* Make this one a permanent local. */
4155 buffer_permanent_local_flags
[idx
++] = 1;
4157 XSETFASTINT (buffer_local_flags
.syntax_table
, idx
); ++idx
;
4158 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, idx
); ++idx
;
4159 XSETFASTINT (buffer_local_flags
.category_table
, idx
); ++idx
;
4160 XSETFASTINT (buffer_local_flags
.direction_reversed
, idx
); ++idx
;
4161 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, idx
);
4162 /* Make this one a permanent local. */
4163 buffer_permanent_local_flags
[idx
++] = 1;
4164 XSETFASTINT (buffer_local_flags
.left_margin_width
, idx
); ++idx
;
4165 XSETFASTINT (buffer_local_flags
.right_margin_width
, idx
); ++idx
;
4166 XSETFASTINT (buffer_local_flags
.indicate_empty_lines
, idx
); ++idx
;
4167 XSETFASTINT (buffer_local_flags
.scroll_up_aggressively
, idx
); ++idx
;
4168 XSETFASTINT (buffer_local_flags
.scroll_down_aggressively
, idx
); ++idx
;
4169 XSETFASTINT (buffer_local_flags
.header_line_format
, idx
); ++idx
;
4170 XSETFASTINT (buffer_local_flags
.cursor_type
, idx
); ++idx
;
4171 XSETFASTINT (buffer_local_flags
.extra_line_spacing
, idx
); ++idx
;
4173 /* Need more room? */
4174 if (idx
>= MAX_PER_BUFFER_VARS
)
4176 last_per_buffer_idx
= idx
;
4178 Vbuffer_alist
= Qnil
;
4182 QSFundamental
= build_string ("Fundamental");
4184 Qfundamental_mode
= intern ("fundamental-mode");
4185 buffer_defaults
.major_mode
= Qfundamental_mode
;
4187 Qmode_class
= intern ("mode-class");
4189 Qprotected_field
= intern ("protected-field");
4191 Qpermanent_local
= intern ("permanent-local");
4193 Qkill_buffer_hook
= intern ("kill-buffer-hook");
4195 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
4197 /* super-magic invisible buffer */
4198 Vbuffer_alist
= Qnil
;
4200 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
4202 inhibit_modification_hooks
= 0;
4208 char buf
[MAXPATHLEN
+1];
4210 struct stat dotstat
, pwdstat
;
4214 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
4215 if (NILP (buffer_defaults
.enable_multibyte_characters
))
4216 Fset_buffer_multibyte (Qnil
);
4218 /* If PWD is accurate, use it instead of calling getwd. This is faster
4219 when PWD is right, and may avoid a fatal error. */
4220 if ((pwd
= getenv ("PWD")) != 0
4221 && (IS_DIRECTORY_SEP (*pwd
) || (*pwd
&& IS_DEVICE_SEP (pwd
[1])))
4222 && stat (pwd
, &pwdstat
) == 0
4223 && stat (".", &dotstat
) == 0
4224 && dotstat
.st_ino
== pwdstat
.st_ino
4225 && dotstat
.st_dev
== pwdstat
.st_dev
4226 && strlen (pwd
) < MAXPATHLEN
)
4229 else if (getcwd (buf
, MAXPATHLEN
+1) == 0)
4230 fatal ("`getcwd' failed: %s\n", strerror (errno
));
4232 else if (getwd (buf
) == 0)
4233 fatal ("`getwd' failed: %s\n", buf
);
4237 /* Maybe this should really use some standard subroutine
4238 whose definition is filename syntax dependent. */
4240 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
4242 buf
[rc
] = DIRECTORY_SEP
;
4245 #endif /* not VMS */
4247 current_buffer
->directory
= build_string (buf
);
4249 /* Add /: to the front of the name
4250 if it would otherwise be treated as magic. */
4251 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
4253 /* If the default dir is just /, TEMP is non-nil
4254 because of the ange-ftp completion handler.
4255 However, it is not necessary to turn / into /:/.
4256 So avoid doing that. */
4257 && strcmp ("/", XSTRING (current_buffer
->directory
)->data
))
4258 current_buffer
->directory
4259 = concat2 (build_string ("/:"), current_buffer
->directory
);
4261 temp
= get_minibuffer (0);
4262 XBUFFER (temp
)->directory
= current_buffer
->directory
;
4265 /* initialize the buffer routines */
4269 staticpro (&last_overlay_modification_hooks
);
4270 last_overlay_modification_hooks
4271 = Fmake_vector (make_number (10), Qnil
);
4273 staticpro (&Vbuffer_defaults
);
4274 staticpro (&Vbuffer_local_symbols
);
4275 staticpro (&Qfundamental_mode
);
4276 staticpro (&Qmode_class
);
4277 staticpro (&QSFundamental
);
4278 staticpro (&Vbuffer_alist
);
4279 staticpro (&Qprotected_field
);
4280 staticpro (&Qpermanent_local
);
4281 staticpro (&Qkill_buffer_hook
);
4282 Qoverlayp
= intern ("overlayp");
4283 staticpro (&Qoverlayp
);
4284 Qevaporate
= intern ("evaporate");
4285 staticpro (&Qevaporate
);
4286 Qmodification_hooks
= intern ("modification-hooks");
4287 staticpro (&Qmodification_hooks
);
4288 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
4289 staticpro (&Qinsert_in_front_hooks
);
4290 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
4291 staticpro (&Qinsert_behind_hooks
);
4292 Qget_file_buffer
= intern ("get-file-buffer");
4293 staticpro (&Qget_file_buffer
);
4294 Qpriority
= intern ("priority");
4295 staticpro (&Qpriority
);
4296 Qwindow
= intern ("window");
4297 staticpro (&Qwindow
);
4298 Qbefore_string
= intern ("before-string");
4299 staticpro (&Qbefore_string
);
4300 Qafter_string
= intern ("after-string");
4301 staticpro (&Qafter_string
);
4302 Qfirst_change_hook
= intern ("first-change-hook");
4303 staticpro (&Qfirst_change_hook
);
4304 Qbefore_change_functions
= intern ("before-change-functions");
4305 staticpro (&Qbefore_change_functions
);
4306 Qafter_change_functions
= intern ("after-change-functions");
4307 staticpro (&Qafter_change_functions
);
4309 Fput (Qprotected_field
, Qerror_conditions
,
4310 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
4311 Fput (Qprotected_field
, Qerror_message
,
4312 build_string ("Attempt to modify a protected field"));
4314 /* All these use DEFVAR_LISP_NOPRO because the slots in
4315 buffer_defaults will all be marked via Vbuffer_defaults. */
4317 DEFVAR_LISP_NOPRO ("default-mode-line-format",
4318 &buffer_defaults
.mode_line_format
,
4319 "Default value of `mode-line-format' for buffers that don't override it.\n\
4320 This is the same as (default-value 'mode-line-format).");
4322 DEFVAR_LISP_NOPRO ("default-header-line-format",
4323 &buffer_defaults
.header_line_format
,
4324 "Default value of `header-line-format' for buffers that don't override it.\n\
4325 This is the same as (default-value 'header-line-format).");
4327 DEFVAR_LISP_NOPRO ("default-cursor-type", &buffer_defaults
.cursor_type
,
4328 "Default value of `cursor-type' for buffers that don't override it.\n\
4329 This is the same as (default-value 'cursor-type).");
4331 DEFVAR_LISP_NOPRO ("default-line-spacing",
4332 &buffer_defaults
.extra_line_spacing
,
4333 "Default value of `line-spacing' for buffers that don't override it.\n\
4334 This is the same as (default-value 'line-spacing).");
4336 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
4337 &buffer_defaults
.abbrev_mode
,
4338 "Default value of `abbrev-mode' for buffers that do not override it.\n\
4339 This is the same as (default-value 'abbrev-mode).");
4341 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
4342 &buffer_defaults
.ctl_arrow
,
4343 "Default value of `ctl-arrow' for buffers that do not override it.\n\
4344 This is the same as (default-value 'ctl-arrow).");
4346 DEFVAR_LISP_NOPRO ("default-direction-reversed",
4347 &buffer_defaults
.direction_reversed
,
4348 "Default value of `direction_reversed' for buffers that do not override it.\n\
4349 This is the same as (default-value 'direction-reversed).");
4351 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
4352 &buffer_defaults
.enable_multibyte_characters
,
4353 "*Default value of `enable-multibyte-characters' for buffers not overriding it.\n\
4354 This is the same as (default-value 'enable-multibyte-characters).");
4356 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
4357 &buffer_defaults
.buffer_file_coding_system
,
4358 "Default value of `buffer-file-coding-system' for buffers not overriding it.\n\
4359 This is the same as (default-value 'buffer-file-coding-system).");
4361 DEFVAR_LISP_NOPRO ("default-truncate-lines",
4362 &buffer_defaults
.truncate_lines
,
4363 "Default value of `truncate-lines' for buffers that do not override it.\n\
4364 This is the same as (default-value 'truncate-lines).");
4366 DEFVAR_LISP_NOPRO ("default-fill-column",
4367 &buffer_defaults
.fill_column
,
4368 "Default value of `fill-column' for buffers that do not override it.\n\
4369 This is the same as (default-value 'fill-column).");
4371 DEFVAR_LISP_NOPRO ("default-left-margin",
4372 &buffer_defaults
.left_margin
,
4373 "Default value of `left-margin' for buffers that do not override it.\n\
4374 This is the same as (default-value 'left-margin).");
4376 DEFVAR_LISP_NOPRO ("default-tab-width",
4377 &buffer_defaults
.tab_width
,
4378 "Default value of `tab-width' for buffers that do not override it.\n\
4379 This is the same as (default-value 'tab-width).");
4381 DEFVAR_LISP_NOPRO ("default-case-fold-search",
4382 &buffer_defaults
.case_fold_search
,
4383 "Default value of `case-fold-search' for buffers that don't override it.\n\
4384 This is the same as (default-value 'case-fold-search).");
4387 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
4388 &buffer_defaults
.buffer_file_type
,
4389 "Default file type for buffers that do not override it.\n\
4390 This is the same as (default-value 'buffer-file-type).\n\
4391 The file type is nil for text, t for binary.");
4394 DEFVAR_LISP_NOPRO ("default-left-margin-width",
4395 &buffer_defaults
.left_margin_width
,
4396 "Default value of `left-margin-width' for buffers that don't override it.\n\
4397 This is the same as (default-value 'left-margin-width).");
4399 DEFVAR_LISP_NOPRO ("default-right-margin-width",
4400 &buffer_defaults
.right_margin_width
,
4401 "Default value of `right_margin_width' for buffers that don't override it.\n\
4402 This is the same as (default-value 'right-margin-width).");
4404 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines",
4405 &buffer_defaults
.indicate_empty_lines
,
4406 "Default value of `indicate-empty-lines' for buffers that don't override it.\n\
4407 This is the same as (default-value 'indicate-empty-lines).");
4409 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively",
4410 &buffer_defaults
.scroll_up_aggressively
,
4411 "Default value of `scroll-up-aggressively' for buffers that\n\
4412 don't override it. This is the same as (default-value\n\
4413 'scroll-up-aggressively).");
4415 DEFVAR_LISP_NOPRO ("default-scroll-down-aggressively",
4416 &buffer_defaults
.scroll_down_aggressively
,
4417 "Default value of `scroll-down-aggressively' for buffers that\n\
4418 don't override it. This is the same as (default-value\n\
4419 'scroll-down-aggressively).");
4421 DEFVAR_PER_BUFFER ("header-line-format",
4422 ¤t_buffer
->header_line_format
,
4424 "Analogous to `mode-line-format', but for a mode line displayed\n\
4425 at the top of windows.");
4427 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
4430 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
4431 But make-docfile finds it!
4432 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
4434 "Template for displaying mode line for current buffer.\n\
4435 Each buffer has its own value of this variable.\n\
4436 Value may be nil, a string, a symbol or a list or cons cell.\n\
4437 A value of nil means don't display a mode line.\n\
4438 For a symbol, its value is used (but it is ignored if t or nil).\n\
4439 A string appearing directly as the value of a symbol is processed verbatim\n\
4440 in that the %-constructs below are not recognized.\n\
4441 For a list of the form `(:eval FORM)', FORM is evaluated and the result\n\
4442 is used as a mode line element.\n\
4443 For a list whose car is a symbol, the symbol's value is taken,\n\
4444 and if that is non-nil, the cadr of the list is processed recursively.\n\
4445 Otherwise, the caddr of the list (if there is one) is processed.\n\
4446 For a list whose car is a string or list, each element is processed\n\
4447 recursively and the results are effectively concatenated.\n\
4448 For a list whose car is an integer, the cdr of the list is processed\n\
4449 and padded (if the number is positive) or truncated (if negative)\n\
4450 to the width specified by that number.\n\
4451 A string is printed verbatim in the mode line except for %-constructs:\n\
4452 (%-constructs are allowed when the string is the entire mode-line-format\n\
4453 or when it is found in a cons-cell or a list)\n\
4454 %b -- print buffer name. %f -- print visited file name.\n\
4455 %F -- print frame name.\n\
4456 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
4457 %& is like %*, but ignore read-only-ness.\n\
4458 % means buffer is read-only and * means it is modified.\n\
4459 For a modified read-only buffer, %* gives % and %+ gives *.\n\
4460 %s -- print process status. %l -- print the current line number.\n\
4461 %c -- print the current column number (this makes editing slower).\n\
4462 To make the column number update correctly in all cases,\n\
4463 `column-number-mode' must be non-nil.\n\
4464 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
4465 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
4466 or print Bottom or All.\n\
4467 %m -- print the mode name.\n\
4468 %n -- print Narrow if appropriate.\n\
4469 %z -- print mnemonics of buffer, terminal, and keyboard coding systems.\n\
4470 %Z -- like %z, but including the end-of-line format.\n\
4471 %[ -- print one [ for each recursive editing level. %] similar.\n\
4472 %% -- print %. %- -- print infinitely many dashes.\n\
4473 Decimal digits after the % specify field width to which to pad.");
4476 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
4477 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
4478 nil here means use current buffer's major mode.");
4480 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
4481 make_number (Lisp_Symbol
),
4482 "Symbol for current buffer's major mode.");
4484 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
4485 make_number (Lisp_String
),
4486 "Pretty name of current buffer's major mode (a string).");
4488 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
4489 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
4490 Automatically becomes buffer-local when set in any fashion.");
4492 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
4494 "*Non-nil if searches and matches should ignore case.\n\
4495 Automatically becomes buffer-local when set in any fashion.");
4497 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
4498 make_number (Lisp_Int
),
4499 "*Column beyond which automatic line-wrapping should happen.\n\
4500 Automatically becomes buffer-local when set in any fashion.");
4502 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
4503 make_number (Lisp_Int
),
4504 "*Column for the default indent-line-function to indent to.\n\
4505 Linefeed indents to this column in Fundamental mode.\n\
4506 Automatically becomes buffer-local when set in any fashion.");
4508 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
4509 make_number (Lisp_Int
),
4510 "*Distance between tab stops (for display of tab characters), in columns.\n\
4511 Automatically becomes buffer-local when set in any fashion.");
4513 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
4514 "*Non-nil means display control chars with uparrow.\n\
4515 A value of nil means use backslash and octal digits.\n\
4516 Automatically becomes buffer-local when set in any fashion.\n\
4517 This variable does not apply to characters whose display is specified\n\
4518 in the current display table (if there is one).");
4520 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
4521 ¤t_buffer
->enable_multibyte_characters
,
4523 "Non-nil means the buffer contents are regarded as multi-byte characters.\n\
4524 Otherwise they are regarded as unibyte. This affects the display,\n\
4525 file I/O and the behavior of various editing commands.\n\
4527 This variable is buffer-local but you cannot set it directly;\n\
4528 use the function `set-buffer-multibyte' to change a buffer's representation.\n\
4529 Changing its default value with `setq-default' is supported.\n\
4530 See also variable `default-enable-multibyte-characters' and Info node\n\
4531 `(elisp)Text Representations'.");
4533 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
4534 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
4535 "Coding system to be used for encoding the buffer contents on saving.\n\
4536 This variable applies to saving the buffer, and also to `write-region'\n\
4537 and other functions that use `write-region'.\n\
4538 It does not apply to sending output to subprocesses, however.\n\
4540 If this is nil, the buffer is saved without any code conversion\n\
4541 unless some coding system is specified in `file-coding-system-alist'\n\
4542 for the buffer file.\n\
4544 The variable `coding-system-for-write', if non-nil, overrides this variable.\n\
4546 This variable is never applied to a way of decoding\n\
4547 a file while reading it.");
4549 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
4551 "*Non-nil means lines in the buffer are displayed right to left.");
4553 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
4554 "*Non-nil means do not display continuation lines;\n\
4555 give each line of text one screen line.\n\
4556 Automatically becomes buffer-local when set in any fashion.\n\
4558 Note that this is overridden by the variable\n\
4559 `truncate-partial-width-windows' if that variable is non-nil\n\
4560 and this buffer is not full-frame width.");
4563 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
4565 "Non-nil if the visited file is a binary file.\n\
4566 This variable is meaningful on MS-DOG and Windows NT.\n\
4567 On those systems, it is automatically local in every buffer.\n\
4568 On other systems, this variable is normally always nil.");
4571 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
4572 make_number (Lisp_String
),
4573 "Name of default directory of current buffer. Should end with slash.\n\
4574 Each buffer has its own value of this variable.");
4576 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
4578 "Function called (if non-nil) to perform auto-fill.\n\
4579 It is called after self-inserting any character specified in\n\
4580 the `auto-fill-chars' table.\n\
4581 Each buffer has its own value of this variable.\n\
4582 NOTE: This variable is not a hook;\n\
4583 its value may not be a list of functions.");
4585 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
4586 make_number (Lisp_String
),
4587 "Name of file visited in current buffer, or nil if not visiting a file.\n\
4588 Each buffer has its own value of this variable.");
4590 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
4591 make_number (Lisp_String
),
4592 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
4593 The truename of a file is calculated by `file-truename'\n\
4594 and then abbreviated with `abbreviate-file-name'.\n\
4595 Each buffer has its own value of this variable.");
4597 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
4598 ¤t_buffer
->auto_save_file_name
,
4599 make_number (Lisp_String
),
4600 "Name of file for auto-saving current buffer,\n\
4601 or nil if buffer should not be auto-saved.\n\
4602 Each buffer has its own value of this variable.");
4604 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
4605 "Non-nil if this buffer is read-only.\n\
4606 Each buffer has its own value of this variable.");
4608 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
4609 "Non-nil if this buffer's file has been backed up.\n\
4610 Backing up is done before the first time the file is saved.\n\
4611 Each buffer has its own value of this variable.");
4613 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
4614 make_number (Lisp_Int
),
4615 "Length of current buffer when last read in, saved or auto-saved.\n\
4617 Each buffer has its own value of this variable.");
4619 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
4621 "Non-nil enables selective display:\n\
4622 Integer N as value means display only lines\n\
4623 that start with less than n columns of space.\n\
4624 A value of t means, after a ^M, all the rest of the line is invisible.\n\
4625 Then ^M's in the file are written into files as newlines.\n\n\
4626 Automatically becomes buffer-local when set in any fashion.");
4629 DEFVAR_PER_BUFFER ("selective-display-ellipses",
4630 ¤t_buffer
->selective_display_ellipses
,
4632 "t means display ... on previous line when a line is invisible.\n\
4633 Automatically becomes buffer-local when set in any fashion.");
4636 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
4637 "Non-nil if self-insertion should replace existing text.\n\
4638 The value should be one of `overwrite-mode-textual',\n\
4639 `overwrite-mode-binary', or nil.\n\
4640 If it is `overwrite-mode-textual', self-insertion still\n\
4641 inserts at the end of a line, and inserts when point is before a tab,\n\
4642 until the tab is filled in.\n\
4643 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
4644 Automatically becomes buffer-local when set in any fashion.");
4646 #if 0 /* The doc string is too long for some compilers,
4647 but make-docfile can find it in this comment. */
4648 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4650 "Display table that controls display of the contents of current buffer.\n\
4651 Automatically becomes buffer-local when set in any fashion.\n\
4652 The display table is a char-table created with `make-display-table'.\n\
4653 The ordinary char-table elements control how to display each possible text\n\
4654 character. Each value should be a vector of characters or nil;\n\
4655 nil means display the character in the default fashion.\n\
4656 There are six extra slots to control the display of\n\
4657 the end of a truncated screen line (extra-slot 0, a single character);\n\
4658 the end of a continued line (extra-slot 1, a single character);\n\
4659 the escape character used to display character codes in octal\n\
4660 (extra-slot 2, a single character);\n\
4661 the character used as an arrow for control characters (extra-slot 3,\n\
4662 a single character);\n\
4663 the decoration indicating the presence of invisible lines (extra-slot 4,\n\
4664 a vector of characters);\n\
4665 the character used to draw the border between side-by-side windows\n\
4666 (extra-slot 5, a single character).\n\
4667 See also the functions `display-table-slot' and `set-display-table-slot'.\n\
4668 If this variable is nil, the value of `standard-display-table' is used.\n\
4669 Each window can have its own, overriding display table.");
4671 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4674 DEFVAR_PER_BUFFER ("left-margin-width", ¤t_buffer
->left_margin_width
,
4676 "*Width of left marginal area for display of a buffer.\n\
4677 Automatically becomes buffer-local when set in any fashion.\n\
4678 A value of nil means no marginal area.");
4680 DEFVAR_PER_BUFFER ("right-margin-width", ¤t_buffer
->right_margin_width
,
4682 "*Width of right marginal area for display of a buffer.\n\
4683 Automatically becomes buffer-local when set in any fashion.\n\
4684 A value of nil means no marginal area.");
4686 DEFVAR_PER_BUFFER ("indicate-empty-lines",
4687 ¤t_buffer
->indicate_empty_lines
, Qnil
,
4688 "*Visually indicate empty lines after the buffer end.\n\
4689 If non-nil, a bitmap is displayed in the left fringe of a window on\n\
4691 Automatically becomes buffer-local when set in any fashion.\n");
4693 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
4694 ¤t_buffer
->scroll_up_aggressively
, Qnil
,
4695 "*If a number, scroll display up aggressively.\n\
4696 If scrolling a window because point is above the window start, choose\n\
4697 a new window start so that point ends up that fraction of the window's\n\
4698 height from the bottom of the window.\n\
4699 Automatically becomes buffer-local when set in any fashion.");
4701 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
4702 ¤t_buffer
->scroll_down_aggressively
, Qnil
,
4703 "*If a number, scroll display down aggressively.\n\
4704 If scrolling a window because point is below the window end, choose\n\
4705 a new window start so that point ends up that fraction of the window's\n\
4706 height from the top of the window.\n\
4707 Automatically becomes buffer-local when set in any fashion.");
4709 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
4712 DEFVAR_LISP ("before-change-function", &Vbefore_change_function
,
4713 "If non-nil, a function to call before each text change (obsolete).\n\
4714 Two arguments are passed to the function: the positions of\n\
4715 the beginning and end of the range of old text to be changed.\n\
4716 \(For an insertion, the beginning and end are at the same place.)\n\
4717 No information is given about the length of the text after the change.\n\
4719 Buffer changes made while executing the `before-change-function'\n\
4720 don't call any before-change or after-change functions.\n\
4721 That's because these variables are temporarily set to nil.\n\
4722 As a result, a hook function cannot straightforwardly alter the value of\n\
4723 these variables. See the Emacs Lisp manual for a way of\n\
4724 accomplishing an equivalent result by using other variables.\n\n\
4725 This variable is obsolete; use `before-change-functions' instead.");
4726 Vbefore_change_function
= Qnil
;
4728 DEFVAR_LISP ("after-change-function", &Vafter_change_function
,
4729 "If non-nil, a Function to call after each text change (obsolete).\n\
4730 Three arguments are passed to the function: the positions of\n\
4731 the beginning and end of the range of changed text,\n\
4732 and the length of the pre-change text replaced by that range.\n\
4733 \(For an insertion, the pre-change length is zero;\n\
4734 for a deletion, that length is the number of bytes deleted,\n\
4735 and the post-change beginning and end are at the same place.)\n\
4737 Buffer changes made while executing the `after-change-function'\n\
4738 don't call any before-change or after-change functions.\n\
4739 That's because these variables are temporarily set to nil.\n\
4740 As a result, a hook function cannot straightforwardly alter the value of\n\
4741 these variables. See the Emacs Lisp manual for a way of\n\
4742 accomplishing an equivalent result by using other variables.\n\n\
4743 This variable is obsolete; use `after-change-functions' instead.");
4744 Vafter_change_function
= Qnil
;
4746 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
4747 "List of functions to call before each text change.\n\
4748 Two arguments are passed to each function: the positions of\n\
4749 the beginning and end of the range of old text to be changed.\n\
4750 \(For an insertion, the beginning and end are at the same place.)\n\
4751 No information is given about the length of the text after the change.\n\
4753 Buffer changes made while executing the `before-change-functions'\n\
4754 don't call any before-change or after-change functions.\n\
4755 That's because these variables are temporarily set to nil.\n\
4756 As a result, a hook function cannot straightforwardly alter the value of\n\
4757 these variables. See the Emacs Lisp manual for a way of\n\
4758 accomplishing an equivalent result by using other variables.\n\
4760 If an unhandled error happens in running these functions,\n\
4761 the variable's value remains nil. That prevents the error\n\
4762 from happening repeatedly and making Emacs nonfunctional.");
4763 Vbefore_change_functions
= Qnil
;
4765 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
4766 "List of function to call after each text change.\n\
4767 Three arguments are passed to each function: the positions of\n\
4768 the beginning and end of the range of changed text,\n\
4769 and the length in bytes of the pre-change text replaced by that range.\n\
4770 \(For an insertion, the pre-change length is zero;\n\
4771 for a deletion, that length is the number of bytes deleted,\n\
4772 and the post-change beginning and end are at the same place.)\n\
4774 Buffer changes made while executing the `after-change-functions'\n\
4775 don't call any before-change or after-change functions.\n\
4776 That's because these variables are temporarily set to nil.\n\
4777 As a result, a hook function cannot straightforwardly alter the value of\n\
4778 these variables. See the Emacs Lisp manual for a way of\n\
4779 accomplishing an equivalent result by using other variables.\n\
4781 If an unhandled error happens in running these functions,\n\
4782 the variable's value remains nil. That prevents the error\n\
4783 from happening repeatedly and making Emacs nonfunctional.");
4784 Vafter_change_functions
= Qnil
;
4786 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
4787 "A list of functions to call before changing a buffer which is unmodified.\n\
4788 The functions are run using the `run-hooks' function.");
4789 Vfirst_change_hook
= Qnil
;
4791 #if 0 /* The doc string is too long for some compilers,
4792 but make-docfile can find it in this comment. */
4793 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4794 "List of undo entries in current buffer.\n\
4795 This variable is always local in all buffers.\n\
4796 Recent changes come first; older changes follow newer.\n\
4798 An entry (BEG . END) represents an insertion which begins at\n\
4799 position BEG and ends at position END.\n\
4801 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
4802 from (abs POSITION). If POSITION is positive, point was at the front\n\
4803 of the text being deleted; if negative, point was at the end.\n\
4805 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
4806 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
4807 of the visited file's modification time, as of that time. If the\n\
4808 modification time of the most recent save is different, this entry is\n\
4811 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
4812 was modified between BEG and END. PROPERTY is the property name,\n\
4813 and VALUE is the old value.\n\
4815 An entry (MARKER . DISTANCE) indicates that the marker MARKER\n\
4816 was adjusted in position by the offset DISTANCE (an integer).\n\
4818 An entry of the form POSITION indicates that point was at the buffer\n\
4819 location given by the integer. Undoing an entry of this form places\n\
4820 point at POSITION.\n\
4822 nil marks undo boundaries. The undo command treats the changes\n\
4823 between two undo boundaries as a single step to be undone.\n\
4825 If the value of the variable is t, undo information is not recorded.");
4827 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4830 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
4831 "Non-nil means the mark and region are currently active in this buffer.\n\
4832 Automatically local in all buffers.");
4834 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
4835 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
4836 This variable is buffer-local, in all buffers.\n\
4838 Normally, the line-motion functions work by scanning the buffer for\n\
4839 newlines. Columnar operations (like move-to-column and\n\
4840 compute-motion) also work by scanning the buffer, summing character\n\
4841 widths as they go. This works well for ordinary text, but if the\n\
4842 buffer's lines are very long (say, more than 500 characters), these\n\
4843 motion functions will take longer to execute. Emacs may also take\n\
4844 longer to update the display.\n\
4846 If cache-long-line-scans is non-nil, these motion functions cache the\n\
4847 results of their scans, and consult the cache to avoid rescanning\n\
4848 regions of the buffer until the text is modified. The caches are most\n\
4849 beneficial when they prevent the most searching---that is, when the\n\
4850 buffer contains long lines and large regions of characters with the\n\
4851 same, fixed screen width.\n\
4853 When cache-long-line-scans is non-nil, processing short lines will\n\
4854 become slightly slower (because of the overhead of consulting the\n\
4855 cache), and the caches will use memory roughly proportional to the\n\
4856 number of newlines and characters whose screen width varies.\n\
4858 The caches require no explicit maintenance; their accuracy is\n\
4859 maintained internally by the Emacs primitives. Enabling or disabling\n\
4860 the cache should not affect the behavior of any of the motion\n\
4861 functions; it should only affect their performance.");
4863 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
4864 "Value of point before the last series of scroll operations, or nil.\n\
4865 This variable is always local in all buffers.");
4867 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
4868 "List of formats to use when saving this buffer.\n\
4869 This variable is always local in all buffers.\n\
4870 Formats are defined by `format-alist'. This variable is\n\
4871 set when a file is visited. Automatically local in all buffers.");
4873 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
4874 ¤t_buffer
->invisibility_spec
, Qnil
,
4875 "Invisibility spec of this buffer.\n\
4876 This variable is always local in all buffers.\n\
4877 The default is t, which means that text is invisible\n\
4878 if it has a non-nil `invisible' property.\n\
4879 If the value is a list, a text character is invisible if its `invisible'\n\
4880 property is an element in that list.\n\
4881 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
4882 then characters with property value PROP are invisible,\n\
4883 and they have an ellipsis as well if ELLIPSIS is non-nil.");
4885 DEFVAR_PER_BUFFER ("buffer-display-count",
4886 ¤t_buffer
->display_count
, Qnil
,
4887 "A number incremented each time this buffer is displayed in a window.\n\
4888 This variable is always local in all buffers.\n\
4889 The function `set-window-buffer increments it.");
4891 DEFVAR_PER_BUFFER ("buffer-display-time",
4892 ¤t_buffer
->display_time
, Qnil
,
4893 "Time stamp updated each time this buffer is displayed in a window.\n\
4894 This variable is always local in all buffers.\n\
4895 The function `set-window-buffer' updates this variable\n\
4896 to the value obtained by calling `current-time'.\n\
4897 If the buffer has never been shown in a window, the value is nil.");
4899 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
4900 "*Non-nil means deactivate the mark when the buffer contents change.\n\
4901 Non-nil also enables highlighting of the region whenever the mark is active.\n\
4902 The variable `highlight-nonselected-windows' controls whether to highlight\n\
4903 all windows or just the selected window.");
4904 Vtransient_mark_mode
= Qnil
;
4906 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
4907 "*Non-nil means disregard read-only status of buffers or characters.\n\
4908 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
4909 text properties. If the value is a list, disregard `buffer-read-only'\n\
4910 and disregard a `read-only' text property if the property value\n\
4911 is a member of the list.");
4912 Vinhibit_read_only
= Qnil
;
4914 DEFVAR_PER_BUFFER ("cursor-type", ¤t_buffer
->cursor_type
, Qnil
,
4915 "Cursor to use in window displaying this buffer.\n\
4916 Values are interpreted as follows:\n\
4918 t use the cursor specified for the frame\n\
4919 nil don't display a cursor\n\
4920 `bar' display a bar cursor with default width\n\
4921 (bar . WIDTH) display a bar cursor with width WIDTH\n\
4922 others display a box cursor.");
4924 DEFVAR_PER_BUFFER ("line-spacing",
4925 ¤t_buffer
->extra_line_spacing
, Qnil
,
4926 "Additional space to put between lines when displaying a buffer.\n\
4927 The space is measured in pixels, and put below lines on window systems.");
4929 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
4930 "List of functions called with no args to query before killing a buffer.");
4931 Vkill_buffer_query_functions
= Qnil
;
4933 defsubr (&Sbuffer_live_p
);
4934 defsubr (&Sbuffer_list
);
4935 defsubr (&Sget_buffer
);
4936 defsubr (&Sget_file_buffer
);
4937 defsubr (&Sget_buffer_create
);
4938 defsubr (&Smake_indirect_buffer
);
4939 defsubr (&Sgenerate_new_buffer_name
);
4940 defsubr (&Sbuffer_name
);
4941 /*defsubr (&Sbuffer_number);*/
4942 defsubr (&Sbuffer_file_name
);
4943 defsubr (&Sbuffer_base_buffer
);
4944 defsubr (&Sbuffer_local_variables
);
4945 defsubr (&Sbuffer_modified_p
);
4946 defsubr (&Sset_buffer_modified_p
);
4947 defsubr (&Sbuffer_modified_tick
);
4948 defsubr (&Srename_buffer
);
4949 defsubr (&Sother_buffer
);
4950 defsubr (&Sbuffer_disable_undo
);
4951 defsubr (&Sbuffer_enable_undo
);
4952 defsubr (&Skill_buffer
);
4953 defsubr (&Sset_buffer_major_mode
);
4954 defsubr (&Sswitch_to_buffer
);
4955 defsubr (&Spop_to_buffer
);
4956 defsubr (&Scurrent_buffer
);
4957 defsubr (&Sset_buffer
);
4958 defsubr (&Sbarf_if_buffer_read_only
);
4959 defsubr (&Sbury_buffer
);
4960 defsubr (&Serase_buffer
);
4961 defsubr (&Sset_buffer_multibyte
);
4962 defsubr (&Skill_all_local_variables
);
4964 defsubr (&Soverlayp
);
4965 defsubr (&Smake_overlay
);
4966 defsubr (&Sdelete_overlay
);
4967 defsubr (&Smove_overlay
);
4968 defsubr (&Soverlay_start
);
4969 defsubr (&Soverlay_end
);
4970 defsubr (&Soverlay_buffer
);
4971 defsubr (&Soverlay_properties
);
4972 defsubr (&Soverlays_at
);
4973 defsubr (&Soverlays_in
);
4974 defsubr (&Snext_overlay_change
);
4975 defsubr (&Sprevious_overlay_change
);
4976 defsubr (&Soverlay_recenter
);
4977 defsubr (&Soverlay_lists
);
4978 defsubr (&Soverlay_get
);
4979 defsubr (&Soverlay_put
);
4980 defsubr (&Srestore_buffer_modified_p
);
4986 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
4987 initial_define_key (control_x_map
, 'k', "kill-buffer");
4989 /* This must not be in syms_of_buffer, because Qdisabled is not
4990 initialized when that function gets called. */
4991 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);