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