1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995, 1997
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <sys/types.h>
25 #include <sys/param.h>
31 /* in 4.1, param.h fails to define this. */
32 #define MAXPATHLEN 1024
33 #endif /* not MAXPATHLEN */
37 #include "intervals.h"
42 #include "region-cache.h"
44 #include "blockinput.h"
47 struct buffer
*current_buffer
; /* the current buffer */
49 /* First buffer in chain of all buffers (in reverse order of creation).
50 Threaded through ->next. */
52 struct buffer
*all_buffers
;
54 /* This structure holds the default values of the buffer-local variables
55 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
56 The default value occupies the same slot in this structure
57 as an individual buffer's value occupies in that buffer.
58 Setting the default value also goes through the alist of buffers
59 and stores into each buffer that does not say it has a local value. */
61 struct buffer buffer_defaults
;
63 /* A Lisp_Object pointer to the above, used for staticpro */
65 static Lisp_Object Vbuffer_defaults
;
67 /* This structure marks which slots in a buffer have corresponding
68 default values in buffer_defaults.
69 Each such slot has a nonzero value in this structure.
70 The value has only one nonzero bit.
72 When a buffer has its own local value for a slot,
73 the bit for that slot (found in the same slot in this structure)
74 is turned on in the buffer's local_var_flags slot.
76 If a slot in this structure is -1, then even though there may
77 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
78 and the corresponding slot in buffer_defaults is not used.
80 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
81 but there is a default value which is copied into each buffer.
83 If a slot in this structure is negative, then even though there may
84 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
85 and the corresponding slot in buffer_defaults is not used.
87 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
88 zero, that is a bug */
90 struct buffer buffer_local_flags
;
92 /* This structure holds the names of symbols whose values may be
93 buffer-local. It is indexed and accessed in the same way as the above. */
95 struct buffer buffer_local_symbols
;
96 /* A Lisp_Object pointer to the above, used for staticpro */
97 static Lisp_Object Vbuffer_local_symbols
;
99 /* This structure holds the required types for the values in the
100 buffer-local slots. If a slot contains Qnil, then the
101 corresponding buffer slot may contain a value of any type. If a
102 slot contains an integer, then prospective values' tags must be
103 equal to that integer. When a tag does not match, the function
104 buffer_slot_type_mismatch will signal an error. */
105 struct buffer buffer_local_types
;
107 /* Flags indicating which built-in buffer-local variables
108 are permanent locals. */
109 static int buffer_permanent_local_flags
;
111 Lisp_Object
Fset_buffer ();
112 void set_buffer_internal ();
113 void set_buffer_internal_1 ();
114 static void call_overlay_mod_hooks ();
115 static void swap_out_buffer_local_variables ();
116 static void reset_buffer_local_variables ();
118 /* Alist of all buffer names vs the buffers. */
119 /* This used to be a variable, but is no longer,
120 to prevent lossage due to user rplac'ing this alist or its elements. */
121 Lisp_Object Vbuffer_alist
;
123 /* Functions to call before and after each text change. */
124 Lisp_Object Vbefore_change_function
;
125 Lisp_Object Vafter_change_function
;
126 Lisp_Object Vbefore_change_functions
;
127 Lisp_Object Vafter_change_functions
;
129 Lisp_Object Vtransient_mark_mode
;
131 /* t means ignore all read-only text properties.
132 A list means ignore such a property if its value is a member of the list.
133 Any non-nil value means ignore buffer-read-only. */
134 Lisp_Object Vinhibit_read_only
;
136 /* List of functions to call that can query about killing a buffer.
137 If any of these functions returns nil, we don't kill it. */
138 Lisp_Object Vkill_buffer_query_functions
;
140 /* List of functions to call before changing an unmodified buffer. */
141 Lisp_Object Vfirst_change_hook
;
143 Lisp_Object Qfirst_change_hook
;
144 Lisp_Object Qbefore_change_functions
;
145 Lisp_Object Qafter_change_functions
;
147 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
149 Lisp_Object Qprotected_field
;
151 Lisp_Object QSFundamental
; /* A string "Fundamental" */
153 Lisp_Object Qkill_buffer_hook
;
155 Lisp_Object Qget_file_buffer
;
157 Lisp_Object Qoverlayp
;
159 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
161 Lisp_Object Qmodification_hooks
;
162 Lisp_Object Qinsert_in_front_hooks
;
163 Lisp_Object Qinsert_behind_hooks
;
165 /* For debugging; temporary. See set_buffer_internal. */
166 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
173 error ("No buffer named %s", XSTRING (spec
)->data
);
174 error ("Invalid buffer argument");
177 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
178 "Return non-nil if OBJECT is a buffer which has not been killed.\n\
179 Value is nil if OBJECT is not a buffer or if it has been killed.")
183 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
187 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
188 "Return a list of all existing live buffers.\n\
189 If the optional arg FRAME is a frame, we return that frame's buffer list.")
193 Lisp_Object framelist
, general
;
194 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
200 CHECK_FRAME (frame
, 1);
202 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
204 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */
206 while (! NILP (tail
))
208 general
= Fdelq (XCONS (tail
)->car
, general
);
209 tail
= XCONS (tail
)->cdr
;
211 return nconc2 (framelist
, general
);
217 /* Like Fassoc, but use Fstring_equal to compare
218 (which ignores text properties),
219 and don't ever QUIT. */
222 assoc_ignore_text_properties (key
, list
)
223 register Lisp_Object key
;
226 register Lisp_Object tail
;
227 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
229 register Lisp_Object elt
, tem
;
231 tem
= Fstring_equal (Fcar (elt
), key
);
238 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
239 "Return the buffer named NAME (a string).\n\
240 If there is no live buffer named NAME, return nil.\n\
241 NAME may also be a buffer; if so, the value is that buffer.")
243 register Lisp_Object name
;
247 CHECK_STRING (name
, 0);
249 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
252 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
253 "Return the buffer visiting file FILENAME (a string).\n\
254 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
255 If there is no such live buffer, return nil.\n\
256 See also `find-buffer-visiting'.")
258 register Lisp_Object filename
;
260 register Lisp_Object tail
, buf
, tem
;
263 CHECK_STRING (filename
, 0);
264 filename
= Fexpand_file_name (filename
, Qnil
);
266 /* If the file name has special constructs in it,
267 call the corresponding file handler. */
268 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
270 return call2 (handler
, Qget_file_buffer
, filename
);
272 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
274 buf
= Fcdr (XCONS (tail
)->car
);
275 if (!BUFFERP (buf
)) continue;
276 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
277 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
285 get_truename_buffer (filename
)
286 register Lisp_Object filename
;
288 register Lisp_Object tail
, buf
, tem
;
290 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
292 buf
= Fcdr (XCONS (tail
)->car
);
293 if (!BUFFERP (buf
)) continue;
294 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
295 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
302 /* Incremented for each buffer created, to assign the buffer number. */
305 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
306 "Return the buffer named NAME, or create such a buffer and return it.\n\
307 A new buffer is created if there is no live buffer named NAME.\n\
308 If NAME starts with a space, the new buffer does not keep undo information.\n\
309 If NAME is a buffer instead of a string, then it is the value returned.\n\
310 The value is never nil.")
312 register Lisp_Object name
;
314 register Lisp_Object buf
;
315 register struct buffer
*b
;
317 buf
= Fget_buffer (name
);
321 if (XSTRING (name
)->size
== 0)
322 error ("Empty string for buffer name is not allowed");
324 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
326 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
328 /* An ordinary buffer uses its own struct buffer_text. */
329 b
->text
= &b
->own_text
;
332 BUF_GAP_SIZE (b
) = 20;
334 /* We allocate extra 1-byte at the tail and keep it always '\0' for
335 anchoring a search. */
336 BUFFER_ALLOC (BUF_BEG_ADDR (b
), (BUF_GAP_SIZE (b
) + 1));
338 if (! BUF_BEG_ADDR (b
))
339 buffer_memory_full ();
347 BUF_OVERLAY_MODIFF (b
) = 1;
348 BUF_SAVE_MODIFF (b
) = 1;
349 BUF_INTERVALS (b
) = 0;
350 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
352 b
->newline_cache
= 0;
353 b
->width_run_cache
= 0;
354 b
->width_table
= Qnil
;
356 /* Put this on the chain of all buffers including killed ones. */
357 b
->next
= all_buffers
;
360 /* An ordinary buffer normally doesn't need markers
361 to handle BEGV and ZV. */
363 b
->begv_marker
= Qnil
;
366 name
= Fcopy_sequence (name
);
367 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
370 if (XSTRING (name
)->data
[0] != ' ')
376 reset_buffer_local_variables (b
, 1);
378 /* Put this in the alist of all live buffers. */
380 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
382 b
->mark
= Fmake_marker ();
383 BUF_MARKERS (b
) = Qnil
;
388 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
, 2, 2,
389 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
390 "Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.\n\
391 BASE-BUFFER should be an existing buffer (or buffer name).\n\
392 NAME should be a string which is not the name of an existing buffer.")
394 register Lisp_Object base_buffer
, name
;
396 register Lisp_Object buf
;
397 register struct buffer
*b
;
399 buf
= Fget_buffer (name
);
401 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
403 base_buffer
= Fget_buffer (base_buffer
);
404 if (NILP (base_buffer
))
405 error ("No such buffer: `%s'",
406 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
408 if (XSTRING (name
)->size
== 0)
409 error ("Empty string for buffer name is not allowed");
411 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
413 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
415 if (XBUFFER (base_buffer
)->base_buffer
)
416 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
418 b
->base_buffer
= XBUFFER (base_buffer
);
420 /* Use the base buffer's text object. */
421 b
->text
= b
->base_buffer
->text
;
423 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
424 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
425 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
427 b
->newline_cache
= 0;
428 b
->width_run_cache
= 0;
429 b
->width_table
= Qnil
;
431 /* Put this on the chain of all buffers including killed ones. */
432 b
->next
= all_buffers
;
435 name
= Fcopy_sequence (name
);
436 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
440 reset_buffer_local_variables (b
, 1);
442 /* Put this in the alist of all live buffers. */
444 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
446 b
->mark
= Fmake_marker ();
449 /* Make sure the base buffer has markers for its narrowing. */
450 if (NILP (b
->base_buffer
->pt_marker
))
452 b
->base_buffer
->pt_marker
= Fmake_marker ();
453 Fset_marker (b
->base_buffer
->pt_marker
,
454 make_number (BUF_PT (b
->base_buffer
)), base_buffer
);
456 if (NILP (b
->base_buffer
->begv_marker
))
458 b
->base_buffer
->begv_marker
= Fmake_marker ();
459 Fset_marker (b
->base_buffer
->begv_marker
,
460 make_number (BUF_BEGV (b
->base_buffer
)), base_buffer
);
462 if (NILP (b
->base_buffer
->zv_marker
))
464 b
->base_buffer
->zv_marker
= Fmake_marker ();
465 Fset_marker (b
->base_buffer
->zv_marker
,
466 make_number (BUF_ZV (b
->base_buffer
)), base_buffer
);
467 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
470 /* Give the indirect buffer markers for its narrowing. */
471 b
->pt_marker
= Fmake_marker ();
472 Fset_marker (b
->pt_marker
, make_number (BUF_PT (b
)), buf
);
473 b
->begv_marker
= Fmake_marker ();
474 Fset_marker (b
->begv_marker
, make_number (BUF_BEGV (b
)), buf
);
475 b
->zv_marker
= Fmake_marker ();
476 Fset_marker (b
->zv_marker
, make_number (BUF_ZV (b
)), buf
);
478 XMARKER (b
->zv_marker
)->insertion_type
= 1;
483 /* Reinitialize everything about a buffer except its name and contents
484 and local variables. */
488 register struct buffer
*b
;
491 b
->file_truename
= Qnil
;
492 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
494 XSETFASTINT (b
->save_length
, 0);
495 b
->last_window_start
= 1;
496 /* It is more conservative to start out "changed" than "unchanged". */
499 b
->auto_save_modified
= 0;
500 b
->auto_save_failure_time
= -1;
501 b
->auto_save_file_name
= Qnil
;
503 b
->overlays_before
= Qnil
;
504 b
->overlays_after
= Qnil
;
505 XSETFASTINT (b
->overlay_center
, 1);
506 b
->mark_active
= Qnil
;
507 b
->point_before_scroll
= Qnil
;
508 b
->file_format
= Qnil
;
509 b
->last_selected_window
= Qnil
;
510 XSETINT (b
->display_count
, 0);
515 /* Reset buffer B's local variables info.
516 Don't use this on a buffer that has already been in use;
517 it does not treat permanent locals consistently.
518 Instead, use Fkill_all_local_variables.
520 If PERMANENT_TOO is 1, then we reset permanent built-in
521 buffer-local variables. If PERMANENT_TOO is 0,
522 we preserve those. */
525 reset_buffer_local_variables (b
, permanent_too
)
526 register struct buffer
*b
;
532 /* Decide which built-in local variables to reset. */
536 dont_reset
= buffer_permanent_local_flags
;
538 /* Reset the major mode to Fundamental, together with all the
539 things that depend on the major mode.
540 default-major-mode is handled at a higher level.
541 We ignore it here. */
542 b
->major_mode
= Qfundamental_mode
;
544 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
545 b
->mode_name
= QSFundamental
;
546 b
->minor_modes
= Qnil
;
548 /* If the standard case table has been altered and invalidated,
549 fix up its insides first. */
550 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
551 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
552 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
553 Fset_standard_case_table (Vascii_downcase_table
);
555 b
->downcase_table
= Vascii_downcase_table
;
556 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
557 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
558 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
559 b
->invisibility_spec
= Qt
;
561 b
->buffer_file_type
= Qnil
;
565 b
->sort_table
= XSTRING (Vascii_sort_table
);
566 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
569 /* Reset all (or most) per-buffer variables to their defaults. */
570 b
->local_var_alist
= Qnil
;
571 b
->local_var_flags
&= dont_reset
;
573 /* For each slot that has a default value,
574 copy that into the slot. */
576 for (offset
= (char *)&buffer_local_flags
.name
- (char *)&buffer_local_flags
;
577 offset
< sizeof (struct buffer
);
578 offset
+= sizeof (Lisp_Object
)) /* sizeof EMACS_INT == sizeof Lisp_Object */
580 int flag
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
582 /* Don't reset a permanent local. */
583 && ! (dont_reset
& flag
))
585 *(Lisp_Object
*)(offset
+ (char *)b
)
586 = *(Lisp_Object
*)(offset
+ (char *)&buffer_defaults
);
590 /* We split this away from generate-new-buffer, because rename-buffer
591 and set-visited-file-name ought to be able to use this to really
592 rename the buffer properly. */
594 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
596 "Return a string that is the name of no existing buffer based on NAME.\n\
597 If there is no live buffer named NAME, then return NAME.\n\
598 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
599 until an unused name is found, and then return that name.\n\
600 Optional second argument IGNORE specifies a name that is okay to use\n\
601 \(if it is in the sequence to be tried)\n\
602 even if a buffer with that name exists.")
604 register Lisp_Object name
, ignore
;
606 register Lisp_Object gentemp
, tem
;
610 CHECK_STRING (name
, 0);
612 tem
= Fget_buffer (name
);
619 sprintf (number
, "<%d>", ++count
);
620 gentemp
= concat2 (name
, build_string (number
));
621 tem
= Fstring_equal (gentemp
, ignore
);
624 tem
= Fget_buffer (gentemp
);
631 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
632 "Return the name of BUFFER, as a string.\n\
633 With no argument or nil as argument, return the name of the current buffer.")
635 register Lisp_Object buffer
;
638 return current_buffer
->name
;
639 CHECK_BUFFER (buffer
, 0);
640 return XBUFFER (buffer
)->name
;
643 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
644 "Return name of file BUFFER is visiting, or nil if none.\n\
645 No argument or nil as argument means use the current buffer.")
647 register Lisp_Object buffer
;
650 return current_buffer
->filename
;
651 CHECK_BUFFER (buffer
, 0);
652 return XBUFFER (buffer
)->filename
;
655 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
657 "Return the base buffer of indirect buffer BUFFER.\n\
658 If BUFFER is not indirect, return nil.")
660 register Lisp_Object buffer
;
663 Lisp_Object base_buffer
;
666 base
= current_buffer
->base_buffer
;
669 CHECK_BUFFER (buffer
, 0);
670 base
= XBUFFER (buffer
)->base_buffer
;
675 XSETBUFFER (base_buffer
, base
);
679 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
680 Sbuffer_local_variables
, 0, 1, 0,
681 "Return an alist of variables that are buffer-local in BUFFER.\n\
682 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
683 For a symbol that is locally unbound, just the symbol appears in the value.\n\
684 Note that storing new VALUEs in these elements doesn't change the variables.\n\
685 No argument or nil as argument means use current buffer as BUFFER.")
687 register Lisp_Object buffer
;
689 register struct buffer
*buf
;
690 register Lisp_Object result
;
693 buf
= current_buffer
;
696 CHECK_BUFFER (buffer
, 0);
697 buf
= XBUFFER (buffer
);
703 register Lisp_Object tail
;
704 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
706 Lisp_Object val
, elt
;
708 elt
= XCONS (tail
)->car
;
710 /* Reference each variable in the alist in buf.
711 If inquiring about the current buffer, this gets the current values,
712 so store them into the alist so the alist is up to date.
713 If inquiring about some other buffer, this swaps out any values
714 for that buffer, making the alist up to date automatically. */
715 val
= find_symbol_value (XCONS (elt
)->car
);
716 /* Use the current buffer value only if buf is the current buffer. */
717 if (buf
!= current_buffer
)
718 val
= XCONS (elt
)->cdr
;
720 /* If symbol is unbound, put just the symbol in the list. */
721 if (EQ (val
, Qunbound
))
722 result
= Fcons (XCONS (elt
)->car
, result
);
723 /* Otherwise, put (symbol . value) in the list. */
725 result
= Fcons (Fcons (XCONS (elt
)->car
, val
), result
);
729 /* Add on all the variables stored in special slots. */
731 register int offset
, mask
;
733 for (offset
= (char *)&buffer_local_symbols
.name
- (char *)&buffer_local_symbols
;
734 offset
< sizeof (struct buffer
);
735 offset
+= (sizeof (EMACS_INT
))) /* sizeof EMACS_INT == sizeof Lisp_Object */
737 mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
738 if (mask
== -1 || (buf
->local_var_flags
& mask
))
739 if (SYMBOLP (*(Lisp_Object
*)(offset
740 + (char *)&buffer_local_symbols
)))
741 result
= Fcons (Fcons (*((Lisp_Object
*)
742 (offset
+ (char *)&buffer_local_symbols
)),
743 *(Lisp_Object
*)(offset
+ (char *)buf
)),
752 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
754 "Return t if BUFFER was modified since its file was last read or saved.\n\
755 No argument or nil as argument means use current buffer as BUFFER.")
757 register Lisp_Object buffer
;
759 register struct buffer
*buf
;
761 buf
= current_buffer
;
764 CHECK_BUFFER (buffer
, 0);
765 buf
= XBUFFER (buffer
);
768 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
771 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
773 "Mark current buffer as modified or unmodified according to FLAG.\n\
774 A non-nil FLAG means mark the buffer modified.")
776 register Lisp_Object flag
;
778 register int already
;
779 register Lisp_Object fn
;
781 #ifdef CLASH_DETECTION
782 /* If buffer becoming modified, lock the file.
783 If buffer becoming unmodified, unlock the file. */
785 fn
= current_buffer
->file_truename
;
788 already
= SAVE_MODIFF
< MODIFF
;
789 if (!already
&& !NILP (flag
))
791 else if (already
&& NILP (flag
))
794 #endif /* CLASH_DETECTION */
796 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
801 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
803 "Return BUFFER's tick counter, incremented for each change in text.\n\
804 Each buffer has a tick counter which is incremented each time the text in\n\
805 that buffer is changed. It wraps around occasionally.\n\
806 No argument or nil as argument means use current buffer as BUFFER.")
808 register Lisp_Object buffer
;
810 register struct buffer
*buf
;
812 buf
= current_buffer
;
815 CHECK_BUFFER (buffer
, 0);
816 buf
= XBUFFER (buffer
);
819 return make_number (BUF_MODIFF (buf
));
822 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
823 "sRename buffer (to new name): \nP",
824 "Change current buffer's name to NEWNAME (a string).\n\
825 If second arg UNIQUE is nil or omitted, it is an error if a\n\
826 buffer named NEWNAME already exists.\n\
827 If UNIQUE is non-nil, come up with a new name using\n\
828 `generate-new-buffer-name'.\n\
829 Interactively, you can set UNIQUE with a prefix argument.\n\
830 We return the name we actually gave the buffer.\n\
831 This does not change the name of the visited file (if any).")
833 register Lisp_Object newname
, unique
;
835 register Lisp_Object tem
, buf
;
837 CHECK_STRING (newname
, 0);
839 if (XSTRING (newname
)->size
== 0)
840 error ("Empty string is invalid as a buffer name");
842 tem
= Fget_buffer (newname
);
843 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
844 the buffer automatically so you can create another with the original name.
845 It makes UNIQUE equivalent to
846 (rename-buffer (generate-new-buffer-name NEWNAME)). */
847 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
848 return current_buffer
->name
;
852 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
854 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
857 current_buffer
->name
= newname
;
859 /* Catch redisplay's attention. Unless we do this, the mode lines for
860 any windows displaying current_buffer will stay unchanged. */
863 XSETBUFFER (buf
, current_buffer
);
864 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
865 if (NILP (current_buffer
->filename
)
866 && !NILP (current_buffer
->auto_save_file_name
))
867 call0 (intern ("rename-auto-save-file"));
868 /* Refetch since that last call may have done GC. */
869 return current_buffer
->name
;
872 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 2, 0,
873 "Return most recently selected buffer other than BUFFER.\n\
874 Buffers not visible in windows are preferred to visible buffers,\n\
875 unless optional second argument VISIBLE-OK is non-nil.\n\
876 If no other buffer exists, the buffer `*scratch*' is returned.\n\
877 If BUFFER is omitted or nil, some interesting buffer is returned.")
879 register Lisp_Object buffer
, visible_ok
;
881 Lisp_Object
Fset_buffer_major_mode ();
882 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
885 tail
= Vbuffer_alist
;
886 pred
= frame_buffer_predicate ();
888 /* Consider buffers that have been seen in the selected frame
889 before other buffers. */
891 tem
= frame_buffer_list ();
895 if (BUFFERP (XCONS (tem
)->car
))
896 add_ons
= Fcons (Fcons (Qnil
, XCONS (tem
)->car
), add_ons
);
897 tem
= XCONS (tem
)->cdr
;
899 tail
= nconc2 (Fnreverse (add_ons
), tail
);
901 for (; !NILP (tail
); tail
= Fcdr (tail
))
903 buf
= Fcdr (Fcar (tail
));
904 if (EQ (buf
, buffer
))
906 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
908 /* If the selected frame has a buffer_predicate,
909 disregard buffers that don't fit the predicate. */
912 tem
= call1 (pred
, buf
);
917 if (NILP (visible_ok
))
918 tem
= Fget_buffer_window (buf
, Qt
);
923 if (NILP (notsogood
))
926 if (!NILP (notsogood
))
928 buf
= Fget_buffer_create (build_string ("*scratch*"));
929 Fset_buffer_major_mode (buf
);
933 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
,
935 "Make BUFFER stop keeping undo information.\n\
936 No argument or nil as argument means do this for the current buffer.")
938 register Lisp_Object buffer
;
940 Lisp_Object real_buffer
;
943 XSETBUFFER (real_buffer
, current_buffer
);
946 real_buffer
= Fget_buffer (buffer
);
947 if (NILP (real_buffer
))
951 XBUFFER (real_buffer
)->undo_list
= Qt
;
956 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
958 "Start keeping undo information for buffer BUFFER.\n\
959 No argument or nil as argument means do this for the current buffer.")
961 register Lisp_Object buffer
;
963 Lisp_Object real_buffer
;
966 XSETBUFFER (real_buffer
, current_buffer
);
969 real_buffer
= Fget_buffer (buffer
);
970 if (NILP (real_buffer
))
974 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
975 XBUFFER (real_buffer
)->undo_list
= Qnil
;
981 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
982 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
983 The buffer being killed will be current while the hook is running.\n\
986 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
987 "Kill the buffer BUFFER.\n\
988 The argument may be a buffer or may be the name of a buffer.\n\
989 An argument of nil means kill the current buffer.\n\n\
990 Value is t if the buffer is actually killed, nil if user says no.\n\n\
991 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
992 if not void, is a list of functions to be called, with no arguments,\n\
993 before the buffer is actually killed. The buffer to be killed is current\n\
994 when the hook functions are called.\n\n\
995 Any processes that have this buffer as the `process-buffer' are killed\n\
1001 register struct buffer
*b
;
1002 register Lisp_Object tem
;
1003 register struct Lisp_Marker
*m
;
1004 struct gcpro gcpro1
, gcpro2
;
1007 buf
= Fcurrent_buffer ();
1009 buf
= Fget_buffer (buffer
);
1015 /* Avoid trouble for buffer already dead. */
1019 /* Query if the buffer is still modified. */
1020 if (INTERACTIVE
&& !NILP (b
->filename
)
1021 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1024 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
1025 XSTRING (b
->name
)->data
));
1031 /* Run hooks with the buffer to be killed the current buffer. */
1033 register Lisp_Object val
;
1034 int count
= specpdl_ptr
- specpdl
;
1037 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1038 set_buffer_internal (b
);
1040 /* First run the query functions; if any query is answered no,
1041 don't kill the buffer. */
1042 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
1044 tem
= call0 (Fcar (list
));
1046 return unbind_to (count
, Qnil
);
1049 /* Then run the hooks. */
1050 if (!NILP (Vrun_hooks
))
1051 call1 (Vrun_hooks
, Qkill_buffer_hook
);
1052 unbind_to (count
, Qnil
);
1055 /* We have no more questions to ask. Verify that it is valid
1056 to kill the buffer. This must be done after the questions
1057 since anything can happen within do_yes_or_no_p. */
1059 /* Don't kill the minibuffer now current. */
1060 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1066 /* When we kill a base buffer, kill all its indirect buffers.
1067 We do it at this stage so nothing terrible happens if they
1068 ask questions or their hooks get errors. */
1069 if (! b
->base_buffer
)
1071 struct buffer
*other
;
1075 for (other
= all_buffers
; other
; other
= other
->next
)
1076 /* all_buffers contains dead buffers too;
1077 don't re-kill them. */
1078 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1081 XSETBUFFER (buf
, other
);
1088 /* Make this buffer not be current.
1089 In the process, notice if this is the sole visible buffer
1090 and give up if so. */
1091 if (b
== current_buffer
)
1093 tem
= Fother_buffer (buf
, Qnil
);
1095 if (b
== current_buffer
)
1099 /* Now there is no question: we can kill the buffer. */
1101 #ifdef CLASH_DETECTION
1102 /* Unlock this buffer's file, if it is locked. */
1104 #endif /* CLASH_DETECTION */
1106 kill_buffer_processes (buf
);
1108 tem
= Vinhibit_quit
;
1110 replace_buffer_in_all_windows (buf
);
1111 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1112 frames_discard_buffer (buf
);
1113 Vinhibit_quit
= tem
;
1115 /* Delete any auto-save file, if we saved it in this session. */
1116 if (STRINGP (b
->auto_save_file_name
)
1117 && b
->auto_save_modified
!= 0
1118 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
)
1121 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1123 internal_delete_file (b
->auto_save_file_name
);
1128 /* Unchain all markers that belong to this indirect buffer.
1129 Don't unchain the markers that belong to the base buffer
1130 or its other indirect buffers. */
1131 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1137 unchain_marker (tem
);
1143 /* Unchain all markers of this buffer and its indirect buffers.
1144 and leave them pointing nowhere. */
1145 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1152 BUF_MARKERS (b
) = Qnil
;
1154 #ifdef USE_TEXT_PROPERTIES
1155 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1158 /* Perhaps we should explicitly free the interval tree here... */
1161 /* Reset the local variables, so that this buffer's local values
1162 won't be protected from GC. They would be protected
1163 if they happened to remain encached in their symbols.
1164 This gets rid of them for certain. */
1165 swap_out_buffer_local_variables (b
);
1166 reset_buffer_local_variables (b
, 1);
1171 if (! b
->base_buffer
)
1172 BUFFER_FREE (BUF_BEG_ADDR (b
));
1174 if (b
->newline_cache
)
1176 free_region_cache (b
->newline_cache
);
1177 b
->newline_cache
= 0;
1179 if (b
->width_run_cache
)
1181 free_region_cache (b
->width_run_cache
);
1182 b
->width_run_cache
= 0;
1184 b
->width_table
= Qnil
;
1186 b
->undo_list
= Qnil
;
1191 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1192 we do this each time BUF is selected visibly, the more recently
1193 selected buffers are always closer to the front of the list. This
1194 means that other_buffer is more likely to choose a relevant buffer. */
1200 register Lisp_Object link
, prev
;
1203 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCONS (link
)->cdr
)
1205 if (EQ (XCONS (XCONS (link
)->car
)->cdr
, buf
))
1210 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1211 we cannot use Fdelq itself here because it allows quitting. */
1214 Vbuffer_alist
= XCONS (Vbuffer_alist
)->cdr
;
1216 XCONS (prev
)->cdr
= XCONS (XCONS (prev
)->cdr
)->cdr
;
1218 XCONS (link
)->cdr
= Vbuffer_alist
;
1219 Vbuffer_alist
= link
;
1221 /* Now move this buffer to the front of frame_buffer_list also. */
1224 for (link
= frame_buffer_list (); CONSP (link
); link
= XCONS (link
)->cdr
)
1226 if (EQ (XCONS (link
)->car
, buf
))
1231 /* Effectively do delq. */
1236 set_frame_buffer_list (XCONS (frame_buffer_list ())->cdr
);
1238 XCONS (prev
)->cdr
= XCONS (XCONS (prev
)->cdr
)->cdr
;
1240 XCONS (link
)->cdr
= frame_buffer_list ();
1241 set_frame_buffer_list (link
);
1244 set_frame_buffer_list (Fcons (buf
, frame_buffer_list ()));
1247 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1248 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1249 Use this function before selecting the buffer, since it may need to inspect\n\
1250 the current buffer's major mode.")
1255 Lisp_Object function
;
1257 function
= buffer_defaults
.major_mode
;
1258 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1259 function
= current_buffer
->major_mode
;
1261 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1264 count
= specpdl_ptr
- specpdl
;
1266 /* To select a nonfundamental mode,
1267 select the buffer temporarily and then call the mode function. */
1269 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1271 Fset_buffer (buffer
);
1274 return unbind_to (count
, Qnil
);
1277 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1278 "Select buffer BUFFER in the current window.\n\
1279 BUFFER may be a buffer or a buffer name.\n\
1280 Optional second arg NORECORD non-nil means\n\
1281 do not put this buffer at the front of the list of recently selected ones.\n\
1283 WARNING: This is NOT the way to work on another buffer temporarily\n\
1284 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1285 the window-buffer correspondences.")
1287 Lisp_Object buffer
, norecord
;
1289 register Lisp_Object buf
;
1292 if (EQ (minibuf_window
, selected_window
))
1293 error ("Cannot switch buffers in minibuffer window");
1294 tem
= Fwindow_dedicated_p (selected_window
);
1296 error ("Cannot switch buffers in a dedicated window");
1299 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1302 buf
= Fget_buffer (buffer
);
1305 buf
= Fget_buffer_create (buffer
);
1306 Fset_buffer_major_mode (buf
);
1310 if (NILP (norecord
))
1311 record_buffer (buf
);
1313 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1314 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1321 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1322 "Select buffer BUFFER in some window, preferably a different one.\n\
1323 If BUFFER is nil, then some other buffer is chosen.\n\
1324 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1325 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1326 window even if BUFFER is already visible in the selected window.\n\
1327 This uses the function `display-buffer' as a subroutine; see the documentation\n\
1328 of `display-buffer' for additional customization information.\n\
1330 Optional third arg NORECORD non-nil means\n\
1331 do not put this buffer at the front of the list of recently selected ones.")
1332 (buffer
, other_window
, norecord
)
1333 Lisp_Object buffer
, other_window
, norecord
;
1335 register Lisp_Object buf
;
1337 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1340 buf
= Fget_buffer (buffer
);
1343 buf
= Fget_buffer_create (buffer
);
1344 Fset_buffer_major_mode (buf
);
1348 if (NILP (norecord
))
1349 record_buffer (buf
);
1350 Fselect_window (Fdisplay_buffer (buf
, other_window
));
1354 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1355 "Return the current buffer as a Lisp object.")
1358 register Lisp_Object buf
;
1359 XSETBUFFER (buf
, current_buffer
);
1363 /* Set the current buffer to B. */
1366 set_buffer_internal (b
)
1367 register struct buffer
*b
;
1369 register struct buffer
*old_buf
;
1370 register Lisp_Object tail
, valcontents
;
1373 if (current_buffer
== b
)
1376 windows_or_buffers_changed
= 1;
1377 set_buffer_internal_1 (b
);
1380 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1381 This is used by redisplay. */
1384 set_buffer_internal_1 (b
)
1385 register struct buffer
*b
;
1387 register struct buffer
*old_buf
;
1388 register Lisp_Object tail
, valcontents
;
1391 if (current_buffer
== b
)
1394 old_buf
= current_buffer
;
1396 last_known_column_point
= -1; /* invalidate indentation cache */
1400 /* Put the undo list back in the base buffer, so that it appears
1401 that an indirect buffer shares the undo list of its base. */
1402 if (old_buf
->base_buffer
)
1403 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1405 /* If the old current buffer has markers to record PT, BEGV and ZV
1406 when it is not current, update them now. */
1407 if (! NILP (old_buf
->pt_marker
))
1410 XSETBUFFER (obuf
, old_buf
);
1411 Fset_marker (old_buf
->pt_marker
, make_number (BUF_PT (old_buf
)),
1414 if (! NILP (old_buf
->begv_marker
))
1417 XSETBUFFER (obuf
, old_buf
);
1418 Fset_marker (old_buf
->begv_marker
, make_number (BUF_BEGV (old_buf
)),
1421 if (! NILP (old_buf
->zv_marker
))
1424 XSETBUFFER (obuf
, old_buf
);
1425 Fset_marker (old_buf
->zv_marker
, make_number (BUF_ZV (old_buf
)),
1430 /* Get the undo list from the base buffer, so that it appears
1431 that an indirect buffer shares the undo list of its base. */
1433 b
->undo_list
= b
->base_buffer
->undo_list
;
1435 /* If the new current buffer has markers to record PT, BEGV and ZV
1436 when it is not current, fetch them now. */
1437 if (! NILP (b
->pt_marker
))
1438 BUF_PT (b
) = marker_position (b
->pt_marker
);
1439 if (! NILP (b
->begv_marker
))
1440 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1441 if (! NILP (b
->zv_marker
))
1442 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1444 /* Look down buffer's list of local Lisp variables
1445 to find and update any that forward into C variables. */
1447 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1449 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1450 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1451 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1452 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1453 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1454 /* Just reference the variable
1455 to cause it to become set for this buffer. */
1456 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1459 /* Do the same with any others that were local to the previous buffer */
1462 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1464 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1465 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1466 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1467 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1468 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1469 /* Just reference the variable
1470 to cause it to become set for this buffer. */
1471 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1475 /* Switch to buffer B temporarily for redisplay purposes.
1476 This avoids certain things that don't need to be done within redisplay. */
1482 register struct buffer
*old_buf
;
1484 if (current_buffer
== b
)
1487 old_buf
= current_buffer
;
1492 /* If the old current buffer has markers to record PT, BEGV and ZV
1493 when it is not current, update them now. */
1494 if (! NILP (old_buf
->pt_marker
))
1497 XSETBUFFER (obuf
, old_buf
);
1498 Fset_marker (old_buf
->pt_marker
, make_number (BUF_PT (old_buf
)),
1501 if (! NILP (old_buf
->begv_marker
))
1504 XSETBUFFER (obuf
, old_buf
);
1505 Fset_marker (old_buf
->begv_marker
, make_number (BUF_BEGV (old_buf
)),
1508 if (! NILP (old_buf
->zv_marker
))
1511 XSETBUFFER (obuf
, old_buf
);
1512 Fset_marker (old_buf
->zv_marker
, make_number (BUF_ZV (old_buf
)),
1517 /* If the new current buffer has markers to record PT, BEGV and ZV
1518 when it is not current, fetch them now. */
1519 if (! NILP (b
->pt_marker
))
1520 BUF_PT (b
) = marker_position (b
->pt_marker
);
1521 if (! NILP (b
->begv_marker
))
1522 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1523 if (! NILP (b
->zv_marker
))
1524 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1527 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1528 "Make the buffer BUFFER current for editing operations.\n\
1529 BUFFER may be a buffer or the name of an existing buffer.\n\
1530 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1531 This function does not display the buffer, so its effect ends\n\
1532 when the current command terminates.\n\
1533 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1535 register Lisp_Object buffer
;
1537 register Lisp_Object buf
;
1538 buf
= Fget_buffer (buffer
);
1541 if (NILP (XBUFFER (buf
)->name
))
1542 error ("Selecting deleted buffer");
1543 set_buffer_internal (XBUFFER (buf
));
1547 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1548 Sbarf_if_buffer_read_only
, 0, 0, 0,
1549 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1552 if (!NILP (current_buffer
->read_only
)
1553 && NILP (Vinhibit_read_only
))
1554 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1558 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1559 "Put BUFFER at the end of the list of all buffers.\n\
1560 There it is the least likely candidate for `other-buffer' to return;\n\
1561 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1562 If BUFFER is nil or omitted, bury the current buffer.\n\
1563 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1564 selected window if it is displayed there.")
1566 register Lisp_Object buffer
;
1568 /* Figure out what buffer we're going to bury. */
1571 XSETBUFFER (buffer
, current_buffer
);
1573 /* If we're burying the current buffer, unshow it. */
1574 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
), Qnil
);
1580 buf1
= Fget_buffer (buffer
);
1586 /* Move buffer to the end of the buffer list. */
1588 register Lisp_Object aelt
, link
;
1590 aelt
= Frassq (buffer
, Vbuffer_alist
);
1591 link
= Fmemq (aelt
, Vbuffer_alist
);
1592 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1593 XCONS (link
)->cdr
= Qnil
;
1594 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1597 frames_bury_buffer (buffer
);
1602 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1603 "Delete the entire contents of the current buffer.\n\
1604 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1605 so the buffer is truly empty after this.")
1610 current_buffer
->last_window_start
= 1;
1611 /* Prevent warnings, or suspension of auto saving, that would happen
1612 if future size is less than past size. Use of erase-buffer
1613 implies that the future text is not really related to the past text. */
1614 XSETFASTINT (current_buffer
->save_length
, 0);
1619 validate_region (b
, e
)
1620 register Lisp_Object
*b
, *e
;
1622 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1623 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1625 if (XINT (*b
) > XINT (*e
))
1628 tem
= *b
; *b
= *e
; *e
= tem
;
1631 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1632 && XINT (*e
) <= ZV
))
1633 args_out_of_range (*b
, *e
);
1636 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
1638 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1639 Most local variable bindings are eliminated so that the default values\n\
1640 become effective once more. Also, the syntax table is set from\n\
1641 `standard-syntax-table', the local keymap is set to nil,\n\
1642 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1643 This function also forces redisplay of the mode line.\n\
1645 Every function to select a new major mode starts by\n\
1646 calling this function.\n\n\
1647 As a special exception, local variables whose names have\n\
1648 a non-nil `permanent-local' property are not eliminated by this function.\n\
1650 The first thing this function does is run\n\
1651 the normal hook `change-major-mode-hook'.")
1654 register Lisp_Object alist
, sym
, tem
;
1657 if (!NILP (Vrun_hooks
))
1658 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
1659 oalist
= current_buffer
->local_var_alist
;
1661 /* Make sure none of the bindings in oalist
1662 remain swapped in, in their symbols. */
1664 swap_out_buffer_local_variables (current_buffer
);
1666 /* Actually eliminate all local bindings of this buffer. */
1668 reset_buffer_local_variables (current_buffer
, 0);
1670 /* Redisplay mode lines; we are changing major mode. */
1672 update_mode_lines
++;
1674 /* Any which are supposed to be permanent,
1675 make local again, with the same values they had. */
1677 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1679 sym
= XCONS (XCONS (alist
)->car
)->car
;
1680 tem
= Fget (sym
, Qpermanent_local
);
1683 Fmake_local_variable (sym
);
1684 Fset (sym
, XCONS (XCONS (alist
)->car
)->cdr
);
1688 /* Force mode-line redisplay. Useful here because all major mode
1689 commands call this function. */
1690 update_mode_lines
++;
1695 /* Make sure no local variables remain set up with buffer B
1696 for their current values. */
1699 swap_out_buffer_local_variables (b
)
1702 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
1704 XSETBUFFER (buffer
, b
);
1705 oalist
= b
->local_var_alist
;
1707 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1709 sym
= XCONS (XCONS (alist
)->car
)->car
;
1711 /* Need not do anything if some other buffer's binding is now encached. */
1712 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
;
1713 if (XBUFFER (tem
) == current_buffer
)
1715 /* Symbol is set up for this buffer's old local value.
1716 Set it up for the current buffer with the default value. */
1718 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->cdr
;
1719 /* Store the symbol's current value into the alist entry
1720 it is currently set up for. This is so that, if the
1721 local is marked permanent, and we make it local again
1722 later in Fkill_all_local_variables, we don't lose the value. */
1723 XCONS (XCONS (tem
)->car
)->cdr
1724 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
);
1725 /* Switch to the symbol's default-value alist entry. */
1726 XCONS (tem
)->car
= tem
;
1727 /* Mark it as current for buffer B. */
1728 XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
1730 /* Store the current value into any forwarding in the symbol. */
1731 store_symval_forwarding (sym
, XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
,
1737 /* Find all the overlays in the current buffer that contain position POS.
1738 Return the number found, and store them in a vector in *VEC_PTR.
1739 Store in *LEN_PTR the size allocated for the vector.
1740 Store in *NEXT_PTR the next position after POS where an overlay starts,
1741 or ZV if there are no more overlays.
1742 Store in *PREV_PTR the previous position before POS where an overlay ends,
1743 or BEGV if there are no previous overlays.
1744 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1746 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1747 when this function is called.
1749 If EXTEND is non-zero, we make the vector bigger if necessary.
1750 If EXTEND is zero, we never extend the vector,
1751 and we store only as many overlays as will fit.
1752 But we still return the total number of overlays. */
1755 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1758 Lisp_Object
**vec_ptr
;
1763 Lisp_Object tail
, overlay
, start
, end
, result
;
1766 Lisp_Object
*vec
= *vec_ptr
;
1769 int inhibit_storing
= 0;
1771 for (tail
= current_buffer
->overlays_before
;
1773 tail
= XCONS (tail
)->cdr
)
1775 int startpos
, endpos
;
1777 overlay
= XCONS (tail
)->car
;
1779 start
= OVERLAY_START (overlay
);
1780 end
= OVERLAY_END (overlay
);
1781 endpos
= OVERLAY_POSITION (end
);
1790 startpos
= OVERLAY_POSITION (start
);
1791 if (startpos
<= pos
)
1795 /* The supplied vector is full.
1796 Either make it bigger, or don't store any more in it. */
1799 *len_ptr
= len
*= 2;
1800 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1804 inhibit_storing
= 1;
1807 if (!inhibit_storing
)
1809 /* Keep counting overlays even if we can't return them all. */
1812 else if (startpos
< next
)
1816 for (tail
= current_buffer
->overlays_after
;
1818 tail
= XCONS (tail
)->cdr
)
1820 int startpos
, endpos
;
1822 overlay
= XCONS (tail
)->car
;
1824 start
= OVERLAY_START (overlay
);
1825 end
= OVERLAY_END (overlay
);
1826 startpos
= OVERLAY_POSITION (start
);
1829 if (startpos
< next
)
1833 endpos
= OVERLAY_POSITION (end
);
1840 *len_ptr
= len
*= 2;
1841 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1845 inhibit_storing
= 1;
1848 if (!inhibit_storing
)
1852 else if (endpos
< pos
&& endpos
> prev
)
1863 /* Find all the overlays in the current buffer that overlap the range BEG-END
1864 or are empty at BEG.
1866 Return the number found, and store them in a vector in *VEC_PTR.
1867 Store in *LEN_PTR the size allocated for the vector.
1868 Store in *NEXT_PTR the next position after POS where an overlay starts,
1869 or ZV if there are no more overlays.
1870 Store in *PREV_PTR the previous position before POS where an overlay ends,
1871 or BEGV if there are no previous overlays.
1872 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1874 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1875 when this function is called.
1877 If EXTEND is non-zero, we make the vector bigger if necessary.
1878 If EXTEND is zero, we never extend the vector,
1879 and we store only as many overlays as will fit.
1880 But we still return the total number of overlays. */
1883 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1886 Lisp_Object
**vec_ptr
;
1891 Lisp_Object tail
, overlay
, ostart
, oend
, result
;
1894 Lisp_Object
*vec
= *vec_ptr
;
1897 int inhibit_storing
= 0;
1899 for (tail
= current_buffer
->overlays_before
;
1901 tail
= XCONS (tail
)->cdr
)
1903 int startpos
, endpos
;
1905 overlay
= XCONS (tail
)->car
;
1907 ostart
= OVERLAY_START (overlay
);
1908 oend
= OVERLAY_END (overlay
);
1909 endpos
= OVERLAY_POSITION (oend
);
1916 startpos
= OVERLAY_POSITION (ostart
);
1917 /* Count an interval if it either overlaps the range
1918 or is empty at the start of the range. */
1919 if ((beg
< endpos
&& startpos
< end
)
1920 || (startpos
== endpos
&& beg
== endpos
))
1924 /* The supplied vector is full.
1925 Either make it bigger, or don't store any more in it. */
1928 *len_ptr
= len
*= 2;
1929 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1933 inhibit_storing
= 1;
1936 if (!inhibit_storing
)
1938 /* Keep counting overlays even if we can't return them all. */
1941 else if (startpos
< next
)
1945 for (tail
= current_buffer
->overlays_after
;
1947 tail
= XCONS (tail
)->cdr
)
1949 int startpos
, endpos
;
1951 overlay
= XCONS (tail
)->car
;
1953 ostart
= OVERLAY_START (overlay
);
1954 oend
= OVERLAY_END (overlay
);
1955 startpos
= OVERLAY_POSITION (ostart
);
1958 if (startpos
< next
)
1962 endpos
= OVERLAY_POSITION (oend
);
1963 /* Count an interval if it either overlaps the range
1964 or is empty at the start of the range. */
1965 if ((beg
< endpos
&& startpos
< end
)
1966 || (startpos
== endpos
&& beg
== endpos
))
1972 *len_ptr
= len
*= 2;
1973 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1977 inhibit_storing
= 1;
1980 if (!inhibit_storing
)
1984 else if (endpos
< beg
&& endpos
> prev
)
1995 /* Fast function to just test if we're at an overlay boundary. */
1997 overlay_touches_p (pos
)
2000 Lisp_Object tail
, overlay
;
2002 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
2003 tail
= XCONS (tail
)->cdr
)
2007 overlay
= XCONS (tail
)->car
;
2008 if (!GC_OVERLAYP (overlay
))
2011 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2014 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2018 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
2019 tail
= XCONS (tail
)->cdr
)
2023 overlay
= XCONS (tail
)->car
;
2024 if (!GC_OVERLAYP (overlay
))
2027 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2030 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2038 Lisp_Object overlay
;
2044 compare_overlays (s1
, s2
)
2045 struct sortvec
*s1
, *s2
;
2047 if (s1
->priority
!= s2
->priority
)
2048 return s1
->priority
- s2
->priority
;
2049 if (s1
->beg
!= s2
->beg
)
2050 return s1
->beg
- s2
->beg
;
2051 if (s1
->end
!= s2
->end
)
2052 return s2
->end
- s1
->end
;
2056 /* Sort an array of overlays by priority. The array is modified in place.
2057 The return value is the new size; this may be smaller than the original
2058 size if some of the overlays were invalid or were window-specific. */
2060 sort_overlays (overlay_vec
, noverlays
, w
)
2061 Lisp_Object
*overlay_vec
;
2066 struct sortvec
*sortvec
;
2067 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2069 /* Put the valid and relevant overlays into sortvec. */
2071 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2074 Lisp_Object overlay
;
2076 overlay
= overlay_vec
[i
];
2077 if (OVERLAY_VALID (overlay
)
2078 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2079 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2081 /* If we're interested in a specific window, then ignore
2082 overlays that are limited to some other window. */
2087 window
= Foverlay_get (overlay
, Qwindow
);
2088 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2092 /* This overlay is good and counts: put it into sortvec. */
2093 sortvec
[j
].overlay
= overlay
;
2094 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2095 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2096 tem
= Foverlay_get (overlay
, Qpriority
);
2098 sortvec
[j
].priority
= XINT (tem
);
2100 sortvec
[j
].priority
= 0;
2106 /* Sort the overlays into the proper order: increasing priority. */
2109 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2111 for (i
= 0; i
< noverlays
; i
++)
2112 overlay_vec
[i
] = sortvec
[i
].overlay
;
2118 Lisp_Object string
, string2
;
2125 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2126 int size
; /* Allocated length of that array. */
2127 int used
; /* How much of the array is currently in use. */
2128 int bytes
; /* Total length of the strings in buf. */
2131 /* Buffers for storing information about the overlays touching a given
2132 position. These could be automatic variables in overlay_strings, but
2133 it's more efficient to hold onto the memory instead of repeatedly
2134 allocating and freeing it. */
2135 static struct sortstrlist overlay_heads
, overlay_tails
;
2136 static unsigned char *overlay_str_buf
;
2138 /* Allocated length of overlay_str_buf. */
2139 static int overlay_str_len
;
2141 /* A comparison function suitable for passing to qsort. */
2143 cmp_for_strings (as1
, as2
)
2146 struct sortstr
*s1
= (struct sortstr
*)as1
;
2147 struct sortstr
*s2
= (struct sortstr
*)as2
;
2148 if (s1
->size
!= s2
->size
)
2149 return s2
->size
- s1
->size
;
2150 if (s1
->priority
!= s2
->priority
)
2151 return s1
->priority
- s2
->priority
;
2156 record_overlay_string (ssl
, str
, str2
, pri
, size
)
2157 struct sortstrlist
*ssl
;
2158 Lisp_Object str
, str2
, pri
;
2161 if (ssl
->used
== ssl
->size
)
2167 ssl
->buf
= ((struct sortstr
*)
2168 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2170 ssl
->buf
[ssl
->used
].string
= str
;
2171 ssl
->buf
[ssl
->used
].string2
= str2
;
2172 ssl
->buf
[ssl
->used
].size
= size
;
2173 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2175 ssl
->bytes
+= XSTRING (str
)->size
;
2177 ssl
->bytes
+= XSTRING (str2
)->size
;
2180 /* Return the concatenation of the strings associated with overlays that
2181 begin or end at POS, ignoring overlays that are specific to a window
2182 other than W. The strings are concatenated in the appropriate order:
2183 shorter overlays nest inside longer ones, and higher priority inside
2184 lower. Normally all of the after-strings come first, but zero-sized
2185 overlays have their after-strings ride along with the before-strings
2186 because it would look strange to print them inside-out.
2188 Returns the string length, and stores the contents indirectly through
2189 PSTR, if that variable is non-null. The string may be overwritten by
2190 subsequent calls. */
2193 overlay_strings (pos
, w
, pstr
)
2196 unsigned char **pstr
;
2198 Lisp_Object ov
, overlay
, window
, str
;
2199 int startpos
, endpos
;
2201 overlay_heads
.used
= overlay_heads
.bytes
= 0;
2202 overlay_tails
.used
= overlay_tails
.bytes
= 0;
2203 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCONS (ov
)->cdr
)
2205 overlay
= XCONS (ov
)->car
;
2206 if (!OVERLAYP (overlay
))
2209 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2210 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2213 if (endpos
!= pos
&& startpos
!= pos
)
2215 window
= Foverlay_get (overlay
, Qwindow
);
2216 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2219 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2220 record_overlay_string (&overlay_heads
, str
,
2222 ? Foverlay_get (overlay
, Qafter_string
)
2224 Foverlay_get (overlay
, Qpriority
),
2226 else if (endpos
== pos
2227 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2228 record_overlay_string (&overlay_tails
, str
, Qnil
,
2229 Foverlay_get (overlay
, Qpriority
),
2232 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCONS (ov
)->cdr
)
2234 overlay
= XCONS (ov
)->car
;
2235 if (!OVERLAYP (overlay
))
2238 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2239 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2242 if (endpos
!= pos
&& startpos
!= pos
)
2244 window
= Foverlay_get (overlay
, Qwindow
);
2245 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2248 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2249 record_overlay_string (&overlay_heads
, str
,
2251 ? Foverlay_get (overlay
, Qafter_string
)
2253 Foverlay_get (overlay
, Qpriority
),
2255 else if (endpos
== pos
2256 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2257 record_overlay_string (&overlay_tails
, str
, Qnil
,
2258 Foverlay_get (overlay
, Qpriority
),
2261 if (overlay_tails
.used
> 1)
2262 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
2264 if (overlay_heads
.used
> 1)
2265 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
2267 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
2272 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
2274 if (total
> overlay_str_len
)
2276 overlay_str_len
= total
;
2277 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
2280 p
= overlay_str_buf
;
2281 for (i
= overlay_tails
.used
; --i
>= 0;)
2283 tem
= overlay_tails
.buf
[i
].string
;
2284 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2285 p
+= XSTRING (tem
)->size
;
2287 for (i
= 0; i
< overlay_heads
.used
; ++i
)
2289 tem
= overlay_heads
.buf
[i
].string
;
2290 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2291 p
+= XSTRING (tem
)->size
;
2292 tem
= overlay_heads
.buf
[i
].string2
;
2295 bcopy (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size
);
2296 p
+= XSTRING (tem
)->size
;
2299 if (p
!= overlay_str_buf
+ total
)
2302 *pstr
= overlay_str_buf
;
2308 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2311 recenter_overlay_lists (buf
, pos
)
2315 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
2317 /* See if anything in overlays_before should move to overlays_after. */
2319 /* We don't strictly need prev in this loop; it should always be nil.
2320 But we use it for symmetry and in case that should cease to be true
2321 with some future change. */
2323 for (tail
= buf
->overlays_before
;
2325 prev
= tail
, tail
= next
)
2327 next
= XCONS (tail
)->cdr
;
2328 overlay
= XCONS (tail
)->car
;
2330 /* If the overlay is not valid, get rid of it. */
2331 if (!OVERLAY_VALID (overlay
))
2336 /* Splice the cons cell TAIL out of overlays_before. */
2338 XCONS (prev
)->cdr
= next
;
2340 buf
->overlays_before
= next
;
2346 beg
= OVERLAY_START (overlay
);
2347 end
= OVERLAY_END (overlay
);
2349 if (OVERLAY_POSITION (end
) > pos
)
2351 /* OVERLAY needs to be moved. */
2352 int where
= OVERLAY_POSITION (beg
);
2353 Lisp_Object other
, other_prev
;
2355 /* Splice the cons cell TAIL out of overlays_before. */
2357 XCONS (prev
)->cdr
= next
;
2359 buf
->overlays_before
= next
;
2361 /* Search thru overlays_after for where to put it. */
2363 for (other
= buf
->overlays_after
;
2365 other_prev
= other
, other
= XCONS (other
)->cdr
)
2367 Lisp_Object otherbeg
, otheroverlay
, follower
;
2370 otheroverlay
= XCONS (other
)->car
;
2371 if (! OVERLAY_VALID (otheroverlay
))
2374 otherbeg
= OVERLAY_START (otheroverlay
);
2375 if (OVERLAY_POSITION (otherbeg
) >= where
)
2379 /* Add TAIL to overlays_after before OTHER. */
2380 XCONS (tail
)->cdr
= other
;
2381 if (!NILP (other_prev
))
2382 XCONS (other_prev
)->cdr
= tail
;
2384 buf
->overlays_after
= tail
;
2388 /* We've reached the things that should stay in overlays_before.
2389 All the rest of overlays_before must end even earlier,
2394 /* See if anything in overlays_after should be in overlays_before. */
2396 for (tail
= buf
->overlays_after
;
2398 prev
= tail
, tail
= next
)
2400 next
= XCONS (tail
)->cdr
;
2401 overlay
= XCONS (tail
)->car
;
2403 /* If the overlay is not valid, get rid of it. */
2404 if (!OVERLAY_VALID (overlay
))
2409 /* Splice the cons cell TAIL out of overlays_after. */
2411 XCONS (prev
)->cdr
= next
;
2413 buf
->overlays_after
= next
;
2419 beg
= OVERLAY_START (overlay
);
2420 end
= OVERLAY_END (overlay
);
2422 /* Stop looking, when we know that nothing further
2423 can possibly end before POS. */
2424 if (OVERLAY_POSITION (beg
) > pos
)
2427 if (OVERLAY_POSITION (end
) <= pos
)
2429 /* OVERLAY needs to be moved. */
2430 int where
= OVERLAY_POSITION (end
);
2431 Lisp_Object other
, other_prev
;
2433 /* Splice the cons cell TAIL out of overlays_after. */
2435 XCONS (prev
)->cdr
= next
;
2437 buf
->overlays_after
= next
;
2439 /* Search thru overlays_before for where to put it. */
2441 for (other
= buf
->overlays_before
;
2443 other_prev
= other
, other
= XCONS (other
)->cdr
)
2445 Lisp_Object otherend
, otheroverlay
;
2448 otheroverlay
= XCONS (other
)->car
;
2449 if (! OVERLAY_VALID (otheroverlay
))
2452 otherend
= OVERLAY_END (otheroverlay
);
2453 if (OVERLAY_POSITION (otherend
) <= where
)
2457 /* Add TAIL to overlays_before before OTHER. */
2458 XCONS (tail
)->cdr
= other
;
2459 if (!NILP (other_prev
))
2460 XCONS (other_prev
)->cdr
= tail
;
2462 buf
->overlays_before
= tail
;
2467 XSETFASTINT (buf
->overlay_center
, pos
);
2471 adjust_overlays_for_insert (pos
, length
)
2475 /* After an insertion, the lists are still sorted properly,
2476 but we may need to update the value of the overlay center. */
2477 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
2478 XSETFASTINT (current_buffer
->overlay_center
,
2479 XFASTINT (current_buffer
->overlay_center
) + length
);
2483 adjust_overlays_for_delete (pos
, length
)
2487 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
2488 /* The deletion was to our right. No change needed; the before- and
2489 after-lists are still consistent. */
2491 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
2492 /* The deletion was to our left. We need to adjust the center value
2493 to account for the change in position, but the lists are consistent
2494 given the new value. */
2495 XSETFASTINT (current_buffer
->overlay_center
,
2496 XFASTINT (current_buffer
->overlay_center
) - length
);
2498 /* We're right in the middle. There might be things on the after-list
2499 that now belong on the before-list. Recentering will move them,
2500 and also update the center point. */
2501 recenter_overlay_lists (current_buffer
, pos
);
2504 /* Fix up overlays that were garbled as a result of permuting markers
2505 in the range START through END. Any overlay with at least one
2506 endpoint in this range will need to be unlinked from the overlay
2507 list and reinserted in its proper place.
2508 Such an overlay might even have negative size at this point.
2509 If so, we'll reverse the endpoints. Can you think of anything
2510 better to do in this situation? */
2512 fix_overlays_in_range (start
, end
)
2513 register int start
, end
;
2515 Lisp_Object tem
, overlay
;
2516 Lisp_Object before_list
, after_list
;
2517 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
2518 int startpos
, endpos
;
2520 /* This algorithm shifts links around instead of consing and GCing.
2521 The loop invariant is that before_list (resp. after_list) is a
2522 well-formed list except that its last element, the one that
2523 *pbefore (resp. *pafter) points to, is still uninitialized.
2524 So it's not a bug that before_list isn't initialized, although
2525 it may look strange. */
2526 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
2528 overlay
= XCONS (*ptail
)->car
;
2529 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2532 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2534 || (startpos
>= start
&& startpos
< end
))
2536 /* If the overlay is backwards, fix that now. */
2537 if (startpos
> endpos
)
2540 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
2542 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
2544 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2546 /* Add it to the end of the wrong list. Later on,
2547 recenter_overlay_lists will move it to the right place. */
2548 if (endpos
< XINT (current_buffer
->overlay_center
))
2551 pafter
= &XCONS (*ptail
)->cdr
;
2556 pbefore
= &XCONS (*ptail
)->cdr
;
2558 *ptail
= XCONS (*ptail
)->cdr
;
2561 ptail
= &XCONS (*ptail
)->cdr
;
2563 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
2565 overlay
= XCONS (*ptail
)->car
;
2566 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2567 if (startpos
>= end
)
2569 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2570 if (startpos
>= start
2571 || (endpos
>= start
&& endpos
< end
))
2573 if (startpos
> endpos
)
2576 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
2578 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
2580 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2582 if (endpos
< XINT (current_buffer
->overlay_center
))
2585 pafter
= &XCONS (*ptail
)->cdr
;
2590 pbefore
= &XCONS (*ptail
)->cdr
;
2592 *ptail
= XCONS (*ptail
)->cdr
;
2595 ptail
= &XCONS (*ptail
)->cdr
;
2598 /* Splice the constructed (wrong) lists into the buffer's lists,
2599 and let the recenter function make it sane again. */
2600 *pbefore
= current_buffer
->overlays_before
;
2601 current_buffer
->overlays_before
= before_list
;
2602 recenter_overlay_lists (current_buffer
,
2603 XINT (current_buffer
->overlay_center
));
2605 *pafter
= current_buffer
->overlays_after
;
2606 current_buffer
->overlays_after
= after_list
;
2607 recenter_overlay_lists (current_buffer
,
2608 XINT (current_buffer
->overlay_center
));
2611 /* We have two types of overlay: the one whose ending marker is
2612 after-insertion-marker (this is the usual case) and the one whose
2613 ending marker is before-insertion-marker. When `overlays_before'
2614 contains overlays of the latter type and the former type in this
2615 order and both overlays end at inserting position, inserting a text
2616 increases only the ending marker of the latter type, which results
2617 in incorrect ordering of `overlays_before'.
2619 This function fixes ordering of overlays in the slot
2620 `overlays_before' of the buffer *BP. Before the insertion, `point'
2621 was at PREV, and now is at POS. */
2624 fix_overlays_before (bp
, prev
, pos
)
2628 Lisp_Object
*tailp
= &bp
->overlays_before
;
2629 Lisp_Object
*right_place
;
2632 /* After the insertion, the several overlays may be in incorrect
2633 order. The possibility is that, in the list `overlays_before',
2634 an overlay which ends at POS appears after an overlay which ends
2635 at PREV. Since POS is greater than PREV, we must fix the
2636 ordering of these overlays, by moving overlays ends at POS before
2637 the overlays ends at PREV. */
2639 /* At first, find a place where disordered overlays should be linked
2640 in. It is where an overlay which end before POS exists. (i.e. an
2641 overlay whose ending marker is after-insertion-marker if disorder
2643 while (!NILP (*tailp
)
2644 && ((end
= OVERLAY_POSITION (OVERLAY_END (XCONS (*tailp
)->car
)))
2646 tailp
= &XCONS (*tailp
)->cdr
;
2648 /* If we don't find such an overlay,
2649 or the found one ends before PREV,
2650 or the found one is the last one in the list,
2651 we don't have to fix anything. */
2654 || NILP (XCONS (*tailp
)->cdr
))
2657 right_place
= tailp
;
2658 tailp
= &XCONS (*tailp
)->cdr
;
2660 /* Now, end position of overlays in the list *TAILP should be before
2661 or equal to PREV. In the loop, an overlay which ends at POS is
2662 moved ahead to the place pointed by RIGHT_PLACE. If we found an
2663 overlay which ends before PREV, the remaining overlays are in
2665 while (!NILP (*tailp
))
2667 end
= OVERLAY_POSITION (OVERLAY_END (XCONS (*tailp
)->car
));
2670 { /* This overlay is disordered. */
2671 Lisp_Object found
= *tailp
;
2673 /* Unlink the found overlay. */
2674 *tailp
= XCONS (found
)->cdr
;
2675 /* Move an overlay at RIGHT_PLACE to the next of the found one. */
2676 XCONS (found
)->cdr
= *right_place
;
2677 /* Link it into the right place. */
2678 *right_place
= found
;
2680 else if (end
== prev
)
2681 tailp
= &XCONS (*tailp
)->cdr
;
2682 else /* No more disordered overlay. */
2687 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
2688 "Return t if OBJECT is an overlay.")
2692 return (OVERLAYP (object
) ? Qt
: Qnil
);
2695 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
2696 "Create a new overlay with range BEG to END in BUFFER.\n\
2697 If omitted, BUFFER defaults to the current buffer.\n\
2698 BEG and END may be integers or markers.\n\
2699 The fourth arg FRONT-ADVANCE, if non-nil, makes the\n\
2700 front delimiter advance when text is inserted there.\n\
2701 The fifth arg REAR-ADVANCE, if non-nil, makes the\n\
2702 rear delimiter advance when text is inserted there.")
2703 (beg
, end
, buffer
, front_advance
, rear_advance
)
2704 Lisp_Object beg
, end
, buffer
;
2705 Lisp_Object front_advance
, rear_advance
;
2707 Lisp_Object overlay
;
2711 XSETBUFFER (buffer
, current_buffer
);
2713 CHECK_BUFFER (buffer
, 2);
2715 && ! EQ (Fmarker_buffer (beg
), buffer
))
2716 error ("Marker points into wrong buffer");
2718 && ! EQ (Fmarker_buffer (end
), buffer
))
2719 error ("Marker points into wrong buffer");
2721 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2722 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2724 if (XINT (beg
) > XINT (end
))
2727 temp
= beg
; beg
= end
; end
= temp
;
2730 b
= XBUFFER (buffer
);
2732 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
2733 end
= Fset_marker (Fmake_marker (), end
, buffer
);
2735 if (!NILP (front_advance
))
2736 XMARKER (beg
)->insertion_type
= 1;
2737 if (!NILP (rear_advance
))
2738 XMARKER (end
)->insertion_type
= 1;
2740 overlay
= allocate_misc ();
2741 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
2742 XOVERLAY (overlay
)->start
= beg
;
2743 XOVERLAY (overlay
)->end
= end
;
2744 XOVERLAY (overlay
)->plist
= Qnil
;
2746 /* Put the new overlay on the wrong list. */
2747 end
= OVERLAY_END (overlay
);
2748 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2749 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2751 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2753 /* This puts it in the right list, and in the right order. */
2754 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2756 /* We don't need to redisplay the region covered by the overlay, because
2757 the overlay has no properties at the moment. */
2762 /* Mark a section of BUF as needing redisplay because of overlays changes. */
2765 modify_overlay (buf
, start
, end
)
2775 start
= end
; end
= temp
;
2778 /* If this is a buffer not in the selected window,
2779 we must do other windows. */
2780 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
2781 windows_or_buffers_changed
= 1;
2782 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2783 else if (buf
!= current_buffer
)
2784 windows_or_buffers_changed
= 1;
2785 /* If multiple windows show this buffer, we must do other windows. */
2786 else if (buffer_shared
> 1)
2787 windows_or_buffers_changed
= 1;
2790 if (unchanged_modified
== MODIFF
2791 && overlay_unchanged_modified
== OVERLAY_MODIFF
)
2793 beg_unchanged
= start
- BEG
;
2794 end_unchanged
= Z
- end
;
2798 if (Z
- end
< end_unchanged
)
2799 end_unchanged
= Z
- end
;
2800 if (start
- BEG
< beg_unchanged
)
2801 beg_unchanged
= start
- BEG
;
2805 ++BUF_OVERLAY_MODIFF (buf
);
2809 Lisp_Object
Fdelete_overlay ();
2811 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
2812 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
2813 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
2814 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
2816 (overlay
, beg
, end
, buffer
)
2817 Lisp_Object overlay
, beg
, end
, buffer
;
2819 struct buffer
*b
, *ob
;
2820 Lisp_Object obuffer
;
2821 int count
= specpdl_ptr
- specpdl
;
2823 CHECK_OVERLAY (overlay
, 0);
2825 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2827 XSETBUFFER (buffer
, current_buffer
);
2828 CHECK_BUFFER (buffer
, 3);
2831 && ! EQ (Fmarker_buffer (beg
), buffer
))
2832 error ("Marker points into wrong buffer");
2834 && ! EQ (Fmarker_buffer (end
), buffer
))
2835 error ("Marker points into wrong buffer");
2837 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2838 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2840 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
2841 return Fdelete_overlay (overlay
);
2843 if (XINT (beg
) > XINT (end
))
2846 temp
= beg
; beg
= end
; end
= temp
;
2849 specbind (Qinhibit_quit
, Qt
);
2851 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2852 b
= XBUFFER (buffer
);
2853 ob
= XBUFFER (obuffer
);
2855 /* If the overlay has changed buffers, do a thorough redisplay. */
2856 if (!EQ (buffer
, obuffer
))
2858 /* Redisplay where the overlay was. */
2859 if (!NILP (obuffer
))
2864 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2865 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2867 modify_overlay (ob
, o_beg
, o_end
);
2870 /* Redisplay where the overlay is going to be. */
2871 modify_overlay (b
, XINT (beg
), XINT (end
));
2874 /* Redisplay the area the overlay has just left, or just enclosed. */
2877 int change_beg
, change_end
;
2879 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2880 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2882 if (o_beg
== XINT (beg
))
2883 modify_overlay (b
, o_end
, XINT (end
));
2884 else if (o_end
== XINT (end
))
2885 modify_overlay (b
, o_beg
, XINT (beg
));
2888 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
2889 if (XINT (end
) > o_end
) o_end
= XINT (end
);
2890 modify_overlay (b
, o_beg
, o_end
);
2894 if (!NILP (obuffer
))
2896 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
2897 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
2900 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
2901 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
2903 /* Put the overlay on the wrong list. */
2904 end
= OVERLAY_END (overlay
);
2905 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2906 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2908 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2910 /* This puts it in the right list, and in the right order. */
2911 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2913 return unbind_to (count
, overlay
);
2916 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
2917 "Delete the overlay OVERLAY from its buffer.")
2919 Lisp_Object overlay
;
2923 int count
= specpdl_ptr
- specpdl
;
2925 CHECK_OVERLAY (overlay
, 0);
2927 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2931 b
= XBUFFER (buffer
);
2933 specbind (Qinhibit_quit
, Qt
);
2935 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
2936 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
2939 marker_position (OVERLAY_START (overlay
)),
2940 marker_position (OVERLAY_END (overlay
)));
2942 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
2943 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
2945 return unbind_to (count
, Qnil
);
2948 /* Overlay dissection functions. */
2950 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
2951 "Return the position at which OVERLAY starts.")
2953 Lisp_Object overlay
;
2955 CHECK_OVERLAY (overlay
, 0);
2957 return (Fmarker_position (OVERLAY_START (overlay
)));
2960 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
2961 "Return the position at which OVERLAY ends.")
2963 Lisp_Object overlay
;
2965 CHECK_OVERLAY (overlay
, 0);
2967 return (Fmarker_position (OVERLAY_END (overlay
)));
2970 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
2971 "Return the buffer OVERLAY belongs to.")
2973 Lisp_Object overlay
;
2975 CHECK_OVERLAY (overlay
, 0);
2977 return Fmarker_buffer (OVERLAY_START (overlay
));
2980 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
2981 "Return a list of the properties on OVERLAY.\n\
2982 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
2985 Lisp_Object overlay
;
2987 CHECK_OVERLAY (overlay
, 0);
2989 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
2993 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
2994 "Return a list of the overlays that contain position POS.")
2999 Lisp_Object
*overlay_vec
;
3003 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3006 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3008 /* Put all the overlays we want in a vector in overlay_vec.
3009 Store the length in len. */
3010 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3011 (int *) 0, (int *) 0);
3013 /* Make a list of them all. */
3014 result
= Flist (noverlays
, overlay_vec
);
3016 xfree (overlay_vec
);
3020 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3021 "Return a list of the overlays that overlap the region BEG ... END.\n\
3022 Overlap means that at least one character is contained within the overlay\n\
3023 and also contained within the specified region.\n\
3024 Empty overlays are included in the result if they are located at BEG\n\
3025 or between BEG and END.")
3027 Lisp_Object beg
, end
;
3030 Lisp_Object
*overlay_vec
;
3034 CHECK_NUMBER_COERCE_MARKER (beg
, 0);
3035 CHECK_NUMBER_COERCE_MARKER (end
, 0);
3038 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3040 /* Put all the overlays we want in a vector in overlay_vec.
3041 Store the length in len. */
3042 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3043 (int *) 0, (int *) 0);
3045 /* Make a list of them all. */
3046 result
= Flist (noverlays
, overlay_vec
);
3048 xfree (overlay_vec
);
3052 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3054 "Return the next position after POS where an overlay starts or ends.\n\
3055 If there are no more overlay boundaries after POS, return (point-max).")
3061 Lisp_Object
*overlay_vec
;
3065 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3068 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3070 /* Put all the overlays we want in a vector in overlay_vec.
3071 Store the length in len.
3072 endpos gets the position where the next overlay starts. */
3073 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3074 &endpos
, (int *) 0);
3076 /* If any of these overlays ends before endpos,
3077 use its ending point instead. */
3078 for (i
= 0; i
< noverlays
; i
++)
3083 oend
= OVERLAY_END (overlay_vec
[i
]);
3084 oendpos
= OVERLAY_POSITION (oend
);
3085 if (oendpos
< endpos
)
3089 xfree (overlay_vec
);
3090 return make_number (endpos
);
3093 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
3094 Sprevious_overlay_change
, 1, 1, 0,
3095 "Return the previous position before POS where an overlay starts or ends.\n\
3096 If there are no more overlay boundaries before POS, return (point-min).")
3102 Lisp_Object
*overlay_vec
;
3107 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3110 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3112 /* At beginning of buffer, we know the answer;
3113 avoid bug subtracting 1 below. */
3114 if (XINT (pos
) == BEGV
)
3117 /* Put all the overlays we want in a vector in overlay_vec.
3118 Store the length in len.
3119 prevpos gets the position of an overlay end. */
3120 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3121 (int *) 0, &prevpos
);
3123 /* If any of these overlays starts after prevpos,
3124 maybe use its starting point instead. */
3125 for (i
= 0; i
< noverlays
; i
++)
3130 ostart
= OVERLAY_START (overlay_vec
[i
]);
3131 ostartpos
= OVERLAY_POSITION (ostart
);
3132 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
3133 prevpos
= ostartpos
;
3136 /* If any overlay ends at pos, consider its starting point too. */
3137 for (tail
= current_buffer
->overlays_before
;
3139 tail
= XCONS (tail
)->cdr
)
3141 Lisp_Object overlay
, ostart
;
3144 overlay
= XCONS (tail
)->car
;
3146 ostart
= OVERLAY_START (overlay
);
3147 ostartpos
= OVERLAY_POSITION (ostart
);
3148 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
3149 prevpos
= ostartpos
;
3152 xfree (overlay_vec
);
3153 return make_number (prevpos
);
3156 /* These functions are for debugging overlays. */
3158 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
3159 "Return a pair of lists giving all the overlays of the current buffer.\n\
3160 The car has all the overlays before the overlay center;\n\
3161 the cdr has all the overlays after the overlay center.\n\
3162 Recentering overlays moves overlays between these lists.\n\
3163 The lists you get are copies, so that changing them has no effect.\n\
3164 However, the overlays you get are the real objects that the buffer uses.")
3167 Lisp_Object before
, after
;
3168 before
= current_buffer
->overlays_before
;
3170 before
= Fcopy_sequence (before
);
3171 after
= current_buffer
->overlays_after
;
3173 after
= Fcopy_sequence (after
);
3175 return Fcons (before
, after
);
3178 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
3179 "Recenter the overlays of the current buffer around position POS.")
3183 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3185 recenter_overlay_lists (current_buffer
, XINT (pos
));
3189 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
3190 "Get the property of overlay OVERLAY with property name PROP.")
3192 Lisp_Object overlay
, prop
;
3194 Lisp_Object plist
, fallback
;
3196 CHECK_OVERLAY (overlay
, 0);
3200 for (plist
= XOVERLAY (overlay
)->plist
;
3201 CONSP (plist
) && CONSP (XCONS (plist
)->cdr
);
3202 plist
= XCONS (XCONS (plist
)->cdr
)->cdr
)
3204 if (EQ (XCONS (plist
)->car
, prop
))
3205 return XCONS (XCONS (plist
)->cdr
)->car
;
3206 else if (EQ (XCONS (plist
)->car
, Qcategory
))
3209 tem
= Fcar (Fcdr (plist
));
3211 fallback
= Fget (tem
, prop
);
3218 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
3219 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
3220 (overlay
, prop
, value
)
3221 Lisp_Object overlay
, prop
, value
;
3223 Lisp_Object tail
, buffer
;
3226 CHECK_OVERLAY (overlay
, 0);
3228 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3230 for (tail
= XOVERLAY (overlay
)->plist
;
3231 CONSP (tail
) && CONSP (XCONS (tail
)->cdr
);
3232 tail
= XCONS (XCONS (tail
)->cdr
)->cdr
)
3233 if (EQ (XCONS (tail
)->car
, prop
))
3235 changed
= !EQ (XCONS (XCONS (tail
)->cdr
)->car
, value
);
3236 XCONS (XCONS (tail
)->cdr
)->car
= value
;
3239 /* It wasn't in the list, so add it to the front. */
3240 changed
= !NILP (value
);
3241 XOVERLAY (overlay
)->plist
3242 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
3244 if (! NILP (buffer
))
3247 modify_overlay (XBUFFER (buffer
),
3248 marker_position (OVERLAY_START (overlay
)),
3249 marker_position (OVERLAY_END (overlay
)));
3250 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
3251 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
3252 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
3253 Fdelete_overlay (overlay
);
3258 /* Subroutine of report_overlay_modification. */
3260 /* Lisp vector holding overlay hook functions to call.
3261 Vector elements come in pairs.
3262 Each even-index element is a list of hook functions.
3263 The following odd-index element is the overlay they came from.
3265 Before the buffer change, we fill in this vector
3266 as we call overlay hook functions.
3267 After the buffer change, we get the functions to call from this vector.
3268 This way we always call the same functions before and after the change. */
3269 static Lisp_Object last_overlay_modification_hooks
;
3271 /* Number of elements actually used in last_overlay_modification_hooks. */
3272 static int last_overlay_modification_hooks_used
;
3274 /* Add one functionlist/overlay pair
3275 to the end of last_overlay_modification_hooks. */
3278 add_overlay_mod_hooklist (functionlist
, overlay
)
3279 Lisp_Object functionlist
, overlay
;
3281 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
3283 if (last_overlay_modification_hooks_used
== oldsize
)
3286 old
= last_overlay_modification_hooks
;
3287 last_overlay_modification_hooks
3288 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
3289 bcopy (XVECTOR (old
)->contents
,
3290 XVECTOR (last_overlay_modification_hooks
)->contents
,
3291 sizeof (Lisp_Object
) * oldsize
);
3293 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = functionlist
;
3294 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = overlay
;
3297 /* Run the modification-hooks of overlays that include
3298 any part of the text in START to END.
3299 If this change is an insertion, also
3300 run the insert-before-hooks of overlay starting at END,
3301 and the insert-after-hooks of overlay ending at START.
3303 This is called both before and after the modification.
3304 AFTER is nonzero when we call after the modification.
3306 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3307 When AFTER is nonzero, they are the start position,
3308 the position after the inserted new text,
3309 and the length of deleted or replaced old text. */
3312 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
3313 Lisp_Object start
, end
;
3315 Lisp_Object arg1
, arg2
, arg3
;
3317 Lisp_Object prop
, overlay
, tail
;
3318 /* 1 if this change is an insertion. */
3319 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
3321 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
3325 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
3329 /* Call the functions recorded in last_overlay_modification_hooks
3330 rather than scanning the overlays again.
3331 First copy the vector contents, in case some of these hooks
3332 do subsequent modification of the buffer. */
3333 int size
= last_overlay_modification_hooks_used
;
3334 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
3337 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
3338 copy
, size
* sizeof (Lisp_Object
));
3340 gcpro1
.nvars
= size
;
3342 for (i
= 0; i
< size
;)
3344 Lisp_Object prop
, overlay
;
3346 overlay
= copy
[i
++];
3347 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3353 /* We are being called before a change.
3354 Scan the overlays to find the functions to call. */
3355 last_overlay_modification_hooks_used
= 0;
3357 for (tail
= current_buffer
->overlays_before
;
3359 tail
= XCONS (tail
)->cdr
)
3361 int startpos
, endpos
;
3362 Lisp_Object ostart
, oend
;
3364 overlay
= XCONS (tail
)->car
;
3366 ostart
= OVERLAY_START (overlay
);
3367 oend
= OVERLAY_END (overlay
);
3368 endpos
= OVERLAY_POSITION (oend
);
3369 if (XFASTINT (start
) > endpos
)
3371 startpos
= OVERLAY_POSITION (ostart
);
3372 if (insertion
&& (XFASTINT (start
) == startpos
3373 || XFASTINT (end
) == startpos
))
3375 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3378 /* Copy TAIL in case the hook recenters the overlay lists. */
3380 tail
= Fcopy_sequence (tail
);
3382 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3385 if (insertion
&& (XFASTINT (start
) == endpos
3386 || XFASTINT (end
) == endpos
))
3388 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3392 tail
= Fcopy_sequence (tail
);
3394 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3397 /* Test for intersecting intervals. This does the right thing
3398 for both insertion and deletion. */
3399 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3401 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3405 tail
= Fcopy_sequence (tail
);
3407 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3413 for (tail
= current_buffer
->overlays_after
;
3415 tail
= XCONS (tail
)->cdr
)
3417 int startpos
, endpos
;
3418 Lisp_Object ostart
, oend
;
3420 overlay
= XCONS (tail
)->car
;
3422 ostart
= OVERLAY_START (overlay
);
3423 oend
= OVERLAY_END (overlay
);
3424 startpos
= OVERLAY_POSITION (ostart
);
3425 endpos
= OVERLAY_POSITION (oend
);
3426 if (XFASTINT (end
) < startpos
)
3428 if (insertion
&& (XFASTINT (start
) == startpos
3429 || XFASTINT (end
) == startpos
))
3431 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3435 tail
= Fcopy_sequence (tail
);
3437 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3440 if (insertion
&& (XFASTINT (start
) == endpos
3441 || XFASTINT (end
) == endpos
))
3443 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3447 tail
= Fcopy_sequence (tail
);
3449 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3452 /* Test for intersecting intervals. This does the right thing
3453 for both insertion and deletion. */
3454 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3456 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3460 tail
= Fcopy_sequence (tail
);
3462 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3471 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
3472 Lisp_Object list
, overlay
;
3474 Lisp_Object arg1
, arg2
, arg3
;
3476 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3478 GCPRO4 (list
, arg1
, arg2
, arg3
);
3480 add_overlay_mod_hooklist (list
, overlay
);
3482 while (!NILP (list
))
3485 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
3487 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
3493 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3496 evaporate_overlays (pos
)
3499 Lisp_Object tail
, overlay
, hit_list
;
3502 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
3503 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
3504 tail
= XCONS (tail
)->cdr
)
3507 overlay
= XCONS (tail
)->car
;
3508 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3511 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
3512 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3513 hit_list
= Fcons (overlay
, hit_list
);
3516 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
3517 tail
= XCONS (tail
)->cdr
)
3520 overlay
= XCONS (tail
)->car
;
3521 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3524 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
3525 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3526 hit_list
= Fcons (overlay
, hit_list
);
3528 for (; CONSP (hit_list
); hit_list
= XCONS (hit_list
)->cdr
)
3529 Fdelete_overlay (XCONS (hit_list
)->car
);
3532 /* Somebody has tried to store a value with an unacceptable type
3533 into the buffer-local slot with offset OFFSET. */
3535 buffer_slot_type_mismatch (offset
)
3540 sym
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
);
3541 switch (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
)))
3543 case Lisp_Int
: type_name
= "integers"; break;
3544 case Lisp_String
: type_name
= "strings"; break;
3545 case Lisp_Symbol
: type_name
= "symbols"; break;
3550 error ("only %s should be stored in the buffer-local variable %s",
3551 type_name
, XSYMBOL (sym
)->name
->data
);
3556 register Lisp_Object tem
;
3558 buffer_permanent_local_flags
= 0;
3560 /* Make sure all markable slots in buffer_defaults
3561 are initialized reasonably, so mark_buffer won't choke. */
3562 reset_buffer (&buffer_defaults
);
3563 reset_buffer_local_variables (&buffer_defaults
, 1);
3564 reset_buffer (&buffer_local_symbols
);
3565 reset_buffer_local_variables (&buffer_local_symbols
, 1);
3566 /* Prevent GC from getting confused. */
3567 buffer_defaults
.text
= &buffer_defaults
.own_text
;
3568 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
3569 #ifdef USE_TEXT_PROPERTIES
3570 BUF_INTERVALS (&buffer_defaults
) = 0;
3571 BUF_INTERVALS (&buffer_local_symbols
) = 0;
3573 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
3574 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
3576 /* Set up the default values of various buffer slots. */
3577 /* Must do these before making the first buffer! */
3579 /* real setup is done in loaddefs.el */
3580 buffer_defaults
.mode_line_format
= build_string ("%-");
3581 buffer_defaults
.abbrev_mode
= Qnil
;
3582 buffer_defaults
.overwrite_mode
= Qnil
;
3583 buffer_defaults
.case_fold_search
= Qt
;
3584 buffer_defaults
.auto_fill_function
= Qnil
;
3585 buffer_defaults
.selective_display
= Qnil
;
3587 buffer_defaults
.selective_display_ellipses
= Qt
;
3589 buffer_defaults
.abbrev_table
= Qnil
;
3590 buffer_defaults
.display_table
= Qnil
;
3591 buffer_defaults
.undo_list
= Qnil
;
3592 buffer_defaults
.mark_active
= Qnil
;
3593 buffer_defaults
.file_format
= Qnil
;
3594 buffer_defaults
.overlays_before
= Qnil
;
3595 buffer_defaults
.overlays_after
= Qnil
;
3596 XSETFASTINT (buffer_defaults
.overlay_center
, BEG
);
3598 XSETFASTINT (buffer_defaults
.tab_width
, 8);
3599 buffer_defaults
.truncate_lines
= Qnil
;
3600 buffer_defaults
.ctl_arrow
= Qt
;
3601 buffer_defaults
.direction_reversed
= Qnil
;
3604 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
3606 buffer_defaults
.enable_multibyte_characters
= Qt
;
3607 buffer_defaults
.buffer_file_coding_system
= Qnil
;
3608 XSETFASTINT (buffer_defaults
.fill_column
, 70);
3609 XSETFASTINT (buffer_defaults
.left_margin
, 0);
3610 buffer_defaults
.cache_long_line_scans
= Qnil
;
3611 buffer_defaults
.file_truename
= Qnil
;
3612 XSETFASTINT (buffer_defaults
.display_count
, 0);
3614 /* Assign the local-flags to the slots that have default values.
3615 The local flag is a bit that is used in the buffer
3616 to say that it has its own local value for the slot.
3617 The local flag bits are in the local_var_flags slot of the buffer. */
3619 /* Nothing can work if this isn't true */
3620 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
3622 /* 0 means not a lisp var, -1 means always local, else mask */
3623 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
3624 XSETINT (buffer_local_flags
.filename
, -1);
3625 XSETINT (buffer_local_flags
.directory
, -1);
3626 XSETINT (buffer_local_flags
.backed_up
, -1);
3627 XSETINT (buffer_local_flags
.save_length
, -1);
3628 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
3629 XSETINT (buffer_local_flags
.read_only
, -1);
3630 XSETINT (buffer_local_flags
.major_mode
, -1);
3631 XSETINT (buffer_local_flags
.mode_name
, -1);
3632 XSETINT (buffer_local_flags
.undo_list
, -1);
3633 XSETINT (buffer_local_flags
.mark_active
, -1);
3634 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
3635 XSETINT (buffer_local_flags
.file_truename
, -1);
3636 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
3637 XSETINT (buffer_local_flags
.file_format
, -1);
3638 XSETINT (buffer_local_flags
.display_count
, -1);
3640 XSETFASTINT (buffer_local_flags
.mode_line_format
, 1);
3641 XSETFASTINT (buffer_local_flags
.abbrev_mode
, 2);
3642 XSETFASTINT (buffer_local_flags
.overwrite_mode
, 4);
3643 XSETFASTINT (buffer_local_flags
.case_fold_search
, 8);
3644 XSETFASTINT (buffer_local_flags
.auto_fill_function
, 0x10);
3645 XSETFASTINT (buffer_local_flags
.selective_display
, 0x20);
3647 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, 0x40);
3649 XSETFASTINT (buffer_local_flags
.tab_width
, 0x80);
3650 XSETFASTINT (buffer_local_flags
.truncate_lines
, 0x100);
3651 XSETFASTINT (buffer_local_flags
.ctl_arrow
, 0x200);
3652 XSETFASTINT (buffer_local_flags
.fill_column
, 0x400);
3653 XSETFASTINT (buffer_local_flags
.left_margin
, 0x800);
3654 XSETFASTINT (buffer_local_flags
.abbrev_table
, 0x1000);
3655 XSETFASTINT (buffer_local_flags
.display_table
, 0x2000);
3657 XSETFASTINT (buffer_local_flags
.buffer_file_type
, 0x4000);
3658 /* Make this one a permanent local. */
3659 buffer_permanent_local_flags
|= 0x4000;
3661 XSETFASTINT (buffer_local_flags
.syntax_table
, 0x8000);
3662 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, 0x10000);
3663 XSETFASTINT (buffer_local_flags
.category_table
, 0x20000);
3664 XSETFASTINT (buffer_local_flags
.direction_reversed
, 0x40000);
3665 XSETFASTINT (buffer_local_flags
.enable_multibyte_characters
, 0x80000);
3666 /* Make this one a permanent local. */
3667 buffer_permanent_local_flags
|= 0x80000;
3668 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, 0x100000);
3669 /* Make this one a permanent local. */
3670 buffer_permanent_local_flags
|= 0x100000;
3672 Vbuffer_alist
= Qnil
;
3676 QSFundamental
= build_string ("Fundamental");
3678 Qfundamental_mode
= intern ("fundamental-mode");
3679 buffer_defaults
.major_mode
= Qfundamental_mode
;
3681 Qmode_class
= intern ("mode-class");
3683 Qprotected_field
= intern ("protected-field");
3685 Qpermanent_local
= intern ("permanent-local");
3687 Qkill_buffer_hook
= intern ("kill-buffer-hook");
3689 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
3691 /* super-magic invisible buffer */
3692 Vbuffer_alist
= Qnil
;
3694 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3699 char buf
[MAXPATHLEN
+1];
3701 struct stat dotstat
, pwdstat
;
3705 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3707 /* If PWD is accurate, use it instead of calling getwd. This is faster
3708 when PWD is right, and may avoid a fatal error. */
3709 if ((pwd
= getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd
)
3710 && stat (pwd
, &pwdstat
) == 0
3711 && stat (".", &dotstat
) == 0
3712 && dotstat
.st_ino
== pwdstat
.st_ino
3713 && dotstat
.st_dev
== pwdstat
.st_dev
3714 && strlen (pwd
) < MAXPATHLEN
)
3717 else if (getcwd (buf
, MAXPATHLEN
+1) == 0)
3718 fatal ("`getcwd' failed: %s\n", strerror (errno
));
3720 else if (getwd (buf
) == 0)
3721 fatal ("`getwd' failed: %s\n", buf
);
3725 /* Maybe this should really use some standard subroutine
3726 whose definition is filename syntax dependent. */
3728 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
3730 buf
[rc
] = DIRECTORY_SEP
;
3733 #endif /* not VMS */
3735 current_buffer
->directory
= build_string (buf
);
3737 /* Add /: to the front of the name
3738 if it would otherwise be treated as magic. */
3739 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
3741 /* If the default dir is just /, TEMP is non-nil
3742 because of the ange-ftp completion handler.
3743 However, it is not necessary to turn / into /:/.
3744 So avoid doing that. */
3745 && strcmp ("/", XSTRING (current_buffer
->directory
)->data
))
3746 current_buffer
->directory
3747 = concat2 (build_string ("/:"), current_buffer
->directory
);
3749 temp
= get_minibuffer (0);
3750 XBUFFER (temp
)->directory
= current_buffer
->directory
;
3753 /* initialize the buffer routines */
3756 extern Lisp_Object Qdisabled
;
3758 staticpro (&last_overlay_modification_hooks
);
3759 last_overlay_modification_hooks
3760 = Fmake_vector (make_number (10), Qnil
);
3762 staticpro (&Vbuffer_defaults
);
3763 staticpro (&Vbuffer_local_symbols
);
3764 staticpro (&Qfundamental_mode
);
3765 staticpro (&Qmode_class
);
3766 staticpro (&QSFundamental
);
3767 staticpro (&Vbuffer_alist
);
3768 staticpro (&Qprotected_field
);
3769 staticpro (&Qpermanent_local
);
3770 staticpro (&Qkill_buffer_hook
);
3771 Qoverlayp
= intern ("overlayp");
3772 staticpro (&Qoverlayp
);
3773 Qevaporate
= intern ("evaporate");
3774 staticpro (&Qevaporate
);
3775 Qmodification_hooks
= intern ("modification-hooks");
3776 staticpro (&Qmodification_hooks
);
3777 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
3778 staticpro (&Qinsert_in_front_hooks
);
3779 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
3780 staticpro (&Qinsert_behind_hooks
);
3781 Qget_file_buffer
= intern ("get-file-buffer");
3782 staticpro (&Qget_file_buffer
);
3783 Qpriority
= intern ("priority");
3784 staticpro (&Qpriority
);
3785 Qwindow
= intern ("window");
3786 staticpro (&Qwindow
);
3787 Qbefore_string
= intern ("before-string");
3788 staticpro (&Qbefore_string
);
3789 Qafter_string
= intern ("after-string");
3790 staticpro (&Qafter_string
);
3791 Qfirst_change_hook
= intern ("first-change-hook");
3792 staticpro (&Qfirst_change_hook
);
3793 Qbefore_change_functions
= intern ("before-change-functions");
3794 staticpro (&Qbefore_change_functions
);
3795 Qafter_change_functions
= intern ("after-change-functions");
3796 staticpro (&Qafter_change_functions
);
3798 Fput (Qprotected_field
, Qerror_conditions
,
3799 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
3800 Fput (Qprotected_field
, Qerror_message
,
3801 build_string ("Attempt to modify a protected field"));
3803 /* All these use DEFVAR_LISP_NOPRO because the slots in
3804 buffer_defaults will all be marked via Vbuffer_defaults. */
3806 DEFVAR_LISP_NOPRO ("default-mode-line-format",
3807 &buffer_defaults
.mode_line_format
,
3808 "Default value of `mode-line-format' for buffers that don't override it.\n\
3809 This is the same as (default-value 'mode-line-format).");
3811 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
3812 &buffer_defaults
.abbrev_mode
,
3813 "Default value of `abbrev-mode' for buffers that do not override it.\n\
3814 This is the same as (default-value 'abbrev-mode).");
3816 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
3817 &buffer_defaults
.ctl_arrow
,
3818 "Default value of `ctl-arrow' for buffers that do not override it.\n\
3819 This is the same as (default-value 'ctl-arrow).");
3821 DEFVAR_LISP_NOPRO ("default-direction-reversed",
3822 &buffer_defaults
.direction_reversed
,
3823 "Default value of `direction_reversed' for buffers that do not override it.\n\
3824 This is the same as (default-value 'direction-reversed).");
3826 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
3827 &buffer_defaults
.enable_multibyte_characters
,
3828 "Default value of `enable-multibyte-characters' for buffers not overriding it.\n\
3829 This is the same as (default-value 'enable-multibyte-characters).");
3831 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
3832 &buffer_defaults
.buffer_file_coding_system
,
3833 "Default value of `buffer-file-coding-system' for buffers not overriding it.\n\
3834 This is the same as (default-value 'buffer-file-coding-system).");
3836 DEFVAR_LISP_NOPRO ("default-truncate-lines",
3837 &buffer_defaults
.truncate_lines
,
3838 "Default value of `truncate-lines' for buffers that do not override it.\n\
3839 This is the same as (default-value 'truncate-lines).");
3841 DEFVAR_LISP_NOPRO ("default-fill-column",
3842 &buffer_defaults
.fill_column
,
3843 "Default value of `fill-column' for buffers that do not override it.\n\
3844 This is the same as (default-value 'fill-column).");
3846 DEFVAR_LISP_NOPRO ("default-left-margin",
3847 &buffer_defaults
.left_margin
,
3848 "Default value of `left-margin' for buffers that do not override it.\n\
3849 This is the same as (default-value 'left-margin).");
3851 DEFVAR_LISP_NOPRO ("default-tab-width",
3852 &buffer_defaults
.tab_width
,
3853 "Default value of `tab-width' for buffers that do not override it.\n\
3854 This is the same as (default-value 'tab-width).");
3856 DEFVAR_LISP_NOPRO ("default-case-fold-search",
3857 &buffer_defaults
.case_fold_search
,
3858 "Default value of `case-fold-search' for buffers that don't override it.\n\
3859 This is the same as (default-value 'case-fold-search).");
3862 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
3863 &buffer_defaults
.buffer_file_type
,
3864 "Default file type for buffers that do not override it.\n\
3865 This is the same as (default-value 'buffer-file-type).\n\
3866 The file type is nil for text, t for binary.");
3869 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
3872 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
3873 But make-docfile finds it!
3874 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
3876 "Template for displaying mode line for current buffer.\n\
3877 Each buffer has its own value of this variable.\n\
3878 Value may be a string, a symbol or a list or cons cell.\n\
3879 For a symbol, its value is used (but it is ignored if t or nil).\n\
3880 A string appearing directly as the value of a symbol is processed verbatim\n\
3881 in that the %-constructs below are not recognized.\n\
3882 For a list whose car is a symbol, the symbol's value is taken,\n\
3883 and if that is non-nil, the cadr of the list is processed recursively.\n\
3884 Otherwise, the caddr of the list (if there is one) is processed.\n\
3885 For a list whose car is a string or list, each element is processed\n\
3886 recursively and the results are effectively concatenated.\n\
3887 For a list whose car is an integer, the cdr of the list is processed\n\
3888 and padded (if the number is positive) or truncated (if negative)\n\
3889 to the width specified by that number.\n\
3890 A string is printed verbatim in the mode line except for %-constructs:\n\
3891 (%-constructs are allowed when the string is the entire mode-line-format\n\
3892 or when it is found in a cons-cell or a list)\n\
3893 %b -- print buffer name. %f -- print visited file name.\n\
3894 %F -- print frame name.\n\
3895 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
3896 % means buffer is read-only and * means it is modified.\n\
3897 For a modified read-only buffer, %* gives % and %+ gives *.\n\
3898 %s -- print process status. %l -- print the current line number.\n\
3899 %c -- print the current column number (this makes editing slower).\n\
3900 To make the column number update correctly in all cases,\n\
3901 `column-number-mode' must be non-nil.\n\
3902 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
3903 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
3904 or print Bottom or All.\n\
3905 %n -- print Narrow if appropriate.\n\
3906 %t -- print T if file is text, B if binary.\n\
3907 %[ -- print one [ for each recursive editing level. %] similar.\n\
3908 %% -- print %. %- -- print infinitely many dashes.\n\
3909 Decimal digits after the % specify field width to which to pad.");
3912 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
3913 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
3914 nil here means use current buffer's major mode.");
3916 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
3917 make_number (Lisp_Symbol
),
3918 "Symbol for current buffer's major mode.");
3920 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
3921 make_number (Lisp_String
),
3922 "Pretty name of current buffer's major mode (a string).");
3924 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
3925 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
3926 Automatically becomes buffer-local when set in any fashion.");
3928 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
3930 "*Non-nil if searches should ignore case.\n\
3931 Automatically becomes buffer-local when set in any fashion.");
3933 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
3934 make_number (Lisp_Int
),
3935 "*Column beyond which automatic line-wrapping should happen.\n\
3936 Automatically becomes buffer-local when set in any fashion.");
3938 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
3939 make_number (Lisp_Int
),
3940 "*Column for the default indent-line-function to indent to.\n\
3941 Linefeed indents to this column in Fundamental mode.\n\
3942 Automatically becomes buffer-local when set in any fashion.");
3944 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
3945 make_number (Lisp_Int
),
3946 "*Distance between tab stops (for display of tab characters), in columns.\n\
3947 Automatically becomes buffer-local when set in any fashion.");
3949 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
3950 "*Non-nil means display control chars with uparrow.\n\
3951 A value of nil means use backslash and octal digits.\n\
3952 Automatically becomes buffer-local when set in any fashion.\n\
3953 This variable does not apply to characters whose display is specified\n\
3954 in the current display table (if there is one).");
3956 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
3957 ¤t_buffer
->enable_multibyte_characters
, Qnil
,
3958 "*Non-nil means the buffer contents are regarded as multi-byte form\n\
3959 of characters, not a binary code. This affects the display, file I/O,\n\
3960 and behaviors of various editing commands.");
3962 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
3963 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
3964 "Coding system to be used for encoding the buffer contents on saving.\n\
3965 If it is nil, the buffer is saved without any code conversion unless\n\
3966 some coding system is specified in file-coding-system-alist\n\
3967 for the buffer file.\n\
3969 This variable is never applied to a way of decoding\n\
3970 a file while reading it.");
3972 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
3974 "*Non-nil means lines in the buffer are displayed right to left.");
3976 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
3977 "*Non-nil means do not display continuation lines;\n\
3978 give each line of text one screen line.\n\
3979 Automatically becomes buffer-local when set in any fashion.\n\
3981 Note that this is overridden by the variable\n\
3982 `truncate-partial-width-windows' if that variable is non-nil\n\
3983 and this buffer is not full-frame width.");
3986 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
3988 "Non-nil if the visited file is a binary file.\n\
3989 This variable is meaningful on MS-DOG and Windows NT.\n\
3990 On those systems, it is automatically local in every buffer.\n\
3991 On other systems, this variable is normally always nil.");
3994 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
3995 make_number (Lisp_String
),
3996 "Name of default directory of current buffer. Should end with slash.\n\
3997 Each buffer has its own value of this variable.");
3999 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
4001 "Function called (if non-nil) to perform auto-fill.\n\
4002 It is called after self-inserting a space or newline.\n\
4003 Each buffer has its own value of this variable.\n\
4004 NOTE: This variable is not a hook;\n\
4005 its value may not be a list of functions.");
4007 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
4008 make_number (Lisp_String
),
4009 "Name of file visited in current buffer, or nil if not visiting a file.\n\
4010 Each buffer has its own value of this variable.");
4012 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
4013 make_number (Lisp_String
),
4014 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
4015 The truename of a file is calculated by `file-truename'\n\
4016 and then abbreviated with `abbreviate-file-name'.\n\
4017 Each buffer has its own value of this variable.");
4019 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
4020 ¤t_buffer
->auto_save_file_name
,
4021 make_number (Lisp_String
),
4022 "Name of file for auto-saving current buffer,\n\
4023 or nil if buffer should not be auto-saved.\n\
4024 Each buffer has its own value of this variable.");
4026 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
4027 "Non-nil if this buffer is read-only.\n\
4028 Each buffer has its own value of this variable.");
4030 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
4031 "Non-nil if this buffer's file has been backed up.\n\
4032 Backing up is done before the first time the file is saved.\n\
4033 Each buffer has its own value of this variable.");
4035 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
4036 make_number (Lisp_Int
),
4037 "Length of current buffer when last read in, saved or auto-saved.\n\
4039 Each buffer has its own value of this variable.");
4041 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
4043 "Non-nil enables selective display:\n\
4044 Integer N as value means display only lines\n\
4045 that start with less than n columns of space.\n\
4046 A value of t means, after a ^M, all the rest of the line is invisible.\n\
4047 Then ^M's in the file are written into files as newlines.\n\n\
4048 Automatically becomes buffer-local when set in any fashion.");
4051 DEFVAR_PER_BUFFER ("selective-display-ellipses",
4052 ¤t_buffer
->selective_display_ellipses
,
4054 "t means display ... on previous line when a line is invisible.\n\
4055 Automatically becomes buffer-local when set in any fashion.");
4058 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
4059 "Non-nil if self-insertion should replace existing text.\n\
4060 The value should be one of `overwrite-mode-textual',\n\
4061 `overwrite-mode-binary', or nil.\n\
4062 If it is `overwrite-mode-textual', self-insertion still\n\
4063 inserts at the end of a line, and inserts when point is before a tab,\n\
4064 until the tab is filled in.\n\
4065 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
4066 Automatically becomes buffer-local when set in any fashion.");
4068 #if 0 /* The doc string is too long for some compilers,
4069 but make-docfile can find it in this comment. */
4070 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4072 "Display table that controls display of the contents of current buffer.\n\
4073 Automatically becomes buffer-local when set in any fashion.\n\
4074 The display table is a char-table created with `make-display-table'.\n\
4075 The ordinary char-table elements control how to display each possible text\n\
4076 character. Each value should be a vector of characters or nil;\n\
4077 nil means display the character in the default fashion.\n\
4078 There are six extra slots to control the display of\n\
4079 the end of a truncated screen line (extra-slot 0, a single character);\n\
4080 the end of a continued line (extra-slot 1, a single character);\n\
4081 the escape character used to display character codes in octal\n\
4082 (extra-slot 2, a single character);\n\
4083 the character used as an arrow for control characters (extra-slot 3,\n\
4084 a single character);\n\
4085 the decoration indicating the presence of invisible lines (extra-slot 4,\n\
4086 a vector of characters);\n\
4087 the character used to draw the border between side-by-side windows\n\
4088 (extra-slot 5, a single character).\n\
4089 See also the functions `display-table-slot' and `set-display-table-slot'.\n\
4090 If this variable is nil, the value of `standard-display-table' is used.\n\
4091 Each window can have its own, overriding display table.");
4093 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4096 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
4099 DEFVAR_LISP ("before-change-function", &Vbefore_change_function
,
4100 "If non-nil, a function to call before each text change (obsolete).\n\
4101 Two arguments are passed to the function: the positions of\n\
4102 the beginning and end of the range of old text to be changed.\n\
4103 \(For an insertion, the beginning and end are at the same place.)\n\
4104 No information is given about the length of the text after the change.\n\
4106 Buffer changes made while executing the `before-change-function'\n\
4107 don't call any before-change or after-change functions.\n\
4108 That's because these variables are temporarily set to nil.\n\
4109 As a result, a hook function cannot straightforwardly alter the value of\n\
4110 these variables. See the Emacs Lisp manual for a way of\n\
4111 accomplishing an equivalent result by using other variables.\n\n\
4112 This variable is obsolete; use `before-change-functions' instead.");
4113 Vbefore_change_function
= Qnil
;
4115 DEFVAR_LISP ("after-change-function", &Vafter_change_function
,
4116 "If non-nil, a Function to call after each text change (obsolete).\n\
4117 Three arguments are passed to the function: the positions of\n\
4118 the beginning and end of the range of changed text,\n\
4119 and the length of the pre-change text replaced by that range.\n\
4120 \(For an insertion, the pre-change length is zero;\n\
4121 for a deletion, that length is the number of bytes deleted,\n\
4122 and the post-change beginning and end are at the same place.)\n\
4124 Buffer changes made while executing the `after-change-function'\n\
4125 don't call any before-change or after-change functions.\n\
4126 That's because these variables are temporarily set to nil.\n\
4127 As a result, a hook function cannot straightforwardly alter the value of\n\
4128 these variables. See the Emacs Lisp manual for a way of\n\
4129 accomplishing an equivalent result by using other variables.\n\n\
4130 This variable is obsolete; use `after-change-functions' instead.");
4131 Vafter_change_function
= Qnil
;
4133 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
4134 "List of functions to call before each text change.\n\
4135 Two arguments are passed to each function: the positions of\n\
4136 the beginning and end of the range of old text to be changed.\n\
4137 \(For an insertion, the beginning and end are at the same place.)\n\
4138 No information is given about the length of the text after the change.\n\
4140 Buffer changes made while executing the `before-change-functions'\n\
4141 don't call any before-change or after-change functions.\n\
4142 That's because these variables are temporarily set to nil.\n\
4143 As a result, a hook function cannot straightforwardly alter the value of\n\
4144 these variables. See the Emacs Lisp manual for a way of\n\
4145 accomplishing an equivalent result by using other variables.");
4146 Vbefore_change_functions
= Qnil
;
4148 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
4149 "List of function to call after each text change.\n\
4150 Three arguments are passed to each function: the positions of\n\
4151 the beginning and end of the range of changed text,\n\
4152 and the length in bytes of the pre-change text replaced by that range.\n\
4153 \(For an insertion, the pre-change length is zero;\n\
4154 for a deletion, that length is the number of bytes deleted,\n\
4155 and the post-change beginning and end are at the same place.)\n\
4157 Buffer changes made while executing the `after-change-functions'\n\
4158 don't call any before-change or after-change functions.\n\
4159 That's because these variables are temporarily set to nil.\n\
4160 As a result, a hook function cannot straightforwardly alter the value of\n\
4161 these variables. See the Emacs Lisp manual for a way of\n\
4162 accomplishing an equivalent result by using other variables.");
4164 Vafter_change_functions
= Qnil
;
4166 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
4167 "A list of functions to call before changing a buffer which is unmodified.\n\
4168 The functions are run using the `run-hooks' function.");
4169 Vfirst_change_hook
= Qnil
;
4171 #if 0 /* The doc string is too long for some compilers,
4172 but make-docfile can find it in this comment. */
4173 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4174 "List of undo entries in current buffer.\n\
4175 Recent changes come first; older changes follow newer.\n\
4177 An entry (BEG . END) represents an insertion which begins at\n\
4178 position BEG and ends at position END.\n\
4180 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
4181 from (abs POSITION). If POSITION is positive, point was at the front\n\
4182 of the text being deleted; if negative, point was at the end.\n\
4184 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
4185 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
4186 of the visited file's modification time, as of that time. If the\n\
4187 modification time of the most recent save is different, this entry is\n\
4190 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
4191 was modified between BEG and END. PROPERTY is the property name,\n\
4192 and VALUE is the old value.\n\
4194 An entry (MARKER . DISTANCE) indicates that the marker MARKER\n\
4195 was adjusted in position by the offset DISTANCE (an integer).\n\
4197 An entry of the form POSITION indicates that point was at the buffer\n\
4198 location given by the integer. Undoing an entry of this form places\n\
4199 point at POSITION.\n\
4201 nil marks undo boundaries. The undo command treats the changes\n\
4202 between two undo boundaries as a single step to be undone.\n\
4204 If the value of the variable is t, undo information is not recorded.");
4206 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4209 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
4210 "Non-nil means the mark and region are currently active in this buffer.\n\
4211 Automatically local in all buffers.");
4213 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
4214 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
4215 This variable is buffer-local, in all buffers.\n\
4217 Normally, the line-motion functions work by scanning the buffer for\n\
4218 newlines. Columnar operations (like move-to-column and\n\
4219 compute-motion) also work by scanning the buffer, summing character\n\
4220 widths as they go. This works well for ordinary text, but if the\n\
4221 buffer's lines are very long (say, more than 500 characters), these\n\
4222 motion functions will take longer to execute. Emacs may also take\n\
4223 longer to update the display.\n\
4225 If cache-long-line-scans is non-nil, these motion functions cache the\n\
4226 results of their scans, and consult the cache to avoid rescanning\n\
4227 regions of the buffer until the text is modified. The caches are most\n\
4228 beneficial when they prevent the most searching---that is, when the\n\
4229 buffer contains long lines and large regions of characters with the\n\
4230 same, fixed screen width.\n\
4232 When cache-long-line-scans is non-nil, processing short lines will\n\
4233 become slightly slower (because of the overhead of consulting the\n\
4234 cache), and the caches will use memory roughly proportional to the\n\
4235 number of newlines and characters whose screen width varies.\n\
4237 The caches require no explicit maintenance; their accuracy is\n\
4238 maintained internally by the Emacs primitives. Enabling or disabling\n\
4239 the cache should not affect the behavior of any of the motion\n\
4240 functions; it should only affect their performance.");
4242 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
4243 "Value of point before the last series of scroll operations, or nil.");
4245 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
4246 "List of formats to use when saving this buffer.\n\
4247 Formats are defined by `format-alist'. This variable is\n\
4248 set when a file is visited. Automatically local in all buffers.");
4250 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
4251 ¤t_buffer
->invisibility_spec
, Qnil
,
4252 "Invisibility spec of this buffer.\n\
4253 The default is t, which means that text is invisible\n\
4254 if it has a non-nil `invisible' property.\n\
4255 If the value is a list, a text character is invisible if its `invisible'\n\
4256 property is an element in that list.\n\
4257 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
4258 then characters with property value PROP are invisible,\n\
4259 and they have an ellipsis as well if ELLIPSIS is non-nil.");
4261 DEFVAR_PER_BUFFER ("buffer-display-count",
4262 ¤t_buffer
->display_count
, Qnil
,
4263 "A number incremented each time the buffer is displayed in a window.");
4265 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
4266 "*Non-nil means deactivate the mark when the buffer contents change.\n\
4267 Non-nil also enables highlighting of the region whenever the mark is active.\n\
4268 The variable `highlight-nonselected-windows' controls whether to highlight\n\
4269 all windows or just the selected window.");
4270 Vtransient_mark_mode
= Qnil
;
4272 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
4273 "*Non-nil means disregard read-only status of buffers or characters.\n\
4274 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
4275 text properties. If the value is a list, disregard `buffer-read-only'\n\
4276 and disregard a `read-only' text property if the property value\n\
4277 is a member of the list.");
4278 Vinhibit_read_only
= Qnil
;
4280 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
4281 "List of functions called with no args to query before killing a buffer.");
4282 Vkill_buffer_query_functions
= Qnil
;
4284 defsubr (&Sbuffer_live_p
);
4285 defsubr (&Sbuffer_list
);
4286 defsubr (&Sget_buffer
);
4287 defsubr (&Sget_file_buffer
);
4288 defsubr (&Sget_buffer_create
);
4289 defsubr (&Smake_indirect_buffer
);
4290 defsubr (&Sgenerate_new_buffer_name
);
4291 defsubr (&Sbuffer_name
);
4292 /*defsubr (&Sbuffer_number);*/
4293 defsubr (&Sbuffer_file_name
);
4294 defsubr (&Sbuffer_base_buffer
);
4295 defsubr (&Sbuffer_local_variables
);
4296 defsubr (&Sbuffer_modified_p
);
4297 defsubr (&Sset_buffer_modified_p
);
4298 defsubr (&Sbuffer_modified_tick
);
4299 defsubr (&Srename_buffer
);
4300 defsubr (&Sother_buffer
);
4301 defsubr (&Sbuffer_disable_undo
);
4302 defsubr (&Sbuffer_enable_undo
);
4303 defsubr (&Skill_buffer
);
4304 defsubr (&Serase_buffer
);
4305 defsubr (&Sset_buffer_major_mode
);
4306 defsubr (&Sswitch_to_buffer
);
4307 defsubr (&Spop_to_buffer
);
4308 defsubr (&Scurrent_buffer
);
4309 defsubr (&Sset_buffer
);
4310 defsubr (&Sbarf_if_buffer_read_only
);
4311 defsubr (&Sbury_buffer
);
4312 defsubr (&Skill_all_local_variables
);
4314 defsubr (&Soverlayp
);
4315 defsubr (&Smake_overlay
);
4316 defsubr (&Sdelete_overlay
);
4317 defsubr (&Smove_overlay
);
4318 defsubr (&Soverlay_start
);
4319 defsubr (&Soverlay_end
);
4320 defsubr (&Soverlay_buffer
);
4321 defsubr (&Soverlay_properties
);
4322 defsubr (&Soverlays_at
);
4323 defsubr (&Soverlays_in
);
4324 defsubr (&Snext_overlay_change
);
4325 defsubr (&Sprevious_overlay_change
);
4326 defsubr (&Soverlay_recenter
);
4327 defsubr (&Soverlay_lists
);
4328 defsubr (&Soverlay_get
);
4329 defsubr (&Soverlay_put
);
4334 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
4335 initial_define_key (control_x_map
, 'k', "kill-buffer");
4337 /* This must not be in syms_of_buffer, because Qdisabled is not
4338 initialized when that function gets called. */
4339 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);