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 static void call_overlay_mod_hooks ();
104 static void swap_out_buffer_local_variables ();
106 /* Alist of all buffer names vs the buffers. */
107 /* This used to be a variable, but is no longer,
108 to prevent lossage due to user rplac'ing this alist or its elements. */
109 Lisp_Object Vbuffer_alist
;
111 /* Functions to call before and after each text change. */
112 Lisp_Object Vbefore_change_function
;
113 Lisp_Object Vafter_change_function
;
114 Lisp_Object Vbefore_change_functions
;
115 Lisp_Object Vafter_change_functions
;
117 Lisp_Object Vtransient_mark_mode
;
119 /* t means ignore all read-only text properties.
120 A list means ignore such a property if its value is a member of the list.
121 Any non-nil value means ignore buffer-read-only. */
122 Lisp_Object Vinhibit_read_only
;
124 /* List of functions to call that can query about killing a buffer.
125 If any of these functions returns nil, we don't kill it. */
126 Lisp_Object Vkill_buffer_query_functions
;
128 /* List of functions to call before changing an unmodified buffer. */
129 Lisp_Object Vfirst_change_hook
;
130 Lisp_Object Qfirst_change_hook
;
132 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
134 Lisp_Object Qprotected_field
;
136 Lisp_Object QSFundamental
; /* A string "Fundamental" */
138 Lisp_Object Qkill_buffer_hook
;
140 Lisp_Object Qget_file_buffer
;
142 Lisp_Object Qoverlayp
;
144 Lisp_Object Qpriority
, Qwindow
, Qevaporate
;
146 Lisp_Object Qmodification_hooks
;
147 Lisp_Object Qinsert_in_front_hooks
;
148 Lisp_Object Qinsert_behind_hooks
;
150 /* For debugging; temporary. See set_buffer_internal. */
151 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
157 error ("No buffer named %s", XSTRING (spec
)->data
);
158 error ("Invalid buffer argument");
161 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 0, 0,
162 "Return a list of all existing live buffers.")
165 return Fmapcar (Qcdr
, Vbuffer_alist
);
168 /* Like Fassoc, but use Fstring_equal to compare
169 (which ignores text properties),
170 and don't ever QUIT. */
173 assoc_ignore_text_properties (key
, list
)
174 register Lisp_Object key
;
177 register Lisp_Object tail
;
178 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
180 register Lisp_Object elt
, tem
;
182 tem
= Fstring_equal (Fcar (elt
), key
);
189 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
190 "Return the buffer named NAME (a string).\n\
191 If there is no live buffer named NAME, return nil.\n\
192 NAME may also be a buffer; if so, the value is that buffer.")
194 register Lisp_Object name
;
198 CHECK_STRING (name
, 0);
200 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
203 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
204 "Return the buffer visiting file FILENAME (a string).\n\
205 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
206 If there is no such live buffer, return nil.\n\
207 See also `find-buffer-visiting'.")
209 register Lisp_Object filename
;
211 register Lisp_Object tail
, buf
, tem
;
214 CHECK_STRING (filename
, 0);
215 filename
= Fexpand_file_name (filename
, Qnil
);
217 /* If the file name has special constructs in it,
218 call the corresponding file handler. */
219 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
221 return call2 (handler
, Qget_file_buffer
, filename
);
223 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
225 buf
= Fcdr (XCONS (tail
)->car
);
226 if (!BUFFERP (buf
)) continue;
227 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
228 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
235 /* Incremented for each buffer created, to assign the buffer number. */
238 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
239 "Return the buffer named NAME, or create such a buffer and return it.\n\
240 A new buffer is created if there is no live buffer named NAME.\n\
241 If NAME starts with a space, the new buffer does not keep undo information.\n\
242 If NAME is a buffer instead of a string, then it is the value returned.\n\
243 The value is never nil.")
245 register Lisp_Object name
;
247 register Lisp_Object buf
;
248 register struct buffer
*b
;
250 buf
= Fget_buffer (name
);
254 if (XSTRING (name
)->size
== 0)
255 error ("Empty string for buffer name is not allowed");
257 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
259 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
261 /* An ordinary buffer uses its own struct buffer_text. */
262 b
->text
= &b
->own_text
;
265 BUF_GAP_SIZE (b
) = 20;
267 BUFFER_ALLOC (BUF_BEG_ADDR (b
), BUF_GAP_SIZE (b
));
269 if (! BUF_BEG_ADDR (b
))
270 buffer_memory_full ();
278 BUF_SAVE_MODIFF (b
) = 1;
279 BUF_INTERVALS (b
) = 0;
281 b
->newline_cache
= 0;
282 b
->width_run_cache
= 0;
283 b
->width_table
= Qnil
;
285 /* Put this on the chain of all buffers including killed ones. */
286 b
->next
= all_buffers
;
289 /* An ordinary buffer normally doesn't need markers
290 to handle BEGV and ZV. */
292 b
->begv_marker
= Qnil
;
295 name
= Fcopy_sequence (name
);
296 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
299 if (XSTRING (name
)->data
[0] != ' ')
305 reset_buffer_local_variables (b
);
307 /* Put this in the alist of all live buffers. */
309 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
311 b
->mark
= Fmake_marker ();
312 BUF_MARKERS (b
) = Qnil
;
317 DEFUN ("make-indirect-buffer",
318 Fmake_indirect_buffer
, Smake_indirect_buffer
, 2, 2,
319 "BMake indirect buffer (to buffer): \nbName of indirect buffer: ",
320 "Create and return an indirect buffer for buffer BASE, named NAME.\n\
321 BASE should be an existing buffer (or buffer name).\n\
322 NAME should be a string which is not the name of an existing buffer.")
324 register Lisp_Object base_buffer
, name
;
326 register Lisp_Object buf
;
327 register struct buffer
*b
;
329 buf
= Fget_buffer (name
);
331 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
333 base_buffer
= Fget_buffer (base_buffer
);
334 if (NILP (base_buffer
))
335 error ("No such buffer: `%s'",
336 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
338 if (XSTRING (name
)->size
== 0)
339 error ("Empty string for buffer name is not allowed");
341 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
343 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
345 if (XBUFFER (base_buffer
)->base_buffer
)
346 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
348 b
->base_buffer
= XBUFFER (base_buffer
);
350 /* Use the base buffer's text object. */
351 b
->text
= b
->base_buffer
->text
;
353 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
354 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
355 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
357 b
->newline_cache
= 0;
358 b
->width_run_cache
= 0;
359 b
->width_table
= Qnil
;
361 /* Put this on the chain of all buffers including killed ones. */
362 b
->next
= all_buffers
;
365 name
= Fcopy_sequence (name
);
366 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
370 reset_buffer_local_variables (b
);
372 /* Put this in the alist of all live buffers. */
374 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
376 b
->mark
= Fmake_marker ();
379 /* Make sure the base buffer has markers for its narrowing. */
380 if (NILP (b
->base_buffer
->pt_marker
))
382 b
->base_buffer
->pt_marker
= Fmake_marker ();
383 Fset_marker (b
->base_buffer
->pt_marker
,
384 make_number (BUF_PT (b
->base_buffer
)), base_buffer
);
386 if (NILP (b
->base_buffer
->begv_marker
))
388 b
->base_buffer
->begv_marker
= Fmake_marker ();
389 Fset_marker (b
->base_buffer
->begv_marker
,
390 make_number (BUF_BEGV (b
->base_buffer
)), base_buffer
);
392 if (NILP (b
->base_buffer
->zv_marker
))
394 b
->base_buffer
->zv_marker
= Fmake_marker ();
395 Fset_marker (b
->base_buffer
->zv_marker
,
396 make_number (BUF_ZV (b
->base_buffer
)), base_buffer
);
399 /* Give the indirect buffer markers for its narrowing. */
400 b
->pt_marker
= Fpoint_marker ();
401 b
->begv_marker
= Fpoint_min_marker ();
402 b
->zv_marker
= Fpoint_max_marker ();
407 /* Reinitialize everything about a buffer except its name and contents
408 and local variables. */
412 register struct buffer
*b
;
415 b
->file_truename
= Qnil
;
416 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
418 XSETFASTINT (b
->save_length
, 0);
419 b
->last_window_start
= 1;
421 b
->auto_save_modified
= 0;
422 b
->auto_save_failure_time
= -1;
423 b
->auto_save_file_name
= Qnil
;
425 b
->overlays_before
= Qnil
;
426 b
->overlays_after
= Qnil
;
427 XSETFASTINT (b
->overlay_center
, 1);
428 b
->mark_active
= Qnil
;
429 b
->point_before_scroll
= Qnil
;
430 b
->file_format
= Qnil
;
433 /* Reset buffer B's local variables info.
434 Don't use this on a buffer that has already been in use;
435 it does not treat permanent locals consistently.
436 Instead, use Fkill_all_local_variables. */
438 reset_buffer_local_variables (b
)
439 register struct buffer
*b
;
443 /* Reset the major mode to Fundamental, together with all the
444 things that depend on the major mode.
445 default-major-mode is handled at a higher level.
446 We ignore it here. */
447 b
->major_mode
= Qfundamental_mode
;
449 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
450 b
->mode_name
= QSFundamental
;
451 b
->minor_modes
= Qnil
;
452 b
->downcase_table
= Vascii_downcase_table
;
453 b
->upcase_table
= Vascii_upcase_table
;
454 b
->case_canon_table
= Vascii_canon_table
;
455 b
->case_eqv_table
= Vascii_eqv_table
;
456 b
->buffer_file_type
= Qnil
;
457 b
->invisibility_spec
= Qt
;
460 b
->sort_table
= XSTRING (Vascii_sort_table
);
461 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
464 /* Reset all per-buffer variables to their defaults. */
465 b
->local_var_alist
= Qnil
;
466 b
->local_var_flags
= 0;
468 /* For each slot that has a default value,
469 copy that into the slot. */
471 for (offset
= (char *)&buffer_local_flags
.name
- (char *)&buffer_local_flags
;
472 offset
< sizeof (struct buffer
);
473 offset
+= sizeof (Lisp_Object
)) /* sizeof EMACS_INT == sizeof Lisp_Object */
475 int flag
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
476 if (flag
> 0 || flag
== -2)
477 *(Lisp_Object
*)(offset
+ (char *)b
) =
478 *(Lisp_Object
*)(offset
+ (char *)&buffer_defaults
);
482 /* We split this away from generate-new-buffer, because rename-buffer
483 and set-visited-file-name ought to be able to use this to really
484 rename the buffer properly. */
486 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
488 "Return a string that is the name of no existing buffer based on NAME.\n\
489 If there is no live buffer named NAME, then return NAME.\n\
490 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
491 until an unused name is found, and then return that name.\n\
492 Optional second argument IGNORE specifies a name that is okay to use\n\
493 \(if it is in the sequence to be tried)\n\
494 even if a buffer with that name exists.")
496 register Lisp_Object name
, ignore
;
498 register Lisp_Object gentemp
, tem
;
502 CHECK_STRING (name
, 0);
504 tem
= Fget_buffer (name
);
511 sprintf (number
, "<%d>", ++count
);
512 gentemp
= concat2 (name
, build_string (number
));
513 tem
= Fstring_equal (gentemp
, ignore
);
516 tem
= Fget_buffer (gentemp
);
523 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
524 "Return the name of BUFFER, as a string.\n\
525 With no argument or nil as argument, return the name of the current buffer.")
527 register Lisp_Object buffer
;
530 return current_buffer
->name
;
531 CHECK_BUFFER (buffer
, 0);
532 return XBUFFER (buffer
)->name
;
535 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
536 "Return name of file BUFFER is visiting, or nil if none.\n\
537 No argument or nil as argument means use the current buffer.")
539 register Lisp_Object buffer
;
542 return current_buffer
->filename
;
543 CHECK_BUFFER (buffer
, 0);
544 return XBUFFER (buffer
)->filename
;
547 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
549 "Return the base buffer of indirect buffer BUFFER.\n\
550 If BUFFER is not indirect, return nil.")
552 register Lisp_Object buffer
;
555 Lisp_Object base_buffer
;
558 base
= current_buffer
->base_buffer
;
561 CHECK_BUFFER (buffer
, 0);
562 base
= XBUFFER (buffer
)->base_buffer
;
567 XSETBUFFER (base_buffer
, base
);
571 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
572 Sbuffer_local_variables
, 0, 1, 0,
573 "Return an alist of variables that are buffer-local in BUFFER.\n\
574 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
575 For a symbol that is locally unbound, just the symbol appears in the value.\n\
576 Note that storing new VALUEs in these elements doesn't change the variables.\n\
577 No argument or nil as argument means use current buffer as BUFFER.")
579 register Lisp_Object buffer
;
581 register struct buffer
*buf
;
582 register Lisp_Object result
;
585 buf
= current_buffer
;
588 CHECK_BUFFER (buffer
, 0);
589 buf
= XBUFFER (buffer
);
595 register Lisp_Object tail
;
596 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
598 Lisp_Object val
, elt
;
600 elt
= XCONS (tail
)->car
;
602 /* Reference each variable in the alist in buf.
603 If inquiring about the current buffer, this gets the current values,
604 so store them into the alist so the alist is up to date.
605 If inquiring about some other buffer, this swaps out any values
606 for that buffer, making the alist up to date automatically. */
607 val
= find_symbol_value (XCONS (elt
)->car
);
608 /* Use the current buffer value only if buf is the current buffer. */
609 if (buf
!= current_buffer
)
610 val
= XCONS (elt
)->cdr
;
612 /* If symbol is unbound, put just the symbol in the list. */
613 if (EQ (val
, Qunbound
))
614 result
= Fcons (XCONS (elt
)->car
, result
);
615 /* Otherwise, put (symbol . value) in the list. */
617 result
= Fcons (Fcons (XCONS (elt
)->car
, val
), result
);
621 /* Add on all the variables stored in special slots. */
623 register int offset
, mask
;
625 for (offset
= (char *)&buffer_local_symbols
.name
- (char *)&buffer_local_symbols
;
626 offset
< sizeof (struct buffer
);
627 offset
+= (sizeof (EMACS_INT
))) /* sizeof EMACS_INT == sizeof Lisp_Object */
629 mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
630 if (mask
== -1 || (buf
->local_var_flags
& mask
))
631 if (SYMBOLP (*(Lisp_Object
*)(offset
632 + (char *)&buffer_local_symbols
)))
633 result
= Fcons (Fcons (*((Lisp_Object
*)
634 (offset
+ (char *)&buffer_local_symbols
)),
635 *(Lisp_Object
*)(offset
+ (char *)buf
)),
644 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
646 "Return t if BUFFER was modified since its file was last read or saved.\n\
647 No argument or nil as argument means use current buffer as BUFFER.")
649 register Lisp_Object buffer
;
651 register struct buffer
*buf
;
653 buf
= current_buffer
;
656 CHECK_BUFFER (buffer
, 0);
657 buf
= XBUFFER (buffer
);
660 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
663 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
665 "Mark current buffer as modified or unmodified according to FLAG.\n\
666 A non-nil FLAG means mark the buffer modified.")
668 register Lisp_Object flag
;
670 register int already
;
671 register Lisp_Object fn
;
673 #ifdef CLASH_DETECTION
674 /* If buffer becoming modified, lock the file.
675 If buffer becoming unmodified, unlock the file. */
677 fn
= current_buffer
->filename
;
680 already
= SAVE_MODIFF
< MODIFF
;
681 if (!already
&& !NILP (flag
))
683 else if (already
&& NILP (flag
))
686 #endif /* CLASH_DETECTION */
688 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
693 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
695 "Return BUFFER's tick counter, incremented for each change in text.\n\
696 Each buffer has a tick counter which is incremented each time the text in\n\
697 that buffer is changed. It wraps around occasionally.\n\
698 No argument or nil as argument means use current buffer as BUFFER.")
700 register Lisp_Object buffer
;
702 register struct buffer
*buf
;
704 buf
= current_buffer
;
707 CHECK_BUFFER (buffer
, 0);
708 buf
= XBUFFER (buffer
);
711 return make_number (BUF_MODIFF (buf
));
714 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
715 "sRename buffer (to new name): \nP",
716 "Change current buffer's name to NEWNAME (a string).\n\
717 If second arg UNIQUE is nil or omitted, it is an error if a\n\
718 buffer named NEWNAME already exists.\n\
719 If UNIQUE is non-nil, come up with a new name using\n\
720 `generate-new-buffer-name'.\n\
721 Interactively, you can set UNIQUE with a prefix argument.\n\
722 We return the name we actually gave the buffer.\n\
723 This does not change the name of the visited file (if any).")
725 register Lisp_Object newname
, unique
;
727 register Lisp_Object tem
, buf
;
729 CHECK_STRING (newname
, 0);
731 if (XSTRING (newname
)->size
== 0)
732 error ("Empty string is invalid as a buffer name");
734 tem
= Fget_buffer (newname
);
735 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
736 the buffer automatically so you can create another with the original name.
737 It makes UNIQUE equivalent to
738 (rename-buffer (generate-new-buffer-name NEWNAME)). */
739 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
740 return current_buffer
->name
;
744 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
746 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
749 current_buffer
->name
= newname
;
751 /* Catch redisplay's attention. Unless we do this, the mode lines for
752 any windows displaying current_buffer will stay unchanged. */
755 XSETBUFFER (buf
, current_buffer
);
756 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
757 if (NILP (current_buffer
->filename
)
758 && !NILP (current_buffer
->auto_save_file_name
))
759 call0 (intern ("rename-auto-save-file"));
760 /* Refetch since that last call may have done GC. */
761 return current_buffer
->name
;
764 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 2, 0,
765 "Return most recently selected buffer other than BUFFER.\n\
766 Buffers not visible in windows are preferred to visible buffers,\n\
767 unless optional second argument VISIBLE-OK is non-nil.\n\
768 If no other buffer exists, the buffer `*scratch*' is returned.\n\
769 If BUFFER is omitted or nil, some interesting buffer is returned.")
771 register Lisp_Object buffer
, visible_ok
;
773 register Lisp_Object tail
, buf
, notsogood
, tem
;
776 for (tail
= Vbuffer_alist
; !NILP (tail
); tail
= Fcdr (tail
))
778 buf
= Fcdr (Fcar (tail
));
779 if (EQ (buf
, buffer
))
781 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
784 /* If the selected frame has a buffer_predicate,
785 disregard buffers that don't fit the predicate. */
786 tem
= frame_buffer_predicate ();
789 tem
= call1 (tem
, buf
);
795 if (NILP (visible_ok
))
796 tem
= Fget_buffer_window (buf
, Qt
);
801 if (NILP (notsogood
))
804 if (!NILP (notsogood
))
806 return Fget_buffer_create (build_string ("*scratch*"));
809 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
, 0, 1,
811 "Make BUFFER stop keeping undo information.\n\
812 No argument or nil as argument means do this for the current buffer.")
814 register Lisp_Object buffer
;
816 Lisp_Object real_buffer
;
819 XSETBUFFER (real_buffer
, current_buffer
);
822 real_buffer
= Fget_buffer (buffer
);
823 if (NILP (real_buffer
))
827 XBUFFER (real_buffer
)->undo_list
= Qt
;
832 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
834 "Start keeping undo information for buffer BUFFER.\n\
835 No argument or nil as argument means do this for the current buffer.")
837 register Lisp_Object buffer
;
839 Lisp_Object real_buffer
;
842 XSETBUFFER (real_buffer
, current_buffer
);
845 real_buffer
= Fget_buffer (buffer
);
846 if (NILP (real_buffer
))
850 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
851 XBUFFER (real_buffer
)->undo_list
= Qnil
;
857 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
858 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
859 The buffer being killed will be current while the hook is running.\n\
862 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
863 "Kill the buffer BUFFER.\n\
864 The argument may be a buffer or may be the name of a buffer.\n\
865 An argument of nil means kill the current buffer.\n\n\
866 Value is t if the buffer is actually killed, nil if user says no.\n\n\
867 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
868 if not void, is a list of functions to be called, with no arguments,\n\
869 before the buffer is actually killed. The buffer to be killed is current\n\
870 when the hook functions are called.\n\n\
871 Any processes that have this buffer as the `process-buffer' are killed\n\
872 with `delete-process'.")
877 register struct buffer
*b
;
878 register Lisp_Object tem
;
879 register struct Lisp_Marker
*m
;
880 struct gcpro gcpro1
, gcpro2
;
883 buf
= Fcurrent_buffer ();
885 buf
= Fget_buffer (bufname
);
891 /* Query if the buffer is still modified. */
892 if (INTERACTIVE
&& !NILP (b
->filename
)
893 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
895 GCPRO2 (buf
, bufname
);
896 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
897 XSTRING (b
->name
)->data
));
903 /* Run hooks with the buffer to be killed the current buffer. */
905 register Lisp_Object val
;
906 int count
= specpdl_ptr
- specpdl
;
909 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
910 set_buffer_internal (b
);
912 /* First run the query functions; if any query is answered no,
913 don't kill the buffer. */
914 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
916 tem
= call0 (Fcar (list
));
918 return unbind_to (count
, Qnil
);
921 /* Then run the hooks. */
922 if (!NILP (Vrun_hooks
))
923 call1 (Vrun_hooks
, Qkill_buffer_hook
);
924 unbind_to (count
, Qnil
);
927 /* We have no more questions to ask. Verify that it is valid
928 to kill the buffer. This must be done after the questions
929 since anything can happen within do_yes_or_no_p. */
931 /* Don't kill the minibuffer now current. */
932 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
938 /* When we kill a base buffer, kill all its indirect buffers.
939 We do it at this stage so nothing terrible happens if they
940 ask questions or their hooks get errors. */
941 if (! b
->base_buffer
)
943 struct buffer
*other
;
947 for (other
= all_buffers
; other
; other
= other
->next
)
948 if (other
->base_buffer
== b
)
951 XSETBUFFER (buf
, other
);
958 /* Make this buffer not be current.
959 In the process, notice if this is the sole visible buffer
960 and give up if so. */
961 if (b
== current_buffer
)
963 tem
= Fother_buffer (buf
, Qnil
);
965 if (b
== current_buffer
)
969 /* Now there is no question: we can kill the buffer. */
971 #ifdef CLASH_DETECTION
972 /* Unlock this buffer's file, if it is locked. */
974 #endif /* CLASH_DETECTION */
976 kill_buffer_processes (buf
);
980 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
981 Freplace_buffer_in_windows (buf
);
984 /* Delete any auto-save file, if we saved it in this session. */
985 if (STRINGP (b
->auto_save_file_name
)
986 && b
->auto_save_modified
!= 0)
989 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
991 internal_delete_file (b
->auto_save_file_name
);
994 if (! b
->base_buffer
)
996 /* Unchain all markers of this buffer
997 and leave them pointing nowhere. */
998 for (tem
= BUF_MARKERS (b
); !EQ (tem
, Qnil
); )
1005 BUF_MARKERS (b
) = Qnil
;
1007 #ifdef USE_TEXT_PROPERTIES
1008 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1011 /* Perhaps we should explicitly free the interval tree here... */
1014 /* Reset the local variables, so that this buffer's local values
1015 won't be protected from GC. They would be protected
1016 if they happened to remain encached in their symbols.
1017 This gets rid of them for certain. */
1018 swap_out_buffer_local_variables (b
);
1019 reset_buffer_local_variables (b
);
1024 if (! b
->base_buffer
)
1025 BUFFER_FREE (BUF_BEG_ADDR (b
));
1027 if (b
->newline_cache
)
1029 free_region_cache (b
->newline_cache
);
1030 b
->newline_cache
= 0;
1032 if (b
->width_run_cache
)
1034 free_region_cache (b
->width_run_cache
);
1035 b
->width_run_cache
= 0;
1037 b
->width_table
= Qnil
;
1039 b
->undo_list
= Qnil
;
1044 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1045 we do this each time BUF is selected visibly, the more recently
1046 selected buffers are always closer to the front of the list. This
1047 means that other_buffer is more likely to choose a relevant buffer. */
1052 register Lisp_Object link
, prev
;
1055 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCONS (link
)->cdr
)
1057 if (EQ (XCONS (XCONS (link
)->car
)->cdr
, buf
))
1062 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1063 we cannot use Fdelq itself here because it allows quitting. */
1066 Vbuffer_alist
= XCONS (Vbuffer_alist
)->cdr
;
1068 XCONS (prev
)->cdr
= XCONS (XCONS (prev
)->cdr
)->cdr
;
1070 XCONS(link
)->cdr
= Vbuffer_alist
;
1071 Vbuffer_alist
= link
;
1074 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1075 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1076 Use this function before selecting the buffer, since it may need to inspect\n\
1077 the current buffer's major mode.")
1082 Lisp_Object function
;
1084 function
= buffer_defaults
.major_mode
;
1085 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1086 function
= current_buffer
->major_mode
;
1088 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1091 count
= specpdl_ptr
- specpdl
;
1093 /* To select a nonfundamental mode,
1094 select the buffer temporarily and then call the mode function. */
1096 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1101 return unbind_to (count
, Qnil
);
1104 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1105 "Select buffer BUFFER in the current window.\n\
1106 BUFFER may be a buffer or a buffer name.\n\
1107 Optional second arg NORECORD non-nil means\n\
1108 do not put this buffer at the front of the list of recently selected ones.\n\
1110 WARNING: This is NOT the way to work on another buffer temporarily\n\
1111 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1112 the window-buffer correspondences.")
1114 Lisp_Object bufname
, norecord
;
1116 register Lisp_Object buf
;
1119 if (EQ (minibuf_window
, selected_window
))
1120 error ("Cannot switch buffers in minibuffer window");
1121 tem
= Fwindow_dedicated_p (selected_window
);
1123 error ("Cannot switch buffers in a dedicated window");
1126 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1129 buf
= Fget_buffer (bufname
);
1132 buf
= Fget_buffer_create (bufname
);
1133 Fset_buffer_major_mode (buf
);
1137 if (NILP (norecord
))
1138 record_buffer (buf
);
1140 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1141 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1148 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 2, 0,
1149 "Select buffer BUFFER in some window, preferably a different one.\n\
1150 If BUFFER is nil, then some other buffer is chosen.\n\
1151 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1152 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1153 window even if BUFFER is already visible in the selected window.")
1155 Lisp_Object bufname
, other
;
1157 register Lisp_Object buf
;
1159 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1162 buf
= Fget_buffer (bufname
);
1165 buf
= Fget_buffer_create (bufname
);
1166 Fset_buffer_major_mode (buf
);
1170 record_buffer (buf
);
1171 Fselect_window (Fdisplay_buffer (buf
, other
));
1175 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1176 "Return the current buffer as a Lisp object.")
1179 register Lisp_Object buf
;
1180 XSETBUFFER (buf
, current_buffer
);
1184 /* Set the current buffer to b */
1187 set_buffer_internal (b
)
1188 register struct buffer
*b
;
1190 register struct buffer
*old_buf
;
1191 register Lisp_Object tail
, valcontents
;
1194 if (current_buffer
== b
)
1197 windows_or_buffers_changed
= 1;
1198 old_buf
= current_buffer
;
1200 last_known_column_point
= -1; /* invalidate indentation cache */
1204 /* Put the undo list back in the base buffer, so that it appears
1205 that an indirect buffer shares the undo list of its base. */
1206 if (old_buf
->base_buffer
)
1207 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1209 /* If the old current buffer has markers to record PT, BEGV and ZV
1210 when it is not current, update them now. */
1211 if (! NILP (old_buf
->pt_marker
))
1214 XSETBUFFER (obuf
, old_buf
);
1215 Fset_marker (old_buf
->pt_marker
, BUF_PT (old_buf
), obuf
);
1217 if (! NILP (old_buf
->begv_marker
))
1220 XSETBUFFER (obuf
, old_buf
);
1221 Fset_marker (old_buf
->begv_marker
, BUF_BEGV (old_buf
), obuf
);
1223 if (! NILP (old_buf
->zv_marker
))
1226 XSETBUFFER (obuf
, old_buf
);
1227 Fset_marker (old_buf
->zv_marker
, BUF_ZV (old_buf
), obuf
);
1231 /* Get the undo list from the base buffer, so that it appears
1232 that an indirect buffer shares the undo list of its base. */
1234 b
->undo_list
= b
->base_buffer
->undo_list
;
1236 /* If the new current buffer has markers to record PT, BEGV and ZV
1237 when it is not current, fetch them now. */
1238 if (! NILP (b
->pt_marker
))
1239 BUF_PT (b
) = marker_position (b
->pt_marker
);
1240 if (! NILP (b
->begv_marker
))
1241 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1242 if (! NILP (b
->zv_marker
))
1243 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1245 /* Look down buffer's list of local Lisp variables
1246 to find and update any that forward into C variables. */
1248 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1250 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1251 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1252 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1253 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1254 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1255 /* Just reference the variable
1256 to cause it to become set for this buffer. */
1257 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1260 /* Do the same with any others that were local to the previous buffer */
1263 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1265 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1266 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1267 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1268 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1269 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1270 /* Just reference the variable
1271 to cause it to become set for this buffer. */
1272 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1276 /* Switch to buffer B temporarily for redisplay purposes.
1277 This avoids certain things thatdon't need to be done within redisplay. */
1283 register struct buffer
*old_buf
;
1285 if (current_buffer
== b
)
1288 old_buf
= current_buffer
;
1293 /* If the old current buffer has markers to record PT, BEGV and ZV
1294 when it is not current, update them now. */
1295 if (! NILP (old_buf
->pt_marker
))
1298 XSETBUFFER (obuf
, old_buf
);
1299 Fset_marker (old_buf
->pt_marker
, BUF_PT (old_buf
), obuf
);
1301 if (! NILP (old_buf
->begv_marker
))
1304 XSETBUFFER (obuf
, old_buf
);
1305 Fset_marker (old_buf
->begv_marker
, BUF_BEGV (old_buf
), obuf
);
1307 if (! NILP (old_buf
->zv_marker
))
1310 XSETBUFFER (obuf
, old_buf
);
1311 Fset_marker (old_buf
->zv_marker
, BUF_ZV (old_buf
), obuf
);
1315 /* If the new current buffer has markers to record PT, BEGV and ZV
1316 when it is not current, fetch them now. */
1317 if (! NILP (b
->pt_marker
))
1318 BUF_PT (b
) = marker_position (b
->pt_marker
);
1319 if (! NILP (b
->begv_marker
))
1320 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1321 if (! NILP (b
->zv_marker
))
1322 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1325 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1326 "Make the buffer BUFFER current for editing operations.\n\
1327 BUFFER may be a buffer or the name of an existing buffer.\n\
1328 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1329 This function does not display the buffer, so its effect ends\n\
1330 when the current command terminates.\n\
1331 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1333 register Lisp_Object bufname
;
1335 register Lisp_Object buffer
;
1336 buffer
= Fget_buffer (bufname
);
1339 if (NILP (XBUFFER (buffer
)->name
))
1340 error ("Selecting deleted buffer");
1341 set_buffer_internal (XBUFFER (buffer
));
1345 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1346 Sbarf_if_buffer_read_only
, 0, 0, 0,
1347 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1350 if (!NILP (current_buffer
->read_only
)
1351 && NILP (Vinhibit_read_only
))
1352 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1356 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1357 "Put BUFFER at the end of the list of all buffers.\n\
1358 There it is the least likely candidate for `other-buffer' to return;\n\
1359 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1360 If BUFFER is nil or omitted, bury the current buffer.\n\
1361 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1362 selected window if it is displayed there.")
1364 register Lisp_Object buf
;
1366 /* Figure out what buffer we're going to bury. */
1369 XSETBUFFER (buf
, current_buffer
);
1371 /* If we're burying the current buffer, unshow it. */
1372 Fswitch_to_buffer (Fother_buffer (buf
, Qnil
), Qnil
);
1378 buf1
= Fget_buffer (buf
);
1384 /* Move buf to the end of the buffer list. */
1386 register Lisp_Object aelt
, link
;
1388 aelt
= Frassq (buf
, Vbuffer_alist
);
1389 link
= Fmemq (aelt
, Vbuffer_alist
);
1390 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1391 XCONS (link
)->cdr
= Qnil
;
1392 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1398 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1399 "Delete the entire contents of the current buffer.\n\
1400 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1401 so the buffer is truly empty after this.")
1406 current_buffer
->last_window_start
= 1;
1407 /* Prevent warnings, or suspension of auto saving, that would happen
1408 if future size is less than past size. Use of erase-buffer
1409 implies that the future text is not really related to the past text. */
1410 XSETFASTINT (current_buffer
->save_length
, 0);
1414 validate_region (b
, e
)
1415 register Lisp_Object
*b
, *e
;
1417 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1418 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1420 if (XINT (*b
) > XINT (*e
))
1423 tem
= *b
; *b
= *e
; *e
= tem
;
1426 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1427 && XINT (*e
) <= ZV
))
1428 args_out_of_range (*b
, *e
);
1431 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
1433 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1434 Most local variable bindings are eliminated so that the default values\n\
1435 become effective once more. Also, the syntax table is set from\n\
1436 `standard-syntax-table', the local keymap is set to nil,\n\
1437 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1438 This function also forces redisplay of the mode line.\n\
1440 Every function to select a new major mode starts by\n\
1441 calling this function.\n\n\
1442 As a special exception, local variables whose names have\n\
1443 a non-nil `permanent-local' property are not eliminated by this function.\n\
1445 The first thing this function does is run\n\
1446 the normal hook `change-major-mode-hook'.")
1449 register Lisp_Object alist
, sym
, tem
;
1452 if (!NILP (Vrun_hooks
))
1453 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
1454 oalist
= current_buffer
->local_var_alist
;
1456 /* Make sure none of the bindings in oalist
1457 remain swapped in, in their symbols. */
1459 swap_out_buffer_local_variables (current_buffer
);
1461 /* Actually eliminate all local bindings of this buffer. */
1463 reset_buffer_local_variables (current_buffer
);
1465 /* Redisplay mode lines; we are changing major mode. */
1467 update_mode_lines
++;
1469 /* Any which are supposed to be permanent,
1470 make local again, with the same values they had. */
1472 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1474 sym
= XCONS (XCONS (alist
)->car
)->car
;
1475 tem
= Fget (sym
, Qpermanent_local
);
1478 Fmake_local_variable (sym
);
1479 Fset (sym
, XCONS (XCONS (alist
)->car
)->cdr
);
1483 /* Force mode-line redisplay. Useful here because all major mode
1484 commands call this function. */
1485 update_mode_lines
++;
1490 /* Make sure no local variables remain set up with buffer B
1491 for their current values. */
1494 swap_out_buffer_local_variables (b
)
1497 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
1499 XSETBUFFER (buffer
, b
);
1500 oalist
= b
->local_var_alist
;
1502 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1504 sym
= XCONS (XCONS (alist
)->car
)->car
;
1506 /* Need not do anything if some other buffer's binding is now encached. */
1507 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
;
1508 if (XBUFFER (tem
) == current_buffer
)
1510 /* Symbol is set up for this buffer's old local value.
1511 Set it up for the current buffer with the default value. */
1513 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->cdr
;
1514 /* Store the symbol's current value into the alist entry
1515 it is currently set up for. This is so that, if the
1516 local is marked permanent, and we make it local again
1517 later in Fkill_all_local_variables, we don't lose the value. */
1518 XCONS (XCONS (tem
)->car
)->cdr
1519 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
);
1520 /* Switch to the symbol's default-value alist entry. */
1521 XCONS (tem
)->car
= tem
;
1522 /* Mark it as current for buffer B. */
1523 XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
1525 /* Store the current value into any forwarding in the symbol. */
1526 store_symval_forwarding (sym
, XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
,
1532 /* Find all the overlays in the current buffer that contain position POS.
1533 Return the number found, and store them in a vector in *VEC_PTR.
1534 Store in *LEN_PTR the size allocated for the vector.
1535 Store in *NEXT_PTR the next position after POS where an overlay starts,
1536 or ZV if there are no more overlays.
1537 Store in *PREV_PTR the previous position after POS where an overlay ends,
1538 or BEGV if there are no previous overlays.
1539 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1541 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1542 when this function is called.
1544 If EXTEND is non-zero, we make the vector bigger if necessary.
1545 If EXTEND is zero, we never extend the vector,
1546 and we store only as many overlays as will fit.
1547 But we still return the total number of overlays. */
1550 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1553 Lisp_Object
**vec_ptr
;
1558 Lisp_Object tail
, overlay
, start
, end
, result
;
1561 Lisp_Object
*vec
= *vec_ptr
;
1564 int inhibit_storing
= 0;
1566 for (tail
= current_buffer
->overlays_before
;
1568 tail
= XCONS (tail
)->cdr
)
1570 int startpos
, endpos
;
1572 overlay
= XCONS (tail
)->car
;
1574 start
= OVERLAY_START (overlay
);
1575 end
= OVERLAY_END (overlay
);
1576 endpos
= OVERLAY_POSITION (end
);
1585 startpos
= OVERLAY_POSITION (start
);
1586 if (startpos
<= pos
)
1590 /* The supplied vector is full.
1591 Either make it bigger, or don't store any more in it. */
1594 *len_ptr
= len
*= 2;
1595 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1599 inhibit_storing
= 1;
1602 if (!inhibit_storing
)
1604 /* Keep counting overlays even if we can't return them all. */
1607 else if (startpos
< next
)
1611 for (tail
= current_buffer
->overlays_after
;
1613 tail
= XCONS (tail
)->cdr
)
1615 int startpos
, endpos
;
1617 overlay
= XCONS (tail
)->car
;
1619 start
= OVERLAY_START (overlay
);
1620 end
= OVERLAY_END (overlay
);
1621 startpos
= OVERLAY_POSITION (start
);
1624 if (startpos
< next
)
1628 endpos
= OVERLAY_POSITION (end
);
1635 *len_ptr
= len
*= 2;
1636 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1640 inhibit_storing
= 1;
1643 if (!inhibit_storing
)
1647 else if (endpos
< pos
&& endpos
> prev
)
1658 /* Fast function to just test if we're at an overlay boundary. */
1660 overlay_touches_p (pos
)
1663 Lisp_Object tail
, overlay
;
1665 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
1666 tail
= XCONS (tail
)->cdr
)
1670 overlay
= XCONS (tail
)->car
;
1671 if (!GC_OVERLAYP (overlay
))
1674 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
1677 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
1681 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
1682 tail
= XCONS (tail
)->cdr
)
1686 overlay
= XCONS (tail
)->car
;
1687 if (!GC_OVERLAYP (overlay
))
1690 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
1693 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
1701 Lisp_Object overlay
;
1707 compare_overlays (s1
, s2
)
1708 struct sortvec
*s1
, *s2
;
1710 if (s1
->priority
!= s2
->priority
)
1711 return s1
->priority
- s2
->priority
;
1712 if (s1
->beg
!= s2
->beg
)
1713 return s1
->beg
- s2
->beg
;
1714 if (s1
->end
!= s2
->end
)
1715 return s2
->end
- s1
->end
;
1719 /* Sort an array of overlays by priority. The array is modified in place.
1720 The return value is the new size; this may be smaller than the original
1721 size if some of the overlays were invalid or were window-specific. */
1723 sort_overlays (overlay_vec
, noverlays
, w
)
1724 Lisp_Object
*overlay_vec
;
1729 struct sortvec
*sortvec
;
1730 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
1732 /* Put the valid and relevant overlays into sortvec. */
1734 for (i
= 0, j
= 0; i
< noverlays
; i
++)
1737 Lisp_Object overlay
;
1739 overlay
= overlay_vec
[i
];
1740 if (OVERLAY_VALID (overlay
)
1741 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
1742 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
1744 /* If we're interested in a specific window, then ignore
1745 overlays that are limited to some other window. */
1750 window
= Foverlay_get (overlay
, Qwindow
);
1751 if (WINDOWP (window
) && XWINDOW (window
) != w
)
1755 /* This overlay is good and counts: put it into sortvec. */
1756 sortvec
[j
].overlay
= overlay
;
1757 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
1758 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
1759 tem
= Foverlay_get (overlay
, Qpriority
);
1761 sortvec
[j
].priority
= XINT (tem
);
1763 sortvec
[j
].priority
= 0;
1769 /* Sort the overlays into the proper order: increasing priority. */
1772 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
1774 for (i
= 0; i
< noverlays
; i
++)
1775 overlay_vec
[i
] = sortvec
[i
].overlay
;
1779 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
1782 recenter_overlay_lists (buf
, pos
)
1786 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
1788 /* See if anything in overlays_before should move to overlays_after. */
1790 /* We don't strictly need prev in this loop; it should always be nil.
1791 But we use it for symmetry and in case that should cease to be true
1792 with some future change. */
1794 for (tail
= buf
->overlays_before
;
1796 prev
= tail
, tail
= next
)
1798 next
= XCONS (tail
)->cdr
;
1799 overlay
= XCONS (tail
)->car
;
1801 /* If the overlay is not valid, get rid of it. */
1802 if (!OVERLAY_VALID (overlay
))
1807 /* Splice the cons cell TAIL out of overlays_before. */
1809 XCONS (prev
)->cdr
= next
;
1811 buf
->overlays_before
= next
;
1817 beg
= OVERLAY_START (overlay
);
1818 end
= OVERLAY_END (overlay
);
1820 if (OVERLAY_POSITION (end
) > pos
)
1822 /* OVERLAY needs to be moved. */
1823 int where
= OVERLAY_POSITION (beg
);
1824 Lisp_Object other
, other_prev
;
1826 /* Splice the cons cell TAIL out of overlays_before. */
1828 XCONS (prev
)->cdr
= next
;
1830 buf
->overlays_before
= next
;
1832 /* Search thru overlays_after for where to put it. */
1834 for (other
= buf
->overlays_after
;
1836 other_prev
= other
, other
= XCONS (other
)->cdr
)
1838 Lisp_Object otherbeg
, otheroverlay
, follower
;
1841 otheroverlay
= XCONS (other
)->car
;
1842 if (! OVERLAY_VALID (otheroverlay
))
1845 otherbeg
= OVERLAY_START (otheroverlay
);
1846 if (OVERLAY_POSITION (otherbeg
) >= where
)
1850 /* Add TAIL to overlays_after before OTHER. */
1851 XCONS (tail
)->cdr
= other
;
1852 if (!NILP (other_prev
))
1853 XCONS (other_prev
)->cdr
= tail
;
1855 buf
->overlays_after
= tail
;
1859 /* We've reached the things that should stay in overlays_before.
1860 All the rest of overlays_before must end even earlier,
1865 /* See if anything in overlays_after should be in overlays_before. */
1867 for (tail
= buf
->overlays_after
;
1869 prev
= tail
, tail
= next
)
1871 next
= XCONS (tail
)->cdr
;
1872 overlay
= XCONS (tail
)->car
;
1874 /* If the overlay is not valid, get rid of it. */
1875 if (!OVERLAY_VALID (overlay
))
1880 /* Splice the cons cell TAIL out of overlays_after. */
1882 XCONS (prev
)->cdr
= next
;
1884 buf
->overlays_after
= next
;
1890 beg
= OVERLAY_START (overlay
);
1891 end
= OVERLAY_END (overlay
);
1893 /* Stop looking, when we know that nothing further
1894 can possibly end before POS. */
1895 if (OVERLAY_POSITION (beg
) > pos
)
1898 if (OVERLAY_POSITION (end
) <= pos
)
1900 /* OVERLAY needs to be moved. */
1901 int where
= OVERLAY_POSITION (end
);
1902 Lisp_Object other
, other_prev
;
1904 /* Splice the cons cell TAIL out of overlays_after. */
1906 XCONS (prev
)->cdr
= next
;
1908 buf
->overlays_after
= next
;
1910 /* Search thru overlays_before for where to put it. */
1912 for (other
= buf
->overlays_before
;
1914 other_prev
= other
, other
= XCONS (other
)->cdr
)
1916 Lisp_Object otherend
, otheroverlay
;
1919 otheroverlay
= XCONS (other
)->car
;
1920 if (! OVERLAY_VALID (otheroverlay
))
1923 otherend
= OVERLAY_END (otheroverlay
);
1924 if (OVERLAY_POSITION (otherend
) <= where
)
1928 /* Add TAIL to overlays_before before OTHER. */
1929 XCONS (tail
)->cdr
= other
;
1930 if (!NILP (other_prev
))
1931 XCONS (other_prev
)->cdr
= tail
;
1933 buf
->overlays_before
= tail
;
1938 XSETFASTINT (buf
->overlay_center
, pos
);
1942 adjust_overlays_for_insert (pos
, length
)
1946 /* After an insertion, the lists are still sorted properly,
1947 but we may need to update the value of the overlay center. */
1948 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
1949 XSETFASTINT (current_buffer
->overlay_center
,
1950 XFASTINT (current_buffer
->overlay_center
) + length
);
1954 adjust_overlays_for_delete (pos
, length
)
1958 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
1959 /* The deletion was to our right. No change needed; the before- and
1960 after-lists are still consistent. */
1962 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
1963 /* The deletion was to our left. We need to adjust the center value
1964 to account for the change in position, but the lists are consistent
1965 given the new value. */
1966 XSETFASTINT (current_buffer
->overlay_center
,
1967 XFASTINT (current_buffer
->overlay_center
) - length
);
1969 /* We're right in the middle. There might be things on the after-list
1970 that now belong on the before-list. Recentering will move them,
1971 and also update the center point. */
1972 recenter_overlay_lists (current_buffer
, pos
);
1975 /* Fix up overlays that were garbled as a result of permuting markers
1976 in the range START through END. Any overlay with at least one
1977 endpoint in this range will need to be unlinked from the overlay
1978 list and reinserted in its proper place.
1979 Such an overlay might even have negative size at this point.
1980 If so, we'll reverse the endpoints. Can you think of anything
1981 better to do in this situation? */
1983 fix_overlays_in_range (start
, end
)
1984 register int start
, end
;
1986 Lisp_Object tem
, overlay
;
1987 Lisp_Object before_list
, after_list
;
1988 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
1989 int startpos
, endpos
;
1991 /* This algorithm shifts links around instead of consing and GCing.
1992 The loop invariant is that before_list (resp. after_list) is a
1993 well-formed list except that its last element, the one that
1994 *pbefore (resp. *pafter) points to, is still uninitialized.
1995 So it's not a bug that before_list isn't initialized, although
1996 it may look strange. */
1997 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
1999 overlay
= XCONS (*ptail
)->car
;
2000 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2003 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2005 || (startpos
>= start
&& startpos
< end
))
2007 /* If the overlay is backwards, fix that now. */
2008 if (startpos
> endpos
)
2011 Fset_marker (OVERLAY_START (overlay
), endpos
, Qnil
);
2012 Fset_marker (OVERLAY_END (overlay
), startpos
, Qnil
);
2013 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2015 /* Add it to the end of the wrong list. Later on,
2016 recenter_overlay_lists will move it to the right place. */
2017 if (endpos
< XINT (current_buffer
->overlay_center
))
2020 pafter
= &XCONS (*ptail
)->cdr
;
2025 pbefore
= &XCONS (*ptail
)->cdr
;
2027 *ptail
= XCONS (*ptail
)->cdr
;
2030 ptail
= &XCONS (*ptail
)->cdr
;
2032 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
2034 overlay
= XCONS (*ptail
)->car
;
2035 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2036 if (startpos
>= end
)
2038 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2039 if (startpos
>= start
2040 || (endpos
>= start
&& endpos
< end
))
2042 if (startpos
> endpos
)
2045 Fset_marker (OVERLAY_START (overlay
), endpos
, Qnil
);
2046 Fset_marker (OVERLAY_END (overlay
), startpos
, Qnil
);
2047 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2049 if (endpos
< XINT (current_buffer
->overlay_center
))
2052 pafter
= &XCONS (*ptail
)->cdr
;
2057 pbefore
= &XCONS (*ptail
)->cdr
;
2059 *ptail
= XCONS (*ptail
)->cdr
;
2062 ptail
= &XCONS (*ptail
)->cdr
;
2065 /* Splice the constructed (wrong) lists into the buffer's lists,
2066 and let the recenter function make it sane again. */
2067 *pbefore
= current_buffer
->overlays_before
;
2068 current_buffer
->overlays_before
= before_list
;
2069 recenter_overlay_lists (current_buffer
,
2070 XINT (current_buffer
->overlay_center
));
2072 *pafter
= current_buffer
->overlays_after
;
2073 current_buffer
->overlays_after
= after_list
;
2074 recenter_overlay_lists (current_buffer
,
2075 XINT (current_buffer
->overlay_center
));
2078 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
2079 "Return t if OBJECT is an overlay.")
2083 return (OVERLAYP (object
) ? Qt
: Qnil
);
2086 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 3, 0,
2087 "Create a new overlay with range BEG to END in BUFFER.\n\
2088 If omitted, BUFFER defaults to the current buffer.\n\
2089 BEG and END may be integers or markers.")
2091 Lisp_Object beg
, end
, buffer
;
2093 Lisp_Object overlay
;
2097 XSETBUFFER (buffer
, current_buffer
);
2099 CHECK_BUFFER (buffer
, 2);
2101 && ! EQ (Fmarker_buffer (beg
), buffer
))
2102 error ("Marker points into wrong buffer");
2104 && ! EQ (Fmarker_buffer (end
), buffer
))
2105 error ("Marker points into wrong buffer");
2107 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2108 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2110 if (XINT (beg
) > XINT (end
))
2113 temp
= beg
; beg
= end
; end
= temp
;
2116 b
= XBUFFER (buffer
);
2118 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
2119 end
= Fset_marker (Fmake_marker (), end
, buffer
);
2121 overlay
= allocate_misc ();
2122 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
2123 XOVERLAY (overlay
)->start
= beg
;
2124 XOVERLAY (overlay
)->end
= end
;
2125 XOVERLAY (overlay
)->plist
= Qnil
;
2127 /* Put the new overlay on the wrong list. */
2128 end
= OVERLAY_END (overlay
);
2129 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2130 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2132 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2134 /* This puts it in the right list, and in the right order. */
2135 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2137 /* We don't need to redisplay the region covered by the overlay, because
2138 the overlay has no properties at the moment. */
2143 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
2144 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
2145 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
2146 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
2148 (overlay
, beg
, end
, buffer
)
2149 Lisp_Object overlay
, beg
, end
, buffer
;
2151 struct buffer
*b
, *ob
;
2152 Lisp_Object obuffer
;
2153 int count
= specpdl_ptr
- specpdl
;
2155 CHECK_OVERLAY (overlay
, 0);
2157 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2159 XSETBUFFER (buffer
, current_buffer
);
2160 CHECK_BUFFER (buffer
, 3);
2163 && ! EQ (Fmarker_buffer (beg
), buffer
))
2164 error ("Marker points into wrong buffer");
2166 && ! EQ (Fmarker_buffer (end
), buffer
))
2167 error ("Marker points into wrong buffer");
2169 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2170 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2172 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
2173 return Fdelete_overlay (overlay
);
2175 if (XINT (beg
) > XINT (end
))
2178 temp
= beg
; beg
= end
; end
= temp
;
2181 specbind (Qinhibit_quit
, Qt
);
2183 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2184 b
= XBUFFER (buffer
);
2185 ob
= XBUFFER (obuffer
);
2187 /* If the overlay has changed buffers, do a thorough redisplay. */
2188 if (!EQ (buffer
, obuffer
))
2190 /* Redisplay where the overlay was. */
2191 if (!NILP (obuffer
))
2196 o_beg
= OVERLAY_START (overlay
);
2197 o_end
= OVERLAY_END (overlay
);
2198 o_beg
= OVERLAY_POSITION (o_beg
);
2199 o_end
= OVERLAY_POSITION (o_end
);
2201 redisplay_region (ob
, XINT (o_beg
), XINT (o_end
));
2204 /* Redisplay where the overlay is going to be. */
2205 redisplay_region (b
, XINT (beg
), XINT (end
));
2207 /* Don't limit redisplay to the selected window. */
2208 windows_or_buffers_changed
= 1;
2211 /* Redisplay the area the overlay has just left, or just enclosed. */
2215 int change_beg
, change_end
;
2217 o_beg
= OVERLAY_START (overlay
);
2218 o_end
= OVERLAY_END (overlay
);
2219 o_beg
= OVERLAY_POSITION (o_beg
);
2220 o_end
= OVERLAY_POSITION (o_end
);
2222 if (XINT (o_beg
) == XINT (beg
))
2223 redisplay_region (b
, XINT (o_end
), XINT (end
));
2224 else if (XINT (o_end
) == XINT (end
))
2225 redisplay_region (b
, XINT (o_beg
), XINT (beg
));
2228 if (XINT (beg
) < XINT (o_beg
)) o_beg
= beg
;
2229 if (XINT (end
) > XINT (o_end
)) o_end
= end
;
2230 redisplay_region (b
, XINT (o_beg
), XINT (o_end
));
2234 if (!NILP (obuffer
))
2236 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
2237 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
2240 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
2241 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
2243 /* Put the overlay on the wrong list. */
2244 end
= OVERLAY_END (overlay
);
2245 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2246 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2248 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2250 /* This puts it in the right list, and in the right order. */
2251 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2253 return unbind_to (count
, overlay
);
2256 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
2257 "Delete the overlay OVERLAY from its buffer.")
2259 Lisp_Object overlay
;
2263 int count
= specpdl_ptr
- specpdl
;
2265 CHECK_OVERLAY (overlay
, 0);
2267 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2271 b
= XBUFFER (buffer
);
2273 specbind (Qinhibit_quit
, Qt
);
2275 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
2276 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
2278 redisplay_region (b
,
2279 marker_position (OVERLAY_START (overlay
)),
2280 marker_position (OVERLAY_END (overlay
)));
2282 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
2283 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
2285 return unbind_to (count
, Qnil
);
2288 /* Overlay dissection functions. */
2290 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
2291 "Return the position at which OVERLAY starts.")
2293 Lisp_Object overlay
;
2295 CHECK_OVERLAY (overlay
, 0);
2297 return (Fmarker_position (OVERLAY_START (overlay
)));
2300 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
2301 "Return the position at which OVERLAY ends.")
2303 Lisp_Object overlay
;
2305 CHECK_OVERLAY (overlay
, 0);
2307 return (Fmarker_position (OVERLAY_END (overlay
)));
2310 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
2311 "Return the buffer OVERLAY belongs to.")
2313 Lisp_Object overlay
;
2315 CHECK_OVERLAY (overlay
, 0);
2317 return Fmarker_buffer (OVERLAY_START (overlay
));
2320 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
2321 "Return a list of the properties on OVERLAY.\n\
2322 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
2325 Lisp_Object overlay
;
2327 CHECK_OVERLAY (overlay
, 0);
2329 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
2333 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
2334 "Return a list of the overlays that contain position POS.")
2339 Lisp_Object
*overlay_vec
;
2343 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2346 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2348 /* Put all the overlays we want in a vector in overlay_vec.
2349 Store the length in len. */
2350 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2351 (int *) 0, (int *) 0);
2353 /* Make a list of them all. */
2354 result
= Flist (noverlays
, overlay_vec
);
2356 xfree (overlay_vec
);
2360 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
2362 "Return the next position after POS where an overlay starts or ends.\n\
2363 If there are no more overlay boundaries after POS, return (point-max).")
2369 Lisp_Object
*overlay_vec
;
2373 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2376 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2378 /* Put all the overlays we want in a vector in overlay_vec.
2379 Store the length in len.
2380 endpos gets the position where the next overlay starts. */
2381 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2382 &endpos
, (int *) 0);
2384 /* If any of these overlays ends before endpos,
2385 use its ending point instead. */
2386 for (i
= 0; i
< noverlays
; i
++)
2391 oend
= OVERLAY_END (overlay_vec
[i
]);
2392 oendpos
= OVERLAY_POSITION (oend
);
2393 if (oendpos
< endpos
)
2397 xfree (overlay_vec
);
2398 return make_number (endpos
);
2401 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
2402 Sprevious_overlay_change
, 1, 1, 0,
2403 "Return the previous position before POS where an overlay starts or ends.\n\
2404 If there are no more overlay boundaries after POS, return (point-min).")
2410 Lisp_Object
*overlay_vec
;
2414 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2417 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2419 /* Put all the overlays we want in a vector in overlay_vec.
2420 Store the length in len.
2421 prevpos gets the position of an overlay end. */
2422 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2423 (int *) 0, &prevpos
);
2425 /* If any of these overlays starts before endpos,
2426 maybe use its starting point instead. */
2427 for (i
= 0; i
< noverlays
; i
++)
2432 ostart
= OVERLAY_START (overlay_vec
[i
]);
2433 ostartpos
= OVERLAY_POSITION (ostart
);
2434 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
2435 prevpos
= ostartpos
;
2438 xfree (overlay_vec
);
2439 return make_number (prevpos
);
2442 /* These functions are for debugging overlays. */
2444 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
2445 "Return a pair of lists giving all the overlays of the current buffer.\n\
2446 The car has all the overlays before the overlay center;\n\
2447 the cdr has all the overlays after the overlay center.\n\
2448 Recentering overlays moves overlays between these lists.\n\
2449 The lists you get are copies, so that changing them has no effect.\n\
2450 However, the overlays you get are the real objects that the buffer uses.")
2453 Lisp_Object before
, after
;
2454 before
= current_buffer
->overlays_before
;
2456 before
= Fcopy_sequence (before
);
2457 after
= current_buffer
->overlays_after
;
2459 after
= Fcopy_sequence (after
);
2461 return Fcons (before
, after
);
2464 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
2465 "Recenter the overlays of the current buffer around position POS.")
2469 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
2471 recenter_overlay_lists (current_buffer
, XINT (pos
));
2475 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
2476 "Get the property of overlay OVERLAY with property name NAME.")
2478 Lisp_Object overlay
, prop
;
2480 Lisp_Object plist
, fallback
;
2482 CHECK_OVERLAY (overlay
, 0);
2486 for (plist
= XOVERLAY (overlay
)->plist
;
2487 CONSP (plist
) && CONSP (XCONS (plist
)->cdr
);
2488 plist
= XCONS (XCONS (plist
)->cdr
)->cdr
)
2490 if (EQ (XCONS (plist
)->car
, prop
))
2491 return XCONS (XCONS (plist
)->cdr
)->car
;
2492 else if (EQ (XCONS (plist
)->car
, Qcategory
))
2495 tem
= Fcar (Fcdr (plist
));
2497 fallback
= Fget (tem
, prop
);
2504 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
2505 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
2506 (overlay
, prop
, value
)
2507 Lisp_Object overlay
, prop
, value
;
2509 Lisp_Object tail
, buffer
;
2512 CHECK_OVERLAY (overlay
, 0);
2514 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2516 for (tail
= XOVERLAY (overlay
)->plist
;
2517 CONSP (tail
) && CONSP (XCONS (tail
)->cdr
);
2518 tail
= XCONS (XCONS (tail
)->cdr
)->cdr
)
2519 if (EQ (XCONS (tail
)->car
, prop
))
2521 changed
= !EQ (XCONS (XCONS (tail
)->cdr
)->car
, value
);
2522 XCONS (XCONS (tail
)->cdr
)->car
= value
;
2525 /* It wasn't in the list, so add it to the front. */
2526 changed
= !NILP (value
);
2527 XOVERLAY (overlay
)->plist
2528 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
2530 if (! NILP (buffer
))
2533 redisplay_region (XBUFFER (buffer
),
2534 marker_position (OVERLAY_START (overlay
)),
2535 marker_position (OVERLAY_END (overlay
)));
2536 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
2537 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
2538 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
2539 Fdelete_overlay (overlay
);
2544 /* Run the modification-hooks of overlays that include
2545 any part of the text in START to END.
2546 Run the insert-before-hooks of overlay starting at END,
2547 and the insert-after-hooks of overlay ending at START.
2549 This is called both before and after the modification.
2550 AFTER is nonzero when we call after the modification.
2552 ARG1, ARG2, ARG3 are arguments to pass to the hook functions. */
2555 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
2556 Lisp_Object start
, end
;
2558 Lisp_Object arg1
, arg2
, arg3
;
2560 Lisp_Object prop
, overlay
, tail
;
2561 int insertion
= EQ (start
, end
);
2563 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
2567 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
2570 for (tail
= current_buffer
->overlays_before
;
2572 tail
= XCONS (tail
)->cdr
)
2574 int startpos
, endpos
;
2575 Lisp_Object ostart
, oend
;
2577 overlay
= XCONS (tail
)->car
;
2579 ostart
= OVERLAY_START (overlay
);
2580 oend
= OVERLAY_END (overlay
);
2581 endpos
= OVERLAY_POSITION (oend
);
2582 if (XFASTINT (start
) > endpos
)
2584 startpos
= OVERLAY_POSITION (ostart
);
2585 if (XFASTINT (end
) == startpos
&& insertion
)
2587 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
2590 /* Copy TAIL in case the hook recenters the overlay lists. */
2592 tail
= Fcopy_sequence (tail
);
2594 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
2597 if (XFASTINT (start
) == endpos
&& insertion
)
2599 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
2603 tail
= Fcopy_sequence (tail
);
2605 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
2608 /* Test for intersecting intervals. This does the right thing
2609 for both insertion and deletion. */
2610 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
2612 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
2616 tail
= Fcopy_sequence (tail
);
2618 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
2624 for (tail
= current_buffer
->overlays_after
;
2626 tail
= XCONS (tail
)->cdr
)
2628 int startpos
, endpos
;
2629 Lisp_Object ostart
, oend
;
2631 overlay
= XCONS (tail
)->car
;
2633 ostart
= OVERLAY_START (overlay
);
2634 oend
= OVERLAY_END (overlay
);
2635 startpos
= OVERLAY_POSITION (ostart
);
2636 endpos
= OVERLAY_POSITION (oend
);
2637 if (XFASTINT (end
) < startpos
)
2639 if (XFASTINT (end
) == startpos
&& insertion
)
2641 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
2645 tail
= Fcopy_sequence (tail
);
2647 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
2650 if (XFASTINT (start
) == endpos
&& insertion
)
2652 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
2656 tail
= Fcopy_sequence (tail
);
2658 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
2661 /* Test for intersecting intervals. This does the right thing
2662 for both insertion and deletion. */
2663 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
2665 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
2669 tail
= Fcopy_sequence (tail
);
2671 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
2680 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
2681 Lisp_Object list
, overlay
;
2683 Lisp_Object arg1
, arg2
, arg3
;
2685 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2686 GCPRO4 (list
, arg1
, arg2
, arg3
);
2687 while (!NILP (list
))
2690 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
2692 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
2698 /* Delete any zero-sized overlays at position POS, if the `evaporate'
2701 evaporate_overlays (pos
)
2704 Lisp_Object tail
, overlay
, hit_list
;
2707 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
2708 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
2709 tail
= XCONS (tail
)->cdr
)
2712 overlay
= XCONS (tail
)->car
;
2713 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2716 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
2717 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
2718 hit_list
= Fcons (overlay
, hit_list
);
2721 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
2722 tail
= XCONS (tail
)->cdr
)
2725 overlay
= XCONS (tail
)->car
;
2726 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2729 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
2730 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
2731 hit_list
= Fcons (overlay
, hit_list
);
2733 for (; CONSP (hit_list
); hit_list
= XCONS (hit_list
)->cdr
)
2734 Fdelete_overlay (XCONS (hit_list
)->car
);
2737 /* Somebody has tried to store a value with an unacceptable type
2738 into the buffer-local slot with offset OFFSET. */
2740 buffer_slot_type_mismatch (offset
)
2745 sym
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
);
2746 switch (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
)))
2748 case Lisp_Int
: type_name
= "integers"; break;
2749 case Lisp_String
: type_name
= "strings"; break;
2750 case Lisp_Symbol
: type_name
= "symbols"; break;
2755 error ("only %s should be stored in the buffer-local variable %s",
2756 type_name
, XSYMBOL (sym
)->name
->data
);
2761 register Lisp_Object tem
;
2763 /* Make sure all markable slots in buffer_defaults
2764 are initialized reasonably, so mark_buffer won't choke. */
2765 reset_buffer (&buffer_defaults
);
2766 reset_buffer_local_variables (&buffer_defaults
);
2767 reset_buffer (&buffer_local_symbols
);
2768 reset_buffer_local_variables (&buffer_local_symbols
);
2769 /* Prevent GC from getting confused. */
2770 buffer_defaults
.text
= &buffer_defaults
.own_text
;
2771 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
2772 #ifdef USE_TEXT_PROPERTIES
2773 BUF_INTERVALS (&buffer_defaults
) = 0;
2774 BUF_INTERVALS (&buffer_local_symbols
) = 0;
2776 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
2777 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
2779 /* Set up the default values of various buffer slots. */
2780 /* Must do these before making the first buffer! */
2782 /* real setup is done in loaddefs.el */
2783 buffer_defaults
.mode_line_format
= build_string ("%-");
2784 buffer_defaults
.abbrev_mode
= Qnil
;
2785 buffer_defaults
.overwrite_mode
= Qnil
;
2786 buffer_defaults
.case_fold_search
= Qt
;
2787 buffer_defaults
.auto_fill_function
= Qnil
;
2788 buffer_defaults
.selective_display
= Qnil
;
2790 buffer_defaults
.selective_display_ellipses
= Qt
;
2792 buffer_defaults
.abbrev_table
= Qnil
;
2793 buffer_defaults
.display_table
= Qnil
;
2794 buffer_defaults
.undo_list
= Qnil
;
2795 buffer_defaults
.mark_active
= Qnil
;
2796 buffer_defaults
.file_format
= Qnil
;
2797 buffer_defaults
.overlays_before
= Qnil
;
2798 buffer_defaults
.overlays_after
= Qnil
;
2799 XSETFASTINT (buffer_defaults
.overlay_center
, 1);
2801 XSETFASTINT (buffer_defaults
.tab_width
, 8);
2802 buffer_defaults
.truncate_lines
= Qnil
;
2803 buffer_defaults
.ctl_arrow
= Qt
;
2806 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
2808 XSETFASTINT (buffer_defaults
.fill_column
, 70);
2809 XSETFASTINT (buffer_defaults
.left_margin
, 0);
2810 buffer_defaults
.cache_long_line_scans
= Qnil
;
2811 buffer_defaults
.file_truename
= Qnil
;
2813 /* Assign the local-flags to the slots that have default values.
2814 The local flag is a bit that is used in the buffer
2815 to say that it has its own local value for the slot.
2816 The local flag bits are in the local_var_flags slot of the buffer. */
2818 /* Nothing can work if this isn't true */
2819 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
2821 /* 0 means not a lisp var, -1 means always local, else mask */
2822 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
2823 XSETINT (buffer_local_flags
.filename
, -1);
2824 XSETINT (buffer_local_flags
.directory
, -1);
2825 XSETINT (buffer_local_flags
.backed_up
, -1);
2826 XSETINT (buffer_local_flags
.save_length
, -1);
2827 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
2828 XSETINT (buffer_local_flags
.read_only
, -1);
2829 XSETINT (buffer_local_flags
.major_mode
, -1);
2830 XSETINT (buffer_local_flags
.mode_name
, -1);
2831 XSETINT (buffer_local_flags
.undo_list
, -1);
2832 XSETINT (buffer_local_flags
.mark_active
, -1);
2833 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
2834 XSETINT (buffer_local_flags
.file_truename
, -1);
2835 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
2837 XSETFASTINT (buffer_local_flags
.mode_line_format
, 1);
2838 XSETFASTINT (buffer_local_flags
.abbrev_mode
, 2);
2839 XSETFASTINT (buffer_local_flags
.overwrite_mode
, 4);
2840 XSETFASTINT (buffer_local_flags
.case_fold_search
, 8);
2841 XSETFASTINT (buffer_local_flags
.auto_fill_function
, 0x10);
2842 XSETFASTINT (buffer_local_flags
.selective_display
, 0x20);
2844 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, 0x40);
2846 XSETFASTINT (buffer_local_flags
.tab_width
, 0x80);
2847 XSETFASTINT (buffer_local_flags
.truncate_lines
, 0x100);
2848 XSETFASTINT (buffer_local_flags
.ctl_arrow
, 0x200);
2849 XSETFASTINT (buffer_local_flags
.fill_column
, 0x400);
2850 XSETFASTINT (buffer_local_flags
.left_margin
, 0x800);
2851 XSETFASTINT (buffer_local_flags
.abbrev_table
, 0x1000);
2852 XSETFASTINT (buffer_local_flags
.display_table
, 0x2000);
2853 XSETFASTINT (buffer_local_flags
.syntax_table
, 0x8000);
2854 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, 0x10000);
2855 XSETFASTINT (buffer_local_flags
.file_format
, 0x20000);
2857 XSETFASTINT (buffer_local_flags
.buffer_file_type
, 0x4000);
2860 Vbuffer_alist
= Qnil
;
2864 QSFundamental
= build_string ("Fundamental");
2866 Qfundamental_mode
= intern ("fundamental-mode");
2867 buffer_defaults
.major_mode
= Qfundamental_mode
;
2869 Qmode_class
= intern ("mode-class");
2871 Qprotected_field
= intern ("protected-field");
2873 Qpermanent_local
= intern ("permanent-local");
2875 Qkill_buffer_hook
= intern ("kill-buffer-hook");
2877 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
2878 /* super-magic invisible buffer */
2879 Vbuffer_alist
= Qnil
;
2881 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
2886 char buf
[MAXPATHLEN
+1];
2888 struct stat dotstat
, pwdstat
;
2892 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
2894 /* If PWD is accurate, use it instead of calling getwd. This is faster
2895 when PWD is right, and may avoid a fatal error. */
2896 if ((pwd
= getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd
)
2897 && stat (pwd
, &pwdstat
) == 0
2898 && stat (".", &dotstat
) == 0
2899 && dotstat
.st_ino
== pwdstat
.st_ino
2900 && dotstat
.st_dev
== pwdstat
.st_dev
2901 && strlen (pwd
) < MAXPATHLEN
)
2903 else if (getwd (buf
) == 0)
2904 fatal ("`getwd' failed: %s\n", buf
);
2907 /* Maybe this should really use some standard subroutine
2908 whose definition is filename syntax dependent. */
2910 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
2912 buf
[rc
] = DIRECTORY_SEP
;
2915 #endif /* not VMS */
2916 current_buffer
->directory
= build_string (buf
);
2918 temp
= get_minibuffer (0);
2919 XBUFFER (temp
)->directory
= current_buffer
->directory
;
2922 /* initialize the buffer routines */
2925 extern Lisp_Object Qdisabled
;
2927 staticpro (&Vbuffer_defaults
);
2928 staticpro (&Vbuffer_local_symbols
);
2929 staticpro (&Qfundamental_mode
);
2930 staticpro (&Qmode_class
);
2931 staticpro (&QSFundamental
);
2932 staticpro (&Vbuffer_alist
);
2933 staticpro (&Qprotected_field
);
2934 staticpro (&Qpermanent_local
);
2935 staticpro (&Qkill_buffer_hook
);
2936 staticpro (&Qoverlayp
);
2937 Qevaporate
= intern ("evaporate");
2938 staticpro (&Qevaporate
);
2939 staticpro (&Qmodification_hooks
);
2940 Qmodification_hooks
= intern ("modification-hooks");
2941 staticpro (&Qinsert_in_front_hooks
);
2942 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
2943 staticpro (&Qinsert_behind_hooks
);
2944 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
2945 staticpro (&Qget_file_buffer
);
2946 Qget_file_buffer
= intern ("get-file-buffer");
2947 Qpriority
= intern ("priority");
2948 staticpro (&Qpriority
);
2949 Qwindow
= intern ("window");
2950 staticpro (&Qwindow
);
2952 Qoverlayp
= intern ("overlayp");
2954 Fput (Qprotected_field
, Qerror_conditions
,
2955 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
2956 Fput (Qprotected_field
, Qerror_message
,
2957 build_string ("Attempt to modify a protected field"));
2959 /* All these use DEFVAR_LISP_NOPRO because the slots in
2960 buffer_defaults will all be marked via Vbuffer_defaults. */
2962 DEFVAR_LISP_NOPRO ("default-mode-line-format",
2963 &buffer_defaults
.mode_line_format
,
2964 "Default value of `mode-line-format' for buffers that don't override it.\n\
2965 This is the same as (default-value 'mode-line-format).");
2967 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
2968 &buffer_defaults
.abbrev_mode
,
2969 "Default value of `abbrev-mode' for buffers that do not override it.\n\
2970 This is the same as (default-value 'abbrev-mode).");
2972 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
2973 &buffer_defaults
.ctl_arrow
,
2974 "Default value of `ctl-arrow' for buffers that do not override it.\n\
2975 This is the same as (default-value 'ctl-arrow).");
2977 DEFVAR_LISP_NOPRO ("default-truncate-lines",
2978 &buffer_defaults
.truncate_lines
,
2979 "Default value of `truncate-lines' for buffers that do not override it.\n\
2980 This is the same as (default-value 'truncate-lines).");
2982 DEFVAR_LISP_NOPRO ("default-fill-column",
2983 &buffer_defaults
.fill_column
,
2984 "Default value of `fill-column' for buffers that do not override it.\n\
2985 This is the same as (default-value 'fill-column).");
2987 DEFVAR_LISP_NOPRO ("default-left-margin",
2988 &buffer_defaults
.left_margin
,
2989 "Default value of `left-margin' for buffers that do not override it.\n\
2990 This is the same as (default-value 'left-margin).");
2992 DEFVAR_LISP_NOPRO ("default-tab-width",
2993 &buffer_defaults
.tab_width
,
2994 "Default value of `tab-width' for buffers that do not override it.\n\
2995 This is the same as (default-value 'tab-width).");
2997 DEFVAR_LISP_NOPRO ("default-case-fold-search",
2998 &buffer_defaults
.case_fold_search
,
2999 "Default value of `case-fold-search' for buffers that don't override it.\n\
3000 This is the same as (default-value 'case-fold-search).");
3003 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
3004 &buffer_defaults
.buffer_file_type
,
3005 "Default file type for buffers that do not override it.\n\
3006 This is the same as (default-value 'buffer-file-type).\n\
3007 The file type is nil for text, t for binary.");
3010 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
3013 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
3014 But make-docfile finds it!
3015 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
3017 "Template for displaying mode line for current buffer.\n\
3018 Each buffer has its own value of this variable.\n\
3019 Value may be a string, a symbol or a list or cons cell.\n\
3020 For a symbol, its value is used (but it is ignored if t or nil).\n\
3021 A string appearing directly as the value of a symbol is processed verbatim\n\
3022 in that the %-constructs below are not recognized.\n\
3023 For a list whose car is a symbol, the symbol's value is taken,\n\
3024 and if that is non-nil, the cadr of the list is processed recursively.\n\
3025 Otherwise, the caddr of the list (if there is one) is processed.\n\
3026 For a list whose car is a string or list, each element is processed\n\
3027 recursively and the results are effectively concatenated.\n\
3028 For a list whose car is an integer, the cdr of the list is processed\n\
3029 and padded (if the number is positive) or truncated (if negative)\n\
3030 to the width specified by that number.\n\
3031 A string is printed verbatim in the mode line except for %-constructs:\n\
3032 (%-constructs are allowed when the string is the entire mode-line-format\n\
3033 or when it is found in a cons-cell or a list)\n\
3034 %b -- print buffer name. %f -- print visited file name.\n\
3035 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
3036 % means buffer is read-only and * means it is modified.\n\
3037 For a modified read-only buffer, %* gives % and %+ gives *.\n\
3038 %s -- print process status. %l -- print the current line number.\n\
3039 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
3040 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
3041 or print Bottom or All.\n\
3042 %n -- print Narrow if appropriate.\n\
3043 %t -- print T if files is text, B if binary.\n\
3044 %[ -- print one [ for each recursive editing level. %] similar.\n\
3045 %% -- print %. %- -- print infinitely many dashes.\n\
3046 Decimal digits after the % specify field width to which to pad.");
3049 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
3050 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
3051 nil here means use current buffer's major mode.");
3053 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
3054 make_number (Lisp_Symbol
),
3055 "Symbol for current buffer's major mode.");
3057 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
3058 make_number (Lisp_String
),
3059 "Pretty name of current buffer's major mode (a string).");
3061 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
3062 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
3063 Automatically becomes buffer-local when set in any fashion.");
3065 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
3067 "*Non-nil if searches should ignore case.\n\
3068 Automatically becomes buffer-local when set in any fashion.");
3070 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
3071 make_number (Lisp_Int
),
3072 "*Column beyond which automatic line-wrapping should happen.\n\
3073 Automatically becomes buffer-local when set in any fashion.");
3075 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
3076 make_number (Lisp_Int
),
3077 "*Column for the default indent-line-function to indent to.\n\
3078 Linefeed indents to this column in Fundamental mode.\n\
3079 Automatically becomes buffer-local when set in any fashion.");
3081 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
3082 make_number (Lisp_Int
),
3083 "*Distance between tab stops (for display of tab characters), in columns.\n\
3084 Automatically becomes buffer-local when set in any fashion.");
3086 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
3087 "*Non-nil means display control chars with uparrow.\n\
3088 Nil means use backslash and octal digits.\n\
3089 Automatically becomes buffer-local when set in any fashion.\n\
3090 This variable does not apply to characters whose display is specified\n\
3091 in the current display table (if there is one).");
3093 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
3094 "*Non-nil means do not display continuation lines;\n\
3095 give each line of text one screen line.\n\
3096 Automatically becomes buffer-local when set in any fashion.\n\
3098 Note that this is overridden by the variable\n\
3099 `truncate-partial-width-windows' if that variable is non-nil\n\
3100 and this buffer is not full-frame width.");
3103 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
3105 "Non-nil if the visited file is a binary file.\n\
3106 This variable is meaningful on MS-DOG and Windows NT.\n\
3107 On those systems, it is automatically local in every buffer.\n\
3108 On other systems, this variable is normally always nil.");
3111 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
3112 make_number (Lisp_String
),
3113 "Name of default directory of current buffer. Should end with slash.\n\
3114 Each buffer has its own value of this variable.");
3116 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
3118 "Function called (if non-nil) to perform auto-fill.\n\
3119 It is called after self-inserting a space at a column beyond `fill-column'.\n\
3120 Each buffer has its own value of this variable.\n\
3121 NOTE: This variable is not an ordinary hook;\n\
3122 It may not be a list of functions.");
3124 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
3125 make_number (Lisp_String
),
3126 "Name of file visited in current buffer, or nil if not visiting a file.\n\
3127 Each buffer has its own value of this variable.");
3129 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
3130 make_number (Lisp_String
),
3131 "Truename of file visited in current buffer, or nil if not visiting a file.\n\
3132 The truename of a file is calculated by `file-truename'.\n\
3133 Each buffer has its own value of this variable.");
3135 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
3136 ¤t_buffer
->auto_save_file_name
,
3137 make_number (Lisp_String
),
3138 "Name of file for auto-saving current buffer,\n\
3139 or nil if buffer should not be auto-saved.\n\
3140 Each buffer has its own value of this variable.");
3142 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
3143 "Non-nil if this buffer is read-only.\n\
3144 Each buffer has its own value of this variable.");
3146 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
3147 "Non-nil if this buffer's file has been backed up.\n\
3148 Backing up is done before the first time the file is saved.\n\
3149 Each buffer has its own value of this variable.");
3151 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
3152 make_number (Lisp_Int
),
3153 "Length of current buffer when last read in, saved or auto-saved.\n\
3155 Each buffer has its own value of this variable.");
3157 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
3159 "Non-nil enables selective display:\n\
3160 Integer N as value means display only lines\n\
3161 that start with less than n columns of space.\n\
3162 A value of t means, after a ^M, all the rest of the line is invisible.\n\
3163 Then ^M's in the file are written into files as newlines.\n\n\
3164 Automatically becomes buffer-local when set in any fashion.");
3167 DEFVAR_PER_BUFFER ("selective-display-ellipses",
3168 ¤t_buffer
->selective_display_ellipses
,
3170 "t means display ... on previous line when a line is invisible.\n\
3171 Automatically becomes buffer-local when set in any fashion.");
3174 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
3175 "Non-nil if self-insertion should replace existing text.\n\
3176 The value should be one of `overwrite-mode-textual',\n\
3177 `overwrite-mode-binary', or nil.\n\
3178 If it is `overwrite-mode-textual', self-insertion still\n\
3179 inserts at the end of a line, and inserts when point is before a tab,\n\
3180 until the tab is filled in.\n\
3181 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
3182 Automatically becomes buffer-local when set in any fashion.");
3184 #if 0 /* The doc string is too long for some compilers,
3185 but make-docfile can find it in this comment. */
3186 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
3188 "Display table that controls display of the contents of current buffer.\n\
3189 Automatically becomes buffer-local when set in any fashion.\n\
3190 The display table is a vector created with `make-display-table'.\n\
3191 The first 256 elements control how to display each possible text character.\n\
3192 Each value should be a vector of characters or nil;\n\
3193 nil means display the character in the default fashion.\n\
3194 The remaining six elements control the display of\n\
3195 the end of a truncated screen line (element 256, a single character);\n\
3196 the end of a continued line (element 257, a single character);\n\
3197 the escape character used to display character codes in octal\n\
3198 (element 258, a single character);\n\
3199 the character used as an arrow for control characters (element 259,\n\
3200 a single character);\n\
3201 the decoration indicating the presence of invisible lines (element 260,\n\
3202 a vector of characters);\n\
3203 the character used to draw the border between side-by-side windows\n\
3204 (element 261, a single character).\n\
3205 If this variable is nil, the value of `standard-display-table' is used.\n\
3206 Each window can have its own, overriding display table.");
3208 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
3211 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
3214 DEFVAR_LISP ("before-change-function", &Vbefore_change_function
,
3215 "Function to call before each text change.\n\
3216 Two arguments are passed to the function: the positions of\n\
3217 the beginning and end of the range of old text to be changed.\n\
3218 \(For an insertion, the beginning and end are at the same place.)\n\
3219 No information is given about the length of the text after the change.\n\
3221 Buffer changes made while executing the `before-change-function'\n\
3222 don't call any before-change or after-change functions.\n\
3223 That's because these variables are temporarily set to nil.\n\
3224 As a result, a hook function cannot straightforwardly alter the value of\n\
3225 these variables. See the Emacs Lisp manual for a way of\n\
3226 accomplishing an equivalent result by using other variables.");
3227 Vbefore_change_function
= Qnil
;
3229 DEFVAR_LISP ("after-change-function", &Vafter_change_function
,
3230 "Function to call after each text change.\n\
3231 Three arguments are passed to the function: the positions of\n\
3232 the beginning and end of the range of changed text,\n\
3233 and the length of the pre-change text replaced by that range.\n\
3234 \(For an insertion, the pre-change length is zero;\n\
3235 for a deletion, that length is the number of characters deleted,\n\
3236 and the post-change beginning and end are at the same place.)\n\
3238 Buffer changes made while executing the `after-change-function'\n\
3239 don't call any before-change or after-change functions.\n\
3240 That's because these variables are temporarily set to nil.\n\
3241 As a result, a hook function cannot straightforwardly alter the value of\n\
3242 these variables. See the Emacs Lisp manual for a way of\n\
3243 accomplishing an equivalent result by using other variables.");
3244 Vafter_change_function
= Qnil
;
3246 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
3247 "List of functions to call before each text change.\n\
3248 Two arguments are passed to each function: the positions of\n\
3249 the beginning and end of the range of old text to be changed.\n\
3250 \(For an insertion, the beginning and end are at the same place.)\n\
3251 No information is given about the length of the text after the change.\n\
3253 Buffer changes made while executing the `before-change-functions'\n\
3254 don't call any before-change or after-change functions.\n\
3255 That's because these variables are temporarily set to nil.\n\
3256 As a result, a hook function cannot straightforwardly alter the value of\n\
3257 these variables. See the Emacs Lisp manual for a way of\n\
3258 accomplishing an equivalent result by using other variables.");
3259 Vbefore_change_functions
= Qnil
;
3261 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
3262 "List of function to call after each text change.\n\
3263 Three arguments are passed to each function: the positions of\n\
3264 the beginning and end of the range of changed text,\n\
3265 and the length of the pre-change text replaced by that range.\n\
3266 \(For an insertion, the pre-change length is zero;\n\
3267 for a deletion, that length is the number of characters deleted,\n\
3268 and the post-change beginning and end are at the same place.)\n\
3270 Buffer changes made while executing the `after-change-functions'\n\
3271 don't call any before-change or after-change functions.\n\
3272 That's because these variables are temporarily set to nil.\n\
3273 As a result, a hook function cannot straightforwardly alter the value of\n\
3274 these variables. See the Emacs Lisp manual for a way of\n\
3275 accomplishing an equivalent result by using other variables.");
3277 Vafter_change_functions
= Qnil
;
3279 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
3280 "A list of functions to call before changing a buffer which is unmodified.\n\
3281 The functions are run using the `run-hooks' function.");
3282 Vfirst_change_hook
= Qnil
;
3283 Qfirst_change_hook
= intern ("first-change-hook");
3284 staticpro (&Qfirst_change_hook
);
3286 #if 0 /* The doc string is too long for some compilers,
3287 but make-docfile can find it in this comment. */
3288 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
3289 "List of undo entries in current buffer.\n\
3290 Recent changes come first; older changes follow newer.\n\
3292 An entry (START . END) represents an insertion which begins at\n\
3293 position START and ends at position END.\n\
3295 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
3296 from (abs POSITION). If POSITION is positive, point was at the front\n\
3297 of the text being deleted; if negative, point was at the end.\n\
3299 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
3300 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
3301 of the visited file's modification time, as of that time. If the\n\
3302 modification time of the most recent save is different, this entry is\n\
3305 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
3306 was modified between BEG and END. PROPERTY is the property name,\n\
3307 and VALUE is the old value.\n\
3309 An entry of the form POSITION indicates that point was at the buffer\n\
3310 location given by the integer. Undoing an entry of this form places\n\
3311 point at POSITION.\n\
3313 nil marks undo boundaries. The undo command treats the changes\n\
3314 between two undo boundaries as a single step to be undone.\n\
3316 If the value of the variable is t, undo information is not recorded.");
3318 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
3321 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
3322 "Non-nil means the mark and region are currently active in this buffer.\n\
3323 Automatically local in all buffers.");
3325 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
3326 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
3327 This variable is buffer-local, in all buffers.\n\
3329 Normally, the line-motion functions work by scanning the buffer for\n\
3330 newlines. Columnar operations (like move-to-column and\n\
3331 compute-motion) also work by scanning the buffer, summing character\n\
3332 widths as they go. This works well for ordinary text, but if the\n\
3333 buffer's lines are very long (say, more than 500 characters), these\n\
3334 motion functions will take longer to execute. Emacs may also take\n\
3335 longer to update the display.\n\
3337 If cache-long-line-scans is non-nil, these motion functions cache the\n\
3338 results of their scans, and consult the cache to avoid rescanning\n\
3339 regions of the buffer until the text is modified. The caches are most\n\
3340 beneficial when they prevent the most searching---that is, when the\n\
3341 buffer contains long lines and large regions of characters with the\n\
3342 same, fixed screen width.\n\
3344 When cache-long-line-scans is non-nil, processing short lines will\n\
3345 become slightly slower (because of the overhead of consulting the\n\
3346 cache), and the caches will use memory roughly proportional to the\n\
3347 number of newlines and characters whose screen width varies.\n\
3349 The caches require no explicit maintenance; their accuracy is\n\
3350 maintained internally by the Emacs primitives. Enabling or disabling\n\
3351 the cache should not affect the behavior of any of the motion\n\
3352 functions; it should only affect their performance.");
3354 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
3355 "Value of point before the last series of scroll operations, or nil.");
3357 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
3358 "List of formats to use when saving this buffer.\n\
3359 Formats are defined by `format-alist'. This variable is\n\
3360 set when a file is visited. Automatically local in all buffers.");
3362 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
3363 ¤t_buffer
->invisibility_spec
, Qnil
,
3364 "Invisibility spec of this buffer.\n\
3365 The default is t, which means that text is invisible\n\
3366 if it has a non-nil `invisible' property.\n\
3367 If the value is a list, a text character is invisible if its `invisible'\n\
3368 property is an element in that list.\n\
3369 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
3370 then characters with property value PROP are invisible,\n\
3371 and they have an ellipsis as well if ELLIPSIS is non-nil.");
3373 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
3374 "*Non-nil means deactivate the mark when the buffer contents change.");
3375 Vtransient_mark_mode
= Qnil
;
3377 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
3378 "*Non-nil means disregard read-only status of buffers or characters.\n\
3379 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
3380 text properties. If the value is a list, disregard `buffer-read-only'\n\
3381 and disregard a `read-only' text property if the property value\n\
3382 is a member of the list.");
3383 Vinhibit_read_only
= Qnil
;
3385 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
3386 "List of functions called with no args to query before killing a buffer.");
3387 Vkill_buffer_query_functions
= Qnil
;
3389 defsubr (&Sbuffer_list
);
3390 defsubr (&Sget_buffer
);
3391 defsubr (&Sget_file_buffer
);
3392 defsubr (&Sget_buffer_create
);
3393 defsubr (&Smake_indirect_buffer
);
3394 defsubr (&Sgenerate_new_buffer_name
);
3395 defsubr (&Sbuffer_name
);
3396 /*defsubr (&Sbuffer_number);*/
3397 defsubr (&Sbuffer_file_name
);
3398 defsubr (&Sbuffer_base_buffer
);
3399 defsubr (&Sbuffer_local_variables
);
3400 defsubr (&Sbuffer_modified_p
);
3401 defsubr (&Sset_buffer_modified_p
);
3402 defsubr (&Sbuffer_modified_tick
);
3403 defsubr (&Srename_buffer
);
3404 defsubr (&Sother_buffer
);
3405 defsubr (&Sbuffer_disable_undo
);
3406 defsubr (&Sbuffer_enable_undo
);
3407 defsubr (&Skill_buffer
);
3408 defsubr (&Serase_buffer
);
3409 defsubr (&Sset_buffer_major_mode
);
3410 defsubr (&Sswitch_to_buffer
);
3411 defsubr (&Spop_to_buffer
);
3412 defsubr (&Scurrent_buffer
);
3413 defsubr (&Sset_buffer
);
3414 defsubr (&Sbarf_if_buffer_read_only
);
3415 defsubr (&Sbury_buffer
);
3416 defsubr (&Skill_all_local_variables
);
3418 defsubr (&Soverlayp
);
3419 defsubr (&Smake_overlay
);
3420 defsubr (&Sdelete_overlay
);
3421 defsubr (&Smove_overlay
);
3422 defsubr (&Soverlay_start
);
3423 defsubr (&Soverlay_end
);
3424 defsubr (&Soverlay_buffer
);
3425 defsubr (&Soverlay_properties
);
3426 defsubr (&Soverlays_at
);
3427 defsubr (&Snext_overlay_change
);
3428 defsubr (&Sprevious_overlay_change
);
3429 defsubr (&Soverlay_recenter
);
3430 defsubr (&Soverlay_lists
);
3431 defsubr (&Soverlay_get
);
3432 defsubr (&Soverlay_put
);
3437 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
3438 initial_define_key (control_x_map
, 'k', "kill-buffer");
3440 /* This must not be in syms_of_buffer, because Qdisabled is not
3441 initialized when that function gets called. */
3442 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);