1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995
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. */
23 #include <sys/types.h>
25 #include <sys/param.h>
28 /* in 4.1, param.h fails to define this. */
29 #define MAXPATHLEN 1024
30 #endif /* not MAXPATHLEN */
34 #include "intervals.h"
38 #include "region-cache.h"
40 #include "blockinput.h"
42 struct buffer
*current_buffer
; /* the current buffer */
44 /* First buffer in chain of all buffers (in reverse order of creation).
45 Threaded through ->next. */
47 struct buffer
*all_buffers
;
49 /* This structure holds the default values of the buffer-local variables
50 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
51 The default value occupies the same slot in this structure
52 as an individual buffer's value occupies in that buffer.
53 Setting the default value also goes through the alist of buffers
54 and stores into each buffer that does not say it has a local value. */
56 struct buffer buffer_defaults
;
58 /* A Lisp_Object pointer to the above, used for staticpro */
60 static Lisp_Object Vbuffer_defaults
;
62 /* This structure marks which slots in a buffer have corresponding
63 default values in buffer_defaults.
64 Each such slot has a nonzero value in this structure.
65 The value has only one nonzero bit.
67 When a buffer has its own local value for a slot,
68 the bit for that slot (found in the same slot in this structure)
69 is turned on in the buffer's local_var_flags slot.
71 If a slot in this structure is -1, then even though there may
72 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
73 and the corresponding slot in buffer_defaults is not used.
75 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
76 but there is a default value which is copied into each buffer.
78 If a slot in this structure is negative, then even though there may
79 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
80 and the corresponding slot in buffer_defaults is not used.
82 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
83 zero, that is a bug */
85 struct buffer buffer_local_flags
;
87 /* This structure holds the names of symbols whose values may be
88 buffer-local. It is indexed and accessed in the same way as the above. */
90 struct buffer buffer_local_symbols
;
91 /* A Lisp_Object pointer to the above, used for staticpro */
92 static Lisp_Object Vbuffer_local_symbols
;
94 /* This structure holds the required types for the values in the
95 buffer-local slots. If a slot contains Qnil, then the
96 corresponding buffer slot may contain a value of any type. If a
97 slot contains an integer, then prospective values' tags must be
98 equal to that integer. When a tag does not match, the function
99 buffer_slot_type_mismatch will signal an error. */
100 struct buffer buffer_local_types
;
102 /* Flags indicating which built-in buffer-local variables
103 are permanent locals. */
104 static int buffer_permanent_local_flags
;
106 Lisp_Object
Fset_buffer ();
107 void set_buffer_internal ();
108 void set_buffer_internal_1 ();
109 static void call_overlay_mod_hooks ();
110 static void swap_out_buffer_local_variables ();
111 static void reset_buffer_local_variables ();
113 /* Alist of all buffer names vs the buffers. */
114 /* This used to be a variable, but is no longer,
115 to prevent lossage due to user rplac'ing this alist or its elements. */
116 Lisp_Object Vbuffer_alist
;
118 /* Functions to call before and after each text change. */
119 Lisp_Object Vbefore_change_function
;
120 Lisp_Object Vafter_change_function
;
121 Lisp_Object Vbefore_change_functions
;
122 Lisp_Object Vafter_change_functions
;
124 Lisp_Object Vtransient_mark_mode
;
126 /* t means ignore all read-only text properties.
127 A list means ignore such a property if its value is a member of the list.
128 Any non-nil value means ignore buffer-read-only. */
129 Lisp_Object Vinhibit_read_only
;
131 /* List of functions to call that can query about killing a buffer.
132 If any of these functions returns nil, we don't kill it. */
133 Lisp_Object Vkill_buffer_query_functions
;
135 /* List of functions to call before changing an unmodified buffer. */
136 Lisp_Object Vfirst_change_hook
;
138 Lisp_Object Qfirst_change_hook
;
139 Lisp_Object Qbefore_change_functions
;
140 Lisp_Object Qafter_change_functions
;
142 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
144 Lisp_Object Qprotected_field
;
146 Lisp_Object QSFundamental
; /* A string "Fundamental" */
148 Lisp_Object Qkill_buffer_hook
;
150 Lisp_Object Qget_file_buffer
;
152 Lisp_Object Qoverlayp
;
154 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
156 Lisp_Object Qmodification_hooks
;
157 Lisp_Object Qinsert_in_front_hooks
;
158 Lisp_Object Qinsert_behind_hooks
;
160 /* For debugging; temporary. See set_buffer_internal. */
161 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
167 error ("No buffer named %s", XSTRING (spec
)->data
);
168 error ("Invalid buffer argument");
171 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
172 "Return non-nil if OBJECT is a buffer which has not been killed.\n\
173 Value is nil if OBJECT is not a buffer or if it has been killed.")
177 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
181 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 0, 0,
182 "Return a list of all existing live buffers.")
185 return Fmapcar (Qcdr
, Vbuffer_alist
);
188 /* Like Fassoc, but use Fstring_equal to compare
189 (which ignores text properties),
190 and don't ever QUIT. */
193 assoc_ignore_text_properties (key
, list
)
194 register Lisp_Object key
;
197 register Lisp_Object tail
;
198 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
200 register Lisp_Object elt
, tem
;
202 tem
= Fstring_equal (Fcar (elt
), key
);
209 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
210 "Return the buffer named NAME (a string).\n\
211 If there is no live buffer named NAME, return nil.\n\
212 NAME may also be a buffer; if so, the value is that buffer.")
214 register Lisp_Object name
;
218 CHECK_STRING (name
, 0);
220 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
223 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
224 "Return the buffer visiting file FILENAME (a string).\n\
225 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
226 If there is no such live buffer, return nil.\n\
227 See also `find-buffer-visiting'.")
229 register Lisp_Object filename
;
231 register Lisp_Object tail
, buf
, tem
;
234 CHECK_STRING (filename
, 0);
235 filename
= Fexpand_file_name (filename
, Qnil
);
237 /* If the file name has special constructs in it,
238 call the corresponding file handler. */
239 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
241 return call2 (handler
, Qget_file_buffer
, filename
);
243 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
245 buf
= Fcdr (XCONS (tail
)->car
);
246 if (!BUFFERP (buf
)) continue;
247 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
248 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
256 get_truename_buffer (filename
)
257 register Lisp_Object filename
;
259 register Lisp_Object tail
, buf
, tem
;
261 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
263 buf
= Fcdr (XCONS (tail
)->car
);
264 if (!BUFFERP (buf
)) continue;
265 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
266 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
273 /* Incremented for each buffer created, to assign the buffer number. */
276 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
277 "Return the buffer named NAME, or create such a buffer and return it.\n\
278 A new buffer is created if there is no live buffer named NAME.\n\
279 If NAME starts with a space, the new buffer does not keep undo information.\n\
280 If NAME is a buffer instead of a string, then it is the value returned.\n\
281 The value is never nil.")
283 register Lisp_Object name
;
285 register Lisp_Object buf
;
286 register struct buffer
*b
;
288 buf
= Fget_buffer (name
);
292 if (XSTRING (name
)->size
== 0)
293 error ("Empty string for buffer name is not allowed");
295 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
297 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
299 /* An ordinary buffer uses its own struct buffer_text. */
300 b
->text
= &b
->own_text
;
303 BUF_GAP_SIZE (b
) = 20;
305 BUFFER_ALLOC (BUF_BEG_ADDR (b
), BUF_GAP_SIZE (b
));
307 if (! BUF_BEG_ADDR (b
))
308 buffer_memory_full ();
316 BUF_OVERLAY_MODIFF (b
) = 1;
317 BUF_SAVE_MODIFF (b
) = 1;
318 BUF_INTERVALS (b
) = 0;
320 b
->newline_cache
= 0;
321 b
->width_run_cache
= 0;
322 b
->width_table
= Qnil
;
324 /* Put this on the chain of all buffers including killed ones. */
325 b
->next
= all_buffers
;
328 /* An ordinary buffer normally doesn't need markers
329 to handle BEGV and ZV. */
331 b
->begv_marker
= Qnil
;
334 name
= Fcopy_sequence (name
);
335 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
338 if (XSTRING (name
)->data
[0] != ' ')
344 reset_buffer_local_variables (b
, 1);
346 /* Put this in the alist of all live buffers. */
348 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
350 b
->mark
= Fmake_marker ();
351 BUF_MARKERS (b
) = Qnil
;
356 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
, 2, 2,
357 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
358 "Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.\n\
359 BASE-BUFFER should be an existing buffer (or buffer name).\n\
360 NAME should be a string which is not the name of an existing buffer.")
362 register Lisp_Object base_buffer
, name
;
364 register Lisp_Object buf
;
365 register struct buffer
*b
;
367 buf
= Fget_buffer (name
);
369 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
371 base_buffer
= Fget_buffer (base_buffer
);
372 if (NILP (base_buffer
))
373 error ("No such buffer: `%s'",
374 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
376 if (XSTRING (name
)->size
== 0)
377 error ("Empty string for buffer name is not allowed");
379 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
381 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
383 if (XBUFFER (base_buffer
)->base_buffer
)
384 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
386 b
->base_buffer
= XBUFFER (base_buffer
);
388 /* Use the base buffer's text object. */
389 b
->text
= b
->base_buffer
->text
;
391 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
392 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
393 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
395 b
->newline_cache
= 0;
396 b
->width_run_cache
= 0;
397 b
->width_table
= Qnil
;
399 /* Put this on the chain of all buffers including killed ones. */
400 b
->next
= all_buffers
;
403 name
= Fcopy_sequence (name
);
404 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
408 reset_buffer_local_variables (b
, 1);
410 /* Put this in the alist of all live buffers. */
412 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
414 b
->mark
= Fmake_marker ();
417 /* Make sure the base buffer has markers for its narrowing. */
418 if (NILP (b
->base_buffer
->pt_marker
))
420 b
->base_buffer
->pt_marker
= Fmake_marker ();
421 Fset_marker (b
->base_buffer
->pt_marker
,
422 make_number (BUF_PT (b
->base_buffer
)), base_buffer
);
424 if (NILP (b
->base_buffer
->begv_marker
))
426 b
->base_buffer
->begv_marker
= Fmake_marker ();
427 Fset_marker (b
->base_buffer
->begv_marker
,
428 make_number (BUF_BEGV (b
->base_buffer
)), base_buffer
);
430 if (NILP (b
->base_buffer
->zv_marker
))
432 b
->base_buffer
->zv_marker
= Fmake_marker ();
433 Fset_marker (b
->base_buffer
->zv_marker
,
434 make_number (BUF_ZV (b
->base_buffer
)), base_buffer
);
435 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
438 /* Give the indirect buffer markers for its narrowing. */
439 b
->pt_marker
= Fmake_marker ();
440 Fset_marker (b
->pt_marker
, make_number (BUF_PT (b
)), buf
);
441 b
->begv_marker
= Fmake_marker ();
442 Fset_marker (b
->begv_marker
, make_number (BUF_BEGV (b
)), buf
);
443 b
->zv_marker
= Fmake_marker ();
444 Fset_marker (b
->zv_marker
, make_number (BUF_ZV (b
)), buf
);
446 XMARKER (b
->zv_marker
)->insertion_type
= 1;
451 /* Reinitialize everything about a buffer except its name and contents
452 and local variables. */
456 register struct buffer
*b
;
459 b
->file_truename
= Qnil
;
460 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
462 XSETFASTINT (b
->save_length
, 0);
463 b
->last_window_start
= 1;
465 b
->auto_save_modified
= 0;
466 b
->auto_save_failure_time
= -1;
467 b
->auto_save_file_name
= Qnil
;
469 b
->overlays_before
= Qnil
;
470 b
->overlays_after
= Qnil
;
471 XSETFASTINT (b
->overlay_center
, 1);
472 b
->mark_active
= Qnil
;
473 b
->point_before_scroll
= Qnil
;
474 b
->file_format
= Qnil
;
475 b
->last_selected_window
= Qnil
;
480 /* Reset buffer B's local variables info.
481 Don't use this on a buffer that has already been in use;
482 it does not treat permanent locals consistently.
483 Instead, use Fkill_all_local_variables.
485 If PERMANENT_TOO is 1, then we reset permanent built-in
486 buffer-local variables. If PERMANENT_TOO is 0,
487 we preserve those. */
490 reset_buffer_local_variables (b
, permanent_too
)
491 register struct buffer
*b
;
497 /* Decide which built-in local variables to reset. */
501 dont_reset
= buffer_permanent_local_flags
;
503 /* Reset the major mode to Fundamental, together with all the
504 things that depend on the major mode.
505 default-major-mode is handled at a higher level.
506 We ignore it here. */
507 b
->major_mode
= Qfundamental_mode
;
509 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
510 b
->mode_name
= QSFundamental
;
511 b
->minor_modes
= Qnil
;
513 /* If the standard case table has been altered and invalidated,
514 fix up its insides first. */
515 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
516 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
517 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
518 Fset_standard_case_table (Vascii_downcase_table
);
520 b
->downcase_table
= Vascii_downcase_table
;
521 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
522 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
523 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
524 b
->invisibility_spec
= Qt
;
526 b
->buffer_file_type
= Qnil
;
530 b
->sort_table
= XSTRING (Vascii_sort_table
);
531 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
534 /* Reset all (or most) per-buffer variables to their defaults. */
535 b
->local_var_alist
= Qnil
;
536 b
->local_var_flags
&= dont_reset
;
538 /* For each slot that has a default value,
539 copy that into the slot. */
541 for (offset
= (char *)&buffer_local_flags
.name
- (char *)&buffer_local_flags
;
542 offset
< sizeof (struct buffer
);
543 offset
+= sizeof (Lisp_Object
)) /* sizeof EMACS_INT == sizeof Lisp_Object */
545 int flag
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
547 /* Don't reset a permanent local. */
548 && ! (dont_reset
& flag
))
550 *(Lisp_Object
*)(offset
+ (char *)b
)
551 = *(Lisp_Object
*)(offset
+ (char *)&buffer_defaults
);
555 /* We split this away from generate-new-buffer, because rename-buffer
556 and set-visited-file-name ought to be able to use this to really
557 rename the buffer properly. */
559 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
561 "Return a string that is the name of no existing buffer based on NAME.\n\
562 If there is no live buffer named NAME, then return NAME.\n\
563 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
564 until an unused name is found, and then return that name.\n\
565 Optional second argument IGNORE specifies a name that is okay to use\n\
566 \(if it is in the sequence to be tried)\n\
567 even if a buffer with that name exists.")
569 register Lisp_Object name
, ignore
;
571 register Lisp_Object gentemp
, tem
;
575 CHECK_STRING (name
, 0);
577 tem
= Fget_buffer (name
);
584 sprintf (number
, "<%d>", ++count
);
585 gentemp
= concat2 (name
, build_string (number
));
586 tem
= Fstring_equal (gentemp
, ignore
);
589 tem
= Fget_buffer (gentemp
);
596 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
597 "Return the name of BUFFER, as a string.\n\
598 With no argument or nil as argument, return the name of the current buffer.")
600 register Lisp_Object buffer
;
603 return current_buffer
->name
;
604 CHECK_BUFFER (buffer
, 0);
605 return XBUFFER (buffer
)->name
;
608 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
609 "Return name of file BUFFER is visiting, or nil if none.\n\
610 No argument or nil as argument means use the current buffer.")
612 register Lisp_Object buffer
;
615 return current_buffer
->filename
;
616 CHECK_BUFFER (buffer
, 0);
617 return XBUFFER (buffer
)->filename
;
620 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
622 "Return the base buffer of indirect buffer BUFFER.\n\
623 If BUFFER is not indirect, return nil.")
625 register Lisp_Object buffer
;
628 Lisp_Object base_buffer
;
631 base
= current_buffer
->base_buffer
;
634 CHECK_BUFFER (buffer
, 0);
635 base
= XBUFFER (buffer
)->base_buffer
;
640 XSETBUFFER (base_buffer
, base
);
644 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
645 Sbuffer_local_variables
, 0, 1, 0,
646 "Return an alist of variables that are buffer-local in BUFFER.\n\
647 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
648 For a symbol that is locally unbound, just the symbol appears in the value.\n\
649 Note that storing new VALUEs in these elements doesn't change the variables.\n\
650 No argument or nil as argument means use current buffer as BUFFER.")
652 register Lisp_Object buffer
;
654 register struct buffer
*buf
;
655 register Lisp_Object result
;
658 buf
= current_buffer
;
661 CHECK_BUFFER (buffer
, 0);
662 buf
= XBUFFER (buffer
);
668 register Lisp_Object tail
;
669 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
671 Lisp_Object val
, elt
;
673 elt
= XCONS (tail
)->car
;
675 /* Reference each variable in the alist in buf.
676 If inquiring about the current buffer, this gets the current values,
677 so store them into the alist so the alist is up to date.
678 If inquiring about some other buffer, this swaps out any values
679 for that buffer, making the alist up to date automatically. */
680 val
= find_symbol_value (XCONS (elt
)->car
);
681 /* Use the current buffer value only if buf is the current buffer. */
682 if (buf
!= current_buffer
)
683 val
= XCONS (elt
)->cdr
;
685 /* If symbol is unbound, put just the symbol in the list. */
686 if (EQ (val
, Qunbound
))
687 result
= Fcons (XCONS (elt
)->car
, result
);
688 /* Otherwise, put (symbol . value) in the list. */
690 result
= Fcons (Fcons (XCONS (elt
)->car
, val
), result
);
694 /* Add on all the variables stored in special slots. */
696 register int offset
, mask
;
698 for (offset
= (char *)&buffer_local_symbols
.name
- (char *)&buffer_local_symbols
;
699 offset
< sizeof (struct buffer
);
700 offset
+= (sizeof (EMACS_INT
))) /* sizeof EMACS_INT == sizeof Lisp_Object */
702 mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
703 if (mask
== -1 || (buf
->local_var_flags
& mask
))
704 if (SYMBOLP (*(Lisp_Object
*)(offset
705 + (char *)&buffer_local_symbols
)))
706 result
= Fcons (Fcons (*((Lisp_Object
*)
707 (offset
+ (char *)&buffer_local_symbols
)),
708 *(Lisp_Object
*)(offset
+ (char *)buf
)),
717 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
719 "Return t if BUFFER was modified since its file was last read or saved.\n\
720 No argument or nil as argument means use current buffer as BUFFER.")
722 register Lisp_Object buffer
;
724 register struct buffer
*buf
;
726 buf
= current_buffer
;
729 CHECK_BUFFER (buffer
, 0);
730 buf
= XBUFFER (buffer
);
733 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
736 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
738 "Mark current buffer as modified or unmodified according to FLAG.\n\
739 A non-nil FLAG means mark the buffer modified.")
741 register Lisp_Object flag
;
743 register int already
;
744 register Lisp_Object fn
;
746 #ifdef CLASH_DETECTION
747 /* If buffer becoming modified, lock the file.
748 If buffer becoming unmodified, unlock the file. */
750 fn
= current_buffer
->file_truename
;
753 already
= SAVE_MODIFF
< MODIFF
;
754 if (!already
&& !NILP (flag
))
756 else if (already
&& NILP (flag
))
759 #endif /* CLASH_DETECTION */
761 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
766 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
768 "Return BUFFER's tick counter, incremented for each change in text.\n\
769 Each buffer has a tick counter which is incremented each time the text in\n\
770 that buffer is changed. It wraps around occasionally.\n\
771 No argument or nil as argument means use current buffer as BUFFER.")
773 register Lisp_Object buffer
;
775 register struct buffer
*buf
;
777 buf
= current_buffer
;
780 CHECK_BUFFER (buffer
, 0);
781 buf
= XBUFFER (buffer
);
784 return make_number (BUF_MODIFF (buf
));
787 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
788 "sRename buffer (to new name): \nP",
789 "Change current buffer's name to NEWNAME (a string).\n\
790 If second arg UNIQUE is nil or omitted, it is an error if a\n\
791 buffer named NEWNAME already exists.\n\
792 If UNIQUE is non-nil, come up with a new name using\n\
793 `generate-new-buffer-name'.\n\
794 Interactively, you can set UNIQUE with a prefix argument.\n\
795 We return the name we actually gave the buffer.\n\
796 This does not change the name of the visited file (if any).")
798 register Lisp_Object newname
, unique
;
800 register Lisp_Object tem
, buf
;
802 CHECK_STRING (newname
, 0);
804 if (XSTRING (newname
)->size
== 0)
805 error ("Empty string is invalid as a buffer name");
807 tem
= Fget_buffer (newname
);
808 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
809 the buffer automatically so you can create another with the original name.
810 It makes UNIQUE equivalent to
811 (rename-buffer (generate-new-buffer-name NEWNAME)). */
812 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
813 return current_buffer
->name
;
817 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
819 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
822 current_buffer
->name
= newname
;
824 /* Catch redisplay's attention. Unless we do this, the mode lines for
825 any windows displaying current_buffer will stay unchanged. */
828 XSETBUFFER (buf
, current_buffer
);
829 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
830 if (NILP (current_buffer
->filename
)
831 && !NILP (current_buffer
->auto_save_file_name
))
832 call0 (intern ("rename-auto-save-file"));
833 /* Refetch since that last call may have done GC. */
834 return current_buffer
->name
;
837 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 2, 0,
838 "Return most recently selected buffer other than BUFFER.\n\
839 Buffers not visible in windows are preferred to visible buffers,\n\
840 unless optional second argument VISIBLE-OK is non-nil.\n\
841 If no other buffer exists, the buffer `*scratch*' is returned.\n\
842 If BUFFER is omitted or nil, some interesting buffer is returned.")
844 register Lisp_Object buffer
, visible_ok
;
846 Lisp_Object
Fset_buffer_major_mode ();
847 register Lisp_Object tail
, buf
, notsogood
, tem
;
850 for (tail
= Vbuffer_alist
; !NILP (tail
); tail
= Fcdr (tail
))
852 buf
= Fcdr (Fcar (tail
));
853 if (EQ (buf
, buffer
))
855 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
857 /* If the selected frame has a buffer_predicate,
858 disregard buffers that don't fit the predicate. */
859 tem
= frame_buffer_predicate ();
862 tem
= call1 (tem
, buf
);
867 if (NILP (visible_ok
))
868 tem
= Fget_buffer_window (buf
, Qt
);
873 if (NILP (notsogood
))
876 if (!NILP (notsogood
))
878 buf
= Fget_buffer_create (build_string ("*scratch*"));
879 Fset_buffer_major_mode (buf
);
883 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
,
885 "Make BUFFER stop keeping undo information.\n\
886 No argument or nil as argument means do this for the current buffer.")
888 register Lisp_Object buffer
;
890 Lisp_Object real_buffer
;
893 XSETBUFFER (real_buffer
, current_buffer
);
896 real_buffer
= Fget_buffer (buffer
);
897 if (NILP (real_buffer
))
901 XBUFFER (real_buffer
)->undo_list
= Qt
;
906 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
908 "Start keeping undo information for buffer BUFFER.\n\
909 No argument or nil as argument means do this for the current buffer.")
911 register Lisp_Object buffer
;
913 Lisp_Object real_buffer
;
916 XSETBUFFER (real_buffer
, current_buffer
);
919 real_buffer
= Fget_buffer (buffer
);
920 if (NILP (real_buffer
))
924 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
925 XBUFFER (real_buffer
)->undo_list
= Qnil
;
931 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
932 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
933 The buffer being killed will be current while the hook is running.\n\
936 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
937 "Kill the buffer BUFFER.\n\
938 The argument may be a buffer or may be the name of a buffer.\n\
939 An argument of nil means kill the current buffer.\n\n\
940 Value is t if the buffer is actually killed, nil if user says no.\n\n\
941 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
942 if not void, is a list of functions to be called, with no arguments,\n\
943 before the buffer is actually killed. The buffer to be killed is current\n\
944 when the hook functions are called.\n\n\
945 Any processes that have this buffer as the `process-buffer' are killed\n\
951 register struct buffer
*b
;
952 register Lisp_Object tem
;
953 register struct Lisp_Marker
*m
;
954 struct gcpro gcpro1
, gcpro2
;
957 buf
= Fcurrent_buffer ();
959 buf
= Fget_buffer (buffer
);
965 /* Avoid trouble for buffer already dead. */
969 /* Query if the buffer is still modified. */
970 if (INTERACTIVE
&& !NILP (b
->filename
)
971 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
974 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
975 XSTRING (b
->name
)->data
));
981 /* Run hooks with the buffer to be killed the current buffer. */
983 register Lisp_Object val
;
984 int count
= specpdl_ptr
- specpdl
;
987 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
988 set_buffer_internal (b
);
990 /* First run the query functions; if any query is answered no,
991 don't kill the buffer. */
992 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
994 tem
= call0 (Fcar (list
));
996 return unbind_to (count
, Qnil
);
999 /* Then run the hooks. */
1000 if (!NILP (Vrun_hooks
))
1001 call1 (Vrun_hooks
, Qkill_buffer_hook
);
1002 unbind_to (count
, Qnil
);
1005 /* We have no more questions to ask. Verify that it is valid
1006 to kill the buffer. This must be done after the questions
1007 since anything can happen within do_yes_or_no_p. */
1009 /* Don't kill the minibuffer now current. */
1010 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1016 /* When we kill a base buffer, kill all its indirect buffers.
1017 We do it at this stage so nothing terrible happens if they
1018 ask questions or their hooks get errors. */
1019 if (! b
->base_buffer
)
1021 struct buffer
*other
;
1025 for (other
= all_buffers
; other
; other
= other
->next
)
1026 /* all_buffers contains dead buffers too;
1027 don't re-kill them. */
1028 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1031 XSETBUFFER (buf
, other
);
1038 /* Make this buffer not be current.
1039 In the process, notice if this is the sole visible buffer
1040 and give up if so. */
1041 if (b
== current_buffer
)
1043 tem
= Fother_buffer (buf
, Qnil
);
1045 if (b
== current_buffer
)
1049 /* Now there is no question: we can kill the buffer. */
1051 #ifdef CLASH_DETECTION
1052 /* Unlock this buffer's file, if it is locked. */
1054 #endif /* CLASH_DETECTION */
1056 kill_buffer_processes (buf
);
1058 tem
= Vinhibit_quit
;
1060 replace_buffer_in_all_windows (buf
);
1061 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1062 Vinhibit_quit
= tem
;
1064 /* Delete any auto-save file, if we saved it in this session. */
1065 if (STRINGP (b
->auto_save_file_name
)
1066 && b
->auto_save_modified
!= 0
1067 && SAVE_MODIFF
< b
->auto_save_modified
)
1070 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1072 internal_delete_file (b
->auto_save_file_name
);
1077 /* Unchain all markers that belong to this indirect buffer.
1078 Don't unchain the markers that belong to the base buffer
1079 or its other indirect buffers. */
1080 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1086 unchain_marker (tem
);
1092 /* Unchain all markers of this buffer and its indirect buffers.
1093 and leave them pointing nowhere. */
1094 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1101 BUF_MARKERS (b
) = Qnil
;
1103 #ifdef USE_TEXT_PROPERTIES
1104 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1107 /* Perhaps we should explicitly free the interval tree here... */
1110 /* Reset the local variables, so that this buffer's local values
1111 won't be protected from GC. They would be protected
1112 if they happened to remain encached in their symbols.
1113 This gets rid of them for certain. */
1114 swap_out_buffer_local_variables (b
);
1115 reset_buffer_local_variables (b
, 1);
1120 if (! b
->base_buffer
)
1121 BUFFER_FREE (BUF_BEG_ADDR (b
));
1123 if (b
->newline_cache
)
1125 free_region_cache (b
->newline_cache
);
1126 b
->newline_cache
= 0;
1128 if (b
->width_run_cache
)
1130 free_region_cache (b
->width_run_cache
);
1131 b
->width_run_cache
= 0;
1133 b
->width_table
= Qnil
;
1135 b
->undo_list
= Qnil
;
1140 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1141 we do this each time BUF is selected visibly, the more recently
1142 selected buffers are always closer to the front of the list. This
1143 means that other_buffer is more likely to choose a relevant buffer. */
1148 register Lisp_Object link
, prev
;
1151 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCONS (link
)->cdr
)
1153 if (EQ (XCONS (XCONS (link
)->car
)->cdr
, buf
))
1158 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1159 we cannot use Fdelq itself here because it allows quitting. */
1162 Vbuffer_alist
= XCONS (Vbuffer_alist
)->cdr
;
1164 XCONS (prev
)->cdr
= XCONS (XCONS (prev
)->cdr
)->cdr
;
1166 XCONS(link
)->cdr
= Vbuffer_alist
;
1167 Vbuffer_alist
= link
;
1170 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1171 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1172 Use this function before selecting the buffer, since it may need to inspect\n\
1173 the current buffer's major mode.")
1178 Lisp_Object function
;
1180 function
= buffer_defaults
.major_mode
;
1181 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1182 function
= current_buffer
->major_mode
;
1184 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1187 count
= specpdl_ptr
- specpdl
;
1189 /* To select a nonfundamental mode,
1190 select the buffer temporarily and then call the mode function. */
1192 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1194 Fset_buffer (buffer
);
1197 return unbind_to (count
, Qnil
);
1200 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1201 "Select buffer BUFFER in the current window.\n\
1202 BUFFER may be a buffer or a buffer name.\n\
1203 Optional second arg NORECORD non-nil means\n\
1204 do not put this buffer at the front of the list of recently selected ones.\n\
1206 WARNING: This is NOT the way to work on another buffer temporarily\n\
1207 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1208 the window-buffer correspondences.")
1210 Lisp_Object buffer
, norecord
;
1212 register Lisp_Object buf
;
1215 if (EQ (minibuf_window
, selected_window
))
1216 error ("Cannot switch buffers in minibuffer window");
1217 tem
= Fwindow_dedicated_p (selected_window
);
1219 error ("Cannot switch buffers in a dedicated window");
1222 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1225 buf
= Fget_buffer (buffer
);
1228 buf
= Fget_buffer_create (buffer
);
1229 Fset_buffer_major_mode (buf
);
1233 if (NILP (norecord
))
1234 record_buffer (buf
);
1236 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1237 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1244 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 2, 0,
1245 "Select buffer BUFFER in some window, preferably a different one.\n\
1246 If BUFFER is nil, then some other buffer is chosen.\n\
1247 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1248 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1249 window even if BUFFER is already visible in the selected window.\n\
1250 This uses the function `display-buffer' as a subroutine; see the documentation\n\
1251 of `display-buffer' for additional customization information.")
1252 (buffer
, other_window
)
1253 Lisp_Object buffer
, other_window
;
1255 register Lisp_Object buf
;
1257 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1260 buf
= Fget_buffer (buffer
);
1263 buf
= Fget_buffer_create (buffer
);
1264 Fset_buffer_major_mode (buf
);
1268 record_buffer (buf
);
1269 Fselect_window (Fdisplay_buffer (buf
, other_window
));
1273 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1274 "Return the current buffer as a Lisp object.")
1277 register Lisp_Object buf
;
1278 XSETBUFFER (buf
, current_buffer
);
1282 /* Set the current buffer to B. */
1285 set_buffer_internal (b
)
1286 register struct buffer
*b
;
1288 register struct buffer
*old_buf
;
1289 register Lisp_Object tail
, valcontents
;
1292 if (current_buffer
== b
)
1295 windows_or_buffers_changed
= 1;
1296 set_buffer_internal_1 (b
);
1299 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1300 This is used by redisplay. */
1303 set_buffer_internal_1 (b
)
1304 register struct buffer
*b
;
1306 register struct buffer
*old_buf
;
1307 register Lisp_Object tail
, valcontents
;
1310 if (current_buffer
== b
)
1313 old_buf
= current_buffer
;
1315 last_known_column_point
= -1; /* invalidate indentation cache */
1319 /* Put the undo list back in the base buffer, so that it appears
1320 that an indirect buffer shares the undo list of its base. */
1321 if (old_buf
->base_buffer
)
1322 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1324 /* If the old current buffer has markers to record PT, BEGV and ZV
1325 when it is not current, update them now. */
1326 if (! NILP (old_buf
->pt_marker
))
1329 XSETBUFFER (obuf
, old_buf
);
1330 Fset_marker (old_buf
->pt_marker
, BUF_PT (old_buf
), obuf
);
1332 if (! NILP (old_buf
->begv_marker
))
1335 XSETBUFFER (obuf
, old_buf
);
1336 Fset_marker (old_buf
->begv_marker
, BUF_BEGV (old_buf
), obuf
);
1338 if (! NILP (old_buf
->zv_marker
))
1341 XSETBUFFER (obuf
, old_buf
);
1342 Fset_marker (old_buf
->zv_marker
, BUF_ZV (old_buf
), obuf
);
1346 /* Get the undo list from the base buffer, so that it appears
1347 that an indirect buffer shares the undo list of its base. */
1349 b
->undo_list
= b
->base_buffer
->undo_list
;
1351 /* If the new current buffer has markers to record PT, BEGV and ZV
1352 when it is not current, fetch them now. */
1353 if (! NILP (b
->pt_marker
))
1354 BUF_PT (b
) = marker_position (b
->pt_marker
);
1355 if (! NILP (b
->begv_marker
))
1356 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1357 if (! NILP (b
->zv_marker
))
1358 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1360 /* Look down buffer's list of local Lisp variables
1361 to find and update any that forward into C variables. */
1363 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1365 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1366 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1367 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1368 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1369 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1370 /* Just reference the variable
1371 to cause it to become set for this buffer. */
1372 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1375 /* Do the same with any others that were local to the previous buffer */
1378 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1380 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1381 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1382 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1383 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1384 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1385 /* Just reference the variable
1386 to cause it to become set for this buffer. */
1387 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1391 /* Switch to buffer B temporarily for redisplay purposes.
1392 This avoids certain things that don't need to be done within redisplay. */
1398 register struct buffer
*old_buf
;
1400 if (current_buffer
== b
)
1403 old_buf
= current_buffer
;
1408 /* If the old current buffer has markers to record PT, BEGV and ZV
1409 when it is not current, update them now. */
1410 if (! NILP (old_buf
->pt_marker
))
1413 XSETBUFFER (obuf
, old_buf
);
1414 Fset_marker (old_buf
->pt_marker
, BUF_PT (old_buf
), obuf
);
1416 if (! NILP (old_buf
->begv_marker
))
1419 XSETBUFFER (obuf
, old_buf
);
1420 Fset_marker (old_buf
->begv_marker
, BUF_BEGV (old_buf
), obuf
);
1422 if (! NILP (old_buf
->zv_marker
))
1425 XSETBUFFER (obuf
, old_buf
);
1426 Fset_marker (old_buf
->zv_marker
, BUF_ZV (old_buf
), obuf
);
1430 /* If the new current buffer has markers to record PT, BEGV and ZV
1431 when it is not current, fetch them now. */
1432 if (! NILP (b
->pt_marker
))
1433 BUF_PT (b
) = marker_position (b
->pt_marker
);
1434 if (! NILP (b
->begv_marker
))
1435 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1436 if (! NILP (b
->zv_marker
))
1437 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1440 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1441 "Make the buffer BUFFER current for editing operations.\n\
1442 BUFFER may be a buffer or the name of an existing buffer.\n\
1443 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1444 This function does not display the buffer, so its effect ends\n\
1445 when the current command terminates.\n\
1446 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1448 register Lisp_Object buffer
;
1450 register Lisp_Object buf
;
1451 buf
= Fget_buffer (buffer
);
1454 if (NILP (XBUFFER (buf
)->name
))
1455 error ("Selecting deleted buffer");
1456 set_buffer_internal (XBUFFER (buf
));
1460 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1461 Sbarf_if_buffer_read_only
, 0, 0, 0,
1462 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1465 if (!NILP (current_buffer
->read_only
)
1466 && NILP (Vinhibit_read_only
))
1467 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1471 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1472 "Put BUFFER at the end of the list of all buffers.\n\
1473 There it is the least likely candidate for `other-buffer' to return;\n\
1474 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1475 If BUFFER is nil or omitted, bury the current buffer.\n\
1476 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1477 selected window if it is displayed there.")
1479 register Lisp_Object buffer
;
1481 /* Figure out what buffer we're going to bury. */
1484 XSETBUFFER (buffer
, current_buffer
);
1486 /* If we're burying the current buffer, unshow it. */
1487 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
), Qnil
);
1493 buf1
= Fget_buffer (buffer
);
1499 /* Move buffer to the end of the buffer list. */
1501 register Lisp_Object aelt
, link
;
1503 aelt
= Frassq (buffer
, Vbuffer_alist
);
1504 link
= Fmemq (aelt
, Vbuffer_alist
);
1505 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1506 XCONS (link
)->cdr
= Qnil
;
1507 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1513 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1514 "Delete the entire contents of the current buffer.\n\
1515 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1516 so the buffer is truly empty after this.")
1521 current_buffer
->last_window_start
= 1;
1522 /* Prevent warnings, or suspension of auto saving, that would happen
1523 if future size is less than past size. Use of erase-buffer
1524 implies that the future text is not really related to the past text. */
1525 XSETFASTINT (current_buffer
->save_length
, 0);
1529 validate_region (b
, e
)
1530 register Lisp_Object
*b
, *e
;
1532 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1533 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1535 if (XINT (*b
) > XINT (*e
))
1538 tem
= *b
; *b
= *e
; *e
= tem
;
1541 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1542 && XINT (*e
) <= ZV
))
1543 args_out_of_range (*b
, *e
);
1546 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
1548 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1549 Most local variable bindings are eliminated so that the default values\n\
1550 become effective once more. Also, the syntax table is set from\n\
1551 `standard-syntax-table', the local keymap is set to nil,\n\
1552 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1553 This function also forces redisplay of the mode line.\n\
1555 Every function to select a new major mode starts by\n\
1556 calling this function.\n\n\
1557 As a special exception, local variables whose names have\n\
1558 a non-nil `permanent-local' property are not eliminated by this function.\n\
1560 The first thing this function does is run\n\
1561 the normal hook `change-major-mode-hook'.")
1564 register Lisp_Object alist
, sym
, tem
;
1567 if (!NILP (Vrun_hooks
))
1568 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
1569 oalist
= current_buffer
->local_var_alist
;
1571 /* Make sure none of the bindings in oalist
1572 remain swapped in, in their symbols. */
1574 swap_out_buffer_local_variables (current_buffer
);
1576 /* Actually eliminate all local bindings of this buffer. */
1578 reset_buffer_local_variables (current_buffer
, 0);
1580 /* Redisplay mode lines; we are changing major mode. */
1582 update_mode_lines
++;
1584 /* Any which are supposed to be permanent,
1585 make local again, with the same values they had. */
1587 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1589 sym
= XCONS (XCONS (alist
)->car
)->car
;
1590 tem
= Fget (sym
, Qpermanent_local
);
1593 Fmake_local_variable (sym
);
1594 Fset (sym
, XCONS (XCONS (alist
)->car
)->cdr
);
1598 /* Force mode-line redisplay. Useful here because all major mode
1599 commands call this function. */
1600 update_mode_lines
++;
1605 /* Make sure no local variables remain set up with buffer B
1606 for their current values. */
1609 swap_out_buffer_local_variables (b
)
1612 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
1614 XSETBUFFER (buffer
, b
);
1615 oalist
= b
->local_var_alist
;
1617 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1619 sym
= XCONS (XCONS (alist
)->car
)->car
;
1621 /* Need not do anything if some other buffer's binding is now encached. */
1622 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
;
1623 if (XBUFFER (tem
) == current_buffer
)
1625 /* Symbol is set up for this buffer's old local value.
1626 Set it up for the current buffer with the default value. */
1628 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->cdr
;
1629 /* Store the symbol's current value into the alist entry
1630 it is currently set up for. This is so that, if the
1631 local is marked permanent, and we make it local again
1632 later in Fkill_all_local_variables, we don't lose the value. */
1633 XCONS (XCONS (tem
)->car
)->cdr
1634 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
);
1635 /* Switch to the symbol's default-value alist entry. */
1636 XCONS (tem
)->car
= tem
;
1637 /* Mark it as current for buffer B. */
1638 XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
1640 /* Store the current value into any forwarding in the symbol. */
1641 store_symval_forwarding (sym
, XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
,
1647 /* Find all the overlays in the current buffer that contain position POS.
1648 Return the number found, and store them in a vector in *VEC_PTR.
1649 Store in *LEN_PTR the size allocated for the vector.
1650 Store in *NEXT_PTR the next position after POS where an overlay starts,
1651 or ZV if there are no more overlays.
1652 Store in *PREV_PTR the previous position before POS where an overlay ends,
1653 or BEGV if there are no previous overlays.
1654 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1656 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1657 when this function is called.
1659 If EXTEND is non-zero, we make the vector bigger if necessary.
1660 If EXTEND is zero, we never extend the vector,
1661 and we store only as many overlays as will fit.
1662 But we still return the total number of overlays. */
1665 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1668 Lisp_Object
**vec_ptr
;
1673 Lisp_Object tail
, overlay
, start
, end
, result
;
1676 Lisp_Object
*vec
= *vec_ptr
;
1679 int inhibit_storing
= 0;
1681 for (tail
= current_buffer
->overlays_before
;
1683 tail
= XCONS (tail
)->cdr
)
1685 int startpos
, endpos
;
1687 overlay
= XCONS (tail
)->car
;
1689 start
= OVERLAY_START (overlay
);
1690 end
= OVERLAY_END (overlay
);
1691 endpos
= OVERLAY_POSITION (end
);
1700 startpos
= OVERLAY_POSITION (start
);
1701 if (startpos
<= pos
)
1705 /* The supplied vector is full.
1706 Either make it bigger, or don't store any more in it. */
1709 *len_ptr
= len
*= 2;
1710 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1714 inhibit_storing
= 1;
1717 if (!inhibit_storing
)
1719 /* Keep counting overlays even if we can't return them all. */
1722 else if (startpos
< next
)
1726 for (tail
= current_buffer
->overlays_after
;
1728 tail
= XCONS (tail
)->cdr
)
1730 int startpos
, endpos
;
1732 overlay
= XCONS (tail
)->car
;
1734 start
= OVERLAY_START (overlay
);
1735 end
= OVERLAY_END (overlay
);
1736 startpos
= OVERLAY_POSITION (start
);
1739 if (startpos
< next
)
1743 endpos
= OVERLAY_POSITION (end
);
1750 *len_ptr
= len
*= 2;
1751 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1755 inhibit_storing
= 1;
1758 if (!inhibit_storing
)
1762 else if (endpos
< pos
&& endpos
> prev
)
1773 /* Find all the overlays in the current buffer that overlap the range BEG-END
1774 or are empty at BEG.
1776 Return the number found, and store them in a vector in *VEC_PTR.
1777 Store in *LEN_PTR the size allocated for the vector.
1778 Store in *NEXT_PTR the next position after POS where an overlay starts,
1779 or ZV if there are no more overlays.
1780 Store in *PREV_PTR the previous position before POS where an overlay ends,
1781 or BEGV if there are no previous overlays.
1782 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1784 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1785 when this function is called.
1787 If EXTEND is non-zero, we make the vector bigger if necessary.
1788 If EXTEND is zero, we never extend the vector,
1789 and we store only as many overlays as will fit.
1790 But we still return the total number of overlays. */
1793 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1796 Lisp_Object
**vec_ptr
;
1801 Lisp_Object tail
, overlay
, ostart
, oend
, result
;
1804 Lisp_Object
*vec
= *vec_ptr
;
1807 int inhibit_storing
= 0;
1809 for (tail
= current_buffer
->overlays_before
;
1811 tail
= XCONS (tail
)->cdr
)
1813 int startpos
, endpos
;
1815 overlay
= XCONS (tail
)->car
;
1817 ostart
= OVERLAY_START (overlay
);
1818 oend
= OVERLAY_END (overlay
);
1819 endpos
= OVERLAY_POSITION (oend
);
1826 startpos
= OVERLAY_POSITION (ostart
);
1827 /* Count an interval if it either overlaps the range
1828 or is empty at the start of the range. */
1829 if ((beg
< endpos
&& startpos
< end
)
1830 || (startpos
== endpos
&& beg
== endpos
))
1834 /* The supplied vector is full.
1835 Either make it bigger, or don't store any more in it. */
1838 *len_ptr
= len
*= 2;
1839 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1843 inhibit_storing
= 1;
1846 if (!inhibit_storing
)
1848 /* Keep counting overlays even if we can't return them all. */
1851 else if (startpos
< next
)
1855 for (tail
= current_buffer
->overlays_after
;
1857 tail
= XCONS (tail
)->cdr
)
1859 int startpos
, endpos
;
1861 overlay
= XCONS (tail
)->car
;
1863 ostart
= OVERLAY_START (overlay
);
1864 oend
= OVERLAY_END (overlay
);
1865 startpos
= OVERLAY_POSITION (ostart
);
1868 if (startpos
< next
)
1872 endpos
= OVERLAY_POSITION (oend
);
1873 /* Count an interval if it either overlaps the range
1874 or is empty at the start of the range. */
1875 if ((beg
< endpos
&& startpos
< end
)
1876 || (startpos
== endpos
&& beg
== endpos
))
1882 *len_ptr
= len
*= 2;
1883 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1887 inhibit_storing
= 1;
1890 if (!inhibit_storing
)
1894 else if (endpos
< beg
&& endpos
> prev
)
1905 /* Fast function to just test if we're at an overlay boundary. */
1907 overlay_touches_p (pos
)
1910 Lisp_Object tail
, overlay
;
1912 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
1913 tail
= XCONS (tail
)->cdr
)
1917 overlay
= XCONS (tail
)->car
;
1918 if (!GC_OVERLAYP (overlay
))
1921 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
1924 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
1928 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
1929 tail
= XCONS (tail
)->cdr
)
1933 overlay
= XCONS (tail
)->car
;
1934 if (!GC_OVERLAYP (overlay
))
1937 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
1940 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
1948 Lisp_Object overlay
;
1954 compare_overlays (s1
, s2
)
1955 struct sortvec
*s1
, *s2
;
1957 if (s1
->priority
!= s2
->priority
)
1958 return s1
->priority
- s2
->priority
;
1959 if (s1
->beg
!= s2
->beg
)
1960 return s1
->beg
- s2
->beg
;
1961 if (s1
->end
!= s2
->end
)
1962 return s2
->end
- s1
->end
;
1966 /* Sort an array of overlays by priority. The array is modified in place.
1967 The return value is the new size; this may be smaller than the original
1968 size if some of the overlays were invalid or were window-specific. */
1970 sort_overlays (overlay_vec
, noverlays
, w
)
1971 Lisp_Object
*overlay_vec
;
1976 struct sortvec
*sortvec
;
1977 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
1979 /* Put the valid and relevant overlays into sortvec. */
1981 for (i
= 0, j
= 0; i
< noverlays
; i
++)
1984 Lisp_Object overlay
;
1986 overlay
= overlay_vec
[i
];
1987 if (OVERLAY_VALID (overlay
)
1988 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
1989 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
1991 /* If we're interested in a specific window, then ignore
1992 overlays that are limited to some other window. */
1997 window
= Foverlay_get (overlay
, Qwindow
);
1998 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2002 /* This overlay is good and counts: put it into sortvec. */
2003 sortvec
[j
].overlay
= overlay
;
2004 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2005 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2006 tem
= Foverlay_get (overlay
, Qpriority
);
2008 sortvec
[j
].priority
= XINT (tem
);
2010 sortvec
[j
].priority
= 0;
2016 /* Sort the overlays into the proper order: increasing priority. */
2019 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2021 for (i
= 0; i
< noverlays
; i
++)
2022 overlay_vec
[i
] = sortvec
[i
].overlay
;
2028 Lisp_Object string
, string2
;
2035 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2036 int size
; /* Allocated length of that array. */
2037 int used
; /* How much of the array is currently in use. */
2038 int bytes
; /* Total length of the strings in buf. */
2041 /* Buffers for storing information about the overlays touching a given
2042 position. These could be automatic variables in overlay_strings, but
2043 it's more efficient to hold onto the memory instead of repeatedly
2044 allocating and freeing it. */
2045 static struct sortstrlist overlay_heads
, overlay_tails
;
2046 static char *overlay_str_buf
;
2048 /* Allocated length of overlay_str_buf. */
2049 static int overlay_str_len
;
2051 /* A comparison function suitable for passing to qsort. */
2053 cmp_for_strings (as1
, as2
)
2056 struct sortstr
*s1
= (struct sortstr
*)as1
;
2057 struct sortstr
*s2
= (struct sortstr
*)as2
;
2058 if (s1
->size
!= s2
->size
)
2059 return s2
->size
- s1
->size
;
2060 if (s1
->priority
!= s2
->priority
)
2061 return s1
->priority
- s2
->priority
;
2066 record_overlay_string (ssl
, str
, str2
, pri
, size
)
2067 struct sortstrlist
*ssl
;
2068 Lisp_Object str
, str2
, pri
;
2071 if (ssl
->used
== ssl
->size
)
2077 ssl
->buf
= ((struct sortstr
*)
2078 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2080 ssl
->buf
[ssl
->used
].string
= str
;
2081 ssl
->buf
[ssl
->used
].string2
= str2
;
2082 ssl
->buf
[ssl
->used
].size
= size
;
2083 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2085 ssl
->bytes
+= XSTRING (str
)->size
;
2087 ssl
->bytes
+= XSTRING (str2
)->size
;
2090 /* Return the concatenation of the strings associated with overlays that
2091 begin or end at POS, ignoring overlays that are specific to a window
2092 other than W. The strings are concatenated in the appropriate order:
2093 shorter overlays nest inside longer ones, and higher priority inside
2094 lower. Normally all of the after-strings come first, but zero-sized
2095 overlays have their after-strings ride along with the before-strings
2096 because it would look strange to print them inside-out.
2098 Returns the string length, and stores the contents indirectly through
2099 PSTR, if that variable is non-null. The string may be overwritten by
2100 subsequent calls. */
2103 overlay_strings (pos
, w
, pstr
)
2106 unsigned char **pstr
;
2108 Lisp_Object ov
, overlay
, window
, str
;
2109 int startpos
, endpos
;
2111 overlay_heads
.used
= overlay_heads
.bytes
= 0;
2112 overlay_tails
.used
= overlay_tails
.bytes
= 0;
2113 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCONS (ov
)->cdr
)
2115 overlay
= XCONS (ov
)->car
;
2116 if (!OVERLAYP (overlay
))
2119 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2120 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2123 if (endpos
!= pos
&& startpos
!= pos
)
2125 window
= Foverlay_get (overlay
, Qwindow
);
2126 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2129 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2130 record_overlay_string (&overlay_heads
, str
,
2132 ? Foverlay_get (overlay
, Qafter_string
)
2134 Foverlay_get (overlay
, Qpriority
),
2136 else if (endpos
== pos
2137 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2138 record_overlay_string (&overlay_tails
, str
, Qnil
,
2139 Foverlay_get (overlay
, Qpriority
),
2142 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCONS (ov
)->cdr
)
2144 overlay
= XCONS (ov
)->car
;
2145 if (!OVERLAYP (overlay
))
2148 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2149 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2152 if (endpos
!= pos
&& startpos
!= pos
)
2154 window
= Foverlay_get (overlay
, Qwindow
);
2155 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2158 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2159 record_overlay_string (&overlay_heads
, str
,
2161 ? Foverlay_get (overlay
, Qafter_string
)
2163 Foverlay_get (overlay
, Qpriority
),
2165 else if (endpos
== pos
2166 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2167 record_overlay_string (&overlay_tails
, str
, Qnil
,
2168 Foverlay_get (overlay
, Qpriority
),
2171 if (overlay_tails
.used
> 1)
2172 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
2174 if (overlay_heads
.used
> 1)
2175 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
2177 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
2182 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
2184 if (total
> overlay_str_len
)
2185 overlay_str_buf
= (char *)xrealloc (overlay_str_buf
,
2186 overlay_str_len
= total
);
2187 p
= overlay_str_buf
;
2188 for (i
= overlay_tails
.used
; --i
>= 0;)
2190 tem
= overlay_tails
.buf
[i
].string
;
2191 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2192 p
+= XSTRING (tem
)->size
;
2194 for (i
= 0; i
< overlay_heads
.used
; ++i
)
2196 tem
= overlay_heads
.buf
[i
].string
;
2197 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2198 p
+= XSTRING (tem
)->size
;
2199 tem
= overlay_heads
.buf
[i
].string2
;
2202 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2203 p
+= XSTRING (tem
)->size
;
2206 if (p
!= overlay_str_buf
+ total
)
2209 *pstr
= overlay_str_buf
;
2215 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2218 recenter_overlay_lists (buf
, pos
)
2222 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
2224 /* See if anything in overlays_before should move to overlays_after. */
2226 /* We don't strictly need prev in this loop; it should always be nil.
2227 But we use it for symmetry and in case that should cease to be true
2228 with some future change. */
2230 for (tail
= buf
->overlays_before
;
2232 prev
= tail
, tail
= next
)
2234 next
= XCONS (tail
)->cdr
;
2235 overlay
= XCONS (tail
)->car
;
2237 /* If the overlay is not valid, get rid of it. */
2238 if (!OVERLAY_VALID (overlay
))
2243 /* Splice the cons cell TAIL out of overlays_before. */
2245 XCONS (prev
)->cdr
= next
;
2247 buf
->overlays_before
= next
;
2253 beg
= OVERLAY_START (overlay
);
2254 end
= OVERLAY_END (overlay
);
2256 if (OVERLAY_POSITION (end
) > pos
)
2258 /* OVERLAY needs to be moved. */
2259 int where
= OVERLAY_POSITION (beg
);
2260 Lisp_Object other
, other_prev
;
2262 /* Splice the cons cell TAIL out of overlays_before. */
2264 XCONS (prev
)->cdr
= next
;
2266 buf
->overlays_before
= next
;
2268 /* Search thru overlays_after for where to put it. */
2270 for (other
= buf
->overlays_after
;
2272 other_prev
= other
, other
= XCONS (other
)->cdr
)
2274 Lisp_Object otherbeg
, otheroverlay
, follower
;
2277 otheroverlay
= XCONS (other
)->car
;
2278 if (! OVERLAY_VALID (otheroverlay
))
2281 otherbeg
= OVERLAY_START (otheroverlay
);
2282 if (OVERLAY_POSITION (otherbeg
) >= where
)
2286 /* Add TAIL to overlays_after before OTHER. */
2287 XCONS (tail
)->cdr
= other
;
2288 if (!NILP (other_prev
))
2289 XCONS (other_prev
)->cdr
= tail
;
2291 buf
->overlays_after
= tail
;
2295 /* We've reached the things that should stay in overlays_before.
2296 All the rest of overlays_before must end even earlier,
2301 /* See if anything in overlays_after should be in overlays_before. */
2303 for (tail
= buf
->overlays_after
;
2305 prev
= tail
, tail
= next
)
2307 next
= XCONS (tail
)->cdr
;
2308 overlay
= XCONS (tail
)->car
;
2310 /* If the overlay is not valid, get rid of it. */
2311 if (!OVERLAY_VALID (overlay
))
2316 /* Splice the cons cell TAIL out of overlays_after. */
2318 XCONS (prev
)->cdr
= next
;
2320 buf
->overlays_after
= next
;
2326 beg
= OVERLAY_START (overlay
);
2327 end
= OVERLAY_END (overlay
);
2329 /* Stop looking, when we know that nothing further
2330 can possibly end before POS. */
2331 if (OVERLAY_POSITION (beg
) > pos
)
2334 if (OVERLAY_POSITION (end
) <= pos
)
2336 /* OVERLAY needs to be moved. */
2337 int where
= OVERLAY_POSITION (end
);
2338 Lisp_Object other
, other_prev
;
2340 /* Splice the cons cell TAIL out of overlays_after. */
2342 XCONS (prev
)->cdr
= next
;
2344 buf
->overlays_after
= next
;
2346 /* Search thru overlays_before for where to put it. */
2348 for (other
= buf
->overlays_before
;
2350 other_prev
= other
, other
= XCONS (other
)->cdr
)
2352 Lisp_Object otherend
, otheroverlay
;
2355 otheroverlay
= XCONS (other
)->car
;
2356 if (! OVERLAY_VALID (otheroverlay
))
2359 otherend
= OVERLAY_END (otheroverlay
);
2360 if (OVERLAY_POSITION (otherend
) <= where
)
2364 /* Add TAIL to overlays_before before OTHER. */
2365 XCONS (tail
)->cdr
= other
;
2366 if (!NILP (other_prev
))
2367 XCONS (other_prev
)->cdr
= tail
;
2369 buf
->overlays_before
= tail
;
2374 XSETFASTINT (buf
->overlay_center
, pos
);
2378 adjust_overlays_for_insert (pos
, length
)
2382 /* After an insertion, the lists are still sorted properly,
2383 but we may need to update the value of the overlay center. */
2384 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
2385 XSETFASTINT (current_buffer
->overlay_center
,
2386 XFASTINT (current_buffer
->overlay_center
) + length
);
2390 adjust_overlays_for_delete (pos
, length
)
2394 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
2395 /* The deletion was to our right. No change needed; the before- and
2396 after-lists are still consistent. */
2398 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
2399 /* The deletion was to our left. We need to adjust the center value
2400 to account for the change in position, but the lists are consistent
2401 given the new value. */
2402 XSETFASTINT (current_buffer
->overlay_center
,
2403 XFASTINT (current_buffer
->overlay_center
) - length
);
2405 /* We're right in the middle. There might be things on the after-list
2406 that now belong on the before-list. Recentering will move them,
2407 and also update the center point. */
2408 recenter_overlay_lists (current_buffer
, pos
);
2411 /* Fix up overlays that were garbled as a result of permuting markers
2412 in the range START through END. Any overlay with at least one
2413 endpoint in this range will need to be unlinked from the overlay
2414 list and reinserted in its proper place.
2415 Such an overlay might even have negative size at this point.
2416 If so, we'll reverse the endpoints. Can you think of anything
2417 better to do in this situation? */
2419 fix_overlays_in_range (start
, end
)
2420 register int start
, end
;
2422 Lisp_Object tem
, overlay
;
2423 Lisp_Object before_list
, after_list
;
2424 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
2425 int startpos
, endpos
;
2427 /* This algorithm shifts links around instead of consing and GCing.
2428 The loop invariant is that before_list (resp. after_list) is a
2429 well-formed list except that its last element, the one that
2430 *pbefore (resp. *pafter) points to, is still uninitialized.
2431 So it's not a bug that before_list isn't initialized, although
2432 it may look strange. */
2433 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
2435 overlay
= XCONS (*ptail
)->car
;
2436 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2439 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2441 || (startpos
>= start
&& startpos
< end
))
2443 /* If the overlay is backwards, fix that now. */
2444 if (startpos
> endpos
)
2447 Fset_marker (OVERLAY_START (overlay
), endpos
, Qnil
);
2448 Fset_marker (OVERLAY_END (overlay
), startpos
, Qnil
);
2449 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2451 /* Add it to the end of the wrong list. Later on,
2452 recenter_overlay_lists will move it to the right place. */
2453 if (endpos
< XINT (current_buffer
->overlay_center
))
2456 pafter
= &XCONS (*ptail
)->cdr
;
2461 pbefore
= &XCONS (*ptail
)->cdr
;
2463 *ptail
= XCONS (*ptail
)->cdr
;
2466 ptail
= &XCONS (*ptail
)->cdr
;
2468 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
2470 overlay
= XCONS (*ptail
)->car
;
2471 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2472 if (startpos
>= end
)
2474 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2475 if (startpos
>= start
2476 || (endpos
>= start
&& endpos
< end
))
2478 if (startpos
> endpos
)
2481 Fset_marker (OVERLAY_START (overlay
), endpos
, Qnil
);
2482 Fset_marker (OVERLAY_END (overlay
), startpos
, Qnil
);
2483 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2485 if (endpos
< XINT (current_buffer
->overlay_center
))
2488 pafter
= &XCONS (*ptail
)->cdr
;
2493 pbefore
= &XCONS (*ptail
)->cdr
;
2495 *ptail
= XCONS (*ptail
)->cdr
;
2498 ptail
= &XCONS (*ptail
)->cdr
;
2501 /* Splice the constructed (wrong) lists into the buffer's lists,
2502 and let the recenter function make it sane again. */
2503 *pbefore
= current_buffer
->overlays_before
;
2504 current_buffer
->overlays_before
= before_list
;
2505 recenter_overlay_lists (current_buffer
,
2506 XINT (current_buffer
->overlay_center
));
2508 *pafter
= current_buffer
->overlays_after
;
2509 current_buffer
->overlays_after
= after_list
;
2510 recenter_overlay_lists (current_buffer
,
2511 XINT (current_buffer
->overlay_center
));
2514 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
2515 "Return t if OBJECT is an overlay.")
2519 return (OVERLAYP (object
) ? Qt
: Qnil
);
2522 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
2523 "Create a new overlay with range BEG to END in BUFFER.\n\
2524 If omitted, BUFFER defaults to the current buffer.\n\
2525 BEG and END may be integers or markers.\n\
2526 The fourth arg FRONT-ADVANCE, if non-nil, makes the\n\
2527 front delimiter advance when text is inserted there.\n\
2528 The fifth arg REAR-ADVANCE, if non-nil, makes the\n\
2529 rear delimiter advance when text is inserted there.")
2530 (beg
, end
, buffer
, front_advance
, rear_advance
)
2531 Lisp_Object beg
, end
, buffer
;
2532 Lisp_Object front_advance
, rear_advance
;
2534 Lisp_Object overlay
;
2538 XSETBUFFER (buffer
, current_buffer
);
2540 CHECK_BUFFER (buffer
, 2);
2542 && ! EQ (Fmarker_buffer (beg
), buffer
))
2543 error ("Marker points into wrong buffer");
2545 && ! EQ (Fmarker_buffer (end
), buffer
))
2546 error ("Marker points into wrong buffer");
2548 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2549 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2551 if (XINT (beg
) > XINT (end
))
2554 temp
= beg
; beg
= end
; end
= temp
;
2557 b
= XBUFFER (buffer
);
2559 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
2560 end
= Fset_marker (Fmake_marker (), end
, buffer
);
2562 if (!NILP (front_advance
))
2563 XMARKER (beg
)->insertion_type
= 1;
2564 if (!NILP (rear_advance
))
2565 XMARKER (end
)->insertion_type
= 1;
2567 overlay
= allocate_misc ();
2568 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
2569 XOVERLAY (overlay
)->start
= beg
;
2570 XOVERLAY (overlay
)->end
= end
;
2571 XOVERLAY (overlay
)->plist
= Qnil
;
2573 /* Put the new overlay on the wrong list. */
2574 end
= OVERLAY_END (overlay
);
2575 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2576 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2578 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2580 /* This puts it in the right list, and in the right order. */
2581 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2583 /* We don't need to redisplay the region covered by the overlay, because
2584 the overlay has no properties at the moment. */
2589 /* Mark a section of BUF as needing redisplay because of overlays changes. */
2592 modify_overlay (buf
, start
, end
)
2602 start
= end
; end
= temp
;
2605 /* If this is a buffer not in the selected window,
2606 we must do other windows. */
2607 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
2608 windows_or_buffers_changed
= 1;
2609 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2610 else if (buf
!= current_buffer
)
2611 windows_or_buffers_changed
= 1;
2612 /* If multiple windows show this buffer, we must do other windows. */
2613 else if (buffer_shared
> 1)
2614 windows_or_buffers_changed
= 1;
2617 if (unchanged_modified
== MODIFF
2618 && overlay_unchanged_modified
== OVERLAY_MODIFF
)
2620 beg_unchanged
= start
- BEG
;
2621 end_unchanged
= Z
- end
;
2625 if (Z
- end
< end_unchanged
)
2626 end_unchanged
= Z
- end
;
2627 if (start
- BEG
< beg_unchanged
)
2628 beg_unchanged
= start
- BEG
;
2636 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
2637 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
2638 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
2639 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
2641 (overlay
, beg
, end
, buffer
)
2642 Lisp_Object overlay
, beg
, end
, buffer
;
2644 struct buffer
*b
, *ob
;
2645 Lisp_Object obuffer
;
2646 int count
= specpdl_ptr
- specpdl
;
2648 CHECK_OVERLAY (overlay
, 0);
2650 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2652 XSETBUFFER (buffer
, current_buffer
);
2653 CHECK_BUFFER (buffer
, 3);
2656 && ! EQ (Fmarker_buffer (beg
), buffer
))
2657 error ("Marker points into wrong buffer");
2659 && ! EQ (Fmarker_buffer (end
), buffer
))
2660 error ("Marker points into wrong buffer");
2662 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2663 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2665 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
2666 return Fdelete_overlay (overlay
);
2668 if (XINT (beg
) > XINT (end
))
2671 temp
= beg
; beg
= end
; end
= temp
;
2674 specbind (Qinhibit_quit
, Qt
);
2676 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2677 b
= XBUFFER (buffer
);
2678 ob
= XBUFFER (obuffer
);
2680 /* If the overlay has changed buffers, do a thorough redisplay. */
2681 if (!EQ (buffer
, obuffer
))
2683 /* Redisplay where the overlay was. */
2684 if (!NILP (obuffer
))
2689 o_beg
= OVERLAY_START (overlay
);
2690 o_end
= OVERLAY_END (overlay
);
2691 o_beg
= OVERLAY_POSITION (o_beg
);
2692 o_end
= OVERLAY_POSITION (o_end
);
2694 modify_overlay (ob
, XINT (o_beg
), XINT (o_end
));
2697 /* Redisplay where the overlay is going to be. */
2698 modify_overlay (b
, XINT (beg
), XINT (end
));
2701 /* Redisplay the area the overlay has just left, or just enclosed. */
2705 int change_beg
, change_end
;
2707 o_beg
= OVERLAY_START (overlay
);
2708 o_end
= OVERLAY_END (overlay
);
2709 o_beg
= OVERLAY_POSITION (o_beg
);
2710 o_end
= OVERLAY_POSITION (o_end
);
2712 if (XINT (o_beg
) == XINT (beg
))
2713 modify_overlay (b
, XINT (o_end
), XINT (end
));
2714 else if (XINT (o_end
) == XINT (end
))
2715 modify_overlay (b
, XINT (o_beg
), XINT (beg
));
2718 if (XINT (beg
) < XINT (o_beg
)) o_beg
= beg
;
2719 if (XINT (end
) > XINT (o_end
)) o_end
= end
;
2720 modify_overlay (b
, XINT (o_beg
), XINT (o_end
));
2724 if (!NILP (obuffer
))
2726 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
2727 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
2730 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
2731 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
2733 /* Put the overlay on the wrong list. */
2734 end
= OVERLAY_END (overlay
);
2735 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2736 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2738 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2740 /* This puts it in the right list, and in the right order. */
2741 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2743 return unbind_to (count
, overlay
);
2746 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
2747 "Delete the overlay OVERLAY from its buffer.")
2749 Lisp_Object overlay
;
2753 int count
= specpdl_ptr
- specpdl
;
2755 CHECK_OVERLAY (overlay
, 0);
2757 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2761 b
= XBUFFER (buffer
);
2763 specbind (Qinhibit_quit
, Qt
);
2765 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
2766 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
2769 marker_position (OVERLAY_START (overlay
)),
2770 marker_position (OVERLAY_END (overlay
)));
2772 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
2773 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
2775 return unbind_to (count
, Qnil
);
2778 /* Overlay dissection functions. */
2780 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
2781 "Return the position at which OVERLAY starts.")
2783 Lisp_Object overlay
;
2785 CHECK_OVERLAY (overlay
, 0);
2787 return (Fmarker_position (OVERLAY_START (overlay
)));
2790 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
2791 "Return the position at which OVERLAY ends.")
2793 Lisp_Object overlay
;
2795 CHECK_OVERLAY (overlay
, 0);
2797 return (Fmarker_position (OVERLAY_END (overlay
)));
2800 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
2801 "Return the buffer OVERLAY belongs to.")
2803 Lisp_Object overlay
;
2805 CHECK_OVERLAY (overlay
, 0);
2807 return Fmarker_buffer (OVERLAY_START (overlay
));
2810 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
2811 "Return a list of the properties on OVERLAY.\n\
2812 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
2815 Lisp_Object overlay
;
2817 CHECK_OVERLAY (overlay
, 0);
2819 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
2823 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
2824 "Return a list of the overlays that contain position POS.")
2829 Lisp_Object
*overlay_vec
;
2833 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2836 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2838 /* Put all the overlays we want in a vector in overlay_vec.
2839 Store the length in len. */
2840 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2841 (int *) 0, (int *) 0);
2843 /* Make a list of them all. */
2844 result
= Flist (noverlays
, overlay_vec
);
2846 xfree (overlay_vec
);
2850 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
2851 "Return a list of the overlays that overlap the region BEG ... END.\n\
2852 Overlap means that at least one character is contained within the overlay\n\
2853 and also contained within the specified region.\n\
2854 Empty overlays are included in the result if they are located at BEG\n\
2855 or between BEG and END.")
2857 Lisp_Object beg
, end
;
2860 Lisp_Object
*overlay_vec
;
2864 CHECK_NUMBER_COERCE_MARKER (beg
, 0);
2865 CHECK_NUMBER_COERCE_MARKER (end
, 0);
2868 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2870 /* Put all the overlays we want in a vector in overlay_vec.
2871 Store the length in len. */
2872 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
2873 (int *) 0, (int *) 0);
2875 /* Make a list of them all. */
2876 result
= Flist (noverlays
, overlay_vec
);
2878 xfree (overlay_vec
);
2882 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
2884 "Return the next position after POS where an overlay starts or ends.\n\
2885 If there are no more overlay boundaries after POS, return (point-max).")
2891 Lisp_Object
*overlay_vec
;
2895 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2898 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2900 /* Put all the overlays we want in a vector in overlay_vec.
2901 Store the length in len.
2902 endpos gets the position where the next overlay starts. */
2903 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2904 &endpos
, (int *) 0);
2906 /* If any of these overlays ends before endpos,
2907 use its ending point instead. */
2908 for (i
= 0; i
< noverlays
; i
++)
2913 oend
= OVERLAY_END (overlay_vec
[i
]);
2914 oendpos
= OVERLAY_POSITION (oend
);
2915 if (oendpos
< endpos
)
2919 xfree (overlay_vec
);
2920 return make_number (endpos
);
2923 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
2924 Sprevious_overlay_change
, 1, 1, 0,
2925 "Return the previous position before POS where an overlay starts or ends.\n\
2926 If there are no more overlay boundaries before POS, return (point-min).")
2932 Lisp_Object
*overlay_vec
;
2937 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2940 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2942 /* At beginning of buffer, we know the answer;
2943 avoid bug subtracting 1 below. */
2944 if (XINT (pos
) == BEGV
)
2947 /* Put all the overlays we want in a vector in overlay_vec.
2948 Store the length in len.
2949 prevpos gets the position of an overlay end. */
2950 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2951 (int *) 0, &prevpos
);
2953 /* If any of these overlays starts after prevpos,
2954 maybe use its starting point instead. */
2955 for (i
= 0; i
< noverlays
; i
++)
2960 ostart
= OVERLAY_START (overlay_vec
[i
]);
2961 ostartpos
= OVERLAY_POSITION (ostart
);
2962 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
2963 prevpos
= ostartpos
;
2966 /* If any overlay ends at pos, consider its starting point too. */
2967 for (tail
= current_buffer
->overlays_before
;
2969 tail
= XCONS (tail
)->cdr
)
2971 Lisp_Object overlay
, ostart
;
2974 overlay
= XCONS (tail
)->car
;
2976 ostart
= OVERLAY_START (overlay
);
2977 ostartpos
= OVERLAY_POSITION (ostart
);
2978 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
2979 prevpos
= ostartpos
;
2982 xfree (overlay_vec
);
2983 return make_number (prevpos
);
2986 /* These functions are for debugging overlays. */
2988 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
2989 "Return a pair of lists giving all the overlays of the current buffer.\n\
2990 The car has all the overlays before the overlay center;\n\
2991 the cdr has all the overlays after the overlay center.\n\
2992 Recentering overlays moves overlays between these lists.\n\
2993 The lists you get are copies, so that changing them has no effect.\n\
2994 However, the overlays you get are the real objects that the buffer uses.")
2997 Lisp_Object before
, after
;
2998 before
= current_buffer
->overlays_before
;
3000 before
= Fcopy_sequence (before
);
3001 after
= current_buffer
->overlays_after
;
3003 after
= Fcopy_sequence (after
);
3005 return Fcons (before
, after
);
3008 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
3009 "Recenter the overlays of the current buffer around position POS.")
3013 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3015 recenter_overlay_lists (current_buffer
, XINT (pos
));
3019 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
3020 "Get the property of overlay OVERLAY with property name PROP.")
3022 Lisp_Object overlay
, prop
;
3024 Lisp_Object plist
, fallback
;
3026 CHECK_OVERLAY (overlay
, 0);
3030 for (plist
= XOVERLAY (overlay
)->plist
;
3031 CONSP (plist
) && CONSP (XCONS (plist
)->cdr
);
3032 plist
= XCONS (XCONS (plist
)->cdr
)->cdr
)
3034 if (EQ (XCONS (plist
)->car
, prop
))
3035 return XCONS (XCONS (plist
)->cdr
)->car
;
3036 else if (EQ (XCONS (plist
)->car
, Qcategory
))
3039 tem
= Fcar (Fcdr (plist
));
3041 fallback
= Fget (tem
, prop
);
3048 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
3049 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
3050 (overlay
, prop
, value
)
3051 Lisp_Object overlay
, prop
, value
;
3053 Lisp_Object tail
, buffer
;
3056 CHECK_OVERLAY (overlay
, 0);
3058 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3060 for (tail
= XOVERLAY (overlay
)->plist
;
3061 CONSP (tail
) && CONSP (XCONS (tail
)->cdr
);
3062 tail
= XCONS (XCONS (tail
)->cdr
)->cdr
)
3063 if (EQ (XCONS (tail
)->car
, prop
))
3065 changed
= !EQ (XCONS (XCONS (tail
)->cdr
)->car
, value
);
3066 XCONS (XCONS (tail
)->cdr
)->car
= value
;
3069 /* It wasn't in the list, so add it to the front. */
3070 changed
= !NILP (value
);
3071 XOVERLAY (overlay
)->plist
3072 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
3074 if (! NILP (buffer
))
3077 modify_overlay (XBUFFER (buffer
),
3078 marker_position (OVERLAY_START (overlay
)),
3079 marker_position (OVERLAY_END (overlay
)));
3080 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
3081 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
3082 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
3083 Fdelete_overlay (overlay
);
3088 /* Subroutine of report_overlay_modification. */
3090 /* Lisp vector holding overlay hook functions to call.
3091 Vector elements come in pairs.
3092 Each even-index element is a list of hook functions.
3093 The following odd-index element is the overlay they came from.
3095 Before the buffer change, we fill in this vector
3096 as we call overlay hook functions.
3097 After the buffer change, we get the functions to call from this vector.
3098 This way we always call the same functions before and after the change. */
3099 static Lisp_Object last_overlay_modification_hooks
;
3101 /* Number of elements actually used in last_overlay_modification_hooks. */
3102 static int last_overlay_modification_hooks_used
;
3104 /* Add one functionlist/overlay pair
3105 to the end of last_overlay_modification_hooks. */
3108 add_overlay_mod_hooklist (functionlist
, overlay
)
3109 Lisp_Object functionlist
, overlay
;
3111 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
3113 if (last_overlay_modification_hooks_used
== oldsize
)
3116 old
= last_overlay_modification_hooks
;
3117 last_overlay_modification_hooks
3118 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
3119 bcopy (XVECTOR (old
)->contents
,
3120 XVECTOR (last_overlay_modification_hooks
)->contents
,
3121 sizeof (Lisp_Object
) * oldsize
);
3123 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = functionlist
;
3124 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = overlay
;
3127 /* Run the modification-hooks of overlays that include
3128 any part of the text in START to END.
3129 If this change is an insertion, also
3130 run the insert-before-hooks of overlay starting at END,
3131 and the insert-after-hooks of overlay ending at START.
3133 This is called both before and after the modification.
3134 AFTER is nonzero when we call after the modification.
3136 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3137 When AFTER is nonzero, they are the start position,
3138 the position after the inserted new text,
3139 and the length of deleted or replaced old text. */
3142 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
3143 Lisp_Object start
, end
;
3145 Lisp_Object arg1
, arg2
, arg3
;
3147 Lisp_Object prop
, overlay
, tail
;
3148 /* 1 if this change is an insertion. */
3149 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
3151 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
3155 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
3159 /* Call the functions recorded in last_overlay_modification_hooks
3160 rather than scanning the overlays again.
3161 First copy the vector contents, in case some of these hooks
3162 do subsequent modification of the buffer. */
3163 int size
= last_overlay_modification_hooks_used
;
3164 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
3167 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
3168 copy
, size
* sizeof (Lisp_Object
));
3170 gcpro1
.nvars
= size
;
3172 for (i
= 0; i
< size
;)
3174 Lisp_Object prop
, overlay
;
3176 overlay
= copy
[i
++];
3177 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3183 /* We are being called before a change.
3184 Scan the overlays to find the functions to call. */
3185 last_overlay_modification_hooks_used
= 0;
3187 for (tail
= current_buffer
->overlays_before
;
3189 tail
= XCONS (tail
)->cdr
)
3191 int startpos
, endpos
;
3192 Lisp_Object ostart
, oend
;
3194 overlay
= XCONS (tail
)->car
;
3196 ostart
= OVERLAY_START (overlay
);
3197 oend
= OVERLAY_END (overlay
);
3198 endpos
= OVERLAY_POSITION (oend
);
3199 if (XFASTINT (start
) > endpos
)
3201 startpos
= OVERLAY_POSITION (ostart
);
3202 if (insertion
&& (XFASTINT (start
) == startpos
3203 || XFASTINT (end
) == startpos
))
3205 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3208 /* Copy TAIL in case the hook recenters the overlay lists. */
3210 tail
= Fcopy_sequence (tail
);
3212 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3215 if (insertion
&& (XFASTINT (start
) == endpos
3216 || XFASTINT (end
) == endpos
))
3218 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3222 tail
= Fcopy_sequence (tail
);
3224 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3227 /* Test for intersecting intervals. This does the right thing
3228 for both insertion and deletion. */
3229 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3231 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3235 tail
= Fcopy_sequence (tail
);
3237 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3243 for (tail
= current_buffer
->overlays_after
;
3245 tail
= XCONS (tail
)->cdr
)
3247 int startpos
, endpos
;
3248 Lisp_Object ostart
, oend
;
3250 overlay
= XCONS (tail
)->car
;
3252 ostart
= OVERLAY_START (overlay
);
3253 oend
= OVERLAY_END (overlay
);
3254 startpos
= OVERLAY_POSITION (ostart
);
3255 endpos
= OVERLAY_POSITION (oend
);
3256 if (XFASTINT (end
) < startpos
)
3258 if (insertion
&& (XFASTINT (start
) == startpos
3259 || XFASTINT (end
) == startpos
))
3261 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3265 tail
= Fcopy_sequence (tail
);
3267 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3270 if (insertion
&& (XFASTINT (start
) == endpos
3271 || XFASTINT (end
) == endpos
))
3273 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3277 tail
= Fcopy_sequence (tail
);
3279 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3282 /* Test for intersecting intervals. This does the right thing
3283 for both insertion and deletion. */
3284 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3286 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3290 tail
= Fcopy_sequence (tail
);
3292 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3301 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
3302 Lisp_Object list
, overlay
;
3304 Lisp_Object arg1
, arg2
, arg3
;
3306 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3308 GCPRO4 (list
, arg1
, arg2
, arg3
);
3310 add_overlay_mod_hooklist (list
, overlay
);
3312 while (!NILP (list
))
3315 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
3317 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
3323 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3326 evaporate_overlays (pos
)
3329 Lisp_Object tail
, overlay
, hit_list
;
3332 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
3333 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
3334 tail
= XCONS (tail
)->cdr
)
3337 overlay
= XCONS (tail
)->car
;
3338 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3341 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
3342 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3343 hit_list
= Fcons (overlay
, hit_list
);
3346 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
3347 tail
= XCONS (tail
)->cdr
)
3350 overlay
= XCONS (tail
)->car
;
3351 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3354 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
3355 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3356 hit_list
= Fcons (overlay
, hit_list
);
3358 for (; CONSP (hit_list
); hit_list
= XCONS (hit_list
)->cdr
)
3359 Fdelete_overlay (XCONS (hit_list
)->car
);
3362 /* Somebody has tried to store a value with an unacceptable type
3363 into the buffer-local slot with offset OFFSET. */
3365 buffer_slot_type_mismatch (offset
)
3370 sym
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
);
3371 switch (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
)))
3373 case Lisp_Int
: type_name
= "integers"; break;
3374 case Lisp_String
: type_name
= "strings"; break;
3375 case Lisp_Symbol
: type_name
= "symbols"; break;
3380 error ("only %s should be stored in the buffer-local variable %s",
3381 type_name
, XSYMBOL (sym
)->name
->data
);
3386 register Lisp_Object tem
;
3388 buffer_permanent_local_flags
= 0;
3390 /* Make sure all markable slots in buffer_defaults
3391 are initialized reasonably, so mark_buffer won't choke. */
3392 reset_buffer (&buffer_defaults
);
3393 reset_buffer_local_variables (&buffer_defaults
, 1);
3394 reset_buffer (&buffer_local_symbols
);
3395 reset_buffer_local_variables (&buffer_local_symbols
, 1);
3396 /* Prevent GC from getting confused. */
3397 buffer_defaults
.text
= &buffer_defaults
.own_text
;
3398 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
3399 #ifdef USE_TEXT_PROPERTIES
3400 BUF_INTERVALS (&buffer_defaults
) = 0;
3401 BUF_INTERVALS (&buffer_local_symbols
) = 0;
3403 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
3404 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
3406 /* Set up the default values of various buffer slots. */
3407 /* Must do these before making the first buffer! */
3409 /* real setup is done in loaddefs.el */
3410 buffer_defaults
.mode_line_format
= build_string ("%-");
3411 buffer_defaults
.abbrev_mode
= Qnil
;
3412 buffer_defaults
.overwrite_mode
= Qnil
;
3413 buffer_defaults
.case_fold_search
= Qt
;
3414 buffer_defaults
.auto_fill_function
= Qnil
;
3415 buffer_defaults
.selective_display
= Qnil
;
3417 buffer_defaults
.selective_display_ellipses
= Qt
;
3419 buffer_defaults
.abbrev_table
= Qnil
;
3420 buffer_defaults
.display_table
= Qnil
;
3421 buffer_defaults
.undo_list
= Qnil
;
3422 buffer_defaults
.mark_active
= Qnil
;
3423 buffer_defaults
.file_format
= Qnil
;
3424 buffer_defaults
.overlays_before
= Qnil
;
3425 buffer_defaults
.overlays_after
= Qnil
;
3426 XSETFASTINT (buffer_defaults
.overlay_center
, BEG
);
3428 XSETFASTINT (buffer_defaults
.tab_width
, 8);
3429 buffer_defaults
.truncate_lines
= Qnil
;
3430 buffer_defaults
.ctl_arrow
= Qt
;
3433 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
3435 XSETFASTINT (buffer_defaults
.fill_column
, 70);
3436 XSETFASTINT (buffer_defaults
.left_margin
, 0);
3437 buffer_defaults
.cache_long_line_scans
= Qnil
;
3438 buffer_defaults
.file_truename
= Qnil
;
3440 /* Assign the local-flags to the slots that have default values.
3441 The local flag is a bit that is used in the buffer
3442 to say that it has its own local value for the slot.
3443 The local flag bits are in the local_var_flags slot of the buffer. */
3445 /* Nothing can work if this isn't true */
3446 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
3448 /* 0 means not a lisp var, -1 means always local, else mask */
3449 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
3450 XSETINT (buffer_local_flags
.filename
, -1);
3451 XSETINT (buffer_local_flags
.directory
, -1);
3452 XSETINT (buffer_local_flags
.backed_up
, -1);
3453 XSETINT (buffer_local_flags
.save_length
, -1);
3454 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
3455 XSETINT (buffer_local_flags
.read_only
, -1);
3456 XSETINT (buffer_local_flags
.major_mode
, -1);
3457 XSETINT (buffer_local_flags
.mode_name
, -1);
3458 XSETINT (buffer_local_flags
.undo_list
, -1);
3459 XSETINT (buffer_local_flags
.mark_active
, -1);
3460 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
3461 XSETINT (buffer_local_flags
.file_truename
, -1);
3462 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
3463 XSETINT (buffer_local_flags
.file_format
, -1);
3465 XSETFASTINT (buffer_local_flags
.mode_line_format
, 1);
3466 XSETFASTINT (buffer_local_flags
.abbrev_mode
, 2);
3467 XSETFASTINT (buffer_local_flags
.overwrite_mode
, 4);
3468 XSETFASTINT (buffer_local_flags
.case_fold_search
, 8);
3469 XSETFASTINT (buffer_local_flags
.auto_fill_function
, 0x10);
3470 XSETFASTINT (buffer_local_flags
.selective_display
, 0x20);
3472 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, 0x40);
3474 XSETFASTINT (buffer_local_flags
.tab_width
, 0x80);
3475 XSETFASTINT (buffer_local_flags
.truncate_lines
, 0x100);
3476 XSETFASTINT (buffer_local_flags
.ctl_arrow
, 0x200);
3477 XSETFASTINT (buffer_local_flags
.fill_column
, 0x400);
3478 XSETFASTINT (buffer_local_flags
.left_margin
, 0x800);
3479 XSETFASTINT (buffer_local_flags
.abbrev_table
, 0x1000);
3480 XSETFASTINT (buffer_local_flags
.display_table
, 0x2000);
3482 XSETFASTINT (buffer_local_flags
.buffer_file_type
, 0x4000);
3483 /* Make this one a permanent local. */
3484 buffer_permanent_local_flags
|= 0x4000;
3486 XSETFASTINT (buffer_local_flags
.syntax_table
, 0x8000);
3487 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, 0x10000);
3489 Vbuffer_alist
= Qnil
;
3493 QSFundamental
= build_string ("Fundamental");
3495 Qfundamental_mode
= intern ("fundamental-mode");
3496 buffer_defaults
.major_mode
= Qfundamental_mode
;
3498 Qmode_class
= intern ("mode-class");
3500 Qprotected_field
= intern ("protected-field");
3502 Qpermanent_local
= intern ("permanent-local");
3504 Qkill_buffer_hook
= intern ("kill-buffer-hook");
3506 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
3508 /* super-magic invisible buffer */
3509 Vbuffer_alist
= Qnil
;
3511 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3516 char buf
[MAXPATHLEN
+1];
3518 struct stat dotstat
, pwdstat
;
3522 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3524 /* If PWD is accurate, use it instead of calling getwd. This is faster
3525 when PWD is right, and may avoid a fatal error. */
3526 if ((pwd
= getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd
)
3527 && stat (pwd
, &pwdstat
) == 0
3528 && stat (".", &dotstat
) == 0
3529 && dotstat
.st_ino
== pwdstat
.st_ino
3530 && dotstat
.st_dev
== pwdstat
.st_dev
3531 && strlen (pwd
) < MAXPATHLEN
)
3533 else if (getwd (buf
) == 0)
3534 fatal ("`getwd' failed: %s\n", buf
);
3537 /* Maybe this should really use some standard subroutine
3538 whose definition is filename syntax dependent. */
3540 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
3542 buf
[rc
] = DIRECTORY_SEP
;
3545 #endif /* not VMS */
3546 current_buffer
->directory
= build_string (buf
);
3548 temp
= get_minibuffer (0);
3549 XBUFFER (temp
)->directory
= current_buffer
->directory
;
3552 /* initialize the buffer routines */
3555 extern Lisp_Object Qdisabled
;
3557 staticpro (&last_overlay_modification_hooks
);
3558 last_overlay_modification_hooks
3559 = Fmake_vector (make_number (10), Qnil
);
3561 staticpro (&Vbuffer_defaults
);
3562 staticpro (&Vbuffer_local_symbols
);
3563 staticpro (&Qfundamental_mode
);
3564 staticpro (&Qmode_class
);
3565 staticpro (&QSFundamental
);
3566 staticpro (&Vbuffer_alist
);
3567 staticpro (&Qprotected_field
);
3568 staticpro (&Qpermanent_local
);
3569 staticpro (&Qkill_buffer_hook
);
3570 Qoverlayp
= intern ("overlayp");
3571 staticpro (&Qoverlayp
);
3572 Qevaporate
= intern ("evaporate");
3573 staticpro (&Qevaporate
);
3574 Qmodification_hooks
= intern ("modification-hooks");
3575 staticpro (&Qmodification_hooks
);
3576 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
3577 staticpro (&Qinsert_in_front_hooks
);
3578 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
3579 staticpro (&Qinsert_behind_hooks
);
3580 Qget_file_buffer
= intern ("get-file-buffer");
3581 staticpro (&Qget_file_buffer
);
3582 Qpriority
= intern ("priority");
3583 staticpro (&Qpriority
);
3584 Qwindow
= intern ("window");
3585 staticpro (&Qwindow
);
3586 Qbefore_string
= intern ("before-string");
3587 staticpro (&Qbefore_string
);
3588 Qafter_string
= intern ("after-string");
3589 staticpro (&Qafter_string
);
3590 Qfirst_change_hook
= intern ("first-change-hook");
3591 staticpro (&Qfirst_change_hook
);
3592 Qbefore_change_functions
= intern ("before-change-functions");
3593 staticpro (&Qbefore_change_functions
);
3594 Qafter_change_functions
= intern ("after-change-functions");
3595 staticpro (&Qafter_change_functions
);
3597 Fput (Qprotected_field
, Qerror_conditions
,
3598 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
3599 Fput (Qprotected_field
, Qerror_message
,
3600 build_string ("Attempt to modify a protected field"));
3602 /* All these use DEFVAR_LISP_NOPRO because the slots in
3603 buffer_defaults will all be marked via Vbuffer_defaults. */
3605 DEFVAR_LISP_NOPRO ("default-mode-line-format",
3606 &buffer_defaults
.mode_line_format
,
3607 "Default value of `mode-line-format' for buffers that don't override it.\n\
3608 This is the same as (default-value 'mode-line-format).");
3610 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
3611 &buffer_defaults
.abbrev_mode
,
3612 "Default value of `abbrev-mode' for buffers that do not override it.\n\
3613 This is the same as (default-value 'abbrev-mode).");
3615 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
3616 &buffer_defaults
.ctl_arrow
,
3617 "Default value of `ctl-arrow' for buffers that do not override it.\n\
3618 This is the same as (default-value 'ctl-arrow).");
3620 DEFVAR_LISP_NOPRO ("default-truncate-lines",
3621 &buffer_defaults
.truncate_lines
,
3622 "Default value of `truncate-lines' for buffers that do not override it.\n\
3623 This is the same as (default-value 'truncate-lines).");
3625 DEFVAR_LISP_NOPRO ("default-fill-column",
3626 &buffer_defaults
.fill_column
,
3627 "Default value of `fill-column' for buffers that do not override it.\n\
3628 This is the same as (default-value 'fill-column).");
3630 DEFVAR_LISP_NOPRO ("default-left-margin",
3631 &buffer_defaults
.left_margin
,
3632 "Default value of `left-margin' for buffers that do not override it.\n\
3633 This is the same as (default-value 'left-margin).");
3635 DEFVAR_LISP_NOPRO ("default-tab-width",
3636 &buffer_defaults
.tab_width
,
3637 "Default value of `tab-width' for buffers that do not override it.\n\
3638 This is the same as (default-value 'tab-width).");
3640 DEFVAR_LISP_NOPRO ("default-case-fold-search",
3641 &buffer_defaults
.case_fold_search
,
3642 "Default value of `case-fold-search' for buffers that don't override it.\n\
3643 This is the same as (default-value 'case-fold-search).");
3646 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
3647 &buffer_defaults
.buffer_file_type
,
3648 "Default file type for buffers that do not override it.\n\
3649 This is the same as (default-value 'buffer-file-type).\n\
3650 The file type is nil for text, t for binary.");
3653 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
3656 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
3657 But make-docfile finds it!
3658 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
3660 "Template for displaying mode line for current buffer.\n\
3661 Each buffer has its own value of this variable.\n\
3662 Value may be a string, a symbol or a list or cons cell.\n\
3663 For a symbol, its value is used (but it is ignored if t or nil).\n\
3664 A string appearing directly as the value of a symbol is processed verbatim\n\
3665 in that the %-constructs below are not recognized.\n\
3666 For a list whose car is a symbol, the symbol's value is taken,\n\
3667 and if that is non-nil, the cadr of the list is processed recursively.\n\
3668 Otherwise, the caddr of the list (if there is one) is processed.\n\
3669 For a list whose car is a string or list, each element is processed\n\
3670 recursively and the results are effectively concatenated.\n\
3671 For a list whose car is an integer, the cdr of the list is processed\n\
3672 and padded (if the number is positive) or truncated (if negative)\n\
3673 to the width specified by that number.\n\
3674 A string is printed verbatim in the mode line except for %-constructs:\n\
3675 (%-constructs are allowed when the string is the entire mode-line-format\n\
3676 or when it is found in a cons-cell or a list)\n\
3677 %b -- print buffer name. %f -- print visited file name.\n\
3678 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
3679 % means buffer is read-only and * means it is modified.\n\
3680 For a modified read-only buffer, %* gives % and %+ gives *.\n\
3681 %s -- print process status. %l -- print the current line number.\n\
3682 %c -- print the current column number (this makes editing slower).\n\
3683 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
3684 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
3685 or print Bottom or All.\n\
3686 %n -- print Narrow if appropriate.\n\
3687 %t -- print T if files is text, B if binary.\n\
3688 %[ -- print one [ for each recursive editing level. %] similar.\n\
3689 %% -- print %. %- -- print infinitely many dashes.\n\
3690 Decimal digits after the % specify field width to which to pad.");
3693 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
3694 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
3695 nil here means use current buffer's major mode.");
3697 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
3698 make_number (Lisp_Symbol
),
3699 "Symbol for current buffer's major mode.");
3701 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
3702 make_number (Lisp_String
),
3703 "Pretty name of current buffer's major mode (a string).");
3705 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
3706 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
3707 Automatically becomes buffer-local when set in any fashion.");
3709 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
3711 "*Non-nil if searches should ignore case.\n\
3712 Automatically becomes buffer-local when set in any fashion.");
3714 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
3715 make_number (Lisp_Int
),
3716 "*Column beyond which automatic line-wrapping should happen.\n\
3717 Automatically becomes buffer-local when set in any fashion.");
3719 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
3720 make_number (Lisp_Int
),
3721 "*Column for the default indent-line-function to indent to.\n\
3722 Linefeed indents to this column in Fundamental mode.\n\
3723 Automatically becomes buffer-local when set in any fashion.");
3725 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
3726 make_number (Lisp_Int
),
3727 "*Distance between tab stops (for display of tab characters), in columns.\n\
3728 Automatically becomes buffer-local when set in any fashion.");
3730 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
3731 "*Non-nil means display control chars with uparrow.\n\
3732 Nil means use backslash and octal digits.\n\
3733 Automatically becomes buffer-local when set in any fashion.\n\
3734 This variable does not apply to characters whose display is specified\n\
3735 in the current display table (if there is one).");
3737 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
3738 "*Non-nil means do not display continuation lines;\n\
3739 give each line of text one screen line.\n\
3740 Automatically becomes buffer-local when set in any fashion.\n\
3742 Note that this is overridden by the variable\n\
3743 `truncate-partial-width-windows' if that variable is non-nil\n\
3744 and this buffer is not full-frame width.");
3747 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
3749 "Non-nil if the visited file is a binary file.\n\
3750 This variable is meaningful on MS-DOG and Windows NT.\n\
3751 On those systems, it is automatically local in every buffer.\n\
3752 On other systems, this variable is normally always nil.");
3755 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
3756 make_number (Lisp_String
),
3757 "Name of default directory of current buffer. Should end with slash.\n\
3758 Each buffer has its own value of this variable.");
3760 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
3762 "Function called (if non-nil) to perform auto-fill.\n\
3763 It is called after self-inserting a space or newline.\n\
3764 Each buffer has its own value of this variable.\n\
3765 NOTE: This variable is not a hook;\n\
3766 its value may not be a list of functions.");
3768 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
3769 make_number (Lisp_String
),
3770 "Name of file visited in current buffer, or nil if not visiting a file.\n\
3771 Each buffer has its own value of this variable.");
3773 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
3774 make_number (Lisp_String
),
3775 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
3776 The truename of a file is calculated by `file-truename'\n\
3777 and then abbreviated with `abbreviate-file-name'.\n\
3778 Each buffer has its own value of this variable.");
3780 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
3781 ¤t_buffer
->auto_save_file_name
,
3782 make_number (Lisp_String
),
3783 "Name of file for auto-saving current buffer,\n\
3784 or nil if buffer should not be auto-saved.\n\
3785 Each buffer has its own value of this variable.");
3787 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
3788 "Non-nil if this buffer is read-only.\n\
3789 Each buffer has its own value of this variable.");
3791 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
3792 "Non-nil if this buffer's file has been backed up.\n\
3793 Backing up is done before the first time the file is saved.\n\
3794 Each buffer has its own value of this variable.");
3796 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
3797 make_number (Lisp_Int
),
3798 "Length of current buffer when last read in, saved or auto-saved.\n\
3800 Each buffer has its own value of this variable.");
3802 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
3804 "Non-nil enables selective display:\n\
3805 Integer N as value means display only lines\n\
3806 that start with less than n columns of space.\n\
3807 A value of t means, after a ^M, all the rest of the line is invisible.\n\
3808 Then ^M's in the file are written into files as newlines.\n\n\
3809 Automatically becomes buffer-local when set in any fashion.");
3812 DEFVAR_PER_BUFFER ("selective-display-ellipses",
3813 ¤t_buffer
->selective_display_ellipses
,
3815 "t means display ... on previous line when a line is invisible.\n\
3816 Automatically becomes buffer-local when set in any fashion.");
3819 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
3820 "Non-nil if self-insertion should replace existing text.\n\
3821 The value should be one of `overwrite-mode-textual',\n\
3822 `overwrite-mode-binary', or nil.\n\
3823 If it is `overwrite-mode-textual', self-insertion still\n\
3824 inserts at the end of a line, and inserts when point is before a tab,\n\
3825 until the tab is filled in.\n\
3826 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
3827 Automatically becomes buffer-local when set in any fashion.");
3829 #if 0 /* The doc string is too long for some compilers,
3830 but make-docfile can find it in this comment. */
3831 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
3833 "Display table that controls display of the contents of current buffer.\n\
3834 Automatically becomes buffer-local when set in any fashion.\n\
3835 The display table is a char-table created with `make-display-table'.\n\
3836 The ordinary char-table elements control how to display each possible text\n\
3837 character. Each value should be a vector of characters or nil;\n\
3838 nil means display the character in the default fashion.\n\
3839 There are six extra slots to control the display of\n\
3840 the end of a truncated screen line (extra-slot 0, a single character);\n\
3841 the end of a continued line (extra-slot 1, a single character);\n\
3842 the escape character used to display character codes in octal\n\
3843 (extra-slot 2, a single character);\n\
3844 the character used as an arrow for control characters (extra-slot 3,\n\
3845 a single character);\n\
3846 the decoration indicating the presence of invisible lines (extra-slot 4,\n\
3847 a vector of characters);\n\
3848 the character used to draw the border between side-by-side windows\n\
3849 (extra-slot 5, a single character).\n\
3850 See also the functions `display-table-slot' and `set-display-table-slot'.\n\
3851 If this variable is nil, the value of `standard-display-table' is used.\n\
3852 Each window can have its own, overriding display table.");
3854 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
3857 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
3860 DEFVAR_LISP ("before-change-function", &Vbefore_change_function
,
3861 "If non-nil, a function to call before each text change (obsolete).\n\
3862 Two arguments are passed to the function: the positions of\n\
3863 the beginning and end of the range of old text to be changed.\n\
3864 \(For an insertion, the beginning and end are at the same place.)\n\
3865 No information is given about the length of the text after the change.\n\
3867 Buffer changes made while executing the `before-change-function'\n\
3868 don't call any before-change or after-change functions.\n\
3869 That's because these variables are temporarily set to nil.\n\
3870 As a result, a hook function cannot straightforwardly alter the value of\n\
3871 these variables. See the Emacs Lisp manual for a way of\n\
3872 accomplishing an equivalent result by using other variables.\n\n\
3873 This variable is obsolete; use `before-change-functions' instead.");
3874 Vbefore_change_function
= Qnil
;
3876 DEFVAR_LISP ("after-change-function", &Vafter_change_function
,
3877 "If non-nil, a Function to call after each text change (obsolete).\n\
3878 Three arguments are passed to the function: the positions of\n\
3879 the beginning and end of the range of changed text,\n\
3880 and the length of the pre-change text replaced by that range.\n\
3881 \(For an insertion, the pre-change length is zero;\n\
3882 for a deletion, that length is the number of characters deleted,\n\
3883 and the post-change beginning and end are at the same place.)\n\
3885 Buffer changes made while executing the `after-change-function'\n\
3886 don't call any before-change or after-change functions.\n\
3887 That's because these variables are temporarily set to nil.\n\
3888 As a result, a hook function cannot straightforwardly alter the value of\n\
3889 these variables. See the Emacs Lisp manual for a way of\n\
3890 accomplishing an equivalent result by using other variables.\n\n\
3891 This variable is obsolete; use `after-change-functions' instead.");
3892 Vafter_change_function
= Qnil
;
3894 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
3895 "List of functions to call before each text change.\n\
3896 Two arguments are passed to each function: the positions of\n\
3897 the beginning and end of the range of old text to be changed.\n\
3898 \(For an insertion, the beginning and end are at the same place.)\n\
3899 No information is given about the length of the text after the change.\n\
3901 Buffer changes made while executing the `before-change-functions'\n\
3902 don't call any before-change or after-change functions.\n\
3903 That's because these variables are temporarily set to nil.\n\
3904 As a result, a hook function cannot straightforwardly alter the value of\n\
3905 these variables. See the Emacs Lisp manual for a way of\n\
3906 accomplishing an equivalent result by using other variables.");
3907 Vbefore_change_functions
= Qnil
;
3909 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
3910 "List of function to call after each text change.\n\
3911 Three arguments are passed to each function: the positions of\n\
3912 the beginning and end of the range of changed text,\n\
3913 and the length of the pre-change text replaced by that range.\n\
3914 \(For an insertion, the pre-change length is zero;\n\
3915 for a deletion, that length is the number of characters deleted,\n\
3916 and the post-change beginning and end are at the same place.)\n\
3918 Buffer changes made while executing the `after-change-functions'\n\
3919 don't call any before-change or after-change functions.\n\
3920 That's because these variables are temporarily set to nil.\n\
3921 As a result, a hook function cannot straightforwardly alter the value of\n\
3922 these variables. See the Emacs Lisp manual for a way of\n\
3923 accomplishing an equivalent result by using other variables.");
3925 Vafter_change_functions
= Qnil
;
3927 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
3928 "A list of functions to call before changing a buffer which is unmodified.\n\
3929 The functions are run using the `run-hooks' function.");
3930 Vfirst_change_hook
= Qnil
;
3932 #if 0 /* The doc string is too long for some compilers,
3933 but make-docfile can find it in this comment. */
3934 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
3935 "List of undo entries in current buffer.\n\
3936 Recent changes come first; older changes follow newer.\n\
3938 An entry (BEG . END) represents an insertion which begins at\n\
3939 position BEG and ends at position END.\n\
3941 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
3942 from (abs POSITION). If POSITION is positive, point was at the front\n\
3943 of the text being deleted; if negative, point was at the end.\n\
3945 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
3946 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
3947 of the visited file's modification time, as of that time. If the\n\
3948 modification time of the most recent save is different, this entry is\n\
3951 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
3952 was modified between BEG and END. PROPERTY is the property name,\n\
3953 and VALUE is the old value.\n\
3955 An entry (MARKER . DISTANCE) indicates that the marker MARKER\n\
3956 was adjusted in position by the offset DISTANCE (an integer).\n\
3958 An entry of the form POSITION indicates that point was at the buffer\n\
3959 location given by the integer. Undoing an entry of this form places\n\
3960 point at POSITION.\n\
3962 nil marks undo boundaries. The undo command treats the changes\n\
3963 between two undo boundaries as a single step to be undone.\n\
3965 If the value of the variable is t, undo information is not recorded.");
3967 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
3970 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
3971 "Non-nil means the mark and region are currently active in this buffer.\n\
3972 Automatically local in all buffers.");
3974 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
3975 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
3976 This variable is buffer-local, in all buffers.\n\
3978 Normally, the line-motion functions work by scanning the buffer for\n\
3979 newlines. Columnar operations (like move-to-column and\n\
3980 compute-motion) also work by scanning the buffer, summing character\n\
3981 widths as they go. This works well for ordinary text, but if the\n\
3982 buffer's lines are very long (say, more than 500 characters), these\n\
3983 motion functions will take longer to execute. Emacs may also take\n\
3984 longer to update the display.\n\
3986 If cache-long-line-scans is non-nil, these motion functions cache the\n\
3987 results of their scans, and consult the cache to avoid rescanning\n\
3988 regions of the buffer until the text is modified. The caches are most\n\
3989 beneficial when they prevent the most searching---that is, when the\n\
3990 buffer contains long lines and large regions of characters with the\n\
3991 same, fixed screen width.\n\
3993 When cache-long-line-scans is non-nil, processing short lines will\n\
3994 become slightly slower (because of the overhead of consulting the\n\
3995 cache), and the caches will use memory roughly proportional to the\n\
3996 number of newlines and characters whose screen width varies.\n\
3998 The caches require no explicit maintenance; their accuracy is\n\
3999 maintained internally by the Emacs primitives. Enabling or disabling\n\
4000 the cache should not affect the behavior of any of the motion\n\
4001 functions; it should only affect their performance.");
4003 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
4004 "Value of point before the last series of scroll operations, or nil.");
4006 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
4007 "List of formats to use when saving this buffer.\n\
4008 Formats are defined by `format-alist'. This variable is\n\
4009 set when a file is visited. Automatically local in all buffers.");
4011 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
4012 ¤t_buffer
->invisibility_spec
, Qnil
,
4013 "Invisibility spec of this buffer.\n\
4014 The default is t, which means that text is invisible\n\
4015 if it has a non-nil `invisible' property.\n\
4016 If the value is a list, a text character is invisible if its `invisible'\n\
4017 property is an element in that list.\n\
4018 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
4019 then characters with property value PROP are invisible,\n\
4020 and they have an ellipsis as well if ELLIPSIS is non-nil.");
4022 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
4023 "*Non-nil means deactivate the mark when the buffer contents change.");
4024 Vtransient_mark_mode
= Qnil
;
4026 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
4027 "*Non-nil means disregard read-only status of buffers or characters.\n\
4028 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
4029 text properties. If the value is a list, disregard `buffer-read-only'\n\
4030 and disregard a `read-only' text property if the property value\n\
4031 is a member of the list.");
4032 Vinhibit_read_only
= Qnil
;
4034 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
4035 "List of functions called with no args to query before killing a buffer.");
4036 Vkill_buffer_query_functions
= Qnil
;
4038 defsubr (&Sbuffer_live_p
);
4039 defsubr (&Sbuffer_list
);
4040 defsubr (&Sget_buffer
);
4041 defsubr (&Sget_file_buffer
);
4042 defsubr (&Sget_buffer_create
);
4043 defsubr (&Smake_indirect_buffer
);
4044 defsubr (&Sgenerate_new_buffer_name
);
4045 defsubr (&Sbuffer_name
);
4046 /*defsubr (&Sbuffer_number);*/
4047 defsubr (&Sbuffer_file_name
);
4048 defsubr (&Sbuffer_base_buffer
);
4049 defsubr (&Sbuffer_local_variables
);
4050 defsubr (&Sbuffer_modified_p
);
4051 defsubr (&Sset_buffer_modified_p
);
4052 defsubr (&Sbuffer_modified_tick
);
4053 defsubr (&Srename_buffer
);
4054 defsubr (&Sother_buffer
);
4055 defsubr (&Sbuffer_disable_undo
);
4056 defsubr (&Sbuffer_enable_undo
);
4057 defsubr (&Skill_buffer
);
4058 defsubr (&Serase_buffer
);
4059 defsubr (&Sset_buffer_major_mode
);
4060 defsubr (&Sswitch_to_buffer
);
4061 defsubr (&Spop_to_buffer
);
4062 defsubr (&Scurrent_buffer
);
4063 defsubr (&Sset_buffer
);
4064 defsubr (&Sbarf_if_buffer_read_only
);
4065 defsubr (&Sbury_buffer
);
4066 defsubr (&Skill_all_local_variables
);
4068 defsubr (&Soverlayp
);
4069 defsubr (&Smake_overlay
);
4070 defsubr (&Sdelete_overlay
);
4071 defsubr (&Smove_overlay
);
4072 defsubr (&Soverlay_start
);
4073 defsubr (&Soverlay_end
);
4074 defsubr (&Soverlay_buffer
);
4075 defsubr (&Soverlay_properties
);
4076 defsubr (&Soverlays_at
);
4077 defsubr (&Soverlays_in
);
4078 defsubr (&Snext_overlay_change
);
4079 defsubr (&Sprevious_overlay_change
);
4080 defsubr (&Soverlay_recenter
);
4081 defsubr (&Soverlay_lists
);
4082 defsubr (&Soverlay_get
);
4083 defsubr (&Soverlay_put
);
4088 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
4089 initial_define_key (control_x_map
, 'k', "kill-buffer");
4091 /* This must not be in syms_of_buffer, because Qdisabled is not
4092 initialized when that function gets called. */
4093 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);