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_functions
;
135 Lisp_Object Vafter_change_functions
;
137 Lisp_Object Vtransient_mark_mode
;
139 /* t means ignore all read-only text properties.
140 A list means ignore such a property if its value is a member of the list.
141 Any non-nil value means ignore buffer-read-only. */
142 Lisp_Object Vinhibit_read_only
;
144 /* List of functions to call that can query about killing a buffer.
145 If any of these functions returns nil, we don't kill it. */
146 Lisp_Object Vkill_buffer_query_functions
;
148 /* List of functions to call before changing an unmodified buffer. */
149 Lisp_Object Vfirst_change_hook
;
151 Lisp_Object Qfirst_change_hook
;
152 Lisp_Object Qbefore_change_functions
;
153 Lisp_Object Qafter_change_functions
;
155 /* If nonzero, all modification hooks are suppressed. */
156 int inhibit_modification_hooks
;
158 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
160 Lisp_Object Qprotected_field
;
162 Lisp_Object QSFundamental
; /* A string "Fundamental" */
164 Lisp_Object Qkill_buffer_hook
;
166 Lisp_Object Qget_file_buffer
;
168 Lisp_Object Qoverlayp
;
170 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
172 Lisp_Object Qmodification_hooks
;
173 Lisp_Object Qinsert_in_front_hooks
;
174 Lisp_Object Qinsert_behind_hooks
;
176 /* For debugging; temporary. See set_buffer_internal. */
177 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
184 error ("No buffer named %s", XSTRING (spec
)->data
);
185 error ("Invalid buffer argument");
188 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
189 "Return non-nil if OBJECT is a buffer which has not been killed.\n\
190 Value is nil if OBJECT is not a buffer or if it has been killed.")
194 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
198 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
199 "Return a list of all existing live buffers.\n\
200 If the optional arg FRAME is a frame, we return that frame's buffer list.")
204 Lisp_Object framelist
, general
;
205 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
211 CHECK_FRAME (frame
, 1);
213 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
215 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */
217 while (! NILP (tail
))
219 general
= Fdelq (XCAR (tail
), general
);
222 return nconc2 (framelist
, general
);
228 /* Like Fassoc, but use Fstring_equal to compare
229 (which ignores text properties),
230 and don't ever QUIT. */
233 assoc_ignore_text_properties (key
, list
)
234 register Lisp_Object key
;
237 register Lisp_Object tail
;
238 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
240 register Lisp_Object elt
, tem
;
242 tem
= Fstring_equal (Fcar (elt
), key
);
249 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
250 "Return the buffer named NAME (a string).\n\
251 If there is no live buffer named NAME, return nil.\n\
252 NAME may also be a buffer; if so, the value is that buffer.")
254 register Lisp_Object name
;
258 CHECK_STRING (name
, 0);
260 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
263 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
264 "Return the buffer visiting file FILENAME (a string).\n\
265 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
266 If there is no such live buffer, return nil.\n\
267 See also `find-buffer-visiting'.")
269 register Lisp_Object filename
;
271 register Lisp_Object tail
, buf
, tem
;
274 CHECK_STRING (filename
, 0);
275 filename
= Fexpand_file_name (filename
, Qnil
);
277 /* If the file name has special constructs in it,
278 call the corresponding file handler. */
279 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
281 return call2 (handler
, Qget_file_buffer
, filename
);
283 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
285 buf
= Fcdr (XCAR (tail
));
286 if (!BUFFERP (buf
)) continue;
287 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
288 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
296 get_truename_buffer (filename
)
297 register Lisp_Object filename
;
299 register Lisp_Object tail
, buf
, tem
;
301 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
303 buf
= Fcdr (XCAR (tail
));
304 if (!BUFFERP (buf
)) continue;
305 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
306 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
313 /* Incremented for each buffer created, to assign the buffer number. */
316 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
317 "Return the buffer named NAME, or create such a buffer and return it.\n\
318 A new buffer is created if there is no live buffer named NAME.\n\
319 If NAME starts with a space, the new buffer does not keep undo information.\n\
320 If NAME is a buffer instead of a string, then it is the value returned.\n\
321 The value is never nil.")
323 register Lisp_Object name
;
325 register Lisp_Object buf
;
326 register struct buffer
*b
;
328 buf
= Fget_buffer (name
);
332 if (XSTRING (name
)->size
== 0)
333 error ("Empty string for buffer name is not allowed");
335 b
= (struct buffer
*) allocate_buffer ();
337 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
339 /* An ordinary buffer uses its own struct buffer_text. */
340 b
->text
= &b
->own_text
;
343 BUF_GAP_SIZE (b
) = 20;
345 /* We allocate extra 1-byte at the tail and keep it always '\0' for
346 anchoring a search. */
347 BUFFER_ALLOC (BUF_BEG_ADDR (b
), (BUF_GAP_SIZE (b
) + 1));
349 if (! BUF_BEG_ADDR (b
))
350 buffer_memory_full ();
358 BUF_GPT_BYTE (b
) = 1;
359 BUF_BEGV_BYTE (b
) = 1;
363 BUF_OVERLAY_MODIFF (b
) = 1;
364 BUF_SAVE_MODIFF (b
) = 1;
365 BUF_INTERVALS (b
) = 0;
366 BUF_UNCHANGED_MODIFIED (b
) = 1;
367 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = 1;
368 BUF_END_UNCHANGED (b
) = 0;
369 BUF_BEG_UNCHANGED (b
) = 0;
370 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
372 b
->newline_cache
= 0;
373 b
->width_run_cache
= 0;
374 b
->width_table
= Qnil
;
375 b
->prevent_redisplay_optimizations_p
= 1;
377 /* Put this on the chain of all buffers including killed ones. */
378 b
->next
= all_buffers
;
381 /* An ordinary buffer normally doesn't need markers
382 to handle BEGV and ZV. */
384 b
->begv_marker
= Qnil
;
387 name
= Fcopy_sequence (name
);
388 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
391 if (XSTRING (name
)->data
[0] != ' ')
397 reset_buffer_local_variables (b
, 1);
399 /* Put this in the alist of all live buffers. */
401 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
403 b
->mark
= Fmake_marker ();
404 BUF_MARKERS (b
) = Qnil
;
410 /* Clone per-buffer values of buffer FROM.
412 Buffer TO gets the same per-buffer values as FROM, with the
413 following exceptions: (1) TO's name is left untouched, (2) markers
414 are copied and made to refer to TO, and (3) overlay lists are
418 clone_per_buffer_values (from
, to
)
419 struct buffer
*from
, *to
;
421 Lisp_Object to_buffer
;
424 XSETBUFFER (to_buffer
, to
);
426 for (offset
= PER_BUFFER_VAR_OFFSET (name
) + sizeof (Lisp_Object
);
428 offset
+= sizeof (Lisp_Object
))
432 obj
= PER_BUFFER_VALUE (from
, offset
);
435 struct Lisp_Marker
*m
= XMARKER (obj
);
436 obj
= Fmake_marker ();
437 XMARKER (obj
)->insertion_type
= m
->insertion_type
;
438 set_marker_both (obj
, to_buffer
, m
->charpos
, m
->bytepos
);
441 PER_BUFFER_VALUE (to
, offset
) = obj
;
444 to
->overlays_after
= Fcopy_sequence (from
->overlays_after
);
445 to
->overlays_before
= Fcopy_sequence (to
->overlays_before
);
446 bcopy (from
->local_flags
, to
->local_flags
, sizeof to
->local_flags
);
450 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
,
452 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
453 "Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.\n\
454 BASE-BUFFER should be an existing buffer (or buffer name).\n\
455 NAME should be a string which is not the name of an existing buffer.\n\
456 Optional argument CLONE non-nil means preserve BASE-BUFFER's state,\n\
457 such as major and minor modes, in the indirect buffer.\n\
458 CLONE nil means the indirect buffer's state is reset to default values.")
459 (base_buffer
, name
, clone
)
460 Lisp_Object base_buffer
, name
, clone
;
465 buf
= Fget_buffer (name
);
467 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
469 base_buffer
= Fget_buffer (base_buffer
);
470 if (NILP (base_buffer
))
471 error ("No such buffer: `%s'",
472 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
474 if (XSTRING (name
)->size
== 0)
475 error ("Empty string for buffer name is not allowed");
477 b
= (struct buffer
*) allocate_buffer ();
478 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
480 if (XBUFFER (base_buffer
)->base_buffer
)
481 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
483 b
->base_buffer
= XBUFFER (base_buffer
);
485 /* Use the base buffer's text object. */
486 b
->text
= b
->base_buffer
->text
;
488 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
489 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
490 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
491 BUF_BEGV_BYTE (b
) = BUF_BEGV_BYTE (b
->base_buffer
);
492 BUF_ZV_BYTE (b
) = BUF_ZV_BYTE (b
->base_buffer
);
493 BUF_PT_BYTE (b
) = BUF_PT_BYTE (b
->base_buffer
);
495 b
->newline_cache
= 0;
496 b
->width_run_cache
= 0;
497 b
->width_table
= Qnil
;
499 /* Put this on the chain of all buffers including killed ones. */
500 b
->next
= all_buffers
;
503 name
= Fcopy_sequence (name
);
504 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
508 reset_buffer_local_variables (b
, 1);
510 /* Put this in the alist of all live buffers. */
512 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
514 b
->mark
= Fmake_marker ();
517 /* The multibyte status belongs to the base buffer. */
518 b
->enable_multibyte_characters
= b
->base_buffer
->enable_multibyte_characters
;
520 /* Make sure the base buffer has markers for its narrowing. */
521 if (NILP (b
->base_buffer
->pt_marker
))
523 b
->base_buffer
->pt_marker
= Fmake_marker ();
524 set_marker_both (b
->base_buffer
->pt_marker
, base_buffer
,
525 BUF_PT (b
->base_buffer
),
526 BUF_PT_BYTE (b
->base_buffer
));
528 if (NILP (b
->base_buffer
->begv_marker
))
530 b
->base_buffer
->begv_marker
= Fmake_marker ();
531 set_marker_both (b
->base_buffer
->begv_marker
, base_buffer
,
532 BUF_BEGV (b
->base_buffer
),
533 BUF_BEGV_BYTE (b
->base_buffer
));
535 if (NILP (b
->base_buffer
->zv_marker
))
537 b
->base_buffer
->zv_marker
= Fmake_marker ();
538 set_marker_both (b
->base_buffer
->zv_marker
, base_buffer
,
539 BUF_ZV (b
->base_buffer
),
540 BUF_ZV_BYTE (b
->base_buffer
));
541 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
546 /* Give the indirect buffer markers for its narrowing. */
547 b
->pt_marker
= Fmake_marker ();
548 set_marker_both (b
->pt_marker
, buf
, BUF_PT (b
), BUF_PT_BYTE (b
));
549 b
->begv_marker
= Fmake_marker ();
550 set_marker_both (b
->begv_marker
, buf
, BUF_BEGV (b
), BUF_BEGV_BYTE (b
));
551 b
->zv_marker
= Fmake_marker ();
552 set_marker_both (b
->zv_marker
, buf
, BUF_ZV (b
), BUF_ZV_BYTE (b
));
553 XMARKER (b
->zv_marker
)->insertion_type
= 1;
556 clone_per_buffer_values (b
->base_buffer
, b
);
561 /* Reinitialize everything about a buffer except its name and contents
562 and local variables. */
566 register struct buffer
*b
;
569 b
->file_truename
= Qnil
;
570 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
572 XSETFASTINT (b
->save_length
, 0);
573 b
->last_window_start
= 1;
574 /* It is more conservative to start out "changed" than "unchanged". */
576 b
->prevent_redisplay_optimizations_p
= 1;
578 b
->auto_save_modified
= 0;
579 b
->auto_save_failure_time
= -1;
580 b
->auto_save_file_name
= Qnil
;
582 b
->overlays_before
= Qnil
;
583 b
->overlays_after
= Qnil
;
584 XSETFASTINT (b
->overlay_center
, 1);
585 b
->mark_active
= Qnil
;
586 b
->point_before_scroll
= Qnil
;
587 b
->file_format
= Qnil
;
588 b
->last_selected_window
= Qnil
;
589 XSETINT (b
->display_count
, 0);
590 b
->display_time
= Qnil
;
591 b
->enable_multibyte_characters
= buffer_defaults
.enable_multibyte_characters
;
592 b
->cursor_type
= buffer_defaults
.cursor_type
;
593 b
->extra_line_spacing
= buffer_defaults
.extra_line_spacing
;
596 /* Reset buffer B's local variables info.
597 Don't use this on a buffer that has already been in use;
598 it does not treat permanent locals consistently.
599 Instead, use Fkill_all_local_variables.
601 If PERMANENT_TOO is 1, then we reset permanent built-in
602 buffer-local variables. If PERMANENT_TOO is 0,
603 we preserve those. */
606 reset_buffer_local_variables (b
, permanent_too
)
607 register struct buffer
*b
;
613 /* Reset the major mode to Fundamental, together with all the
614 things that depend on the major mode.
615 default-major-mode is handled at a higher level.
616 We ignore it here. */
617 b
->major_mode
= Qfundamental_mode
;
619 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
620 b
->mode_name
= QSFundamental
;
621 b
->minor_modes
= Qnil
;
623 /* If the standard case table has been altered and invalidated,
624 fix up its insides first. */
625 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
626 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
627 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
628 Fset_standard_case_table (Vascii_downcase_table
);
630 b
->downcase_table
= Vascii_downcase_table
;
631 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
632 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
633 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
634 b
->invisibility_spec
= Qt
;
636 b
->buffer_file_type
= Qnil
;
640 b
->sort_table
= XSTRING (Vascii_sort_table
);
641 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
644 /* Reset all (or most) per-buffer variables to their defaults. */
645 b
->local_var_alist
= Qnil
;
646 for (i
= 0; i
< last_per_buffer_idx
; ++i
)
647 if (permanent_too
|| buffer_permanent_local_flags
[i
] == 0)
648 SET_PER_BUFFER_VALUE_P (b
, i
, 0);
650 /* For each slot that has a default value,
651 copy that into the slot. */
653 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
655 offset
+= sizeof (Lisp_Object
))
657 int idx
= PER_BUFFER_IDX (offset
);
660 || buffer_permanent_local_flags
[idx
] == 0))
661 /* Is -2 used anywhere? */
663 PER_BUFFER_VALUE (b
, offset
) = PER_BUFFER_DEFAULT (offset
);
667 /* We split this away from generate-new-buffer, because rename-buffer
668 and set-visited-file-name ought to be able to use this to really
669 rename the buffer properly. */
671 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
673 "Return a string that is the name of no existing buffer based on NAME.\n\
674 If there is no live buffer named NAME, then return NAME.\n\
675 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
676 until an unused name is found, and then return that name.\n\
677 Optional second argument IGNORE specifies a name that is okay to use\n\
678 \(if it is in the sequence to be tried)\n\
679 even if a buffer with that name exists.")
681 register Lisp_Object name
, ignore
;
683 register Lisp_Object gentemp
, tem
;
687 CHECK_STRING (name
, 0);
689 tem
= Fget_buffer (name
);
696 sprintf (number
, "<%d>", ++count
);
697 gentemp
= concat2 (name
, build_string (number
));
698 tem
= Fstring_equal (gentemp
, ignore
);
701 tem
= Fget_buffer (gentemp
);
708 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
709 "Return the name of BUFFER, as a string.\n\
710 With no argument or nil as argument, return the name of the current buffer.")
712 register Lisp_Object buffer
;
715 return current_buffer
->name
;
716 CHECK_BUFFER (buffer
, 0);
717 return XBUFFER (buffer
)->name
;
720 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
721 "Return name of file BUFFER is visiting, or nil if none.\n\
722 No argument or nil as argument means use the current buffer.")
724 register Lisp_Object buffer
;
727 return current_buffer
->filename
;
728 CHECK_BUFFER (buffer
, 0);
729 return XBUFFER (buffer
)->filename
;
732 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
734 "Return the base buffer of indirect buffer BUFFER.\n\
735 If BUFFER is not indirect, return nil.")
737 register Lisp_Object buffer
;
740 Lisp_Object base_buffer
;
743 base
= current_buffer
->base_buffer
;
746 CHECK_BUFFER (buffer
, 0);
747 base
= XBUFFER (buffer
)->base_buffer
;
752 XSETBUFFER (base_buffer
, base
);
756 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
757 Sbuffer_local_variables
, 0, 1, 0,
758 "Return an alist of variables that are buffer-local in BUFFER.\n\
759 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
760 For a symbol that is locally unbound, just the symbol appears in the value.\n\
761 Note that storing new VALUEs in these elements doesn't change the variables.\n\
762 No argument or nil as argument means use current buffer as BUFFER.")
764 register Lisp_Object buffer
;
766 register struct buffer
*buf
;
767 register Lisp_Object result
;
770 buf
= current_buffer
;
773 CHECK_BUFFER (buffer
, 0);
774 buf
= XBUFFER (buffer
);
780 register Lisp_Object tail
;
781 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
783 Lisp_Object val
, elt
;
787 /* Reference each variable in the alist in buf.
788 If inquiring about the current buffer, this gets the current values,
789 so store them into the alist so the alist is up to date.
790 If inquiring about some other buffer, this swaps out any values
791 for that buffer, making the alist up to date automatically. */
792 val
= find_symbol_value (XCAR (elt
));
793 /* Use the current buffer value only if buf is the current buffer. */
794 if (buf
!= current_buffer
)
797 /* If symbol is unbound, put just the symbol in the list. */
798 if (EQ (val
, Qunbound
))
799 result
= Fcons (XCAR (elt
), result
);
800 /* Otherwise, put (symbol . value) in the list. */
802 result
= Fcons (Fcons (XCAR (elt
), val
), result
);
806 /* Add on all the variables stored in special slots. */
810 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
811 offset
< sizeof (struct buffer
);
812 /* sizeof EMACS_INT == sizeof Lisp_Object */
813 offset
+= (sizeof (EMACS_INT
)))
815 idx
= PER_BUFFER_IDX (offset
);
816 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
817 && SYMBOLP (PER_BUFFER_SYMBOL (offset
)))
818 result
= Fcons (Fcons (PER_BUFFER_SYMBOL (offset
),
819 PER_BUFFER_VALUE (buf
, offset
)),
828 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
830 "Return t if BUFFER was modified since its file was last read or saved.\n\
831 No argument or nil as argument means use current buffer as BUFFER.")
833 register Lisp_Object buffer
;
835 register struct buffer
*buf
;
837 buf
= current_buffer
;
840 CHECK_BUFFER (buffer
, 0);
841 buf
= XBUFFER (buffer
);
844 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
847 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
849 "Mark current buffer as modified or unmodified according to FLAG.\n\
850 A non-nil FLAG means mark the buffer modified.")
852 register Lisp_Object flag
;
854 register int already
;
855 register Lisp_Object fn
;
856 Lisp_Object buffer
, window
;
858 #ifdef CLASH_DETECTION
859 /* If buffer becoming modified, lock the file.
860 If buffer becoming unmodified, unlock the file. */
862 fn
= current_buffer
->file_truename
;
863 /* Test buffer-file-name so that binding it to nil is effective. */
864 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
866 already
= SAVE_MODIFF
< MODIFF
;
867 if (!already
&& !NILP (flag
))
869 else if (already
&& NILP (flag
))
872 #endif /* CLASH_DETECTION */
874 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
876 /* Set update_mode_lines only if buffer is displayed in some window.
877 Packages like jit-lock or lazy-lock preserve a buffer's modified
878 state by recording/restoring the state around blocks of code.
879 Setting update_mode_lines makes redisplay consider all windows
880 (on all frames). Stealth fontification of buffers not displayed
881 would incur additional redisplay costs if we'd set
882 update_modes_lines unconditionally.
884 Ideally, I think there should be another mechanism for fontifying
885 buffers without "modifying" buffers, or redisplay should be
886 smarter about updating the `*' in mode lines. --gerd */
887 XSETBUFFER (buffer
, current_buffer
);
888 window
= Fget_buffer_window (buffer
, Qt
);
889 if (WINDOWP (window
))
895 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p
,
896 Srestore_buffer_modified_p
, 1, 1, 0,
897 "Like `set-buffer-modified-p', with a differences concerning redisplay.\n\
898 It is not ensured that mode lines will be updated to show the modified\n\
899 state of the current buffer. Use with care.")
903 #ifdef CLASH_DETECTION
906 /* If buffer becoming modified, lock the file.
907 If buffer becoming unmodified, unlock the file. */
909 fn
= current_buffer
->file_truename
;
910 /* Test buffer-file-name so that binding it to nil is effective. */
911 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
913 int already
= SAVE_MODIFF
< MODIFF
;
914 if (!already
&& !NILP (flag
))
916 else if (already
&& NILP (flag
))
919 #endif /* CLASH_DETECTION */
921 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
925 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
927 "Return BUFFER's tick counter, incremented for each change in text.\n\
928 Each buffer has a tick counter which is incremented each time the text in\n\
929 that buffer is changed. It wraps around occasionally.\n\
930 No argument or nil as argument means use current buffer as BUFFER.")
932 register Lisp_Object buffer
;
934 register struct buffer
*buf
;
936 buf
= current_buffer
;
939 CHECK_BUFFER (buffer
, 0);
940 buf
= XBUFFER (buffer
);
943 return make_number (BUF_MODIFF (buf
));
946 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
947 "sRename buffer (to new name): \nP",
948 "Change current buffer's name to NEWNAME (a string).\n\
949 If second arg UNIQUE is nil or omitted, it is an error if a\n\
950 buffer named NEWNAME already exists.\n\
951 If UNIQUE is non-nil, come up with a new name using\n\
952 `generate-new-buffer-name'.\n\
953 Interactively, you can set UNIQUE with a prefix argument.\n\
954 We return the name we actually gave the buffer.\n\
955 This does not change the name of the visited file (if any).")
957 register Lisp_Object newname
, unique
;
959 register Lisp_Object tem
, buf
;
961 CHECK_STRING (newname
, 0);
963 if (XSTRING (newname
)->size
== 0)
964 error ("Empty string is invalid as a buffer name");
966 tem
= Fget_buffer (newname
);
969 /* Don't short-circuit if UNIQUE is t. That is a useful way to
970 rename the buffer automatically so you can create another
971 with the original name. It makes UNIQUE equivalent to
972 (rename-buffer (generate-new-buffer-name NEWNAME)). */
973 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
974 return current_buffer
->name
;
976 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
978 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
981 current_buffer
->name
= newname
;
983 /* Catch redisplay's attention. Unless we do this, the mode lines for
984 any windows displaying current_buffer will stay unchanged. */
987 XSETBUFFER (buf
, current_buffer
);
988 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
989 if (NILP (current_buffer
->filename
)
990 && !NILP (current_buffer
->auto_save_file_name
))
991 call0 (intern ("rename-auto-save-file"));
992 /* Refetch since that last call may have done GC. */
993 return current_buffer
->name
;
996 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 3, 0,
997 "Return most recently selected buffer other than BUFFER.\n\
998 Buffers not visible in windows are preferred to visible buffers,\n\
999 unless optional second argument VISIBLE-OK is non-nil.\n\
1000 If the optional third argument FRAME is non-nil, use that frame's\n\
1001 buffer list instead of the selected frame's buffer list.\n\
1002 If no other buffer exists, the buffer `*scratch*' is returned.\n\
1003 If BUFFER is omitted or nil, some interesting buffer is returned.")
1004 (buffer
, visible_ok
, frame
)
1005 register Lisp_Object buffer
, visible_ok
, frame
;
1007 Lisp_Object
Fset_buffer_major_mode ();
1008 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
1012 frame
= selected_frame
;
1014 tail
= Vbuffer_alist
;
1015 pred
= frame_buffer_predicate (frame
);
1017 /* Consider buffers that have been seen in the selected frame
1018 before other buffers. */
1020 tem
= frame_buffer_list (frame
);
1024 if (BUFFERP (XCAR (tem
)))
1025 add_ons
= Fcons (Fcons (Qnil
, XCAR (tem
)), add_ons
);
1028 tail
= nconc2 (Fnreverse (add_ons
), tail
);
1030 for (; !NILP (tail
); tail
= Fcdr (tail
))
1032 buf
= Fcdr (Fcar (tail
));
1033 if (EQ (buf
, buffer
))
1035 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
1037 /* If the selected frame has a buffer_predicate,
1038 disregard buffers that don't fit the predicate. */
1041 tem
= call1 (pred
, buf
);
1046 if (NILP (visible_ok
))
1047 tem
= Fget_buffer_window (buf
, Qt
);
1052 if (NILP (notsogood
))
1055 if (!NILP (notsogood
))
1057 buf
= Fget_buffer (build_string ("*scratch*"));
1060 buf
= Fget_buffer_create (build_string ("*scratch*"));
1061 Fset_buffer_major_mode (buf
);
1066 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
,
1068 "Make BUFFER stop keeping undo information.\n\
1069 No argument or nil as argument means do this for the current buffer.")
1071 register Lisp_Object buffer
;
1073 Lisp_Object real_buffer
;
1076 XSETBUFFER (real_buffer
, current_buffer
);
1079 real_buffer
= Fget_buffer (buffer
);
1080 if (NILP (real_buffer
))
1084 XBUFFER (real_buffer
)->undo_list
= Qt
;
1089 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
1091 "Start keeping undo information for buffer BUFFER.\n\
1092 No argument or nil as argument means do this for the current buffer.")
1094 register Lisp_Object buffer
;
1096 Lisp_Object real_buffer
;
1099 XSETBUFFER (real_buffer
, current_buffer
);
1102 real_buffer
= Fget_buffer (buffer
);
1103 if (NILP (real_buffer
))
1107 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
1108 XBUFFER (real_buffer
)->undo_list
= Qnil
;
1114 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
1115 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1116 The buffer being killed will be current while the hook is running.\n\
1119 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
1120 "Kill the buffer BUFFER.\n\
1121 The argument may be a buffer or may be the name of a buffer.\n\
1122 An argument of nil means kill the current buffer.\n\n\
1123 Value is t if the buffer is actually killed, nil if user says no.\n\n\
1124 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
1125 if not void, is a list of functions to be called, with no arguments,\n\
1126 before the buffer is actually killed. The buffer to be killed is current\n\
1127 when the hook functions are called.\n\n\
1128 Any processes that have this buffer as the `process-buffer' are killed\n\
1134 register struct buffer
*b
;
1135 register Lisp_Object tem
;
1136 register struct Lisp_Marker
*m
;
1137 struct gcpro gcpro1
;
1140 buf
= Fcurrent_buffer ();
1142 buf
= Fget_buffer (buffer
);
1148 /* Avoid trouble for buffer already dead. */
1152 /* Query if the buffer is still modified. */
1153 if (INTERACTIVE
&& !NILP (b
->filename
)
1154 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1157 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
1158 XSTRING (b
->name
)->data
));
1164 /* Run hooks with the buffer to be killed the current buffer. */
1166 int count
= specpdl_ptr
- specpdl
;
1169 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1170 set_buffer_internal (b
);
1172 /* First run the query functions; if any query is answered no,
1173 don't kill the buffer. */
1174 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
1176 tem
= call0 (Fcar (list
));
1178 return unbind_to (count
, Qnil
);
1181 /* Then run the hooks. */
1182 if (!NILP (Vrun_hooks
))
1183 call1 (Vrun_hooks
, Qkill_buffer_hook
);
1184 unbind_to (count
, Qnil
);
1187 /* We have no more questions to ask. Verify that it is valid
1188 to kill the buffer. This must be done after the questions
1189 since anything can happen within do_yes_or_no_p. */
1191 /* Don't kill the minibuffer now current. */
1192 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1198 /* When we kill a base buffer, kill all its indirect buffers.
1199 We do it at this stage so nothing terrible happens if they
1200 ask questions or their hooks get errors. */
1201 if (! b
->base_buffer
)
1203 struct buffer
*other
;
1207 for (other
= all_buffers
; other
; other
= other
->next
)
1208 /* all_buffers contains dead buffers too;
1209 don't re-kill them. */
1210 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1213 XSETBUFFER (buf
, other
);
1220 /* Make this buffer not be current.
1221 In the process, notice if this is the sole visible buffer
1222 and give up if so. */
1223 if (b
== current_buffer
)
1225 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1227 if (b
== current_buffer
)
1231 /* Now there is no question: we can kill the buffer. */
1233 #ifdef CLASH_DETECTION
1234 /* Unlock this buffer's file, if it is locked. */
1236 #endif /* CLASH_DETECTION */
1238 kill_buffer_processes (buf
);
1240 tem
= Vinhibit_quit
;
1242 replace_buffer_in_all_windows (buf
);
1243 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1244 frames_discard_buffer (buf
);
1245 Vinhibit_quit
= tem
;
1247 /* Delete any auto-save file, if we saved it in this session. */
1248 if (STRINGP (b
->auto_save_file_name
)
1249 && b
->auto_save_modified
!= 0
1250 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
)
1253 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1255 internal_delete_file (b
->auto_save_file_name
);
1260 /* Unchain all markers that belong to this indirect buffer.
1261 Don't unchain the markers that belong to the base buffer
1262 or its other indirect buffers. */
1263 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1269 unchain_marker (tem
);
1275 /* Unchain all markers of this buffer and its indirect buffers.
1276 and leave them pointing nowhere. */
1277 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1284 BUF_MARKERS (b
) = Qnil
;
1285 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1287 /* Perhaps we should explicitly free the interval tree here... */
1290 /* Reset the local variables, so that this buffer's local values
1291 won't be protected from GC. They would be protected
1292 if they happened to remain encached in their symbols.
1293 This gets rid of them for certain. */
1294 swap_out_buffer_local_variables (b
);
1295 reset_buffer_local_variables (b
, 1);
1300 if (! b
->base_buffer
)
1301 BUFFER_FREE (BUF_BEG_ADDR (b
));
1303 if (b
->newline_cache
)
1305 free_region_cache (b
->newline_cache
);
1306 b
->newline_cache
= 0;
1308 if (b
->width_run_cache
)
1310 free_region_cache (b
->width_run_cache
);
1311 b
->width_run_cache
= 0;
1313 b
->width_table
= Qnil
;
1315 b
->undo_list
= Qnil
;
1320 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1321 we do this each time BUF is selected visibly, the more recently
1322 selected buffers are always closer to the front of the list. This
1323 means that other_buffer is more likely to choose a relevant buffer. */
1329 register Lisp_Object link
, prev
;
1331 frame
= selected_frame
;
1334 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCDR (link
))
1336 if (EQ (XCDR (XCAR (link
)), buf
))
1341 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1342 we cannot use Fdelq itself here because it allows quitting. */
1345 Vbuffer_alist
= XCDR (Vbuffer_alist
);
1347 XCDR (prev
) = XCDR (XCDR (prev
));
1349 XCDR (link
) = Vbuffer_alist
;
1350 Vbuffer_alist
= link
;
1352 /* Now move this buffer to the front of frame_buffer_list also. */
1355 for (link
= frame_buffer_list (frame
); CONSP (link
);
1358 if (EQ (XCAR (link
), buf
))
1363 /* Effectively do delq. */
1368 set_frame_buffer_list (frame
,
1369 XCDR (frame_buffer_list (frame
)));
1371 XCDR (prev
) = XCDR (XCDR (prev
));
1373 XCDR (link
) = frame_buffer_list (frame
);
1374 set_frame_buffer_list (frame
, link
);
1377 set_frame_buffer_list (frame
, Fcons (buf
, frame_buffer_list (frame
)));
1380 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1381 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1382 Use this function before selecting the buffer, since it may need to inspect\n\
1383 the current buffer's major mode.")
1388 Lisp_Object function
;
1390 function
= buffer_defaults
.major_mode
;
1391 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1392 function
= current_buffer
->major_mode
;
1394 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1397 count
= specpdl_ptr
- specpdl
;
1399 /* To select a nonfundamental mode,
1400 select the buffer temporarily and then call the mode function. */
1402 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1404 Fset_buffer (buffer
);
1407 return unbind_to (count
, Qnil
);
1410 /* If switching buffers in WINDOW would be an error, return
1411 a C string saying what the error would be. */
1414 no_switch_window (window
)
1418 if (EQ (minibuf_window
, window
))
1419 return "Cannot switch buffers in minibuffer window";
1420 tem
= Fwindow_dedicated_p (window
);
1422 return "Cannot switch buffers in a dedicated window";
1426 /* Switch to buffer BUFFER in the selected window.
1427 If NORECORD is non-nil, don't call record_buffer. */
1430 switch_to_buffer_1 (buffer
, norecord
)
1431 Lisp_Object buffer
, norecord
;
1433 register Lisp_Object buf
;
1436 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1439 buf
= Fget_buffer (buffer
);
1442 buf
= Fget_buffer_create (buffer
);
1443 Fset_buffer_major_mode (buf
);
1447 if (NILP (norecord
))
1448 record_buffer (buf
);
1450 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1451 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1458 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1459 "Select buffer BUFFER in the current window.\n\
1460 BUFFER may be a buffer or a buffer name.\n\
1461 Optional second arg NORECORD non-nil means\n\
1462 do not put this buffer at the front of the list of recently selected ones.\n\
1464 WARNING: This is NOT the way to work on another buffer temporarily\n\
1465 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1466 the window-buffer correspondences.")
1468 Lisp_Object buffer
, norecord
;
1472 err
= no_switch_window (selected_window
);
1473 if (err
) error (err
);
1475 return switch_to_buffer_1 (buffer
, norecord
);
1478 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1479 "Select buffer BUFFER in some window, preferably a different one.\n\
1480 If BUFFER is nil, then some other buffer is chosen.\n\
1481 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1482 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1483 window even if BUFFER is already visible in the selected window.\n\
1484 This uses the function `display-buffer' as a subroutine; see the documentation\n\
1485 of `display-buffer' for additional customization information.\n\
1487 Optional third arg NORECORD non-nil means\n\
1488 do not put this buffer at the front of the list of recently selected ones.")
1489 (buffer
, other_window
, norecord
)
1490 Lisp_Object buffer
, other_window
, norecord
;
1492 register Lisp_Object buf
;
1494 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1497 buf
= Fget_buffer (buffer
);
1500 buf
= Fget_buffer_create (buffer
);
1501 Fset_buffer_major_mode (buf
);
1505 if (NILP (norecord
))
1506 record_buffer (buf
);
1507 Fselect_window (Fdisplay_buffer (buf
, other_window
, Qnil
));
1511 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1512 "Return the current buffer as a Lisp object.")
1515 register Lisp_Object buf
;
1516 XSETBUFFER (buf
, current_buffer
);
1520 /* Set the current buffer to B.
1522 We previously set windows_or_buffers_changed here to invalidate
1523 global unchanged information in beg_unchanged and end_unchanged.
1524 This is no longer necessary because we now compute unchanged
1525 information on a buffer-basis. Every action affecting other
1526 windows than the selected one requires a select_window at some
1527 time, and that increments windows_or_buffers_changed. */
1530 set_buffer_internal (b
)
1531 register struct buffer
*b
;
1533 if (current_buffer
!= b
)
1534 set_buffer_internal_1 (b
);
1537 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1538 This is used by redisplay. */
1541 set_buffer_internal_1 (b
)
1542 register struct buffer
*b
;
1544 register struct buffer
*old_buf
;
1545 register Lisp_Object tail
, valcontents
;
1548 if (current_buffer
== b
)
1551 old_buf
= current_buffer
;
1553 last_known_column_point
= -1; /* invalidate indentation cache */
1557 /* Put the undo list back in the base buffer, so that it appears
1558 that an indirect buffer shares the undo list of its base. */
1559 if (old_buf
->base_buffer
)
1560 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1562 /* If the old current buffer has markers to record PT, BEGV and ZV
1563 when it is not current, update them now. */
1564 if (! NILP (old_buf
->pt_marker
))
1567 XSETBUFFER (obuf
, old_buf
);
1568 set_marker_both (old_buf
->pt_marker
, obuf
,
1569 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1571 if (! NILP (old_buf
->begv_marker
))
1574 XSETBUFFER (obuf
, old_buf
);
1575 set_marker_both (old_buf
->begv_marker
, obuf
,
1576 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1578 if (! NILP (old_buf
->zv_marker
))
1581 XSETBUFFER (obuf
, old_buf
);
1582 set_marker_both (old_buf
->zv_marker
, obuf
,
1583 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1587 /* Get the undo list from the base buffer, so that it appears
1588 that an indirect buffer shares the undo list of its base. */
1590 b
->undo_list
= b
->base_buffer
->undo_list
;
1592 /* If the new current buffer has markers to record PT, BEGV and ZV
1593 when it is not current, fetch them now. */
1594 if (! NILP (b
->pt_marker
))
1596 BUF_PT (b
) = marker_position (b
->pt_marker
);
1597 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1599 if (! NILP (b
->begv_marker
))
1601 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1602 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1604 if (! NILP (b
->zv_marker
))
1606 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1607 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1610 /* Look down buffer's list of local Lisp variables
1611 to find and update any that forward into C variables. */
1613 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCDR (tail
))
1615 valcontents
= XSYMBOL (XCAR (XCAR (tail
)))->value
;
1616 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1617 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1618 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1619 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1620 /* Just reference the variable
1621 to cause it to become set for this buffer. */
1622 Fsymbol_value (XCAR (XCAR (tail
)));
1625 /* Do the same with any others that were local to the previous buffer */
1628 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCDR (tail
))
1630 valcontents
= XSYMBOL (XCAR (XCAR (tail
)))->value
;
1631 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1632 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1633 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1634 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1635 /* Just reference the variable
1636 to cause it to become set for this buffer. */
1637 Fsymbol_value (XCAR (XCAR (tail
)));
1641 /* Switch to buffer B temporarily for redisplay purposes.
1642 This avoids certain things that don't need to be done within redisplay. */
1648 register struct buffer
*old_buf
;
1650 if (current_buffer
== b
)
1653 old_buf
= current_buffer
;
1658 /* If the old current buffer has markers to record PT, BEGV and ZV
1659 when it is not current, update them now. */
1660 if (! NILP (old_buf
->pt_marker
))
1663 XSETBUFFER (obuf
, old_buf
);
1664 set_marker_both (old_buf
->pt_marker
, obuf
,
1665 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1667 if (! NILP (old_buf
->begv_marker
))
1670 XSETBUFFER (obuf
, old_buf
);
1671 set_marker_both (old_buf
->begv_marker
, obuf
,
1672 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1674 if (! NILP (old_buf
->zv_marker
))
1677 XSETBUFFER (obuf
, old_buf
);
1678 set_marker_both (old_buf
->zv_marker
, obuf
,
1679 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1683 /* If the new current buffer has markers to record PT, BEGV and ZV
1684 when it is not current, fetch them now. */
1685 if (! NILP (b
->pt_marker
))
1687 BUF_PT (b
) = marker_position (b
->pt_marker
);
1688 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1690 if (! NILP (b
->begv_marker
))
1692 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1693 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1695 if (! NILP (b
->zv_marker
))
1697 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1698 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1702 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1703 "Make the buffer BUFFER current for editing operations.\n\
1704 BUFFER may be a buffer or the name of an existing buffer.\n\
1705 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1706 This function does not display the buffer, so its effect ends\n\
1707 when the current command terminates.\n\
1708 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1710 register Lisp_Object buffer
;
1712 register Lisp_Object buf
;
1713 buf
= Fget_buffer (buffer
);
1716 if (NILP (XBUFFER (buf
)->name
))
1717 error ("Selecting deleted buffer");
1718 set_buffer_internal (XBUFFER (buf
));
1722 /* Set the current buffer to BUFFER provided it is alive. */
1725 set_buffer_if_live (buffer
)
1728 if (! NILP (XBUFFER (buffer
)->name
))
1729 Fset_buffer (buffer
);
1733 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1734 Sbarf_if_buffer_read_only
, 0, 0, 0,
1735 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1738 if (!NILP (current_buffer
->read_only
)
1739 && NILP (Vinhibit_read_only
))
1740 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1744 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1745 "Put BUFFER at the end of the list of all buffers.\n\
1746 There it is the least likely candidate for `other-buffer' to return;\n\
1747 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1748 If BUFFER is nil or omitted, bury the current buffer.\n\
1749 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1750 selected window if it is displayed there.")
1752 register Lisp_Object buffer
;
1754 /* Figure out what buffer we're going to bury. */
1757 XSETBUFFER (buffer
, current_buffer
);
1759 /* If we're burying the current buffer, unshow it. */
1760 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
, Qnil
), Qnil
);
1766 buf1
= Fget_buffer (buffer
);
1772 /* Move buffer to the end of the buffer list. Do nothing if the
1773 buffer is killed. */
1774 if (!NILP (XBUFFER (buffer
)->name
))
1776 Lisp_Object aelt
, link
;
1778 aelt
= Frassq (buffer
, Vbuffer_alist
);
1779 link
= Fmemq (aelt
, Vbuffer_alist
);
1780 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1782 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1784 frames_bury_buffer (buffer
);
1790 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1791 "Delete the entire contents of the current buffer.\n\
1792 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1793 so the buffer is truly empty after this.")
1800 current_buffer
->last_window_start
= 1;
1801 /* Prevent warnings, or suspension of auto saving, that would happen
1802 if future size is less than past size. Use of erase-buffer
1803 implies that the future text is not really related to the past text. */
1804 XSETFASTINT (current_buffer
->save_length
, 0);
1809 validate_region (b
, e
)
1810 register Lisp_Object
*b
, *e
;
1812 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1813 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1815 if (XINT (*b
) > XINT (*e
))
1818 tem
= *b
; *b
= *e
; *e
= tem
;
1821 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1822 && XINT (*e
) <= ZV
))
1823 args_out_of_range (*b
, *e
);
1826 /* Advance BYTE_POS up to a character boundary
1827 and return the adjusted position. */
1830 advance_to_char_boundary (byte_pos
)
1835 if (byte_pos
== BEG
)
1836 /* Beginning of buffer is always a character boundary. */
1839 c
= FETCH_BYTE (byte_pos
);
1840 if (! CHAR_HEAD_P (c
))
1842 /* We should advance BYTE_POS only when C is a constituent of a
1843 multibyte sequence. */
1844 int orig_byte_pos
= byte_pos
;
1849 c
= FETCH_BYTE (byte_pos
);
1851 while (! CHAR_HEAD_P (c
) && byte_pos
> BEG
);
1853 if (byte_pos
< orig_byte_pos
)
1854 byte_pos
= orig_byte_pos
;
1855 /* If C is a constituent of a multibyte sequence, BYTE_POS was
1856 surely advance to the correct character boundary. If C is
1857 not, BYTE_POS was unchanged. */
1863 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte
, Sset_buffer_multibyte
,
1865 "Set the multibyte flag of the current buffer to FLAG.\n\
1866 If FLAG is t, this makes the buffer a multibyte buffer.\n\
1867 If FLAG is nil, this makes the buffer a single-byte buffer.\n\
1868 The buffer contents remain unchanged as a sequence of bytes\n\
1869 but the contents viewed as characters do change.")
1873 Lisp_Object tail
, markers
;
1874 struct buffer
*other
;
1875 int undo_enabled_p
= !EQ (current_buffer
->undo_list
, Qt
);
1876 int begv
= BEGV
, zv
= ZV
;
1877 int narrowed
= (BEG
!= begv
|| Z
!= zv
);
1878 int modified_p
= !NILP (Fbuffer_modified_p (Qnil
));
1880 if (current_buffer
->base_buffer
)
1881 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
1883 /* Do nothing if nothing actually changes. */
1884 if (NILP (flag
) == NILP (current_buffer
->enable_multibyte_characters
))
1887 /* It would be better to update the list,
1888 but this is good enough for now. */
1890 current_buffer
->undo_list
= Qt
;
1892 /* If the cached position is for this buffer, clear it out. */
1893 clear_charpos_cache (current_buffer
);
1903 /* Do this first, so it can use CHAR_TO_BYTE
1904 to calculate the old correspondences. */
1905 set_intervals_multibyte (0);
1907 current_buffer
->enable_multibyte_characters
= Qnil
;
1913 TEMP_SET_PT_BOTH (PT_BYTE
, PT_BYTE
);
1915 tail
= BUF_MARKERS (current_buffer
);
1916 while (! NILP (tail
))
1918 XMARKER (tail
)->charpos
= XMARKER (tail
)->bytepos
;
1919 tail
= XMARKER (tail
)->chain
;
1922 /* Convert multibyte form of 8-bit characters to unibyte. */
1937 if (MULTIBYTE_STR_AS_UNIBYTE_P (p
, bytes
))
1938 p
+= bytes
, pos
+= bytes
;
1941 c
= STRING_CHAR (p
, stop
- pos
);
1942 /* Delete all bytes for this 8-bit character but the
1943 last one, and change the last one to the charcter
1946 del_range_2 (pos
, pos
, pos
+ bytes
, pos
+ bytes
, 0);
1958 Fnarrow_to_region (make_number (begv
), make_number (zv
));
1966 /* Be sure not to have a multibyte sequence striding over the GAP.
1967 Ex: We change this: "...abc\201 _GAP_ \241def..."
1968 to: "...abc _GAP_ \201\241def..." */
1970 if (GPT_BYTE
> 1 && GPT_BYTE
< Z_BYTE
1971 && ! CHAR_HEAD_P (*(GAP_END_ADDR
)))
1973 unsigned char *p
= GPT_ADDR
- 1;
1975 while (! CHAR_HEAD_P (*p
) && p
> BEG_ADDR
) p
--;
1976 if (BASE_LEADING_CODE_P (*p
))
1978 int new_gpt
= GPT_BYTE
- (GPT_ADDR
- p
);
1980 move_gap_both (new_gpt
, new_gpt
);
1984 /* Make the buffer contents valid as multibyte by converting
1985 8-bit characters to multibyte form. */
2001 if (UNIBYTE_STR_AS_MULTIBYTE_P (p
, stop
- pos
, bytes
))
2002 p
+= bytes
, pos
+= bytes
;
2005 unsigned char tmp
[MAX_MULTIBYTE_LENGTH
];
2007 bytes
= CHAR_STRING (*p
, tmp
);
2009 TEMP_SET_PT_BOTH (pos
+ 1, pos
+ 1);
2011 insert_1_both (tmp
+ 1, bytes
, bytes
, 1, 0, 0);
2012 /* Now the gap is after the just inserted data. */
2029 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2031 /* Do this first, so that chars_in_text asks the right question.
2032 set_intervals_multibyte needs it too. */
2033 current_buffer
->enable_multibyte_characters
= Qt
;
2035 GPT_BYTE
= advance_to_char_boundary (GPT_BYTE
);
2036 GPT
= chars_in_text (BEG_ADDR
, GPT_BYTE
- BEG_BYTE
) + BEG
;
2038 Z
= chars_in_text (GAP_END_ADDR
, Z_BYTE
- GPT_BYTE
) + GPT
;
2040 BEGV_BYTE
= advance_to_char_boundary (BEGV_BYTE
);
2041 if (BEGV_BYTE
> GPT_BYTE
)
2042 BEGV
= chars_in_text (GAP_END_ADDR
, BEGV_BYTE
- GPT_BYTE
) + GPT
;
2044 BEGV
= chars_in_text (BEG_ADDR
, BEGV_BYTE
- BEG_BYTE
) + BEG
;
2046 ZV_BYTE
= advance_to_char_boundary (ZV_BYTE
);
2047 if (ZV_BYTE
> GPT_BYTE
)
2048 ZV
= chars_in_text (GAP_END_ADDR
, ZV_BYTE
- GPT_BYTE
) + GPT
;
2050 ZV
= chars_in_text (BEG_ADDR
, ZV_BYTE
- BEG_BYTE
) + BEG
;
2053 int pt_byte
= advance_to_char_boundary (PT_BYTE
);
2056 if (pt_byte
> GPT_BYTE
)
2057 pt
= chars_in_text (GAP_END_ADDR
, pt_byte
- GPT_BYTE
) + GPT
;
2059 pt
= chars_in_text (BEG_ADDR
, pt_byte
- BEG_BYTE
) + BEG
;
2060 TEMP_SET_PT_BOTH (pt
, pt_byte
);
2063 tail
= markers
= BUF_MARKERS (current_buffer
);
2065 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
2066 getting confused by the markers that have not yet been updated.
2067 It is also a signal that it should never create a marker. */
2068 BUF_MARKERS (current_buffer
) = Qnil
;
2070 while (! NILP (tail
))
2072 XMARKER (tail
)->bytepos
2073 = advance_to_char_boundary (XMARKER (tail
)->bytepos
);
2074 XMARKER (tail
)->charpos
= BYTE_TO_CHAR (XMARKER (tail
)->bytepos
);
2076 tail
= XMARKER (tail
)->chain
;
2079 /* Make sure no markers were put on the chain
2080 while the chain value was incorrect. */
2081 if (! EQ (BUF_MARKERS (current_buffer
), Qnil
))
2084 BUF_MARKERS (current_buffer
) = markers
;
2086 /* Do this last, so it can calculate the new correspondences
2087 between chars and bytes. */
2088 set_intervals_multibyte (1);
2092 current_buffer
->undo_list
= Qnil
;
2094 /* Changing the multibyteness of a buffer means that all windows
2095 showing that buffer must be updated thoroughly. */
2096 current_buffer
->prevent_redisplay_optimizations_p
= 1;
2097 ++windows_or_buffers_changed
;
2099 /* Copy this buffer's new multibyte status
2100 into all of its indirect buffers. */
2101 for (other
= all_buffers
; other
; other
= other
->next
)
2102 if (other
->base_buffer
== current_buffer
&& !NILP (other
->name
))
2104 other
->enable_multibyte_characters
2105 = current_buffer
->enable_multibyte_characters
;
2106 other
->prevent_redisplay_optimizations_p
= 1;
2109 /* Restore the modifiedness of the buffer. */
2110 if (!modified_p
&& !NILP (Fbuffer_modified_p (Qnil
)))
2111 Fset_buffer_modified_p (Qnil
);
2116 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
2118 "Switch to Fundamental mode by killing current buffer's local variables.\n\
2119 Most local variable bindings are eliminated so that the default values\n\
2120 become effective once more. Also, the syntax table is set from\n\
2121 `standard-syntax-table', the local keymap is set to nil,\n\
2122 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
2123 This function also forces redisplay of the mode line.\n\
2125 Every function to select a new major mode starts by\n\
2126 calling this function.\n\n\
2127 As a special exception, local variables whose names have\n\
2128 a non-nil `permanent-local' property are not eliminated by this function.\n\
2130 The first thing this function does is run\n\
2131 the normal hook `change-major-mode-hook'.")
2134 register Lisp_Object alist
, sym
, tem
;
2137 if (!NILP (Vrun_hooks
))
2138 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
2139 oalist
= current_buffer
->local_var_alist
;
2141 /* Make sure none of the bindings in oalist
2142 remain swapped in, in their symbols. */
2144 swap_out_buffer_local_variables (current_buffer
);
2146 /* Actually eliminate all local bindings of this buffer. */
2148 reset_buffer_local_variables (current_buffer
, 0);
2150 /* Redisplay mode lines; we are changing major mode. */
2152 update_mode_lines
++;
2154 /* Any which are supposed to be permanent,
2155 make local again, with the same values they had. */
2157 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
2159 sym
= XCAR (XCAR (alist
));
2160 tem
= Fget (sym
, Qpermanent_local
);
2163 Fmake_local_variable (sym
);
2164 Fset (sym
, XCDR (XCAR (alist
)));
2168 /* Force mode-line redisplay. Useful here because all major mode
2169 commands call this function. */
2170 update_mode_lines
++;
2175 /* Make sure no local variables remain set up with buffer B
2176 for their current values. */
2179 swap_out_buffer_local_variables (b
)
2182 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
2184 XSETBUFFER (buffer
, b
);
2185 oalist
= b
->local_var_alist
;
2187 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
2189 sym
= XCAR (XCAR (alist
));
2191 /* Need not do anything if some other buffer's binding is now encached. */
2192 tem
= XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->buffer
;
2193 if (BUFFERP (tem
) && XBUFFER (tem
) == current_buffer
)
2195 /* Symbol is set up for this buffer's old local value.
2196 Set it up for the current buffer with the default value. */
2198 tem
= XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
;
2199 /* Store the symbol's current value into the alist entry
2200 it is currently set up for. This is so that, if the
2201 local is marked permanent, and we make it local again
2202 later in Fkill_all_local_variables, we don't lose the value. */
2204 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->realvalue
);
2205 /* Switch to the symbol's default-value alist entry. */
2207 /* Mark it as current for buffer B. */
2208 XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->buffer
= buffer
;
2209 /* Store the current value into any forwarding in the symbol. */
2210 store_symval_forwarding (sym
,
2211 XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->realvalue
,
2217 /* Find all the overlays in the current buffer that contain position POS.
2218 Return the number found, and store them in a vector in *VEC_PTR.
2219 Store in *LEN_PTR the size allocated for the vector.
2220 Store in *NEXT_PTR the next position after POS where an overlay starts,
2221 or ZV if there are no more overlays.
2222 Store in *PREV_PTR the previous position before POS where an overlay ends,
2223 or where an overlay starts which ends at or after POS;
2224 or BEGV if there are no such overlays.
2225 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2227 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2228 when this function is called.
2230 If EXTEND is non-zero, we make the vector bigger if necessary.
2231 If EXTEND is zero, we never extend the vector,
2232 and we store only as many overlays as will fit.
2233 But we still return the total number of overlays. */
2236 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2239 Lisp_Object
**vec_ptr
;
2244 Lisp_Object tail
, overlay
, start
, end
;
2247 Lisp_Object
*vec
= *vec_ptr
;
2250 int inhibit_storing
= 0;
2252 for (tail
= current_buffer
->overlays_before
;
2256 int startpos
, endpos
;
2258 overlay
= XCAR (tail
);
2260 start
= OVERLAY_START (overlay
);
2261 end
= OVERLAY_END (overlay
);
2262 endpos
= OVERLAY_POSITION (end
);
2269 startpos
= OVERLAY_POSITION (start
);
2270 /* This one ends at or after POS
2271 so its start counts for PREV_PTR if it's before POS. */
2272 if (prev
< startpos
&& startpos
< pos
)
2276 if (startpos
<= pos
)
2280 /* The supplied vector is full.
2281 Either make it bigger, or don't store any more in it. */
2284 /* Make it work with an initial len == 0. */
2289 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2293 inhibit_storing
= 1;
2296 if (!inhibit_storing
)
2298 /* Keep counting overlays even if we can't return them all. */
2301 else if (startpos
< next
)
2305 for (tail
= current_buffer
->overlays_after
;
2309 int startpos
, endpos
;
2311 overlay
= XCAR (tail
);
2313 start
= OVERLAY_START (overlay
);
2314 end
= OVERLAY_END (overlay
);
2315 startpos
= OVERLAY_POSITION (start
);
2318 if (startpos
< next
)
2322 endpos
= OVERLAY_POSITION (end
);
2329 *len_ptr
= len
*= 2;
2332 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2336 inhibit_storing
= 1;
2339 if (!inhibit_storing
)
2343 if (startpos
< pos
&& startpos
> prev
)
2346 else if (endpos
< pos
&& endpos
> prev
)
2348 else if (endpos
== pos
&& startpos
> prev
)
2359 /* Find all the overlays in the current buffer that overlap the range BEG-END
2360 or are empty at BEG.
2362 Return the number found, and store them in a vector in *VEC_PTR.
2363 Store in *LEN_PTR the size allocated for the vector.
2364 Store in *NEXT_PTR the next position after POS where an overlay starts,
2365 or ZV if there are no more overlays.
2366 Store in *PREV_PTR the previous position before POS where an overlay ends,
2367 or BEGV if there are no previous overlays.
2368 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2370 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2371 when this function is called.
2373 If EXTEND is non-zero, we make the vector bigger if necessary.
2374 If EXTEND is zero, we never extend the vector,
2375 and we store only as many overlays as will fit.
2376 But we still return the total number of overlays. */
2379 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2382 Lisp_Object
**vec_ptr
;
2387 Lisp_Object tail
, overlay
, ostart
, oend
;
2390 Lisp_Object
*vec
= *vec_ptr
;
2393 int inhibit_storing
= 0;
2395 for (tail
= current_buffer
->overlays_before
;
2399 int startpos
, endpos
;
2401 overlay
= XCAR (tail
);
2403 ostart
= OVERLAY_START (overlay
);
2404 oend
= OVERLAY_END (overlay
);
2405 endpos
= OVERLAY_POSITION (oend
);
2412 startpos
= OVERLAY_POSITION (ostart
);
2413 /* Count an interval if it either overlaps the range
2414 or is empty at the start of the range. */
2415 if ((beg
< endpos
&& startpos
< end
)
2416 || (startpos
== endpos
&& beg
== endpos
))
2420 /* The supplied vector is full.
2421 Either make it bigger, or don't store any more in it. */
2424 *len_ptr
= len
*= 2;
2425 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2429 inhibit_storing
= 1;
2432 if (!inhibit_storing
)
2434 /* Keep counting overlays even if we can't return them all. */
2437 else if (startpos
< next
)
2441 for (tail
= current_buffer
->overlays_after
;
2445 int startpos
, endpos
;
2447 overlay
= XCAR (tail
);
2449 ostart
= OVERLAY_START (overlay
);
2450 oend
= OVERLAY_END (overlay
);
2451 startpos
= OVERLAY_POSITION (ostart
);
2454 if (startpos
< next
)
2458 endpos
= OVERLAY_POSITION (oend
);
2459 /* Count an interval if it either overlaps the range
2460 or is empty at the start of the range. */
2461 if ((beg
< endpos
&& startpos
< end
)
2462 || (startpos
== endpos
&& beg
== endpos
))
2468 *len_ptr
= len
*= 2;
2469 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2473 inhibit_storing
= 1;
2476 if (!inhibit_storing
)
2480 else if (endpos
< beg
&& endpos
> prev
)
2491 /* Fast function to just test if we're at an overlay boundary. */
2493 overlay_touches_p (pos
)
2496 Lisp_Object tail
, overlay
;
2498 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
2503 overlay
= XCAR (tail
);
2504 if (!GC_OVERLAYP (overlay
))
2507 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2510 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2514 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
2519 overlay
= XCAR (tail
);
2520 if (!GC_OVERLAYP (overlay
))
2523 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2526 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2534 Lisp_Object overlay
;
2540 compare_overlays (v1
, v2
)
2541 const void *v1
, *v2
;
2543 const struct sortvec
*s1
= (const struct sortvec
*) v1
;
2544 const struct sortvec
*s2
= (const struct sortvec
*) v2
;
2545 if (s1
->priority
!= s2
->priority
)
2546 return s1
->priority
- s2
->priority
;
2547 if (s1
->beg
!= s2
->beg
)
2548 return s1
->beg
- s2
->beg
;
2549 if (s1
->end
!= s2
->end
)
2550 return s2
->end
- s1
->end
;
2554 /* Sort an array of overlays by priority. The array is modified in place.
2555 The return value is the new size; this may be smaller than the original
2556 size if some of the overlays were invalid or were window-specific. */
2558 sort_overlays (overlay_vec
, noverlays
, w
)
2559 Lisp_Object
*overlay_vec
;
2564 struct sortvec
*sortvec
;
2565 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2567 /* Put the valid and relevant overlays into sortvec. */
2569 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2572 Lisp_Object overlay
;
2574 overlay
= overlay_vec
[i
];
2575 if (OVERLAY_VALID (overlay
)
2576 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2577 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2579 /* If we're interested in a specific window, then ignore
2580 overlays that are limited to some other window. */
2585 window
= Foverlay_get (overlay
, Qwindow
);
2586 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2590 /* This overlay is good and counts: put it into sortvec. */
2591 sortvec
[j
].overlay
= overlay
;
2592 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2593 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2594 tem
= Foverlay_get (overlay
, Qpriority
);
2596 sortvec
[j
].priority
= XINT (tem
);
2598 sortvec
[j
].priority
= 0;
2604 /* Sort the overlays into the proper order: increasing priority. */
2607 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2609 for (i
= 0; i
< noverlays
; i
++)
2610 overlay_vec
[i
] = sortvec
[i
].overlay
;
2616 Lisp_Object string
, string2
;
2623 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2624 int size
; /* Allocated length of that array. */
2625 int used
; /* How much of the array is currently in use. */
2626 int bytes
; /* Total length of the strings in buf. */
2629 /* Buffers for storing information about the overlays touching a given
2630 position. These could be automatic variables in overlay_strings, but
2631 it's more efficient to hold onto the memory instead of repeatedly
2632 allocating and freeing it. */
2633 static struct sortstrlist overlay_heads
, overlay_tails
;
2634 static unsigned char *overlay_str_buf
;
2636 /* Allocated length of overlay_str_buf. */
2637 static int overlay_str_len
;
2639 /* A comparison function suitable for passing to qsort. */
2641 cmp_for_strings (as1
, as2
)
2644 struct sortstr
*s1
= (struct sortstr
*)as1
;
2645 struct sortstr
*s2
= (struct sortstr
*)as2
;
2646 if (s1
->size
!= s2
->size
)
2647 return s2
->size
- s1
->size
;
2648 if (s1
->priority
!= s2
->priority
)
2649 return s1
->priority
- s2
->priority
;
2654 record_overlay_string (ssl
, str
, str2
, pri
, size
)
2655 struct sortstrlist
*ssl
;
2656 Lisp_Object str
, str2
, pri
;
2661 if (ssl
->used
== ssl
->size
)
2667 ssl
->buf
= ((struct sortstr
*)
2668 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2670 ssl
->buf
[ssl
->used
].string
= str
;
2671 ssl
->buf
[ssl
->used
].string2
= str2
;
2672 ssl
->buf
[ssl
->used
].size
= size
;
2673 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2676 if (NILP (current_buffer
->enable_multibyte_characters
))
2677 nbytes
= XSTRING (str
)->size
;
2678 else if (! STRING_MULTIBYTE (str
))
2679 nbytes
= count_size_as_multibyte (XSTRING (str
)->data
,
2680 STRING_BYTES (XSTRING (str
)));
2682 nbytes
= STRING_BYTES (XSTRING (str
));
2684 ssl
->bytes
+= nbytes
;
2688 if (NILP (current_buffer
->enable_multibyte_characters
))
2689 nbytes
= XSTRING (str2
)->size
;
2690 else if (! STRING_MULTIBYTE (str2
))
2691 nbytes
= count_size_as_multibyte (XSTRING (str2
)->data
,
2692 STRING_BYTES (XSTRING (str2
)));
2694 nbytes
= STRING_BYTES (XSTRING (str2
));
2696 ssl
->bytes
+= nbytes
;
2700 /* Return the concatenation of the strings associated with overlays that
2701 begin or end at POS, ignoring overlays that are specific to a window
2702 other than W. The strings are concatenated in the appropriate order:
2703 shorter overlays nest inside longer ones, and higher priority inside
2704 lower. Normally all of the after-strings come first, but zero-sized
2705 overlays have their after-strings ride along with the before-strings
2706 because it would look strange to print them inside-out.
2708 Returns the string length, and stores the contents indirectly through
2709 PSTR, if that variable is non-null. The string may be overwritten by
2710 subsequent calls. */
2713 overlay_strings (pos
, w
, pstr
)
2716 unsigned char **pstr
;
2718 Lisp_Object ov
, overlay
, window
, str
;
2719 int startpos
, endpos
;
2720 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
2722 overlay_heads
.used
= overlay_heads
.bytes
= 0;
2723 overlay_tails
.used
= overlay_tails
.bytes
= 0;
2724 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
2726 overlay
= XCAR (ov
);
2727 if (!OVERLAYP (overlay
))
2730 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2731 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2734 if (endpos
!= pos
&& startpos
!= pos
)
2736 window
= Foverlay_get (overlay
, Qwindow
);
2737 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2740 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2741 record_overlay_string (&overlay_heads
, str
,
2743 ? Foverlay_get (overlay
, Qafter_string
)
2745 Foverlay_get (overlay
, Qpriority
),
2747 else if (endpos
== pos
2748 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2749 record_overlay_string (&overlay_tails
, str
, Qnil
,
2750 Foverlay_get (overlay
, Qpriority
),
2753 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
2755 overlay
= XCAR (ov
);
2756 if (!OVERLAYP (overlay
))
2759 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2760 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2763 if (endpos
!= pos
&& startpos
!= pos
)
2765 window
= Foverlay_get (overlay
, Qwindow
);
2766 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2769 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2770 record_overlay_string (&overlay_heads
, str
,
2772 ? Foverlay_get (overlay
, Qafter_string
)
2774 Foverlay_get (overlay
, Qpriority
),
2776 else if (endpos
== pos
2777 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2778 record_overlay_string (&overlay_tails
, str
, Qnil
,
2779 Foverlay_get (overlay
, Qpriority
),
2782 if (overlay_tails
.used
> 1)
2783 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
2785 if (overlay_heads
.used
> 1)
2786 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
2788 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
2793 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
2795 if (total
> overlay_str_len
)
2797 overlay_str_len
= total
;
2798 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
2801 p
= overlay_str_buf
;
2802 for (i
= overlay_tails
.used
; --i
>= 0;)
2805 tem
= overlay_tails
.buf
[i
].string
;
2806 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2807 STRING_BYTES (XSTRING (tem
)),
2808 STRING_MULTIBYTE (tem
), multibyte
);
2811 for (i
= 0; i
< overlay_heads
.used
; ++i
)
2814 tem
= overlay_heads
.buf
[i
].string
;
2815 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2816 STRING_BYTES (XSTRING (tem
)),
2817 STRING_MULTIBYTE (tem
), multibyte
);
2819 tem
= overlay_heads
.buf
[i
].string2
;
2822 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2823 STRING_BYTES (XSTRING (tem
)),
2824 STRING_MULTIBYTE (tem
), multibyte
);
2828 if (p
!= overlay_str_buf
+ total
)
2831 *pstr
= overlay_str_buf
;
2837 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2840 recenter_overlay_lists (buf
, pos
)
2844 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
2846 /* See if anything in overlays_before should move to overlays_after. */
2848 /* We don't strictly need prev in this loop; it should always be nil.
2849 But we use it for symmetry and in case that should cease to be true
2850 with some future change. */
2852 for (tail
= buf
->overlays_before
;
2854 prev
= tail
, tail
= next
)
2857 overlay
= XCAR (tail
);
2859 /* If the overlay is not valid, get rid of it. */
2860 if (!OVERLAY_VALID (overlay
))
2865 /* Splice the cons cell TAIL out of overlays_before. */
2869 buf
->overlays_before
= next
;
2875 beg
= OVERLAY_START (overlay
);
2876 end
= OVERLAY_END (overlay
);
2878 if (OVERLAY_POSITION (end
) > pos
)
2880 /* OVERLAY needs to be moved. */
2881 int where
= OVERLAY_POSITION (beg
);
2882 Lisp_Object other
, other_prev
;
2884 /* Splice the cons cell TAIL out of overlays_before. */
2888 buf
->overlays_before
= next
;
2890 /* Search thru overlays_after for where to put it. */
2892 for (other
= buf
->overlays_after
;
2894 other_prev
= other
, other
= XCDR (other
))
2896 Lisp_Object otherbeg
, otheroverlay
;
2898 otheroverlay
= XCAR (other
);
2899 if (! OVERLAY_VALID (otheroverlay
))
2902 otherbeg
= OVERLAY_START (otheroverlay
);
2903 if (OVERLAY_POSITION (otherbeg
) >= where
)
2907 /* Add TAIL to overlays_after before OTHER. */
2908 XCDR (tail
) = other
;
2909 if (!NILP (other_prev
))
2910 XCDR (other_prev
) = tail
;
2912 buf
->overlays_after
= tail
;
2916 /* We've reached the things that should stay in overlays_before.
2917 All the rest of overlays_before must end even earlier,
2922 /* See if anything in overlays_after should be in overlays_before. */
2924 for (tail
= buf
->overlays_after
;
2926 prev
= tail
, tail
= next
)
2929 overlay
= XCAR (tail
);
2931 /* If the overlay is not valid, get rid of it. */
2932 if (!OVERLAY_VALID (overlay
))
2937 /* Splice the cons cell TAIL out of overlays_after. */
2941 buf
->overlays_after
= next
;
2947 beg
= OVERLAY_START (overlay
);
2948 end
= OVERLAY_END (overlay
);
2950 /* Stop looking, when we know that nothing further
2951 can possibly end before POS. */
2952 if (OVERLAY_POSITION (beg
) > pos
)
2955 if (OVERLAY_POSITION (end
) <= pos
)
2957 /* OVERLAY needs to be moved. */
2958 int where
= OVERLAY_POSITION (end
);
2959 Lisp_Object other
, other_prev
;
2961 /* Splice the cons cell TAIL out of overlays_after. */
2965 buf
->overlays_after
= next
;
2967 /* Search thru overlays_before for where to put it. */
2969 for (other
= buf
->overlays_before
;
2971 other_prev
= other
, other
= XCDR (other
))
2973 Lisp_Object otherend
, otheroverlay
;
2975 otheroverlay
= XCAR (other
);
2976 if (! OVERLAY_VALID (otheroverlay
))
2979 otherend
= OVERLAY_END (otheroverlay
);
2980 if (OVERLAY_POSITION (otherend
) <= where
)
2984 /* Add TAIL to overlays_before before OTHER. */
2985 XCDR (tail
) = other
;
2986 if (!NILP (other_prev
))
2987 XCDR (other_prev
) = tail
;
2989 buf
->overlays_before
= tail
;
2994 XSETFASTINT (buf
->overlay_center
, pos
);
2998 adjust_overlays_for_insert (pos
, length
)
3002 /* After an insertion, the lists are still sorted properly,
3003 but we may need to update the value of the overlay center. */
3004 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
3005 XSETFASTINT (current_buffer
->overlay_center
,
3006 XFASTINT (current_buffer
->overlay_center
) + length
);
3010 adjust_overlays_for_delete (pos
, length
)
3014 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
3015 /* The deletion was to our right. No change needed; the before- and
3016 after-lists are still consistent. */
3018 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
3019 /* The deletion was to our left. We need to adjust the center value
3020 to account for the change in position, but the lists are consistent
3021 given the new value. */
3022 XSETFASTINT (current_buffer
->overlay_center
,
3023 XFASTINT (current_buffer
->overlay_center
) - length
);
3025 /* We're right in the middle. There might be things on the after-list
3026 that now belong on the before-list. Recentering will move them,
3027 and also update the center point. */
3028 recenter_overlay_lists (current_buffer
, pos
);
3031 /* Fix up overlays that were garbled as a result of permuting markers
3032 in the range START through END. Any overlay with at least one
3033 endpoint in this range will need to be unlinked from the overlay
3034 list and reinserted in its proper place.
3035 Such an overlay might even have negative size at this point.
3036 If so, we'll reverse the endpoints. Can you think of anything
3037 better to do in this situation? */
3039 fix_overlays_in_range (start
, end
)
3040 register int start
, end
;
3042 Lisp_Object overlay
;
3043 Lisp_Object before_list
, after_list
;
3044 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
3045 int startpos
, endpos
;
3047 /* This algorithm shifts links around instead of consing and GCing.
3048 The loop invariant is that before_list (resp. after_list) is a
3049 well-formed list except that its last element, the one that
3050 *pbefore (resp. *pafter) points to, is still uninitialized.
3051 So it's not a bug that before_list isn't initialized, although
3052 it may look strange. */
3053 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
3055 overlay
= XCAR (*ptail
);
3056 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3059 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3061 || (startpos
>= start
&& startpos
< end
))
3063 /* If the overlay is backwards, fix that now. */
3064 if (startpos
> endpos
)
3067 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
3069 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
3071 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
3073 /* Add it to the end of the wrong list. Later on,
3074 recenter_overlay_lists will move it to the right place. */
3075 if (endpos
< XINT (current_buffer
->overlay_center
))
3078 pafter
= &XCDR (*ptail
);
3083 pbefore
= &XCDR (*ptail
);
3085 *ptail
= XCDR (*ptail
);
3088 ptail
= &XCDR (*ptail
);
3090 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
3092 overlay
= XCAR (*ptail
);
3093 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3094 if (startpos
>= end
)
3096 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3097 if (startpos
>= start
3098 || (endpos
>= start
&& endpos
< end
))
3100 if (startpos
> endpos
)
3103 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
3105 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
3107 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
3109 if (endpos
< XINT (current_buffer
->overlay_center
))
3112 pafter
= &XCDR (*ptail
);
3117 pbefore
= &XCDR (*ptail
);
3119 *ptail
= XCDR (*ptail
);
3122 ptail
= &XCDR (*ptail
);
3125 /* Splice the constructed (wrong) lists into the buffer's lists,
3126 and let the recenter function make it sane again. */
3127 *pbefore
= current_buffer
->overlays_before
;
3128 current_buffer
->overlays_before
= before_list
;
3129 recenter_overlay_lists (current_buffer
,
3130 XINT (current_buffer
->overlay_center
));
3132 *pafter
= current_buffer
->overlays_after
;
3133 current_buffer
->overlays_after
= after_list
;
3134 recenter_overlay_lists (current_buffer
,
3135 XINT (current_buffer
->overlay_center
));
3138 /* We have two types of overlay: the one whose ending marker is
3139 after-insertion-marker (this is the usual case) and the one whose
3140 ending marker is before-insertion-marker. When `overlays_before'
3141 contains overlays of the latter type and the former type in this
3142 order and both overlays end at inserting position, inserting a text
3143 increases only the ending marker of the latter type, which results
3144 in incorrect ordering of `overlays_before'.
3146 This function fixes ordering of overlays in the slot
3147 `overlays_before' of the buffer *BP. Before the insertion, `point'
3148 was at PREV, and now is at POS. */
3151 fix_overlays_before (bp
, prev
, pos
)
3155 Lisp_Object
*tailp
= &bp
->overlays_before
;
3156 Lisp_Object
*right_place
;
3159 /* After the insertion, the several overlays may be in incorrect
3160 order. The possibility is that, in the list `overlays_before',
3161 an overlay which ends at POS appears after an overlay which ends
3162 at PREV. Since POS is greater than PREV, we must fix the
3163 ordering of these overlays, by moving overlays ends at POS before
3164 the overlays ends at PREV. */
3166 /* At first, find a place where disordered overlays should be linked
3167 in. It is where an overlay which end before POS exists. (i.e. an
3168 overlay whose ending marker is after-insertion-marker if disorder
3170 while (!NILP (*tailp
)
3171 && ((end
= OVERLAY_POSITION (OVERLAY_END (XCAR (*tailp
))))
3173 tailp
= &XCDR (*tailp
);
3175 /* If we don't find such an overlay,
3176 or the found one ends before PREV,
3177 or the found one is the last one in the list,
3178 we don't have to fix anything. */
3181 || NILP (XCDR (*tailp
)))
3184 right_place
= tailp
;
3185 tailp
= &XCDR (*tailp
);
3187 /* Now, end position of overlays in the list *TAILP should be before
3188 or equal to PREV. In the loop, an overlay which ends at POS is
3189 moved ahead to the place pointed by RIGHT_PLACE. If we found an
3190 overlay which ends before PREV, the remaining overlays are in
3192 while (!NILP (*tailp
))
3194 end
= OVERLAY_POSITION (OVERLAY_END (XCAR (*tailp
)));
3197 { /* This overlay is disordered. */
3198 Lisp_Object found
= *tailp
;
3200 /* Unlink the found overlay. */
3201 *tailp
= XCDR (found
);
3202 /* Move an overlay at RIGHT_PLACE to the next of the found one. */
3203 XCDR (found
) = *right_place
;
3204 /* Link it into the right place. */
3205 *right_place
= found
;
3207 else if (end
== prev
)
3208 tailp
= &XCDR (*tailp
);
3209 else /* No more disordered overlay. */
3214 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
3215 "Return t if OBJECT is an overlay.")
3219 return (OVERLAYP (object
) ? Qt
: Qnil
);
3222 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
3223 "Create a new overlay with range BEG to END in BUFFER.\n\
3224 If omitted, BUFFER defaults to the current buffer.\n\
3225 BEG and END may be integers or markers.\n\
3226 The fourth arg FRONT-ADVANCE, if non-nil, makes the\n\
3227 front delimiter advance when text is inserted there.\n\
3228 The fifth arg REAR-ADVANCE, if non-nil, makes the\n\
3229 rear delimiter advance when text is inserted there.")
3230 (beg
, end
, buffer
, front_advance
, rear_advance
)
3231 Lisp_Object beg
, end
, buffer
;
3232 Lisp_Object front_advance
, rear_advance
;
3234 Lisp_Object overlay
;
3238 XSETBUFFER (buffer
, current_buffer
);
3240 CHECK_BUFFER (buffer
, 2);
3242 && ! EQ (Fmarker_buffer (beg
), buffer
))
3243 error ("Marker points into wrong buffer");
3245 && ! EQ (Fmarker_buffer (end
), buffer
))
3246 error ("Marker points into wrong buffer");
3248 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
3249 CHECK_NUMBER_COERCE_MARKER (end
, 1);
3251 if (XINT (beg
) > XINT (end
))
3254 temp
= beg
; beg
= end
; end
= temp
;
3257 b
= XBUFFER (buffer
);
3259 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
3260 end
= Fset_marker (Fmake_marker (), end
, buffer
);
3262 if (!NILP (front_advance
))
3263 XMARKER (beg
)->insertion_type
= 1;
3264 if (!NILP (rear_advance
))
3265 XMARKER (end
)->insertion_type
= 1;
3267 overlay
= allocate_misc ();
3268 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
3269 XOVERLAY (overlay
)->start
= beg
;
3270 XOVERLAY (overlay
)->end
= end
;
3271 XOVERLAY (overlay
)->plist
= Qnil
;
3273 /* Put the new overlay on the wrong list. */
3274 end
= OVERLAY_END (overlay
);
3275 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
3276 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
3278 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
3280 /* This puts it in the right list, and in the right order. */
3281 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
3283 /* We don't need to redisplay the region covered by the overlay, because
3284 the overlay has no properties at the moment. */
3289 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3292 modify_overlay (buf
, start
, end
)
3302 start
= end
; end
= temp
;
3305 BUF_COMPUTE_UNCHANGED (buf
, start
, end
);
3307 /* If this is a buffer not in the selected window,
3308 we must do other windows. */
3309 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
3310 windows_or_buffers_changed
= 1;
3311 /* If multiple windows show this buffer, we must do other windows. */
3312 else if (buffer_shared
> 1)
3313 windows_or_buffers_changed
= 1;
3315 ++BUF_OVERLAY_MODIFF (buf
);
3319 Lisp_Object
Fdelete_overlay ();
3321 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
3322 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
3323 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
3324 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
3326 (overlay
, beg
, end
, buffer
)
3327 Lisp_Object overlay
, beg
, end
, buffer
;
3329 struct buffer
*b
, *ob
;
3330 Lisp_Object obuffer
;
3331 int count
= specpdl_ptr
- specpdl
;
3333 CHECK_OVERLAY (overlay
, 0);
3335 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3337 XSETBUFFER (buffer
, current_buffer
);
3338 CHECK_BUFFER (buffer
, 3);
3341 && ! EQ (Fmarker_buffer (beg
), buffer
))
3342 error ("Marker points into wrong buffer");
3344 && ! EQ (Fmarker_buffer (end
), buffer
))
3345 error ("Marker points into wrong buffer");
3347 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
3348 CHECK_NUMBER_COERCE_MARKER (end
, 1);
3350 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3351 return Fdelete_overlay (overlay
);
3353 if (XINT (beg
) > XINT (end
))
3356 temp
= beg
; beg
= end
; end
= temp
;
3359 specbind (Qinhibit_quit
, Qt
);
3361 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3362 b
= XBUFFER (buffer
);
3363 ob
= BUFFERP (obuffer
) ? XBUFFER (obuffer
) : (struct buffer
*) 0;
3365 /* If the overlay has changed buffers, do a thorough redisplay. */
3366 if (!EQ (buffer
, obuffer
))
3368 /* Redisplay where the overlay was. */
3369 if (!NILP (obuffer
))
3374 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3375 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3377 modify_overlay (ob
, o_beg
, o_end
);
3380 /* Redisplay where the overlay is going to be. */
3381 modify_overlay (b
, XINT (beg
), XINT (end
));
3384 /* Redisplay the area the overlay has just left, or just enclosed. */
3388 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3389 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3391 if (o_beg
== XINT (beg
))
3392 modify_overlay (b
, o_end
, XINT (end
));
3393 else if (o_end
== XINT (end
))
3394 modify_overlay (b
, o_beg
, XINT (beg
));
3397 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
3398 if (XINT (end
) > o_end
) o_end
= XINT (end
);
3399 modify_overlay (b
, o_beg
, o_end
);
3403 if (!NILP (obuffer
))
3405 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
3406 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
3409 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
3410 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
3412 /* Put the overlay on the wrong list. */
3413 end
= OVERLAY_END (overlay
);
3414 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
3415 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
3417 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
3419 /* This puts it in the right list, and in the right order. */
3420 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
3422 return unbind_to (count
, overlay
);
3425 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
3426 "Delete the overlay OVERLAY from its buffer.")
3428 Lisp_Object overlay
;
3432 int count
= specpdl_ptr
- specpdl
;
3434 CHECK_OVERLAY (overlay
, 0);
3436 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3440 b
= XBUFFER (buffer
);
3442 specbind (Qinhibit_quit
, Qt
);
3444 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
3445 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
3448 marker_position (OVERLAY_START (overlay
)),
3449 marker_position (OVERLAY_END (overlay
)));
3451 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
3452 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
3454 return unbind_to (count
, Qnil
);
3457 /* Overlay dissection functions. */
3459 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3460 "Return the position at which OVERLAY starts.")
3462 Lisp_Object overlay
;
3464 CHECK_OVERLAY (overlay
, 0);
3466 return (Fmarker_position (OVERLAY_START (overlay
)));
3469 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3470 "Return the position at which OVERLAY ends.")
3472 Lisp_Object overlay
;
3474 CHECK_OVERLAY (overlay
, 0);
3476 return (Fmarker_position (OVERLAY_END (overlay
)));
3479 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3480 "Return the buffer OVERLAY belongs to.")
3482 Lisp_Object overlay
;
3484 CHECK_OVERLAY (overlay
, 0);
3486 return Fmarker_buffer (OVERLAY_START (overlay
));
3489 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3490 "Return a list of the properties on OVERLAY.\n\
3491 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
3494 Lisp_Object overlay
;
3496 CHECK_OVERLAY (overlay
, 0);
3498 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3502 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3503 "Return a list of the overlays that contain position POS.")
3508 Lisp_Object
*overlay_vec
;
3512 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3515 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3517 /* Put all the overlays we want in a vector in overlay_vec.
3518 Store the length in len. */
3519 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3520 (int *) 0, (int *) 0);
3522 /* Make a list of them all. */
3523 result
= Flist (noverlays
, overlay_vec
);
3525 xfree (overlay_vec
);
3529 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3530 "Return a list of the overlays that overlap the region BEG ... END.\n\
3531 Overlap means that at least one character is contained within the overlay\n\
3532 and also contained within the specified region.\n\
3533 Empty overlays are included in the result if they are located at BEG\n\
3534 or between BEG and END.")
3536 Lisp_Object beg
, end
;
3539 Lisp_Object
*overlay_vec
;
3543 CHECK_NUMBER_COERCE_MARKER (beg
, 0);
3544 CHECK_NUMBER_COERCE_MARKER (end
, 0);
3547 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3549 /* Put all the overlays we want in a vector in overlay_vec.
3550 Store the length in len. */
3551 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3552 (int *) 0, (int *) 0);
3554 /* Make a list of them all. */
3555 result
= Flist (noverlays
, overlay_vec
);
3557 xfree (overlay_vec
);
3561 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3563 "Return the next position after POS where an overlay starts or ends.\n\
3564 If there are no more overlay boundaries after POS, return (point-max).")
3570 Lisp_Object
*overlay_vec
;
3574 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3577 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3579 /* Put all the overlays we want in a vector in overlay_vec.
3580 Store the length in len.
3581 endpos gets the position where the next overlay starts. */
3582 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3583 &endpos
, (int *) 0);
3585 /* If any of these overlays ends before endpos,
3586 use its ending point instead. */
3587 for (i
= 0; i
< noverlays
; i
++)
3592 oend
= OVERLAY_END (overlay_vec
[i
]);
3593 oendpos
= OVERLAY_POSITION (oend
);
3594 if (oendpos
< endpos
)
3598 xfree (overlay_vec
);
3599 return make_number (endpos
);
3602 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
3603 Sprevious_overlay_change
, 1, 1, 0,
3604 "Return the previous position before POS where an overlay starts or ends.\n\
3605 If there are no more overlay boundaries before POS, return (point-min).")
3611 Lisp_Object
*overlay_vec
;
3614 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3617 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3619 /* At beginning of buffer, we know the answer;
3620 avoid bug subtracting 1 below. */
3621 if (XINT (pos
) == BEGV
)
3624 /* Put all the overlays we want in a vector in overlay_vec.
3625 Store the length in len.
3626 prevpos gets the position of the previous change. */
3627 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3628 (int *) 0, &prevpos
);
3630 xfree (overlay_vec
);
3631 return make_number (prevpos
);
3634 /* These functions are for debugging overlays. */
3636 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
3637 "Return a pair of lists giving all the overlays of the current buffer.\n\
3638 The car has all the overlays before the overlay center;\n\
3639 the cdr has all the overlays after the overlay center.\n\
3640 Recentering overlays moves overlays between these lists.\n\
3641 The lists you get are copies, so that changing them has no effect.\n\
3642 However, the overlays you get are the real objects that the buffer uses.")
3645 Lisp_Object before
, after
;
3646 before
= current_buffer
->overlays_before
;
3648 before
= Fcopy_sequence (before
);
3649 after
= current_buffer
->overlays_after
;
3651 after
= Fcopy_sequence (after
);
3653 return Fcons (before
, after
);
3656 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
3657 "Recenter the overlays of the current buffer around position POS.")
3661 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3663 recenter_overlay_lists (current_buffer
, XINT (pos
));
3667 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
3668 "Get the property of overlay OVERLAY with property name PROP.")
3670 Lisp_Object overlay
, prop
;
3672 Lisp_Object plist
, fallback
;
3674 CHECK_OVERLAY (overlay
, 0);
3678 for (plist
= XOVERLAY (overlay
)->plist
;
3679 CONSP (plist
) && CONSP (XCDR (plist
));
3680 plist
= XCDR (XCDR (plist
)))
3682 if (EQ (XCAR (plist
), prop
))
3683 return XCAR (XCDR (plist
));
3684 else if (EQ (XCAR (plist
), Qcategory
))
3687 tem
= Fcar (Fcdr (plist
));
3689 fallback
= Fget (tem
, prop
);
3696 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
3697 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
3698 (overlay
, prop
, value
)
3699 Lisp_Object overlay
, prop
, value
;
3701 Lisp_Object tail
, buffer
;
3704 CHECK_OVERLAY (overlay
, 0);
3706 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3708 for (tail
= XOVERLAY (overlay
)->plist
;
3709 CONSP (tail
) && CONSP (XCDR (tail
));
3710 tail
= XCDR (XCDR (tail
)))
3711 if (EQ (XCAR (tail
), prop
))
3713 changed
= !EQ (XCAR (XCDR (tail
)), value
);
3714 XCAR (XCDR (tail
)) = value
;
3717 /* It wasn't in the list, so add it to the front. */
3718 changed
= !NILP (value
);
3719 XOVERLAY (overlay
)->plist
3720 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
3722 if (! NILP (buffer
))
3725 modify_overlay (XBUFFER (buffer
),
3726 marker_position (OVERLAY_START (overlay
)),
3727 marker_position (OVERLAY_END (overlay
)));
3728 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
3729 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
3730 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
3731 Fdelete_overlay (overlay
);
3736 /* Subroutine of report_overlay_modification. */
3738 /* Lisp vector holding overlay hook functions to call.
3739 Vector elements come in pairs.
3740 Each even-index element is a list of hook functions.
3741 The following odd-index element is the overlay they came from.
3743 Before the buffer change, we fill in this vector
3744 as we call overlay hook functions.
3745 After the buffer change, we get the functions to call from this vector.
3746 This way we always call the same functions before and after the change. */
3747 static Lisp_Object last_overlay_modification_hooks
;
3749 /* Number of elements actually used in last_overlay_modification_hooks. */
3750 static int last_overlay_modification_hooks_used
;
3752 /* Add one functionlist/overlay pair
3753 to the end of last_overlay_modification_hooks. */
3756 add_overlay_mod_hooklist (functionlist
, overlay
)
3757 Lisp_Object functionlist
, overlay
;
3759 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
3761 if (last_overlay_modification_hooks_used
== oldsize
)
3764 old
= last_overlay_modification_hooks
;
3765 last_overlay_modification_hooks
3766 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
3767 bcopy (XVECTOR (old
)->contents
,
3768 XVECTOR (last_overlay_modification_hooks
)->contents
,
3769 sizeof (Lisp_Object
) * oldsize
);
3771 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = functionlist
;
3772 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = overlay
;
3775 /* Run the modification-hooks of overlays that include
3776 any part of the text in START to END.
3777 If this change is an insertion, also
3778 run the insert-before-hooks of overlay starting at END,
3779 and the insert-after-hooks of overlay ending at START.
3781 This is called both before and after the modification.
3782 AFTER is nonzero when we call after the modification.
3784 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3785 When AFTER is nonzero, they are the start position,
3786 the position after the inserted new text,
3787 and the length of deleted or replaced old text. */
3790 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
3791 Lisp_Object start
, end
;
3793 Lisp_Object arg1
, arg2
, arg3
;
3795 Lisp_Object prop
, overlay
, tail
;
3796 /* 1 if this change is an insertion. */
3797 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
3799 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
3803 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
3807 /* Call the functions recorded in last_overlay_modification_hooks
3808 rather than scanning the overlays again.
3809 First copy the vector contents, in case some of these hooks
3810 do subsequent modification of the buffer. */
3811 int size
= last_overlay_modification_hooks_used
;
3812 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
3815 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
3816 copy
, size
* sizeof (Lisp_Object
));
3818 gcpro1
.nvars
= size
;
3820 for (i
= 0; i
< size
;)
3822 Lisp_Object prop
, overlay
;
3824 overlay
= copy
[i
++];
3825 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3831 /* We are being called before a change.
3832 Scan the overlays to find the functions to call. */
3833 last_overlay_modification_hooks_used
= 0;
3835 for (tail
= current_buffer
->overlays_before
;
3839 int startpos
, endpos
;
3840 Lisp_Object ostart
, oend
;
3842 overlay
= XCAR (tail
);
3844 ostart
= OVERLAY_START (overlay
);
3845 oend
= OVERLAY_END (overlay
);
3846 endpos
= OVERLAY_POSITION (oend
);
3847 if (XFASTINT (start
) > endpos
)
3849 startpos
= OVERLAY_POSITION (ostart
);
3850 if (insertion
&& (XFASTINT (start
) == startpos
3851 || XFASTINT (end
) == startpos
))
3853 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3856 /* Copy TAIL in case the hook recenters the overlay lists. */
3858 tail
= Fcopy_sequence (tail
);
3860 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3863 if (insertion
&& (XFASTINT (start
) == endpos
3864 || XFASTINT (end
) == endpos
))
3866 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3870 tail
= Fcopy_sequence (tail
);
3872 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3875 /* Test for intersecting intervals. This does the right thing
3876 for both insertion and deletion. */
3877 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3879 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3883 tail
= Fcopy_sequence (tail
);
3885 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3891 for (tail
= current_buffer
->overlays_after
;
3895 int startpos
, endpos
;
3896 Lisp_Object ostart
, oend
;
3898 overlay
= XCAR (tail
);
3900 ostart
= OVERLAY_START (overlay
);
3901 oend
= OVERLAY_END (overlay
);
3902 startpos
= OVERLAY_POSITION (ostart
);
3903 endpos
= OVERLAY_POSITION (oend
);
3904 if (XFASTINT (end
) < startpos
)
3906 if (insertion
&& (XFASTINT (start
) == startpos
3907 || XFASTINT (end
) == startpos
))
3909 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3913 tail
= Fcopy_sequence (tail
);
3915 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3918 if (insertion
&& (XFASTINT (start
) == endpos
3919 || XFASTINT (end
) == endpos
))
3921 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3925 tail
= Fcopy_sequence (tail
);
3927 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3930 /* Test for intersecting intervals. This does the right thing
3931 for both insertion and deletion. */
3932 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3934 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3938 tail
= Fcopy_sequence (tail
);
3940 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3949 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
3950 Lisp_Object list
, overlay
;
3952 Lisp_Object arg1
, arg2
, arg3
;
3954 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3956 GCPRO4 (list
, arg1
, arg2
, arg3
);
3958 add_overlay_mod_hooklist (list
, overlay
);
3960 while (!NILP (list
))
3963 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
3965 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
3971 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3974 evaporate_overlays (pos
)
3977 Lisp_Object tail
, overlay
, hit_list
;
3980 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
3981 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
3985 overlay
= XCAR (tail
);
3986 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3989 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
3990 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3991 hit_list
= Fcons (overlay
, hit_list
);
3994 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
3998 overlay
= XCAR (tail
);
3999 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4002 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
4003 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4004 hit_list
= Fcons (overlay
, hit_list
);
4006 for (; CONSP (hit_list
); hit_list
= XCDR (hit_list
))
4007 Fdelete_overlay (XCAR (hit_list
));
4010 /* Somebody has tried to store a value with an unacceptable type
4011 in the slot with offset OFFSET. */
4014 buffer_slot_type_mismatch (offset
)
4020 switch (XINT (PER_BUFFER_TYPE (offset
)))
4023 type_name
= "integers";
4027 type_name
= "strings";
4031 type_name
= "symbols";
4038 sym
= PER_BUFFER_SYMBOL (offset
);
4039 error ("Only %s should be stored in the buffer-local variable %s",
4040 type_name
, XSYMBOL (sym
)->name
->data
);
4049 bzero (buffer_permanent_local_flags
, sizeof buffer_permanent_local_flags
);
4051 /* Make sure all markable slots in buffer_defaults
4052 are initialized reasonably, so mark_buffer won't choke. */
4053 reset_buffer (&buffer_defaults
);
4054 reset_buffer_local_variables (&buffer_defaults
, 1);
4055 reset_buffer (&buffer_local_symbols
);
4056 reset_buffer_local_variables (&buffer_local_symbols
, 1);
4057 /* Prevent GC from getting confused. */
4058 buffer_defaults
.text
= &buffer_defaults
.own_text
;
4059 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
4060 BUF_INTERVALS (&buffer_defaults
) = 0;
4061 BUF_INTERVALS (&buffer_local_symbols
) = 0;
4062 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
4063 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
4065 /* Set up the default values of various buffer slots. */
4066 /* Must do these before making the first buffer! */
4068 /* real setup is done in bindings.el */
4069 buffer_defaults
.mode_line_format
= build_string ("%-");
4070 buffer_defaults
.header_line_format
= Qnil
;
4071 buffer_defaults
.abbrev_mode
= Qnil
;
4072 buffer_defaults
.overwrite_mode
= Qnil
;
4073 buffer_defaults
.case_fold_search
= Qt
;
4074 buffer_defaults
.auto_fill_function
= Qnil
;
4075 buffer_defaults
.selective_display
= Qnil
;
4077 buffer_defaults
.selective_display_ellipses
= Qt
;
4079 buffer_defaults
.abbrev_table
= Qnil
;
4080 buffer_defaults
.display_table
= Qnil
;
4081 buffer_defaults
.undo_list
= Qnil
;
4082 buffer_defaults
.mark_active
= Qnil
;
4083 buffer_defaults
.file_format
= Qnil
;
4084 buffer_defaults
.overlays_before
= Qnil
;
4085 buffer_defaults
.overlays_after
= Qnil
;
4086 XSETFASTINT (buffer_defaults
.overlay_center
, BEG
);
4088 XSETFASTINT (buffer_defaults
.tab_width
, 8);
4089 buffer_defaults
.truncate_lines
= Qnil
;
4090 buffer_defaults
.ctl_arrow
= Qt
;
4091 buffer_defaults
.direction_reversed
= Qnil
;
4092 buffer_defaults
.cursor_type
= Qt
;
4093 buffer_defaults
.extra_line_spacing
= Qnil
;
4096 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
4098 buffer_defaults
.enable_multibyte_characters
= Qt
;
4099 buffer_defaults
.buffer_file_coding_system
= Qnil
;
4100 XSETFASTINT (buffer_defaults
.fill_column
, 70);
4101 XSETFASTINT (buffer_defaults
.left_margin
, 0);
4102 buffer_defaults
.cache_long_line_scans
= Qnil
;
4103 buffer_defaults
.file_truename
= Qnil
;
4104 XSETFASTINT (buffer_defaults
.display_count
, 0);
4105 buffer_defaults
.indicate_empty_lines
= Qnil
;
4106 buffer_defaults
.scroll_up_aggressively
= Qnil
;
4107 buffer_defaults
.scroll_down_aggressively
= Qnil
;
4108 buffer_defaults
.display_time
= Qnil
;
4110 /* Assign the local-flags to the slots that have default values.
4111 The local flag is a bit that is used in the buffer
4112 to say that it has its own local value for the slot.
4113 The local flag bits are in the local_var_flags slot of the buffer. */
4115 /* Nothing can work if this isn't true */
4116 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
4118 /* 0 means not a lisp var, -1 means always local, else mask */
4119 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
4120 XSETINT (buffer_local_flags
.filename
, -1);
4121 XSETINT (buffer_local_flags
.directory
, -1);
4122 XSETINT (buffer_local_flags
.backed_up
, -1);
4123 XSETINT (buffer_local_flags
.save_length
, -1);
4124 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
4125 XSETINT (buffer_local_flags
.read_only
, -1);
4126 XSETINT (buffer_local_flags
.major_mode
, -1);
4127 XSETINT (buffer_local_flags
.mode_name
, -1);
4128 XSETINT (buffer_local_flags
.undo_list
, -1);
4129 XSETINT (buffer_local_flags
.mark_active
, -1);
4130 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
4131 XSETINT (buffer_local_flags
.file_truename
, -1);
4132 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
4133 XSETINT (buffer_local_flags
.file_format
, -1);
4134 XSETINT (buffer_local_flags
.display_count
, -1);
4135 XSETINT (buffer_local_flags
.display_time
, -1);
4136 XSETINT (buffer_local_flags
.enable_multibyte_characters
, -1);
4139 XSETFASTINT (buffer_local_flags
.mode_line_format
, idx
); ++idx
;
4140 XSETFASTINT (buffer_local_flags
.abbrev_mode
, idx
); ++idx
;
4141 XSETFASTINT (buffer_local_flags
.overwrite_mode
, idx
); ++idx
;
4142 XSETFASTINT (buffer_local_flags
.case_fold_search
, idx
); ++idx
;
4143 XSETFASTINT (buffer_local_flags
.auto_fill_function
, idx
); ++idx
;
4144 XSETFASTINT (buffer_local_flags
.selective_display
, idx
); ++idx
;
4146 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, idx
); ++idx
;
4148 XSETFASTINT (buffer_local_flags
.tab_width
, idx
); ++idx
;
4149 XSETFASTINT (buffer_local_flags
.truncate_lines
, idx
); ++idx
;
4150 XSETFASTINT (buffer_local_flags
.ctl_arrow
, idx
); ++idx
;
4151 XSETFASTINT (buffer_local_flags
.fill_column
, idx
); ++idx
;
4152 XSETFASTINT (buffer_local_flags
.left_margin
, idx
); ++idx
;
4153 XSETFASTINT (buffer_local_flags
.abbrev_table
, idx
); ++idx
;
4154 XSETFASTINT (buffer_local_flags
.display_table
, idx
); ++idx
;
4156 XSETFASTINT (buffer_local_flags
.buffer_file_type
, idx
);
4157 /* Make this one a permanent local. */
4158 buffer_permanent_local_flags
[idx
++] = 1;
4160 XSETFASTINT (buffer_local_flags
.syntax_table
, idx
); ++idx
;
4161 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, idx
); ++idx
;
4162 XSETFASTINT (buffer_local_flags
.category_table
, idx
); ++idx
;
4163 XSETFASTINT (buffer_local_flags
.direction_reversed
, idx
); ++idx
;
4164 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, idx
);
4165 /* Make this one a permanent local. */
4166 buffer_permanent_local_flags
[idx
++] = 1;
4167 XSETFASTINT (buffer_local_flags
.left_margin_width
, idx
); ++idx
;
4168 XSETFASTINT (buffer_local_flags
.right_margin_width
, idx
); ++idx
;
4169 XSETFASTINT (buffer_local_flags
.indicate_empty_lines
, idx
); ++idx
;
4170 XSETFASTINT (buffer_local_flags
.scroll_up_aggressively
, idx
); ++idx
;
4171 XSETFASTINT (buffer_local_flags
.scroll_down_aggressively
, idx
); ++idx
;
4172 XSETFASTINT (buffer_local_flags
.header_line_format
, idx
); ++idx
;
4173 XSETFASTINT (buffer_local_flags
.cursor_type
, idx
); ++idx
;
4174 XSETFASTINT (buffer_local_flags
.extra_line_spacing
, idx
); ++idx
;
4176 /* Need more room? */
4177 if (idx
>= MAX_PER_BUFFER_VARS
)
4179 last_per_buffer_idx
= idx
;
4181 Vbuffer_alist
= Qnil
;
4185 QSFundamental
= build_string ("Fundamental");
4187 Qfundamental_mode
= intern ("fundamental-mode");
4188 buffer_defaults
.major_mode
= Qfundamental_mode
;
4190 Qmode_class
= intern ("mode-class");
4192 Qprotected_field
= intern ("protected-field");
4194 Qpermanent_local
= intern ("permanent-local");
4196 Qkill_buffer_hook
= intern ("kill-buffer-hook");
4198 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
4200 /* super-magic invisible buffer */
4201 Vbuffer_alist
= Qnil
;
4203 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
4205 inhibit_modification_hooks
= 0;
4211 char buf
[MAXPATHLEN
+1];
4213 struct stat dotstat
, pwdstat
;
4217 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
4218 if (NILP (buffer_defaults
.enable_multibyte_characters
))
4219 Fset_buffer_multibyte (Qnil
);
4221 /* If PWD is accurate, use it instead of calling getwd. This is faster
4222 when PWD is right, and may avoid a fatal error. */
4223 if ((pwd
= getenv ("PWD")) != 0
4224 && (IS_DIRECTORY_SEP (*pwd
) || (*pwd
&& IS_DEVICE_SEP (pwd
[1])))
4225 && stat (pwd
, &pwdstat
) == 0
4226 && stat (".", &dotstat
) == 0
4227 && dotstat
.st_ino
== pwdstat
.st_ino
4228 && dotstat
.st_dev
== pwdstat
.st_dev
4229 && strlen (pwd
) < MAXPATHLEN
)
4232 else if (getcwd (buf
, MAXPATHLEN
+1) == 0)
4233 fatal ("`getcwd' failed: %s\n", strerror (errno
));
4235 else if (getwd (buf
) == 0)
4236 fatal ("`getwd' failed: %s\n", buf
);
4240 /* Maybe this should really use some standard subroutine
4241 whose definition is filename syntax dependent. */
4243 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
4245 buf
[rc
] = DIRECTORY_SEP
;
4248 #endif /* not VMS */
4250 current_buffer
->directory
= build_string (buf
);
4252 /* Add /: to the front of the name
4253 if it would otherwise be treated as magic. */
4254 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
4256 /* If the default dir is just /, TEMP is non-nil
4257 because of the ange-ftp completion handler.
4258 However, it is not necessary to turn / into /:/.
4259 So avoid doing that. */
4260 && strcmp ("/", XSTRING (current_buffer
->directory
)->data
))
4261 current_buffer
->directory
4262 = concat2 (build_string ("/:"), current_buffer
->directory
);
4264 temp
= get_minibuffer (0);
4265 XBUFFER (temp
)->directory
= current_buffer
->directory
;
4268 /* initialize the buffer routines */
4272 staticpro (&last_overlay_modification_hooks
);
4273 last_overlay_modification_hooks
4274 = Fmake_vector (make_number (10), Qnil
);
4276 staticpro (&Vbuffer_defaults
);
4277 staticpro (&Vbuffer_local_symbols
);
4278 staticpro (&Qfundamental_mode
);
4279 staticpro (&Qmode_class
);
4280 staticpro (&QSFundamental
);
4281 staticpro (&Vbuffer_alist
);
4282 staticpro (&Qprotected_field
);
4283 staticpro (&Qpermanent_local
);
4284 staticpro (&Qkill_buffer_hook
);
4285 Qoverlayp
= intern ("overlayp");
4286 staticpro (&Qoverlayp
);
4287 Qevaporate
= intern ("evaporate");
4288 staticpro (&Qevaporate
);
4289 Qmodification_hooks
= intern ("modification-hooks");
4290 staticpro (&Qmodification_hooks
);
4291 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
4292 staticpro (&Qinsert_in_front_hooks
);
4293 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
4294 staticpro (&Qinsert_behind_hooks
);
4295 Qget_file_buffer
= intern ("get-file-buffer");
4296 staticpro (&Qget_file_buffer
);
4297 Qpriority
= intern ("priority");
4298 staticpro (&Qpriority
);
4299 Qwindow
= intern ("window");
4300 staticpro (&Qwindow
);
4301 Qbefore_string
= intern ("before-string");
4302 staticpro (&Qbefore_string
);
4303 Qafter_string
= intern ("after-string");
4304 staticpro (&Qafter_string
);
4305 Qfirst_change_hook
= intern ("first-change-hook");
4306 staticpro (&Qfirst_change_hook
);
4307 Qbefore_change_functions
= intern ("before-change-functions");
4308 staticpro (&Qbefore_change_functions
);
4309 Qafter_change_functions
= intern ("after-change-functions");
4310 staticpro (&Qafter_change_functions
);
4312 Fput (Qprotected_field
, Qerror_conditions
,
4313 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
4314 Fput (Qprotected_field
, Qerror_message
,
4315 build_string ("Attempt to modify a protected field"));
4317 /* All these use DEFVAR_LISP_NOPRO because the slots in
4318 buffer_defaults will all be marked via Vbuffer_defaults. */
4320 DEFVAR_LISP_NOPRO ("default-mode-line-format",
4321 &buffer_defaults
.mode_line_format
,
4322 "Default value of `mode-line-format' for buffers that don't override it.\n\
4323 This is the same as (default-value 'mode-line-format).");
4325 DEFVAR_LISP_NOPRO ("default-header-line-format",
4326 &buffer_defaults
.header_line_format
,
4327 "Default value of `header-line-format' for buffers that don't override it.\n\
4328 This is the same as (default-value 'header-line-format).");
4330 DEFVAR_LISP_NOPRO ("default-cursor-type", &buffer_defaults
.cursor_type
,
4331 "Default value of `cursor-type' for buffers that don't override it.\n\
4332 This is the same as (default-value 'cursor-type).");
4334 DEFVAR_LISP_NOPRO ("default-line-spacing",
4335 &buffer_defaults
.extra_line_spacing
,
4336 "Default value of `line-spacing' for buffers that don't override it.\n\
4337 This is the same as (default-value 'line-spacing).");
4339 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
4340 &buffer_defaults
.abbrev_mode
,
4341 "Default value of `abbrev-mode' for buffers that do not override it.\n\
4342 This is the same as (default-value 'abbrev-mode).");
4344 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
4345 &buffer_defaults
.ctl_arrow
,
4346 "Default value of `ctl-arrow' for buffers that do not override it.\n\
4347 This is the same as (default-value 'ctl-arrow).");
4349 DEFVAR_LISP_NOPRO ("default-direction-reversed",
4350 &buffer_defaults
.direction_reversed
,
4351 "Default value of `direction_reversed' for buffers that do not override it.\n\
4352 This is the same as (default-value 'direction-reversed).");
4354 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
4355 &buffer_defaults
.enable_multibyte_characters
,
4356 "*Default value of `enable-multibyte-characters' for buffers not overriding it.\n\
4357 This is the same as (default-value 'enable-multibyte-characters).");
4359 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
4360 &buffer_defaults
.buffer_file_coding_system
,
4361 "Default value of `buffer-file-coding-system' for buffers not overriding it.\n\
4362 This is the same as (default-value 'buffer-file-coding-system).");
4364 DEFVAR_LISP_NOPRO ("default-truncate-lines",
4365 &buffer_defaults
.truncate_lines
,
4366 "Default value of `truncate-lines' for buffers that do not override it.\n\
4367 This is the same as (default-value 'truncate-lines).");
4369 DEFVAR_LISP_NOPRO ("default-fill-column",
4370 &buffer_defaults
.fill_column
,
4371 "Default value of `fill-column' for buffers that do not override it.\n\
4372 This is the same as (default-value 'fill-column).");
4374 DEFVAR_LISP_NOPRO ("default-left-margin",
4375 &buffer_defaults
.left_margin
,
4376 "Default value of `left-margin' for buffers that do not override it.\n\
4377 This is the same as (default-value 'left-margin).");
4379 DEFVAR_LISP_NOPRO ("default-tab-width",
4380 &buffer_defaults
.tab_width
,
4381 "Default value of `tab-width' for buffers that do not override it.\n\
4382 This is the same as (default-value 'tab-width).");
4384 DEFVAR_LISP_NOPRO ("default-case-fold-search",
4385 &buffer_defaults
.case_fold_search
,
4386 "Default value of `case-fold-search' for buffers that don't override it.\n\
4387 This is the same as (default-value 'case-fold-search).");
4390 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
4391 &buffer_defaults
.buffer_file_type
,
4392 "Default file type for buffers that do not override it.\n\
4393 This is the same as (default-value 'buffer-file-type).\n\
4394 The file type is nil for text, t for binary.");
4397 DEFVAR_LISP_NOPRO ("default-left-margin-width",
4398 &buffer_defaults
.left_margin_width
,
4399 "Default value of `left-margin-width' for buffers that don't override it.\n\
4400 This is the same as (default-value 'left-margin-width).");
4402 DEFVAR_LISP_NOPRO ("default-right-margin-width",
4403 &buffer_defaults
.right_margin_width
,
4404 "Default value of `right_margin_width' for buffers that don't override it.\n\
4405 This is the same as (default-value 'right-margin-width).");
4407 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines",
4408 &buffer_defaults
.indicate_empty_lines
,
4409 "Default value of `indicate-empty-lines' for buffers that don't override it.\n\
4410 This is the same as (default-value 'indicate-empty-lines).");
4412 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively",
4413 &buffer_defaults
.scroll_up_aggressively
,
4414 "Default value of `scroll-up-aggressively' for buffers that\n\
4415 don't override it. This is the same as (default-value\n\
4416 'scroll-up-aggressively).");
4418 DEFVAR_LISP_NOPRO ("default-scroll-down-aggressively",
4419 &buffer_defaults
.scroll_down_aggressively
,
4420 "Default value of `scroll-down-aggressively' for buffers that\n\
4421 don't override it. This is the same as (default-value\n\
4422 'scroll-down-aggressively).");
4424 DEFVAR_PER_BUFFER ("header-line-format",
4425 ¤t_buffer
->header_line_format
,
4427 "Analogous to `mode-line-format', but for a mode line displayed\n\
4428 at the top of windows.");
4430 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
4433 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
4434 But make-docfile finds it!
4435 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
4437 "Template for displaying mode line for current buffer.\n\
4438 Each buffer has its own value of this variable.\n\
4439 Value may be nil, a string, a symbol or a list or cons cell.\n\
4440 A value of nil means don't display a mode line.\n\
4441 For a symbol, its value is used (but it is ignored if t or nil).\n\
4442 A string appearing directly as the value of a symbol is processed verbatim\n\
4443 in that the %-constructs below are not recognized.\n\
4444 For a list of the form `(:eval FORM)', FORM is evaluated and the result\n\
4445 is used as a mode line element.\n\
4446 For a list whose car is a symbol, the symbol's value is taken,\n\
4447 and if that is non-nil, the cadr of the list is processed recursively.\n\
4448 Otherwise, the caddr of the list (if there is one) is processed.\n\
4449 For a list whose car is a string or list, each element is processed\n\
4450 recursively and the results are effectively concatenated.\n\
4451 For a list whose car is an integer, the cdr of the list is processed\n\
4452 and padded (if the number is positive) or truncated (if negative)\n\
4453 to the width specified by that number.\n\
4454 A string is printed verbatim in the mode line except for %-constructs:\n\
4455 (%-constructs are allowed when the string is the entire mode-line-format\n\
4456 or when it is found in a cons-cell or a list)\n\
4457 %b -- print buffer name. %f -- print visited file name.\n\
4458 %F -- print frame name.\n\
4459 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
4460 %& is like %*, but ignore read-only-ness.\n\
4461 % means buffer is read-only and * means it is modified.\n\
4462 For a modified read-only buffer, %* gives % and %+ gives *.\n\
4463 %s -- print process status. %l -- print the current line number.\n\
4464 %c -- print the current column number (this makes editing slower).\n\
4465 To make the column number update correctly in all cases,\n\
4466 `column-number-mode' must be non-nil.\n\
4467 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
4468 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
4469 or print Bottom or All.\n\
4470 %m -- print the mode name.\n\
4471 %n -- print Narrow if appropriate.\n\
4472 %z -- print mnemonics of buffer, terminal, and keyboard coding systems.\n\
4473 %Z -- like %z, but including the end-of-line format.\n\
4474 %[ -- print one [ for each recursive editing level. %] similar.\n\
4475 %% -- print %. %- -- print infinitely many dashes.\n\
4476 Decimal digits after the % specify field width to which to pad.");
4479 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
4480 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
4481 nil here means use current buffer's major mode.");
4483 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
4484 make_number (Lisp_Symbol
),
4485 "Symbol for current buffer's major mode.");
4487 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
4488 make_number (Lisp_String
),
4489 "Pretty name of current buffer's major mode (a string).");
4491 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
4492 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
4493 Automatically becomes buffer-local when set in any fashion.");
4495 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
4497 "*Non-nil if searches and matches should ignore case.\n\
4498 Automatically becomes buffer-local when set in any fashion.");
4500 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
4501 make_number (Lisp_Int
),
4502 "*Column beyond which automatic line-wrapping should happen.\n\
4503 Automatically becomes buffer-local when set in any fashion.");
4505 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
4506 make_number (Lisp_Int
),
4507 "*Column for the default indent-line-function to indent to.\n\
4508 Linefeed indents to this column in Fundamental mode.\n\
4509 Automatically becomes buffer-local when set in any fashion.");
4511 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
4512 make_number (Lisp_Int
),
4513 "*Distance between tab stops (for display of tab characters), in columns.\n\
4514 Automatically becomes buffer-local when set in any fashion.");
4516 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
4517 "*Non-nil means display control chars with uparrow.\n\
4518 A value of nil means use backslash and octal digits.\n\
4519 Automatically becomes buffer-local when set in any fashion.\n\
4520 This variable does not apply to characters whose display is specified\n\
4521 in the current display table (if there is one).");
4523 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
4524 ¤t_buffer
->enable_multibyte_characters
,
4526 "Non-nil means the buffer contents are regarded as multi-byte characters.\n\
4527 Otherwise they are regarded as unibyte. This affects the display,\n\
4528 file I/O and the behavior of various editing commands.\n\
4530 This variable is buffer-local but you cannot set it directly;\n\
4531 use the function `set-buffer-multibyte' to change a buffer's representation.\n\
4532 Changing its default value with `setq-default' is supported.\n\
4533 See also variable `default-enable-multibyte-characters' and Info node\n\
4534 `(elisp)Text Representations'.");
4536 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
4537 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
4538 "Coding system to be used for encoding the buffer contents on saving.\n\
4539 This variable applies to saving the buffer, and also to `write-region'\n\
4540 and other functions that use `write-region'.\n\
4541 It does not apply to sending output to subprocesses, however.\n\
4543 If this is nil, the buffer is saved without any code conversion\n\
4544 unless some coding system is specified in `file-coding-system-alist'\n\
4545 for the buffer file.\n\
4547 The variable `coding-system-for-write', if non-nil, overrides this variable.\n\
4549 This variable is never applied to a way of decoding\n\
4550 a file while reading it.");
4552 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
4554 "*Non-nil means lines in the buffer are displayed right to left.");
4556 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
4557 "*Non-nil means do not display continuation lines;\n\
4558 give each line of text one screen line.\n\
4559 Automatically becomes buffer-local when set in any fashion.\n\
4561 Note that this is overridden by the variable\n\
4562 `truncate-partial-width-windows' if that variable is non-nil\n\
4563 and this buffer is not full-frame width.");
4566 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
4568 "Non-nil if the visited file is a binary file.\n\
4569 This variable is meaningful on MS-DOG and Windows NT.\n\
4570 On those systems, it is automatically local in every buffer.\n\
4571 On other systems, this variable is normally always nil.");
4574 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
4575 make_number (Lisp_String
),
4576 "Name of default directory of current buffer. Should end with slash.\n\
4577 Each buffer has its own value of this variable.");
4579 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
4581 "Function called (if non-nil) to perform auto-fill.\n\
4582 It is called after self-inserting any character specified in\n\
4583 the `auto-fill-chars' table.\n\
4584 Each buffer has its own value of this variable.\n\
4585 NOTE: This variable is not a hook;\n\
4586 its value may not be a list of functions.");
4588 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
4589 make_number (Lisp_String
),
4590 "Name of file visited in current buffer, or nil if not visiting a file.\n\
4591 Each buffer has its own value of this variable.");
4593 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
4594 make_number (Lisp_String
),
4595 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
4596 The truename of a file is calculated by `file-truename'\n\
4597 and then abbreviated with `abbreviate-file-name'.\n\
4598 Each buffer has its own value of this variable.");
4600 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
4601 ¤t_buffer
->auto_save_file_name
,
4602 make_number (Lisp_String
),
4603 "Name of file for auto-saving current buffer,\n\
4604 or nil if buffer should not be auto-saved.\n\
4605 Each buffer has its own value of this variable.");
4607 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
4608 "Non-nil if this buffer is read-only.\n\
4609 Each buffer has its own value of this variable.");
4611 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
4612 "Non-nil if this buffer's file has been backed up.\n\
4613 Backing up is done before the first time the file is saved.\n\
4614 Each buffer has its own value of this variable.");
4616 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
4617 make_number (Lisp_Int
),
4618 "Length of current buffer when last read in, saved or auto-saved.\n\
4620 Each buffer has its own value of this variable.");
4622 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
4624 "Non-nil enables selective display:\n\
4625 Integer N as value means display only lines\n\
4626 that start with less than n columns of space.\n\
4627 A value of t means, after a ^M, all the rest of the line is invisible.\n\
4628 Then ^M's in the file are written into files as newlines.\n\n\
4629 Automatically becomes buffer-local when set in any fashion.");
4632 DEFVAR_PER_BUFFER ("selective-display-ellipses",
4633 ¤t_buffer
->selective_display_ellipses
,
4635 "t means display ... on previous line when a line is invisible.\n\
4636 Automatically becomes buffer-local when set in any fashion.");
4639 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
4640 "Non-nil if self-insertion should replace existing text.\n\
4641 The value should be one of `overwrite-mode-textual',\n\
4642 `overwrite-mode-binary', or nil.\n\
4643 If it is `overwrite-mode-textual', self-insertion still\n\
4644 inserts at the end of a line, and inserts when point is before a tab,\n\
4645 until the tab is filled in.\n\
4646 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
4647 Automatically becomes buffer-local when set in any fashion.");
4649 #if 0 /* The doc string is too long for some compilers,
4650 but make-docfile can find it in this comment. */
4651 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4653 "Display table that controls display of the contents of current buffer.\n\
4654 Automatically becomes buffer-local when set in any fashion.\n\
4655 The display table is a char-table created with `make-display-table'.\n\
4656 The ordinary char-table elements control how to display each possible text\n\
4657 character. Each value should be a vector of characters or nil;\n\
4658 nil means display the character in the default fashion.\n\
4659 There are six extra slots to control the display of\n\
4660 the end of a truncated screen line (extra-slot 0, a single character);\n\
4661 the end of a continued line (extra-slot 1, a single character);\n\
4662 the escape character used to display character codes in octal\n\
4663 (extra-slot 2, a single character);\n\
4664 the character used as an arrow for control characters (extra-slot 3,\n\
4665 a single character);\n\
4666 the decoration indicating the presence of invisible lines (extra-slot 4,\n\
4667 a vector of characters);\n\
4668 the character used to draw the border between side-by-side windows\n\
4669 (extra-slot 5, a single character).\n\
4670 See also the functions `display-table-slot' and `set-display-table-slot'.\n\
4671 If this variable is nil, the value of `standard-display-table' is used.\n\
4672 Each window can have its own, overriding display table.");
4674 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4677 DEFVAR_PER_BUFFER ("left-margin-width", ¤t_buffer
->left_margin_width
,
4679 "*Width of left marginal area for display of a buffer.\n\
4680 Automatically becomes buffer-local when set in any fashion.\n\
4681 A value of nil means no marginal area.");
4683 DEFVAR_PER_BUFFER ("right-margin-width", ¤t_buffer
->right_margin_width
,
4685 "*Width of right marginal area for display of a buffer.\n\
4686 Automatically becomes buffer-local when set in any fashion.\n\
4687 A value of nil means no marginal area.");
4689 DEFVAR_PER_BUFFER ("indicate-empty-lines",
4690 ¤t_buffer
->indicate_empty_lines
, Qnil
,
4691 "*Visually indicate empty lines after the buffer end.\n\
4692 If non-nil, a bitmap is displayed in the left fringe of a window on\n\
4694 Automatically becomes buffer-local when set in any fashion.\n");
4696 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
4697 ¤t_buffer
->scroll_up_aggressively
, Qnil
,
4698 "*If a number, scroll display up aggressively.\n\
4699 If scrolling a window because point is above the window start, choose\n\
4700 a new window start so that point ends up that fraction of the window's\n\
4701 height from the bottom of the window.\n\
4702 Automatically becomes buffer-local when set in any fashion.");
4704 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
4705 ¤t_buffer
->scroll_down_aggressively
, Qnil
,
4706 "*If a number, scroll display down aggressively.\n\
4707 If scrolling a window because point is below the window end, choose\n\
4708 a new window start so that point ends up that fraction of the window's\n\
4709 height from the top of the window.\n\
4710 Automatically becomes buffer-local when set in any fashion.");
4712 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
4716 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
4717 "List of functions to call before each text change.\n\
4718 Two arguments are passed to each function: the positions of\n\
4719 the beginning and end of the range of old text to be changed.\n\
4720 \(For an insertion, the beginning and end are at the same place.)\n\
4721 No information is given about the length of the text after the change.\n\
4723 Buffer changes made while executing the `before-change-functions'\n\
4724 don't call any before-change or after-change functions.\n\
4725 That's because these variables are temporarily set to nil.\n\
4726 As a result, a hook function cannot straightforwardly alter the value of\n\
4727 these variables. See the Emacs Lisp manual for a way of\n\
4728 accomplishing an equivalent result by using other variables.\n\
4730 If an unhandled error happens in running these functions,\n\
4731 the variable's value remains nil. That prevents the error\n\
4732 from happening repeatedly and making Emacs nonfunctional.");
4733 Vbefore_change_functions
= Qnil
;
4735 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
4736 "List of function to call after each text change.\n\
4737 Three arguments are passed to each function: the positions of\n\
4738 the beginning and end of the range of changed text,\n\
4739 and the length in bytes of the pre-change text replaced by that range.\n\
4740 \(For an insertion, the pre-change length is zero;\n\
4741 for a deletion, that length is the number of bytes deleted,\n\
4742 and the post-change beginning and end are at the same place.)\n\
4744 Buffer changes made while executing the `after-change-functions'\n\
4745 don't call any before-change or after-change functions.\n\
4746 That's because these variables are temporarily set to nil.\n\
4747 As a result, a hook function cannot straightforwardly alter the value of\n\
4748 these variables. See the Emacs Lisp manual for a way of\n\
4749 accomplishing an equivalent result by using other variables.\n\
4751 If an unhandled error happens in running these functions,\n\
4752 the variable's value remains nil. That prevents the error\n\
4753 from happening repeatedly and making Emacs nonfunctional.");
4754 Vafter_change_functions
= Qnil
;
4756 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
4757 "A list of functions to call before changing a buffer which is unmodified.\n\
4758 The functions are run using the `run-hooks' function.");
4759 Vfirst_change_hook
= Qnil
;
4761 #if 0 /* The doc string is too long for some compilers,
4762 but make-docfile can find it in this comment. */
4763 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4764 "List of undo entries in current buffer.\n\
4765 This variable is always local in all buffers.\n\
4766 Recent changes come first; older changes follow newer.\n\
4768 An entry (BEG . END) represents an insertion which begins at\n\
4769 position BEG and ends at position END.\n\
4771 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
4772 from (abs POSITION). If POSITION is positive, point was at the front\n\
4773 of the text being deleted; if negative, point was at the end.\n\
4775 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
4776 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
4777 of the visited file's modification time, as of that time. If the\n\
4778 modification time of the most recent save is different, this entry is\n\
4781 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
4782 was modified between BEG and END. PROPERTY is the property name,\n\
4783 and VALUE is the old value.\n\
4785 An entry (MARKER . DISTANCE) indicates that the marker MARKER\n\
4786 was adjusted in position by the offset DISTANCE (an integer).\n\
4788 An entry of the form POSITION indicates that point was at the buffer\n\
4789 location given by the integer. Undoing an entry of this form places\n\
4790 point at POSITION.\n\
4792 nil marks undo boundaries. The undo command treats the changes\n\
4793 between two undo boundaries as a single step to be undone.\n\
4795 If the value of the variable is t, undo information is not recorded.");
4797 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4800 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
4801 "Non-nil means the mark and region are currently active in this buffer.\n\
4802 Automatically local in all buffers.");
4804 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
4805 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
4806 This variable is buffer-local, in all buffers.\n\
4808 Normally, the line-motion functions work by scanning the buffer for\n\
4809 newlines. Columnar operations (like move-to-column and\n\
4810 compute-motion) also work by scanning the buffer, summing character\n\
4811 widths as they go. This works well for ordinary text, but if the\n\
4812 buffer's lines are very long (say, more than 500 characters), these\n\
4813 motion functions will take longer to execute. Emacs may also take\n\
4814 longer to update the display.\n\
4816 If cache-long-line-scans is non-nil, these motion functions cache the\n\
4817 results of their scans, and consult the cache to avoid rescanning\n\
4818 regions of the buffer until the text is modified. The caches are most\n\
4819 beneficial when they prevent the most searching---that is, when the\n\
4820 buffer contains long lines and large regions of characters with the\n\
4821 same, fixed screen width.\n\
4823 When cache-long-line-scans is non-nil, processing short lines will\n\
4824 become slightly slower (because of the overhead of consulting the\n\
4825 cache), and the caches will use memory roughly proportional to the\n\
4826 number of newlines and characters whose screen width varies.\n\
4828 The caches require no explicit maintenance; their accuracy is\n\
4829 maintained internally by the Emacs primitives. Enabling or disabling\n\
4830 the cache should not affect the behavior of any of the motion\n\
4831 functions; it should only affect their performance.");
4833 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
4834 "Value of point before the last series of scroll operations, or nil.\n\
4835 This variable is always local in all buffers.");
4837 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
4838 "List of formats to use when saving this buffer.\n\
4839 This variable is always local in all buffers.\n\
4840 Formats are defined by `format-alist'. This variable is\n\
4841 set when a file is visited. Automatically local in all buffers.");
4843 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
4844 ¤t_buffer
->invisibility_spec
, Qnil
,
4845 "Invisibility spec of this buffer.\n\
4846 This variable is always local in all buffers.\n\
4847 The default is t, which means that text is invisible\n\
4848 if it has a non-nil `invisible' property.\n\
4849 If the value is a list, a text character is invisible if its `invisible'\n\
4850 property is an element in that list.\n\
4851 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
4852 then characters with property value PROP are invisible,\n\
4853 and they have an ellipsis as well if ELLIPSIS is non-nil.");
4855 DEFVAR_PER_BUFFER ("buffer-display-count",
4856 ¤t_buffer
->display_count
, Qnil
,
4857 "A number incremented each time this buffer is displayed in a window.\n\
4858 This variable is always local in all buffers.\n\
4859 The function `set-window-buffer increments it.");
4861 DEFVAR_PER_BUFFER ("buffer-display-time",
4862 ¤t_buffer
->display_time
, Qnil
,
4863 "Time stamp updated each time this buffer is displayed in a window.\n\
4864 This variable is always local in all buffers.\n\
4865 The function `set-window-buffer' updates this variable\n\
4866 to the value obtained by calling `current-time'.\n\
4867 If the buffer has never been shown in a window, the value is nil.");
4869 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
4870 "*Non-nil means deactivate the mark when the buffer contents change.\n\
4871 Non-nil also enables highlighting of the region whenever the mark is active.\n\
4872 The variable `highlight-nonselected-windows' controls whether to highlight\n\
4873 all windows or just the selected window.");
4874 Vtransient_mark_mode
= Qnil
;
4876 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
4877 "*Non-nil means disregard read-only status of buffers or characters.\n\
4878 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
4879 text properties. If the value is a list, disregard `buffer-read-only'\n\
4880 and disregard a `read-only' text property if the property value\n\
4881 is a member of the list.");
4882 Vinhibit_read_only
= Qnil
;
4884 DEFVAR_PER_BUFFER ("cursor-type", ¤t_buffer
->cursor_type
, Qnil
,
4885 "Cursor to use in window displaying this buffer.\n\
4886 Values are interpreted as follows:\n\
4888 t use the cursor specified for the frame\n\
4889 nil don't display a cursor\n\
4890 `bar' display a bar cursor with default width\n\
4891 (bar . WIDTH) display a bar cursor with width WIDTH\n\
4892 others display a box cursor.");
4894 DEFVAR_PER_BUFFER ("line-spacing",
4895 ¤t_buffer
->extra_line_spacing
, Qnil
,
4896 "Additional space to put between lines when displaying a buffer.\n\
4897 The space is measured in pixels, and put below lines on window systems.");
4899 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
4900 "List of functions called with no args to query before killing a buffer.");
4901 Vkill_buffer_query_functions
= Qnil
;
4903 defsubr (&Sbuffer_live_p
);
4904 defsubr (&Sbuffer_list
);
4905 defsubr (&Sget_buffer
);
4906 defsubr (&Sget_file_buffer
);
4907 defsubr (&Sget_buffer_create
);
4908 defsubr (&Smake_indirect_buffer
);
4909 defsubr (&Sgenerate_new_buffer_name
);
4910 defsubr (&Sbuffer_name
);
4911 /*defsubr (&Sbuffer_number);*/
4912 defsubr (&Sbuffer_file_name
);
4913 defsubr (&Sbuffer_base_buffer
);
4914 defsubr (&Sbuffer_local_variables
);
4915 defsubr (&Sbuffer_modified_p
);
4916 defsubr (&Sset_buffer_modified_p
);
4917 defsubr (&Sbuffer_modified_tick
);
4918 defsubr (&Srename_buffer
);
4919 defsubr (&Sother_buffer
);
4920 defsubr (&Sbuffer_disable_undo
);
4921 defsubr (&Sbuffer_enable_undo
);
4922 defsubr (&Skill_buffer
);
4923 defsubr (&Sset_buffer_major_mode
);
4924 defsubr (&Sswitch_to_buffer
);
4925 defsubr (&Spop_to_buffer
);
4926 defsubr (&Scurrent_buffer
);
4927 defsubr (&Sset_buffer
);
4928 defsubr (&Sbarf_if_buffer_read_only
);
4929 defsubr (&Sbury_buffer
);
4930 defsubr (&Serase_buffer
);
4931 defsubr (&Sset_buffer_multibyte
);
4932 defsubr (&Skill_all_local_variables
);
4934 defsubr (&Soverlayp
);
4935 defsubr (&Smake_overlay
);
4936 defsubr (&Sdelete_overlay
);
4937 defsubr (&Smove_overlay
);
4938 defsubr (&Soverlay_start
);
4939 defsubr (&Soverlay_end
);
4940 defsubr (&Soverlay_buffer
);
4941 defsubr (&Soverlay_properties
);
4942 defsubr (&Soverlays_at
);
4943 defsubr (&Soverlays_in
);
4944 defsubr (&Snext_overlay_change
);
4945 defsubr (&Sprevious_overlay_change
);
4946 defsubr (&Soverlay_recenter
);
4947 defsubr (&Soverlay_lists
);
4948 defsubr (&Soverlay_get
);
4949 defsubr (&Soverlay_put
);
4950 defsubr (&Srestore_buffer_modified_p
);
4956 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
4957 initial_define_key (control_x_map
, 'k', "kill-buffer");
4959 /* This must not be in syms_of_buffer, because Qdisabled is not
4960 initialized when that function gets called. */
4961 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);