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, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include <sys/types.h>
24 #include <sys/param.h>
27 /* in 4.1, param.h fails to define this. */
28 #define MAXPATHLEN 1024
29 #endif /* not MAXPATHLEN */
33 #include "intervals.h"
37 #include "region-cache.h"
39 #include "blockinput.h"
41 struct buffer
*current_buffer
; /* the current buffer */
43 /* First buffer in chain of all buffers (in reverse order of creation).
44 Threaded through ->next. */
46 struct buffer
*all_buffers
;
48 /* This structure holds the default values of the buffer-local variables
49 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
50 The default value occupies the same slot in this structure
51 as an individual buffer's value occupies in that buffer.
52 Setting the default value also goes through the alist of buffers
53 and stores into each buffer that does not say it has a local value. */
55 struct buffer buffer_defaults
;
57 /* A Lisp_Object pointer to the above, used for staticpro */
59 static Lisp_Object Vbuffer_defaults
;
61 /* This structure marks which slots in a buffer have corresponding
62 default values in buffer_defaults.
63 Each such slot has a nonzero value in this structure.
64 The value has only one nonzero bit.
66 When a buffer has its own local value for a slot,
67 the bit for that slot (found in the same slot in this structure)
68 is turned on in the buffer's local_var_flags slot.
70 If a slot in this structure is -1, then even though there may
71 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
72 and the corresponding slot in buffer_defaults is not used.
74 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
75 but there is a default value which is copied into each buffer.
77 If a slot in this structure is negative, then even though there may
78 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
79 and the corresponding slot in buffer_defaults is not used.
81 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
82 zero, that is a bug */
84 struct buffer buffer_local_flags
;
86 /* This structure holds the names of symbols whose values may be
87 buffer-local. It is indexed and accessed in the same way as the above. */
89 struct buffer buffer_local_symbols
;
90 /* A Lisp_Object pointer to the above, used for staticpro */
91 static Lisp_Object Vbuffer_local_symbols
;
93 /* This structure holds the required types for the values in the
94 buffer-local slots. If a slot contains Qnil, then the
95 corresponding buffer slot may contain a value of any type. If a
96 slot contains an integer, then prospective values' tags must be
97 equal to that integer. When a tag does not match, the function
98 buffer_slot_type_mismatch will signal an error. */
99 struct buffer buffer_local_types
;
101 Lisp_Object
Fset_buffer ();
102 void set_buffer_internal ();
103 void set_buffer_internal_1 ();
104 static void call_overlay_mod_hooks ();
105 static void swap_out_buffer_local_variables ();
107 /* Alist of all buffer names vs the buffers. */
108 /* This used to be a variable, but is no longer,
109 to prevent lossage due to user rplac'ing this alist or its elements. */
110 Lisp_Object Vbuffer_alist
;
112 /* Functions to call before and after each text change. */
113 Lisp_Object Vbefore_change_function
;
114 Lisp_Object Vafter_change_function
;
115 Lisp_Object Vbefore_change_functions
;
116 Lisp_Object Vafter_change_functions
;
118 Lisp_Object Vtransient_mark_mode
;
120 /* t means ignore all read-only text properties.
121 A list means ignore such a property if its value is a member of the list.
122 Any non-nil value means ignore buffer-read-only. */
123 Lisp_Object Vinhibit_read_only
;
125 /* List of functions to call that can query about killing a buffer.
126 If any of these functions returns nil, we don't kill it. */
127 Lisp_Object Vkill_buffer_query_functions
;
129 /* List of functions to call before changing an unmodified buffer. */
130 Lisp_Object Vfirst_change_hook
;
131 Lisp_Object Qfirst_change_hook
;
133 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
135 Lisp_Object Qprotected_field
;
137 Lisp_Object QSFundamental
; /* A string "Fundamental" */
139 Lisp_Object Qkill_buffer_hook
;
141 Lisp_Object Qget_file_buffer
;
143 Lisp_Object Qoverlayp
;
145 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
147 Lisp_Object Qmodification_hooks
;
148 Lisp_Object Qinsert_in_front_hooks
;
149 Lisp_Object Qinsert_behind_hooks
;
151 /* For debugging; temporary. See set_buffer_internal. */
152 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
158 error ("No buffer named %s", XSTRING (spec
)->data
);
159 error ("Invalid buffer argument");
162 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 0, 0,
163 "Return a list of all existing live buffers.")
166 return Fmapcar (Qcdr
, Vbuffer_alist
);
169 /* Like Fassoc, but use Fstring_equal to compare
170 (which ignores text properties),
171 and don't ever QUIT. */
174 assoc_ignore_text_properties (key
, list
)
175 register Lisp_Object key
;
178 register Lisp_Object tail
;
179 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
181 register Lisp_Object elt
, tem
;
183 tem
= Fstring_equal (Fcar (elt
), key
);
190 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
191 "Return the buffer named NAME (a string).\n\
192 If there is no live buffer named NAME, return nil.\n\
193 NAME may also be a buffer; if so, the value is that buffer.")
195 register Lisp_Object name
;
199 CHECK_STRING (name
, 0);
201 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
204 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
205 "Return the buffer visiting file FILENAME (a string).\n\
206 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
207 If there is no such live buffer, return nil.\n\
208 See also `find-buffer-visiting'.")
210 register Lisp_Object filename
;
212 register Lisp_Object tail
, buf
, tem
;
215 CHECK_STRING (filename
, 0);
216 filename
= Fexpand_file_name (filename
, Qnil
);
218 /* If the file name has special constructs in it,
219 call the corresponding file handler. */
220 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
222 return call2 (handler
, Qget_file_buffer
, filename
);
224 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
226 buf
= Fcdr (XCONS (tail
)->car
);
227 if (!BUFFERP (buf
)) continue;
228 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
229 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
236 /* Incremented for each buffer created, to assign the buffer number. */
239 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
240 "Return the buffer named NAME, or create such a buffer and return it.\n\
241 A new buffer is created if there is no live buffer named NAME.\n\
242 If NAME starts with a space, the new buffer does not keep undo information.\n\
243 If NAME is a buffer instead of a string, then it is the value returned.\n\
244 The value is never nil.")
246 register Lisp_Object name
;
248 register Lisp_Object buf
;
249 register struct buffer
*b
;
251 buf
= Fget_buffer (name
);
255 if (XSTRING (name
)->size
== 0)
256 error ("Empty string for buffer name is not allowed");
258 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
260 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
262 /* An ordinary buffer uses its own struct buffer_text. */
263 b
->text
= &b
->own_text
;
266 BUF_GAP_SIZE (b
) = 20;
268 BUFFER_ALLOC (BUF_BEG_ADDR (b
), BUF_GAP_SIZE (b
));
270 if (! BUF_BEG_ADDR (b
))
271 buffer_memory_full ();
279 BUF_SAVE_MODIFF (b
) = 1;
280 BUF_INTERVALS (b
) = 0;
282 b
->newline_cache
= 0;
283 b
->width_run_cache
= 0;
284 b
->width_table
= Qnil
;
286 /* Put this on the chain of all buffers including killed ones. */
287 b
->next
= all_buffers
;
290 /* An ordinary buffer normally doesn't need markers
291 to handle BEGV and ZV. */
293 b
->begv_marker
= Qnil
;
296 name
= Fcopy_sequence (name
);
297 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
300 if (XSTRING (name
)->data
[0] != ' ')
306 reset_buffer_local_variables (b
);
308 /* Put this in the alist of all live buffers. */
310 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
312 b
->mark
= Fmake_marker ();
313 BUF_MARKERS (b
) = Qnil
;
318 DEFUN ("make-indirect-buffer",
319 Fmake_indirect_buffer
, Smake_indirect_buffer
, 2, 2,
320 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
321 "Create and return an indirect buffer for buffer BASE, named NAME.\n\
322 BASE should be an existing buffer (or buffer name).\n\
323 NAME should be a string which is not the name of an existing buffer.")
325 register Lisp_Object base_buffer
, name
;
327 register Lisp_Object buf
;
328 register struct buffer
*b
;
330 buf
= Fget_buffer (name
);
332 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
334 base_buffer
= Fget_buffer (base_buffer
);
335 if (NILP (base_buffer
))
336 error ("No such buffer: `%s'",
337 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
339 if (XSTRING (name
)->size
== 0)
340 error ("Empty string for buffer name is not allowed");
342 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
344 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
346 if (XBUFFER (base_buffer
)->base_buffer
)
347 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
349 b
->base_buffer
= XBUFFER (base_buffer
);
351 /* Use the base buffer's text object. */
352 b
->text
= b
->base_buffer
->text
;
354 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
355 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
356 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
358 b
->newline_cache
= 0;
359 b
->width_run_cache
= 0;
360 b
->width_table
= Qnil
;
362 /* Put this on the chain of all buffers including killed ones. */
363 b
->next
= all_buffers
;
366 name
= Fcopy_sequence (name
);
367 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
371 reset_buffer_local_variables (b
);
373 /* Put this in the alist of all live buffers. */
375 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
377 b
->mark
= Fmake_marker ();
380 /* Make sure the base buffer has markers for its narrowing. */
381 if (NILP (b
->base_buffer
->pt_marker
))
383 b
->base_buffer
->pt_marker
= Fmake_marker ();
384 Fset_marker (b
->base_buffer
->pt_marker
,
385 make_number (BUF_PT (b
->base_buffer
)), base_buffer
);
387 if (NILP (b
->base_buffer
->begv_marker
))
389 b
->base_buffer
->begv_marker
= Fmake_marker ();
390 Fset_marker (b
->base_buffer
->begv_marker
,
391 make_number (BUF_BEGV (b
->base_buffer
)), base_buffer
);
393 if (NILP (b
->base_buffer
->zv_marker
))
395 b
->base_buffer
->zv_marker
= Fmake_marker ();
396 Fset_marker (b
->base_buffer
->zv_marker
,
397 make_number (BUF_ZV (b
->base_buffer
)), base_buffer
);
400 /* Give the indirect buffer markers for its narrowing. */
401 b
->pt_marker
= Fpoint_marker ();
402 b
->begv_marker
= Fpoint_min_marker ();
403 b
->zv_marker
= Fpoint_max_marker ();
408 /* Reinitialize everything about a buffer except its name and contents
409 and local variables. */
413 register struct buffer
*b
;
416 b
->file_truename
= Qnil
;
417 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
419 XSETFASTINT (b
->save_length
, 0);
420 b
->last_window_start
= 1;
422 b
->auto_save_modified
= 0;
423 b
->auto_save_failure_time
= -1;
424 b
->auto_save_file_name
= Qnil
;
426 b
->overlays_before
= Qnil
;
427 b
->overlays_after
= Qnil
;
428 XSETFASTINT (b
->overlay_center
, 1);
429 b
->mark_active
= Qnil
;
430 b
->point_before_scroll
= Qnil
;
431 b
->file_format
= Qnil
;
434 /* Reset buffer B's local variables info.
435 Don't use this on a buffer that has already been in use;
436 it does not treat permanent locals consistently.
437 Instead, use Fkill_all_local_variables. */
439 reset_buffer_local_variables (b
)
440 register struct buffer
*b
;
444 /* Reset the major mode to Fundamental, together with all the
445 things that depend on the major mode.
446 default-major-mode is handled at a higher level.
447 We ignore it here. */
448 b
->major_mode
= Qfundamental_mode
;
450 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
451 b
->mode_name
= QSFundamental
;
452 b
->minor_modes
= Qnil
;
453 b
->downcase_table
= Vascii_downcase_table
;
454 b
->upcase_table
= Vascii_upcase_table
;
455 b
->case_canon_table
= Vascii_canon_table
;
456 b
->case_eqv_table
= Vascii_eqv_table
;
457 b
->buffer_file_type
= Qnil
;
458 b
->invisibility_spec
= Qt
;
461 b
->sort_table
= XSTRING (Vascii_sort_table
);
462 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
465 /* Reset all per-buffer variables to their defaults. */
466 b
->local_var_alist
= Qnil
;
467 b
->local_var_flags
= 0;
469 /* For each slot that has a default value,
470 copy that into the slot. */
472 for (offset
= (char *)&buffer_local_flags
.name
- (char *)&buffer_local_flags
;
473 offset
< sizeof (struct buffer
);
474 offset
+= sizeof (Lisp_Object
)) /* sizeof EMACS_INT == sizeof Lisp_Object */
476 int flag
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
477 if (flag
> 0 || flag
== -2)
478 *(Lisp_Object
*)(offset
+ (char *)b
) =
479 *(Lisp_Object
*)(offset
+ (char *)&buffer_defaults
);
483 /* We split this away from generate-new-buffer, because rename-buffer
484 and set-visited-file-name ought to be able to use this to really
485 rename the buffer properly. */
487 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
489 "Return a string that is the name of no existing buffer based on NAME.\n\
490 If there is no live buffer named NAME, then return NAME.\n\
491 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
492 until an unused name is found, and then return that name.\n\
493 Optional second argument IGNORE specifies a name that is okay to use\n\
494 \(if it is in the sequence to be tried)\n\
495 even if a buffer with that name exists.")
497 register Lisp_Object name
, ignore
;
499 register Lisp_Object gentemp
, tem
;
503 CHECK_STRING (name
, 0);
505 tem
= Fget_buffer (name
);
512 sprintf (number
, "<%d>", ++count
);
513 gentemp
= concat2 (name
, build_string (number
));
514 tem
= Fstring_equal (gentemp
, ignore
);
517 tem
= Fget_buffer (gentemp
);
524 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
525 "Return the name of BUFFER, as a string.\n\
526 With no argument or nil as argument, return the name of the current buffer.")
528 register Lisp_Object buffer
;
531 return current_buffer
->name
;
532 CHECK_BUFFER (buffer
, 0);
533 return XBUFFER (buffer
)->name
;
536 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
537 "Return name of file BUFFER is visiting, or nil if none.\n\
538 No argument or nil as argument means use the current buffer.")
540 register Lisp_Object buffer
;
543 return current_buffer
->filename
;
544 CHECK_BUFFER (buffer
, 0);
545 return XBUFFER (buffer
)->filename
;
548 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
550 "Return the base buffer of indirect buffer BUFFER.\n\
551 If BUFFER is not indirect, return nil.")
553 register Lisp_Object buffer
;
556 Lisp_Object base_buffer
;
559 base
= current_buffer
->base_buffer
;
562 CHECK_BUFFER (buffer
, 0);
563 base
= XBUFFER (buffer
)->base_buffer
;
568 XSETBUFFER (base_buffer
, base
);
572 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
573 Sbuffer_local_variables
, 0, 1, 0,
574 "Return an alist of variables that are buffer-local in BUFFER.\n\
575 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
576 For a symbol that is locally unbound, just the symbol appears in the value.\n\
577 Note that storing new VALUEs in these elements doesn't change the variables.\n\
578 No argument or nil as argument means use current buffer as BUFFER.")
580 register Lisp_Object buffer
;
582 register struct buffer
*buf
;
583 register Lisp_Object result
;
586 buf
= current_buffer
;
589 CHECK_BUFFER (buffer
, 0);
590 buf
= XBUFFER (buffer
);
596 register Lisp_Object tail
;
597 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
599 Lisp_Object val
, elt
;
601 elt
= XCONS (tail
)->car
;
603 /* Reference each variable in the alist in buf.
604 If inquiring about the current buffer, this gets the current values,
605 so store them into the alist so the alist is up to date.
606 If inquiring about some other buffer, this swaps out any values
607 for that buffer, making the alist up to date automatically. */
608 val
= find_symbol_value (XCONS (elt
)->car
);
609 /* Use the current buffer value only if buf is the current buffer. */
610 if (buf
!= current_buffer
)
611 val
= XCONS (elt
)->cdr
;
613 /* If symbol is unbound, put just the symbol in the list. */
614 if (EQ (val
, Qunbound
))
615 result
= Fcons (XCONS (elt
)->car
, result
);
616 /* Otherwise, put (symbol . value) in the list. */
618 result
= Fcons (Fcons (XCONS (elt
)->car
, val
), result
);
622 /* Add on all the variables stored in special slots. */
624 register int offset
, mask
;
626 for (offset
= (char *)&buffer_local_symbols
.name
- (char *)&buffer_local_symbols
;
627 offset
< sizeof (struct buffer
);
628 offset
+= (sizeof (EMACS_INT
))) /* sizeof EMACS_INT == sizeof Lisp_Object */
630 mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
631 if (mask
== -1 || (buf
->local_var_flags
& mask
))
632 if (SYMBOLP (*(Lisp_Object
*)(offset
633 + (char *)&buffer_local_symbols
)))
634 result
= Fcons (Fcons (*((Lisp_Object
*)
635 (offset
+ (char *)&buffer_local_symbols
)),
636 *(Lisp_Object
*)(offset
+ (char *)buf
)),
645 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
647 "Return t if BUFFER was modified since its file was last read or saved.\n\
648 No argument or nil as argument means use current buffer as BUFFER.")
650 register Lisp_Object buffer
;
652 register struct buffer
*buf
;
654 buf
= current_buffer
;
657 CHECK_BUFFER (buffer
, 0);
658 buf
= XBUFFER (buffer
);
661 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
664 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
666 "Mark current buffer as modified or unmodified according to FLAG.\n\
667 A non-nil FLAG means mark the buffer modified.")
669 register Lisp_Object flag
;
671 register int already
;
672 register Lisp_Object fn
;
674 #ifdef CLASH_DETECTION
675 /* If buffer becoming modified, lock the file.
676 If buffer becoming unmodified, unlock the file. */
678 fn
= current_buffer
->file_truename
;
681 already
= SAVE_MODIFF
< MODIFF
;
682 if (!already
&& !NILP (flag
))
684 else if (already
&& NILP (flag
))
687 #endif /* CLASH_DETECTION */
689 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
694 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
696 "Return BUFFER's tick counter, incremented for each change in text.\n\
697 Each buffer has a tick counter which is incremented each time the text in\n\
698 that buffer is changed. It wraps around occasionally.\n\
699 No argument or nil as argument means use current buffer as BUFFER.")
701 register Lisp_Object buffer
;
703 register struct buffer
*buf
;
705 buf
= current_buffer
;
708 CHECK_BUFFER (buffer
, 0);
709 buf
= XBUFFER (buffer
);
712 return make_number (BUF_MODIFF (buf
));
715 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
716 "sRename buffer (to new name): \nP",
717 "Change current buffer's name to NEWNAME (a string).\n\
718 If second arg UNIQUE is nil or omitted, it is an error if a\n\
719 buffer named NEWNAME already exists.\n\
720 If UNIQUE is non-nil, come up with a new name using\n\
721 `generate-new-buffer-name'.\n\
722 Interactively, you can set UNIQUE with a prefix argument.\n\
723 We return the name we actually gave the buffer.\n\
724 This does not change the name of the visited file (if any).")
726 register Lisp_Object newname
, unique
;
728 register Lisp_Object tem
, buf
;
730 CHECK_STRING (newname
, 0);
732 if (XSTRING (newname
)->size
== 0)
733 error ("Empty string is invalid as a buffer name");
735 tem
= Fget_buffer (newname
);
736 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
737 the buffer automatically so you can create another with the original name.
738 It makes UNIQUE equivalent to
739 (rename-buffer (generate-new-buffer-name NEWNAME)). */
740 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
741 return current_buffer
->name
;
745 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
747 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
750 current_buffer
->name
= newname
;
752 /* Catch redisplay's attention. Unless we do this, the mode lines for
753 any windows displaying current_buffer will stay unchanged. */
756 XSETBUFFER (buf
, current_buffer
);
757 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
758 if (NILP (current_buffer
->filename
)
759 && !NILP (current_buffer
->auto_save_file_name
))
760 call0 (intern ("rename-auto-save-file"));
761 /* Refetch since that last call may have done GC. */
762 return current_buffer
->name
;
765 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 2, 0,
766 "Return most recently selected buffer other than BUFFER.\n\
767 Buffers not visible in windows are preferred to visible buffers,\n\
768 unless optional second argument VISIBLE-OK is non-nil.\n\
769 If no other buffer exists, the buffer `*scratch*' is returned.\n\
770 If BUFFER is omitted or nil, some interesting buffer is returned.")
772 register Lisp_Object buffer
, visible_ok
;
774 register Lisp_Object tail
, buf
, notsogood
, tem
;
777 for (tail
= Vbuffer_alist
; !NILP (tail
); tail
= Fcdr (tail
))
779 buf
= Fcdr (Fcar (tail
));
780 if (EQ (buf
, buffer
))
782 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
785 /* If the selected frame has a buffer_predicate,
786 disregard buffers that don't fit the predicate. */
787 tem
= frame_buffer_predicate ();
790 tem
= call1 (tem
, buf
);
796 if (NILP (visible_ok
))
797 tem
= Fget_buffer_window (buf
, Qt
);
802 if (NILP (notsogood
))
805 if (!NILP (notsogood
))
807 return Fget_buffer_create (build_string ("*scratch*"));
810 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
,
812 "Make BUFFER stop keeping undo information.\n\
813 No argument or nil as argument means do this for the current buffer.")
815 register Lisp_Object buffer
;
817 Lisp_Object real_buffer
;
820 XSETBUFFER (real_buffer
, current_buffer
);
823 real_buffer
= Fget_buffer (buffer
);
824 if (NILP (real_buffer
))
828 XBUFFER (real_buffer
)->undo_list
= Qt
;
833 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
835 "Start keeping undo information for buffer BUFFER.\n\
836 No argument or nil as argument means do this for the current buffer.")
838 register Lisp_Object buffer
;
840 Lisp_Object real_buffer
;
843 XSETBUFFER (real_buffer
, current_buffer
);
846 real_buffer
= Fget_buffer (buffer
);
847 if (NILP (real_buffer
))
851 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
852 XBUFFER (real_buffer
)->undo_list
= Qnil
;
858 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
859 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
860 The buffer being killed will be current while the hook is running.\n\
863 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
864 "Kill the buffer BUFFER.\n\
865 The argument may be a buffer or may be the name of a buffer.\n\
866 An argument of nil means kill the current buffer.\n\n\
867 Value is t if the buffer is actually killed, nil if user says no.\n\n\
868 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
869 if not void, is a list of functions to be called, with no arguments,\n\
870 before the buffer is actually killed. The buffer to be killed is current\n\
871 when the hook functions are called.\n\n\
872 Any processes that have this buffer as the `process-buffer' are killed\n\
873 with `delete-process'.")
878 register struct buffer
*b
;
879 register Lisp_Object tem
;
880 register struct Lisp_Marker
*m
;
881 struct gcpro gcpro1
, gcpro2
;
884 buf
= Fcurrent_buffer ();
886 buf
= Fget_buffer (bufname
);
892 /* Avoid trouble for buffer already dead. */
896 /* Query if the buffer is still modified. */
897 if (INTERACTIVE
&& !NILP (b
->filename
)
898 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
900 GCPRO2 (buf
, bufname
);
901 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
902 XSTRING (b
->name
)->data
));
908 /* Run hooks with the buffer to be killed the current buffer. */
910 register Lisp_Object val
;
911 int count
= specpdl_ptr
- specpdl
;
914 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
915 set_buffer_internal (b
);
917 /* First run the query functions; if any query is answered no,
918 don't kill the buffer. */
919 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
921 tem
= call0 (Fcar (list
));
923 return unbind_to (count
, Qnil
);
926 /* Then run the hooks. */
927 if (!NILP (Vrun_hooks
))
928 call1 (Vrun_hooks
, Qkill_buffer_hook
);
929 unbind_to (count
, Qnil
);
932 /* We have no more questions to ask. Verify that it is valid
933 to kill the buffer. This must be done after the questions
934 since anything can happen within do_yes_or_no_p. */
936 /* Don't kill the minibuffer now current. */
937 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
943 /* When we kill a base buffer, kill all its indirect buffers.
944 We do it at this stage so nothing terrible happens if they
945 ask questions or their hooks get errors. */
946 if (! b
->base_buffer
)
948 struct buffer
*other
;
952 for (other
= all_buffers
; other
; other
= other
->next
)
953 /* all_buffers contains dead buffers too;
954 don't re-kill them. */
955 if (other
->base_buffer
== b
&& !NILP (other
->name
))
958 XSETBUFFER (buf
, other
);
965 /* Make this buffer not be current.
966 In the process, notice if this is the sole visible buffer
967 and give up if so. */
968 if (b
== current_buffer
)
970 tem
= Fother_buffer (buf
, Qnil
);
972 if (b
== current_buffer
)
976 /* Now there is no question: we can kill the buffer. */
978 #ifdef CLASH_DETECTION
979 /* Unlock this buffer's file, if it is locked. */
981 #endif /* CLASH_DETECTION */
983 kill_buffer_processes (buf
);
987 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
988 Freplace_buffer_in_windows (buf
);
991 /* Delete any auto-save file, if we saved it in this session. */
992 if (STRINGP (b
->auto_save_file_name
)
993 && b
->auto_save_modified
!= 0)
996 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
998 internal_delete_file (b
->auto_save_file_name
);
1003 /* Unchain all markers that belong to this indirect buffer.
1004 Don't unchain the markers that belong to the base buffer
1005 or its other indirect buffers. */
1006 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1012 unchain_marker (tem
);
1018 /* Unchain all markers of this buffer and its indirect buffers.
1019 and leave them pointing nowhere. */
1020 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1027 BUF_MARKERS (b
) = Qnil
;
1029 #ifdef USE_TEXT_PROPERTIES
1030 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1033 /* Perhaps we should explicitly free the interval tree here... */
1036 /* Reset the local variables, so that this buffer's local values
1037 won't be protected from GC. They would be protected
1038 if they happened to remain encached in their symbols.
1039 This gets rid of them for certain. */
1040 swap_out_buffer_local_variables (b
);
1041 reset_buffer_local_variables (b
);
1046 if (! b
->base_buffer
)
1047 BUFFER_FREE (BUF_BEG_ADDR (b
));
1049 if (b
->newline_cache
)
1051 free_region_cache (b
->newline_cache
);
1052 b
->newline_cache
= 0;
1054 if (b
->width_run_cache
)
1056 free_region_cache (b
->width_run_cache
);
1057 b
->width_run_cache
= 0;
1059 b
->width_table
= Qnil
;
1061 b
->undo_list
= Qnil
;
1066 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1067 we do this each time BUF is selected visibly, the more recently
1068 selected buffers are always closer to the front of the list. This
1069 means that other_buffer is more likely to choose a relevant buffer. */
1074 register Lisp_Object link
, prev
;
1077 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCONS (link
)->cdr
)
1079 if (EQ (XCONS (XCONS (link
)->car
)->cdr
, buf
))
1084 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1085 we cannot use Fdelq itself here because it allows quitting. */
1088 Vbuffer_alist
= XCONS (Vbuffer_alist
)->cdr
;
1090 XCONS (prev
)->cdr
= XCONS (XCONS (prev
)->cdr
)->cdr
;
1092 XCONS(link
)->cdr
= Vbuffer_alist
;
1093 Vbuffer_alist
= link
;
1096 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1097 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1098 Use this function before selecting the buffer, since it may need to inspect\n\
1099 the current buffer's major mode.")
1104 Lisp_Object function
;
1106 function
= buffer_defaults
.major_mode
;
1107 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1108 function
= current_buffer
->major_mode
;
1110 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1113 count
= specpdl_ptr
- specpdl
;
1115 /* To select a nonfundamental mode,
1116 select the buffer temporarily and then call the mode function. */
1118 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1123 return unbind_to (count
, Qnil
);
1126 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1127 "Select buffer BUFFER in the current window.\n\
1128 BUFFER may be a buffer or a buffer name.\n\
1129 Optional second arg NORECORD non-nil means\n\
1130 do not put this buffer at the front of the list of recently selected ones.\n\
1132 WARNING: This is NOT the way to work on another buffer temporarily\n\
1133 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1134 the window-buffer correspondences.")
1136 Lisp_Object bufname
, norecord
;
1138 register Lisp_Object buf
;
1141 if (EQ (minibuf_window
, selected_window
))
1142 error ("Cannot switch buffers in minibuffer window");
1143 tem
= Fwindow_dedicated_p (selected_window
);
1145 error ("Cannot switch buffers in a dedicated window");
1148 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1151 buf
= Fget_buffer (bufname
);
1154 buf
= Fget_buffer_create (bufname
);
1155 Fset_buffer_major_mode (buf
);
1159 if (NILP (norecord
))
1160 record_buffer (buf
);
1162 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1163 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1170 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 2, 0,
1171 "Select buffer BUFFER in some window, preferably a different one.\n\
1172 If BUFFER is nil, then some other buffer is chosen.\n\
1173 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1174 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1175 window even if BUFFER is already visible in the selected window.")
1177 Lisp_Object bufname
, other
;
1179 register Lisp_Object buf
;
1181 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1184 buf
= Fget_buffer (bufname
);
1187 buf
= Fget_buffer_create (bufname
);
1188 Fset_buffer_major_mode (buf
);
1192 record_buffer (buf
);
1193 Fselect_window (Fdisplay_buffer (buf
, other
));
1197 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1198 "Return the current buffer as a Lisp object.")
1201 register Lisp_Object buf
;
1202 XSETBUFFER (buf
, current_buffer
);
1206 /* Set the current buffer to B. */
1209 set_buffer_internal (b
)
1210 register struct buffer
*b
;
1212 register struct buffer
*old_buf
;
1213 register Lisp_Object tail
, valcontents
;
1216 if (current_buffer
== b
)
1219 windows_or_buffers_changed
= 1;
1220 set_buffer_internal_1 (b
);
1223 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1224 This is used by redisplay. */
1227 set_buffer_internal_1 (b
)
1228 register struct buffer
*b
;
1230 register struct buffer
*old_buf
;
1231 register Lisp_Object tail
, valcontents
;
1234 if (current_buffer
== b
)
1237 old_buf
= current_buffer
;
1239 last_known_column_point
= -1; /* invalidate indentation cache */
1243 /* Put the undo list back in the base buffer, so that it appears
1244 that an indirect buffer shares the undo list of its base. */
1245 if (old_buf
->base_buffer
)
1246 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1248 /* If the old current buffer has markers to record PT, BEGV and ZV
1249 when it is not current, update them now. */
1250 if (! NILP (old_buf
->pt_marker
))
1253 XSETBUFFER (obuf
, old_buf
);
1254 Fset_marker (old_buf
->pt_marker
, BUF_PT (old_buf
), obuf
);
1256 if (! NILP (old_buf
->begv_marker
))
1259 XSETBUFFER (obuf
, old_buf
);
1260 Fset_marker (old_buf
->begv_marker
, BUF_BEGV (old_buf
), obuf
);
1262 if (! NILP (old_buf
->zv_marker
))
1265 XSETBUFFER (obuf
, old_buf
);
1266 Fset_marker (old_buf
->zv_marker
, BUF_ZV (old_buf
), obuf
);
1270 /* Get the undo list from the base buffer, so that it appears
1271 that an indirect buffer shares the undo list of its base. */
1273 b
->undo_list
= b
->base_buffer
->undo_list
;
1275 /* If the new current buffer has markers to record PT, BEGV and ZV
1276 when it is not current, fetch them now. */
1277 if (! NILP (b
->pt_marker
))
1278 BUF_PT (b
) = marker_position (b
->pt_marker
);
1279 if (! NILP (b
->begv_marker
))
1280 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1281 if (! NILP (b
->zv_marker
))
1282 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1284 /* Look down buffer's list of local Lisp variables
1285 to find and update any that forward into C variables. */
1287 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1289 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1290 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1291 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1292 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1293 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1294 /* Just reference the variable
1295 to cause it to become set for this buffer. */
1296 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1299 /* Do the same with any others that were local to the previous buffer */
1302 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1304 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1305 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1306 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1307 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1308 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1309 /* Just reference the variable
1310 to cause it to become set for this buffer. */
1311 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1315 /* Switch to buffer B temporarily for redisplay purposes.
1316 This avoids certain things that don't need to be done within redisplay. */
1322 register struct buffer
*old_buf
;
1324 if (current_buffer
== b
)
1327 old_buf
= current_buffer
;
1332 /* If the old current buffer has markers to record PT, BEGV and ZV
1333 when it is not current, update them now. */
1334 if (! NILP (old_buf
->pt_marker
))
1337 XSETBUFFER (obuf
, old_buf
);
1338 Fset_marker (old_buf
->pt_marker
, BUF_PT (old_buf
), obuf
);
1340 if (! NILP (old_buf
->begv_marker
))
1343 XSETBUFFER (obuf
, old_buf
);
1344 Fset_marker (old_buf
->begv_marker
, BUF_BEGV (old_buf
), obuf
);
1346 if (! NILP (old_buf
->zv_marker
))
1349 XSETBUFFER (obuf
, old_buf
);
1350 Fset_marker (old_buf
->zv_marker
, BUF_ZV (old_buf
), obuf
);
1354 /* If the new current buffer has markers to record PT, BEGV and ZV
1355 when it is not current, fetch them now. */
1356 if (! NILP (b
->pt_marker
))
1357 BUF_PT (b
) = marker_position (b
->pt_marker
);
1358 if (! NILP (b
->begv_marker
))
1359 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1360 if (! NILP (b
->zv_marker
))
1361 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1364 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1365 "Make the buffer BUFFER current for editing operations.\n\
1366 BUFFER may be a buffer or the name of an existing buffer.\n\
1367 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1368 This function does not display the buffer, so its effect ends\n\
1369 when the current command terminates.\n\
1370 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1372 register Lisp_Object bufname
;
1374 register Lisp_Object buffer
;
1375 buffer
= Fget_buffer (bufname
);
1378 if (NILP (XBUFFER (buffer
)->name
))
1379 error ("Selecting deleted buffer");
1380 set_buffer_internal (XBUFFER (buffer
));
1384 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1385 Sbarf_if_buffer_read_only
, 0, 0, 0,
1386 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1389 if (!NILP (current_buffer
->read_only
)
1390 && NILP (Vinhibit_read_only
))
1391 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1395 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1396 "Put BUFFER at the end of the list of all buffers.\n\
1397 There it is the least likely candidate for `other-buffer' to return;\n\
1398 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1399 If BUFFER is nil or omitted, bury the current buffer.\n\
1400 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1401 selected window if it is displayed there.")
1403 register Lisp_Object buf
;
1405 /* Figure out what buffer we're going to bury. */
1408 XSETBUFFER (buf
, current_buffer
);
1410 /* If we're burying the current buffer, unshow it. */
1411 Fswitch_to_buffer (Fother_buffer (buf
, Qnil
), Qnil
);
1417 buf1
= Fget_buffer (buf
);
1423 /* Move buf to the end of the buffer list. */
1425 register Lisp_Object aelt
, link
;
1427 aelt
= Frassq (buf
, Vbuffer_alist
);
1428 link
= Fmemq (aelt
, Vbuffer_alist
);
1429 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1430 XCONS (link
)->cdr
= Qnil
;
1431 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1437 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1438 "Delete the entire contents of the current buffer.\n\
1439 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1440 so the buffer is truly empty after this.")
1445 current_buffer
->last_window_start
= 1;
1446 /* Prevent warnings, or suspension of auto saving, that would happen
1447 if future size is less than past size. Use of erase-buffer
1448 implies that the future text is not really related to the past text. */
1449 XSETFASTINT (current_buffer
->save_length
, 0);
1453 validate_region (b
, e
)
1454 register Lisp_Object
*b
, *e
;
1456 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1457 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1459 if (XINT (*b
) > XINT (*e
))
1462 tem
= *b
; *b
= *e
; *e
= tem
;
1465 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1466 && XINT (*e
) <= ZV
))
1467 args_out_of_range (*b
, *e
);
1470 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
1472 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1473 Most local variable bindings are eliminated so that the default values\n\
1474 become effective once more. Also, the syntax table is set from\n\
1475 `standard-syntax-table', the local keymap is set to nil,\n\
1476 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1477 This function also forces redisplay of the mode line.\n\
1479 Every function to select a new major mode starts by\n\
1480 calling this function.\n\n\
1481 As a special exception, local variables whose names have\n\
1482 a non-nil `permanent-local' property are not eliminated by this function.\n\
1484 The first thing this function does is run\n\
1485 the normal hook `change-major-mode-hook'.")
1488 register Lisp_Object alist
, sym
, tem
;
1491 if (!NILP (Vrun_hooks
))
1492 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
1493 oalist
= current_buffer
->local_var_alist
;
1495 /* Make sure none of the bindings in oalist
1496 remain swapped in, in their symbols. */
1498 swap_out_buffer_local_variables (current_buffer
);
1500 /* Actually eliminate all local bindings of this buffer. */
1502 reset_buffer_local_variables (current_buffer
);
1504 /* Redisplay mode lines; we are changing major mode. */
1506 update_mode_lines
++;
1508 /* Any which are supposed to be permanent,
1509 make local again, with the same values they had. */
1511 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1513 sym
= XCONS (XCONS (alist
)->car
)->car
;
1514 tem
= Fget (sym
, Qpermanent_local
);
1517 Fmake_local_variable (sym
);
1518 Fset (sym
, XCONS (XCONS (alist
)->car
)->cdr
);
1522 /* Force mode-line redisplay. Useful here because all major mode
1523 commands call this function. */
1524 update_mode_lines
++;
1529 /* Make sure no local variables remain set up with buffer B
1530 for their current values. */
1533 swap_out_buffer_local_variables (b
)
1536 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
1538 XSETBUFFER (buffer
, b
);
1539 oalist
= b
->local_var_alist
;
1541 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1543 sym
= XCONS (XCONS (alist
)->car
)->car
;
1545 /* Need not do anything if some other buffer's binding is now encached. */
1546 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
;
1547 if (XBUFFER (tem
) == current_buffer
)
1549 /* Symbol is set up for this buffer's old local value.
1550 Set it up for the current buffer with the default value. */
1552 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->cdr
;
1553 /* Store the symbol's current value into the alist entry
1554 it is currently set up for. This is so that, if the
1555 local is marked permanent, and we make it local again
1556 later in Fkill_all_local_variables, we don't lose the value. */
1557 XCONS (XCONS (tem
)->car
)->cdr
1558 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
);
1559 /* Switch to the symbol's default-value alist entry. */
1560 XCONS (tem
)->car
= tem
;
1561 /* Mark it as current for buffer B. */
1562 XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
1564 /* Store the current value into any forwarding in the symbol. */
1565 store_symval_forwarding (sym
, XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
,
1571 /* Find all the overlays in the current buffer that contain position POS.
1572 Return the number found, and store them in a vector in *VEC_PTR.
1573 Store in *LEN_PTR the size allocated for the vector.
1574 Store in *NEXT_PTR the next position after POS where an overlay starts,
1575 or ZV if there are no more overlays.
1576 Store in *PREV_PTR the previous position before POS where an overlay ends,
1577 or BEGV if there are no previous overlays.
1578 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1580 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1581 when this function is called.
1583 If EXTEND is non-zero, we make the vector bigger if necessary.
1584 If EXTEND is zero, we never extend the vector,
1585 and we store only as many overlays as will fit.
1586 But we still return the total number of overlays. */
1589 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1592 Lisp_Object
**vec_ptr
;
1597 Lisp_Object tail
, overlay
, start
, end
, result
;
1600 Lisp_Object
*vec
= *vec_ptr
;
1603 int inhibit_storing
= 0;
1605 for (tail
= current_buffer
->overlays_before
;
1607 tail
= XCONS (tail
)->cdr
)
1609 int startpos
, endpos
;
1611 overlay
= XCONS (tail
)->car
;
1613 start
= OVERLAY_START (overlay
);
1614 end
= OVERLAY_END (overlay
);
1615 endpos
= OVERLAY_POSITION (end
);
1624 startpos
= OVERLAY_POSITION (start
);
1625 if (startpos
<= pos
)
1629 /* The supplied vector is full.
1630 Either make it bigger, or don't store any more in it. */
1633 *len_ptr
= len
*= 2;
1634 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1638 inhibit_storing
= 1;
1641 if (!inhibit_storing
)
1643 /* Keep counting overlays even if we can't return them all. */
1646 else if (startpos
< next
)
1650 for (tail
= current_buffer
->overlays_after
;
1652 tail
= XCONS (tail
)->cdr
)
1654 int startpos
, endpos
;
1656 overlay
= XCONS (tail
)->car
;
1658 start
= OVERLAY_START (overlay
);
1659 end
= OVERLAY_END (overlay
);
1660 startpos
= OVERLAY_POSITION (start
);
1663 if (startpos
< next
)
1667 endpos
= OVERLAY_POSITION (end
);
1674 *len_ptr
= len
*= 2;
1675 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1679 inhibit_storing
= 1;
1682 if (!inhibit_storing
)
1686 else if (endpos
< pos
&& endpos
> prev
)
1697 /* Find all the overlays in the current buffer that overlap the range BEG-END
1698 or are empty at BEG.
1700 Return the number found, and store them in a vector in *VEC_PTR.
1701 Store in *LEN_PTR the size allocated for the vector.
1702 Store in *NEXT_PTR the next position after POS where an overlay starts,
1703 or ZV if there are no more overlays.
1704 Store in *PREV_PTR the previous position before POS where an overlay ends,
1705 or BEGV if there are no previous overlays.
1706 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1708 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1709 when this function is called.
1711 If EXTEND is non-zero, we make the vector bigger if necessary.
1712 If EXTEND is zero, we never extend the vector,
1713 and we store only as many overlays as will fit.
1714 But we still return the total number of overlays. */
1717 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1720 Lisp_Object
**vec_ptr
;
1725 Lisp_Object tail
, overlay
, ostart
, oend
, result
;
1728 Lisp_Object
*vec
= *vec_ptr
;
1731 int inhibit_storing
= 0;
1733 for (tail
= current_buffer
->overlays_before
;
1735 tail
= XCONS (tail
)->cdr
)
1737 int startpos
, endpos
;
1739 overlay
= XCONS (tail
)->car
;
1741 ostart
= OVERLAY_START (overlay
);
1742 oend
= OVERLAY_END (overlay
);
1743 endpos
= OVERLAY_POSITION (oend
);
1750 startpos
= OVERLAY_POSITION (ostart
);
1751 /* Count an interval if it either overlaps the range
1752 or is empty at the start of the range. */
1753 if ((beg
< endpos
&& startpos
< end
)
1754 || (startpos
== endpos
&& beg
== endpos
))
1758 /* The supplied vector is full.
1759 Either make it bigger, or don't store any more in it. */
1762 *len_ptr
= len
*= 2;
1763 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1767 inhibit_storing
= 1;
1770 if (!inhibit_storing
)
1772 /* Keep counting overlays even if we can't return them all. */
1775 else if (startpos
< next
)
1779 for (tail
= current_buffer
->overlays_after
;
1781 tail
= XCONS (tail
)->cdr
)
1783 int startpos
, endpos
;
1785 overlay
= XCONS (tail
)->car
;
1787 ostart
= OVERLAY_START (overlay
);
1788 oend
= OVERLAY_END (overlay
);
1789 startpos
= OVERLAY_POSITION (ostart
);
1792 if (startpos
< next
)
1796 endpos
= OVERLAY_POSITION (oend
);
1797 /* Count an interval if it either overlaps the range
1798 or is empty at the start of the range. */
1799 if ((beg
< endpos
&& startpos
< end
)
1800 || (startpos
== endpos
&& beg
== endpos
))
1806 *len_ptr
= len
*= 2;
1807 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1811 inhibit_storing
= 1;
1814 if (!inhibit_storing
)
1818 else if (endpos
< beg
&& endpos
> prev
)
1829 /* Fast function to just test if we're at an overlay boundary. */
1831 overlay_touches_p (pos
)
1834 Lisp_Object tail
, overlay
;
1836 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
1837 tail
= XCONS (tail
)->cdr
)
1841 overlay
= XCONS (tail
)->car
;
1842 if (!GC_OVERLAYP (overlay
))
1845 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
1848 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
1852 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
1853 tail
= XCONS (tail
)->cdr
)
1857 overlay
= XCONS (tail
)->car
;
1858 if (!GC_OVERLAYP (overlay
))
1861 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
1864 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
1872 Lisp_Object overlay
;
1878 compare_overlays (s1
, s2
)
1879 struct sortvec
*s1
, *s2
;
1881 if (s1
->priority
!= s2
->priority
)
1882 return s1
->priority
- s2
->priority
;
1883 if (s1
->beg
!= s2
->beg
)
1884 return s1
->beg
- s2
->beg
;
1885 if (s1
->end
!= s2
->end
)
1886 return s2
->end
- s1
->end
;
1890 /* Sort an array of overlays by priority. The array is modified in place.
1891 The return value is the new size; this may be smaller than the original
1892 size if some of the overlays were invalid or were window-specific. */
1894 sort_overlays (overlay_vec
, noverlays
, w
)
1895 Lisp_Object
*overlay_vec
;
1900 struct sortvec
*sortvec
;
1901 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
1903 /* Put the valid and relevant overlays into sortvec. */
1905 for (i
= 0, j
= 0; i
< noverlays
; i
++)
1908 Lisp_Object overlay
;
1910 overlay
= overlay_vec
[i
];
1911 if (OVERLAY_VALID (overlay
)
1912 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
1913 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
1915 /* If we're interested in a specific window, then ignore
1916 overlays that are limited to some other window. */
1921 window
= Foverlay_get (overlay
, Qwindow
);
1922 if (WINDOWP (window
) && XWINDOW (window
) != w
)
1926 /* This overlay is good and counts: put it into sortvec. */
1927 sortvec
[j
].overlay
= overlay
;
1928 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
1929 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
1930 tem
= Foverlay_get (overlay
, Qpriority
);
1932 sortvec
[j
].priority
= XINT (tem
);
1934 sortvec
[j
].priority
= 0;
1940 /* Sort the overlays into the proper order: increasing priority. */
1943 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
1945 for (i
= 0; i
< noverlays
; i
++)
1946 overlay_vec
[i
] = sortvec
[i
].overlay
;
1952 Lisp_Object string
, string2
;
1959 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
1960 int size
; /* Allocated length of that array. */
1961 int used
; /* How much of the array is currently in use. */
1962 int bytes
; /* Total length of the strings in buf. */
1965 /* Buffers for storing information about the overlays touching a given
1966 position. These could be automatic variables in overlay_strings, but
1967 it's more efficient to hold onto the memory instead of repeatedly
1968 allocating and freeing it. */
1969 static struct sortstrlist overlay_heads
, overlay_tails
;
1970 static char *overlay_str_buf
;
1972 /* Allocated length of overlay_str_buf. */
1973 static int overlay_str_len
;
1975 /* A comparison function suitable for passing to qsort. */
1977 cmp_for_strings (as1
, as2
)
1980 struct sortstr
*s1
= (struct sortstr
*)as1
;
1981 struct sortstr
*s2
= (struct sortstr
*)as2
;
1982 if (s1
->size
!= s2
->size
)
1983 return s2
->size
- s1
->size
;
1984 if (s1
->priority
!= s2
->priority
)
1985 return s1
->priority
- s2
->priority
;
1990 record_overlay_string (ssl
, str
, str2
, pri
, size
)
1991 struct sortstrlist
*ssl
;
1992 Lisp_Object str
, str2
, pri
;
1995 if (ssl
->used
== ssl
->size
)
2001 ssl
->buf
= ((struct sortstr
*)
2002 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2004 ssl
->buf
[ssl
->used
].string
= str
;
2005 ssl
->buf
[ssl
->used
].string2
= str2
;
2006 ssl
->buf
[ssl
->used
].size
= size
;
2007 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2009 ssl
->bytes
+= XSTRING (str
)->size
;
2011 ssl
->bytes
+= XSTRING (str2
)->size
;
2014 /* Return the concatenation of the strings associated with overlays that
2015 begin or end at POS, ignoring overlays that are specific to a window
2016 other than W. The strings are concatenated in the appropriate order:
2017 shorter overlays nest inside longer ones, and higher priority inside
2018 lower. Normally all of the after-strings come first, but zero-sized
2019 overlays have their after-strings ride along with the before-strings
2020 because it would look strange to print them inside-out.
2022 Returns the string length, and stores the contents indirectly through
2023 PSTR, if that variable is non-null. The string may be overwritten by
2024 subsequent calls. */
2026 overlay_strings (pos
, w
, pstr
)
2031 Lisp_Object ov
, overlay
, window
, str
;
2032 int startpos
, endpos
;
2034 overlay_heads
.used
= overlay_heads
.bytes
= 0;
2035 overlay_tails
.used
= overlay_tails
.bytes
= 0;
2036 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCONS (ov
)->cdr
)
2038 overlay
= XCONS (ov
)->car
;
2039 if (!OVERLAYP (overlay
))
2042 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2043 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2046 if (endpos
!= pos
&& startpos
!= pos
)
2048 window
= Foverlay_get (overlay
, Qwindow
);
2049 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2052 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2053 record_overlay_string (&overlay_heads
, str
,
2055 ? Foverlay_get (overlay
, Qafter_string
)
2057 Foverlay_get (overlay
, Qpriority
),
2059 else if (endpos
== pos
2060 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2061 record_overlay_string (&overlay_tails
, str
, Qnil
,
2062 Foverlay_get (overlay
, Qpriority
),
2065 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCONS (ov
)->cdr
)
2067 overlay
= XCONS (ov
)->car
;
2068 if (!OVERLAYP (overlay
))
2071 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2072 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2075 if (endpos
!= pos
&& startpos
!= pos
)
2077 window
= Foverlay_get (overlay
, Qwindow
);
2078 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2081 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2082 record_overlay_string (&overlay_heads
, str
,
2084 ? Foverlay_get (overlay
, Qafter_string
)
2086 Foverlay_get (overlay
, Qpriority
),
2088 else if (endpos
== pos
2089 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2090 record_overlay_string (&overlay_tails
, str
, Qnil
,
2091 Foverlay_get (overlay
, Qpriority
),
2094 if (overlay_tails
.used
> 1)
2095 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
2097 if (overlay_heads
.used
> 1)
2098 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
2100 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
2105 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
2107 if (total
> overlay_str_len
)
2108 overlay_str_buf
= (char *)xrealloc (overlay_str_buf
,
2109 overlay_str_len
= total
);
2110 p
= overlay_str_buf
;
2111 for (i
= overlay_tails
.used
; --i
>= 0;)
2113 tem
= overlay_tails
.buf
[i
].string
;
2114 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2115 p
+= XSTRING (tem
)->size
;
2117 for (i
= 0; i
< overlay_heads
.used
; ++i
)
2119 tem
= overlay_heads
.buf
[i
].string
;
2120 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2121 p
+= XSTRING (tem
)->size
;
2122 tem
= overlay_heads
.buf
[i
].string2
;
2125 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2126 p
+= XSTRING (tem
)->size
;
2129 if (p
!= overlay_str_buf
+ total
)
2132 *pstr
= overlay_str_buf
;
2138 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2141 recenter_overlay_lists (buf
, pos
)
2145 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
2147 /* See if anything in overlays_before should move to overlays_after. */
2149 /* We don't strictly need prev in this loop; it should always be nil.
2150 But we use it for symmetry and in case that should cease to be true
2151 with some future change. */
2153 for (tail
= buf
->overlays_before
;
2155 prev
= tail
, tail
= next
)
2157 next
= XCONS (tail
)->cdr
;
2158 overlay
= XCONS (tail
)->car
;
2160 /* If the overlay is not valid, get rid of it. */
2161 if (!OVERLAY_VALID (overlay
))
2166 /* Splice the cons cell TAIL out of overlays_before. */
2168 XCONS (prev
)->cdr
= next
;
2170 buf
->overlays_before
= next
;
2176 beg
= OVERLAY_START (overlay
);
2177 end
= OVERLAY_END (overlay
);
2179 if (OVERLAY_POSITION (end
) > pos
)
2181 /* OVERLAY needs to be moved. */
2182 int where
= OVERLAY_POSITION (beg
);
2183 Lisp_Object other
, other_prev
;
2185 /* Splice the cons cell TAIL out of overlays_before. */
2187 XCONS (prev
)->cdr
= next
;
2189 buf
->overlays_before
= next
;
2191 /* Search thru overlays_after for where to put it. */
2193 for (other
= buf
->overlays_after
;
2195 other_prev
= other
, other
= XCONS (other
)->cdr
)
2197 Lisp_Object otherbeg
, otheroverlay
, follower
;
2200 otheroverlay
= XCONS (other
)->car
;
2201 if (! OVERLAY_VALID (otheroverlay
))
2204 otherbeg
= OVERLAY_START (otheroverlay
);
2205 if (OVERLAY_POSITION (otherbeg
) >= where
)
2209 /* Add TAIL to overlays_after before OTHER. */
2210 XCONS (tail
)->cdr
= other
;
2211 if (!NILP (other_prev
))
2212 XCONS (other_prev
)->cdr
= tail
;
2214 buf
->overlays_after
= tail
;
2218 /* We've reached the things that should stay in overlays_before.
2219 All the rest of overlays_before must end even earlier,
2224 /* See if anything in overlays_after should be in overlays_before. */
2226 for (tail
= buf
->overlays_after
;
2228 prev
= tail
, tail
= next
)
2230 next
= XCONS (tail
)->cdr
;
2231 overlay
= XCONS (tail
)->car
;
2233 /* If the overlay is not valid, get rid of it. */
2234 if (!OVERLAY_VALID (overlay
))
2239 /* Splice the cons cell TAIL out of overlays_after. */
2241 XCONS (prev
)->cdr
= next
;
2243 buf
->overlays_after
= next
;
2249 beg
= OVERLAY_START (overlay
);
2250 end
= OVERLAY_END (overlay
);
2252 /* Stop looking, when we know that nothing further
2253 can possibly end before POS. */
2254 if (OVERLAY_POSITION (beg
) > pos
)
2257 if (OVERLAY_POSITION (end
) <= pos
)
2259 /* OVERLAY needs to be moved. */
2260 int where
= OVERLAY_POSITION (end
);
2261 Lisp_Object other
, other_prev
;
2263 /* Splice the cons cell TAIL out of overlays_after. */
2265 XCONS (prev
)->cdr
= next
;
2267 buf
->overlays_after
= next
;
2269 /* Search thru overlays_before for where to put it. */
2271 for (other
= buf
->overlays_before
;
2273 other_prev
= other
, other
= XCONS (other
)->cdr
)
2275 Lisp_Object otherend
, otheroverlay
;
2278 otheroverlay
= XCONS (other
)->car
;
2279 if (! OVERLAY_VALID (otheroverlay
))
2282 otherend
= OVERLAY_END (otheroverlay
);
2283 if (OVERLAY_POSITION (otherend
) <= where
)
2287 /* Add TAIL to overlays_before before OTHER. */
2288 XCONS (tail
)->cdr
= other
;
2289 if (!NILP (other_prev
))
2290 XCONS (other_prev
)->cdr
= tail
;
2292 buf
->overlays_before
= tail
;
2297 XSETFASTINT (buf
->overlay_center
, pos
);
2301 adjust_overlays_for_insert (pos
, length
)
2305 /* After an insertion, the lists are still sorted properly,
2306 but we may need to update the value of the overlay center. */
2307 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
2308 XSETFASTINT (current_buffer
->overlay_center
,
2309 XFASTINT (current_buffer
->overlay_center
) + length
);
2313 adjust_overlays_for_delete (pos
, length
)
2317 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
2318 /* The deletion was to our right. No change needed; the before- and
2319 after-lists are still consistent. */
2321 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
2322 /* The deletion was to our left. We need to adjust the center value
2323 to account for the change in position, but the lists are consistent
2324 given the new value. */
2325 XSETFASTINT (current_buffer
->overlay_center
,
2326 XFASTINT (current_buffer
->overlay_center
) - length
);
2328 /* We're right in the middle. There might be things on the after-list
2329 that now belong on the before-list. Recentering will move them,
2330 and also update the center point. */
2331 recenter_overlay_lists (current_buffer
, pos
);
2334 /* Fix up overlays that were garbled as a result of permuting markers
2335 in the range START through END. Any overlay with at least one
2336 endpoint in this range will need to be unlinked from the overlay
2337 list and reinserted in its proper place.
2338 Such an overlay might even have negative size at this point.
2339 If so, we'll reverse the endpoints. Can you think of anything
2340 better to do in this situation? */
2342 fix_overlays_in_range (start
, end
)
2343 register int start
, end
;
2345 Lisp_Object tem
, overlay
;
2346 Lisp_Object before_list
, after_list
;
2347 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
2348 int startpos
, endpos
;
2350 /* This algorithm shifts links around instead of consing and GCing.
2351 The loop invariant is that before_list (resp. after_list) is a
2352 well-formed list except that its last element, the one that
2353 *pbefore (resp. *pafter) points to, is still uninitialized.
2354 So it's not a bug that before_list isn't initialized, although
2355 it may look strange. */
2356 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
2358 overlay
= XCONS (*ptail
)->car
;
2359 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2362 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2364 || (startpos
>= start
&& startpos
< end
))
2366 /* If the overlay is backwards, fix that now. */
2367 if (startpos
> endpos
)
2370 Fset_marker (OVERLAY_START (overlay
), endpos
, Qnil
);
2371 Fset_marker (OVERLAY_END (overlay
), startpos
, Qnil
);
2372 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2374 /* Add it to the end of the wrong list. Later on,
2375 recenter_overlay_lists will move it to the right place. */
2376 if (endpos
< XINT (current_buffer
->overlay_center
))
2379 pafter
= &XCONS (*ptail
)->cdr
;
2384 pbefore
= &XCONS (*ptail
)->cdr
;
2386 *ptail
= XCONS (*ptail
)->cdr
;
2389 ptail
= &XCONS (*ptail
)->cdr
;
2391 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
2393 overlay
= XCONS (*ptail
)->car
;
2394 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2395 if (startpos
>= end
)
2397 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2398 if (startpos
>= start
2399 || (endpos
>= start
&& endpos
< end
))
2401 if (startpos
> endpos
)
2404 Fset_marker (OVERLAY_START (overlay
), endpos
, Qnil
);
2405 Fset_marker (OVERLAY_END (overlay
), startpos
, Qnil
);
2406 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2408 if (endpos
< XINT (current_buffer
->overlay_center
))
2411 pafter
= &XCONS (*ptail
)->cdr
;
2416 pbefore
= &XCONS (*ptail
)->cdr
;
2418 *ptail
= XCONS (*ptail
)->cdr
;
2421 ptail
= &XCONS (*ptail
)->cdr
;
2424 /* Splice the constructed (wrong) lists into the buffer's lists,
2425 and let the recenter function make it sane again. */
2426 *pbefore
= current_buffer
->overlays_before
;
2427 current_buffer
->overlays_before
= before_list
;
2428 recenter_overlay_lists (current_buffer
,
2429 XINT (current_buffer
->overlay_center
));
2431 *pafter
= current_buffer
->overlays_after
;
2432 current_buffer
->overlays_after
= after_list
;
2433 recenter_overlay_lists (current_buffer
,
2434 XINT (current_buffer
->overlay_center
));
2437 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
2438 "Return t if OBJECT is an overlay.")
2442 return (OVERLAYP (object
) ? Qt
: Qnil
);
2445 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 3, 0,
2446 "Create a new overlay with range BEG to END in BUFFER.\n\
2447 If omitted, BUFFER defaults to the current buffer.\n\
2448 BEG and END may be integers or markers.")
2450 Lisp_Object beg
, end
, buffer
;
2452 Lisp_Object overlay
;
2456 XSETBUFFER (buffer
, current_buffer
);
2458 CHECK_BUFFER (buffer
, 2);
2460 && ! EQ (Fmarker_buffer (beg
), buffer
))
2461 error ("Marker points into wrong buffer");
2463 && ! EQ (Fmarker_buffer (end
), buffer
))
2464 error ("Marker points into wrong buffer");
2466 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2467 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2469 if (XINT (beg
) > XINT (end
))
2472 temp
= beg
; beg
= end
; end
= temp
;
2475 b
= XBUFFER (buffer
);
2477 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
2478 end
= Fset_marker (Fmake_marker (), end
, buffer
);
2480 overlay
= allocate_misc ();
2481 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
2482 XOVERLAY (overlay
)->start
= beg
;
2483 XOVERLAY (overlay
)->end
= end
;
2484 XOVERLAY (overlay
)->plist
= Qnil
;
2486 /* Put the new overlay on the wrong list. */
2487 end
= OVERLAY_END (overlay
);
2488 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2489 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2491 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2493 /* This puts it in the right list, and in the right order. */
2494 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2496 /* We don't need to redisplay the region covered by the overlay, because
2497 the overlay has no properties at the moment. */
2502 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
2503 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
2504 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
2505 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
2507 (overlay
, beg
, end
, buffer
)
2508 Lisp_Object overlay
, beg
, end
, buffer
;
2510 struct buffer
*b
, *ob
;
2511 Lisp_Object obuffer
;
2512 int count
= specpdl_ptr
- specpdl
;
2514 CHECK_OVERLAY (overlay
, 0);
2516 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2518 XSETBUFFER (buffer
, current_buffer
);
2519 CHECK_BUFFER (buffer
, 3);
2522 && ! EQ (Fmarker_buffer (beg
), buffer
))
2523 error ("Marker points into wrong buffer");
2525 && ! EQ (Fmarker_buffer (end
), buffer
))
2526 error ("Marker points into wrong buffer");
2528 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2529 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2531 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
2532 return Fdelete_overlay (overlay
);
2534 if (XINT (beg
) > XINT (end
))
2537 temp
= beg
; beg
= end
; end
= temp
;
2540 specbind (Qinhibit_quit
, Qt
);
2542 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2543 b
= XBUFFER (buffer
);
2544 ob
= XBUFFER (obuffer
);
2546 /* If the overlay has changed buffers, do a thorough redisplay. */
2547 if (!EQ (buffer
, obuffer
))
2549 /* Redisplay where the overlay was. */
2550 if (!NILP (obuffer
))
2555 o_beg
= OVERLAY_START (overlay
);
2556 o_end
= OVERLAY_END (overlay
);
2557 o_beg
= OVERLAY_POSITION (o_beg
);
2558 o_end
= OVERLAY_POSITION (o_end
);
2560 redisplay_region (ob
, XINT (o_beg
), XINT (o_end
));
2563 /* Redisplay where the overlay is going to be. */
2564 redisplay_region (b
, XINT (beg
), XINT (end
));
2567 /* Redisplay the area the overlay has just left, or just enclosed. */
2571 int change_beg
, change_end
;
2573 o_beg
= OVERLAY_START (overlay
);
2574 o_end
= OVERLAY_END (overlay
);
2575 o_beg
= OVERLAY_POSITION (o_beg
);
2576 o_end
= OVERLAY_POSITION (o_end
);
2578 if (XINT (o_beg
) == XINT (beg
))
2579 redisplay_region (b
, XINT (o_end
), XINT (end
));
2580 else if (XINT (o_end
) == XINT (end
))
2581 redisplay_region (b
, XINT (o_beg
), XINT (beg
));
2584 if (XINT (beg
) < XINT (o_beg
)) o_beg
= beg
;
2585 if (XINT (end
) > XINT (o_end
)) o_end
= end
;
2586 redisplay_region (b
, XINT (o_beg
), XINT (o_end
));
2590 if (!NILP (obuffer
))
2592 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
2593 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
2596 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
2597 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
2599 /* Put the overlay on the wrong list. */
2600 end
= OVERLAY_END (overlay
);
2601 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2602 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2604 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2606 /* This puts it in the right list, and in the right order. */
2607 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2609 return unbind_to (count
, overlay
);
2612 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
2613 "Delete the overlay OVERLAY from its buffer.")
2615 Lisp_Object overlay
;
2619 int count
= specpdl_ptr
- specpdl
;
2621 CHECK_OVERLAY (overlay
, 0);
2623 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2627 b
= XBUFFER (buffer
);
2629 specbind (Qinhibit_quit
, Qt
);
2631 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
2632 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
2634 redisplay_region (b
,
2635 marker_position (OVERLAY_START (overlay
)),
2636 marker_position (OVERLAY_END (overlay
)));
2638 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
2639 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
2641 return unbind_to (count
, Qnil
);
2644 /* Overlay dissection functions. */
2646 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
2647 "Return the position at which OVERLAY starts.")
2649 Lisp_Object overlay
;
2651 CHECK_OVERLAY (overlay
, 0);
2653 return (Fmarker_position (OVERLAY_START (overlay
)));
2656 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
2657 "Return the position at which OVERLAY ends.")
2659 Lisp_Object overlay
;
2661 CHECK_OVERLAY (overlay
, 0);
2663 return (Fmarker_position (OVERLAY_END (overlay
)));
2666 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
2667 "Return the buffer OVERLAY belongs to.")
2669 Lisp_Object overlay
;
2671 CHECK_OVERLAY (overlay
, 0);
2673 return Fmarker_buffer (OVERLAY_START (overlay
));
2676 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
2677 "Return a list of the properties on OVERLAY.\n\
2678 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
2681 Lisp_Object overlay
;
2683 CHECK_OVERLAY (overlay
, 0);
2685 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
2689 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
2690 "Return a list of the overlays that contain position POS.")
2695 Lisp_Object
*overlay_vec
;
2699 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2702 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2704 /* Put all the overlays we want in a vector in overlay_vec.
2705 Store the length in len. */
2706 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2707 (int *) 0, (int *) 0);
2709 /* Make a list of them all. */
2710 result
= Flist (noverlays
, overlay_vec
);
2712 xfree (overlay_vec
);
2716 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
2717 "Return a list of the overlays that overlap the region BEG ... END.\n\
2718 Overlap means that at least one character is contained within the overlay\n\
2719 and also contained within the specified region.\n\
2720 Empty overlays are included in the result if they are located at BEG\n\
2721 or between BEG and END.")
2723 Lisp_Object beg
, end
;
2726 Lisp_Object
*overlay_vec
;
2730 CHECK_NUMBER_COERCE_MARKER (beg
, 0);
2731 CHECK_NUMBER_COERCE_MARKER (end
, 0);
2734 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2736 /* Put all the overlays we want in a vector in overlay_vec.
2737 Store the length in len. */
2738 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
2739 (int *) 0, (int *) 0);
2741 /* Make a list of them all. */
2742 result
= Flist (noverlays
, overlay_vec
);
2744 xfree (overlay_vec
);
2748 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
2750 "Return the next position after POS where an overlay starts or ends.\n\
2751 If there are no more overlay boundaries after POS, return (point-max).")
2757 Lisp_Object
*overlay_vec
;
2761 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2764 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2766 /* Put all the overlays we want in a vector in overlay_vec.
2767 Store the length in len.
2768 endpos gets the position where the next overlay starts. */
2769 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2770 &endpos
, (int *) 0);
2772 /* If any of these overlays ends before endpos,
2773 use its ending point instead. */
2774 for (i
= 0; i
< noverlays
; i
++)
2779 oend
= OVERLAY_END (overlay_vec
[i
]);
2780 oendpos
= OVERLAY_POSITION (oend
);
2781 if (oendpos
< endpos
)
2785 xfree (overlay_vec
);
2786 return make_number (endpos
);
2789 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
2790 Sprevious_overlay_change
, 1, 1, 0,
2791 "Return the previous position before POS where an overlay starts or ends.\n\
2792 If there are no more overlay boundaries before POS, return (point-min).")
2798 Lisp_Object
*overlay_vec
;
2803 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2806 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2808 /* At beginning of buffer, we know the answer;
2809 avoid bug subtracting 1 below. */
2810 if (XINT (pos
) == BEGV
)
2813 /* Put all the overlays we want in a vector in overlay_vec.
2814 Store the length in len.
2815 prevpos gets the position of an overlay end. */
2816 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2817 (int *) 0, &prevpos
);
2819 /* If any of these overlays starts after prevpos,
2820 maybe use its starting point instead. */
2821 for (i
= 0; i
< noverlays
; i
++)
2826 ostart
= OVERLAY_START (overlay_vec
[i
]);
2827 ostartpos
= OVERLAY_POSITION (ostart
);
2828 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
2829 prevpos
= ostartpos
;
2832 /* If any overlay ends at pos, consider its starting point too. */
2833 for (tail
= current_buffer
->overlays_before
;
2835 tail
= XCONS (tail
)->cdr
)
2837 Lisp_Object overlay
, ostart
;
2840 overlay
= XCONS (tail
)->car
;
2842 ostart
= OVERLAY_START (overlay
);
2843 ostartpos
= OVERLAY_POSITION (ostart
);
2844 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
2845 prevpos
= ostartpos
;
2848 xfree (overlay_vec
);
2849 return make_number (prevpos
);
2852 /* These functions are for debugging overlays. */
2854 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
2855 "Return a pair of lists giving all the overlays of the current buffer.\n\
2856 The car has all the overlays before the overlay center;\n\
2857 the cdr has all the overlays after the overlay center.\n\
2858 Recentering overlays moves overlays between these lists.\n\
2859 The lists you get are copies, so that changing them has no effect.\n\
2860 However, the overlays you get are the real objects that the buffer uses.")
2863 Lisp_Object before
, after
;
2864 before
= current_buffer
->overlays_before
;
2866 before
= Fcopy_sequence (before
);
2867 after
= current_buffer
->overlays_after
;
2869 after
= Fcopy_sequence (after
);
2871 return Fcons (before
, after
);
2874 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
2875 "Recenter the overlays of the current buffer around position POS.")
2879 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2881 recenter_overlay_lists (current_buffer
, XINT (pos
));
2885 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
2886 "Get the property of overlay OVERLAY with property name NAME.")
2888 Lisp_Object overlay
, prop
;
2890 Lisp_Object plist
, fallback
;
2892 CHECK_OVERLAY (overlay
, 0);
2896 for (plist
= XOVERLAY (overlay
)->plist
;
2897 CONSP (plist
) && CONSP (XCONS (plist
)->cdr
);
2898 plist
= XCONS (XCONS (plist
)->cdr
)->cdr
)
2900 if (EQ (XCONS (plist
)->car
, prop
))
2901 return XCONS (XCONS (plist
)->cdr
)->car
;
2902 else if (EQ (XCONS (plist
)->car
, Qcategory
))
2905 tem
= Fcar (Fcdr (plist
));
2907 fallback
= Fget (tem
, prop
);
2914 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
2915 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
2916 (overlay
, prop
, value
)
2917 Lisp_Object overlay
, prop
, value
;
2919 Lisp_Object tail
, buffer
;
2922 CHECK_OVERLAY (overlay
, 0);
2924 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2926 for (tail
= XOVERLAY (overlay
)->plist
;
2927 CONSP (tail
) && CONSP (XCONS (tail
)->cdr
);
2928 tail
= XCONS (XCONS (tail
)->cdr
)->cdr
)
2929 if (EQ (XCONS (tail
)->car
, prop
))
2931 changed
= !EQ (XCONS (XCONS (tail
)->cdr
)->car
, value
);
2932 XCONS (XCONS (tail
)->cdr
)->car
= value
;
2935 /* It wasn't in the list, so add it to the front. */
2936 changed
= !NILP (value
);
2937 XOVERLAY (overlay
)->plist
2938 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
2940 if (! NILP (buffer
))
2943 redisplay_region (XBUFFER (buffer
),
2944 marker_position (OVERLAY_START (overlay
)),
2945 marker_position (OVERLAY_END (overlay
)));
2946 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
2947 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
2948 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
2949 Fdelete_overlay (overlay
);
2954 /* Subroutine of report_overlay_modification. */
2956 /* Lisp vector holding overlay hook functions to call.
2957 Vector elements come in pairs.
2958 Each even-index element is a list of hook functions.
2959 The following odd-index element is the overlay they came from.
2961 Before the buffer change, we fill in this vector
2962 as we call overlay hook functions.
2963 After the buffer change, we get the functions to call from this vector.
2964 This way we always call the same functions before and after the change. */
2965 static Lisp_Object last_overlay_modification_hooks
;
2967 /* Number of elements actually used in last_overlay_modification_hooks. */
2968 static int last_overlay_modification_hooks_used
;
2970 /* Add one functionlist/overlay pair
2971 to the end of last_overlay_modification_hooks. */
2974 add_overlay_mod_hooklist (functionlist
, overlay
)
2975 Lisp_Object functionlist
, overlay
;
2977 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
2979 if (last_overlay_modification_hooks_used
== oldsize
)
2982 old
= last_overlay_modification_hooks
;
2983 last_overlay_modification_hooks
2984 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
2985 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
2986 XVECTOR (old
)->contents
,
2987 sizeof (Lisp_Object
) * oldsize
);
2989 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = functionlist
;
2990 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = overlay
;
2993 /* Run the modification-hooks of overlays that include
2994 any part of the text in START to END.
2995 If this change is an insertion, also
2996 run the insert-before-hooks of overlay starting at END,
2997 and the insert-after-hooks of overlay ending at START.
2999 This is called both before and after the modification.
3000 AFTER is nonzero when we call after the modification.
3002 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3003 When AFTER is nonzero, they are the start position,
3004 the position after the inserted new text,
3005 and the length of deleted or replaced old text. */
3008 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
3009 Lisp_Object start
, end
;
3011 Lisp_Object arg1
, arg2
, arg3
;
3013 Lisp_Object prop
, overlay
, tail
;
3014 /* 1 if this change is an insertion. */
3015 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
3017 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
3021 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
3025 /* Call the functions recorded in last_overlay_modification_hooks
3026 rather than scanning the overlays again.
3027 First copy the vector contents, in case some of these hooks
3028 do subsequent modification of the buffer. */
3029 int size
= last_overlay_modification_hooks_used
;
3030 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
3033 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
3034 copy
, size
* sizeof (Lisp_Object
));
3036 gcpro1
.nvars
= size
;
3038 for (i
= 0; i
< size
;)
3040 Lisp_Object prop
, overlay
;
3042 overlay
= copy
[i
++];
3043 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3049 /* We are being called before a change.
3050 Scan the overlays to find the functions to call. */
3051 last_overlay_modification_hooks_used
= 0;
3053 for (tail
= current_buffer
->overlays_before
;
3055 tail
= XCONS (tail
)->cdr
)
3057 int startpos
, endpos
;
3058 Lisp_Object ostart
, oend
;
3060 overlay
= XCONS (tail
)->car
;
3062 ostart
= OVERLAY_START (overlay
);
3063 oend
= OVERLAY_END (overlay
);
3064 endpos
= OVERLAY_POSITION (oend
);
3065 if (XFASTINT (start
) > endpos
)
3067 startpos
= OVERLAY_POSITION (ostart
);
3068 if (insertion
&& (XFASTINT (start
) == startpos
3069 || XFASTINT (end
) == startpos
))
3071 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3074 /* Copy TAIL in case the hook recenters the overlay lists. */
3076 tail
= Fcopy_sequence (tail
);
3078 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3081 if (insertion
&& (XFASTINT (start
) == endpos
3082 || XFASTINT (end
) == endpos
))
3084 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3088 tail
= Fcopy_sequence (tail
);
3090 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3093 /* Test for intersecting intervals. This does the right thing
3094 for both insertion and deletion. */
3095 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3097 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3101 tail
= Fcopy_sequence (tail
);
3103 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3109 for (tail
= current_buffer
->overlays_after
;
3111 tail
= XCONS (tail
)->cdr
)
3113 int startpos
, endpos
;
3114 Lisp_Object ostart
, oend
;
3116 overlay
= XCONS (tail
)->car
;
3118 ostart
= OVERLAY_START (overlay
);
3119 oend
= OVERLAY_END (overlay
);
3120 startpos
= OVERLAY_POSITION (ostart
);
3121 endpos
= OVERLAY_POSITION (oend
);
3122 if (XFASTINT (end
) < startpos
)
3124 if (insertion
&& (XFASTINT (start
) == startpos
3125 || XFASTINT (end
) == startpos
))
3127 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3131 tail
= Fcopy_sequence (tail
);
3133 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3136 if (insertion
&& (XFASTINT (start
) == endpos
3137 || XFASTINT (end
) == endpos
))
3139 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3143 tail
= Fcopy_sequence (tail
);
3145 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3148 /* Test for intersecting intervals. This does the right thing
3149 for both insertion and deletion. */
3150 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3152 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3156 tail
= Fcopy_sequence (tail
);
3158 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3167 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
3168 Lisp_Object list
, overlay
;
3170 Lisp_Object arg1
, arg2
, arg3
;
3172 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3174 GCPRO4 (list
, arg1
, arg2
, arg3
);
3176 add_overlay_mod_hooklist (list
, overlay
);
3178 while (!NILP (list
))
3181 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
3183 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
3189 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3192 evaporate_overlays (pos
)
3195 Lisp_Object tail
, overlay
, hit_list
;
3198 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
3199 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
3200 tail
= XCONS (tail
)->cdr
)
3203 overlay
= XCONS (tail
)->car
;
3204 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3207 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
3208 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3209 hit_list
= Fcons (overlay
, hit_list
);
3212 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
3213 tail
= XCONS (tail
)->cdr
)
3216 overlay
= XCONS (tail
)->car
;
3217 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3220 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
3221 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3222 hit_list
= Fcons (overlay
, hit_list
);
3224 for (; CONSP (hit_list
); hit_list
= XCONS (hit_list
)->cdr
)
3225 Fdelete_overlay (XCONS (hit_list
)->car
);
3228 /* Somebody has tried to store a value with an unacceptable type
3229 into the buffer-local slot with offset OFFSET. */
3231 buffer_slot_type_mismatch (offset
)
3236 sym
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
);
3237 switch (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
)))
3239 case Lisp_Int
: type_name
= "integers"; break;
3240 case Lisp_String
: type_name
= "strings"; break;
3241 case Lisp_Symbol
: type_name
= "symbols"; break;
3246 error ("only %s should be stored in the buffer-local variable %s",
3247 type_name
, XSYMBOL (sym
)->name
->data
);
3252 register Lisp_Object tem
;
3254 /* Make sure all markable slots in buffer_defaults
3255 are initialized reasonably, so mark_buffer won't choke. */
3256 reset_buffer (&buffer_defaults
);
3257 reset_buffer_local_variables (&buffer_defaults
);
3258 reset_buffer (&buffer_local_symbols
);
3259 reset_buffer_local_variables (&buffer_local_symbols
);
3260 /* Prevent GC from getting confused. */
3261 buffer_defaults
.text
= &buffer_defaults
.own_text
;
3262 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
3263 #ifdef USE_TEXT_PROPERTIES
3264 BUF_INTERVALS (&buffer_defaults
) = 0;
3265 BUF_INTERVALS (&buffer_local_symbols
) = 0;
3267 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
3268 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
3270 /* Set up the default values of various buffer slots. */
3271 /* Must do these before making the first buffer! */
3273 /* real setup is done in loaddefs.el */
3274 buffer_defaults
.mode_line_format
= build_string ("%-");
3275 buffer_defaults
.abbrev_mode
= Qnil
;
3276 buffer_defaults
.overwrite_mode
= Qnil
;
3277 buffer_defaults
.case_fold_search
= Qt
;
3278 buffer_defaults
.auto_fill_function
= Qnil
;
3279 buffer_defaults
.selective_display
= Qnil
;
3281 buffer_defaults
.selective_display_ellipses
= Qt
;
3283 buffer_defaults
.abbrev_table
= Qnil
;
3284 buffer_defaults
.display_table
= Qnil
;
3285 buffer_defaults
.undo_list
= Qnil
;
3286 buffer_defaults
.mark_active
= Qnil
;
3287 buffer_defaults
.file_format
= Qnil
;
3288 buffer_defaults
.overlays_before
= Qnil
;
3289 buffer_defaults
.overlays_after
= Qnil
;
3290 XSETFASTINT (buffer_defaults
.overlay_center
, BEG
);
3292 XSETFASTINT (buffer_defaults
.tab_width
, 8);
3293 buffer_defaults
.truncate_lines
= Qnil
;
3294 buffer_defaults
.ctl_arrow
= Qt
;
3297 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
3299 XSETFASTINT (buffer_defaults
.fill_column
, 70);
3300 XSETFASTINT (buffer_defaults
.left_margin
, 0);
3301 buffer_defaults
.cache_long_line_scans
= Qnil
;
3302 buffer_defaults
.file_truename
= Qnil
;
3304 /* Assign the local-flags to the slots that have default values.
3305 The local flag is a bit that is used in the buffer
3306 to say that it has its own local value for the slot.
3307 The local flag bits are in the local_var_flags slot of the buffer. */
3309 /* Nothing can work if this isn't true */
3310 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
3312 /* 0 means not a lisp var, -1 means always local, else mask */
3313 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
3314 XSETINT (buffer_local_flags
.filename
, -1);
3315 XSETINT (buffer_local_flags
.directory
, -1);
3316 XSETINT (buffer_local_flags
.backed_up
, -1);
3317 XSETINT (buffer_local_flags
.save_length
, -1);
3318 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
3319 XSETINT (buffer_local_flags
.read_only
, -1);
3320 XSETINT (buffer_local_flags
.major_mode
, -1);
3321 XSETINT (buffer_local_flags
.mode_name
, -1);
3322 XSETINT (buffer_local_flags
.undo_list
, -1);
3323 XSETINT (buffer_local_flags
.mark_active
, -1);
3324 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
3325 XSETINT (buffer_local_flags
.file_truename
, -1);
3326 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
3328 XSETFASTINT (buffer_local_flags
.mode_line_format
, 1);
3329 XSETFASTINT (buffer_local_flags
.abbrev_mode
, 2);
3330 XSETFASTINT (buffer_local_flags
.overwrite_mode
, 4);
3331 XSETFASTINT (buffer_local_flags
.case_fold_search
, 8);
3332 XSETFASTINT (buffer_local_flags
.auto_fill_function
, 0x10);
3333 XSETFASTINT (buffer_local_flags
.selective_display
, 0x20);
3335 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, 0x40);
3337 XSETFASTINT (buffer_local_flags
.tab_width
, 0x80);
3338 XSETFASTINT (buffer_local_flags
.truncate_lines
, 0x100);
3339 XSETFASTINT (buffer_local_flags
.ctl_arrow
, 0x200);
3340 XSETFASTINT (buffer_local_flags
.fill_column
, 0x400);
3341 XSETFASTINT (buffer_local_flags
.left_margin
, 0x800);
3342 XSETFASTINT (buffer_local_flags
.abbrev_table
, 0x1000);
3343 XSETFASTINT (buffer_local_flags
.display_table
, 0x2000);
3344 XSETFASTINT (buffer_local_flags
.syntax_table
, 0x8000);
3345 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, 0x10000);
3346 XSETFASTINT (buffer_local_flags
.file_format
, 0x20000);
3348 XSETFASTINT (buffer_local_flags
.buffer_file_type
, 0x4000);
3351 Vbuffer_alist
= Qnil
;
3355 QSFundamental
= build_string ("Fundamental");
3357 Qfundamental_mode
= intern ("fundamental-mode");
3358 buffer_defaults
.major_mode
= Qfundamental_mode
;
3360 Qmode_class
= intern ("mode-class");
3362 Qprotected_field
= intern ("protected-field");
3364 Qpermanent_local
= intern ("permanent-local");
3366 Qkill_buffer_hook
= intern ("kill-buffer-hook");
3368 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
3369 /* super-magic invisible buffer */
3370 Vbuffer_alist
= Qnil
;
3372 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3377 char buf
[MAXPATHLEN
+1];
3379 struct stat dotstat
, pwdstat
;
3383 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3385 /* If PWD is accurate, use it instead of calling getwd. This is faster
3386 when PWD is right, and may avoid a fatal error. */
3387 if ((pwd
= getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd
)
3388 && stat (pwd
, &pwdstat
) == 0
3389 && stat (".", &dotstat
) == 0
3390 && dotstat
.st_ino
== pwdstat
.st_ino
3391 && dotstat
.st_dev
== pwdstat
.st_dev
3392 && strlen (pwd
) < MAXPATHLEN
)
3394 else if (getwd (buf
) == 0)
3395 fatal ("`getwd' failed: %s\n", buf
);
3398 /* Maybe this should really use some standard subroutine
3399 whose definition is filename syntax dependent. */
3401 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
3403 buf
[rc
] = DIRECTORY_SEP
;
3406 #endif /* not VMS */
3407 current_buffer
->directory
= build_string (buf
);
3409 temp
= get_minibuffer (0);
3410 XBUFFER (temp
)->directory
= current_buffer
->directory
;
3413 /* initialize the buffer routines */
3416 extern Lisp_Object Qdisabled
;
3418 staticpro (&last_overlay_modification_hooks
);
3419 last_overlay_modification_hooks
3420 = Fmake_vector (make_number (10), Qnil
);
3422 staticpro (&Vbuffer_defaults
);
3423 staticpro (&Vbuffer_local_symbols
);
3424 staticpro (&Qfundamental_mode
);
3425 staticpro (&Qmode_class
);
3426 staticpro (&QSFundamental
);
3427 staticpro (&Vbuffer_alist
);
3428 staticpro (&Qprotected_field
);
3429 staticpro (&Qpermanent_local
);
3430 staticpro (&Qkill_buffer_hook
);
3431 staticpro (&Qoverlayp
);
3432 Qevaporate
= intern ("evaporate");
3433 staticpro (&Qevaporate
);
3434 staticpro (&Qmodification_hooks
);
3435 Qmodification_hooks
= intern ("modification-hooks");
3436 staticpro (&Qinsert_in_front_hooks
);
3437 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
3438 staticpro (&Qinsert_behind_hooks
);
3439 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
3440 staticpro (&Qget_file_buffer
);
3441 Qget_file_buffer
= intern ("get-file-buffer");
3442 Qpriority
= intern ("priority");
3443 staticpro (&Qpriority
);
3444 Qwindow
= intern ("window");
3445 staticpro (&Qwindow
);
3446 Qbefore_string
= intern ("before-string");
3447 staticpro (&Qbefore_string
);
3448 Qafter_string
= intern ("after-string");
3449 staticpro (&Qafter_string
);
3451 Qoverlayp
= intern ("overlayp");
3453 Fput (Qprotected_field
, Qerror_conditions
,
3454 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
3455 Fput (Qprotected_field
, Qerror_message
,
3456 build_string ("Attempt to modify a protected field"));
3458 /* All these use DEFVAR_LISP_NOPRO because the slots in
3459 buffer_defaults will all be marked via Vbuffer_defaults. */
3461 DEFVAR_LISP_NOPRO ("default-mode-line-format",
3462 &buffer_defaults
.mode_line_format
,
3463 "Default value of `mode-line-format' for buffers that don't override it.\n\
3464 This is the same as (default-value 'mode-line-format).");
3466 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
3467 &buffer_defaults
.abbrev_mode
,
3468 "Default value of `abbrev-mode' for buffers that do not override it.\n\
3469 This is the same as (default-value 'abbrev-mode).");
3471 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
3472 &buffer_defaults
.ctl_arrow
,
3473 "Default value of `ctl-arrow' for buffers that do not override it.\n\
3474 This is the same as (default-value 'ctl-arrow).");
3476 DEFVAR_LISP_NOPRO ("default-truncate-lines",
3477 &buffer_defaults
.truncate_lines
,
3478 "Default value of `truncate-lines' for buffers that do not override it.\n\
3479 This is the same as (default-value 'truncate-lines).");
3481 DEFVAR_LISP_NOPRO ("default-fill-column",
3482 &buffer_defaults
.fill_column
,
3483 "Default value of `fill-column' for buffers that do not override it.\n\
3484 This is the same as (default-value 'fill-column).");
3486 DEFVAR_LISP_NOPRO ("default-left-margin",
3487 &buffer_defaults
.left_margin
,
3488 "Default value of `left-margin' for buffers that do not override it.\n\
3489 This is the same as (default-value 'left-margin).");
3491 DEFVAR_LISP_NOPRO ("default-tab-width",
3492 &buffer_defaults
.tab_width
,
3493 "Default value of `tab-width' for buffers that do not override it.\n\
3494 This is the same as (default-value 'tab-width).");
3496 DEFVAR_LISP_NOPRO ("default-case-fold-search",
3497 &buffer_defaults
.case_fold_search
,
3498 "Default value of `case-fold-search' for buffers that don't override it.\n\
3499 This is the same as (default-value 'case-fold-search).");
3502 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
3503 &buffer_defaults
.buffer_file_type
,
3504 "Default file type for buffers that do not override it.\n\
3505 This is the same as (default-value 'buffer-file-type).\n\
3506 The file type is nil for text, t for binary.");
3509 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
3512 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
3513 But make-docfile finds it!
3514 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
3516 "Template for displaying mode line for current buffer.\n\
3517 Each buffer has its own value of this variable.\n\
3518 Value may be a string, a symbol or a list or cons cell.\n\
3519 For a symbol, its value is used (but it is ignored if t or nil).\n\
3520 A string appearing directly as the value of a symbol is processed verbatim\n\
3521 in that the %-constructs below are not recognized.\n\
3522 For a list whose car is a symbol, the symbol's value is taken,\n\
3523 and if that is non-nil, the cadr of the list is processed recursively.\n\
3524 Otherwise, the caddr of the list (if there is one) is processed.\n\
3525 For a list whose car is a string or list, each element is processed\n\
3526 recursively and the results are effectively concatenated.\n\
3527 For a list whose car is an integer, the cdr of the list is processed\n\
3528 and padded (if the number is positive) or truncated (if negative)\n\
3529 to the width specified by that number.\n\
3530 A string is printed verbatim in the mode line except for %-constructs:\n\
3531 (%-constructs are allowed when the string is the entire mode-line-format\n\
3532 or when it is found in a cons-cell or a list)\n\
3533 %b -- print buffer name. %f -- print visited file name.\n\
3534 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
3535 % means buffer is read-only and * means it is modified.\n\
3536 For a modified read-only buffer, %* gives % and %+ gives *.\n\
3537 %s -- print process status. %l -- print the current line number.\n\
3538 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
3539 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
3540 or print Bottom or All.\n\
3541 %n -- print Narrow if appropriate.\n\
3542 %t -- print T if files is text, B if binary.\n\
3543 %[ -- print one [ for each recursive editing level. %] similar.\n\
3544 %% -- print %. %- -- print infinitely many dashes.\n\
3545 Decimal digits after the % specify field width to which to pad.");
3548 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
3549 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
3550 nil here means use current buffer's major mode.");
3552 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
3553 make_number (Lisp_Symbol
),
3554 "Symbol for current buffer's major mode.");
3556 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
3557 make_number (Lisp_String
),
3558 "Pretty name of current buffer's major mode (a string).");
3560 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
3561 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
3562 Automatically becomes buffer-local when set in any fashion.");
3564 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
3566 "*Non-nil if searches should ignore case.\n\
3567 Automatically becomes buffer-local when set in any fashion.");
3569 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
3570 make_number (Lisp_Int
),
3571 "*Column beyond which automatic line-wrapping should happen.\n\
3572 Automatically becomes buffer-local when set in any fashion.");
3574 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
3575 make_number (Lisp_Int
),
3576 "*Column for the default indent-line-function to indent to.\n\
3577 Linefeed indents to this column in Fundamental mode.\n\
3578 Automatically becomes buffer-local when set in any fashion.");
3580 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
3581 make_number (Lisp_Int
),
3582 "*Distance between tab stops (for display of tab characters), in columns.\n\
3583 Automatically becomes buffer-local when set in any fashion.");
3585 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
3586 "*Non-nil means display control chars with uparrow.\n\
3587 Nil means use backslash and octal digits.\n\
3588 Automatically becomes buffer-local when set in any fashion.\n\
3589 This variable does not apply to characters whose display is specified\n\
3590 in the current display table (if there is one).");
3592 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
3593 "*Non-nil means do not display continuation lines;\n\
3594 give each line of text one screen line.\n\
3595 Automatically becomes buffer-local when set in any fashion.\n\
3597 Note that this is overridden by the variable\n\
3598 `truncate-partial-width-windows' if that variable is non-nil\n\
3599 and this buffer is not full-frame width.");
3602 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
3604 "Non-nil if the visited file is a binary file.\n\
3605 This variable is meaningful on MS-DOG and Windows NT.\n\
3606 On those systems, it is automatically local in every buffer.\n\
3607 On other systems, this variable is normally always nil.");
3610 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
3611 make_number (Lisp_String
),
3612 "Name of default directory of current buffer. Should end with slash.\n\
3613 Each buffer has its own value of this variable.");
3615 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
3617 "Function called (if non-nil) to perform auto-fill.\n\
3618 It is called after self-inserting a space at a column beyond `fill-column'.\n\
3619 Each buffer has its own value of this variable.\n\
3620 NOTE: This variable is not an ordinary hook;\n\
3621 It may not be a list of functions.");
3623 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
3624 make_number (Lisp_String
),
3625 "Name of file visited in current buffer, or nil if not visiting a file.\n\
3626 Each buffer has its own value of this variable.");
3628 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
3629 make_number (Lisp_String
),
3630 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
3631 The truename of a file is calculated by `file-truename'\n\
3632 and then abbreviated with `abbreviate-file-name'.\n\
3633 Each buffer has its own value of this variable.");
3635 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
3636 ¤t_buffer
->auto_save_file_name
,
3637 make_number (Lisp_String
),
3638 "Name of file for auto-saving current buffer,\n\
3639 or nil if buffer should not be auto-saved.\n\
3640 Each buffer has its own value of this variable.");
3642 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
3643 "Non-nil if this buffer is read-only.\n\
3644 Each buffer has its own value of this variable.");
3646 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
3647 "Non-nil if this buffer's file has been backed up.\n\
3648 Backing up is done before the first time the file is saved.\n\
3649 Each buffer has its own value of this variable.");
3651 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
3652 make_number (Lisp_Int
),
3653 "Length of current buffer when last read in, saved or auto-saved.\n\
3655 Each buffer has its own value of this variable.");
3657 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
3659 "Non-nil enables selective display:\n\
3660 Integer N as value means display only lines\n\
3661 that start with less than n columns of space.\n\
3662 A value of t means, after a ^M, all the rest of the line is invisible.\n\
3663 Then ^M's in the file are written into files as newlines.\n\n\
3664 Automatically becomes buffer-local when set in any fashion.");
3667 DEFVAR_PER_BUFFER ("selective-display-ellipses",
3668 ¤t_buffer
->selective_display_ellipses
,
3670 "t means display ... on previous line when a line is invisible.\n\
3671 Automatically becomes buffer-local when set in any fashion.");
3674 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
3675 "Non-nil if self-insertion should replace existing text.\n\
3676 The value should be one of `overwrite-mode-textual',\n\
3677 `overwrite-mode-binary', or nil.\n\
3678 If it is `overwrite-mode-textual', self-insertion still\n\
3679 inserts at the end of a line, and inserts when point is before a tab,\n\
3680 until the tab is filled in.\n\
3681 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
3682 Automatically becomes buffer-local when set in any fashion.");
3684 #if 0 /* The doc string is too long for some compilers,
3685 but make-docfile can find it in this comment. */
3686 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
3688 "Display table that controls display of the contents of current buffer.\n\
3689 Automatically becomes buffer-local when set in any fashion.\n\
3690 The display table is a vector created with `make-display-table'.\n\
3691 The first 256 elements control how to display each possible text character.\n\
3692 Each value should be a vector of characters or nil;\n\
3693 nil means display the character in the default fashion.\n\
3694 The remaining six elements control the display of\n\
3695 the end of a truncated screen line (element 256, a single character);\n\
3696 the end of a continued line (element 257, a single character);\n\
3697 the escape character used to display character codes in octal\n\
3698 (element 258, a single character);\n\
3699 the character used as an arrow for control characters (element 259,\n\
3700 a single character);\n\
3701 the decoration indicating the presence of invisible lines (element 260,\n\
3702 a vector of characters);\n\
3703 the character used to draw the border between side-by-side windows\n\
3704 (element 261, a single character).\n\
3705 If this variable is nil, the value of `standard-display-table' is used.\n\
3706 Each window can have its own, overriding display table.");
3708 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
3711 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
3714 DEFVAR_LISP ("before-change-function", &Vbefore_change_function
,
3715 "Function to call before each text change.\n\
3716 Two arguments are passed to the function: the positions of\n\
3717 the beginning and end of the range of old text to be changed.\n\
3718 \(For an insertion, the beginning and end are at the same place.)\n\
3719 No information is given about the length of the text after the change.\n\
3721 Buffer changes made while executing the `before-change-function'\n\
3722 don't call any before-change or after-change functions.\n\
3723 That's because these variables are temporarily set to nil.\n\
3724 As a result, a hook function cannot straightforwardly alter the value of\n\
3725 these variables. See the Emacs Lisp manual for a way of\n\
3726 accomplishing an equivalent result by using other variables.");
3727 Vbefore_change_function
= Qnil
;
3729 DEFVAR_LISP ("after-change-function", &Vafter_change_function
,
3730 "Function to call after each text change.\n\
3731 Three arguments are passed to the function: the positions of\n\
3732 the beginning and end of the range of changed text,\n\
3733 and the length of the pre-change text replaced by that range.\n\
3734 \(For an insertion, the pre-change length is zero;\n\
3735 for a deletion, that length is the number of characters deleted,\n\
3736 and the post-change beginning and end are at the same place.)\n\
3738 Buffer changes made while executing the `after-change-function'\n\
3739 don't call any before-change or after-change functions.\n\
3740 That's because these variables are temporarily set to nil.\n\
3741 As a result, a hook function cannot straightforwardly alter the value of\n\
3742 these variables. See the Emacs Lisp manual for a way of\n\
3743 accomplishing an equivalent result by using other variables.");
3744 Vafter_change_function
= Qnil
;
3746 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
3747 "List of functions to call before each text change.\n\
3748 Two arguments are passed to each function: the positions of\n\
3749 the beginning and end of the range of old text to be changed.\n\
3750 \(For an insertion, the beginning and end are at the same place.)\n\
3751 No information is given about the length of the text after the change.\n\
3753 Buffer changes made while executing the `before-change-functions'\n\
3754 don't call any before-change or after-change functions.\n\
3755 That's because these variables are temporarily set to nil.\n\
3756 As a result, a hook function cannot straightforwardly alter the value of\n\
3757 these variables. See the Emacs Lisp manual for a way of\n\
3758 accomplishing an equivalent result by using other variables.");
3759 Vbefore_change_functions
= Qnil
;
3761 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
3762 "List of function to call after each text change.\n\
3763 Three arguments are passed to each function: the positions of\n\
3764 the beginning and end of the range of changed text,\n\
3765 and the length of the pre-change text replaced by that range.\n\
3766 \(For an insertion, the pre-change length is zero;\n\
3767 for a deletion, that length is the number of characters deleted,\n\
3768 and the post-change beginning and end are at the same place.)\n\
3770 Buffer changes made while executing the `after-change-functions'\n\
3771 don't call any before-change or after-change functions.\n\
3772 That's because these variables are temporarily set to nil.\n\
3773 As a result, a hook function cannot straightforwardly alter the value of\n\
3774 these variables. See the Emacs Lisp manual for a way of\n\
3775 accomplishing an equivalent result by using other variables.");
3777 Vafter_change_functions
= Qnil
;
3779 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
3780 "A list of functions to call before changing a buffer which is unmodified.\n\
3781 The functions are run using the `run-hooks' function.");
3782 Vfirst_change_hook
= Qnil
;
3783 Qfirst_change_hook
= intern ("first-change-hook");
3784 staticpro (&Qfirst_change_hook
);
3786 #if 0 /* The doc string is too long for some compilers,
3787 but make-docfile can find it in this comment. */
3788 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
3789 "List of undo entries in current buffer.\n\
3790 Recent changes come first; older changes follow newer.\n\
3792 An entry (BEG . END) represents an insertion which begins at\n\
3793 position BEG and ends at position END.\n\
3795 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
3796 from (abs POSITION). If POSITION is positive, point was at the front\n\
3797 of the text being deleted; if negative, point was at the end.\n\
3799 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
3800 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
3801 of the visited file's modification time, as of that time. If the\n\
3802 modification time of the most recent save is different, this entry is\n\
3805 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
3806 was modified between BEG and END. PROPERTY is the property name,\n\
3807 and VALUE is the old value.\n\
3809 An entry of the form POSITION indicates that point was at the buffer\n\
3810 location given by the integer. Undoing an entry of this form places\n\
3811 point at POSITION.\n\
3813 nil marks undo boundaries. The undo command treats the changes\n\
3814 between two undo boundaries as a single step to be undone.\n\
3816 If the value of the variable is t, undo information is not recorded.");
3818 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
3821 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
3822 "Non-nil means the mark and region are currently active in this buffer.\n\
3823 Automatically local in all buffers.");
3825 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
3826 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
3827 This variable is buffer-local, in all buffers.\n\
3829 Normally, the line-motion functions work by scanning the buffer for\n\
3830 newlines. Columnar operations (like move-to-column and\n\
3831 compute-motion) also work by scanning the buffer, summing character\n\
3832 widths as they go. This works well for ordinary text, but if the\n\
3833 buffer's lines are very long (say, more than 500 characters), these\n\
3834 motion functions will take longer to execute. Emacs may also take\n\
3835 longer to update the display.\n\
3837 If cache-long-line-scans is non-nil, these motion functions cache the\n\
3838 results of their scans, and consult the cache to avoid rescanning\n\
3839 regions of the buffer until the text is modified. The caches are most\n\
3840 beneficial when they prevent the most searching---that is, when the\n\
3841 buffer contains long lines and large regions of characters with the\n\
3842 same, fixed screen width.\n\
3844 When cache-long-line-scans is non-nil, processing short lines will\n\
3845 become slightly slower (because of the overhead of consulting the\n\
3846 cache), and the caches will use memory roughly proportional to the\n\
3847 number of newlines and characters whose screen width varies.\n\
3849 The caches require no explicit maintenance; their accuracy is\n\
3850 maintained internally by the Emacs primitives. Enabling or disabling\n\
3851 the cache should not affect the behavior of any of the motion\n\
3852 functions; it should only affect their performance.");
3854 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
3855 "Value of point before the last series of scroll operations, or nil.");
3857 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
3858 "List of formats to use when saving this buffer.\n\
3859 Formats are defined by `format-alist'. This variable is\n\
3860 set when a file is visited. Automatically local in all buffers.");
3862 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
3863 ¤t_buffer
->invisibility_spec
, Qnil
,
3864 "Invisibility spec of this buffer.\n\
3865 The default is t, which means that text is invisible\n\
3866 if it has a non-nil `invisible' property.\n\
3867 If the value is a list, a text character is invisible if its `invisible'\n\
3868 property is an element in that list.\n\
3869 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
3870 then characters with property value PROP are invisible,\n\
3871 and they have an ellipsis as well if ELLIPSIS is non-nil.");
3873 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
3874 "*Non-nil means deactivate the mark when the buffer contents change.");
3875 Vtransient_mark_mode
= Qnil
;
3877 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
3878 "*Non-nil means disregard read-only status of buffers or characters.\n\
3879 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
3880 text properties. If the value is a list, disregard `buffer-read-only'\n\
3881 and disregard a `read-only' text property if the property value\n\
3882 is a member of the list.");
3883 Vinhibit_read_only
= Qnil
;
3885 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
3886 "List of functions called with no args to query before killing a buffer.");
3887 Vkill_buffer_query_functions
= Qnil
;
3889 defsubr (&Sbuffer_list
);
3890 defsubr (&Sget_buffer
);
3891 defsubr (&Sget_file_buffer
);
3892 defsubr (&Sget_buffer_create
);
3893 defsubr (&Smake_indirect_buffer
);
3894 defsubr (&Sgenerate_new_buffer_name
);
3895 defsubr (&Sbuffer_name
);
3896 /*defsubr (&Sbuffer_number);*/
3897 defsubr (&Sbuffer_file_name
);
3898 defsubr (&Sbuffer_base_buffer
);
3899 defsubr (&Sbuffer_local_variables
);
3900 defsubr (&Sbuffer_modified_p
);
3901 defsubr (&Sset_buffer_modified_p
);
3902 defsubr (&Sbuffer_modified_tick
);
3903 defsubr (&Srename_buffer
);
3904 defsubr (&Sother_buffer
);
3905 defsubr (&Sbuffer_disable_undo
);
3906 defsubr (&Sbuffer_enable_undo
);
3907 defsubr (&Skill_buffer
);
3908 defsubr (&Serase_buffer
);
3909 defsubr (&Sset_buffer_major_mode
);
3910 defsubr (&Sswitch_to_buffer
);
3911 defsubr (&Spop_to_buffer
);
3912 defsubr (&Scurrent_buffer
);
3913 defsubr (&Sset_buffer
);
3914 defsubr (&Sbarf_if_buffer_read_only
);
3915 defsubr (&Sbury_buffer
);
3916 defsubr (&Skill_all_local_variables
);
3918 defsubr (&Soverlayp
);
3919 defsubr (&Smake_overlay
);
3920 defsubr (&Sdelete_overlay
);
3921 defsubr (&Smove_overlay
);
3922 defsubr (&Soverlay_start
);
3923 defsubr (&Soverlay_end
);
3924 defsubr (&Soverlay_buffer
);
3925 defsubr (&Soverlay_properties
);
3926 defsubr (&Soverlays_at
);
3927 defsubr (&Soverlays_in
);
3928 defsubr (&Snext_overlay_change
);
3929 defsubr (&Sprevious_overlay_change
);
3930 defsubr (&Soverlay_recenter
);
3931 defsubr (&Soverlay_lists
);
3932 defsubr (&Soverlay_get
);
3933 defsubr (&Soverlay_put
);
3938 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
3939 initial_define_key (control_x_map
, 'k', "kill-buffer");
3941 /* This must not be in syms_of_buffer, because Qdisabled is not
3942 initialized when that function gets called. */
3943 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);