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 entry for that slot (found in the same slot in this structure)
77 is turned on in the buffer's local_flags array.
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 char buffer_permanent_local_flags
[MAX_BUFFER_LOCAL_VARS
];
117 /* Number of per-buffer variables used. */
119 int max_buffer_local_idx
;
121 Lisp_Object
Fset_buffer ();
122 void set_buffer_internal ();
123 void set_buffer_internal_1 ();
124 static void call_overlay_mod_hooks ();
125 static void swap_out_buffer_local_variables ();
126 static void reset_buffer_local_variables ();
128 /* Alist of all buffer names vs the buffers. */
129 /* This used to be a variable, but is no longer,
130 to prevent lossage due to user rplac'ing this alist or its elements. */
131 Lisp_Object Vbuffer_alist
;
133 /* Functions to call before and after each text change. */
134 Lisp_Object Vbefore_change_function
;
135 Lisp_Object Vafter_change_function
;
136 Lisp_Object Vbefore_change_functions
;
137 Lisp_Object Vafter_change_functions
;
139 Lisp_Object Vtransient_mark_mode
;
141 /* t means ignore all read-only text properties.
142 A list means ignore such a property if its value is a member of the list.
143 Any non-nil value means ignore buffer-read-only. */
144 Lisp_Object Vinhibit_read_only
;
146 /* List of functions to call that can query about killing a buffer.
147 If any of these functions returns nil, we don't kill it. */
148 Lisp_Object Vkill_buffer_query_functions
;
150 /* List of functions to call before changing an unmodified buffer. */
151 Lisp_Object Vfirst_change_hook
;
153 Lisp_Object Qfirst_change_hook
;
154 Lisp_Object Qbefore_change_functions
;
155 Lisp_Object Qafter_change_functions
;
157 /* If nonzero, all modification hooks are suppressed. */
158 int inhibit_modification_hooks
;
160 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
162 Lisp_Object Qprotected_field
;
164 Lisp_Object QSFundamental
; /* A string "Fundamental" */
166 Lisp_Object Qkill_buffer_hook
;
168 Lisp_Object Qget_file_buffer
;
170 Lisp_Object Qoverlayp
;
172 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
174 Lisp_Object Qmodification_hooks
;
175 Lisp_Object Qinsert_in_front_hooks
;
176 Lisp_Object Qinsert_behind_hooks
;
178 /* For debugging; temporary. See set_buffer_internal. */
179 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
186 error ("No buffer named %s", XSTRING (spec
)->data
);
187 error ("Invalid buffer argument");
190 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
191 "Return non-nil if OBJECT is a buffer which has not been killed.\n\
192 Value is nil if OBJECT is not a buffer or if it has been killed.")
196 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
200 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
201 "Return a list of all existing live buffers.\n\
202 If the optional arg FRAME is a frame, we return that frame's buffer list.")
206 Lisp_Object framelist
, general
;
207 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
213 CHECK_FRAME (frame
, 1);
215 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
217 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */
219 while (! NILP (tail
))
221 general
= Fdelq (XCAR (tail
), general
);
224 return nconc2 (framelist
, general
);
230 /* Like Fassoc, but use Fstring_equal to compare
231 (which ignores text properties),
232 and don't ever QUIT. */
235 assoc_ignore_text_properties (key
, list
)
236 register Lisp_Object key
;
239 register Lisp_Object tail
;
240 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
242 register Lisp_Object elt
, tem
;
244 tem
= Fstring_equal (Fcar (elt
), key
);
251 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
252 "Return the buffer named NAME (a string).\n\
253 If there is no live buffer named NAME, return nil.\n\
254 NAME may also be a buffer; if so, the value is that buffer.")
256 register Lisp_Object name
;
260 CHECK_STRING (name
, 0);
262 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
265 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
266 "Return the buffer visiting file FILENAME (a string).\n\
267 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
268 If there is no such live buffer, return nil.\n\
269 See also `find-buffer-visiting'.")
271 register Lisp_Object filename
;
273 register Lisp_Object tail
, buf
, tem
;
276 CHECK_STRING (filename
, 0);
277 filename
= Fexpand_file_name (filename
, Qnil
);
279 /* If the file name has special constructs in it,
280 call the corresponding file handler. */
281 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
283 return call2 (handler
, Qget_file_buffer
, filename
);
285 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
287 buf
= Fcdr (XCAR (tail
));
288 if (!BUFFERP (buf
)) continue;
289 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
290 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
298 get_truename_buffer (filename
)
299 register Lisp_Object filename
;
301 register Lisp_Object tail
, buf
, tem
;
303 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
305 buf
= Fcdr (XCAR (tail
));
306 if (!BUFFERP (buf
)) continue;
307 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
308 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
315 /* Incremented for each buffer created, to assign the buffer number. */
318 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
319 "Return the buffer named NAME, or create such a buffer and return it.\n\
320 A new buffer is created if there is no live buffer named NAME.\n\
321 If NAME starts with a space, the new buffer does not keep undo information.\n\
322 If NAME is a buffer instead of a string, then it is the value returned.\n\
323 The value is never nil.")
325 register Lisp_Object name
;
327 register Lisp_Object buf
;
328 register struct buffer
*b
;
330 buf
= Fget_buffer (name
);
334 if (XSTRING (name
)->size
== 0)
335 error ("Empty string for buffer name is not allowed");
337 b
= (struct buffer
*) allocate_buffer ();
339 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
341 /* An ordinary buffer uses its own struct buffer_text. */
342 b
->text
= &b
->own_text
;
345 BUF_GAP_SIZE (b
) = 20;
347 /* We allocate extra 1-byte at the tail and keep it always '\0' for
348 anchoring a search. */
349 BUFFER_ALLOC (BUF_BEG_ADDR (b
), (BUF_GAP_SIZE (b
) + 1));
351 if (! BUF_BEG_ADDR (b
))
352 buffer_memory_full ();
360 BUF_GPT_BYTE (b
) = 1;
361 BUF_BEGV_BYTE (b
) = 1;
365 BUF_OVERLAY_MODIFF (b
) = 1;
366 BUF_SAVE_MODIFF (b
) = 1;
367 BUF_INTERVALS (b
) = 0;
368 BUF_UNCHANGED_MODIFIED (b
) = 1;
369 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = 1;
370 BUF_END_UNCHANGED (b
) = 0;
371 BUF_BEG_UNCHANGED (b
) = 0;
372 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
374 b
->newline_cache
= 0;
375 b
->width_run_cache
= 0;
376 b
->width_table
= Qnil
;
377 b
->prevent_redisplay_optimizations_p
= 1;
379 /* Put this on the chain of all buffers including killed ones. */
380 b
->next
= all_buffers
;
383 /* An ordinary buffer normally doesn't need markers
384 to handle BEGV and ZV. */
386 b
->begv_marker
= Qnil
;
389 name
= Fcopy_sequence (name
);
390 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
393 if (XSTRING (name
)->data
[0] != ' ')
399 reset_buffer_local_variables (b
, 1);
401 /* Put this in the alist of all live buffers. */
403 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
405 b
->mark
= Fmake_marker ();
406 BUF_MARKERS (b
) = Qnil
;
411 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
, 2, 2,
412 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
413 "Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.\n\
414 BASE-BUFFER should be an existing buffer (or buffer name).\n\
415 NAME should be a string which is not the name of an existing buffer.")
417 register Lisp_Object base_buffer
, name
;
419 register Lisp_Object buf
;
420 register struct buffer
*b
;
422 buf
= Fget_buffer (name
);
424 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
426 base_buffer
= Fget_buffer (base_buffer
);
427 if (NILP (base_buffer
))
428 error ("No such buffer: `%s'",
429 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
431 if (XSTRING (name
)->size
== 0)
432 error ("Empty string for buffer name is not allowed");
434 b
= (struct buffer
*) allocate_buffer ();
435 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
437 if (XBUFFER (base_buffer
)->base_buffer
)
438 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
440 b
->base_buffer
= XBUFFER (base_buffer
);
442 /* Use the base buffer's text object. */
443 b
->text
= b
->base_buffer
->text
;
445 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
446 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
447 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
448 BUF_BEGV_BYTE (b
) = BUF_BEGV_BYTE (b
->base_buffer
);
449 BUF_ZV_BYTE (b
) = BUF_ZV_BYTE (b
->base_buffer
);
450 BUF_PT_BYTE (b
) = BUF_PT_BYTE (b
->base_buffer
);
452 b
->newline_cache
= 0;
453 b
->width_run_cache
= 0;
454 b
->width_table
= Qnil
;
456 /* Put this on the chain of all buffers including killed ones. */
457 b
->next
= all_buffers
;
460 name
= Fcopy_sequence (name
);
461 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
465 reset_buffer_local_variables (b
, 1);
467 /* Put this in the alist of all live buffers. */
469 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
471 b
->mark
= Fmake_marker ();
474 /* The multibyte status belongs to the base buffer. */
475 b
->enable_multibyte_characters
= b
->base_buffer
->enable_multibyte_characters
;
477 /* Make sure the base buffer has markers for its narrowing. */
478 if (NILP (b
->base_buffer
->pt_marker
))
480 b
->base_buffer
->pt_marker
= Fmake_marker ();
481 set_marker_both (b
->base_buffer
->pt_marker
, base_buffer
,
482 BUF_PT (b
->base_buffer
),
483 BUF_PT_BYTE (b
->base_buffer
));
485 if (NILP (b
->base_buffer
->begv_marker
))
487 b
->base_buffer
->begv_marker
= Fmake_marker ();
488 set_marker_both (b
->base_buffer
->begv_marker
, base_buffer
,
489 BUF_BEGV (b
->base_buffer
),
490 BUF_BEGV_BYTE (b
->base_buffer
));
492 if (NILP (b
->base_buffer
->zv_marker
))
494 b
->base_buffer
->zv_marker
= Fmake_marker ();
495 set_marker_both (b
->base_buffer
->zv_marker
, base_buffer
,
496 BUF_ZV (b
->base_buffer
),
497 BUF_ZV_BYTE (b
->base_buffer
));
498 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
501 /* Give the indirect buffer markers for its narrowing. */
502 b
->pt_marker
= Fmake_marker ();
503 set_marker_both (b
->pt_marker
, buf
, BUF_PT (b
), BUF_PT_BYTE (b
));
504 b
->begv_marker
= Fmake_marker ();
505 set_marker_both (b
->begv_marker
, buf
, BUF_BEGV (b
), BUF_BEGV_BYTE (b
));
506 b
->zv_marker
= Fmake_marker ();
507 set_marker_both (b
->zv_marker
, buf
, BUF_ZV (b
), BUF_ZV_BYTE (b
));
508 XMARKER (b
->zv_marker
)->insertion_type
= 1;
513 /* Reinitialize everything about a buffer except its name and contents
514 and local variables. */
518 register struct buffer
*b
;
521 b
->file_truename
= Qnil
;
522 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
524 XSETFASTINT (b
->save_length
, 0);
525 b
->last_window_start
= 1;
526 /* It is more conservative to start out "changed" than "unchanged". */
528 b
->prevent_redisplay_optimizations_p
= 1;
530 b
->auto_save_modified
= 0;
531 b
->auto_save_failure_time
= -1;
532 b
->auto_save_file_name
= Qnil
;
534 b
->overlays_before
= Qnil
;
535 b
->overlays_after
= Qnil
;
536 XSETFASTINT (b
->overlay_center
, 1);
537 b
->mark_active
= Qnil
;
538 b
->point_before_scroll
= Qnil
;
539 b
->file_format
= Qnil
;
540 b
->last_selected_window
= Qnil
;
541 XSETINT (b
->display_count
, 0);
542 b
->display_time
= Qnil
;
545 b
->enable_multibyte_characters
= buffer_defaults
.enable_multibyte_characters
;
548 /* Reset buffer B's local variables info.
549 Don't use this on a buffer that has already been in use;
550 it does not treat permanent locals consistently.
551 Instead, use Fkill_all_local_variables.
553 If PERMANENT_TOO is 1, then we reset permanent built-in
554 buffer-local variables. If PERMANENT_TOO is 0,
555 we preserve those. */
558 reset_buffer_local_variables (b
, permanent_too
)
559 register struct buffer
*b
;
565 /* Reset the major mode to Fundamental, together with all the
566 things that depend on the major mode.
567 default-major-mode is handled at a higher level.
568 We ignore it here. */
569 b
->major_mode
= Qfundamental_mode
;
571 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
572 b
->mode_name
= QSFundamental
;
573 b
->minor_modes
= Qnil
;
575 /* If the standard case table has been altered and invalidated,
576 fix up its insides first. */
577 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
578 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
579 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
580 Fset_standard_case_table (Vascii_downcase_table
);
582 b
->downcase_table
= Vascii_downcase_table
;
583 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
584 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
585 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
586 b
->invisibility_spec
= Qt
;
588 b
->buffer_file_type
= Qnil
;
592 b
->sort_table
= XSTRING (Vascii_sort_table
);
593 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
596 /* Reset all (or most) per-buffer variables to their defaults. */
597 b
->local_var_alist
= Qnil
;
598 for (i
= 0; i
< max_buffer_local_idx
; ++i
)
599 if (permanent_too
|| buffer_permanent_local_flags
[i
] == 0)
600 SET_BUFFER_HAS_LOCAL_VALUE_P (b
, i
, 0);
602 /* For each slot that has a default value,
603 copy that into the slot. */
605 for (offset
= BUFFER_LOCAL_VAR_OFFSET (name
);
607 offset
+= sizeof (Lisp_Object
))
609 int idx
= BUFFER_LOCAL_IDX (offset
);
612 || buffer_permanent_local_flags
[idx
] == 0))
613 /* Is -2 used anywhere? */
615 BUFFER_LOCAL_VALUE (b
, offset
) = BUFFER_LOCAL_DEFAULT_VALUE (offset
);
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. */
762 for (offset
= BUFFER_LOCAL_VAR_OFFSET (name
);
763 offset
< sizeof (struct buffer
);
764 /* sizeof EMACS_INT == sizeof Lisp_Object */
765 offset
+= (sizeof (EMACS_INT
)))
767 idx
= BUFFER_LOCAL_IDX (offset
);
768 if ((idx
== -1 || BUFFER_HAS_LOCAL_VALUE_P (buf
, idx
))
769 && SYMBOLP (BUFFER_LOCAL_SYMBOL (offset
)))
770 result
= Fcons (Fcons (BUFFER_LOCAL_SYMBOL (offset
),
771 BUFFER_LOCAL_VALUE (buf
, offset
)),
780 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
782 "Return t if BUFFER was modified since its file was last read or saved.\n\
783 No argument or nil as argument means use current buffer as BUFFER.")
785 register Lisp_Object buffer
;
787 register struct buffer
*buf
;
789 buf
= current_buffer
;
792 CHECK_BUFFER (buffer
, 0);
793 buf
= XBUFFER (buffer
);
796 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
799 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
801 "Mark current buffer as modified or unmodified according to FLAG.\n\
802 A non-nil FLAG means mark the buffer modified.")
804 register Lisp_Object flag
;
806 register int already
;
807 register Lisp_Object fn
;
808 Lisp_Object buffer
, window
;
810 #ifdef CLASH_DETECTION
811 /* If buffer becoming modified, lock the file.
812 If buffer becoming unmodified, unlock the file. */
814 fn
= current_buffer
->file_truename
;
815 /* Test buffer-file-name so that binding it to nil is effective. */
816 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
818 already
= SAVE_MODIFF
< MODIFF
;
819 if (!already
&& !NILP (flag
))
821 else if (already
&& NILP (flag
))
824 #endif /* CLASH_DETECTION */
826 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
828 /* Set update_mode_lines only if buffer is displayed in some window.
829 Packages like jit-lock or lazy-lock preserve a buffer's modified
830 state by recording/restoring the state around blocks of code.
831 Setting update_mode_lines makes redisplay consider all windows
832 (on all frames). Stealth fontification of buffers not displayed
833 would incur additional redisplay costs if we'd set
834 update_modes_lines unconditionally.
836 Ideally, I think there should be another mechanism for fontifying
837 buffers without "modifying" buffers, or redisplay should be
838 smarter about updating the `*' in mode lines. --gerd */
839 XSETBUFFER (buffer
, current_buffer
);
840 window
= Fget_buffer_window (buffer
, Qt
);
841 if (WINDOWP (window
))
847 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
849 "Return BUFFER's tick counter, incremented for each change in text.\n\
850 Each buffer has a tick counter which is incremented each time the text in\n\
851 that buffer is changed. It wraps around occasionally.\n\
852 No argument or nil as argument means use current buffer as BUFFER.")
854 register Lisp_Object buffer
;
856 register struct buffer
*buf
;
858 buf
= current_buffer
;
861 CHECK_BUFFER (buffer
, 0);
862 buf
= XBUFFER (buffer
);
865 return make_number (BUF_MODIFF (buf
));
868 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
869 "sRename buffer (to new name): \nP",
870 "Change current buffer's name to NEWNAME (a string).\n\
871 If second arg UNIQUE is nil or omitted, it is an error if a\n\
872 buffer named NEWNAME already exists.\n\
873 If UNIQUE is non-nil, come up with a new name using\n\
874 `generate-new-buffer-name'.\n\
875 Interactively, you can set UNIQUE with a prefix argument.\n\
876 We return the name we actually gave the buffer.\n\
877 This does not change the name of the visited file (if any).")
879 register Lisp_Object newname
, unique
;
881 register Lisp_Object tem
, buf
;
883 CHECK_STRING (newname
, 0);
885 if (XSTRING (newname
)->size
== 0)
886 error ("Empty string is invalid as a buffer name");
888 tem
= Fget_buffer (newname
);
889 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
890 the buffer automatically so you can create another with the original name.
891 It makes UNIQUE equivalent to
892 (rename-buffer (generate-new-buffer-name NEWNAME)). */
893 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
894 return current_buffer
->name
;
898 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
900 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
903 current_buffer
->name
= newname
;
905 /* Catch redisplay's attention. Unless we do this, the mode lines for
906 any windows displaying current_buffer will stay unchanged. */
909 XSETBUFFER (buf
, current_buffer
);
910 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
911 if (NILP (current_buffer
->filename
)
912 && !NILP (current_buffer
->auto_save_file_name
))
913 call0 (intern ("rename-auto-save-file"));
914 /* Refetch since that last call may have done GC. */
915 return current_buffer
->name
;
918 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 3, 0,
919 "Return most recently selected buffer other than BUFFER.\n\
920 Buffers not visible in windows are preferred to visible buffers,\n\
921 unless optional second argument VISIBLE-OK is non-nil.\n\
922 If the optional third argument FRAME is non-nil, use that frame's\n\
923 buffer list instead of the selected frame's buffer list.\n\
924 If no other buffer exists, the buffer `*scratch*' is returned.\n\
925 If BUFFER is omitted or nil, some interesting buffer is returned.")
926 (buffer
, visible_ok
, frame
)
927 register Lisp_Object buffer
, visible_ok
, frame
;
929 Lisp_Object
Fset_buffer_major_mode ();
930 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
934 frame
= selected_frame
;
936 tail
= Vbuffer_alist
;
937 pred
= frame_buffer_predicate (frame
);
939 /* Consider buffers that have been seen in the selected frame
940 before other buffers. */
942 tem
= frame_buffer_list (frame
);
946 if (BUFFERP (XCAR (tem
)))
947 add_ons
= Fcons (Fcons (Qnil
, XCAR (tem
)), add_ons
);
950 tail
= nconc2 (Fnreverse (add_ons
), tail
);
952 for (; !NILP (tail
); tail
= Fcdr (tail
))
954 buf
= Fcdr (Fcar (tail
));
955 if (EQ (buf
, buffer
))
957 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
959 /* If the selected frame has a buffer_predicate,
960 disregard buffers that don't fit the predicate. */
963 tem
= call1 (pred
, buf
);
968 if (NILP (visible_ok
))
969 tem
= Fget_buffer_window (buf
, Qt
);
974 if (NILP (notsogood
))
977 if (!NILP (notsogood
))
979 buf
= Fget_buffer (build_string ("*scratch*"));
982 buf
= Fget_buffer_create (build_string ("*scratch*"));
983 Fset_buffer_major_mode (buf
);
988 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
,
990 "Make BUFFER stop keeping undo information.\n\
991 No argument or nil as argument means do this for the current buffer.")
993 register Lisp_Object buffer
;
995 Lisp_Object real_buffer
;
998 XSETBUFFER (real_buffer
, current_buffer
);
1001 real_buffer
= Fget_buffer (buffer
);
1002 if (NILP (real_buffer
))
1006 XBUFFER (real_buffer
)->undo_list
= Qt
;
1011 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
1013 "Start keeping undo information for buffer BUFFER.\n\
1014 No argument or nil as argument means do this for the current buffer.")
1016 register Lisp_Object buffer
;
1018 Lisp_Object real_buffer
;
1021 XSETBUFFER (real_buffer
, current_buffer
);
1024 real_buffer
= Fget_buffer (buffer
);
1025 if (NILP (real_buffer
))
1029 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
1030 XBUFFER (real_buffer
)->undo_list
= Qnil
;
1036 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
1037 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1038 The buffer being killed will be current while the hook is running.\n\
1041 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
1042 "Kill the buffer BUFFER.\n\
1043 The argument may be a buffer or may be the name of a buffer.\n\
1044 An argument of nil means kill the current buffer.\n\n\
1045 Value is t if the buffer is actually killed, nil if user says no.\n\n\
1046 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
1047 if not void, is a list of functions to be called, with no arguments,\n\
1048 before the buffer is actually killed. The buffer to be killed is current\n\
1049 when the hook functions are called.\n\n\
1050 Any processes that have this buffer as the `process-buffer' are killed\n\
1056 register struct buffer
*b
;
1057 register Lisp_Object tem
;
1058 register struct Lisp_Marker
*m
;
1059 struct gcpro gcpro1
;
1062 buf
= Fcurrent_buffer ();
1064 buf
= Fget_buffer (buffer
);
1070 /* Avoid trouble for buffer already dead. */
1074 /* Query if the buffer is still modified. */
1075 if (INTERACTIVE
&& !NILP (b
->filename
)
1076 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1079 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
1080 XSTRING (b
->name
)->data
));
1086 /* Run hooks with the buffer to be killed the current buffer. */
1088 int count
= specpdl_ptr
- specpdl
;
1091 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1092 set_buffer_internal (b
);
1094 /* First run the query functions; if any query is answered no,
1095 don't kill the buffer. */
1096 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
1098 tem
= call0 (Fcar (list
));
1100 return unbind_to (count
, Qnil
);
1103 /* Then run the hooks. */
1104 if (!NILP (Vrun_hooks
))
1105 call1 (Vrun_hooks
, Qkill_buffer_hook
);
1106 unbind_to (count
, Qnil
);
1109 /* We have no more questions to ask. Verify that it is valid
1110 to kill the buffer. This must be done after the questions
1111 since anything can happen within do_yes_or_no_p. */
1113 /* Don't kill the minibuffer now current. */
1114 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1120 /* When we kill a base buffer, kill all its indirect buffers.
1121 We do it at this stage so nothing terrible happens if they
1122 ask questions or their hooks get errors. */
1123 if (! b
->base_buffer
)
1125 struct buffer
*other
;
1129 for (other
= all_buffers
; other
; other
= other
->next
)
1130 /* all_buffers contains dead buffers too;
1131 don't re-kill them. */
1132 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1135 XSETBUFFER (buf
, other
);
1142 /* Make this buffer not be current.
1143 In the process, notice if this is the sole visible buffer
1144 and give up if so. */
1145 if (b
== current_buffer
)
1147 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1149 if (b
== current_buffer
)
1153 /* Now there is no question: we can kill the buffer. */
1155 #ifdef CLASH_DETECTION
1156 /* Unlock this buffer's file, if it is locked. */
1158 #endif /* CLASH_DETECTION */
1160 kill_buffer_processes (buf
);
1162 tem
= Vinhibit_quit
;
1164 replace_buffer_in_all_windows (buf
);
1165 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1166 frames_discard_buffer (buf
);
1167 Vinhibit_quit
= tem
;
1169 /* Delete any auto-save file, if we saved it in this session. */
1170 if (STRINGP (b
->auto_save_file_name
)
1171 && b
->auto_save_modified
!= 0
1172 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
)
1175 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1177 internal_delete_file (b
->auto_save_file_name
);
1182 /* Unchain all markers that belong to this indirect buffer.
1183 Don't unchain the markers that belong to the base buffer
1184 or its other indirect buffers. */
1185 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1191 unchain_marker (tem
);
1197 /* Unchain all markers of this buffer and its indirect buffers.
1198 and leave them pointing nowhere. */
1199 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1206 BUF_MARKERS (b
) = Qnil
;
1207 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1209 /* Perhaps we should explicitly free the interval tree here... */
1212 /* Reset the local variables, so that this buffer's local values
1213 won't be protected from GC. They would be protected
1214 if they happened to remain encached in their symbols.
1215 This gets rid of them for certain. */
1216 swap_out_buffer_local_variables (b
);
1217 reset_buffer_local_variables (b
, 1);
1222 if (! b
->base_buffer
)
1223 BUFFER_FREE (BUF_BEG_ADDR (b
));
1225 if (b
->newline_cache
)
1227 free_region_cache (b
->newline_cache
);
1228 b
->newline_cache
= 0;
1230 if (b
->width_run_cache
)
1232 free_region_cache (b
->width_run_cache
);
1233 b
->width_run_cache
= 0;
1235 b
->width_table
= Qnil
;
1237 b
->undo_list
= Qnil
;
1242 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1243 we do this each time BUF is selected visibly, the more recently
1244 selected buffers are always closer to the front of the list. This
1245 means that other_buffer is more likely to choose a relevant buffer. */
1251 register Lisp_Object link
, prev
;
1253 frame
= selected_frame
;
1256 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCDR (link
))
1258 if (EQ (XCDR (XCAR (link
)), buf
))
1263 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1264 we cannot use Fdelq itself here because it allows quitting. */
1267 Vbuffer_alist
= XCDR (Vbuffer_alist
);
1269 XCDR (prev
) = XCDR (XCDR (prev
));
1271 XCDR (link
) = Vbuffer_alist
;
1272 Vbuffer_alist
= link
;
1274 /* Now move this buffer to the front of frame_buffer_list also. */
1277 for (link
= frame_buffer_list (frame
); CONSP (link
);
1280 if (EQ (XCAR (link
), buf
))
1285 /* Effectively do delq. */
1290 set_frame_buffer_list (frame
,
1291 XCDR (frame_buffer_list (frame
)));
1293 XCDR (prev
) = XCDR (XCDR (prev
));
1295 XCDR (link
) = frame_buffer_list (frame
);
1296 set_frame_buffer_list (frame
, link
);
1299 set_frame_buffer_list (frame
, Fcons (buf
, frame_buffer_list (frame
)));
1302 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1303 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1304 Use this function before selecting the buffer, since it may need to inspect\n\
1305 the current buffer's major mode.")
1310 Lisp_Object function
;
1312 function
= buffer_defaults
.major_mode
;
1313 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1314 function
= current_buffer
->major_mode
;
1316 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1319 count
= specpdl_ptr
- specpdl
;
1321 /* To select a nonfundamental mode,
1322 select the buffer temporarily and then call the mode function. */
1324 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1326 Fset_buffer (buffer
);
1329 return unbind_to (count
, Qnil
);
1332 /* If switching buffers in WINDOW would be an error, return
1333 a C string saying what the error would be. */
1336 no_switch_window (window
)
1340 if (EQ (minibuf_window
, window
))
1341 return "Cannot switch buffers in minibuffer window";
1342 tem
= Fwindow_dedicated_p (window
);
1344 return "Cannot switch buffers in a dedicated window";
1348 /* Switch to buffer BUFFER in the selected window.
1349 If NORECORD is non-nil, don't call record_buffer. */
1352 switch_to_buffer_1 (buffer
, norecord
)
1353 Lisp_Object buffer
, norecord
;
1355 register Lisp_Object buf
;
1358 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1361 buf
= Fget_buffer (buffer
);
1364 buf
= Fget_buffer_create (buffer
);
1365 Fset_buffer_major_mode (buf
);
1369 if (NILP (norecord
))
1370 record_buffer (buf
);
1372 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1373 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1380 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1381 "Select buffer BUFFER in the current window.\n\
1382 BUFFER may be a buffer or a buffer name.\n\
1383 Optional second arg NORECORD non-nil means\n\
1384 do not put this buffer at the front of the list of recently selected ones.\n\
1386 WARNING: This is NOT the way to work on another buffer temporarily\n\
1387 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1388 the window-buffer correspondences.")
1390 Lisp_Object buffer
, norecord
;
1394 err
= no_switch_window (selected_window
);
1395 if (err
) error (err
);
1397 return switch_to_buffer_1 (buffer
, norecord
);
1400 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1401 "Select buffer BUFFER in some window, preferably a different one.\n\
1402 If BUFFER is nil, then some other buffer is chosen.\n\
1403 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1404 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1405 window even if BUFFER is already visible in the selected window.\n\
1406 This uses the function `display-buffer' as a subroutine; see the documentation\n\
1407 of `display-buffer' for additional customization information.\n\
1409 Optional third arg NORECORD non-nil means\n\
1410 do not put this buffer at the front of the list of recently selected ones.")
1411 (buffer
, other_window
, norecord
)
1412 Lisp_Object buffer
, other_window
, norecord
;
1414 register Lisp_Object buf
;
1416 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1419 buf
= Fget_buffer (buffer
);
1422 buf
= Fget_buffer_create (buffer
);
1423 Fset_buffer_major_mode (buf
);
1427 if (NILP (norecord
))
1428 record_buffer (buf
);
1429 Fselect_window (Fdisplay_buffer (buf
, other_window
, Qnil
));
1433 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1434 "Return the current buffer as a Lisp object.")
1437 register Lisp_Object buf
;
1438 XSETBUFFER (buf
, current_buffer
);
1442 /* Set the current buffer to B.
1444 We previously set windows_or_buffers_changed here to invalidate
1445 global unchanged information in beg_unchanged and end_unchanged.
1446 This is no longer necessary because we now compute unchanged
1447 information on a buffer-basis. Every action affecting other
1448 windows than the selected one requires a select_window at some
1449 time, and that increments windows_or_buffers_changed. */
1452 set_buffer_internal (b
)
1453 register struct buffer
*b
;
1455 if (current_buffer
!= b
)
1456 set_buffer_internal_1 (b
);
1459 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1460 This is used by redisplay. */
1463 set_buffer_internal_1 (b
)
1464 register struct buffer
*b
;
1466 register struct buffer
*old_buf
;
1467 register Lisp_Object tail
, valcontents
;
1470 if (current_buffer
== b
)
1473 old_buf
= current_buffer
;
1475 last_known_column_point
= -1; /* invalidate indentation cache */
1479 /* Put the undo list back in the base buffer, so that it appears
1480 that an indirect buffer shares the undo list of its base. */
1481 if (old_buf
->base_buffer
)
1482 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1484 /* If the old current buffer has markers to record PT, BEGV and ZV
1485 when it is not current, update them now. */
1486 if (! NILP (old_buf
->pt_marker
))
1489 XSETBUFFER (obuf
, old_buf
);
1490 set_marker_both (old_buf
->pt_marker
, obuf
,
1491 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1493 if (! NILP (old_buf
->begv_marker
))
1496 XSETBUFFER (obuf
, old_buf
);
1497 set_marker_both (old_buf
->begv_marker
, obuf
,
1498 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1500 if (! NILP (old_buf
->zv_marker
))
1503 XSETBUFFER (obuf
, old_buf
);
1504 set_marker_both (old_buf
->zv_marker
, obuf
,
1505 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1509 /* Get the undo list from the base buffer, so that it appears
1510 that an indirect buffer shares the undo list of its base. */
1512 b
->undo_list
= b
->base_buffer
->undo_list
;
1514 /* If the new current buffer has markers to record PT, BEGV and ZV
1515 when it is not current, fetch them now. */
1516 if (! NILP (b
->pt_marker
))
1518 BUF_PT (b
) = marker_position (b
->pt_marker
);
1519 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1521 if (! NILP (b
->begv_marker
))
1523 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1524 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1526 if (! NILP (b
->zv_marker
))
1528 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1529 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1532 /* Look down buffer's list of local Lisp variables
1533 to find and update any that forward into C variables. */
1535 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCDR (tail
))
1537 valcontents
= XSYMBOL (XCAR (XCAR (tail
)))->value
;
1538 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1539 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1540 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1541 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1542 /* Just reference the variable
1543 to cause it to become set for this buffer. */
1544 Fsymbol_value (XCAR (XCAR (tail
)));
1547 /* Do the same with any others that were local to the previous buffer */
1550 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCDR (tail
))
1552 valcontents
= XSYMBOL (XCAR (XCAR (tail
)))->value
;
1553 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1554 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1555 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1556 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1557 /* Just reference the variable
1558 to cause it to become set for this buffer. */
1559 Fsymbol_value (XCAR (XCAR (tail
)));
1563 /* Switch to buffer B temporarily for redisplay purposes.
1564 This avoids certain things that don't need to be done within redisplay. */
1570 register struct buffer
*old_buf
;
1572 if (current_buffer
== b
)
1575 old_buf
= current_buffer
;
1580 /* If the old current buffer has markers to record PT, BEGV and ZV
1581 when it is not current, update them now. */
1582 if (! NILP (old_buf
->pt_marker
))
1585 XSETBUFFER (obuf
, old_buf
);
1586 set_marker_both (old_buf
->pt_marker
, obuf
,
1587 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1589 if (! NILP (old_buf
->begv_marker
))
1592 XSETBUFFER (obuf
, old_buf
);
1593 set_marker_both (old_buf
->begv_marker
, obuf
,
1594 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1596 if (! NILP (old_buf
->zv_marker
))
1599 XSETBUFFER (obuf
, old_buf
);
1600 set_marker_both (old_buf
->zv_marker
, obuf
,
1601 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1605 /* If the new current buffer has markers to record PT, BEGV and ZV
1606 when it is not current, fetch them now. */
1607 if (! NILP (b
->pt_marker
))
1609 BUF_PT (b
) = marker_position (b
->pt_marker
);
1610 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1612 if (! NILP (b
->begv_marker
))
1614 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1615 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1617 if (! NILP (b
->zv_marker
))
1619 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1620 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1624 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1625 "Make the buffer BUFFER current for editing operations.\n\
1626 BUFFER may be a buffer or the name of an existing buffer.\n\
1627 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1628 This function does not display the buffer, so its effect ends\n\
1629 when the current command terminates.\n\
1630 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1632 register Lisp_Object buffer
;
1634 register Lisp_Object buf
;
1635 buf
= Fget_buffer (buffer
);
1638 if (NILP (XBUFFER (buf
)->name
))
1639 error ("Selecting deleted buffer");
1640 set_buffer_internal (XBUFFER (buf
));
1644 /* Set the current buffer to BUFFER provided it is alive. */
1647 set_buffer_if_live (buffer
)
1650 if (! NILP (XBUFFER (buffer
)->name
))
1651 Fset_buffer (buffer
);
1655 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1656 Sbarf_if_buffer_read_only
, 0, 0, 0,
1657 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1660 if (!NILP (current_buffer
->read_only
)
1661 && NILP (Vinhibit_read_only
))
1662 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1666 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1667 "Put BUFFER at the end of the list of all buffers.\n\
1668 There it is the least likely candidate for `other-buffer' to return;\n\
1669 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1670 If BUFFER is nil or omitted, bury the current buffer.\n\
1671 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1672 selected window if it is displayed there.")
1674 register Lisp_Object buffer
;
1676 /* Figure out what buffer we're going to bury. */
1679 XSETBUFFER (buffer
, current_buffer
);
1681 /* If we're burying the current buffer, unshow it. */
1682 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
, Qnil
), Qnil
);
1688 buf1
= Fget_buffer (buffer
);
1694 /* Move buffer to the end of the buffer list. */
1696 register Lisp_Object aelt
, link
;
1698 aelt
= Frassq (buffer
, Vbuffer_alist
);
1699 link
= Fmemq (aelt
, Vbuffer_alist
);
1700 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1702 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1705 frames_bury_buffer (buffer
);
1710 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1711 "Delete the entire contents of the current buffer.\n\
1712 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1713 so the buffer is truly empty after this.")
1720 current_buffer
->last_window_start
= 1;
1721 /* Prevent warnings, or suspension of auto saving, that would happen
1722 if future size is less than past size. Use of erase-buffer
1723 implies that the future text is not really related to the past text. */
1724 XSETFASTINT (current_buffer
->save_length
, 0);
1729 validate_region (b
, e
)
1730 register Lisp_Object
*b
, *e
;
1732 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1733 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1735 if (XINT (*b
) > XINT (*e
))
1738 tem
= *b
; *b
= *e
; *e
= tem
;
1741 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1742 && XINT (*e
) <= ZV
))
1743 args_out_of_range (*b
, *e
);
1746 /* Advance BYTE_POS up to a character boundary
1747 and return the adjusted position. */
1750 advance_to_char_boundary (byte_pos
)
1755 if (byte_pos
== BEG
)
1756 /* Beginning of buffer is always a character boundary. */
1759 c
= FETCH_BYTE (byte_pos
);
1760 if (! CHAR_HEAD_P (c
))
1762 /* We should advance BYTE_POS only when C is a constituent of a
1763 multibyte sequence. */
1766 /* If C is a constituent of a multibyte sequence, BYTE_POS was
1767 surely advance to the correct character boundary. If C is
1768 not, BYTE_POS was unchanged. */
1774 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte
, Sset_buffer_multibyte
,
1776 "Set the multibyte flag of the current buffer to FLAG.\n\
1777 If FLAG is t, this makes the buffer a multibyte buffer.\n\
1778 If FLAG is nil, this makes the buffer a single-byte buffer.\n\
1779 The buffer contents remain unchanged as a sequence of bytes\n\
1780 but the contents viewed as characters do change.")
1784 Lisp_Object tail
, markers
;
1785 struct buffer
*other
;
1787 if (current_buffer
->base_buffer
)
1788 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
1790 /* Do nothing if nothing actually changes. */
1791 if (NILP (flag
) == NILP (current_buffer
->enable_multibyte_characters
))
1794 /* It would be better to update the list,
1795 but this is good enough for now. */
1796 if (! EQ (current_buffer
->undo_list
, Qt
))
1797 current_buffer
->undo_list
= Qnil
;
1799 /* If the cached position is for this buffer, clear it out. */
1800 clear_charpos_cache (current_buffer
);
1804 /* Do this first, so it can use CHAR_TO_BYTE
1805 to calculate the old correspondences. */
1806 set_intervals_multibyte (0);
1808 current_buffer
->enable_multibyte_characters
= Qnil
;
1814 TEMP_SET_PT_BOTH (PT_BYTE
, PT_BYTE
);
1816 tail
= BUF_MARKERS (current_buffer
);
1817 while (XSYMBOL (tail
) != XSYMBOL (Qnil
))
1819 XMARKER (tail
)->charpos
= XMARKER (tail
)->bytepos
;
1820 tail
= XMARKER (tail
)->chain
;
1825 /* Be sure not to have a multibyte sequence striding over the GAP.
1826 Ex: We change this: "...abc\201\241\241 _GAP_ \241\241\241..."
1827 to: "...abc _GAP_ \201\241\241\241\241\241..." */
1829 if (GPT_BYTE
> 1 && GPT_BYTE
< Z_BYTE
1830 && ! CHAR_HEAD_P (*(GAP_END_ADDR
)))
1832 unsigned char *p
= GPT_ADDR
- 1;
1834 while (! CHAR_HEAD_P (*p
) && p
> BEG_ADDR
) p
--;
1835 if (BASE_LEADING_CODE_P (*p
))
1837 int new_gpt
= GPT_BYTE
- (GPT_ADDR
- p
);
1839 move_gap_both (new_gpt
, new_gpt
);
1843 /* Do this first, so that chars_in_text asks the right question.
1844 set_intervals_multibyte needs it too. */
1845 current_buffer
->enable_multibyte_characters
= Qt
;
1847 GPT_BYTE
= advance_to_char_boundary (GPT_BYTE
);
1848 GPT
= chars_in_text (BEG_ADDR
, GPT_BYTE
- BEG_BYTE
) + BEG
;
1850 Z
= chars_in_text (GAP_END_ADDR
, Z_BYTE
- GPT_BYTE
) + GPT
;
1852 BEGV_BYTE
= advance_to_char_boundary (BEGV_BYTE
);
1853 if (BEGV_BYTE
> GPT_BYTE
)
1854 BEGV
= chars_in_text (GAP_END_ADDR
, BEGV_BYTE
- GPT_BYTE
) + GPT
;
1856 BEGV
= chars_in_text (BEG_ADDR
, BEGV_BYTE
- BEG_BYTE
) + BEG
;
1858 ZV_BYTE
= advance_to_char_boundary (ZV_BYTE
);
1859 if (ZV_BYTE
> GPT_BYTE
)
1860 ZV
= chars_in_text (GAP_END_ADDR
, ZV_BYTE
- GPT_BYTE
) + GPT
;
1862 ZV
= chars_in_text (BEG_ADDR
, ZV_BYTE
- BEG_BYTE
) + BEG
;
1865 int pt_byte
= advance_to_char_boundary (PT_BYTE
);
1868 if (pt_byte
> GPT_BYTE
)
1869 pt
= chars_in_text (GAP_END_ADDR
, pt_byte
- GPT_BYTE
) + GPT
;
1871 pt
= chars_in_text (BEG_ADDR
, pt_byte
- BEG_BYTE
) + BEG
;
1872 TEMP_SET_PT_BOTH (pt
, pt_byte
);
1875 tail
= markers
= BUF_MARKERS (current_buffer
);
1877 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
1878 getting confused by the markers that have not yet been updated.
1879 It is also a signal that it should never create a marker. */
1880 BUF_MARKERS (current_buffer
) = Qnil
;
1882 while (XSYMBOL (tail
) != XSYMBOL (Qnil
))
1884 XMARKER (tail
)->bytepos
1885 = advance_to_char_boundary (XMARKER (tail
)->bytepos
);
1886 XMARKER (tail
)->charpos
= BYTE_TO_CHAR (XMARKER (tail
)->bytepos
);
1888 tail
= XMARKER (tail
)->chain
;
1891 /* Make sure no markers were put on the chain
1892 while the chain value was incorrect. */
1893 if (! EQ (BUF_MARKERS (current_buffer
), Qnil
))
1896 BUF_MARKERS (current_buffer
) = markers
;
1898 /* Do this last, so it can calculate the new correspondences
1899 between chars and bytes. */
1900 set_intervals_multibyte (1);
1903 /* Changing the multibyteness of a buffer means that all windows
1904 showing that buffer must be updated thoroughly. */
1905 current_buffer
->prevent_redisplay_optimizations_p
= 1;
1906 ++windows_or_buffers_changed
;
1908 /* Copy this buffer's new multibyte status
1909 into all of its indirect buffers. */
1910 for (other
= all_buffers
; other
; other
= other
->next
)
1911 if (other
->base_buffer
== current_buffer
&& !NILP (other
->name
))
1913 other
->enable_multibyte_characters
1914 = current_buffer
->enable_multibyte_characters
;
1915 other
->prevent_redisplay_optimizations_p
= 1;
1921 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
1923 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1924 Most local variable bindings are eliminated so that the default values\n\
1925 become effective once more. Also, the syntax table is set from\n\
1926 `standard-syntax-table', the local keymap is set to nil,\n\
1927 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1928 This function also forces redisplay of the mode line.\n\
1930 Every function to select a new major mode starts by\n\
1931 calling this function.\n\n\
1932 As a special exception, local variables whose names have\n\
1933 a non-nil `permanent-local' property are not eliminated by this function.\n\
1935 The first thing this function does is run\n\
1936 the normal hook `change-major-mode-hook'.")
1939 register Lisp_Object alist
, sym
, tem
;
1942 if (!NILP (Vrun_hooks
))
1943 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
1944 oalist
= current_buffer
->local_var_alist
;
1946 /* Make sure none of the bindings in oalist
1947 remain swapped in, in their symbols. */
1949 swap_out_buffer_local_variables (current_buffer
);
1951 /* Actually eliminate all local bindings of this buffer. */
1953 reset_buffer_local_variables (current_buffer
, 0);
1955 /* Redisplay mode lines; we are changing major mode. */
1957 update_mode_lines
++;
1959 /* Any which are supposed to be permanent,
1960 make local again, with the same values they had. */
1962 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
1964 sym
= XCAR (XCAR (alist
));
1965 tem
= Fget (sym
, Qpermanent_local
);
1968 Fmake_local_variable (sym
);
1969 Fset (sym
, XCDR (XCAR (alist
)));
1973 /* Force mode-line redisplay. Useful here because all major mode
1974 commands call this function. */
1975 update_mode_lines
++;
1980 /* Make sure no local variables remain set up with buffer B
1981 for their current values. */
1984 swap_out_buffer_local_variables (b
)
1987 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
1989 XSETBUFFER (buffer
, b
);
1990 oalist
= b
->local_var_alist
;
1992 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
1994 sym
= XCAR (XCAR (alist
));
1996 /* Need not do anything if some other buffer's binding is now encached. */
1997 tem
= XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->buffer
;
1998 if (XBUFFER (tem
) == current_buffer
)
2000 /* Symbol is set up for this buffer's old local value.
2001 Set it up for the current buffer with the default value. */
2003 tem
= XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
;
2004 /* Store the symbol's current value into the alist entry
2005 it is currently set up for. This is so that, if the
2006 local is marked permanent, and we make it local again
2007 later in Fkill_all_local_variables, we don't lose the value. */
2009 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->realvalue
);
2010 /* Switch to the symbol's default-value alist entry. */
2012 /* Mark it as current for buffer B. */
2013 XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->buffer
= buffer
;
2014 /* Store the current value into any forwarding in the symbol. */
2015 store_symval_forwarding (sym
,
2016 XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->realvalue
,
2022 /* Find all the overlays in the current buffer that contain position POS.
2023 Return the number found, and store them in a vector in *VEC_PTR.
2024 Store in *LEN_PTR the size allocated for the vector.
2025 Store in *NEXT_PTR the next position after POS where an overlay starts,
2026 or ZV if there are no more overlays.
2027 Store in *PREV_PTR the previous position before POS where an overlay ends,
2028 or where an overlay starts which ends at or after POS;
2029 or BEGV if there are no such overlays.
2030 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2032 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2033 when this function is called.
2035 If EXTEND is non-zero, we make the vector bigger if necessary.
2036 If EXTEND is zero, we never extend the vector,
2037 and we store only as many overlays as will fit.
2038 But we still return the total number of overlays. */
2041 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2044 Lisp_Object
**vec_ptr
;
2049 Lisp_Object tail
, overlay
, start
, end
;
2052 Lisp_Object
*vec
= *vec_ptr
;
2055 int inhibit_storing
= 0;
2057 for (tail
= current_buffer
->overlays_before
;
2061 int startpos
, endpos
;
2063 overlay
= XCAR (tail
);
2065 start
= OVERLAY_START (overlay
);
2066 end
= OVERLAY_END (overlay
);
2067 endpos
= OVERLAY_POSITION (end
);
2074 startpos
= OVERLAY_POSITION (start
);
2075 /* This one ends at or after POS
2076 so its start counts for PREV_PTR if it's before POS. */
2077 if (prev
< startpos
&& startpos
< pos
)
2081 if (startpos
<= pos
)
2085 /* The supplied vector is full.
2086 Either make it bigger, or don't store any more in it. */
2089 /* Make it work with an initial len == 0. */
2094 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2098 inhibit_storing
= 1;
2101 if (!inhibit_storing
)
2103 /* Keep counting overlays even if we can't return them all. */
2106 else if (startpos
< next
)
2110 for (tail
= current_buffer
->overlays_after
;
2114 int startpos
, endpos
;
2116 overlay
= XCAR (tail
);
2118 start
= OVERLAY_START (overlay
);
2119 end
= OVERLAY_END (overlay
);
2120 startpos
= OVERLAY_POSITION (start
);
2123 if (startpos
< next
)
2127 endpos
= OVERLAY_POSITION (end
);
2134 *len_ptr
= len
*= 2;
2137 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2141 inhibit_storing
= 1;
2144 if (!inhibit_storing
)
2148 if (startpos
< pos
&& startpos
> prev
)
2151 else if (endpos
< pos
&& endpos
> prev
)
2153 else if (endpos
== pos
&& startpos
> prev
)
2164 /* Find all the overlays in the current buffer that overlap the range BEG-END
2165 or are empty at BEG.
2167 Return the number found, and store them in a vector in *VEC_PTR.
2168 Store in *LEN_PTR the size allocated for the vector.
2169 Store in *NEXT_PTR the next position after POS where an overlay starts,
2170 or ZV if there are no more overlays.
2171 Store in *PREV_PTR the previous position before POS where an overlay ends,
2172 or BEGV if there are no previous overlays.
2173 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2175 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2176 when this function is called.
2178 If EXTEND is non-zero, we make the vector bigger if necessary.
2179 If EXTEND is zero, we never extend the vector,
2180 and we store only as many overlays as will fit.
2181 But we still return the total number of overlays. */
2184 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2187 Lisp_Object
**vec_ptr
;
2192 Lisp_Object tail
, overlay
, ostart
, oend
;
2195 Lisp_Object
*vec
= *vec_ptr
;
2198 int inhibit_storing
= 0;
2200 for (tail
= current_buffer
->overlays_before
;
2204 int startpos
, endpos
;
2206 overlay
= XCAR (tail
);
2208 ostart
= OVERLAY_START (overlay
);
2209 oend
= OVERLAY_END (overlay
);
2210 endpos
= OVERLAY_POSITION (oend
);
2217 startpos
= OVERLAY_POSITION (ostart
);
2218 /* Count an interval if it either overlaps the range
2219 or is empty at the start of the range. */
2220 if ((beg
< endpos
&& startpos
< end
)
2221 || (startpos
== endpos
&& beg
== endpos
))
2225 /* The supplied vector is full.
2226 Either make it bigger, or don't store any more in it. */
2229 *len_ptr
= len
*= 2;
2230 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2234 inhibit_storing
= 1;
2237 if (!inhibit_storing
)
2239 /* Keep counting overlays even if we can't return them all. */
2242 else if (startpos
< next
)
2246 for (tail
= current_buffer
->overlays_after
;
2250 int startpos
, endpos
;
2252 overlay
= XCAR (tail
);
2254 ostart
= OVERLAY_START (overlay
);
2255 oend
= OVERLAY_END (overlay
);
2256 startpos
= OVERLAY_POSITION (ostart
);
2259 if (startpos
< next
)
2263 endpos
= OVERLAY_POSITION (oend
);
2264 /* Count an interval if it either overlaps the range
2265 or is empty at the start of the range. */
2266 if ((beg
< endpos
&& startpos
< end
)
2267 || (startpos
== endpos
&& beg
== endpos
))
2273 *len_ptr
= len
*= 2;
2274 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2278 inhibit_storing
= 1;
2281 if (!inhibit_storing
)
2285 else if (endpos
< beg
&& endpos
> prev
)
2296 /* Fast function to just test if we're at an overlay boundary. */
2298 overlay_touches_p (pos
)
2301 Lisp_Object tail
, overlay
;
2303 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
2308 overlay
= XCAR (tail
);
2309 if (!GC_OVERLAYP (overlay
))
2312 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2315 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2319 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
2324 overlay
= XCAR (tail
);
2325 if (!GC_OVERLAYP (overlay
))
2328 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2331 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2339 Lisp_Object overlay
;
2345 compare_overlays (v1
, v2
)
2346 const void *v1
, *v2
;
2348 const struct sortvec
*s1
= (const struct sortvec
*) v1
;
2349 const struct sortvec
*s2
= (const struct sortvec
*) v2
;
2350 if (s1
->priority
!= s2
->priority
)
2351 return s1
->priority
- s2
->priority
;
2352 if (s1
->beg
!= s2
->beg
)
2353 return s1
->beg
- s2
->beg
;
2354 if (s1
->end
!= s2
->end
)
2355 return s2
->end
- s1
->end
;
2359 /* Sort an array of overlays by priority. The array is modified in place.
2360 The return value is the new size; this may be smaller than the original
2361 size if some of the overlays were invalid or were window-specific. */
2363 sort_overlays (overlay_vec
, noverlays
, w
)
2364 Lisp_Object
*overlay_vec
;
2369 struct sortvec
*sortvec
;
2370 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2372 /* Put the valid and relevant overlays into sortvec. */
2374 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2377 Lisp_Object overlay
;
2379 overlay
= overlay_vec
[i
];
2380 if (OVERLAY_VALID (overlay
)
2381 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2382 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2384 /* If we're interested in a specific window, then ignore
2385 overlays that are limited to some other window. */
2390 window
= Foverlay_get (overlay
, Qwindow
);
2391 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2395 /* This overlay is good and counts: put it into sortvec. */
2396 sortvec
[j
].overlay
= overlay
;
2397 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2398 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2399 tem
= Foverlay_get (overlay
, Qpriority
);
2401 sortvec
[j
].priority
= XINT (tem
);
2403 sortvec
[j
].priority
= 0;
2409 /* Sort the overlays into the proper order: increasing priority. */
2412 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2414 for (i
= 0; i
< noverlays
; i
++)
2415 overlay_vec
[i
] = sortvec
[i
].overlay
;
2421 Lisp_Object string
, string2
;
2428 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2429 int size
; /* Allocated length of that array. */
2430 int used
; /* How much of the array is currently in use. */
2431 int bytes
; /* Total length of the strings in buf. */
2434 /* Buffers for storing information about the overlays touching a given
2435 position. These could be automatic variables in overlay_strings, but
2436 it's more efficient to hold onto the memory instead of repeatedly
2437 allocating and freeing it. */
2438 static struct sortstrlist overlay_heads
, overlay_tails
;
2439 static unsigned char *overlay_str_buf
;
2441 /* Allocated length of overlay_str_buf. */
2442 static int overlay_str_len
;
2444 /* A comparison function suitable for passing to qsort. */
2446 cmp_for_strings (as1
, as2
)
2449 struct sortstr
*s1
= (struct sortstr
*)as1
;
2450 struct sortstr
*s2
= (struct sortstr
*)as2
;
2451 if (s1
->size
!= s2
->size
)
2452 return s2
->size
- s1
->size
;
2453 if (s1
->priority
!= s2
->priority
)
2454 return s1
->priority
- s2
->priority
;
2459 record_overlay_string (ssl
, str
, str2
, pri
, size
)
2460 struct sortstrlist
*ssl
;
2461 Lisp_Object str
, str2
, pri
;
2466 if (ssl
->used
== ssl
->size
)
2472 ssl
->buf
= ((struct sortstr
*)
2473 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2475 ssl
->buf
[ssl
->used
].string
= str
;
2476 ssl
->buf
[ssl
->used
].string2
= str2
;
2477 ssl
->buf
[ssl
->used
].size
= size
;
2478 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2481 if (NILP (current_buffer
->enable_multibyte_characters
))
2482 nbytes
= XSTRING (str
)->size
;
2483 else if (! STRING_MULTIBYTE (str
))
2484 nbytes
= count_size_as_multibyte (XSTRING (str
)->data
,
2485 STRING_BYTES (XSTRING (str
)));
2487 nbytes
= STRING_BYTES (XSTRING (str
));
2489 ssl
->bytes
+= nbytes
;
2493 if (NILP (current_buffer
->enable_multibyte_characters
))
2494 nbytes
= XSTRING (str2
)->size
;
2495 else if (! STRING_MULTIBYTE (str2
))
2496 nbytes
= count_size_as_multibyte (XSTRING (str2
)->data
,
2497 STRING_BYTES (XSTRING (str2
)));
2499 nbytes
= STRING_BYTES (XSTRING (str2
));
2501 ssl
->bytes
+= nbytes
;
2505 /* Return the concatenation of the strings associated with overlays that
2506 begin or end at POS, ignoring overlays that are specific to a window
2507 other than W. The strings are concatenated in the appropriate order:
2508 shorter overlays nest inside longer ones, and higher priority inside
2509 lower. Normally all of the after-strings come first, but zero-sized
2510 overlays have their after-strings ride along with the before-strings
2511 because it would look strange to print them inside-out.
2513 Returns the string length, and stores the contents indirectly through
2514 PSTR, if that variable is non-null. The string may be overwritten by
2515 subsequent calls. */
2518 overlay_strings (pos
, w
, pstr
)
2521 unsigned char **pstr
;
2523 Lisp_Object ov
, overlay
, window
, str
;
2524 int startpos
, endpos
;
2525 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
2527 overlay_heads
.used
= overlay_heads
.bytes
= 0;
2528 overlay_tails
.used
= overlay_tails
.bytes
= 0;
2529 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
2531 overlay
= XCAR (ov
);
2532 if (!OVERLAYP (overlay
))
2535 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2536 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2539 if (endpos
!= pos
&& startpos
!= pos
)
2541 window
= Foverlay_get (overlay
, Qwindow
);
2542 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2545 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2546 record_overlay_string (&overlay_heads
, str
,
2548 ? Foverlay_get (overlay
, Qafter_string
)
2550 Foverlay_get (overlay
, Qpriority
),
2552 else if (endpos
== pos
2553 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2554 record_overlay_string (&overlay_tails
, str
, Qnil
,
2555 Foverlay_get (overlay
, Qpriority
),
2558 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
2560 overlay
= XCAR (ov
);
2561 if (!OVERLAYP (overlay
))
2564 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2565 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2568 if (endpos
!= pos
&& startpos
!= pos
)
2570 window
= Foverlay_get (overlay
, Qwindow
);
2571 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2574 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2575 record_overlay_string (&overlay_heads
, str
,
2577 ? Foverlay_get (overlay
, Qafter_string
)
2579 Foverlay_get (overlay
, Qpriority
),
2581 else if (endpos
== pos
2582 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2583 record_overlay_string (&overlay_tails
, str
, Qnil
,
2584 Foverlay_get (overlay
, Qpriority
),
2587 if (overlay_tails
.used
> 1)
2588 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
2590 if (overlay_heads
.used
> 1)
2591 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
2593 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
2598 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
2600 if (total
> overlay_str_len
)
2602 overlay_str_len
= total
;
2603 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
2606 p
= overlay_str_buf
;
2607 for (i
= overlay_tails
.used
; --i
>= 0;)
2610 tem
= overlay_tails
.buf
[i
].string
;
2611 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2612 STRING_BYTES (XSTRING (tem
)),
2613 STRING_MULTIBYTE (tem
), multibyte
);
2616 for (i
= 0; i
< overlay_heads
.used
; ++i
)
2619 tem
= overlay_heads
.buf
[i
].string
;
2620 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2621 STRING_BYTES (XSTRING (tem
)),
2622 STRING_MULTIBYTE (tem
), multibyte
);
2624 tem
= overlay_heads
.buf
[i
].string2
;
2627 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2628 STRING_BYTES (XSTRING (tem
)),
2629 STRING_MULTIBYTE (tem
), multibyte
);
2633 if (p
!= overlay_str_buf
+ total
)
2636 *pstr
= overlay_str_buf
;
2642 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2645 recenter_overlay_lists (buf
, pos
)
2649 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
2651 /* See if anything in overlays_before should move to overlays_after. */
2653 /* We don't strictly need prev in this loop; it should always be nil.
2654 But we use it for symmetry and in case that should cease to be true
2655 with some future change. */
2657 for (tail
= buf
->overlays_before
;
2659 prev
= tail
, tail
= next
)
2662 overlay
= XCAR (tail
);
2664 /* If the overlay is not valid, get rid of it. */
2665 if (!OVERLAY_VALID (overlay
))
2670 /* Splice the cons cell TAIL out of overlays_before. */
2674 buf
->overlays_before
= next
;
2680 beg
= OVERLAY_START (overlay
);
2681 end
= OVERLAY_END (overlay
);
2683 if (OVERLAY_POSITION (end
) > pos
)
2685 /* OVERLAY needs to be moved. */
2686 int where
= OVERLAY_POSITION (beg
);
2687 Lisp_Object other
, other_prev
;
2689 /* Splice the cons cell TAIL out of overlays_before. */
2693 buf
->overlays_before
= next
;
2695 /* Search thru overlays_after for where to put it. */
2697 for (other
= buf
->overlays_after
;
2699 other_prev
= other
, other
= XCDR (other
))
2701 Lisp_Object otherbeg
, otheroverlay
;
2703 otheroverlay
= XCAR (other
);
2704 if (! OVERLAY_VALID (otheroverlay
))
2707 otherbeg
= OVERLAY_START (otheroverlay
);
2708 if (OVERLAY_POSITION (otherbeg
) >= where
)
2712 /* Add TAIL to overlays_after before OTHER. */
2713 XCDR (tail
) = other
;
2714 if (!NILP (other_prev
))
2715 XCDR (other_prev
) = tail
;
2717 buf
->overlays_after
= tail
;
2721 /* We've reached the things that should stay in overlays_before.
2722 All the rest of overlays_before must end even earlier,
2727 /* See if anything in overlays_after should be in overlays_before. */
2729 for (tail
= buf
->overlays_after
;
2731 prev
= tail
, tail
= next
)
2734 overlay
= XCAR (tail
);
2736 /* If the overlay is not valid, get rid of it. */
2737 if (!OVERLAY_VALID (overlay
))
2742 /* Splice the cons cell TAIL out of overlays_after. */
2746 buf
->overlays_after
= next
;
2752 beg
= OVERLAY_START (overlay
);
2753 end
= OVERLAY_END (overlay
);
2755 /* Stop looking, when we know that nothing further
2756 can possibly end before POS. */
2757 if (OVERLAY_POSITION (beg
) > pos
)
2760 if (OVERLAY_POSITION (end
) <= pos
)
2762 /* OVERLAY needs to be moved. */
2763 int where
= OVERLAY_POSITION (end
);
2764 Lisp_Object other
, other_prev
;
2766 /* Splice the cons cell TAIL out of overlays_after. */
2770 buf
->overlays_after
= next
;
2772 /* Search thru overlays_before for where to put it. */
2774 for (other
= buf
->overlays_before
;
2776 other_prev
= other
, other
= XCDR (other
))
2778 Lisp_Object otherend
, otheroverlay
;
2780 otheroverlay
= XCAR (other
);
2781 if (! OVERLAY_VALID (otheroverlay
))
2784 otherend
= OVERLAY_END (otheroverlay
);
2785 if (OVERLAY_POSITION (otherend
) <= where
)
2789 /* Add TAIL to overlays_before before OTHER. */
2790 XCDR (tail
) = other
;
2791 if (!NILP (other_prev
))
2792 XCDR (other_prev
) = tail
;
2794 buf
->overlays_before
= tail
;
2799 XSETFASTINT (buf
->overlay_center
, pos
);
2803 adjust_overlays_for_insert (pos
, length
)
2807 /* After an insertion, the lists are still sorted properly,
2808 but we may need to update the value of the overlay center. */
2809 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
2810 XSETFASTINT (current_buffer
->overlay_center
,
2811 XFASTINT (current_buffer
->overlay_center
) + length
);
2815 adjust_overlays_for_delete (pos
, length
)
2819 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
2820 /* The deletion was to our right. No change needed; the before- and
2821 after-lists are still consistent. */
2823 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
2824 /* The deletion was to our left. We need to adjust the center value
2825 to account for the change in position, but the lists are consistent
2826 given the new value. */
2827 XSETFASTINT (current_buffer
->overlay_center
,
2828 XFASTINT (current_buffer
->overlay_center
) - length
);
2830 /* We're right in the middle. There might be things on the after-list
2831 that now belong on the before-list. Recentering will move them,
2832 and also update the center point. */
2833 recenter_overlay_lists (current_buffer
, pos
);
2836 /* Fix up overlays that were garbled as a result of permuting markers
2837 in the range START through END. Any overlay with at least one
2838 endpoint in this range will need to be unlinked from the overlay
2839 list and reinserted in its proper place.
2840 Such an overlay might even have negative size at this point.
2841 If so, we'll reverse the endpoints. Can you think of anything
2842 better to do in this situation? */
2844 fix_overlays_in_range (start
, end
)
2845 register int start
, end
;
2847 Lisp_Object overlay
;
2848 Lisp_Object before_list
, after_list
;
2849 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
2850 int startpos
, endpos
;
2852 /* This algorithm shifts links around instead of consing and GCing.
2853 The loop invariant is that before_list (resp. after_list) is a
2854 well-formed list except that its last element, the one that
2855 *pbefore (resp. *pafter) points to, is still uninitialized.
2856 So it's not a bug that before_list isn't initialized, although
2857 it may look strange. */
2858 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
2860 overlay
= XCAR (*ptail
);
2861 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2864 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2866 || (startpos
>= start
&& startpos
< end
))
2868 /* If the overlay is backwards, fix that now. */
2869 if (startpos
> endpos
)
2872 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
2874 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
2876 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2878 /* Add it to the end of the wrong list. Later on,
2879 recenter_overlay_lists will move it to the right place. */
2880 if (endpos
< XINT (current_buffer
->overlay_center
))
2883 pafter
= &XCDR (*ptail
);
2888 pbefore
= &XCDR (*ptail
);
2890 *ptail
= XCDR (*ptail
);
2893 ptail
= &XCDR (*ptail
);
2895 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
2897 overlay
= XCAR (*ptail
);
2898 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2899 if (startpos
>= end
)
2901 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2902 if (startpos
>= start
2903 || (endpos
>= start
&& endpos
< end
))
2905 if (startpos
> endpos
)
2908 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
2910 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
2912 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2914 if (endpos
< XINT (current_buffer
->overlay_center
))
2917 pafter
= &XCDR (*ptail
);
2922 pbefore
= &XCDR (*ptail
);
2924 *ptail
= XCDR (*ptail
);
2927 ptail
= &XCDR (*ptail
);
2930 /* Splice the constructed (wrong) lists into the buffer's lists,
2931 and let the recenter function make it sane again. */
2932 *pbefore
= current_buffer
->overlays_before
;
2933 current_buffer
->overlays_before
= before_list
;
2934 recenter_overlay_lists (current_buffer
,
2935 XINT (current_buffer
->overlay_center
));
2937 *pafter
= current_buffer
->overlays_after
;
2938 current_buffer
->overlays_after
= after_list
;
2939 recenter_overlay_lists (current_buffer
,
2940 XINT (current_buffer
->overlay_center
));
2943 /* We have two types of overlay: the one whose ending marker is
2944 after-insertion-marker (this is the usual case) and the one whose
2945 ending marker is before-insertion-marker. When `overlays_before'
2946 contains overlays of the latter type and the former type in this
2947 order and both overlays end at inserting position, inserting a text
2948 increases only the ending marker of the latter type, which results
2949 in incorrect ordering of `overlays_before'.
2951 This function fixes ordering of overlays in the slot
2952 `overlays_before' of the buffer *BP. Before the insertion, `point'
2953 was at PREV, and now is at POS. */
2956 fix_overlays_before (bp
, prev
, pos
)
2960 Lisp_Object
*tailp
= &bp
->overlays_before
;
2961 Lisp_Object
*right_place
;
2964 /* After the insertion, the several overlays may be in incorrect
2965 order. The possibility is that, in the list `overlays_before',
2966 an overlay which ends at POS appears after an overlay which ends
2967 at PREV. Since POS is greater than PREV, we must fix the
2968 ordering of these overlays, by moving overlays ends at POS before
2969 the overlays ends at PREV. */
2971 /* At first, find a place where disordered overlays should be linked
2972 in. It is where an overlay which end before POS exists. (i.e. an
2973 overlay whose ending marker is after-insertion-marker if disorder
2975 while (!NILP (*tailp
)
2976 && ((end
= OVERLAY_POSITION (OVERLAY_END (XCAR (*tailp
))))
2978 tailp
= &XCDR (*tailp
);
2980 /* If we don't find such an overlay,
2981 or the found one ends before PREV,
2982 or the found one is the last one in the list,
2983 we don't have to fix anything. */
2986 || NILP (XCDR (*tailp
)))
2989 right_place
= tailp
;
2990 tailp
= &XCDR (*tailp
);
2992 /* Now, end position of overlays in the list *TAILP should be before
2993 or equal to PREV. In the loop, an overlay which ends at POS is
2994 moved ahead to the place pointed by RIGHT_PLACE. If we found an
2995 overlay which ends before PREV, the remaining overlays are in
2997 while (!NILP (*tailp
))
2999 end
= OVERLAY_POSITION (OVERLAY_END (XCAR (*tailp
)));
3002 { /* This overlay is disordered. */
3003 Lisp_Object found
= *tailp
;
3005 /* Unlink the found overlay. */
3006 *tailp
= XCDR (found
);
3007 /* Move an overlay at RIGHT_PLACE to the next of the found one. */
3008 XCDR (found
) = *right_place
;
3009 /* Link it into the right place. */
3010 *right_place
= found
;
3012 else if (end
== prev
)
3013 tailp
= &XCDR (*tailp
);
3014 else /* No more disordered overlay. */
3019 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
3020 "Return t if OBJECT is an overlay.")
3024 return (OVERLAYP (object
) ? Qt
: Qnil
);
3027 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
3028 "Create a new overlay with range BEG to END in BUFFER.\n\
3029 If omitted, BUFFER defaults to the current buffer.\n\
3030 BEG and END may be integers or markers.\n\
3031 The fourth arg FRONT-ADVANCE, if non-nil, makes the\n\
3032 front delimiter advance when text is inserted there.\n\
3033 The fifth arg REAR-ADVANCE, if non-nil, makes the\n\
3034 rear delimiter advance when text is inserted there.")
3035 (beg
, end
, buffer
, front_advance
, rear_advance
)
3036 Lisp_Object beg
, end
, buffer
;
3037 Lisp_Object front_advance
, rear_advance
;
3039 Lisp_Object overlay
;
3043 XSETBUFFER (buffer
, current_buffer
);
3045 CHECK_BUFFER (buffer
, 2);
3047 && ! EQ (Fmarker_buffer (beg
), buffer
))
3048 error ("Marker points into wrong buffer");
3050 && ! EQ (Fmarker_buffer (end
), buffer
))
3051 error ("Marker points into wrong buffer");
3053 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
3054 CHECK_NUMBER_COERCE_MARKER (end
, 1);
3056 if (XINT (beg
) > XINT (end
))
3059 temp
= beg
; beg
= end
; end
= temp
;
3062 b
= XBUFFER (buffer
);
3064 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
3065 end
= Fset_marker (Fmake_marker (), end
, buffer
);
3067 if (!NILP (front_advance
))
3068 XMARKER (beg
)->insertion_type
= 1;
3069 if (!NILP (rear_advance
))
3070 XMARKER (end
)->insertion_type
= 1;
3072 overlay
= allocate_misc ();
3073 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
3074 XOVERLAY (overlay
)->start
= beg
;
3075 XOVERLAY (overlay
)->end
= end
;
3076 XOVERLAY (overlay
)->plist
= Qnil
;
3078 /* Put the new overlay on the wrong list. */
3079 end
= OVERLAY_END (overlay
);
3080 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
3081 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
3083 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
3085 /* This puts it in the right list, and in the right order. */
3086 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
3088 /* We don't need to redisplay the region covered by the overlay, because
3089 the overlay has no properties at the moment. */
3094 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3097 modify_overlay (buf
, start
, end
)
3107 start
= end
; end
= temp
;
3110 BUF_COMPUTE_UNCHANGED (buf
, start
, end
);
3112 /* If this is a buffer not in the selected window,
3113 we must do other windows. */
3114 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
3115 windows_or_buffers_changed
= 1;
3116 /* If multiple windows show this buffer, we must do other windows. */
3117 else if (buffer_shared
> 1)
3118 windows_or_buffers_changed
= 1;
3120 ++BUF_OVERLAY_MODIFF (buf
);
3124 Lisp_Object
Fdelete_overlay ();
3126 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
3127 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
3128 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
3129 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
3131 (overlay
, beg
, end
, buffer
)
3132 Lisp_Object overlay
, beg
, end
, buffer
;
3134 struct buffer
*b
, *ob
;
3135 Lisp_Object obuffer
;
3136 int count
= specpdl_ptr
- specpdl
;
3138 CHECK_OVERLAY (overlay
, 0);
3140 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3142 XSETBUFFER (buffer
, current_buffer
);
3143 CHECK_BUFFER (buffer
, 3);
3146 && ! EQ (Fmarker_buffer (beg
), buffer
))
3147 error ("Marker points into wrong buffer");
3149 && ! EQ (Fmarker_buffer (end
), buffer
))
3150 error ("Marker points into wrong buffer");
3152 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
3153 CHECK_NUMBER_COERCE_MARKER (end
, 1);
3155 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3156 return Fdelete_overlay (overlay
);
3158 if (XINT (beg
) > XINT (end
))
3161 temp
= beg
; beg
= end
; end
= temp
;
3164 specbind (Qinhibit_quit
, Qt
);
3166 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3167 b
= XBUFFER (buffer
);
3168 ob
= XBUFFER (obuffer
);
3170 /* If the overlay has changed buffers, do a thorough redisplay. */
3171 if (!EQ (buffer
, obuffer
))
3173 /* Redisplay where the overlay was. */
3174 if (!NILP (obuffer
))
3179 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3180 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3182 modify_overlay (ob
, o_beg
, o_end
);
3185 /* Redisplay where the overlay is going to be. */
3186 modify_overlay (b
, XINT (beg
), XINT (end
));
3189 /* Redisplay the area the overlay has just left, or just enclosed. */
3193 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3194 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3196 if (o_beg
== XINT (beg
))
3197 modify_overlay (b
, o_end
, XINT (end
));
3198 else if (o_end
== XINT (end
))
3199 modify_overlay (b
, o_beg
, XINT (beg
));
3202 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
3203 if (XINT (end
) > o_end
) o_end
= XINT (end
);
3204 modify_overlay (b
, o_beg
, o_end
);
3208 if (!NILP (obuffer
))
3210 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
3211 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
3214 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
3215 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
3217 /* Put the overlay on the wrong list. */
3218 end
= OVERLAY_END (overlay
);
3219 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
3220 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
3222 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
3224 /* This puts it in the right list, and in the right order. */
3225 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
3227 return unbind_to (count
, overlay
);
3230 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
3231 "Delete the overlay OVERLAY from its buffer.")
3233 Lisp_Object overlay
;
3237 int count
= specpdl_ptr
- specpdl
;
3239 CHECK_OVERLAY (overlay
, 0);
3241 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3245 b
= XBUFFER (buffer
);
3247 specbind (Qinhibit_quit
, Qt
);
3249 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
3250 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
3253 marker_position (OVERLAY_START (overlay
)),
3254 marker_position (OVERLAY_END (overlay
)));
3256 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
3257 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
3259 return unbind_to (count
, Qnil
);
3262 /* Overlay dissection functions. */
3264 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3265 "Return the position at which OVERLAY starts.")
3267 Lisp_Object overlay
;
3269 CHECK_OVERLAY (overlay
, 0);
3271 return (Fmarker_position (OVERLAY_START (overlay
)));
3274 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3275 "Return the position at which OVERLAY ends.")
3277 Lisp_Object overlay
;
3279 CHECK_OVERLAY (overlay
, 0);
3281 return (Fmarker_position (OVERLAY_END (overlay
)));
3284 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3285 "Return the buffer OVERLAY belongs to.")
3287 Lisp_Object overlay
;
3289 CHECK_OVERLAY (overlay
, 0);
3291 return Fmarker_buffer (OVERLAY_START (overlay
));
3294 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3295 "Return a list of the properties on OVERLAY.\n\
3296 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
3299 Lisp_Object overlay
;
3301 CHECK_OVERLAY (overlay
, 0);
3303 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3307 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3308 "Return a list of the overlays that contain position POS.")
3313 Lisp_Object
*overlay_vec
;
3317 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3320 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3322 /* Put all the overlays we want in a vector in overlay_vec.
3323 Store the length in len. */
3324 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3325 (int *) 0, (int *) 0);
3327 /* Make a list of them all. */
3328 result
= Flist (noverlays
, overlay_vec
);
3330 xfree (overlay_vec
);
3334 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3335 "Return a list of the overlays that overlap the region BEG ... END.\n\
3336 Overlap means that at least one character is contained within the overlay\n\
3337 and also contained within the specified region.\n\
3338 Empty overlays are included in the result if they are located at BEG\n\
3339 or between BEG and END.")
3341 Lisp_Object beg
, end
;
3344 Lisp_Object
*overlay_vec
;
3348 CHECK_NUMBER_COERCE_MARKER (beg
, 0);
3349 CHECK_NUMBER_COERCE_MARKER (end
, 0);
3352 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3354 /* Put all the overlays we want in a vector in overlay_vec.
3355 Store the length in len. */
3356 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3357 (int *) 0, (int *) 0);
3359 /* Make a list of them all. */
3360 result
= Flist (noverlays
, overlay_vec
);
3362 xfree (overlay_vec
);
3366 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3368 "Return the next position after POS where an overlay starts or ends.\n\
3369 If there are no more overlay boundaries after POS, return (point-max).")
3375 Lisp_Object
*overlay_vec
;
3379 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3382 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3384 /* Put all the overlays we want in a vector in overlay_vec.
3385 Store the length in len.
3386 endpos gets the position where the next overlay starts. */
3387 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3388 &endpos
, (int *) 0);
3390 /* If any of these overlays ends before endpos,
3391 use its ending point instead. */
3392 for (i
= 0; i
< noverlays
; i
++)
3397 oend
= OVERLAY_END (overlay_vec
[i
]);
3398 oendpos
= OVERLAY_POSITION (oend
);
3399 if (oendpos
< endpos
)
3403 xfree (overlay_vec
);
3404 return make_number (endpos
);
3407 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
3408 Sprevious_overlay_change
, 1, 1, 0,
3409 "Return the previous position before POS where an overlay starts or ends.\n\
3410 If there are no more overlay boundaries before POS, return (point-min).")
3416 Lisp_Object
*overlay_vec
;
3419 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3422 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3424 /* At beginning of buffer, we know the answer;
3425 avoid bug subtracting 1 below. */
3426 if (XINT (pos
) == BEGV
)
3429 /* Put all the overlays we want in a vector in overlay_vec.
3430 Store the length in len.
3431 prevpos gets the position of the previous change. */
3432 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3433 (int *) 0, &prevpos
);
3435 xfree (overlay_vec
);
3436 return make_number (prevpos
);
3439 /* These functions are for debugging overlays. */
3441 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
3442 "Return a pair of lists giving all the overlays of the current buffer.\n\
3443 The car has all the overlays before the overlay center;\n\
3444 the cdr has all the overlays after the overlay center.\n\
3445 Recentering overlays moves overlays between these lists.\n\
3446 The lists you get are copies, so that changing them has no effect.\n\
3447 However, the overlays you get are the real objects that the buffer uses.")
3450 Lisp_Object before
, after
;
3451 before
= current_buffer
->overlays_before
;
3453 before
= Fcopy_sequence (before
);
3454 after
= current_buffer
->overlays_after
;
3456 after
= Fcopy_sequence (after
);
3458 return Fcons (before
, after
);
3461 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
3462 "Recenter the overlays of the current buffer around position POS.")
3466 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3468 recenter_overlay_lists (current_buffer
, XINT (pos
));
3472 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
3473 "Get the property of overlay OVERLAY with property name PROP.")
3475 Lisp_Object overlay
, prop
;
3477 Lisp_Object plist
, fallback
;
3479 CHECK_OVERLAY (overlay
, 0);
3483 for (plist
= XOVERLAY (overlay
)->plist
;
3484 CONSP (plist
) && CONSP (XCDR (plist
));
3485 plist
= XCDR (XCDR (plist
)))
3487 if (EQ (XCAR (plist
), prop
))
3488 return XCAR (XCDR (plist
));
3489 else if (EQ (XCAR (plist
), Qcategory
))
3492 tem
= Fcar (Fcdr (plist
));
3494 fallback
= Fget (tem
, prop
);
3501 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
3502 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
3503 (overlay
, prop
, value
)
3504 Lisp_Object overlay
, prop
, value
;
3506 Lisp_Object tail
, buffer
;
3509 CHECK_OVERLAY (overlay
, 0);
3511 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3513 for (tail
= XOVERLAY (overlay
)->plist
;
3514 CONSP (tail
) && CONSP (XCDR (tail
));
3515 tail
= XCDR (XCDR (tail
)))
3516 if (EQ (XCAR (tail
), prop
))
3518 changed
= !EQ (XCAR (XCDR (tail
)), value
);
3519 XCAR (XCDR (tail
)) = value
;
3522 /* It wasn't in the list, so add it to the front. */
3523 changed
= !NILP (value
);
3524 XOVERLAY (overlay
)->plist
3525 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
3527 if (! NILP (buffer
))
3530 modify_overlay (XBUFFER (buffer
),
3531 marker_position (OVERLAY_START (overlay
)),
3532 marker_position (OVERLAY_END (overlay
)));
3533 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
3534 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
3535 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
3536 Fdelete_overlay (overlay
);
3541 /* Subroutine of report_overlay_modification. */
3543 /* Lisp vector holding overlay hook functions to call.
3544 Vector elements come in pairs.
3545 Each even-index element is a list of hook functions.
3546 The following odd-index element is the overlay they came from.
3548 Before the buffer change, we fill in this vector
3549 as we call overlay hook functions.
3550 After the buffer change, we get the functions to call from this vector.
3551 This way we always call the same functions before and after the change. */
3552 static Lisp_Object last_overlay_modification_hooks
;
3554 /* Number of elements actually used in last_overlay_modification_hooks. */
3555 static int last_overlay_modification_hooks_used
;
3557 /* Add one functionlist/overlay pair
3558 to the end of last_overlay_modification_hooks. */
3561 add_overlay_mod_hooklist (functionlist
, overlay
)
3562 Lisp_Object functionlist
, overlay
;
3564 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
3566 if (last_overlay_modification_hooks_used
== oldsize
)
3569 old
= last_overlay_modification_hooks
;
3570 last_overlay_modification_hooks
3571 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
3572 bcopy (XVECTOR (old
)->contents
,
3573 XVECTOR (last_overlay_modification_hooks
)->contents
,
3574 sizeof (Lisp_Object
) * oldsize
);
3576 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = functionlist
;
3577 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = overlay
;
3580 /* Run the modification-hooks of overlays that include
3581 any part of the text in START to END.
3582 If this change is an insertion, also
3583 run the insert-before-hooks of overlay starting at END,
3584 and the insert-after-hooks of overlay ending at START.
3586 This is called both before and after the modification.
3587 AFTER is nonzero when we call after the modification.
3589 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3590 When AFTER is nonzero, they are the start position,
3591 the position after the inserted new text,
3592 and the length of deleted or replaced old text. */
3595 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
3596 Lisp_Object start
, end
;
3598 Lisp_Object arg1
, arg2
, arg3
;
3600 Lisp_Object prop
, overlay
, tail
;
3601 /* 1 if this change is an insertion. */
3602 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
3604 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
3608 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
3612 /* Call the functions recorded in last_overlay_modification_hooks
3613 rather than scanning the overlays again.
3614 First copy the vector contents, in case some of these hooks
3615 do subsequent modification of the buffer. */
3616 int size
= last_overlay_modification_hooks_used
;
3617 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
3620 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
3621 copy
, size
* sizeof (Lisp_Object
));
3623 gcpro1
.nvars
= size
;
3625 for (i
= 0; i
< size
;)
3627 Lisp_Object prop
, overlay
;
3629 overlay
= copy
[i
++];
3630 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3636 /* We are being called before a change.
3637 Scan the overlays to find the functions to call. */
3638 last_overlay_modification_hooks_used
= 0;
3640 for (tail
= current_buffer
->overlays_before
;
3644 int startpos
, endpos
;
3645 Lisp_Object ostart
, oend
;
3647 overlay
= XCAR (tail
);
3649 ostart
= OVERLAY_START (overlay
);
3650 oend
= OVERLAY_END (overlay
);
3651 endpos
= OVERLAY_POSITION (oend
);
3652 if (XFASTINT (start
) > endpos
)
3654 startpos
= OVERLAY_POSITION (ostart
);
3655 if (insertion
&& (XFASTINT (start
) == startpos
3656 || XFASTINT (end
) == startpos
))
3658 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3661 /* Copy TAIL in case the hook recenters the overlay lists. */
3663 tail
= Fcopy_sequence (tail
);
3665 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3668 if (insertion
&& (XFASTINT (start
) == endpos
3669 || XFASTINT (end
) == endpos
))
3671 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3675 tail
= Fcopy_sequence (tail
);
3677 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3680 /* Test for intersecting intervals. This does the right thing
3681 for both insertion and deletion. */
3682 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3684 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3688 tail
= Fcopy_sequence (tail
);
3690 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3696 for (tail
= current_buffer
->overlays_after
;
3700 int startpos
, endpos
;
3701 Lisp_Object ostart
, oend
;
3703 overlay
= XCAR (tail
);
3705 ostart
= OVERLAY_START (overlay
);
3706 oend
= OVERLAY_END (overlay
);
3707 startpos
= OVERLAY_POSITION (ostart
);
3708 endpos
= OVERLAY_POSITION (oend
);
3709 if (XFASTINT (end
) < startpos
)
3711 if (insertion
&& (XFASTINT (start
) == startpos
3712 || XFASTINT (end
) == startpos
))
3714 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3718 tail
= Fcopy_sequence (tail
);
3720 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3723 if (insertion
&& (XFASTINT (start
) == endpos
3724 || XFASTINT (end
) == endpos
))
3726 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3730 tail
= Fcopy_sequence (tail
);
3732 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3735 /* Test for intersecting intervals. This does the right thing
3736 for both insertion and deletion. */
3737 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3739 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3743 tail
= Fcopy_sequence (tail
);
3745 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3754 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
3755 Lisp_Object list
, overlay
;
3757 Lisp_Object arg1
, arg2
, arg3
;
3759 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3761 GCPRO4 (list
, arg1
, arg2
, arg3
);
3763 add_overlay_mod_hooklist (list
, overlay
);
3765 while (!NILP (list
))
3768 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
3770 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
3776 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3779 evaporate_overlays (pos
)
3782 Lisp_Object tail
, overlay
, hit_list
;
3785 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
3786 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
3790 overlay
= XCAR (tail
);
3791 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3794 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
3795 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3796 hit_list
= Fcons (overlay
, hit_list
);
3799 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
3803 overlay
= XCAR (tail
);
3804 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3807 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
3808 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3809 hit_list
= Fcons (overlay
, hit_list
);
3811 for (; CONSP (hit_list
); hit_list
= XCDR (hit_list
))
3812 Fdelete_overlay (XCAR (hit_list
));
3815 /* Somebody has tried to store a value with an unacceptable type
3816 in the slot with offset OFFSET. */
3819 buffer_slot_type_mismatch (offset
)
3825 switch (XINT (BUFFER_LOCAL_TYPE (offset
)))
3828 type_name
= "integers";
3832 type_name
= "strings";
3836 type_name
= "symbols";
3843 sym
= BUFFER_LOCAL_SYMBOL (offset
);
3844 error ("Only %s should be stored in the buffer-local variable %s",
3845 type_name
, XSYMBOL (sym
)->name
->data
);
3854 bzero (buffer_permanent_local_flags
, sizeof buffer_permanent_local_flags
);
3856 /* Make sure all markable slots in buffer_defaults
3857 are initialized reasonably, so mark_buffer won't choke. */
3858 reset_buffer (&buffer_defaults
);
3859 reset_buffer_local_variables (&buffer_defaults
, 1);
3860 reset_buffer (&buffer_local_symbols
);
3861 reset_buffer_local_variables (&buffer_local_symbols
, 1);
3862 /* Prevent GC from getting confused. */
3863 buffer_defaults
.text
= &buffer_defaults
.own_text
;
3864 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
3865 BUF_INTERVALS (&buffer_defaults
) = 0;
3866 BUF_INTERVALS (&buffer_local_symbols
) = 0;
3867 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
3868 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
3870 /* Set up the default values of various buffer slots. */
3871 /* Must do these before making the first buffer! */
3873 /* real setup is done in loaddefs.el */
3874 buffer_defaults
.mode_line_format
= build_string ("%-");
3875 buffer_defaults
.header_line_format
= Qnil
;
3876 buffer_defaults
.abbrev_mode
= Qnil
;
3877 buffer_defaults
.overwrite_mode
= Qnil
;
3878 buffer_defaults
.case_fold_search
= Qt
;
3879 buffer_defaults
.auto_fill_function
= Qnil
;
3880 buffer_defaults
.selective_display
= Qnil
;
3882 buffer_defaults
.selective_display_ellipses
= Qt
;
3884 buffer_defaults
.abbrev_table
= Qnil
;
3885 buffer_defaults
.display_table
= Qnil
;
3886 buffer_defaults
.undo_list
= Qnil
;
3887 buffer_defaults
.mark_active
= Qnil
;
3888 buffer_defaults
.file_format
= Qnil
;
3889 buffer_defaults
.overlays_before
= Qnil
;
3890 buffer_defaults
.overlays_after
= Qnil
;
3891 XSETFASTINT (buffer_defaults
.overlay_center
, BEG
);
3893 XSETFASTINT (buffer_defaults
.tab_width
, 8);
3894 buffer_defaults
.truncate_lines
= Qnil
;
3895 buffer_defaults
.ctl_arrow
= Qt
;
3896 buffer_defaults
.direction_reversed
= Qnil
;
3899 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
3901 buffer_defaults
.enable_multibyte_characters
= Qt
;
3902 buffer_defaults
.buffer_file_coding_system
= Qnil
;
3903 XSETFASTINT (buffer_defaults
.fill_column
, 70);
3904 XSETFASTINT (buffer_defaults
.left_margin
, 0);
3905 buffer_defaults
.cache_long_line_scans
= Qnil
;
3906 buffer_defaults
.file_truename
= Qnil
;
3907 XSETFASTINT (buffer_defaults
.display_count
, 0);
3908 buffer_defaults
.indicate_empty_lines
= Qnil
;
3909 buffer_defaults
.scroll_up_aggressively
= Qnil
;
3910 buffer_defaults
.scroll_down_aggressively
= Qnil
;
3911 buffer_defaults
.display_time
= Qnil
;
3913 /* Assign the local-flags to the slots that have default values.
3914 The local flag is a bit that is used in the buffer
3915 to say that it has its own local value for the slot.
3916 The local flag bits are in the local_var_flags slot of the buffer. */
3918 /* Nothing can work if this isn't true */
3919 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
3921 /* 0 means not a lisp var, -1 means always local, else mask */
3922 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
3923 XSETINT (buffer_local_flags
.filename
, -1);
3924 XSETINT (buffer_local_flags
.directory
, -1);
3925 XSETINT (buffer_local_flags
.backed_up
, -1);
3926 XSETINT (buffer_local_flags
.save_length
, -1);
3927 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
3928 XSETINT (buffer_local_flags
.read_only
, -1);
3929 XSETINT (buffer_local_flags
.major_mode
, -1);
3930 XSETINT (buffer_local_flags
.mode_name
, -1);
3931 XSETINT (buffer_local_flags
.undo_list
, -1);
3932 XSETINT (buffer_local_flags
.mark_active
, -1);
3933 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
3934 XSETINT (buffer_local_flags
.file_truename
, -1);
3935 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
3936 XSETINT (buffer_local_flags
.file_format
, -1);
3937 XSETINT (buffer_local_flags
.display_count
, -1);
3938 XSETINT (buffer_local_flags
.display_time
, -1);
3939 XSETINT (buffer_local_flags
.enable_multibyte_characters
, -1);
3942 XSETFASTINT (buffer_local_flags
.mode_line_format
, idx
); ++idx
;
3943 XSETFASTINT (buffer_local_flags
.abbrev_mode
, idx
); ++idx
;
3944 XSETFASTINT (buffer_local_flags
.overwrite_mode
, idx
); ++idx
;
3945 XSETFASTINT (buffer_local_flags
.case_fold_search
, idx
); ++idx
;
3946 XSETFASTINT (buffer_local_flags
.auto_fill_function
, idx
); ++idx
;
3947 XSETFASTINT (buffer_local_flags
.selective_display
, idx
); ++idx
;
3949 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, idx
); ++idx
;
3951 XSETFASTINT (buffer_local_flags
.tab_width
, idx
); ++idx
;
3952 XSETFASTINT (buffer_local_flags
.truncate_lines
, idx
); ++idx
;
3953 XSETFASTINT (buffer_local_flags
.ctl_arrow
, idx
); ++idx
;
3954 XSETFASTINT (buffer_local_flags
.fill_column
, idx
); ++idx
;
3955 XSETFASTINT (buffer_local_flags
.left_margin
, idx
); ++idx
;
3956 XSETFASTINT (buffer_local_flags
.abbrev_table
, idx
); ++idx
;
3957 XSETFASTINT (buffer_local_flags
.display_table
, idx
); ++idx
;
3959 XSETFASTINT (buffer_local_flags
.buffer_file_type
, idx
);
3960 /* Make this one a permanent local. */
3961 buffer_permanent_local_flags
[idx
++] = 1;
3963 XSETFASTINT (buffer_local_flags
.syntax_table
, idx
); ++idx
;
3964 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, idx
); ++idx
;
3965 XSETFASTINT (buffer_local_flags
.category_table
, idx
); ++idx
;
3966 XSETFASTINT (buffer_local_flags
.direction_reversed
, idx
); ++idx
;
3967 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, idx
);
3968 /* Make this one a permanent local. */
3969 buffer_permanent_local_flags
[idx
++] = 1;
3970 XSETFASTINT (buffer_local_flags
.left_margin_width
, idx
); ++idx
;
3971 XSETFASTINT (buffer_local_flags
.right_margin_width
, idx
); ++idx
;
3972 XSETFASTINT (buffer_local_flags
.indicate_empty_lines
, idx
); ++idx
;
3973 XSETFASTINT (buffer_local_flags
.scroll_up_aggressively
, idx
); ++idx
;
3974 XSETFASTINT (buffer_local_flags
.scroll_down_aggressively
, idx
); ++idx
;
3975 XSETFASTINT (buffer_local_flags
.header_line_format
, idx
); ++idx
;
3977 /* Need more room? */
3978 if (idx
>= MAX_BUFFER_LOCAL_VARS
)
3980 max_buffer_local_idx
= idx
;
3982 Vbuffer_alist
= Qnil
;
3986 QSFundamental
= build_string ("Fundamental");
3988 Qfundamental_mode
= intern ("fundamental-mode");
3989 buffer_defaults
.major_mode
= Qfundamental_mode
;
3991 Qmode_class
= intern ("mode-class");
3993 Qprotected_field
= intern ("protected-field");
3995 Qpermanent_local
= intern ("permanent-local");
3997 Qkill_buffer_hook
= intern ("kill-buffer-hook");
3999 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
4001 /* super-magic invisible buffer */
4002 Vbuffer_alist
= Qnil
;
4004 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
4006 inhibit_modification_hooks
= 0;
4012 char buf
[MAXPATHLEN
+1];
4014 struct stat dotstat
, pwdstat
;
4018 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
4019 if (NILP (buffer_defaults
.enable_multibyte_characters
))
4020 Fset_buffer_multibyte (Qnil
);
4022 /* If PWD is accurate, use it instead of calling getwd. This is faster
4023 when PWD is right, and may avoid a fatal error. */
4024 if ((pwd
= getenv ("PWD")) != 0
4025 && (IS_DIRECTORY_SEP (*pwd
) || (*pwd
&& IS_DEVICE_SEP (pwd
[1])))
4026 && stat (pwd
, &pwdstat
) == 0
4027 && stat (".", &dotstat
) == 0
4028 && dotstat
.st_ino
== pwdstat
.st_ino
4029 && dotstat
.st_dev
== pwdstat
.st_dev
4030 && strlen (pwd
) < MAXPATHLEN
)
4033 else if (getcwd (buf
, MAXPATHLEN
+1) == 0)
4034 fatal ("`getcwd' failed: %s\n", strerror (errno
));
4036 else if (getwd (buf
) == 0)
4037 fatal ("`getwd' failed: %s\n", buf
);
4041 /* Maybe this should really use some standard subroutine
4042 whose definition is filename syntax dependent. */
4044 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
4046 buf
[rc
] = DIRECTORY_SEP
;
4049 #endif /* not VMS */
4051 current_buffer
->directory
= build_string (buf
);
4053 /* Add /: to the front of the name
4054 if it would otherwise be treated as magic. */
4055 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
4057 /* If the default dir is just /, TEMP is non-nil
4058 because of the ange-ftp completion handler.
4059 However, it is not necessary to turn / into /:/.
4060 So avoid doing that. */
4061 && strcmp ("/", XSTRING (current_buffer
->directory
)->data
))
4062 current_buffer
->directory
4063 = concat2 (build_string ("/:"), current_buffer
->directory
);
4065 temp
= get_minibuffer (0);
4066 XBUFFER (temp
)->directory
= current_buffer
->directory
;
4069 /* initialize the buffer routines */
4073 staticpro (&last_overlay_modification_hooks
);
4074 last_overlay_modification_hooks
4075 = Fmake_vector (make_number (10), Qnil
);
4077 staticpro (&Vbuffer_defaults
);
4078 staticpro (&Vbuffer_local_symbols
);
4079 staticpro (&Qfundamental_mode
);
4080 staticpro (&Qmode_class
);
4081 staticpro (&QSFundamental
);
4082 staticpro (&Vbuffer_alist
);
4083 staticpro (&Qprotected_field
);
4084 staticpro (&Qpermanent_local
);
4085 staticpro (&Qkill_buffer_hook
);
4086 Qoverlayp
= intern ("overlayp");
4087 staticpro (&Qoverlayp
);
4088 Qevaporate
= intern ("evaporate");
4089 staticpro (&Qevaporate
);
4090 Qmodification_hooks
= intern ("modification-hooks");
4091 staticpro (&Qmodification_hooks
);
4092 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
4093 staticpro (&Qinsert_in_front_hooks
);
4094 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
4095 staticpro (&Qinsert_behind_hooks
);
4096 Qget_file_buffer
= intern ("get-file-buffer");
4097 staticpro (&Qget_file_buffer
);
4098 Qpriority
= intern ("priority");
4099 staticpro (&Qpriority
);
4100 Qwindow
= intern ("window");
4101 staticpro (&Qwindow
);
4102 Qbefore_string
= intern ("before-string");
4103 staticpro (&Qbefore_string
);
4104 Qafter_string
= intern ("after-string");
4105 staticpro (&Qafter_string
);
4106 Qfirst_change_hook
= intern ("first-change-hook");
4107 staticpro (&Qfirst_change_hook
);
4108 Qbefore_change_functions
= intern ("before-change-functions");
4109 staticpro (&Qbefore_change_functions
);
4110 Qafter_change_functions
= intern ("after-change-functions");
4111 staticpro (&Qafter_change_functions
);
4113 Fput (Qprotected_field
, Qerror_conditions
,
4114 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
4115 Fput (Qprotected_field
, Qerror_message
,
4116 build_string ("Attempt to modify a protected field"));
4118 /* All these use DEFVAR_LISP_NOPRO because the slots in
4119 buffer_defaults will all be marked via Vbuffer_defaults. */
4121 DEFVAR_LISP_NOPRO ("default-mode-line-format",
4122 &buffer_defaults
.mode_line_format
,
4123 "Default value of `mode-line-format' for buffers that don't override it.\n\
4124 This is the same as (default-value 'mode-line-format).");
4126 DEFVAR_LISP_NOPRO ("default-header-line-format",
4127 &buffer_defaults
.header_line_format
,
4128 "Default value of `header-line-format' for buffers that don't override it.\n\
4129 This is the same as (default-value 'header-line-format).");
4131 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
4132 &buffer_defaults
.abbrev_mode
,
4133 "Default value of `abbrev-mode' for buffers that do not override it.\n\
4134 This is the same as (default-value 'abbrev-mode).");
4136 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
4137 &buffer_defaults
.ctl_arrow
,
4138 "Default value of `ctl-arrow' for buffers that do not override it.\n\
4139 This is the same as (default-value 'ctl-arrow).");
4141 DEFVAR_LISP_NOPRO ("default-direction-reversed",
4142 &buffer_defaults
.direction_reversed
,
4143 "Default value of `direction_reversed' for buffers that do not override it.\n\
4144 This is the same as (default-value 'direction-reversed).");
4146 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
4147 &buffer_defaults
.enable_multibyte_characters
,
4148 "*Default value of `enable-multibyte-characters' for buffers not overriding it.\n\
4149 This is the same as (default-value 'enable-multibyte-characters).");
4151 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
4152 &buffer_defaults
.buffer_file_coding_system
,
4153 "Default value of `buffer-file-coding-system' for buffers not overriding it.\n\
4154 This is the same as (default-value 'buffer-file-coding-system).");
4156 DEFVAR_LISP_NOPRO ("default-truncate-lines",
4157 &buffer_defaults
.truncate_lines
,
4158 "Default value of `truncate-lines' for buffers that do not override it.\n\
4159 This is the same as (default-value 'truncate-lines).");
4161 DEFVAR_LISP_NOPRO ("default-fill-column",
4162 &buffer_defaults
.fill_column
,
4163 "Default value of `fill-column' for buffers that do not override it.\n\
4164 This is the same as (default-value 'fill-column).");
4166 DEFVAR_LISP_NOPRO ("default-left-margin",
4167 &buffer_defaults
.left_margin
,
4168 "Default value of `left-margin' for buffers that do not override it.\n\
4169 This is the same as (default-value 'left-margin).");
4171 DEFVAR_LISP_NOPRO ("default-tab-width",
4172 &buffer_defaults
.tab_width
,
4173 "Default value of `tab-width' for buffers that do not override it.\n\
4174 This is the same as (default-value 'tab-width).");
4176 DEFVAR_LISP_NOPRO ("default-case-fold-search",
4177 &buffer_defaults
.case_fold_search
,
4178 "Default value of `case-fold-search' for buffers that don't override it.\n\
4179 This is the same as (default-value 'case-fold-search).");
4182 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
4183 &buffer_defaults
.buffer_file_type
,
4184 "Default file type for buffers that do not override it.\n\
4185 This is the same as (default-value 'buffer-file-type).\n\
4186 The file type is nil for text, t for binary.");
4189 DEFVAR_LISP_NOPRO ("default-left-margin-width",
4190 &buffer_defaults
.left_margin_width
,
4191 "Default value of `left-margin-width' for buffers that don't override it.\n\
4192 This is the same as (default-value 'left-margin-width).");
4194 DEFVAR_LISP_NOPRO ("default-right-margin-width",
4195 &buffer_defaults
.right_margin_width
,
4196 "Default value of `right_margin_width' for buffers that don't override it.\n\
4197 This is the same as (default-value 'right-margin-width).");
4199 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines",
4200 &buffer_defaults
.indicate_empty_lines
,
4201 "Default value of `indicate-empty-lines' for buffers that don't override it.\n\
4202 This is the same as (default-value 'indicate-empty-lines).");
4204 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively",
4205 &buffer_defaults
.scroll_up_aggressively
,
4206 "Default value of `scroll-up-aggressively' for buffers that\n\
4207 don't override it. This is the same as (default-value\n\
4208 'scroll-up-aggressively).");
4210 DEFVAR_LISP_NOPRO ("default-scroll-down-aggressively",
4211 &buffer_defaults
.scroll_down_aggressively
,
4212 "Default value of `scroll-down-aggressively' for buffers that\n\
4213 don't override it. This is the same as (default-value\n\
4214 'scroll-down-aggressively).");
4216 DEFVAR_PER_BUFFER ("header-line-format",
4217 ¤t_buffer
->header_line_format
,
4219 "Analogous to `mode-line-format', but for a mode line displayed\n\
4220 at the top of windows.");
4222 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
4225 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
4226 But make-docfile finds it!
4227 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
4229 "Template for displaying mode line for current buffer.\n\
4230 Each buffer has its own value of this variable.\n\
4231 Value may be nil, a string, a symbol or a list or cons cell.\n\
4232 A value of nil means don't display a mode line.\n\
4233 For a symbol, its value is used (but it is ignored if t or nil).\n\
4234 A string appearing directly as the value of a symbol is processed verbatim\n\
4235 in that the %-constructs below are not recognized.\n\
4236 For a list of the form `(:eval FORM)', FORM is evaluated and the result\n\
4237 is used as a mode line element.\n\
4238 For a list whose car is a symbol, the symbol's value is taken,\n\
4239 and if that is non-nil, the cadr of the list is processed recursively.\n\
4240 Otherwise, the caddr of the list (if there is one) is processed.\n\
4241 For a list whose car is a string or list, each element is processed\n\
4242 recursively and the results are effectively concatenated.\n\
4243 For a list whose car is an integer, the cdr of the list is processed\n\
4244 and padded (if the number is positive) or truncated (if negative)\n\
4245 to the width specified by that number.\n\
4246 A string is printed verbatim in the mode line except for %-constructs:\n\
4247 (%-constructs are allowed when the string is the entire mode-line-format\n\
4248 or when it is found in a cons-cell or a list)\n\
4249 %b -- print buffer name. %f -- print visited file name.\n\
4250 %F -- print frame name.\n\
4251 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
4252 %& is like %*, but ignore read-only-ness.\n\
4253 % means buffer is read-only and * means it is modified.\n\
4254 For a modified read-only buffer, %* gives % and %+ gives *.\n\
4255 %s -- print process status. %l -- print the current line number.\n\
4256 %c -- print the current column number (this makes editing slower).\n\
4257 To make the column number update correctly in all cases,\n\
4258 `column-number-mode' must be non-nil.\n\
4259 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
4260 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
4261 or print Bottom or All.\n\
4262 %m -- print the mode name.\n\
4263 %n -- print Narrow if appropriate.\n\
4264 %z -- print mnemonics of buffer, terminal, and keyboard coding systems.\n\
4265 %Z -- like %z, but including the end-of-line format.\n\
4266 %[ -- print one [ for each recursive editing level. %] similar.\n\
4267 %% -- print %. %- -- print infinitely many dashes.\n\
4268 Decimal digits after the % specify field width to which to pad.");
4271 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
4272 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
4273 nil here means use current buffer's major mode.");
4275 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
4276 make_number (Lisp_Symbol
),
4277 "Symbol for current buffer's major mode.");
4279 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
4280 make_number (Lisp_String
),
4281 "Pretty name of current buffer's major mode (a string).");
4283 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
4284 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
4285 Automatically becomes buffer-local when set in any fashion.");
4287 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
4289 "*Non-nil if searches and matches should ignore case.\n\
4290 Automatically becomes buffer-local when set in any fashion.");
4292 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
4293 make_number (Lisp_Int
),
4294 "*Column beyond which automatic line-wrapping should happen.\n\
4295 Automatically becomes buffer-local when set in any fashion.");
4297 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
4298 make_number (Lisp_Int
),
4299 "*Column for the default indent-line-function to indent to.\n\
4300 Linefeed indents to this column in Fundamental mode.\n\
4301 Automatically becomes buffer-local when set in any fashion.");
4303 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
4304 make_number (Lisp_Int
),
4305 "*Distance between tab stops (for display of tab characters), in columns.\n\
4306 Automatically becomes buffer-local when set in any fashion.");
4308 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
4309 "*Non-nil means display control chars with uparrow.\n\
4310 A value of nil means use backslash and octal digits.\n\
4311 Automatically becomes buffer-local when set in any fashion.\n\
4312 This variable does not apply to characters whose display is specified\n\
4313 in the current display table (if there is one).");
4315 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
4316 ¤t_buffer
->enable_multibyte_characters
,
4318 "Non-nil means the buffer contents are regarded as multi-byte characters.\n\
4319 Otherwise they are regarded as unibyte. This affects the display,\n\
4320 file I/O and the behavior of various editing commands.\n\
4322 This variable is buffer-local but you cannot set it directly;\n\
4323 use the function `set-buffer-multibyte' to change a buffer's representation.\n\
4324 Changing its default value with `setq-default' is supported.\n\
4325 See also variable `default-enable-multibyte-characters' and Info node\n\
4326 `(elisp)Text Representations'.");
4328 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
4329 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
4330 "Coding system to be used for encoding the buffer contents on saving.\n\
4331 This variable applies to saving the buffer, and also to `write-region'\n\
4332 and other functions that use `write-region'.\n\
4333 It does not apply to sending output to subprocesses, however.\n\
4335 If this is nil, the buffer is saved without any code conversion\n\
4336 unless some coding system is specified in `file-coding-system-alist'\n\
4337 for the buffer file.\n\
4339 The variable `coding-system-for-write', if non-nil, overrides this variable.\n\
4341 This variable is never applied to a way of decoding\n\
4342 a file while reading it.");
4344 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
4346 "*Non-nil means lines in the buffer are displayed right to left.");
4348 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
4349 "*Non-nil means do not display continuation lines;\n\
4350 give each line of text one screen line.\n\
4351 Automatically becomes buffer-local when set in any fashion.\n\
4353 Note that this is overridden by the variable\n\
4354 `truncate-partial-width-windows' if that variable is non-nil\n\
4355 and this buffer is not full-frame width.");
4358 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
4360 "Non-nil if the visited file is a binary file.\n\
4361 This variable is meaningful on MS-DOG and Windows NT.\n\
4362 On those systems, it is automatically local in every buffer.\n\
4363 On other systems, this variable is normally always nil.");
4366 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
4367 make_number (Lisp_String
),
4368 "Name of default directory of current buffer. Should end with slash.\n\
4369 Each buffer has its own value of this variable.");
4371 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
4373 "Function called (if non-nil) to perform auto-fill.\n\
4374 It is called after self-inserting a space or newline.\n\
4375 Each buffer has its own value of this variable.\n\
4376 NOTE: This variable is not a hook;\n\
4377 its value may not be a list of functions.");
4379 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
4380 make_number (Lisp_String
),
4381 "Name of file visited in current buffer, or nil if not visiting a file.\n\
4382 Each buffer has its own value of this variable.");
4384 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
4385 make_number (Lisp_String
),
4386 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
4387 The truename of a file is calculated by `file-truename'\n\
4388 and then abbreviated with `abbreviate-file-name'.\n\
4389 Each buffer has its own value of this variable.");
4391 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
4392 ¤t_buffer
->auto_save_file_name
,
4393 make_number (Lisp_String
),
4394 "Name of file for auto-saving current buffer,\n\
4395 or nil if buffer should not be auto-saved.\n\
4396 Each buffer has its own value of this variable.");
4398 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
4399 "Non-nil if this buffer is read-only.\n\
4400 Each buffer has its own value of this variable.");
4402 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
4403 "Non-nil if this buffer's file has been backed up.\n\
4404 Backing up is done before the first time the file is saved.\n\
4405 Each buffer has its own value of this variable.");
4407 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
4408 make_number (Lisp_Int
),
4409 "Length of current buffer when last read in, saved or auto-saved.\n\
4411 Each buffer has its own value of this variable.");
4413 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
4415 "Non-nil enables selective display:\n\
4416 Integer N as value means display only lines\n\
4417 that start with less than n columns of space.\n\
4418 A value of t means, after a ^M, all the rest of the line is invisible.\n\
4419 Then ^M's in the file are written into files as newlines.\n\n\
4420 Automatically becomes buffer-local when set in any fashion.");
4423 DEFVAR_PER_BUFFER ("selective-display-ellipses",
4424 ¤t_buffer
->selective_display_ellipses
,
4426 "t means display ... on previous line when a line is invisible.\n\
4427 Automatically becomes buffer-local when set in any fashion.");
4430 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
4431 "Non-nil if self-insertion should replace existing text.\n\
4432 The value should be one of `overwrite-mode-textual',\n\
4433 `overwrite-mode-binary', or nil.\n\
4434 If it is `overwrite-mode-textual', self-insertion still\n\
4435 inserts at the end of a line, and inserts when point is before a tab,\n\
4436 until the tab is filled in.\n\
4437 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
4438 Automatically becomes buffer-local when set in any fashion.");
4440 #if 0 /* The doc string is too long for some compilers,
4441 but make-docfile can find it in this comment. */
4442 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4444 "Display table that controls display of the contents of current buffer.\n\
4445 Automatically becomes buffer-local when set in any fashion.\n\
4446 The display table is a char-table created with `make-display-table'.\n\
4447 The ordinary char-table elements control how to display each possible text\n\
4448 character. Each value should be a vector of characters or nil;\n\
4449 nil means display the character in the default fashion.\n\
4450 There are six extra slots to control the display of\n\
4451 the end of a truncated screen line (extra-slot 0, a single character);\n\
4452 the end of a continued line (extra-slot 1, a single character);\n\
4453 the escape character used to display character codes in octal\n\
4454 (extra-slot 2, a single character);\n\
4455 the character used as an arrow for control characters (extra-slot 3,\n\
4456 a single character);\n\
4457 the decoration indicating the presence of invisible lines (extra-slot 4,\n\
4458 a vector of characters);\n\
4459 the character used to draw the border between side-by-side windows\n\
4460 (extra-slot 5, a single character).\n\
4461 See also the functions `display-table-slot' and `set-display-table-slot'.\n\
4462 If this variable is nil, the value of `standard-display-table' is used.\n\
4463 Each window can have its own, overriding display table.");
4465 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4468 DEFVAR_PER_BUFFER ("left-margin-width", ¤t_buffer
->left_margin_width
,
4470 "*Width of left marginal area for display of a buffer.\n\
4471 Automatically becomes buffer-local when set in any fashion.\n\
4472 A value of nil means no marginal area.");
4474 DEFVAR_PER_BUFFER ("right-margin-width", ¤t_buffer
->right_margin_width
,
4476 "*Width of right marginal area for display of a buffer.\n\
4477 Automatically becomes buffer-local when set in any fashion.\n\
4478 A value of nil means no marginal area.");
4480 DEFVAR_PER_BUFFER ("indicate-empty-lines",
4481 ¤t_buffer
->indicate_empty_lines
, Qnil
,
4482 "*Visually indicate empty lines after the buffer end.\n\
4483 If non-nil, a bitmap is displayed in the left fringe of a window on\n\
4485 Automatically becomes buffer-local when set in any fashion.\n");
4487 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
4488 ¤t_buffer
->scroll_up_aggressively
, Qnil
,
4489 "*If a number, scroll display up aggressively.\n\
4490 If scrolling a window because point is above the window start, choose\n\
4491 a new window start so that point ends up that fraction of the window's\n\
4492 height from the bottom of the window.\n\
4493 Automatically becomes buffer-local when set in any fashion.");
4495 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
4496 ¤t_buffer
->scroll_down_aggressively
, Qnil
,
4497 "*If a number, scroll display down aggressively.\n\
4498 If scrolling a window because point is below the window end, choose\n\
4499 a new window start so that point ends up that fraction of the window's\n\
4500 height from the top of the window.\n\
4501 Automatically becomes buffer-local when set in any fashion.");
4503 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
4506 DEFVAR_LISP ("before-change-function", &Vbefore_change_function
,
4507 "If non-nil, a function to call before each text change (obsolete).\n\
4508 Two arguments are passed to the function: the positions of\n\
4509 the beginning and end of the range of old text to be changed.\n\
4510 \(For an insertion, the beginning and end are at the same place.)\n\
4511 No information is given about the length of the text after the change.\n\
4513 Buffer changes made while executing the `before-change-function'\n\
4514 don't call any before-change or after-change functions.\n\
4515 That's because these variables are temporarily set to nil.\n\
4516 As a result, a hook function cannot straightforwardly alter the value of\n\
4517 these variables. See the Emacs Lisp manual for a way of\n\
4518 accomplishing an equivalent result by using other variables.\n\n\
4519 This variable is obsolete; use `before-change-functions' instead.");
4520 Vbefore_change_function
= Qnil
;
4522 DEFVAR_LISP ("after-change-function", &Vafter_change_function
,
4523 "If non-nil, a Function to call after each text change (obsolete).\n\
4524 Three arguments are passed to the function: the positions of\n\
4525 the beginning and end of the range of changed text,\n\
4526 and the length of the pre-change text replaced by that range.\n\
4527 \(For an insertion, the pre-change length is zero;\n\
4528 for a deletion, that length is the number of bytes deleted,\n\
4529 and the post-change beginning and end are at the same place.)\n\
4531 Buffer changes made while executing the `after-change-function'\n\
4532 don't call any before-change or after-change functions.\n\
4533 That's because these variables are temporarily set to nil.\n\
4534 As a result, a hook function cannot straightforwardly alter the value of\n\
4535 these variables. See the Emacs Lisp manual for a way of\n\
4536 accomplishing an equivalent result by using other variables.\n\n\
4537 This variable is obsolete; use `after-change-functions' instead.");
4538 Vafter_change_function
= Qnil
;
4540 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
4541 "List of functions to call before each text change.\n\
4542 Two arguments are passed to each function: the positions of\n\
4543 the beginning and end of the range of old text to be changed.\n\
4544 \(For an insertion, the beginning and end are at the same place.)\n\
4545 No information is given about the length of the text after the change.\n\
4547 Buffer changes made while executing the `before-change-functions'\n\
4548 don't call any before-change or after-change functions.\n\
4549 That's because these variables are temporarily set to nil.\n\
4550 As a result, a hook function cannot straightforwardly alter the value of\n\
4551 these variables. See the Emacs Lisp manual for a way of\n\
4552 accomplishing an equivalent result by using other variables.\n\
4554 If an unhandled error happens in running these functions,\n\
4555 the variable's value remains nil. That prevents the error\n\
4556 from happening repeatedly and making Emacs nonfunctional.");
4557 Vbefore_change_functions
= Qnil
;
4559 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
4560 "List of function to call after each text change.\n\
4561 Three arguments are passed to each function: the positions of\n\
4562 the beginning and end of the range of changed text,\n\
4563 and the length in bytes of the pre-change text replaced by that range.\n\
4564 \(For an insertion, the pre-change length is zero;\n\
4565 for a deletion, that length is the number of bytes deleted,\n\
4566 and the post-change beginning and end are at the same place.)\n\
4568 Buffer changes made while executing the `after-change-functions'\n\
4569 don't call any before-change or after-change functions.\n\
4570 That's because these variables are temporarily set to nil.\n\
4571 As a result, a hook function cannot straightforwardly alter the value of\n\
4572 these variables. See the Emacs Lisp manual for a way of\n\
4573 accomplishing an equivalent result by using other variables.\n\
4575 If an unhandled error happens in running these functions,\n\
4576 the variable's value remains nil. That prevents the error\n\
4577 from happening repeatedly and making Emacs nonfunctional.");
4578 Vafter_change_functions
= Qnil
;
4580 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
4581 "A list of functions to call before changing a buffer which is unmodified.\n\
4582 The functions are run using the `run-hooks' function.");
4583 Vfirst_change_hook
= Qnil
;
4585 #if 0 /* The doc string is too long for some compilers,
4586 but make-docfile can find it in this comment. */
4587 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4588 "List of undo entries in current buffer.\n\
4589 This variable is always local in all buffers.\n\
4590 Recent changes come first; older changes follow newer.\n\
4592 An entry (BEG . END) represents an insertion which begins at\n\
4593 position BEG and ends at position END.\n\
4595 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
4596 from (abs POSITION). If POSITION is positive, point was at the front\n\
4597 of the text being deleted; if negative, point was at the end.\n\
4599 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
4600 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
4601 of the visited file's modification time, as of that time. If the\n\
4602 modification time of the most recent save is different, this entry is\n\
4605 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
4606 was modified between BEG and END. PROPERTY is the property name,\n\
4607 and VALUE is the old value.\n\
4609 An entry (MARKER . DISTANCE) indicates that the marker MARKER\n\
4610 was adjusted in position by the offset DISTANCE (an integer).\n\
4612 An entry of the form POSITION indicates that point was at the buffer\n\
4613 location given by the integer. Undoing an entry of this form places\n\
4614 point at POSITION.\n\
4616 nil marks undo boundaries. The undo command treats the changes\n\
4617 between two undo boundaries as a single step to be undone.\n\
4619 If the value of the variable is t, undo information is not recorded.");
4621 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4624 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
4625 "Non-nil means the mark and region are currently active in this buffer.\n\
4626 Automatically local in all buffers.");
4628 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
4629 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
4630 This variable is buffer-local, in all buffers.\n\
4632 Normally, the line-motion functions work by scanning the buffer for\n\
4633 newlines. Columnar operations (like move-to-column and\n\
4634 compute-motion) also work by scanning the buffer, summing character\n\
4635 widths as they go. This works well for ordinary text, but if the\n\
4636 buffer's lines are very long (say, more than 500 characters), these\n\
4637 motion functions will take longer to execute. Emacs may also take\n\
4638 longer to update the display.\n\
4640 If cache-long-line-scans is non-nil, these motion functions cache the\n\
4641 results of their scans, and consult the cache to avoid rescanning\n\
4642 regions of the buffer until the text is modified. The caches are most\n\
4643 beneficial when they prevent the most searching---that is, when the\n\
4644 buffer contains long lines and large regions of characters with the\n\
4645 same, fixed screen width.\n\
4647 When cache-long-line-scans is non-nil, processing short lines will\n\
4648 become slightly slower (because of the overhead of consulting the\n\
4649 cache), and the caches will use memory roughly proportional to the\n\
4650 number of newlines and characters whose screen width varies.\n\
4652 The caches require no explicit maintenance; their accuracy is\n\
4653 maintained internally by the Emacs primitives. Enabling or disabling\n\
4654 the cache should not affect the behavior of any of the motion\n\
4655 functions; it should only affect their performance.");
4657 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
4658 "Value of point before the last series of scroll operations, or nil.\n\
4659 This variable is always local in all buffers.");
4661 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
4662 "List of formats to use when saving this buffer.\n\
4663 This variable is always local in all buffers.\n\
4664 Formats are defined by `format-alist'. This variable is\n\
4665 set when a file is visited. Automatically local in all buffers.");
4667 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
4668 ¤t_buffer
->invisibility_spec
, Qnil
,
4669 "Invisibility spec of this buffer.\n\
4670 This variable is always local in all buffers.\n\
4671 The default is t, which means that text is invisible\n\
4672 if it has a non-nil `invisible' property.\n\
4673 If the value is a list, a text character is invisible if its `invisible'\n\
4674 property is an element in that list.\n\
4675 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
4676 then characters with property value PROP are invisible,\n\
4677 and they have an ellipsis as well if ELLIPSIS is non-nil.");
4679 DEFVAR_PER_BUFFER ("buffer-display-count",
4680 ¤t_buffer
->display_count
, Qnil
,
4681 "A number incremented each time this buffer is displayed in a window.\n\
4682 This variable is always local in all buffers.\n\
4683 The function `set-window-buffer increments it.");
4685 DEFVAR_PER_BUFFER ("buffer-display-time",
4686 ¤t_buffer
->display_time
, Qnil
,
4687 "Time stamp updated each time this buffer is displayed in a window.\n\
4688 This variable is always local in all buffers.\n\
4689 The function `set-window-buffer' updates this variable\n\
4690 to the value obtained by calling `current-time'.\n\
4691 If the buffer has never been shown in a window, the value is nil.");
4693 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
4694 "*Non-nil means deactivate the mark when the buffer contents change.\n\
4695 Non-nil also enables highlighting of the region whenever the mark is active.\n\
4696 The variable `highlight-nonselected-windows' controls whether to highlight\n\
4697 all windows or just the selected window.");
4698 Vtransient_mark_mode
= Qnil
;
4700 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
4701 "*Non-nil means disregard read-only status of buffers or characters.\n\
4702 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
4703 text properties. If the value is a list, disregard `buffer-read-only'\n\
4704 and disregard a `read-only' text property if the property value\n\
4705 is a member of the list.");
4706 Vinhibit_read_only
= Qnil
;
4708 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
4709 "List of functions called with no args to query before killing a buffer.");
4710 Vkill_buffer_query_functions
= Qnil
;
4712 defsubr (&Sbuffer_live_p
);
4713 defsubr (&Sbuffer_list
);
4714 defsubr (&Sget_buffer
);
4715 defsubr (&Sget_file_buffer
);
4716 defsubr (&Sget_buffer_create
);
4717 defsubr (&Smake_indirect_buffer
);
4718 defsubr (&Sgenerate_new_buffer_name
);
4719 defsubr (&Sbuffer_name
);
4720 /*defsubr (&Sbuffer_number);*/
4721 defsubr (&Sbuffer_file_name
);
4722 defsubr (&Sbuffer_base_buffer
);
4723 defsubr (&Sbuffer_local_variables
);
4724 defsubr (&Sbuffer_modified_p
);
4725 defsubr (&Sset_buffer_modified_p
);
4726 defsubr (&Sbuffer_modified_tick
);
4727 defsubr (&Srename_buffer
);
4728 defsubr (&Sother_buffer
);
4729 defsubr (&Sbuffer_disable_undo
);
4730 defsubr (&Sbuffer_enable_undo
);
4731 defsubr (&Skill_buffer
);
4732 defsubr (&Sset_buffer_major_mode
);
4733 defsubr (&Sswitch_to_buffer
);
4734 defsubr (&Spop_to_buffer
);
4735 defsubr (&Scurrent_buffer
);
4736 defsubr (&Sset_buffer
);
4737 defsubr (&Sbarf_if_buffer_read_only
);
4738 defsubr (&Sbury_buffer
);
4739 defsubr (&Serase_buffer
);
4740 defsubr (&Sset_buffer_multibyte
);
4741 defsubr (&Skill_all_local_variables
);
4743 defsubr (&Soverlayp
);
4744 defsubr (&Smake_overlay
);
4745 defsubr (&Sdelete_overlay
);
4746 defsubr (&Smove_overlay
);
4747 defsubr (&Soverlay_start
);
4748 defsubr (&Soverlay_end
);
4749 defsubr (&Soverlay_buffer
);
4750 defsubr (&Soverlay_properties
);
4751 defsubr (&Soverlays_at
);
4752 defsubr (&Soverlays_in
);
4753 defsubr (&Snext_overlay_change
);
4754 defsubr (&Sprevious_overlay_change
);
4755 defsubr (&Soverlay_recenter
);
4756 defsubr (&Soverlay_lists
);
4757 defsubr (&Soverlay_get
);
4758 defsubr (&Soverlay_put
);
4764 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
4765 initial_define_key (control_x_map
, 'k', "kill-buffer");
4767 /* This must not be in syms_of_buffer, because Qdisabled is not
4768 initialized when that function gets called. */
4769 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);