1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985,86,87,88,89,93,94,95,97,98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include <sys/types.h>
26 #include <sys/param.h>
32 /* in 4.1, param.h fails to define this. */
33 #define MAXPATHLEN 1024
34 #endif /* not MAXPATHLEN */
40 #include "intervals.h"
45 #include "region-cache.h"
47 #include "blockinput.h"
50 struct buffer
*current_buffer
; /* the current buffer */
52 /* First buffer in chain of all buffers (in reverse order of creation).
53 Threaded through ->next. */
55 struct buffer
*all_buffers
;
57 /* This structure holds the default values of the buffer-local variables
58 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
59 The default value occupies the same slot in this structure
60 as an individual buffer's value occupies in that buffer.
61 Setting the default value also goes through the alist of buffers
62 and stores into each buffer that does not say it has a local value. */
64 struct buffer buffer_defaults
;
66 /* A Lisp_Object pointer to the above, used for staticpro */
68 static Lisp_Object Vbuffer_defaults
;
70 /* This structure marks which slots in a buffer have corresponding
71 default values in buffer_defaults.
72 Each such slot has a nonzero value in this structure.
73 The value has only one nonzero bit.
75 When a buffer has its own local value for a slot,
76 the bit for that slot (found in the same slot in this structure)
77 is turned on in the buffer's local_var_flags slot.
79 If a slot in this structure is -1, then even though there may
80 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
81 and the corresponding slot in buffer_defaults is not used.
83 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
84 but there is a default value which is copied into each buffer.
86 If a slot in this structure is negative, then even though there may
87 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
88 and the corresponding slot in buffer_defaults is not used.
90 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
91 zero, that is a bug */
93 struct buffer buffer_local_flags
;
95 /* This structure holds the names of symbols whose values may be
96 buffer-local. It is indexed and accessed in the same way as the above. */
98 struct buffer buffer_local_symbols
;
99 /* A Lisp_Object pointer to the above, used for staticpro */
100 static Lisp_Object Vbuffer_local_symbols
;
102 /* This structure holds the required types for the values in the
103 buffer-local slots. If a slot contains Qnil, then the
104 corresponding buffer slot may contain a value of any type. If a
105 slot contains an integer, then prospective values' tags must be
106 equal to that integer (except nil is always allowed).
107 When a tag does not match, the function
108 buffer_slot_type_mismatch will signal an error.
110 If a slot here contains -1, the corresponding variable is read-only. */
111 struct buffer buffer_local_types
;
113 /* Flags indicating which built-in buffer-local variables
114 are permanent locals. */
115 static int buffer_permanent_local_flags
;
117 Lisp_Object
Fset_buffer ();
118 void set_buffer_internal ();
119 void set_buffer_internal_1 ();
120 static void call_overlay_mod_hooks ();
121 static void swap_out_buffer_local_variables ();
122 static void reset_buffer_local_variables ();
124 /* Alist of all buffer names vs the buffers. */
125 /* This used to be a variable, but is no longer,
126 to prevent lossage due to user rplac'ing this alist or its elements. */
127 Lisp_Object Vbuffer_alist
;
129 /* Functions to call before and after each text change. */
130 Lisp_Object Vbefore_change_function
;
131 Lisp_Object Vafter_change_function
;
132 Lisp_Object Vbefore_change_functions
;
133 Lisp_Object Vafter_change_functions
;
135 Lisp_Object Vtransient_mark_mode
;
137 /* t means ignore all read-only text properties.
138 A list means ignore such a property if its value is a member of the list.
139 Any non-nil value means ignore buffer-read-only. */
140 Lisp_Object Vinhibit_read_only
;
142 /* List of functions to call that can query about killing a buffer.
143 If any of these functions returns nil, we don't kill it. */
144 Lisp_Object Vkill_buffer_query_functions
;
146 /* List of functions to call before changing an unmodified buffer. */
147 Lisp_Object Vfirst_change_hook
;
149 Lisp_Object Qfirst_change_hook
;
150 Lisp_Object Qbefore_change_functions
;
151 Lisp_Object Qafter_change_functions
;
153 /* If nonzero, all modification hooks are suppressed. */
154 int inhibit_modification_hooks
;
156 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
158 Lisp_Object Qprotected_field
;
160 Lisp_Object QSFundamental
; /* A string "Fundamental" */
162 Lisp_Object Qkill_buffer_hook
;
164 Lisp_Object Qget_file_buffer
;
166 Lisp_Object Qoverlayp
;
168 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
170 Lisp_Object Qmodification_hooks
;
171 Lisp_Object Qinsert_in_front_hooks
;
172 Lisp_Object Qinsert_behind_hooks
;
174 /* For debugging; temporary. See set_buffer_internal. */
175 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
182 error ("No buffer named %s", XSTRING (spec
)->data
);
183 error ("Invalid buffer argument");
186 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
187 "Return non-nil if OBJECT is a buffer which has not been killed.\n\
188 Value is nil if OBJECT is not a buffer or if it has been killed.")
192 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
196 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
197 "Return a list of all existing live buffers.\n\
198 If the optional arg FRAME is a frame, we return that frame's buffer list.")
202 Lisp_Object framelist
, general
;
203 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
209 CHECK_FRAME (frame
, 1);
211 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
213 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */
215 while (! NILP (tail
))
217 general
= Fdelq (XCAR (tail
), general
);
220 return nconc2 (framelist
, general
);
226 /* Like Fassoc, but use Fstring_equal to compare
227 (which ignores text properties),
228 and don't ever QUIT. */
231 assoc_ignore_text_properties (key
, list
)
232 register Lisp_Object key
;
235 register Lisp_Object tail
;
236 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
238 register Lisp_Object elt
, tem
;
240 tem
= Fstring_equal (Fcar (elt
), key
);
247 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
248 "Return the buffer named NAME (a string).\n\
249 If there is no live buffer named NAME, return nil.\n\
250 NAME may also be a buffer; if so, the value is that buffer.")
252 register Lisp_Object name
;
256 CHECK_STRING (name
, 0);
258 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
261 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
262 "Return the buffer visiting file FILENAME (a string).\n\
263 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
264 If there is no such live buffer, return nil.\n\
265 See also `find-buffer-visiting'.")
267 register Lisp_Object filename
;
269 register Lisp_Object tail
, buf
, tem
;
272 CHECK_STRING (filename
, 0);
273 filename
= Fexpand_file_name (filename
, Qnil
);
275 /* If the file name has special constructs in it,
276 call the corresponding file handler. */
277 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
279 return call2 (handler
, Qget_file_buffer
, filename
);
281 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
283 buf
= Fcdr (XCAR (tail
));
284 if (!BUFFERP (buf
)) continue;
285 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
286 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
294 get_truename_buffer (filename
)
295 register Lisp_Object filename
;
297 register Lisp_Object tail
, buf
, tem
;
299 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
301 buf
= Fcdr (XCAR (tail
));
302 if (!BUFFERP (buf
)) continue;
303 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
304 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
311 /* Incremented for each buffer created, to assign the buffer number. */
314 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
315 "Return the buffer named NAME, or create such a buffer and return it.\n\
316 A new buffer is created if there is no live buffer named NAME.\n\
317 If NAME starts with a space, the new buffer does not keep undo information.\n\
318 If NAME is a buffer instead of a string, then it is the value returned.\n\
319 The value is never nil.")
321 register Lisp_Object name
;
323 register Lisp_Object buf
;
324 register struct buffer
*b
;
326 buf
= Fget_buffer (name
);
330 if (XSTRING (name
)->size
== 0)
331 error ("Empty string for buffer name is not allowed");
333 b
= (struct buffer
*) allocate_buffer ();
335 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
337 /* An ordinary buffer uses its own struct buffer_text. */
338 b
->text
= &b
->own_text
;
341 BUF_GAP_SIZE (b
) = 20;
343 /* We allocate extra 1-byte at the tail and keep it always '\0' for
344 anchoring a search. */
345 BUFFER_ALLOC (BUF_BEG_ADDR (b
), (BUF_GAP_SIZE (b
) + 1));
347 if (! BUF_BEG_ADDR (b
))
348 buffer_memory_full ();
356 BUF_GPT_BYTE (b
) = 1;
357 BUF_BEGV_BYTE (b
) = 1;
361 BUF_OVERLAY_MODIFF (b
) = 1;
362 BUF_SAVE_MODIFF (b
) = 1;
363 BUF_INTERVALS (b
) = 0;
364 BUF_UNCHANGED_MODIFIED (b
) = 1;
365 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = 1;
366 BUF_END_UNCHANGED (b
) = 0;
367 BUF_BEG_UNCHANGED (b
) = 0;
368 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
370 b
->newline_cache
= 0;
371 b
->width_run_cache
= 0;
372 b
->width_table
= Qnil
;
373 b
->prevent_redisplay_optimizations_p
= 1;
375 /* Put this on the chain of all buffers including killed ones. */
376 b
->next
= all_buffers
;
379 /* An ordinary buffer normally doesn't need markers
380 to handle BEGV and ZV. */
382 b
->begv_marker
= Qnil
;
385 name
= Fcopy_sequence (name
);
386 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
389 if (XSTRING (name
)->data
[0] != ' ')
395 reset_buffer_local_variables (b
, 1);
397 /* Put this in the alist of all live buffers. */
399 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
401 b
->mark
= Fmake_marker ();
402 BUF_MARKERS (b
) = Qnil
;
407 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
, 2, 2,
408 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
409 "Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.\n\
410 BASE-BUFFER should be an existing buffer (or buffer name).\n\
411 NAME should be a string which is not the name of an existing buffer.")
413 register Lisp_Object base_buffer
, name
;
415 register Lisp_Object buf
;
416 register struct buffer
*b
;
418 buf
= Fget_buffer (name
);
420 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
422 base_buffer
= Fget_buffer (base_buffer
);
423 if (NILP (base_buffer
))
424 error ("No such buffer: `%s'",
425 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
427 if (XSTRING (name
)->size
== 0)
428 error ("Empty string for buffer name is not allowed");
430 b
= (struct buffer
*) allocate_buffer ();
431 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
433 if (XBUFFER (base_buffer
)->base_buffer
)
434 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
436 b
->base_buffer
= XBUFFER (base_buffer
);
438 /* Use the base buffer's text object. */
439 b
->text
= b
->base_buffer
->text
;
441 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
442 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
443 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
444 BUF_BEGV_BYTE (b
) = BUF_BEGV_BYTE (b
->base_buffer
);
445 BUF_ZV_BYTE (b
) = BUF_ZV_BYTE (b
->base_buffer
);
446 BUF_PT_BYTE (b
) = BUF_PT_BYTE (b
->base_buffer
);
448 b
->newline_cache
= 0;
449 b
->width_run_cache
= 0;
450 b
->width_table
= Qnil
;
452 /* Put this on the chain of all buffers including killed ones. */
453 b
->next
= all_buffers
;
456 name
= Fcopy_sequence (name
);
457 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
461 reset_buffer_local_variables (b
, 1);
463 /* Put this in the alist of all live buffers. */
465 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
467 b
->mark
= Fmake_marker ();
470 /* The multibyte status belongs to the base buffer. */
471 b
->enable_multibyte_characters
= b
->base_buffer
->enable_multibyte_characters
;
473 /* Make sure the base buffer has markers for its narrowing. */
474 if (NILP (b
->base_buffer
->pt_marker
))
476 b
->base_buffer
->pt_marker
= Fmake_marker ();
477 set_marker_both (b
->base_buffer
->pt_marker
, base_buffer
,
478 BUF_PT (b
->base_buffer
),
479 BUF_PT_BYTE (b
->base_buffer
));
481 if (NILP (b
->base_buffer
->begv_marker
))
483 b
->base_buffer
->begv_marker
= Fmake_marker ();
484 set_marker_both (b
->base_buffer
->begv_marker
, base_buffer
,
485 BUF_BEGV (b
->base_buffer
),
486 BUF_BEGV_BYTE (b
->base_buffer
));
488 if (NILP (b
->base_buffer
->zv_marker
))
490 b
->base_buffer
->zv_marker
= Fmake_marker ();
491 set_marker_both (b
->base_buffer
->zv_marker
, base_buffer
,
492 BUF_ZV (b
->base_buffer
),
493 BUF_ZV_BYTE (b
->base_buffer
));
494 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
497 /* Give the indirect buffer markers for its narrowing. */
498 b
->pt_marker
= Fmake_marker ();
499 set_marker_both (b
->pt_marker
, buf
, BUF_PT (b
), BUF_PT_BYTE (b
));
500 b
->begv_marker
= Fmake_marker ();
501 set_marker_both (b
->begv_marker
, buf
, BUF_BEGV (b
), BUF_BEGV_BYTE (b
));
502 b
->zv_marker
= Fmake_marker ();
503 set_marker_both (b
->zv_marker
, buf
, BUF_ZV (b
), BUF_ZV_BYTE (b
));
504 XMARKER (b
->zv_marker
)->insertion_type
= 1;
509 /* Reinitialize everything about a buffer except its name and contents
510 and local variables. */
514 register struct buffer
*b
;
517 b
->file_truename
= Qnil
;
518 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
520 XSETFASTINT (b
->save_length
, 0);
521 b
->last_window_start
= 1;
522 /* It is more conservative to start out "changed" than "unchanged". */
524 b
->prevent_redisplay_optimizations_p
= 1;
526 b
->auto_save_modified
= 0;
527 b
->auto_save_failure_time
= -1;
528 b
->auto_save_file_name
= Qnil
;
530 b
->overlays_before
= Qnil
;
531 b
->overlays_after
= Qnil
;
532 XSETFASTINT (b
->overlay_center
, 1);
533 b
->mark_active
= Qnil
;
534 b
->point_before_scroll
= Qnil
;
535 b
->file_format
= Qnil
;
536 b
->last_selected_window
= Qnil
;
537 XSETINT (b
->display_count
, 0);
538 b
->display_time
= Qnil
;
541 b
->enable_multibyte_characters
= buffer_defaults
.enable_multibyte_characters
;
544 /* Reset buffer B's local variables info.
545 Don't use this on a buffer that has already been in use;
546 it does not treat permanent locals consistently.
547 Instead, use Fkill_all_local_variables.
549 If PERMANENT_TOO is 1, then we reset permanent built-in
550 buffer-local variables. If PERMANENT_TOO is 0,
551 we preserve those. */
554 reset_buffer_local_variables (b
, permanent_too
)
555 register struct buffer
*b
;
561 /* Decide which built-in local variables to reset. */
565 dont_reset
= buffer_permanent_local_flags
;
567 /* Reset the major mode to Fundamental, together with all the
568 things that depend on the major mode.
569 default-major-mode is handled at a higher level.
570 We ignore it here. */
571 b
->major_mode
= Qfundamental_mode
;
573 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
574 b
->mode_name
= QSFundamental
;
575 b
->minor_modes
= Qnil
;
577 /* If the standard case table has been altered and invalidated,
578 fix up its insides first. */
579 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
580 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
581 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
582 Fset_standard_case_table (Vascii_downcase_table
);
584 b
->downcase_table
= Vascii_downcase_table
;
585 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
586 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
587 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
588 b
->invisibility_spec
= Qt
;
590 b
->buffer_file_type
= Qnil
;
594 b
->sort_table
= XSTRING (Vascii_sort_table
);
595 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
598 /* Reset all (or most) per-buffer variables to their defaults. */
599 b
->local_var_alist
= Qnil
;
600 b
->local_var_flags
&= dont_reset
;
602 /* For each slot that has a default value,
603 copy that into the slot. */
605 for (offset
= (char *)&buffer_local_flags
.name
- (char *)&buffer_local_flags
;
606 offset
< sizeof (struct buffer
);
607 offset
+= sizeof (Lisp_Object
)) /* sizeof EMACS_INT == sizeof Lisp_Object */
609 int flag
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
611 /* Don't reset a permanent local. */
612 && ! (dont_reset
& flag
))
614 *(Lisp_Object
*)(offset
+ (char *)b
)
615 = *(Lisp_Object
*)(offset
+ (char *)&buffer_defaults
);
619 /* We split this away from generate-new-buffer, because rename-buffer
620 and set-visited-file-name ought to be able to use this to really
621 rename the buffer properly. */
623 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
625 "Return a string that is the name of no existing buffer based on NAME.\n\
626 If there is no live buffer named NAME, then return NAME.\n\
627 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
628 until an unused name is found, and then return that name.\n\
629 Optional second argument IGNORE specifies a name that is okay to use\n\
630 \(if it is in the sequence to be tried)\n\
631 even if a buffer with that name exists.")
633 register Lisp_Object name
, ignore
;
635 register Lisp_Object gentemp
, tem
;
639 CHECK_STRING (name
, 0);
641 tem
= Fget_buffer (name
);
648 sprintf (number
, "<%d>", ++count
);
649 gentemp
= concat2 (name
, build_string (number
));
650 tem
= Fstring_equal (gentemp
, ignore
);
653 tem
= Fget_buffer (gentemp
);
660 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
661 "Return the name of BUFFER, as a string.\n\
662 With no argument or nil as argument, return the name of the current buffer.")
664 register Lisp_Object buffer
;
667 return current_buffer
->name
;
668 CHECK_BUFFER (buffer
, 0);
669 return XBUFFER (buffer
)->name
;
672 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
673 "Return name of file BUFFER is visiting, or nil if none.\n\
674 No argument or nil as argument means use the current buffer.")
676 register Lisp_Object buffer
;
679 return current_buffer
->filename
;
680 CHECK_BUFFER (buffer
, 0);
681 return XBUFFER (buffer
)->filename
;
684 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
686 "Return the base buffer of indirect buffer BUFFER.\n\
687 If BUFFER is not indirect, return nil.")
689 register Lisp_Object buffer
;
692 Lisp_Object base_buffer
;
695 base
= current_buffer
->base_buffer
;
698 CHECK_BUFFER (buffer
, 0);
699 base
= XBUFFER (buffer
)->base_buffer
;
704 XSETBUFFER (base_buffer
, base
);
708 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
709 Sbuffer_local_variables
, 0, 1, 0,
710 "Return an alist of variables that are buffer-local in BUFFER.\n\
711 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
712 For a symbol that is locally unbound, just the symbol appears in the value.\n\
713 Note that storing new VALUEs in these elements doesn't change the variables.\n\
714 No argument or nil as argument means use current buffer as BUFFER.")
716 register Lisp_Object buffer
;
718 register struct buffer
*buf
;
719 register Lisp_Object result
;
722 buf
= current_buffer
;
725 CHECK_BUFFER (buffer
, 0);
726 buf
= XBUFFER (buffer
);
732 register Lisp_Object tail
;
733 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
735 Lisp_Object val
, elt
;
739 /* Reference each variable in the alist in buf.
740 If inquiring about the current buffer, this gets the current values,
741 so store them into the alist so the alist is up to date.
742 If inquiring about some other buffer, this swaps out any values
743 for that buffer, making the alist up to date automatically. */
744 val
= find_symbol_value (XCAR (elt
));
745 /* Use the current buffer value only if buf is the current buffer. */
746 if (buf
!= current_buffer
)
749 /* If symbol is unbound, put just the symbol in the list. */
750 if (EQ (val
, Qunbound
))
751 result
= Fcons (XCAR (elt
), result
);
752 /* Otherwise, put (symbol . value) in the list. */
754 result
= Fcons (Fcons (XCAR (elt
), val
), result
);
758 /* Add on all the variables stored in special slots. */
760 register int offset
, mask
;
762 for (offset
= (char *)&buffer_local_symbols
.name
- (char *)&buffer_local_symbols
;
763 offset
< sizeof (struct buffer
);
764 offset
+= (sizeof (EMACS_INT
))) /* sizeof EMACS_INT == sizeof Lisp_Object */
766 mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
767 if (mask
== -1 || (buf
->local_var_flags
& mask
))
768 if (SYMBOLP (*(Lisp_Object
*)(offset
769 + (char *)&buffer_local_symbols
)))
770 result
= Fcons (Fcons (*((Lisp_Object
*)
771 (offset
+ (char *)&buffer_local_symbols
)),
772 *(Lisp_Object
*)(offset
+ (char *)buf
)),
781 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
783 "Return t if BUFFER was modified since its file was last read or saved.\n\
784 No argument or nil as argument means use current buffer as BUFFER.")
786 register Lisp_Object buffer
;
788 register struct buffer
*buf
;
790 buf
= current_buffer
;
793 CHECK_BUFFER (buffer
, 0);
794 buf
= XBUFFER (buffer
);
797 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
800 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
802 "Mark current buffer as modified or unmodified according to FLAG.\n\
803 A non-nil FLAG means mark the buffer modified.")
805 register Lisp_Object flag
;
807 register int already
;
808 register Lisp_Object fn
;
809 Lisp_Object buffer
, window
;
811 #ifdef CLASH_DETECTION
812 /* If buffer becoming modified, lock the file.
813 If buffer becoming unmodified, unlock the file. */
815 fn
= current_buffer
->file_truename
;
816 /* Test buffer-file-name so that binding it to nil is effective. */
817 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
819 already
= SAVE_MODIFF
< MODIFF
;
820 if (!already
&& !NILP (flag
))
822 else if (already
&& NILP (flag
))
825 #endif /* CLASH_DETECTION */
827 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
829 /* Set update_mode_lines only if buffer is displayed in some window.
830 Packages like jit-lock or lazy-lock preserve a buffer's modified
831 state by recording/restoring the state around blocks of code.
832 Setting update_mode_lines makes redisplay consider all windows
833 (on all frames). Stealth fontification of buffers not displayed
834 would incur additional redisplay costs if we'd set
835 update_modes_lines unconditionally.
837 Ideally, I think there should be another mechanism for fontifying
838 buffers without "modifying" buffers, or redisplay should be
839 smarter about updating the `*' in mode lines. --gerd */
840 XSETBUFFER (buffer
, current_buffer
);
841 window
= Fget_buffer_window (buffer
, Qt
);
842 if (WINDOWP (window
))
848 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
850 "Return BUFFER's tick counter, incremented for each change in text.\n\
851 Each buffer has a tick counter which is incremented each time the text in\n\
852 that buffer is changed. It wraps around occasionally.\n\
853 No argument or nil as argument means use current buffer as BUFFER.")
855 register Lisp_Object buffer
;
857 register struct buffer
*buf
;
859 buf
= current_buffer
;
862 CHECK_BUFFER (buffer
, 0);
863 buf
= XBUFFER (buffer
);
866 return make_number (BUF_MODIFF (buf
));
869 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
870 "sRename buffer (to new name): \nP",
871 "Change current buffer's name to NEWNAME (a string).\n\
872 If second arg UNIQUE is nil or omitted, it is an error if a\n\
873 buffer named NEWNAME already exists.\n\
874 If UNIQUE is non-nil, come up with a new name using\n\
875 `generate-new-buffer-name'.\n\
876 Interactively, you can set UNIQUE with a prefix argument.\n\
877 We return the name we actually gave the buffer.\n\
878 This does not change the name of the visited file (if any).")
880 register Lisp_Object newname
, unique
;
882 register Lisp_Object tem
, buf
;
884 CHECK_STRING (newname
, 0);
886 if (XSTRING (newname
)->size
== 0)
887 error ("Empty string is invalid as a buffer name");
889 tem
= Fget_buffer (newname
);
890 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
891 the buffer automatically so you can create another with the original name.
892 It makes UNIQUE equivalent to
893 (rename-buffer (generate-new-buffer-name NEWNAME)). */
894 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
895 return current_buffer
->name
;
899 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
901 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
904 current_buffer
->name
= newname
;
906 /* Catch redisplay's attention. Unless we do this, the mode lines for
907 any windows displaying current_buffer will stay unchanged. */
910 XSETBUFFER (buf
, current_buffer
);
911 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
912 if (NILP (current_buffer
->filename
)
913 && !NILP (current_buffer
->auto_save_file_name
))
914 call0 (intern ("rename-auto-save-file"));
915 /* Refetch since that last call may have done GC. */
916 return current_buffer
->name
;
919 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 3, 0,
920 "Return most recently selected buffer other than BUFFER.\n\
921 Buffers not visible in windows are preferred to visible buffers,\n\
922 unless optional second argument VISIBLE-OK is non-nil.\n\
923 If the optional third argument FRAME is non-nil, use that frame's\n\
924 buffer list instead of the selected frame's buffer list.\n\
925 If no other buffer exists, the buffer `*scratch*' is returned.\n\
926 If BUFFER is omitted or nil, some interesting buffer is returned.")
927 (buffer
, visible_ok
, frame
)
928 register Lisp_Object buffer
, visible_ok
, frame
;
930 Lisp_Object
Fset_buffer_major_mode ();
931 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
935 frame
= selected_frame
;
937 tail
= Vbuffer_alist
;
938 pred
= frame_buffer_predicate (frame
);
940 /* Consider buffers that have been seen in the selected frame
941 before other buffers. */
943 tem
= frame_buffer_list (frame
);
947 if (BUFFERP (XCAR (tem
)))
948 add_ons
= Fcons (Fcons (Qnil
, XCAR (tem
)), add_ons
);
951 tail
= nconc2 (Fnreverse (add_ons
), tail
);
953 for (; !NILP (tail
); tail
= Fcdr (tail
))
955 buf
= Fcdr (Fcar (tail
));
956 if (EQ (buf
, buffer
))
958 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
960 /* If the selected frame has a buffer_predicate,
961 disregard buffers that don't fit the predicate. */
964 tem
= call1 (pred
, buf
);
969 if (NILP (visible_ok
))
970 tem
= Fget_buffer_window (buf
, Qt
);
975 if (NILP (notsogood
))
978 if (!NILP (notsogood
))
980 buf
= Fget_buffer (build_string ("*scratch*"));
983 buf
= Fget_buffer_create (build_string ("*scratch*"));
984 Fset_buffer_major_mode (buf
);
989 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
,
991 "Make BUFFER stop keeping undo information.\n\
992 No argument or nil as argument means do this for the current buffer.")
994 register Lisp_Object buffer
;
996 Lisp_Object real_buffer
;
999 XSETBUFFER (real_buffer
, current_buffer
);
1002 real_buffer
= Fget_buffer (buffer
);
1003 if (NILP (real_buffer
))
1007 XBUFFER (real_buffer
)->undo_list
= Qt
;
1012 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
1014 "Start keeping undo information for buffer BUFFER.\n\
1015 No argument or nil as argument means do this for the current buffer.")
1017 register Lisp_Object buffer
;
1019 Lisp_Object real_buffer
;
1022 XSETBUFFER (real_buffer
, current_buffer
);
1025 real_buffer
= Fget_buffer (buffer
);
1026 if (NILP (real_buffer
))
1030 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
1031 XBUFFER (real_buffer
)->undo_list
= Qnil
;
1037 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
1038 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1039 The buffer being killed will be current while the hook is running.\n\
1042 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
1043 "Kill the buffer BUFFER.\n\
1044 The argument may be a buffer or may be the name of a buffer.\n\
1045 An argument of nil means kill the current buffer.\n\n\
1046 Value is t if the buffer is actually killed, nil if user says no.\n\n\
1047 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
1048 if not void, is a list of functions to be called, with no arguments,\n\
1049 before the buffer is actually killed. The buffer to be killed is current\n\
1050 when the hook functions are called.\n\n\
1051 Any processes that have this buffer as the `process-buffer' are killed\n\
1057 register struct buffer
*b
;
1058 register Lisp_Object tem
;
1059 register struct Lisp_Marker
*m
;
1060 struct gcpro gcpro1
;
1063 buf
= Fcurrent_buffer ();
1065 buf
= Fget_buffer (buffer
);
1071 /* Avoid trouble for buffer already dead. */
1075 /* Query if the buffer is still modified. */
1076 if (INTERACTIVE
&& !NILP (b
->filename
)
1077 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1080 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
1081 XSTRING (b
->name
)->data
));
1087 /* Run hooks with the buffer to be killed the current buffer. */
1089 int count
= specpdl_ptr
- specpdl
;
1092 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1093 set_buffer_internal (b
);
1095 /* First run the query functions; if any query is answered no,
1096 don't kill the buffer. */
1097 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
1099 tem
= call0 (Fcar (list
));
1101 return unbind_to (count
, Qnil
);
1104 /* Then run the hooks. */
1105 if (!NILP (Vrun_hooks
))
1106 call1 (Vrun_hooks
, Qkill_buffer_hook
);
1107 unbind_to (count
, Qnil
);
1110 /* We have no more questions to ask. Verify that it is valid
1111 to kill the buffer. This must be done after the questions
1112 since anything can happen within do_yes_or_no_p. */
1114 /* Don't kill the minibuffer now current. */
1115 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1121 /* When we kill a base buffer, kill all its indirect buffers.
1122 We do it at this stage so nothing terrible happens if they
1123 ask questions or their hooks get errors. */
1124 if (! b
->base_buffer
)
1126 struct buffer
*other
;
1130 for (other
= all_buffers
; other
; other
= other
->next
)
1131 /* all_buffers contains dead buffers too;
1132 don't re-kill them. */
1133 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1136 XSETBUFFER (buf
, other
);
1143 /* Make this buffer not be current.
1144 In the process, notice if this is the sole visible buffer
1145 and give up if so. */
1146 if (b
== current_buffer
)
1148 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1150 if (b
== current_buffer
)
1154 /* Now there is no question: we can kill the buffer. */
1156 #ifdef CLASH_DETECTION
1157 /* Unlock this buffer's file, if it is locked. */
1159 #endif /* CLASH_DETECTION */
1161 kill_buffer_processes (buf
);
1163 tem
= Vinhibit_quit
;
1165 replace_buffer_in_all_windows (buf
);
1166 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1167 frames_discard_buffer (buf
);
1168 Vinhibit_quit
= tem
;
1170 /* Delete any auto-save file, if we saved it in this session. */
1171 if (STRINGP (b
->auto_save_file_name
)
1172 && b
->auto_save_modified
!= 0
1173 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
)
1176 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1178 internal_delete_file (b
->auto_save_file_name
);
1183 /* Unchain all markers that belong to this indirect buffer.
1184 Don't unchain the markers that belong to the base buffer
1185 or its other indirect buffers. */
1186 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1192 unchain_marker (tem
);
1198 /* Unchain all markers of this buffer and its indirect buffers.
1199 and leave them pointing nowhere. */
1200 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1207 BUF_MARKERS (b
) = Qnil
;
1208 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1210 /* Perhaps we should explicitly free the interval tree here... */
1213 /* Reset the local variables, so that this buffer's local values
1214 won't be protected from GC. They would be protected
1215 if they happened to remain encached in their symbols.
1216 This gets rid of them for certain. */
1217 swap_out_buffer_local_variables (b
);
1218 reset_buffer_local_variables (b
, 1);
1223 if (! b
->base_buffer
)
1224 BUFFER_FREE (BUF_BEG_ADDR (b
));
1226 if (b
->newline_cache
)
1228 free_region_cache (b
->newline_cache
);
1229 b
->newline_cache
= 0;
1231 if (b
->width_run_cache
)
1233 free_region_cache (b
->width_run_cache
);
1234 b
->width_run_cache
= 0;
1236 b
->width_table
= Qnil
;
1238 b
->undo_list
= Qnil
;
1243 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1244 we do this each time BUF is selected visibly, the more recently
1245 selected buffers are always closer to the front of the list. This
1246 means that other_buffer is more likely to choose a relevant buffer. */
1252 register Lisp_Object link
, prev
;
1254 frame
= selected_frame
;
1257 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCDR (link
))
1259 if (EQ (XCDR (XCAR (link
)), buf
))
1264 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1265 we cannot use Fdelq itself here because it allows quitting. */
1268 Vbuffer_alist
= XCDR (Vbuffer_alist
);
1270 XCDR (prev
) = XCDR (XCDR (prev
));
1272 XCDR (link
) = Vbuffer_alist
;
1273 Vbuffer_alist
= link
;
1275 /* Now move this buffer to the front of frame_buffer_list also. */
1278 for (link
= frame_buffer_list (frame
); CONSP (link
);
1281 if (EQ (XCAR (link
), buf
))
1286 /* Effectively do delq. */
1291 set_frame_buffer_list (frame
,
1292 XCDR (frame_buffer_list (frame
)));
1294 XCDR (prev
) = XCDR (XCDR (prev
));
1296 XCDR (link
) = frame_buffer_list (frame
);
1297 set_frame_buffer_list (frame
, link
);
1300 set_frame_buffer_list (frame
, Fcons (buf
, frame_buffer_list (frame
)));
1303 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1304 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1305 Use this function before selecting the buffer, since it may need to inspect\n\
1306 the current buffer's major mode.")
1311 Lisp_Object function
;
1313 function
= buffer_defaults
.major_mode
;
1314 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1315 function
= current_buffer
->major_mode
;
1317 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1320 count
= specpdl_ptr
- specpdl
;
1322 /* To select a nonfundamental mode,
1323 select the buffer temporarily and then call the mode function. */
1325 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1327 Fset_buffer (buffer
);
1330 return unbind_to (count
, Qnil
);
1333 /* If switching buffers in WINDOW would be an error, return
1334 a C string saying what the error would be. */
1337 no_switch_window (window
)
1341 if (EQ (minibuf_window
, window
))
1342 return "Cannot switch buffers in minibuffer window";
1343 tem
= Fwindow_dedicated_p (window
);
1345 return "Cannot switch buffers in a dedicated window";
1349 /* Switch to buffer BUFFER in the selected window.
1350 If NORECORD is non-nil, don't call record_buffer. */
1353 switch_to_buffer_1 (buffer
, norecord
)
1354 Lisp_Object buffer
, norecord
;
1356 register Lisp_Object buf
;
1359 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1362 buf
= Fget_buffer (buffer
);
1365 buf
= Fget_buffer_create (buffer
);
1366 Fset_buffer_major_mode (buf
);
1370 if (NILP (norecord
))
1371 record_buffer (buf
);
1373 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1374 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1381 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1382 "Select buffer BUFFER in the current window.\n\
1383 BUFFER may be a buffer or a buffer name.\n\
1384 Optional second arg NORECORD non-nil means\n\
1385 do not put this buffer at the front of the list of recently selected ones.\n\
1387 WARNING: This is NOT the way to work on another buffer temporarily\n\
1388 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1389 the window-buffer correspondences.")
1391 Lisp_Object buffer
, norecord
;
1395 err
= no_switch_window (selected_window
);
1396 if (err
) error (err
);
1398 return switch_to_buffer_1 (buffer
, norecord
);
1401 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1402 "Select buffer BUFFER in some window, preferably a different one.\n\
1403 If BUFFER is nil, then some other buffer is chosen.\n\
1404 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1405 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1406 window even if BUFFER is already visible in the selected window.\n\
1407 This uses the function `display-buffer' as a subroutine; see the documentation\n\
1408 of `display-buffer' for additional customization information.\n\
1410 Optional third arg NORECORD non-nil means\n\
1411 do not put this buffer at the front of the list of recently selected ones.")
1412 (buffer
, other_window
, norecord
)
1413 Lisp_Object buffer
, other_window
, norecord
;
1415 register Lisp_Object buf
;
1417 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1420 buf
= Fget_buffer (buffer
);
1423 buf
= Fget_buffer_create (buffer
);
1424 Fset_buffer_major_mode (buf
);
1428 if (NILP (norecord
))
1429 record_buffer (buf
);
1430 Fselect_window (Fdisplay_buffer (buf
, other_window
, Qnil
));
1434 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1435 "Return the current buffer as a Lisp object.")
1438 register Lisp_Object buf
;
1439 XSETBUFFER (buf
, current_buffer
);
1443 /* Set the current buffer to B.
1445 We previously set windows_or_buffers_changed here to invalidate
1446 global unchanged information in beg_unchanged and end_unchanged.
1447 This is no longer necessary because we now compute unchanged
1448 information on a buffer-basis. Every action affecting other
1449 windows than the selected one requires a select_window at some
1450 time, and that increments windows_or_buffers_changed. */
1453 set_buffer_internal (b
)
1454 register struct buffer
*b
;
1456 if (current_buffer
!= b
)
1457 set_buffer_internal_1 (b
);
1460 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1461 This is used by redisplay. */
1464 set_buffer_internal_1 (b
)
1465 register struct buffer
*b
;
1467 register struct buffer
*old_buf
;
1468 register Lisp_Object tail
, valcontents
;
1471 if (current_buffer
== b
)
1474 old_buf
= current_buffer
;
1476 last_known_column_point
= -1; /* invalidate indentation cache */
1480 /* Put the undo list back in the base buffer, so that it appears
1481 that an indirect buffer shares the undo list of its base. */
1482 if (old_buf
->base_buffer
)
1483 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1485 /* If the old current buffer has markers to record PT, BEGV and ZV
1486 when it is not current, update them now. */
1487 if (! NILP (old_buf
->pt_marker
))
1490 XSETBUFFER (obuf
, old_buf
);
1491 set_marker_both (old_buf
->pt_marker
, obuf
,
1492 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1494 if (! NILP (old_buf
->begv_marker
))
1497 XSETBUFFER (obuf
, old_buf
);
1498 set_marker_both (old_buf
->begv_marker
, obuf
,
1499 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1501 if (! NILP (old_buf
->zv_marker
))
1504 XSETBUFFER (obuf
, old_buf
);
1505 set_marker_both (old_buf
->zv_marker
, obuf
,
1506 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1510 /* Get the undo list from the base buffer, so that it appears
1511 that an indirect buffer shares the undo list of its base. */
1513 b
->undo_list
= b
->base_buffer
->undo_list
;
1515 /* If the new current buffer has markers to record PT, BEGV and ZV
1516 when it is not current, fetch them now. */
1517 if (! NILP (b
->pt_marker
))
1519 BUF_PT (b
) = marker_position (b
->pt_marker
);
1520 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1522 if (! NILP (b
->begv_marker
))
1524 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1525 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1527 if (! NILP (b
->zv_marker
))
1529 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1530 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1533 /* Look down buffer's list of local Lisp variables
1534 to find and update any that forward into C variables. */
1536 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCDR (tail
))
1538 valcontents
= XSYMBOL (XCAR (XCAR (tail
)))->value
;
1539 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1540 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1541 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1542 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1543 /* Just reference the variable
1544 to cause it to become set for this buffer. */
1545 Fsymbol_value (XCAR (XCAR (tail
)));
1548 /* Do the same with any others that were local to the previous buffer */
1551 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCDR (tail
))
1553 valcontents
= XSYMBOL (XCAR (XCAR (tail
)))->value
;
1554 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1555 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1556 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1557 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1558 /* Just reference the variable
1559 to cause it to become set for this buffer. */
1560 Fsymbol_value (XCAR (XCAR (tail
)));
1564 /* Switch to buffer B temporarily for redisplay purposes.
1565 This avoids certain things that don't need to be done within redisplay. */
1571 register struct buffer
*old_buf
;
1573 if (current_buffer
== b
)
1576 old_buf
= current_buffer
;
1581 /* If the old current buffer has markers to record PT, BEGV and ZV
1582 when it is not current, update them now. */
1583 if (! NILP (old_buf
->pt_marker
))
1586 XSETBUFFER (obuf
, old_buf
);
1587 set_marker_both (old_buf
->pt_marker
, obuf
,
1588 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1590 if (! NILP (old_buf
->begv_marker
))
1593 XSETBUFFER (obuf
, old_buf
);
1594 set_marker_both (old_buf
->begv_marker
, obuf
,
1595 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1597 if (! NILP (old_buf
->zv_marker
))
1600 XSETBUFFER (obuf
, old_buf
);
1601 set_marker_both (old_buf
->zv_marker
, obuf
,
1602 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1606 /* If the new current buffer has markers to record PT, BEGV and ZV
1607 when it is not current, fetch them now. */
1608 if (! NILP (b
->pt_marker
))
1610 BUF_PT (b
) = marker_position (b
->pt_marker
);
1611 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1613 if (! NILP (b
->begv_marker
))
1615 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1616 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1618 if (! NILP (b
->zv_marker
))
1620 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1621 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1625 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1626 "Make the buffer BUFFER current for editing operations.\n\
1627 BUFFER may be a buffer or the name of an existing buffer.\n\
1628 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1629 This function does not display the buffer, so its effect ends\n\
1630 when the current command terminates.\n\
1631 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1633 register Lisp_Object buffer
;
1635 register Lisp_Object buf
;
1636 buf
= Fget_buffer (buffer
);
1639 if (NILP (XBUFFER (buf
)->name
))
1640 error ("Selecting deleted buffer");
1641 set_buffer_internal (XBUFFER (buf
));
1645 /* Set the current buffer to BUFFER provided it is alive. */
1648 set_buffer_if_live (buffer
)
1651 if (! NILP (XBUFFER (buffer
)->name
))
1652 Fset_buffer (buffer
);
1656 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1657 Sbarf_if_buffer_read_only
, 0, 0, 0,
1658 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1661 if (!NILP (current_buffer
->read_only
)
1662 && NILP (Vinhibit_read_only
))
1663 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1667 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1668 "Put BUFFER at the end of the list of all buffers.\n\
1669 There it is the least likely candidate for `other-buffer' to return;\n\
1670 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1671 If BUFFER is nil or omitted, bury the current buffer.\n\
1672 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1673 selected window if it is displayed there.")
1675 register Lisp_Object buffer
;
1677 /* Figure out what buffer we're going to bury. */
1680 XSETBUFFER (buffer
, current_buffer
);
1682 /* If we're burying the current buffer, unshow it. */
1683 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
, Qnil
), Qnil
);
1689 buf1
= Fget_buffer (buffer
);
1695 /* Move buffer to the end of the buffer list. */
1697 register Lisp_Object aelt
, link
;
1699 aelt
= Frassq (buffer
, Vbuffer_alist
);
1700 link
= Fmemq (aelt
, Vbuffer_alist
);
1701 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1703 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1706 frames_bury_buffer (buffer
);
1711 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1712 "Delete the entire contents of the current buffer.\n\
1713 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1714 so the buffer is truly empty after this.")
1721 current_buffer
->last_window_start
= 1;
1722 /* Prevent warnings, or suspension of auto saving, that would happen
1723 if future size is less than past size. Use of erase-buffer
1724 implies that the future text is not really related to the past text. */
1725 XSETFASTINT (current_buffer
->save_length
, 0);
1730 validate_region (b
, e
)
1731 register Lisp_Object
*b
, *e
;
1733 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1734 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1736 if (XINT (*b
) > XINT (*e
))
1739 tem
= *b
; *b
= *e
; *e
= tem
;
1742 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1743 && XINT (*e
) <= ZV
))
1744 args_out_of_range (*b
, *e
);
1747 /* Advance BYTE_POS up to a character boundary
1748 and return the adjusted position. */
1751 advance_to_char_boundary (byte_pos
)
1756 if (byte_pos
== BEG
)
1757 /* Beginning of buffer is always a character boundary. */
1760 c
= FETCH_BYTE (byte_pos
);
1761 if (! CHAR_HEAD_P (c
))
1763 /* We should advance BYTE_POS only when C is a constituent of a
1764 multibyte sequence. */
1767 /* If C is a constituent of a multibyte sequence, BYTE_POS was
1768 surely advance to the correct character boundary. If C is
1769 not, BYTE_POS was unchanged. */
1775 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte
, Sset_buffer_multibyte
,
1777 "Set the multibyte flag of the current buffer to FLAG.\n\
1778 If FLAG is t, this makes the buffer a multibyte buffer.\n\
1779 If FLAG is nil, this makes the buffer a single-byte buffer.\n\
1780 The buffer contents remain unchanged as a sequence of bytes\n\
1781 but the contents viewed as characters do change.")
1785 Lisp_Object tail
, markers
;
1786 struct buffer
*other
;
1788 if (current_buffer
->base_buffer
)
1789 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
1791 /* Do nothing if nothing actually changes. */
1792 if (NILP (flag
) == NILP (current_buffer
->enable_multibyte_characters
))
1795 /* It would be better to update the list,
1796 but this is good enough for now. */
1797 if (! EQ (current_buffer
->undo_list
, Qt
))
1798 current_buffer
->undo_list
= Qnil
;
1800 /* If the cached position is for this buffer, clear it out. */
1801 clear_charpos_cache (current_buffer
);
1805 /* Do this first, so it can use CHAR_TO_BYTE
1806 to calculate the old correspondences. */
1807 set_intervals_multibyte (0);
1809 current_buffer
->enable_multibyte_characters
= Qnil
;
1815 TEMP_SET_PT_BOTH (PT_BYTE
, PT_BYTE
);
1817 tail
= BUF_MARKERS (current_buffer
);
1818 while (XSYMBOL (tail
) != XSYMBOL (Qnil
))
1820 XMARKER (tail
)->charpos
= XMARKER (tail
)->bytepos
;
1821 tail
= XMARKER (tail
)->chain
;
1826 /* Be sure not to have a multibyte sequence striding over the GAP.
1827 Ex: We change this: "...abc\201\241\241 _GAP_ \241\241\241..."
1828 to: "...abc _GAP_ \201\241\241\241\241\241..." */
1830 if (GPT_BYTE
> 1 && GPT_BYTE
< Z_BYTE
1831 && ! CHAR_HEAD_P (*(GAP_END_ADDR
)))
1833 unsigned char *p
= GPT_ADDR
- 1;
1835 while (! CHAR_HEAD_P (*p
) && p
> BEG_ADDR
) p
--;
1836 if (BASE_LEADING_CODE_P (*p
))
1838 int new_gpt
= GPT_BYTE
- (GPT_ADDR
- p
);
1840 move_gap_both (new_gpt
, new_gpt
);
1844 /* Do this first, so that chars_in_text asks the right question.
1845 set_intervals_multibyte needs it too. */
1846 current_buffer
->enable_multibyte_characters
= Qt
;
1848 GPT_BYTE
= advance_to_char_boundary (GPT_BYTE
);
1849 GPT
= chars_in_text (BEG_ADDR
, GPT_BYTE
- BEG_BYTE
) + BEG
;
1851 Z
= chars_in_text (GAP_END_ADDR
, Z_BYTE
- GPT_BYTE
) + GPT
;
1853 BEGV_BYTE
= advance_to_char_boundary (BEGV_BYTE
);
1854 if (BEGV_BYTE
> GPT_BYTE
)
1855 BEGV
= chars_in_text (GAP_END_ADDR
, BEGV_BYTE
- GPT_BYTE
) + GPT
;
1857 BEGV
= chars_in_text (BEG_ADDR
, BEGV_BYTE
- BEG_BYTE
) + BEG
;
1859 ZV_BYTE
= advance_to_char_boundary (ZV_BYTE
);
1860 if (ZV_BYTE
> GPT_BYTE
)
1861 ZV
= chars_in_text (GAP_END_ADDR
, ZV_BYTE
- GPT_BYTE
) + GPT
;
1863 ZV
= chars_in_text (BEG_ADDR
, ZV_BYTE
- BEG_BYTE
) + BEG
;
1866 int pt_byte
= advance_to_char_boundary (PT_BYTE
);
1869 if (pt_byte
> GPT_BYTE
)
1870 pt
= chars_in_text (GAP_END_ADDR
, pt_byte
- GPT_BYTE
) + GPT
;
1872 pt
= chars_in_text (BEG_ADDR
, pt_byte
- BEG_BYTE
) + BEG
;
1873 TEMP_SET_PT_BOTH (pt
, pt_byte
);
1876 tail
= markers
= BUF_MARKERS (current_buffer
);
1878 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
1879 getting confused by the markers that have not yet been updated.
1880 It is also a signal that it should never create a marker. */
1881 BUF_MARKERS (current_buffer
) = Qnil
;
1883 while (XSYMBOL (tail
) != XSYMBOL (Qnil
))
1885 XMARKER (tail
)->bytepos
1886 = advance_to_char_boundary (XMARKER (tail
)->bytepos
);
1887 XMARKER (tail
)->charpos
= BYTE_TO_CHAR (XMARKER (tail
)->bytepos
);
1889 tail
= XMARKER (tail
)->chain
;
1892 /* Make sure no markers were put on the chain
1893 while the chain value was incorrect. */
1894 if (! EQ (BUF_MARKERS (current_buffer
), Qnil
))
1897 BUF_MARKERS (current_buffer
) = markers
;
1899 /* Do this last, so it can calculate the new correspondences
1900 between chars and bytes. */
1901 set_intervals_multibyte (1);
1904 /* Changing the multibyteness of a buffer means that all windows
1905 showing that buffer must be updated thoroughly. */
1906 current_buffer
->prevent_redisplay_optimizations_p
= 1;
1907 ++windows_or_buffers_changed
;
1909 /* Copy this buffer's new multibyte status
1910 into all of its indirect buffers. */
1911 for (other
= all_buffers
; other
; other
= other
->next
)
1912 if (other
->base_buffer
== current_buffer
&& !NILP (other
->name
))
1914 other
->enable_multibyte_characters
1915 = current_buffer
->enable_multibyte_characters
;
1916 other
->prevent_redisplay_optimizations_p
= 1;
1922 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
1924 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1925 Most local variable bindings are eliminated so that the default values\n\
1926 become effective once more. Also, the syntax table is set from\n\
1927 `standard-syntax-table', the local keymap is set to nil,\n\
1928 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1929 This function also forces redisplay of the mode line.\n\
1931 Every function to select a new major mode starts by\n\
1932 calling this function.\n\n\
1933 As a special exception, local variables whose names have\n\
1934 a non-nil `permanent-local' property are not eliminated by this function.\n\
1936 The first thing this function does is run\n\
1937 the normal hook `change-major-mode-hook'.")
1940 register Lisp_Object alist
, sym
, tem
;
1943 if (!NILP (Vrun_hooks
))
1944 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
1945 oalist
= current_buffer
->local_var_alist
;
1947 /* Make sure none of the bindings in oalist
1948 remain swapped in, in their symbols. */
1950 swap_out_buffer_local_variables (current_buffer
);
1952 /* Actually eliminate all local bindings of this buffer. */
1954 reset_buffer_local_variables (current_buffer
, 0);
1956 /* Redisplay mode lines; we are changing major mode. */
1958 update_mode_lines
++;
1960 /* Any which are supposed to be permanent,
1961 make local again, with the same values they had. */
1963 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
1965 sym
= XCAR (XCAR (alist
));
1966 tem
= Fget (sym
, Qpermanent_local
);
1969 Fmake_local_variable (sym
);
1970 Fset (sym
, XCDR (XCAR (alist
)));
1974 /* Force mode-line redisplay. Useful here because all major mode
1975 commands call this function. */
1976 update_mode_lines
++;
1981 /* Make sure no local variables remain set up with buffer B
1982 for their current values. */
1985 swap_out_buffer_local_variables (b
)
1988 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
1990 XSETBUFFER (buffer
, b
);
1991 oalist
= b
->local_var_alist
;
1993 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
1995 sym
= XCAR (XCAR (alist
));
1997 /* Need not do anything if some other buffer's binding is now encached. */
1998 tem
= XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->buffer
;
1999 if (XBUFFER (tem
) == current_buffer
)
2001 /* Symbol is set up for this buffer's old local value.
2002 Set it up for the current buffer with the default value. */
2004 tem
= XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
;
2005 /* Store the symbol's current value into the alist entry
2006 it is currently set up for. This is so that, if the
2007 local is marked permanent, and we make it local again
2008 later in Fkill_all_local_variables, we don't lose the value. */
2010 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->realvalue
);
2011 /* Switch to the symbol's default-value alist entry. */
2013 /* Mark it as current for buffer B. */
2014 XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->buffer
= buffer
;
2015 /* Store the current value into any forwarding in the symbol. */
2016 store_symval_forwarding (sym
,
2017 XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->realvalue
,
2023 /* Find all the overlays in the current buffer that contain position POS.
2024 Return the number found, and store them in a vector in *VEC_PTR.
2025 Store in *LEN_PTR the size allocated for the vector.
2026 Store in *NEXT_PTR the next position after POS where an overlay starts,
2027 or ZV if there are no more overlays.
2028 Store in *PREV_PTR the previous position before POS where an overlay ends,
2029 or where an overlay starts which ends at or after POS;
2030 or BEGV if there are no such overlays.
2031 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2033 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2034 when this function is called.
2036 If EXTEND is non-zero, we make the vector bigger if necessary.
2037 If EXTEND is zero, we never extend the vector,
2038 and we store only as many overlays as will fit.
2039 But we still return the total number of overlays. */
2042 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2045 Lisp_Object
**vec_ptr
;
2050 Lisp_Object tail
, overlay
, start
, end
;
2053 Lisp_Object
*vec
= *vec_ptr
;
2056 int inhibit_storing
= 0;
2058 for (tail
= current_buffer
->overlays_before
;
2062 int startpos
, endpos
;
2064 overlay
= XCAR (tail
);
2066 start
= OVERLAY_START (overlay
);
2067 end
= OVERLAY_END (overlay
);
2068 endpos
= OVERLAY_POSITION (end
);
2075 startpos
= OVERLAY_POSITION (start
);
2076 /* This one ends at or after POS
2077 so its start counts for PREV_PTR if it's before POS. */
2078 if (prev
< startpos
&& startpos
< pos
)
2082 if (startpos
<= pos
)
2086 /* The supplied vector is full.
2087 Either make it bigger, or don't store any more in it. */
2090 /* Make it work with an initial len == 0. */
2095 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2099 inhibit_storing
= 1;
2102 if (!inhibit_storing
)
2104 /* Keep counting overlays even if we can't return them all. */
2107 else if (startpos
< next
)
2111 for (tail
= current_buffer
->overlays_after
;
2115 int startpos
, endpos
;
2117 overlay
= XCAR (tail
);
2119 start
= OVERLAY_START (overlay
);
2120 end
= OVERLAY_END (overlay
);
2121 startpos
= OVERLAY_POSITION (start
);
2124 if (startpos
< next
)
2128 endpos
= OVERLAY_POSITION (end
);
2135 *len_ptr
= len
*= 2;
2138 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2142 inhibit_storing
= 1;
2145 if (!inhibit_storing
)
2149 if (startpos
< pos
&& startpos
> prev
)
2152 else if (endpos
< pos
&& endpos
> prev
)
2154 else if (endpos
== pos
&& startpos
> prev
)
2165 /* Find all the overlays in the current buffer that overlap the range BEG-END
2166 or are empty at BEG.
2168 Return the number found, and store them in a vector in *VEC_PTR.
2169 Store in *LEN_PTR the size allocated for the vector.
2170 Store in *NEXT_PTR the next position after POS where an overlay starts,
2171 or ZV if there are no more overlays.
2172 Store in *PREV_PTR the previous position before POS where an overlay ends,
2173 or BEGV if there are no previous overlays.
2174 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2176 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2177 when this function is called.
2179 If EXTEND is non-zero, we make the vector bigger if necessary.
2180 If EXTEND is zero, we never extend the vector,
2181 and we store only as many overlays as will fit.
2182 But we still return the total number of overlays. */
2185 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2188 Lisp_Object
**vec_ptr
;
2193 Lisp_Object tail
, overlay
, ostart
, oend
;
2196 Lisp_Object
*vec
= *vec_ptr
;
2199 int inhibit_storing
= 0;
2201 for (tail
= current_buffer
->overlays_before
;
2205 int startpos
, endpos
;
2207 overlay
= XCAR (tail
);
2209 ostart
= OVERLAY_START (overlay
);
2210 oend
= OVERLAY_END (overlay
);
2211 endpos
= OVERLAY_POSITION (oend
);
2218 startpos
= OVERLAY_POSITION (ostart
);
2219 /* Count an interval if it either overlaps the range
2220 or is empty at the start of the range. */
2221 if ((beg
< endpos
&& startpos
< end
)
2222 || (startpos
== endpos
&& beg
== endpos
))
2226 /* The supplied vector is full.
2227 Either make it bigger, or don't store any more in it. */
2230 *len_ptr
= len
*= 2;
2231 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2235 inhibit_storing
= 1;
2238 if (!inhibit_storing
)
2240 /* Keep counting overlays even if we can't return them all. */
2243 else if (startpos
< next
)
2247 for (tail
= current_buffer
->overlays_after
;
2251 int startpos
, endpos
;
2253 overlay
= XCAR (tail
);
2255 ostart
= OVERLAY_START (overlay
);
2256 oend
= OVERLAY_END (overlay
);
2257 startpos
= OVERLAY_POSITION (ostart
);
2260 if (startpos
< next
)
2264 endpos
= OVERLAY_POSITION (oend
);
2265 /* Count an interval if it either overlaps the range
2266 or is empty at the start of the range. */
2267 if ((beg
< endpos
&& startpos
< end
)
2268 || (startpos
== endpos
&& beg
== endpos
))
2274 *len_ptr
= len
*= 2;
2275 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2279 inhibit_storing
= 1;
2282 if (!inhibit_storing
)
2286 else if (endpos
< beg
&& endpos
> prev
)
2297 /* Fast function to just test if we're at an overlay boundary. */
2299 overlay_touches_p (pos
)
2302 Lisp_Object tail
, overlay
;
2304 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
2309 overlay
= XCAR (tail
);
2310 if (!GC_OVERLAYP (overlay
))
2313 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2316 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2320 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
2325 overlay
= XCAR (tail
);
2326 if (!GC_OVERLAYP (overlay
))
2329 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2332 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2340 Lisp_Object overlay
;
2346 compare_overlays (v1
, v2
)
2347 const void *v1
, *v2
;
2349 const struct sortvec
*s1
= (const struct sortvec
*) v1
;
2350 const struct sortvec
*s2
= (const struct sortvec
*) v2
;
2351 if (s1
->priority
!= s2
->priority
)
2352 return s1
->priority
- s2
->priority
;
2353 if (s1
->beg
!= s2
->beg
)
2354 return s1
->beg
- s2
->beg
;
2355 if (s1
->end
!= s2
->end
)
2356 return s2
->end
- s1
->end
;
2360 /* Sort an array of overlays by priority. The array is modified in place.
2361 The return value is the new size; this may be smaller than the original
2362 size if some of the overlays were invalid or were window-specific. */
2364 sort_overlays (overlay_vec
, noverlays
, w
)
2365 Lisp_Object
*overlay_vec
;
2370 struct sortvec
*sortvec
;
2371 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2373 /* Put the valid and relevant overlays into sortvec. */
2375 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2378 Lisp_Object overlay
;
2380 overlay
= overlay_vec
[i
];
2381 if (OVERLAY_VALID (overlay
)
2382 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2383 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2385 /* If we're interested in a specific window, then ignore
2386 overlays that are limited to some other window. */
2391 window
= Foverlay_get (overlay
, Qwindow
);
2392 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2396 /* This overlay is good and counts: put it into sortvec. */
2397 sortvec
[j
].overlay
= overlay
;
2398 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2399 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2400 tem
= Foverlay_get (overlay
, Qpriority
);
2402 sortvec
[j
].priority
= XINT (tem
);
2404 sortvec
[j
].priority
= 0;
2410 /* Sort the overlays into the proper order: increasing priority. */
2413 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2415 for (i
= 0; i
< noverlays
; i
++)
2416 overlay_vec
[i
] = sortvec
[i
].overlay
;
2422 Lisp_Object string
, string2
;
2429 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2430 int size
; /* Allocated length of that array. */
2431 int used
; /* How much of the array is currently in use. */
2432 int bytes
; /* Total length of the strings in buf. */
2435 /* Buffers for storing information about the overlays touching a given
2436 position. These could be automatic variables in overlay_strings, but
2437 it's more efficient to hold onto the memory instead of repeatedly
2438 allocating and freeing it. */
2439 static struct sortstrlist overlay_heads
, overlay_tails
;
2440 static unsigned char *overlay_str_buf
;
2442 /* Allocated length of overlay_str_buf. */
2443 static int overlay_str_len
;
2445 /* A comparison function suitable for passing to qsort. */
2447 cmp_for_strings (as1
, as2
)
2450 struct sortstr
*s1
= (struct sortstr
*)as1
;
2451 struct sortstr
*s2
= (struct sortstr
*)as2
;
2452 if (s1
->size
!= s2
->size
)
2453 return s2
->size
- s1
->size
;
2454 if (s1
->priority
!= s2
->priority
)
2455 return s1
->priority
- s2
->priority
;
2460 record_overlay_string (ssl
, str
, str2
, pri
, size
)
2461 struct sortstrlist
*ssl
;
2462 Lisp_Object str
, str2
, pri
;
2467 if (ssl
->used
== ssl
->size
)
2473 ssl
->buf
= ((struct sortstr
*)
2474 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2476 ssl
->buf
[ssl
->used
].string
= str
;
2477 ssl
->buf
[ssl
->used
].string2
= str2
;
2478 ssl
->buf
[ssl
->used
].size
= size
;
2479 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2482 if (NILP (current_buffer
->enable_multibyte_characters
))
2483 nbytes
= XSTRING (str
)->size
;
2484 else if (! STRING_MULTIBYTE (str
))
2485 nbytes
= count_size_as_multibyte (XSTRING (str
)->data
,
2486 STRING_BYTES (XSTRING (str
)));
2488 nbytes
= STRING_BYTES (XSTRING (str
));
2490 ssl
->bytes
+= nbytes
;
2494 if (NILP (current_buffer
->enable_multibyte_characters
))
2495 nbytes
= XSTRING (str2
)->size
;
2496 else if (! STRING_MULTIBYTE (str2
))
2497 nbytes
= count_size_as_multibyte (XSTRING (str2
)->data
,
2498 STRING_BYTES (XSTRING (str2
)));
2500 nbytes
= STRING_BYTES (XSTRING (str2
));
2502 ssl
->bytes
+= nbytes
;
2506 /* Return the concatenation of the strings associated with overlays that
2507 begin or end at POS, ignoring overlays that are specific to a window
2508 other than W. The strings are concatenated in the appropriate order:
2509 shorter overlays nest inside longer ones, and higher priority inside
2510 lower. Normally all of the after-strings come first, but zero-sized
2511 overlays have their after-strings ride along with the before-strings
2512 because it would look strange to print them inside-out.
2514 Returns the string length, and stores the contents indirectly through
2515 PSTR, if that variable is non-null. The string may be overwritten by
2516 subsequent calls. */
2519 overlay_strings (pos
, w
, pstr
)
2522 unsigned char **pstr
;
2524 Lisp_Object ov
, overlay
, window
, str
;
2525 int startpos
, endpos
;
2526 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
2528 overlay_heads
.used
= overlay_heads
.bytes
= 0;
2529 overlay_tails
.used
= overlay_tails
.bytes
= 0;
2530 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
2532 overlay
= XCAR (ov
);
2533 if (!OVERLAYP (overlay
))
2536 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2537 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2540 if (endpos
!= pos
&& startpos
!= pos
)
2542 window
= Foverlay_get (overlay
, Qwindow
);
2543 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2546 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2547 record_overlay_string (&overlay_heads
, str
,
2549 ? Foverlay_get (overlay
, Qafter_string
)
2551 Foverlay_get (overlay
, Qpriority
),
2553 else if (endpos
== pos
2554 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2555 record_overlay_string (&overlay_tails
, str
, Qnil
,
2556 Foverlay_get (overlay
, Qpriority
),
2559 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
2561 overlay
= XCAR (ov
);
2562 if (!OVERLAYP (overlay
))
2565 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2566 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2569 if (endpos
!= pos
&& startpos
!= pos
)
2571 window
= Foverlay_get (overlay
, Qwindow
);
2572 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2575 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2576 record_overlay_string (&overlay_heads
, str
,
2578 ? Foverlay_get (overlay
, Qafter_string
)
2580 Foverlay_get (overlay
, Qpriority
),
2582 else if (endpos
== pos
2583 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2584 record_overlay_string (&overlay_tails
, str
, Qnil
,
2585 Foverlay_get (overlay
, Qpriority
),
2588 if (overlay_tails
.used
> 1)
2589 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
2591 if (overlay_heads
.used
> 1)
2592 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
2594 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
2599 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
2601 if (total
> overlay_str_len
)
2603 overlay_str_len
= total
;
2604 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
2607 p
= overlay_str_buf
;
2608 for (i
= overlay_tails
.used
; --i
>= 0;)
2611 tem
= overlay_tails
.buf
[i
].string
;
2612 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2613 STRING_BYTES (XSTRING (tem
)),
2614 STRING_MULTIBYTE (tem
), multibyte
);
2617 for (i
= 0; i
< overlay_heads
.used
; ++i
)
2620 tem
= overlay_heads
.buf
[i
].string
;
2621 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2622 STRING_BYTES (XSTRING (tem
)),
2623 STRING_MULTIBYTE (tem
), multibyte
);
2625 tem
= overlay_heads
.buf
[i
].string2
;
2628 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2629 STRING_BYTES (XSTRING (tem
)),
2630 STRING_MULTIBYTE (tem
), multibyte
);
2634 if (p
!= overlay_str_buf
+ total
)
2637 *pstr
= overlay_str_buf
;
2643 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2646 recenter_overlay_lists (buf
, pos
)
2650 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
2652 /* See if anything in overlays_before should move to overlays_after. */
2654 /* We don't strictly need prev in this loop; it should always be nil.
2655 But we use it for symmetry and in case that should cease to be true
2656 with some future change. */
2658 for (tail
= buf
->overlays_before
;
2660 prev
= tail
, tail
= next
)
2663 overlay
= XCAR (tail
);
2665 /* If the overlay is not valid, get rid of it. */
2666 if (!OVERLAY_VALID (overlay
))
2671 /* Splice the cons cell TAIL out of overlays_before. */
2675 buf
->overlays_before
= next
;
2681 beg
= OVERLAY_START (overlay
);
2682 end
= OVERLAY_END (overlay
);
2684 if (OVERLAY_POSITION (end
) > pos
)
2686 /* OVERLAY needs to be moved. */
2687 int where
= OVERLAY_POSITION (beg
);
2688 Lisp_Object other
, other_prev
;
2690 /* Splice the cons cell TAIL out of overlays_before. */
2694 buf
->overlays_before
= next
;
2696 /* Search thru overlays_after for where to put it. */
2698 for (other
= buf
->overlays_after
;
2700 other_prev
= other
, other
= XCDR (other
))
2702 Lisp_Object otherbeg
, otheroverlay
;
2704 otheroverlay
= XCAR (other
);
2705 if (! OVERLAY_VALID (otheroverlay
))
2708 otherbeg
= OVERLAY_START (otheroverlay
);
2709 if (OVERLAY_POSITION (otherbeg
) >= where
)
2713 /* Add TAIL to overlays_after before OTHER. */
2714 XCDR (tail
) = other
;
2715 if (!NILP (other_prev
))
2716 XCDR (other_prev
) = tail
;
2718 buf
->overlays_after
= tail
;
2722 /* We've reached the things that should stay in overlays_before.
2723 All the rest of overlays_before must end even earlier,
2728 /* See if anything in overlays_after should be in overlays_before. */
2730 for (tail
= buf
->overlays_after
;
2732 prev
= tail
, tail
= next
)
2735 overlay
= XCAR (tail
);
2737 /* If the overlay is not valid, get rid of it. */
2738 if (!OVERLAY_VALID (overlay
))
2743 /* Splice the cons cell TAIL out of overlays_after. */
2747 buf
->overlays_after
= next
;
2753 beg
= OVERLAY_START (overlay
);
2754 end
= OVERLAY_END (overlay
);
2756 /* Stop looking, when we know that nothing further
2757 can possibly end before POS. */
2758 if (OVERLAY_POSITION (beg
) > pos
)
2761 if (OVERLAY_POSITION (end
) <= pos
)
2763 /* OVERLAY needs to be moved. */
2764 int where
= OVERLAY_POSITION (end
);
2765 Lisp_Object other
, other_prev
;
2767 /* Splice the cons cell TAIL out of overlays_after. */
2771 buf
->overlays_after
= next
;
2773 /* Search thru overlays_before for where to put it. */
2775 for (other
= buf
->overlays_before
;
2777 other_prev
= other
, other
= XCDR (other
))
2779 Lisp_Object otherend
, otheroverlay
;
2781 otheroverlay
= XCAR (other
);
2782 if (! OVERLAY_VALID (otheroverlay
))
2785 otherend
= OVERLAY_END (otheroverlay
);
2786 if (OVERLAY_POSITION (otherend
) <= where
)
2790 /* Add TAIL to overlays_before before OTHER. */
2791 XCDR (tail
) = other
;
2792 if (!NILP (other_prev
))
2793 XCDR (other_prev
) = tail
;
2795 buf
->overlays_before
= tail
;
2800 XSETFASTINT (buf
->overlay_center
, pos
);
2804 adjust_overlays_for_insert (pos
, length
)
2808 /* After an insertion, the lists are still sorted properly,
2809 but we may need to update the value of the overlay center. */
2810 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
2811 XSETFASTINT (current_buffer
->overlay_center
,
2812 XFASTINT (current_buffer
->overlay_center
) + length
);
2816 adjust_overlays_for_delete (pos
, length
)
2820 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
2821 /* The deletion was to our right. No change needed; the before- and
2822 after-lists are still consistent. */
2824 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
2825 /* The deletion was to our left. We need to adjust the center value
2826 to account for the change in position, but the lists are consistent
2827 given the new value. */
2828 XSETFASTINT (current_buffer
->overlay_center
,
2829 XFASTINT (current_buffer
->overlay_center
) - length
);
2831 /* We're right in the middle. There might be things on the after-list
2832 that now belong on the before-list. Recentering will move them,
2833 and also update the center point. */
2834 recenter_overlay_lists (current_buffer
, pos
);
2837 /* Fix up overlays that were garbled as a result of permuting markers
2838 in the range START through END. Any overlay with at least one
2839 endpoint in this range will need to be unlinked from the overlay
2840 list and reinserted in its proper place.
2841 Such an overlay might even have negative size at this point.
2842 If so, we'll reverse the endpoints. Can you think of anything
2843 better to do in this situation? */
2845 fix_overlays_in_range (start
, end
)
2846 register int start
, end
;
2848 Lisp_Object overlay
;
2849 Lisp_Object before_list
, after_list
;
2850 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
2851 int startpos
, endpos
;
2853 /* This algorithm shifts links around instead of consing and GCing.
2854 The loop invariant is that before_list (resp. after_list) is a
2855 well-formed list except that its last element, the one that
2856 *pbefore (resp. *pafter) points to, is still uninitialized.
2857 So it's not a bug that before_list isn't initialized, although
2858 it may look strange. */
2859 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
2861 overlay
= XCAR (*ptail
);
2862 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2865 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2867 || (startpos
>= start
&& startpos
< end
))
2869 /* If the overlay is backwards, fix that now. */
2870 if (startpos
> endpos
)
2873 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
2875 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
2877 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2879 /* Add it to the end of the wrong list. Later on,
2880 recenter_overlay_lists will move it to the right place. */
2881 if (endpos
< XINT (current_buffer
->overlay_center
))
2884 pafter
= &XCDR (*ptail
);
2889 pbefore
= &XCDR (*ptail
);
2891 *ptail
= XCDR (*ptail
);
2894 ptail
= &XCDR (*ptail
);
2896 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
2898 overlay
= XCAR (*ptail
);
2899 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2900 if (startpos
>= end
)
2902 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2903 if (startpos
>= start
2904 || (endpos
>= start
&& endpos
< end
))
2906 if (startpos
> endpos
)
2909 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
2911 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
2913 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2915 if (endpos
< XINT (current_buffer
->overlay_center
))
2918 pafter
= &XCDR (*ptail
);
2923 pbefore
= &XCDR (*ptail
);
2925 *ptail
= XCDR (*ptail
);
2928 ptail
= &XCDR (*ptail
);
2931 /* Splice the constructed (wrong) lists into the buffer's lists,
2932 and let the recenter function make it sane again. */
2933 *pbefore
= current_buffer
->overlays_before
;
2934 current_buffer
->overlays_before
= before_list
;
2935 recenter_overlay_lists (current_buffer
,
2936 XINT (current_buffer
->overlay_center
));
2938 *pafter
= current_buffer
->overlays_after
;
2939 current_buffer
->overlays_after
= after_list
;
2940 recenter_overlay_lists (current_buffer
,
2941 XINT (current_buffer
->overlay_center
));
2944 /* We have two types of overlay: the one whose ending marker is
2945 after-insertion-marker (this is the usual case) and the one whose
2946 ending marker is before-insertion-marker. When `overlays_before'
2947 contains overlays of the latter type and the former type in this
2948 order and both overlays end at inserting position, inserting a text
2949 increases only the ending marker of the latter type, which results
2950 in incorrect ordering of `overlays_before'.
2952 This function fixes ordering of overlays in the slot
2953 `overlays_before' of the buffer *BP. Before the insertion, `point'
2954 was at PREV, and now is at POS. */
2957 fix_overlays_before (bp
, prev
, pos
)
2961 Lisp_Object
*tailp
= &bp
->overlays_before
;
2962 Lisp_Object
*right_place
;
2965 /* After the insertion, the several overlays may be in incorrect
2966 order. The possibility is that, in the list `overlays_before',
2967 an overlay which ends at POS appears after an overlay which ends
2968 at PREV. Since POS is greater than PREV, we must fix the
2969 ordering of these overlays, by moving overlays ends at POS before
2970 the overlays ends at PREV. */
2972 /* At first, find a place where disordered overlays should be linked
2973 in. It is where an overlay which end before POS exists. (i.e. an
2974 overlay whose ending marker is after-insertion-marker if disorder
2976 while (!NILP (*tailp
)
2977 && ((end
= OVERLAY_POSITION (OVERLAY_END (XCAR (*tailp
))))
2979 tailp
= &XCDR (*tailp
);
2981 /* If we don't find such an overlay,
2982 or the found one ends before PREV,
2983 or the found one is the last one in the list,
2984 we don't have to fix anything. */
2987 || NILP (XCDR (*tailp
)))
2990 right_place
= tailp
;
2991 tailp
= &XCDR (*tailp
);
2993 /* Now, end position of overlays in the list *TAILP should be before
2994 or equal to PREV. In the loop, an overlay which ends at POS is
2995 moved ahead to the place pointed by RIGHT_PLACE. If we found an
2996 overlay which ends before PREV, the remaining overlays are in
2998 while (!NILP (*tailp
))
3000 end
= OVERLAY_POSITION (OVERLAY_END (XCAR (*tailp
)));
3003 { /* This overlay is disordered. */
3004 Lisp_Object found
= *tailp
;
3006 /* Unlink the found overlay. */
3007 *tailp
= XCDR (found
);
3008 /* Move an overlay at RIGHT_PLACE to the next of the found one. */
3009 XCDR (found
) = *right_place
;
3010 /* Link it into the right place. */
3011 *right_place
= found
;
3013 else if (end
== prev
)
3014 tailp
= &XCDR (*tailp
);
3015 else /* No more disordered overlay. */
3020 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
3021 "Return t if OBJECT is an overlay.")
3025 return (OVERLAYP (object
) ? Qt
: Qnil
);
3028 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
3029 "Create a new overlay with range BEG to END in BUFFER.\n\
3030 If omitted, BUFFER defaults to the current buffer.\n\
3031 BEG and END may be integers or markers.\n\
3032 The fourth arg FRONT-ADVANCE, if non-nil, makes the\n\
3033 front delimiter advance when text is inserted there.\n\
3034 The fifth arg REAR-ADVANCE, if non-nil, makes the\n\
3035 rear delimiter advance when text is inserted there.")
3036 (beg
, end
, buffer
, front_advance
, rear_advance
)
3037 Lisp_Object beg
, end
, buffer
;
3038 Lisp_Object front_advance
, rear_advance
;
3040 Lisp_Object overlay
;
3044 XSETBUFFER (buffer
, current_buffer
);
3046 CHECK_BUFFER (buffer
, 2);
3048 && ! EQ (Fmarker_buffer (beg
), buffer
))
3049 error ("Marker points into wrong buffer");
3051 && ! EQ (Fmarker_buffer (end
), buffer
))
3052 error ("Marker points into wrong buffer");
3054 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
3055 CHECK_NUMBER_COERCE_MARKER (end
, 1);
3057 if (XINT (beg
) > XINT (end
))
3060 temp
= beg
; beg
= end
; end
= temp
;
3063 b
= XBUFFER (buffer
);
3065 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
3066 end
= Fset_marker (Fmake_marker (), end
, buffer
);
3068 if (!NILP (front_advance
))
3069 XMARKER (beg
)->insertion_type
= 1;
3070 if (!NILP (rear_advance
))
3071 XMARKER (end
)->insertion_type
= 1;
3073 overlay
= allocate_misc ();
3074 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
3075 XOVERLAY (overlay
)->start
= beg
;
3076 XOVERLAY (overlay
)->end
= end
;
3077 XOVERLAY (overlay
)->plist
= Qnil
;
3079 /* Put the new overlay on the wrong list. */
3080 end
= OVERLAY_END (overlay
);
3081 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
3082 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
3084 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
3086 /* This puts it in the right list, and in the right order. */
3087 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
3089 /* We don't need to redisplay the region covered by the overlay, because
3090 the overlay has no properties at the moment. */
3095 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3098 modify_overlay (buf
, start
, end
)
3108 start
= end
; end
= temp
;
3111 BUF_COMPUTE_UNCHANGED (buf
, start
, end
);
3113 /* If this is a buffer not in the selected window,
3114 we must do other windows. */
3115 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
3116 windows_or_buffers_changed
= 1;
3117 /* If multiple windows show this buffer, we must do other windows. */
3118 else if (buffer_shared
> 1)
3119 windows_or_buffers_changed
= 1;
3121 ++BUF_OVERLAY_MODIFF (buf
);
3125 Lisp_Object
Fdelete_overlay ();
3127 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
3128 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
3129 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
3130 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
3132 (overlay
, beg
, end
, buffer
)
3133 Lisp_Object overlay
, beg
, end
, buffer
;
3135 struct buffer
*b
, *ob
;
3136 Lisp_Object obuffer
;
3137 int count
= specpdl_ptr
- specpdl
;
3139 CHECK_OVERLAY (overlay
, 0);
3141 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3143 XSETBUFFER (buffer
, current_buffer
);
3144 CHECK_BUFFER (buffer
, 3);
3147 && ! EQ (Fmarker_buffer (beg
), buffer
))
3148 error ("Marker points into wrong buffer");
3150 && ! EQ (Fmarker_buffer (end
), buffer
))
3151 error ("Marker points into wrong buffer");
3153 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
3154 CHECK_NUMBER_COERCE_MARKER (end
, 1);
3156 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3157 return Fdelete_overlay (overlay
);
3159 if (XINT (beg
) > XINT (end
))
3162 temp
= beg
; beg
= end
; end
= temp
;
3165 specbind (Qinhibit_quit
, Qt
);
3167 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3168 b
= XBUFFER (buffer
);
3169 ob
= XBUFFER (obuffer
);
3171 /* If the overlay has changed buffers, do a thorough redisplay. */
3172 if (!EQ (buffer
, obuffer
))
3174 /* Redisplay where the overlay was. */
3175 if (!NILP (obuffer
))
3180 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3181 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3183 modify_overlay (ob
, o_beg
, o_end
);
3186 /* Redisplay where the overlay is going to be. */
3187 modify_overlay (b
, XINT (beg
), XINT (end
));
3190 /* Redisplay the area the overlay has just left, or just enclosed. */
3194 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3195 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3197 if (o_beg
== XINT (beg
))
3198 modify_overlay (b
, o_end
, XINT (end
));
3199 else if (o_end
== XINT (end
))
3200 modify_overlay (b
, o_beg
, XINT (beg
));
3203 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
3204 if (XINT (end
) > o_end
) o_end
= XINT (end
);
3205 modify_overlay (b
, o_beg
, o_end
);
3209 if (!NILP (obuffer
))
3211 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
3212 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
3215 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
3216 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
3218 /* Put the overlay on the wrong list. */
3219 end
= OVERLAY_END (overlay
);
3220 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
3221 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
3223 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
3225 /* This puts it in the right list, and in the right order. */
3226 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
3228 return unbind_to (count
, overlay
);
3231 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
3232 "Delete the overlay OVERLAY from its buffer.")
3234 Lisp_Object overlay
;
3238 int count
= specpdl_ptr
- specpdl
;
3240 CHECK_OVERLAY (overlay
, 0);
3242 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3246 b
= XBUFFER (buffer
);
3248 specbind (Qinhibit_quit
, Qt
);
3250 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
3251 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
3254 marker_position (OVERLAY_START (overlay
)),
3255 marker_position (OVERLAY_END (overlay
)));
3257 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
3258 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
3260 return unbind_to (count
, Qnil
);
3263 /* Overlay dissection functions. */
3265 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3266 "Return the position at which OVERLAY starts.")
3268 Lisp_Object overlay
;
3270 CHECK_OVERLAY (overlay
, 0);
3272 return (Fmarker_position (OVERLAY_START (overlay
)));
3275 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3276 "Return the position at which OVERLAY ends.")
3278 Lisp_Object overlay
;
3280 CHECK_OVERLAY (overlay
, 0);
3282 return (Fmarker_position (OVERLAY_END (overlay
)));
3285 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3286 "Return the buffer OVERLAY belongs to.")
3288 Lisp_Object overlay
;
3290 CHECK_OVERLAY (overlay
, 0);
3292 return Fmarker_buffer (OVERLAY_START (overlay
));
3295 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3296 "Return a list of the properties on OVERLAY.\n\
3297 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
3300 Lisp_Object overlay
;
3302 CHECK_OVERLAY (overlay
, 0);
3304 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3308 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3309 "Return a list of the overlays that contain position POS.")
3314 Lisp_Object
*overlay_vec
;
3318 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3321 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3323 /* Put all the overlays we want in a vector in overlay_vec.
3324 Store the length in len. */
3325 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3326 (int *) 0, (int *) 0);
3328 /* Make a list of them all. */
3329 result
= Flist (noverlays
, overlay_vec
);
3331 xfree (overlay_vec
);
3335 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3336 "Return a list of the overlays that overlap the region BEG ... END.\n\
3337 Overlap means that at least one character is contained within the overlay\n\
3338 and also contained within the specified region.\n\
3339 Empty overlays are included in the result if they are located at BEG\n\
3340 or between BEG and END.")
3342 Lisp_Object beg
, end
;
3345 Lisp_Object
*overlay_vec
;
3349 CHECK_NUMBER_COERCE_MARKER (beg
, 0);
3350 CHECK_NUMBER_COERCE_MARKER (end
, 0);
3353 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3355 /* Put all the overlays we want in a vector in overlay_vec.
3356 Store the length in len. */
3357 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3358 (int *) 0, (int *) 0);
3360 /* Make a list of them all. */
3361 result
= Flist (noverlays
, overlay_vec
);
3363 xfree (overlay_vec
);
3367 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3369 "Return the next position after POS where an overlay starts or ends.\n\
3370 If there are no more overlay boundaries after POS, return (point-max).")
3376 Lisp_Object
*overlay_vec
;
3380 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3383 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3385 /* Put all the overlays we want in a vector in overlay_vec.
3386 Store the length in len.
3387 endpos gets the position where the next overlay starts. */
3388 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3389 &endpos
, (int *) 0);
3391 /* If any of these overlays ends before endpos,
3392 use its ending point instead. */
3393 for (i
= 0; i
< noverlays
; i
++)
3398 oend
= OVERLAY_END (overlay_vec
[i
]);
3399 oendpos
= OVERLAY_POSITION (oend
);
3400 if (oendpos
< endpos
)
3404 xfree (overlay_vec
);
3405 return make_number (endpos
);
3408 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
3409 Sprevious_overlay_change
, 1, 1, 0,
3410 "Return the previous position before POS where an overlay starts or ends.\n\
3411 If there are no more overlay boundaries before POS, return (point-min).")
3417 Lisp_Object
*overlay_vec
;
3420 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3423 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3425 /* At beginning of buffer, we know the answer;
3426 avoid bug subtracting 1 below. */
3427 if (XINT (pos
) == BEGV
)
3430 /* Put all the overlays we want in a vector in overlay_vec.
3431 Store the length in len.
3432 prevpos gets the position of the previous change. */
3433 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3434 (int *) 0, &prevpos
);
3436 xfree (overlay_vec
);
3437 return make_number (prevpos
);
3440 /* These functions are for debugging overlays. */
3442 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
3443 "Return a pair of lists giving all the overlays of the current buffer.\n\
3444 The car has all the overlays before the overlay center;\n\
3445 the cdr has all the overlays after the overlay center.\n\
3446 Recentering overlays moves overlays between these lists.\n\
3447 The lists you get are copies, so that changing them has no effect.\n\
3448 However, the overlays you get are the real objects that the buffer uses.")
3451 Lisp_Object before
, after
;
3452 before
= current_buffer
->overlays_before
;
3454 before
= Fcopy_sequence (before
);
3455 after
= current_buffer
->overlays_after
;
3457 after
= Fcopy_sequence (after
);
3459 return Fcons (before
, after
);
3462 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
3463 "Recenter the overlays of the current buffer around position POS.")
3467 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3469 recenter_overlay_lists (current_buffer
, XINT (pos
));
3473 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
3474 "Get the property of overlay OVERLAY with property name PROP.")
3476 Lisp_Object overlay
, prop
;
3478 Lisp_Object plist
, fallback
;
3480 CHECK_OVERLAY (overlay
, 0);
3484 for (plist
= XOVERLAY (overlay
)->plist
;
3485 CONSP (plist
) && CONSP (XCDR (plist
));
3486 plist
= XCDR (XCDR (plist
)))
3488 if (EQ (XCAR (plist
), prop
))
3489 return XCAR (XCDR (plist
));
3490 else if (EQ (XCAR (plist
), Qcategory
))
3493 tem
= Fcar (Fcdr (plist
));
3495 fallback
= Fget (tem
, prop
);
3502 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
3503 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
3504 (overlay
, prop
, value
)
3505 Lisp_Object overlay
, prop
, value
;
3507 Lisp_Object tail
, buffer
;
3510 CHECK_OVERLAY (overlay
, 0);
3512 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3514 for (tail
= XOVERLAY (overlay
)->plist
;
3515 CONSP (tail
) && CONSP (XCDR (tail
));
3516 tail
= XCDR (XCDR (tail
)))
3517 if (EQ (XCAR (tail
), prop
))
3519 changed
= !EQ (XCAR (XCDR (tail
)), value
);
3520 XCAR (XCDR (tail
)) = value
;
3523 /* It wasn't in the list, so add it to the front. */
3524 changed
= !NILP (value
);
3525 XOVERLAY (overlay
)->plist
3526 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
3528 if (! NILP (buffer
))
3531 modify_overlay (XBUFFER (buffer
),
3532 marker_position (OVERLAY_START (overlay
)),
3533 marker_position (OVERLAY_END (overlay
)));
3534 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
3535 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
3536 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
3537 Fdelete_overlay (overlay
);
3542 /* Subroutine of report_overlay_modification. */
3544 /* Lisp vector holding overlay hook functions to call.
3545 Vector elements come in pairs.
3546 Each even-index element is a list of hook functions.
3547 The following odd-index element is the overlay they came from.
3549 Before the buffer change, we fill in this vector
3550 as we call overlay hook functions.
3551 After the buffer change, we get the functions to call from this vector.
3552 This way we always call the same functions before and after the change. */
3553 static Lisp_Object last_overlay_modification_hooks
;
3555 /* Number of elements actually used in last_overlay_modification_hooks. */
3556 static int last_overlay_modification_hooks_used
;
3558 /* Add one functionlist/overlay pair
3559 to the end of last_overlay_modification_hooks. */
3562 add_overlay_mod_hooklist (functionlist
, overlay
)
3563 Lisp_Object functionlist
, overlay
;
3565 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
3567 if (last_overlay_modification_hooks_used
== oldsize
)
3570 old
= last_overlay_modification_hooks
;
3571 last_overlay_modification_hooks
3572 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
3573 bcopy (XVECTOR (old
)->contents
,
3574 XVECTOR (last_overlay_modification_hooks
)->contents
,
3575 sizeof (Lisp_Object
) * oldsize
);
3577 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = functionlist
;
3578 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = overlay
;
3581 /* Run the modification-hooks of overlays that include
3582 any part of the text in START to END.
3583 If this change is an insertion, also
3584 run the insert-before-hooks of overlay starting at END,
3585 and the insert-after-hooks of overlay ending at START.
3587 This is called both before and after the modification.
3588 AFTER is nonzero when we call after the modification.
3590 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3591 When AFTER is nonzero, they are the start position,
3592 the position after the inserted new text,
3593 and the length of deleted or replaced old text. */
3596 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
3597 Lisp_Object start
, end
;
3599 Lisp_Object arg1
, arg2
, arg3
;
3601 Lisp_Object prop
, overlay
, tail
;
3602 /* 1 if this change is an insertion. */
3603 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
3605 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
3609 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
3613 /* Call the functions recorded in last_overlay_modification_hooks
3614 rather than scanning the overlays again.
3615 First copy the vector contents, in case some of these hooks
3616 do subsequent modification of the buffer. */
3617 int size
= last_overlay_modification_hooks_used
;
3618 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
3621 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
3622 copy
, size
* sizeof (Lisp_Object
));
3624 gcpro1
.nvars
= size
;
3626 for (i
= 0; i
< size
;)
3628 Lisp_Object prop
, overlay
;
3630 overlay
= copy
[i
++];
3631 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3637 /* We are being called before a change.
3638 Scan the overlays to find the functions to call. */
3639 last_overlay_modification_hooks_used
= 0;
3641 for (tail
= current_buffer
->overlays_before
;
3645 int startpos
, endpos
;
3646 Lisp_Object ostart
, oend
;
3648 overlay
= XCAR (tail
);
3650 ostart
= OVERLAY_START (overlay
);
3651 oend
= OVERLAY_END (overlay
);
3652 endpos
= OVERLAY_POSITION (oend
);
3653 if (XFASTINT (start
) > endpos
)
3655 startpos
= OVERLAY_POSITION (ostart
);
3656 if (insertion
&& (XFASTINT (start
) == startpos
3657 || XFASTINT (end
) == startpos
))
3659 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3662 /* Copy TAIL in case the hook recenters the overlay lists. */
3664 tail
= Fcopy_sequence (tail
);
3666 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3669 if (insertion
&& (XFASTINT (start
) == endpos
3670 || XFASTINT (end
) == endpos
))
3672 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3676 tail
= Fcopy_sequence (tail
);
3678 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3681 /* Test for intersecting intervals. This does the right thing
3682 for both insertion and deletion. */
3683 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3685 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3689 tail
= Fcopy_sequence (tail
);
3691 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3697 for (tail
= current_buffer
->overlays_after
;
3701 int startpos
, endpos
;
3702 Lisp_Object ostart
, oend
;
3704 overlay
= XCAR (tail
);
3706 ostart
= OVERLAY_START (overlay
);
3707 oend
= OVERLAY_END (overlay
);
3708 startpos
= OVERLAY_POSITION (ostart
);
3709 endpos
= OVERLAY_POSITION (oend
);
3710 if (XFASTINT (end
) < startpos
)
3712 if (insertion
&& (XFASTINT (start
) == startpos
3713 || XFASTINT (end
) == startpos
))
3715 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3719 tail
= Fcopy_sequence (tail
);
3721 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3724 if (insertion
&& (XFASTINT (start
) == endpos
3725 || XFASTINT (end
) == endpos
))
3727 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3731 tail
= Fcopy_sequence (tail
);
3733 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3736 /* Test for intersecting intervals. This does the right thing
3737 for both insertion and deletion. */
3738 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3740 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3744 tail
= Fcopy_sequence (tail
);
3746 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3755 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
3756 Lisp_Object list
, overlay
;
3758 Lisp_Object arg1
, arg2
, arg3
;
3760 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3762 GCPRO4 (list
, arg1
, arg2
, arg3
);
3764 add_overlay_mod_hooklist (list
, overlay
);
3766 while (!NILP (list
))
3769 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
3771 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
3777 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3780 evaporate_overlays (pos
)
3783 Lisp_Object tail
, overlay
, hit_list
;
3786 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
3787 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
3791 overlay
= XCAR (tail
);
3792 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3795 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
3796 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3797 hit_list
= Fcons (overlay
, hit_list
);
3800 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
3804 overlay
= XCAR (tail
);
3805 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3808 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
3809 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3810 hit_list
= Fcons (overlay
, hit_list
);
3812 for (; CONSP (hit_list
); hit_list
= XCDR (hit_list
))
3813 Fdelete_overlay (XCAR (hit_list
));
3816 /* Somebody has tried to store a value with an unacceptable type
3817 in the slot with offset OFFSET. */
3820 buffer_slot_type_mismatch (offset
)
3825 sym
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
);
3826 switch (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
)))
3828 case Lisp_Int
: type_name
= "integers"; break;
3829 case Lisp_String
: type_name
= "strings"; break;
3830 case Lisp_Symbol
: type_name
= "symbols"; break;
3836 error ("Only %s should be stored in the buffer-local variable %s",
3837 type_name
, XSYMBOL (sym
)->name
->data
);
3843 buffer_permanent_local_flags
= 0;
3845 /* Make sure all markable slots in buffer_defaults
3846 are initialized reasonably, so mark_buffer won't choke. */
3847 reset_buffer (&buffer_defaults
);
3848 reset_buffer_local_variables (&buffer_defaults
, 1);
3849 reset_buffer (&buffer_local_symbols
);
3850 reset_buffer_local_variables (&buffer_local_symbols
, 1);
3851 /* Prevent GC from getting confused. */
3852 buffer_defaults
.text
= &buffer_defaults
.own_text
;
3853 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
3854 BUF_INTERVALS (&buffer_defaults
) = 0;
3855 BUF_INTERVALS (&buffer_local_symbols
) = 0;
3856 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
3857 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
3859 /* Set up the default values of various buffer slots. */
3860 /* Must do these before making the first buffer! */
3862 /* real setup is done in loaddefs.el */
3863 buffer_defaults
.mode_line_format
= build_string ("%-");
3864 buffer_defaults
.header_line_format
= Qnil
;
3865 buffer_defaults
.abbrev_mode
= Qnil
;
3866 buffer_defaults
.overwrite_mode
= Qnil
;
3867 buffer_defaults
.case_fold_search
= Qt
;
3868 buffer_defaults
.auto_fill_function
= Qnil
;
3869 buffer_defaults
.selective_display
= Qnil
;
3871 buffer_defaults
.selective_display_ellipses
= Qt
;
3873 buffer_defaults
.abbrev_table
= Qnil
;
3874 buffer_defaults
.display_table
= Qnil
;
3875 buffer_defaults
.undo_list
= Qnil
;
3876 buffer_defaults
.mark_active
= Qnil
;
3877 buffer_defaults
.file_format
= Qnil
;
3878 buffer_defaults
.overlays_before
= Qnil
;
3879 buffer_defaults
.overlays_after
= Qnil
;
3880 XSETFASTINT (buffer_defaults
.overlay_center
, BEG
);
3882 XSETFASTINT (buffer_defaults
.tab_width
, 8);
3883 buffer_defaults
.truncate_lines
= Qnil
;
3884 buffer_defaults
.ctl_arrow
= Qt
;
3885 buffer_defaults
.direction_reversed
= Qnil
;
3888 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
3890 buffer_defaults
.enable_multibyte_characters
= Qt
;
3891 buffer_defaults
.buffer_file_coding_system
= Qnil
;
3892 XSETFASTINT (buffer_defaults
.fill_column
, 70);
3893 XSETFASTINT (buffer_defaults
.left_margin
, 0);
3894 buffer_defaults
.cache_long_line_scans
= Qnil
;
3895 buffer_defaults
.file_truename
= Qnil
;
3896 XSETFASTINT (buffer_defaults
.display_count
, 0);
3897 buffer_defaults
.indicate_empty_lines
= Qnil
;
3898 buffer_defaults
.scroll_up_aggressively
= Qnil
;
3899 buffer_defaults
.scroll_down_aggressively
= Qnil
;
3900 buffer_defaults
.display_time
= Qnil
;
3902 /* Assign the local-flags to the slots that have default values.
3903 The local flag is a bit that is used in the buffer
3904 to say that it has its own local value for the slot.
3905 The local flag bits are in the local_var_flags slot of the buffer. */
3907 /* Nothing can work if this isn't true */
3908 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
3910 /* 0 means not a lisp var, -1 means always local, else mask */
3911 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
3912 XSETINT (buffer_local_flags
.filename
, -1);
3913 XSETINT (buffer_local_flags
.directory
, -1);
3914 XSETINT (buffer_local_flags
.backed_up
, -1);
3915 XSETINT (buffer_local_flags
.save_length
, -1);
3916 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
3917 XSETINT (buffer_local_flags
.read_only
, -1);
3918 XSETINT (buffer_local_flags
.major_mode
, -1);
3919 XSETINT (buffer_local_flags
.mode_name
, -1);
3920 XSETINT (buffer_local_flags
.undo_list
, -1);
3921 XSETINT (buffer_local_flags
.mark_active
, -1);
3922 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
3923 XSETINT (buffer_local_flags
.file_truename
, -1);
3924 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
3925 XSETINT (buffer_local_flags
.file_format
, -1);
3926 XSETINT (buffer_local_flags
.display_count
, -1);
3927 XSETINT (buffer_local_flags
.display_time
, -1);
3928 XSETINT (buffer_local_flags
.enable_multibyte_characters
, -1);
3930 XSETFASTINT (buffer_local_flags
.mode_line_format
, 1);
3931 XSETFASTINT (buffer_local_flags
.abbrev_mode
, 2);
3932 XSETFASTINT (buffer_local_flags
.overwrite_mode
, 4);
3933 XSETFASTINT (buffer_local_flags
.case_fold_search
, 8);
3934 XSETFASTINT (buffer_local_flags
.auto_fill_function
, 0x10);
3935 XSETFASTINT (buffer_local_flags
.selective_display
, 0x20);
3937 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, 0x40);
3939 XSETFASTINT (buffer_local_flags
.tab_width
, 0x80);
3940 XSETFASTINT (buffer_local_flags
.truncate_lines
, 0x100);
3941 XSETFASTINT (buffer_local_flags
.ctl_arrow
, 0x200);
3942 XSETFASTINT (buffer_local_flags
.fill_column
, 0x400);
3943 XSETFASTINT (buffer_local_flags
.left_margin
, 0x800);
3944 XSETFASTINT (buffer_local_flags
.abbrev_table
, 0x1000);
3945 XSETFASTINT (buffer_local_flags
.display_table
, 0x2000);
3947 XSETFASTINT (buffer_local_flags
.buffer_file_type
, 0x4000);
3948 /* Make this one a permanent local. */
3949 buffer_permanent_local_flags
|= 0x4000;
3951 XSETFASTINT (buffer_local_flags
.syntax_table
, 0x8000);
3952 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, 0x10000);
3953 XSETFASTINT (buffer_local_flags
.category_table
, 0x20000);
3954 XSETFASTINT (buffer_local_flags
.direction_reversed
, 0x40000);
3955 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, 0x80000);
3956 /* Make this one a permanent local. */
3957 buffer_permanent_local_flags
|= 0x80000;
3958 XSETFASTINT (buffer_local_flags
.left_margin_width
, 0x100000);
3959 XSETFASTINT (buffer_local_flags
.right_margin_width
, 0x200000);
3960 XSETFASTINT (buffer_local_flags
.indicate_empty_lines
, 0x400000);
3961 XSETFASTINT (buffer_local_flags
.scroll_up_aggressively
, 0x800000);
3962 XSETFASTINT (buffer_local_flags
.scroll_down_aggressively
, 0x1000000);
3963 XSETFASTINT (buffer_local_flags
.header_line_format
, 0x2000000);
3965 Vbuffer_alist
= Qnil
;
3969 QSFundamental
= build_string ("Fundamental");
3971 Qfundamental_mode
= intern ("fundamental-mode");
3972 buffer_defaults
.major_mode
= Qfundamental_mode
;
3974 Qmode_class
= intern ("mode-class");
3976 Qprotected_field
= intern ("protected-field");
3978 Qpermanent_local
= intern ("permanent-local");
3980 Qkill_buffer_hook
= intern ("kill-buffer-hook");
3982 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
3984 /* super-magic invisible buffer */
3985 Vbuffer_alist
= Qnil
;
3987 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3989 inhibit_modification_hooks
= 0;
3995 char buf
[MAXPATHLEN
+1];
3997 struct stat dotstat
, pwdstat
;
4001 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
4002 if (NILP (buffer_defaults
.enable_multibyte_characters
))
4003 Fset_buffer_multibyte (Qnil
);
4005 /* If PWD is accurate, use it instead of calling getwd. This is faster
4006 when PWD is right, and may avoid a fatal error. */
4007 if ((pwd
= getenv ("PWD")) != 0
4008 && (IS_DIRECTORY_SEP (*pwd
) || (*pwd
&& IS_DEVICE_SEP (pwd
[1])))
4009 && stat (pwd
, &pwdstat
) == 0
4010 && stat (".", &dotstat
) == 0
4011 && dotstat
.st_ino
== pwdstat
.st_ino
4012 && dotstat
.st_dev
== pwdstat
.st_dev
4013 && strlen (pwd
) < MAXPATHLEN
)
4016 else if (getcwd (buf
, MAXPATHLEN
+1) == 0)
4017 fatal ("`getcwd' failed: %s\n", strerror (errno
));
4019 else if (getwd (buf
) == 0)
4020 fatal ("`getwd' failed: %s\n", buf
);
4024 /* Maybe this should really use some standard subroutine
4025 whose definition is filename syntax dependent. */
4027 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
4029 buf
[rc
] = DIRECTORY_SEP
;
4032 #endif /* not VMS */
4034 current_buffer
->directory
= build_string (buf
);
4036 /* Add /: to the front of the name
4037 if it would otherwise be treated as magic. */
4038 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
4040 /* If the default dir is just /, TEMP is non-nil
4041 because of the ange-ftp completion handler.
4042 However, it is not necessary to turn / into /:/.
4043 So avoid doing that. */
4044 && strcmp ("/", XSTRING (current_buffer
->directory
)->data
))
4045 current_buffer
->directory
4046 = concat2 (build_string ("/:"), current_buffer
->directory
);
4048 temp
= get_minibuffer (0);
4049 XBUFFER (temp
)->directory
= current_buffer
->directory
;
4052 /* initialize the buffer routines */
4056 staticpro (&last_overlay_modification_hooks
);
4057 last_overlay_modification_hooks
4058 = Fmake_vector (make_number (10), Qnil
);
4060 staticpro (&Vbuffer_defaults
);
4061 staticpro (&Vbuffer_local_symbols
);
4062 staticpro (&Qfundamental_mode
);
4063 staticpro (&Qmode_class
);
4064 staticpro (&QSFundamental
);
4065 staticpro (&Vbuffer_alist
);
4066 staticpro (&Qprotected_field
);
4067 staticpro (&Qpermanent_local
);
4068 staticpro (&Qkill_buffer_hook
);
4069 Qoverlayp
= intern ("overlayp");
4070 staticpro (&Qoverlayp
);
4071 Qevaporate
= intern ("evaporate");
4072 staticpro (&Qevaporate
);
4073 Qmodification_hooks
= intern ("modification-hooks");
4074 staticpro (&Qmodification_hooks
);
4075 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
4076 staticpro (&Qinsert_in_front_hooks
);
4077 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
4078 staticpro (&Qinsert_behind_hooks
);
4079 Qget_file_buffer
= intern ("get-file-buffer");
4080 staticpro (&Qget_file_buffer
);
4081 Qpriority
= intern ("priority");
4082 staticpro (&Qpriority
);
4083 Qwindow
= intern ("window");
4084 staticpro (&Qwindow
);
4085 Qbefore_string
= intern ("before-string");
4086 staticpro (&Qbefore_string
);
4087 Qafter_string
= intern ("after-string");
4088 staticpro (&Qafter_string
);
4089 Qfirst_change_hook
= intern ("first-change-hook");
4090 staticpro (&Qfirst_change_hook
);
4091 Qbefore_change_functions
= intern ("before-change-functions");
4092 staticpro (&Qbefore_change_functions
);
4093 Qafter_change_functions
= intern ("after-change-functions");
4094 staticpro (&Qafter_change_functions
);
4096 Fput (Qprotected_field
, Qerror_conditions
,
4097 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
4098 Fput (Qprotected_field
, Qerror_message
,
4099 build_string ("Attempt to modify a protected field"));
4101 /* All these use DEFVAR_LISP_NOPRO because the slots in
4102 buffer_defaults will all be marked via Vbuffer_defaults. */
4104 DEFVAR_LISP_NOPRO ("default-mode-line-format",
4105 &buffer_defaults
.mode_line_format
,
4106 "Default value of `mode-line-format' for buffers that don't override it.\n\
4107 This is the same as (default-value 'mode-line-format).");
4109 DEFVAR_LISP_NOPRO ("default-header-line-format",
4110 &buffer_defaults
.header_line_format
,
4111 "Default value of `header-line-format' for buffers that don't override it.\n\
4112 This is the same as (default-value 'header-line-format).");
4114 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
4115 &buffer_defaults
.abbrev_mode
,
4116 "Default value of `abbrev-mode' for buffers that do not override it.\n\
4117 This is the same as (default-value 'abbrev-mode).");
4119 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
4120 &buffer_defaults
.ctl_arrow
,
4121 "Default value of `ctl-arrow' for buffers that do not override it.\n\
4122 This is the same as (default-value 'ctl-arrow).");
4124 DEFVAR_LISP_NOPRO ("default-direction-reversed",
4125 &buffer_defaults
.direction_reversed
,
4126 "Default value of `direction_reversed' for buffers that do not override it.\n\
4127 This is the same as (default-value 'direction-reversed).");
4129 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
4130 &buffer_defaults
.enable_multibyte_characters
,
4131 "*Default value of `enable-multibyte-characters' for buffers not overriding it.\n\
4132 This is the same as (default-value 'enable-multibyte-characters).");
4134 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
4135 &buffer_defaults
.buffer_file_coding_system
,
4136 "Default value of `buffer-file-coding-system' for buffers not overriding it.\n\
4137 This is the same as (default-value 'buffer-file-coding-system).");
4139 DEFVAR_LISP_NOPRO ("default-truncate-lines",
4140 &buffer_defaults
.truncate_lines
,
4141 "Default value of `truncate-lines' for buffers that do not override it.\n\
4142 This is the same as (default-value 'truncate-lines).");
4144 DEFVAR_LISP_NOPRO ("default-fill-column",
4145 &buffer_defaults
.fill_column
,
4146 "Default value of `fill-column' for buffers that do not override it.\n\
4147 This is the same as (default-value 'fill-column).");
4149 DEFVAR_LISP_NOPRO ("default-left-margin",
4150 &buffer_defaults
.left_margin
,
4151 "Default value of `left-margin' for buffers that do not override it.\n\
4152 This is the same as (default-value 'left-margin).");
4154 DEFVAR_LISP_NOPRO ("default-tab-width",
4155 &buffer_defaults
.tab_width
,
4156 "Default value of `tab-width' for buffers that do not override it.\n\
4157 This is the same as (default-value 'tab-width).");
4159 DEFVAR_LISP_NOPRO ("default-case-fold-search",
4160 &buffer_defaults
.case_fold_search
,
4161 "Default value of `case-fold-search' for buffers that don't override it.\n\
4162 This is the same as (default-value 'case-fold-search).");
4165 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
4166 &buffer_defaults
.buffer_file_type
,
4167 "Default file type for buffers that do not override it.\n\
4168 This is the same as (default-value 'buffer-file-type).\n\
4169 The file type is nil for text, t for binary.");
4172 DEFVAR_LISP_NOPRO ("default-left-margin-width",
4173 &buffer_defaults
.left_margin_width
,
4174 "Default value of `left-margin-width' for buffers that don't override it.\n\
4175 This is the same as (default-value 'left-margin-width).");
4177 DEFVAR_LISP_NOPRO ("default-right-margin-width",
4178 &buffer_defaults
.right_margin_width
,
4179 "Default value of `right_margin_width' for buffers that don't override it.\n\
4180 This is the same as (default-value 'right-margin-width).");
4182 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines",
4183 &buffer_defaults
.indicate_empty_lines
,
4184 "Default value of `indicate-empty-lines' for buffers that don't override it.\n\
4185 This is the same as (default-value 'indicate-empty-lines).");
4187 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively",
4188 &buffer_defaults
.scroll_up_aggressively
,
4189 "Default value of `scroll-up-aggressively' for buffers that\n\
4190 don't override it. This is the same as (default-value\n\
4191 'scroll-up-aggressively).");
4193 DEFVAR_LISP_NOPRO ("default-scroll-down-aggressively",
4194 &buffer_defaults
.scroll_down_aggressively
,
4195 "Default value of `scroll-down-aggressively' for buffers that\n\
4196 don't override it. This is the same as (default-value\n\
4197 'scroll-down-aggressively).");
4199 DEFVAR_PER_BUFFER ("header-line-format",
4200 ¤t_buffer
->header_line_format
,
4202 "Analogous to `mode-line-format', but for a mode line displayed\n\
4203 at the top of windows.");
4205 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
4208 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
4209 But make-docfile finds it!
4210 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
4212 "Template for displaying mode line for current buffer.\n\
4213 Each buffer has its own value of this variable.\n\
4214 Value may be nil, a string, a symbol or a list or cons cell.\n\
4215 A value of nil means don't display a mode line.\n\
4216 For a symbol, its value is used (but it is ignored if t or nil).\n\
4217 A string appearing directly as the value of a symbol is processed verbatim\n\
4218 in that the %-constructs below are not recognized.\n\
4219 For a list of the form `(:eval FORM)', FORM is evaluated and the result\n\
4220 is used as a mode line element.\n\
4221 For a list whose car is a symbol, the symbol's value is taken,\n\
4222 and if that is non-nil, the cadr of the list is processed recursively.\n\
4223 Otherwise, the caddr of the list (if there is one) is processed.\n\
4224 For a list whose car is a string or list, each element is processed\n\
4225 recursively and the results are effectively concatenated.\n\
4226 For a list whose car is an integer, the cdr of the list is processed\n\
4227 and padded (if the number is positive) or truncated (if negative)\n\
4228 to the width specified by that number.\n\
4229 A string is printed verbatim in the mode line except for %-constructs:\n\
4230 (%-constructs are allowed when the string is the entire mode-line-format\n\
4231 or when it is found in a cons-cell or a list)\n\
4232 %b -- print buffer name. %f -- print visited file name.\n\
4233 %F -- print frame name.\n\
4234 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
4235 %& is like %*, but ignore read-only-ness.\n\
4236 % means buffer is read-only and * means it is modified.\n\
4237 For a modified read-only buffer, %* gives % and %+ gives *.\n\
4238 %s -- print process status. %l -- print the current line number.\n\
4239 %c -- print the current column number (this makes editing slower).\n\
4240 To make the column number update correctly in all cases,\n\
4241 `column-number-mode' must be non-nil.\n\
4242 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
4243 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
4244 or print Bottom or All.\n\
4245 %m -- print the mode name.\n\
4246 %n -- print Narrow if appropriate.\n\
4247 %z -- print mnemonics of buffer, terminal, and keyboard coding systems.\n\
4248 %Z -- like %z, but including the end-of-line format.\n\
4249 %[ -- print one [ for each recursive editing level. %] similar.\n\
4250 %% -- print %. %- -- print infinitely many dashes.\n\
4251 Decimal digits after the % specify field width to which to pad.");
4254 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
4255 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
4256 nil here means use current buffer's major mode.");
4258 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
4259 make_number (Lisp_Symbol
),
4260 "Symbol for current buffer's major mode.");
4262 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
4263 make_number (Lisp_String
),
4264 "Pretty name of current buffer's major mode (a string).");
4266 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
4267 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
4268 Automatically becomes buffer-local when set in any fashion.");
4270 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
4272 "*Non-nil if searches and matches should ignore case.\n\
4273 Automatically becomes buffer-local when set in any fashion.");
4275 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
4276 make_number (Lisp_Int
),
4277 "*Column beyond which automatic line-wrapping should happen.\n\
4278 Automatically becomes buffer-local when set in any fashion.");
4280 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
4281 make_number (Lisp_Int
),
4282 "*Column for the default indent-line-function to indent to.\n\
4283 Linefeed indents to this column in Fundamental mode.\n\
4284 Automatically becomes buffer-local when set in any fashion.");
4286 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
4287 make_number (Lisp_Int
),
4288 "*Distance between tab stops (for display of tab characters), in columns.\n\
4289 Automatically becomes buffer-local when set in any fashion.");
4291 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
4292 "*Non-nil means display control chars with uparrow.\n\
4293 A value of nil means use backslash and octal digits.\n\
4294 Automatically becomes buffer-local when set in any fashion.\n\
4295 This variable does not apply to characters whose display is specified\n\
4296 in the current display table (if there is one).");
4298 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
4299 ¤t_buffer
->enable_multibyte_characters
,
4301 "Non-nil means the buffer contents are regarded as multi-byte characters.\n\
4302 Otherwise they are regarded as unibyte. This affects the display,\n\
4303 file I/O and the behavior of various editing commands.\n\
4305 This variable is buffer-local but you cannot set it directly;\n\
4306 use the function `set-buffer-multibyte' to change a buffer's representation.\n\
4307 Changing its default value with `setq-default' is supported.\n\
4308 See also variable `default-enable-multibyte-characters' and Info node\n\
4309 `(elisp)Text Representations'.");
4311 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
4312 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
4313 "Coding system to be used for encoding the buffer contents on saving.\n\
4314 This variable applies to saving the buffer, and also to `write-region'\n\
4315 and other functions that use `write-region'.\n\
4316 It does not apply to sending output to subprocesses, however.\n\
4318 If this is nil, the buffer is saved without any code conversion\n\
4319 unless some coding system is specified in `file-coding-system-alist'\n\
4320 for the buffer file.\n\
4322 The variable `coding-system-for-write', if non-nil, overrides this variable.\n\
4324 This variable is never applied to a way of decoding\n\
4325 a file while reading it.");
4327 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
4329 "*Non-nil means lines in the buffer are displayed right to left.");
4331 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
4332 "*Non-nil means do not display continuation lines;\n\
4333 give each line of text one screen line.\n\
4334 Automatically becomes buffer-local when set in any fashion.\n\
4336 Note that this is overridden by the variable\n\
4337 `truncate-partial-width-windows' if that variable is non-nil\n\
4338 and this buffer is not full-frame width.");
4341 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
4343 "Non-nil if the visited file is a binary file.\n\
4344 This variable is meaningful on MS-DOG and Windows NT.\n\
4345 On those systems, it is automatically local in every buffer.\n\
4346 On other systems, this variable is normally always nil.");
4349 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
4350 make_number (Lisp_String
),
4351 "Name of default directory of current buffer. Should end with slash.\n\
4352 Each buffer has its own value of this variable.");
4354 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
4356 "Function called (if non-nil) to perform auto-fill.\n\
4357 It is called after self-inserting a space or newline.\n\
4358 Each buffer has its own value of this variable.\n\
4359 NOTE: This variable is not a hook;\n\
4360 its value may not be a list of functions.");
4362 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
4363 make_number (Lisp_String
),
4364 "Name of file visited in current buffer, or nil if not visiting a file.\n\
4365 Each buffer has its own value of this variable.");
4367 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
4368 make_number (Lisp_String
),
4369 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
4370 The truename of a file is calculated by `file-truename'\n\
4371 and then abbreviated with `abbreviate-file-name'.\n\
4372 Each buffer has its own value of this variable.");
4374 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
4375 ¤t_buffer
->auto_save_file_name
,
4376 make_number (Lisp_String
),
4377 "Name of file for auto-saving current buffer,\n\
4378 or nil if buffer should not be auto-saved.\n\
4379 Each buffer has its own value of this variable.");
4381 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
4382 "Non-nil if this buffer is read-only.\n\
4383 Each buffer has its own value of this variable.");
4385 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
4386 "Non-nil if this buffer's file has been backed up.\n\
4387 Backing up is done before the first time the file is saved.\n\
4388 Each buffer has its own value of this variable.");
4390 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
4391 make_number (Lisp_Int
),
4392 "Length of current buffer when last read in, saved or auto-saved.\n\
4394 Each buffer has its own value of this variable.");
4396 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
4398 "Non-nil enables selective display:\n\
4399 Integer N as value means display only lines\n\
4400 that start with less than n columns of space.\n\
4401 A value of t means, after a ^M, all the rest of the line is invisible.\n\
4402 Then ^M's in the file are written into files as newlines.\n\n\
4403 Automatically becomes buffer-local when set in any fashion.");
4406 DEFVAR_PER_BUFFER ("selective-display-ellipses",
4407 ¤t_buffer
->selective_display_ellipses
,
4409 "t means display ... on previous line when a line is invisible.\n\
4410 Automatically becomes buffer-local when set in any fashion.");
4413 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
4414 "Non-nil if self-insertion should replace existing text.\n\
4415 The value should be one of `overwrite-mode-textual',\n\
4416 `overwrite-mode-binary', or nil.\n\
4417 If it is `overwrite-mode-textual', self-insertion still\n\
4418 inserts at the end of a line, and inserts when point is before a tab,\n\
4419 until the tab is filled in.\n\
4420 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
4421 Automatically becomes buffer-local when set in any fashion.");
4423 #if 0 /* The doc string is too long for some compilers,
4424 but make-docfile can find it in this comment. */
4425 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4427 "Display table that controls display of the contents of current buffer.\n\
4428 Automatically becomes buffer-local when set in any fashion.\n\
4429 The display table is a char-table created with `make-display-table'.\n\
4430 The ordinary char-table elements control how to display each possible text\n\
4431 character. Each value should be a vector of characters or nil;\n\
4432 nil means display the character in the default fashion.\n\
4433 There are six extra slots to control the display of\n\
4434 the end of a truncated screen line (extra-slot 0, a single character);\n\
4435 the end of a continued line (extra-slot 1, a single character);\n\
4436 the escape character used to display character codes in octal\n\
4437 (extra-slot 2, a single character);\n\
4438 the character used as an arrow for control characters (extra-slot 3,\n\
4439 a single character);\n\
4440 the decoration indicating the presence of invisible lines (extra-slot 4,\n\
4441 a vector of characters);\n\
4442 the character used to draw the border between side-by-side windows\n\
4443 (extra-slot 5, a single character).\n\
4444 See also the functions `display-table-slot' and `set-display-table-slot'.\n\
4445 If this variable is nil, the value of `standard-display-table' is used.\n\
4446 Each window can have its own, overriding display table.");
4448 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4451 DEFVAR_PER_BUFFER ("left-margin-width", ¤t_buffer
->left_margin_width
,
4453 "*Width of left marginal area for display of a buffer.\n\
4454 Automatically becomes buffer-local when set in any fashion.\n\
4455 A value of nil means no marginal area.");
4457 DEFVAR_PER_BUFFER ("right-margin-width", ¤t_buffer
->right_margin_width
,
4459 "*Width of right marginal area for display of a buffer.\n\
4460 Automatically becomes buffer-local when set in any fashion.\n\
4461 A value of nil means no marginal area.");
4463 DEFVAR_PER_BUFFER ("indicate-empty-lines",
4464 ¤t_buffer
->indicate_empty_lines
, Qnil
,
4465 "*Visually indicate empty lines after the buffer end.\n\
4466 If non-nil, a bitmap is displayed in the left fringe of a window on\n\
4468 Automatically becomes buffer-local when set in any fashion.\n");
4470 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
4471 ¤t_buffer
->scroll_up_aggressively
, Qnil
,
4472 "*If a number, scroll display up aggressively.\n\
4473 If scrolling a window because point is above the window start, choose\n\
4474 a new window start so that point ends up that fraction of the window's\n\
4475 height from the bottom of the window.\n\
4476 Automatically becomes buffer-local when set in any fashion.");
4478 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
4479 ¤t_buffer
->scroll_down_aggressively
, Qnil
,
4480 "*If a number, scroll display down aggressively.\n\
4481 If scrolling a window because point is below the window end, choose\n\
4482 a new window start so that point ends up that fraction of the window's\n\
4483 height from the top of the window.\n\
4484 Automatically becomes buffer-local when set in any fashion.");
4486 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
4489 DEFVAR_LISP ("before-change-function", &Vbefore_change_function
,
4490 "If non-nil, a function to call before each text change (obsolete).\n\
4491 Two arguments are passed to the function: the positions of\n\
4492 the beginning and end of the range of old text to be changed.\n\
4493 \(For an insertion, the beginning and end are at the same place.)\n\
4494 No information is given about the length of the text after the change.\n\
4496 Buffer changes made while executing the `before-change-function'\n\
4497 don't call any before-change or after-change functions.\n\
4498 That's because these variables are temporarily set to nil.\n\
4499 As a result, a hook function cannot straightforwardly alter the value of\n\
4500 these variables. See the Emacs Lisp manual for a way of\n\
4501 accomplishing an equivalent result by using other variables.\n\n\
4502 This variable is obsolete; use `before-change-functions' instead.");
4503 Vbefore_change_function
= Qnil
;
4505 DEFVAR_LISP ("after-change-function", &Vafter_change_function
,
4506 "If non-nil, a Function to call after each text change (obsolete).\n\
4507 Three arguments are passed to the function: the positions of\n\
4508 the beginning and end of the range of changed text,\n\
4509 and the length of the pre-change text replaced by that range.\n\
4510 \(For an insertion, the pre-change length is zero;\n\
4511 for a deletion, that length is the number of bytes deleted,\n\
4512 and the post-change beginning and end are at the same place.)\n\
4514 Buffer changes made while executing the `after-change-function'\n\
4515 don't call any before-change or after-change functions.\n\
4516 That's because these variables are temporarily set to nil.\n\
4517 As a result, a hook function cannot straightforwardly alter the value of\n\
4518 these variables. See the Emacs Lisp manual for a way of\n\
4519 accomplishing an equivalent result by using other variables.\n\n\
4520 This variable is obsolete; use `after-change-functions' instead.");
4521 Vafter_change_function
= Qnil
;
4523 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
4524 "List of functions to call before each text change.\n\
4525 Two arguments are passed to each function: the positions of\n\
4526 the beginning and end of the range of old text to be changed.\n\
4527 \(For an insertion, the beginning and end are at the same place.)\n\
4528 No information is given about the length of the text after the change.\n\
4530 Buffer changes made while executing the `before-change-functions'\n\
4531 don't call any before-change or after-change functions.\n\
4532 That's because these variables are temporarily set to nil.\n\
4533 As a result, a hook function cannot straightforwardly alter the value of\n\
4534 these variables. See the Emacs Lisp manual for a way of\n\
4535 accomplishing an equivalent result by using other variables.\n\
4537 If an unhandled error happens in running these functions,\n\
4538 the variable's value remains nil. That prevents the error\n\
4539 from happening repeatedly and making Emacs nonfunctional.");
4540 Vbefore_change_functions
= Qnil
;
4542 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
4543 "List of function to call after each text change.\n\
4544 Three arguments are passed to each function: the positions of\n\
4545 the beginning and end of the range of changed text,\n\
4546 and the length in bytes of the pre-change text replaced by that range.\n\
4547 \(For an insertion, the pre-change length is zero;\n\
4548 for a deletion, that length is the number of bytes deleted,\n\
4549 and the post-change beginning and end are at the same place.)\n\
4551 Buffer changes made while executing the `after-change-functions'\n\
4552 don't call any before-change or after-change functions.\n\
4553 That's because these variables are temporarily set to nil.\n\
4554 As a result, a hook function cannot straightforwardly alter the value of\n\
4555 these variables. See the Emacs Lisp manual for a way of\n\
4556 accomplishing an equivalent result by using other variables.\n\
4558 If an unhandled error happens in running these functions,\n\
4559 the variable's value remains nil. That prevents the error\n\
4560 from happening repeatedly and making Emacs nonfunctional.");
4561 Vafter_change_functions
= Qnil
;
4563 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
4564 "A list of functions to call before changing a buffer which is unmodified.\n\
4565 The functions are run using the `run-hooks' function.");
4566 Vfirst_change_hook
= Qnil
;
4568 #if 0 /* The doc string is too long for some compilers,
4569 but make-docfile can find it in this comment. */
4570 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4571 "List of undo entries in current buffer.\n\
4572 This variable is always local in all buffers.\n\
4573 Recent changes come first; older changes follow newer.\n\
4575 An entry (BEG . END) represents an insertion which begins at\n\
4576 position BEG and ends at position END.\n\
4578 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
4579 from (abs POSITION). If POSITION is positive, point was at the front\n\
4580 of the text being deleted; if negative, point was at the end.\n\
4582 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
4583 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
4584 of the visited file's modification time, as of that time. If the\n\
4585 modification time of the most recent save is different, this entry is\n\
4588 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
4589 was modified between BEG and END. PROPERTY is the property name,\n\
4590 and VALUE is the old value.\n\
4592 An entry (MARKER . DISTANCE) indicates that the marker MARKER\n\
4593 was adjusted in position by the offset DISTANCE (an integer).\n\
4595 An entry of the form POSITION indicates that point was at the buffer\n\
4596 location given by the integer. Undoing an entry of this form places\n\
4597 point at POSITION.\n\
4599 nil marks undo boundaries. The undo command treats the changes\n\
4600 between two undo boundaries as a single step to be undone.\n\
4602 If the value of the variable is t, undo information is not recorded.");
4604 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4607 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
4608 "Non-nil means the mark and region are currently active in this buffer.\n\
4609 Automatically local in all buffers.");
4611 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
4612 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
4613 This variable is buffer-local, in all buffers.\n\
4615 Normally, the line-motion functions work by scanning the buffer for\n\
4616 newlines. Columnar operations (like move-to-column and\n\
4617 compute-motion) also work by scanning the buffer, summing character\n\
4618 widths as they go. This works well for ordinary text, but if the\n\
4619 buffer's lines are very long (say, more than 500 characters), these\n\
4620 motion functions will take longer to execute. Emacs may also take\n\
4621 longer to update the display.\n\
4623 If cache-long-line-scans is non-nil, these motion functions cache the\n\
4624 results of their scans, and consult the cache to avoid rescanning\n\
4625 regions of the buffer until the text is modified. The caches are most\n\
4626 beneficial when they prevent the most searching---that is, when the\n\
4627 buffer contains long lines and large regions of characters with the\n\
4628 same, fixed screen width.\n\
4630 When cache-long-line-scans is non-nil, processing short lines will\n\
4631 become slightly slower (because of the overhead of consulting the\n\
4632 cache), and the caches will use memory roughly proportional to the\n\
4633 number of newlines and characters whose screen width varies.\n\
4635 The caches require no explicit maintenance; their accuracy is\n\
4636 maintained internally by the Emacs primitives. Enabling or disabling\n\
4637 the cache should not affect the behavior of any of the motion\n\
4638 functions; it should only affect their performance.");
4640 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
4641 "Value of point before the last series of scroll operations, or nil.\n\
4642 This variable is always local in all buffers.");
4644 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
4645 "List of formats to use when saving this buffer.\n\
4646 This variable is always local in all buffers.\n\
4647 Formats are defined by `format-alist'. This variable is\n\
4648 set when a file is visited. Automatically local in all buffers.");
4650 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
4651 ¤t_buffer
->invisibility_spec
, Qnil
,
4652 "Invisibility spec of this buffer.\n\
4653 This variable is always local in all buffers.\n\
4654 The default is t, which means that text is invisible\n\
4655 if it has a non-nil `invisible' property.\n\
4656 If the value is a list, a text character is invisible if its `invisible'\n\
4657 property is an element in that list.\n\
4658 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
4659 then characters with property value PROP are invisible,\n\
4660 and they have an ellipsis as well if ELLIPSIS is non-nil.");
4662 DEFVAR_PER_BUFFER ("buffer-display-count",
4663 ¤t_buffer
->display_count
, Qnil
,
4664 "A number incremented each time this buffer is displayed in a window.\n\
4665 This variable is always local in all buffers.\n\
4666 The function `set-window-buffer increments it.");
4668 DEFVAR_PER_BUFFER ("buffer-display-time",
4669 ¤t_buffer
->display_time
, Qnil
,
4670 "Time stamp updated each time this buffer is displayed in a window.\n\
4671 This variable is always local in all buffers.\n\
4672 The function `set-window-buffer' updates this variable\n\
4673 to the value obtained by calling `current-time'.\n\
4674 If the buffer has never been shown in a window, the value is nil.");
4676 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
4677 "*Non-nil means deactivate the mark when the buffer contents change.\n\
4678 Non-nil also enables highlighting of the region whenever the mark is active.\n\
4679 The variable `highlight-nonselected-windows' controls whether to highlight\n\
4680 all windows or just the selected window.");
4681 Vtransient_mark_mode
= Qnil
;
4683 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
4684 "*Non-nil means disregard read-only status of buffers or characters.\n\
4685 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
4686 text properties. If the value is a list, disregard `buffer-read-only'\n\
4687 and disregard a `read-only' text property if the property value\n\
4688 is a member of the list.");
4689 Vinhibit_read_only
= Qnil
;
4691 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
4692 "List of functions called with no args to query before killing a buffer.");
4693 Vkill_buffer_query_functions
= Qnil
;
4695 defsubr (&Sbuffer_live_p
);
4696 defsubr (&Sbuffer_list
);
4697 defsubr (&Sget_buffer
);
4698 defsubr (&Sget_file_buffer
);
4699 defsubr (&Sget_buffer_create
);
4700 defsubr (&Smake_indirect_buffer
);
4701 defsubr (&Sgenerate_new_buffer_name
);
4702 defsubr (&Sbuffer_name
);
4703 /*defsubr (&Sbuffer_number);*/
4704 defsubr (&Sbuffer_file_name
);
4705 defsubr (&Sbuffer_base_buffer
);
4706 defsubr (&Sbuffer_local_variables
);
4707 defsubr (&Sbuffer_modified_p
);
4708 defsubr (&Sset_buffer_modified_p
);
4709 defsubr (&Sbuffer_modified_tick
);
4710 defsubr (&Srename_buffer
);
4711 defsubr (&Sother_buffer
);
4712 defsubr (&Sbuffer_disable_undo
);
4713 defsubr (&Sbuffer_enable_undo
);
4714 defsubr (&Skill_buffer
);
4715 defsubr (&Sset_buffer_major_mode
);
4716 defsubr (&Sswitch_to_buffer
);
4717 defsubr (&Spop_to_buffer
);
4718 defsubr (&Scurrent_buffer
);
4719 defsubr (&Sset_buffer
);
4720 defsubr (&Sbarf_if_buffer_read_only
);
4721 defsubr (&Sbury_buffer
);
4722 defsubr (&Serase_buffer
);
4723 defsubr (&Sset_buffer_multibyte
);
4724 defsubr (&Skill_all_local_variables
);
4726 defsubr (&Soverlayp
);
4727 defsubr (&Smake_overlay
);
4728 defsubr (&Sdelete_overlay
);
4729 defsubr (&Smove_overlay
);
4730 defsubr (&Soverlay_start
);
4731 defsubr (&Soverlay_end
);
4732 defsubr (&Soverlay_buffer
);
4733 defsubr (&Soverlay_properties
);
4734 defsubr (&Soverlays_at
);
4735 defsubr (&Soverlays_in
);
4736 defsubr (&Snext_overlay_change
);
4737 defsubr (&Sprevious_overlay_change
);
4738 defsubr (&Soverlay_recenter
);
4739 defsubr (&Soverlay_lists
);
4740 defsubr (&Soverlay_get
);
4741 defsubr (&Soverlay_put
);
4747 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
4748 initial_define_key (control_x_map
, 'k', "kill-buffer");
4750 /* This must not be in syms_of_buffer, because Qdisabled is not
4751 initialized when that function gets called. */
4752 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);