1 /* Buffer manipulation primitives for XEmacs.
2 Copyright (C) 1985-1989, 1992-1995 Free Software Foundation, Inc.
3 Copyright (C) 1995 Sun Microsystems, Inc.
4 Copyright (C) 1995, 1996 Ben Wing.
6 This file is part of XEmacs.
8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with XEmacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Synched up with: Mule 2.0, FSF 19.30. */
28 JWZ: some changes for Lemacs, long ago. (e.g. separate buffer
30 Mly: a few changes for buffer-local vars, 19.8 or 19.9.
31 Ben Wing: some changes and cleanups for Mule, 19.12.
34 /* This file contains functions that work with buffer objects.
35 Functions that manipulate a buffer's text, however, are not
38 1) The low-level functions that actually know about the
39 implementation of a buffer's text are located in insdel.c.
40 2) The higher-level (mostly Lisp) functions that manipulate a
41 buffer's text are in editfns.c.
42 3) The highest-level Lisp commands are in cmds.c.
46 -- Functions that know about syntax tables (forward-word,
47 scan-sexps, etc.) are in syntax.c, as are functions
48 that manipulate syntax tables.
49 -- Functions that know about case tables (upcase, downcase,
50 etc.) are in casefiddle.c. Functions that manipulate
51 case tables (case-table-p, set-case-table, etc.) are
53 -- Functions that do searching and replacing are in
54 search.c. The low-level functions that implement
55 regular expressions are in regex.c.
59 -- Some file and process functions (in fileio.c and process.c)
60 copy text from or insert text into a buffer; they call
61 low-level functions in insdel.c to do this.
62 -- insdel.c calls low-level functions in undo.c and extents.c
63 to record buffer modifications for undoing and to handle
64 extent adjustment and extent-data creation and insertion.
78 #include "file-coding.h"
83 #include "process.h" /* for kill_buffer_processes */
84 #ifdef REGION_CACHE_NEEDS_WORK
85 #include "region-cache.h"
87 #include "select.h" /* for select_notify_buffer_kill */
88 #include "specifier.h"
90 #include "sysdep.h" /* for getwd */
95 struct buffer *current_buffer; /* the current buffer */
97 /* This structure holds the default values of the buffer-local variables
98 defined with DEFVAR_BUFFER_LOCAL, that have special slots in each buffer.
99 The default value occupies the same slot in this structure
100 as an individual buffer's value occupies in that buffer.
101 Setting the default value also goes through the alist of buffers
102 and stores into each buffer that does not say it has a local value. */
103 Lisp_Object Vbuffer_defaults;
104 static void *buffer_defaults_saved_slots;
106 /* This structure marks which slots in a buffer have corresponding
107 default values in Vbuffer_defaults.
108 Each such slot has a nonzero value in this structure.
109 The value has only one nonzero bit.
111 When a buffer has its own local value for a slot,
112 the bit for that slot (found in the same slot in this structure)
113 is turned on in the buffer's local_var_flags slot.
115 If a slot in this structure is 0, then there is a DEFVAR_BUFFER_LOCAL
116 for the slot, but there is no default value for it; the corresponding
117 slot in Vbuffer_defaults is not used except to initialize newly-created
120 If a slot is -1, then there is a DEFVAR_BUFFER_LOCAL for it
121 as well as a default value which is used to initialize newly-created
122 buffers and as a reset-value when local-vars are killed.
124 If a slot is -2, there is no DEFVAR_BUFFER_LOCAL for it.
125 (The slot is always local, but there's no lisp variable for it.)
126 The default value is only used to initialize newly-creation buffers.
128 If a slot is -3, then there is no DEFVAR_BUFFER_LOCAL for it but
129 there is a default which is used to initialize newly-creation
130 buffers and as a reset-value when local-vars are killed. */
131 struct buffer buffer_local_flags;
133 /* This is the initial (startup) directory, as used for the *scratch* buffer.
134 We're making this a global to make others aware of the startup directory.
135 `initial_directory' is stored in external format.
137 char initial_directory[MAXPATHLEN+1];
139 /* This structure holds the names of symbols whose values may be
140 buffer-local. It is indexed and accessed in the same way as the above. */
141 static Lisp_Object Vbuffer_local_symbols;
142 static void *buffer_local_symbols_saved_slots;
144 /* Alist of all buffer names vs the buffers. */
145 /* This used to be a variable, but is no longer,
146 to prevent lossage due to user rplac'ing this alist or its elements.
147 Note that there is a per-frame copy of this as well; the frame slot
148 and the global variable contain the same data, but possibly in different
149 orders, so that the buffer ordering can be per-frame.
151 Lisp_Object Vbuffer_alist;
153 /* Functions to call before and after each text change. */
154 Lisp_Object Qbefore_change_functions;
155 Lisp_Object Qafter_change_functions;
156 Lisp_Object Vbefore_change_functions;
157 Lisp_Object Vafter_change_functions;
159 /* #### Obsolete, for compatibility */
160 Lisp_Object Qbefore_change_function;
161 Lisp_Object Qafter_change_function;
162 Lisp_Object Vbefore_change_function;
163 Lisp_Object Vafter_change_function;
166 Lisp_Object Vtransient_mark_mode;
169 /* t means ignore all read-only text properties.
170 A list means ignore such a property if its value is a member of the list.
171 Any non-nil value means ignore buffer-read-only. */
172 Lisp_Object Vinhibit_read_only;
174 /* List of functions to call that can query about killing a buffer.
175 If any of these functions returns nil, we don't kill it. */
176 Lisp_Object Vkill_buffer_query_functions;
178 /* Non-nil means delete a buffer's auto-save file when the buffer is saved. */
179 int delete_auto_save_files;
181 Lisp_Object Qbuffer_live_p;
182 Lisp_Object Qbuffer_or_string_p;
184 /* List of functions to call before changing an unmodified buffer. */
185 Lisp_Object Vfirst_change_hook;
186 Lisp_Object Qfirst_change_hook;
188 Lisp_Object Qfundamental_mode;
189 Lisp_Object Qmode_class;
190 Lisp_Object Qpermanent_local;
192 Lisp_Object Qprotected_field;
194 Lisp_Object QSFundamental; /* A string "Fundamental" */
195 Lisp_Object QSscratch; /* "*scratch*" */
196 Lisp_Object Qdefault_directory;
198 Lisp_Object Qkill_buffer_hook;
200 Lisp_Object Qrename_auto_save_file;
202 Lisp_Object Qget_file_buffer;
203 Lisp_Object Qchange_major_mode_hook, Vchange_major_mode_hook;
205 Lisp_Object Qfind_file_compare_truenames;
207 Lisp_Object Qswitch_to_buffer;
209 /* Two thresholds controlling how much undo information to keep. */
211 int undo_high_threshold;
213 int find_file_compare_truenames;
214 int find_file_use_truenames;
217 static void reset_buffer_local_variables (struct buffer *, int first_time);
218 static void nuke_all_buffer_slots (struct buffer *b, Lisp_Object zap);
221 make_buffer (struct buffer *buf)
224 XSETBUFFER (obj, buf);
229 mark_buffer (Lisp_Object obj)
231 struct buffer *buf = XBUFFER (obj);
233 /* Truncate undo information. */
234 buf->undo_list = truncate_undo_list (buf->undo_list,
236 undo_high_threshold);
238 #define MARKED_SLOT(x) mark_object (buf->x)
239 #include "bufslots.h"
242 mark_object (buf->extent_info);
244 mark_object (buf->text->line_number_cache);
246 /* Don't mark normally through the children slot.
247 (Actually, in this case, it doesn't matter.) */
248 if (! EQ (buf->indirect_children, Qnull_pointer))
249 mark_conses_in_list (buf->indirect_children);
251 return buf->base_buffer ? make_buffer (buf->base_buffer) : Qnil;
255 print_buffer (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
257 struct buffer *b = XBUFFER (obj);
261 if (!BUFFER_LIVE_P (b))
262 error ("printing unreadable object #<killed buffer>");
264 error ("printing unreadable object #<buffer %s>",
265 XSTRING_DATA (b->name));
267 else if (!BUFFER_LIVE_P (b))
268 write_c_string ("#<killed buffer>", printcharfun);
271 write_c_string ("#<buffer ", printcharfun);
272 print_internal (b->name, printcharfun, 1);
273 write_c_string (">", printcharfun);
277 print_internal (b->name, printcharfun, 0);
281 /* We do not need a finalize method to handle a buffer's children list
282 because all buffers have `kill-buffer' applied to them before
283 they disappear, and the children removal happens then. */
284 DEFINE_LRECORD_IMPLEMENTATION ("buffer", buffer,
285 mark_buffer, print_buffer, 0, 0, 0, 0,
288 DEFUN ("bufferp", Fbufferp, 1, 1, 0, /*
289 Return t if OBJECT is an editor buffer.
293 return BUFFERP (object) ? Qt : Qnil;
296 DEFUN ("buffer-live-p", Fbuffer_live_p, 1, 1, 0, /*
297 Return t if OBJECT is an editor buffer that has not been deleted.
301 return BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)) ? Qt : Qnil;
305 nsberror (Lisp_Object spec)
308 error ("No buffer named %s", XSTRING_DATA (spec));
309 signal_simple_error ("Invalid buffer argument", spec);
312 DEFUN ("buffer-list", Fbuffer_list, 0, 1, 0, /*
313 Return a list of all existing live buffers.
314 The order is specific to the selected frame; if the optional FRAME
315 argument is provided, the ordering for that frame is returned instead.
316 If the FRAME argument is t, then the global (non-frame) ordering is
321 return Fmapcar (Qcdr,
322 EQ (frame, Qt) ? Vbuffer_alist :
323 decode_frame (frame)->buffer_alist);
327 get_buffer (Lisp_Object name, int error_if_deleted_or_does_not_exist)
331 if (!BUFFER_LIVE_P (XBUFFER (name)))
333 if (error_if_deleted_or_does_not_exist)
345 name = LISP_GETTEXT (name); /* I18N3 */
347 buf = Fcdr (Fassoc (name, Vbuffer_alist));
349 if (NILP (buf) && error_if_deleted_or_does_not_exist)
356 decode_buffer (Lisp_Object buffer, int allow_string)
359 return current_buffer;
361 if (allow_string && STRINGP (buffer))
362 return XBUFFER (get_buffer (buffer, 1));
364 CHECK_LIVE_BUFFER (buffer);
365 return XBUFFER (buffer);
368 DEFUN ("decode-buffer", Fdecode_buffer, 1, 1, 0, /*
369 Validate BUFFER or if BUFFER is nil, return the current buffer.
370 If BUFFER is a valid buffer or a string representing a valid buffer,
371 the corresponding buffer object will be returned. Otherwise an error
376 struct buffer *b = decode_buffer (buffer, 1);
377 XSETBUFFER (buffer, b);
383 /* Like Fassoc, but use Fstring_equal to compare
384 (which ignores text properties),
385 and don't ever QUIT. */
388 assoc_ignore_text_properties (REGISTER Lisp_Object key, Lisp_Object list)
390 REGISTER Lisp_Object tail;
391 for (tail = list; !NILP (tail); tail = Fcdr (tail))
393 REGISTER Lisp_Object elt, tem;
395 tem = Fstring_equal (Fcar (elt), key);
404 DEFUN ("get-buffer", Fget_buffer, 1, 1, 0, /*
405 Return the buffer named NAME (a string).
406 If there is no live buffer named NAME, return nil.
407 NAME may also be a buffer; if so, the value is that buffer.
412 /* #### Doc string should indicate that the buffer name will get
416 /* #### This might return a dead buffer. This is gross. This is
417 called FSF compatibility. */
420 return get_buffer (name, 0);
421 /* FSFmacs 19.29 calls assoc_ignore_text_properties() here.
426 DEFUN ("get-file-buffer", Fget_file_buffer, 1, 1, 0, /*
427 Return the buffer visiting file FILENAME (a string).
428 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.
429 If there is no such live buffer, return nil.
431 Normally, the comparison is done by canonicalizing FILENAME (using
432 `expand-file-name') and comparing that to the value of `buffer-file-name'
433 for each existing buffer. However, If `find-file-compare-truenames' is
434 non-nil, FILENAME will be converted to its truename and the search will be
435 done on each buffer's value of `buffer-file-truename' instead of
436 `buffer-file-name'. Otherwise, if `find-file-use-truenames' is non-nil,
437 FILENAME will be converted to its truename and used for searching, but
438 the search will still be done on `buffer-file-name'.
442 /* This function can GC. GC checked and fixed 7-11-2000 ben. */
443 REGISTER Lisp_Object buf;
447 /* DO NOT translate the filename. */
450 CHECK_STRING (filename);
451 filename = Fexpand_file_name (filename, Qnil);
453 /* If the file name has special constructs in it,
454 call the corresponding file handler. */
455 Lisp_Object handler = Ffind_file_name_handler (filename, Qget_file_buffer);
459 return call2 (handler, Qget_file_buffer, filename);
464 if (find_file_compare_truenames || find_file_use_truenames)
466 struct gcpro ngcpro1, ngcpro2, ngcpro3;
467 Lisp_Object fn = Qnil;
468 Lisp_Object dn = Qnil;
470 NGCPRO3 (fn, dn, filename);
471 fn = Ffile_truename (filename, Qnil);
474 dn = Ffile_name_directory (filename);
475 fn = Ffile_truename (dn, Qnil);
476 if (! NILP (fn)) dn = fn;
477 /* Formerly the two calls below were combined, but that is
478 not GC-safe because the first call returns unprotected
479 data and the second call can GC. --ben */
480 fn = Ffile_name_nondirectory (filename);
481 fn = Fexpand_file_name (fn, dn);
488 LIST_LOOP_2 (elt, Vbuffer_alist)
491 if (!BUFFERP (buf)) continue;
492 if (!STRINGP (XBUFFER (buf)->filename)) continue;
493 if (!NILP (Fstring_equal (filename,
494 (find_file_compare_truenames
495 ? XBUFFER (buf)->file_truename
496 : XBUFFER (buf)->filename))))
505 push_buffer_alist (Lisp_Object name, Lisp_Object buf)
507 Lisp_Object cons = Fcons (name, buf);
508 Lisp_Object frmcons, devcons, concons;
510 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (cons, Qnil));
511 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
514 f = XFRAME (XCAR (frmcons));
515 f->buffer_alist = nconc2 (f->buffer_alist, Fcons (cons, Qnil));
520 delete_from_buffer_alist (Lisp_Object buf)
522 Lisp_Object cons = Frassq (buf, Vbuffer_alist);
523 Lisp_Object frmcons, devcons, concons;
525 return; /* abort() ? */
526 Vbuffer_alist = delq_no_quit (cons, Vbuffer_alist);
528 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
531 f = XFRAME (XCAR (frmcons));
532 f->buffer_alist = delq_no_quit (cons, f->buffer_alist);
537 get_truename_buffer (REGISTER Lisp_Object filename)
539 /* This function can GC. GC correct 7-11-00 ben */
540 /* FSFmacs has its own code here and doesn't call get-file-buffer.
541 That's because their equivalent of find-file-compare-truenames
542 (find-file-existing-other-name) isn't looked at in get-file-buffer.
543 This way is more correct. */
544 int count = specpdl_depth ();
546 specbind (Qfind_file_compare_truenames, Qt);
547 return unbind_to (count, Fget_file_buffer (filename));
550 static struct buffer *
551 allocate_buffer (void)
553 struct buffer *b = alloc_lcrecord_type (struct buffer, &lrecord_buffer);
555 copy_lcrecord (b, XBUFFER (Vbuffer_defaults));
561 finish_init_buffer (struct buffer *b, Lisp_Object name)
567 name = Fcopy_sequence (name);
568 /* #### This really does not need to be called. We already
569 initialized the buffer-local variables in allocate_buffer().
570 local_var_alist is set to Qnil at the same point, in
571 nuke_all_buffer_slots(). */
572 reset_buffer_local_variables (b, 1);
573 b->directory = current_buffer ? current_buffer->directory : Qnil;
575 b->last_window_start = 1;
578 if (string_byte (XSTRING (name), 0) != ' ')
583 /* initialize the extent list */
584 init_buffer_extents (b);
586 /* Put this in the alist of all live buffers. */
587 push_buffer_alist (name, buf);
589 init_buffer_markers (b);
591 b->generated_modeline_string = Fmake_string (make_int (84), make_int (' '));
592 b->modeline_extent_table = make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK,
598 DEFUN ("get-buffer-create", Fget_buffer_create, 1, 1, 0, /*
599 Return the buffer named NAME, or create such a buffer and return it.
600 A new buffer is created if there is no live buffer named NAME.
601 If NAME starts with a space, the new buffer does not keep undo information.
602 If NAME is a buffer instead of a string, then it is the value returned.
603 The value is never nil.
607 /* This function can GC */
609 REGISTER struct buffer *b;
612 /* #### Doc string should indicate that the buffer name will get
616 name = LISP_GETTEXT (name);
617 buf = Fget_buffer (name);
621 if (XSTRING_LENGTH (name) == 0)
622 error ("Empty string for buffer name is not allowed");
624 b = allocate_buffer ();
626 b->text = &b->own_text;
628 b->indirect_children = Qnil;
629 init_buffer_text (b);
631 return finish_init_buffer (b, name);
634 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, 2, 2,
635 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ", /*
636 Create and return an indirect buffer for buffer BASE, named NAME.
637 BASE should be an existing buffer (or buffer name).
638 NAME should be a string which is not the name of an existing buffer.
639 If BASE is an indirect buffer itself, the base buffer for that buffer
640 is made the base buffer for the newly created buffer. (Thus, there will
641 never be indirect buffers whose base buffers are themselves indirect.)
645 /* This function can GC */
647 /* #### The above interactive specification is totally bogus,
648 because it offers an existing buffer as default answer to the
649 second question. However, the second argument may not BE an
653 base_buffer = get_buffer (base_buffer, 1);
656 /* #### Doc string should indicate that the buffer name will get
660 name = LISP_GETTEXT (name);
661 if (!NILP (Fget_buffer (name)))
662 signal_simple_error ("Buffer name already in use", name);
663 if (XSTRING_LENGTH (name) == 0)
664 error ("Empty string for buffer name is not allowed");
666 b = allocate_buffer ();
668 b->base_buffer = BUFFER_BASE_BUFFER (XBUFFER (base_buffer));
670 /* Use the base buffer's text object. */
671 b->text = b->base_buffer->text;
672 b->indirect_children = Qnil;
673 b->base_buffer->indirect_children =
674 Fcons (make_buffer (b), b->base_buffer->indirect_children);
675 init_buffer_text (b);
677 return finish_init_buffer (b, name);
683 reset_buffer_local_variables (struct buffer *b, int first_time)
685 struct buffer *def = XBUFFER (Vbuffer_defaults);
687 b->local_var_flags = 0;
688 /* For each slot that has a default value,
689 copy that into the slot. */
690 #define MARKED_SLOT(slot) \
691 { int mask = XINT (buffer_local_flags.slot); \
692 if ((mask > 0 || mask == -1 || mask == -3) \
694 || NILP (Fget (XBUFFER (Vbuffer_local_symbols)->slot, \
695 Qpermanent_local, Qnil)))) \
696 b->slot = def->slot; \
698 #include "bufslots.h"
701 #define STRING256_P(obj) \
702 (STRINGP (obj) && XSTRING_CHAR_LENGTH (obj) == 256)
703 /* If the standard case table has been altered and invalidated,
704 fix up its insides first. */
705 if (!(STRING256_P(Vascii_upcase_table) &&
706 STRING256_P(Vascii_canon_table) &&
707 STRING256_P(Vascii_eqv_table)))
709 Fset_standard_case_table (Vascii_downcase_table);
711 b->downcase_table = Vascii_downcase_table;
712 b->upcase_table = Vascii_upcase_table;
713 b->case_canon_table = Vascii_canon_table;
714 b->case_eqv_table = Vascii_eqv_table;
716 b->mirror_downcase_table = Vmirror_ascii_downcase_table;
717 b->mirror_upcase_table = Vmirror_ascii_upcase_table;
718 b->mirror_case_canon_table = Vmirror_ascii_canon_table;
719 b->mirror_case_eqv_table = Vmirror_ascii_eqv_table;
725 /* We split this away from generate-new-buffer, because rename-buffer
726 and set-visited-file-name ought to be able to use this to really
727 rename the buffer properly. */
729 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, 1, 2, 0, /*
730 Return a string that is the name of no existing buffer based on NAME.
731 If there is no live buffer named NAME, then return NAME.
732 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
733 until an unused name is found, and then return that name.
734 Optional second argument IGNORE specifies a name that is okay to use
735 \(if it is in the sequence to be tried)
736 even if a buffer with that name exists.
740 REGISTER Lisp_Object gentemp, tem;
746 name = LISP_GETTEXT (name);
748 /* #### Doc string should indicate that the buffer name will get
752 tem = Fget_buffer (name);
759 sprintf (number, "<%d>", ++count);
760 gentemp = concat2 (name, build_string (number));
763 tem = Fstring_equal (gentemp, ignore);
767 tem = Fget_buffer (gentemp);
774 DEFUN ("buffer-name", Fbuffer_name, 0, 1, 0, /*
775 Return the name of BUFFER, as a string.
776 With no argument or nil as argument, return the name of the current buffer.
780 /* For compatibility, we allow a dead buffer here.
781 Earlier versions of Emacs didn't provide buffer-live-p. */
783 return current_buffer->name;
784 CHECK_BUFFER (buffer);
785 return XBUFFER (buffer)->name;
788 DEFUN ("buffer-file-name", Fbuffer_file_name, 0, 1, 0, /*
789 Return name of file BUFFER is visiting, or nil if none.
790 No argument or nil as argument means use the current buffer.
794 /* For compatibility, we allow a dead buffer here. Yuck! */
796 return current_buffer->filename;
797 CHECK_BUFFER (buffer);
798 return XBUFFER (buffer)->filename;
801 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, 0, 1, 0, /*
802 Return the base buffer of indirect buffer BUFFER.
803 If BUFFER is not indirect, return nil.
807 struct buffer *buf = decode_buffer (buffer, 0);
809 return buf->base_buffer ? make_buffer (buf->base_buffer) : Qnil;
812 DEFUN ("buffer-indirect-children", Fbuffer_indirect_children, 0, 1, 0, /*
813 Return a list of all indirect buffers whose base buffer is BUFFER.
814 If BUFFER is indirect, the return value will always be nil; see
815 `make-indirect-buffer'.
819 struct buffer *buf = decode_buffer (buffer, 0);
821 return Fcopy_sequence (buf->indirect_children);
824 DEFUN ("buffer-local-variables", Fbuffer_local_variables, 0, 1, 0, /*
825 Return an alist of variables that are buffer-local in BUFFER.
826 Most elements look like (SYMBOL . VALUE), describing one variable.
827 For a symbol that is locally unbound, just the symbol appears in the value.
828 Note that storing new VALUEs in these elements doesn't change the variables.
829 No argument or nil as argument means use current buffer as BUFFER.
833 struct buffer *buf = decode_buffer (buffer, 0);
834 Lisp_Object result = Qnil;
838 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
840 Lisp_Object elt = XCAR (tail);
841 /* Reference each variable in the alist in buf.
842 If inquiring about the current buffer, this gets the current values,
843 so store them into the alist so the alist is up to date.
844 If inquiring about some other buffer, this swaps out any values
845 for that buffer, making the alist up to date automatically. */
846 Lisp_Object val = find_symbol_value (XCAR (elt));
847 /* Use the current buffer value only if buf is the current buffer. */
848 if (buf != current_buffer)
851 /* If symbol is unbound, put just the symbol in the list. */
853 result = Fcons (XCAR (elt), result);
854 /* Otherwise, put (symbol . value) in the list. */
856 result = Fcons (Fcons (XCAR (elt), val), result);
860 /* Add on all the variables stored in special slots. */
862 struct buffer *syms = XBUFFER (Vbuffer_local_symbols);
863 #define MARKED_SLOT(slot) \
864 { int mask = XINT (buffer_local_flags.slot); \
865 if (mask == 0 || mask == -1 \
866 || ((mask > 0) && (buf->local_var_flags & mask))) \
867 result = Fcons (Fcons (syms->slot, buf->slot), result); \
869 #include "bufslots.h"
876 DEFUN ("buffer-modified-p", Fbuffer_modified_p, 0, 1, 0, /*
877 Return t if BUFFER was modified since its file was last read or saved.
878 No argument or nil as argument means use current buffer as BUFFER.
882 struct buffer *buf = decode_buffer (buffer, 0);
884 return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil;
887 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, 1, 2, 0, /*
888 Mark BUFFER as modified or unmodified according to FLAG.
889 A non-nil FLAG means mark the buffer modified. No argument or nil
890 as BUFFER means use current buffer.
894 /* This function can GC */
895 struct buffer *buf = decode_buffer (buffer, 0);
897 #ifdef CLASH_DETECTION
898 /* If buffer becoming modified, lock the file.
899 If buffer becoming unmodified, unlock the file. */
901 Lisp_Object fn = buf->file_truename;
904 int already = BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf);
905 if (already == NILP (flag))
907 int count = specpdl_depth ();
908 /* lock_file() and unlock_file() currently use current_buffer */
909 /* #### - dmoore, what if lock_file or unlock_file kill
910 the current buffer? */
911 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
912 set_buffer_internal (buf);
913 if (!already && !NILP (flag))
915 else if (already && NILP (flag))
917 unbind_to (count, Qnil);
920 #endif /* CLASH_DETECTION */
922 /* This is often called when the buffer contents are altered but we
923 don't want to treat the changes that way (e.g. selective
924 display). We still need to make sure redisplay realizes that the
925 contents have potentially altered and it needs to do some
927 buf = decode_buffer(buffer, 0);
929 BUF_SAVE_MODIFF (buf) = NILP (flag) ? BUF_MODIFF (buf) : 0;
930 MARK_MODELINE_CHANGED;
935 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, 0, 1, 0, /*
936 Return BUFFER's tick counter, incremented for each change in text.
937 Each buffer has a tick counter which is incremented each time the text in
938 that buffer is changed. It wraps around occasionally.
939 No argument or nil as argument means use current buffer as BUFFER.
943 struct buffer *buf = decode_buffer (buffer, 0);
945 return make_int (BUF_MODIFF (buf));
948 DEFUN ("rename-buffer", Frename_buffer, 1, 2,
949 "sRename buffer (to new name): \nP", /*
950 Change current buffer's name to NEWNAME (a string).
951 If second arg UNIQUE is nil or omitted, it is an error if a
952 buffer named NEWNAME already exists.
953 If UNIQUE is non-nil, come up with a new name using
954 `generate-new-buffer-name'.
955 Interactively, one can set UNIQUE with a prefix argument.
956 Returns the name we actually gave the buffer.
957 This does not change the name of the visited file (if any).
961 /* This function can GC */
962 Lisp_Object tem, buf;
965 /* #### Doc string should indicate that the buffer name will get
968 CHECK_STRING (newname);
969 newname = LISP_GETTEXT (newname);
971 if (XSTRING_LENGTH (newname) == 0)
972 error ("Empty string is invalid as a buffer name");
974 tem = Fget_buffer (newname);
975 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
976 the buffer automatically so you can create another with the original name.
977 It makes UNIQUE equivalent to
978 (rename-buffer (generate-new-buffer-name NEWNAME)). */
979 /* XEmacs change: added check for nil */
980 if (NILP (unique) && !NILP (tem) && XBUFFER (tem) == current_buffer)
981 return current_buffer->name;
985 newname = Fgenerate_new_buffer_name (newname, current_buffer->name);
987 error ("Buffer name \"%s\" is in use",
988 XSTRING_DATA (newname));
991 current_buffer->name = newname;
993 /* Catch redisplay's attention. Unless we do this, the modelines for
994 any windows displaying current_buffer will stay unchanged. */
995 MARK_MODELINE_CHANGED;
997 buf = Fcurrent_buffer ();
999 /* The aconses in the Vbuffer_alist are shared with frame->buffer_alist,
1000 so this will change it in the per-frame ordering as well. */
1001 Fsetcar (Frassq (buf, Vbuffer_alist), newname);
1003 if (NILP (current_buffer->filename)
1004 && !NILP (current_buffer->auto_save_file_name))
1005 call0 (Qrename_auto_save_file);
1006 /* refetch since that last call may have done GC */
1007 /* (hypothetical relocating GC) */
1008 return current_buffer->name;
1011 DEFUN ("other-buffer", Fother_buffer, 0, 3, 0, /*
1012 Return most recently selected buffer other than BUFFER.
1013 Buffers not visible in windows are preferred to visible buffers,
1014 unless optional third argument VISIBLE-OK is non-nil.
1015 If no other buffer exists, the buffer `*scratch*' is returned.
1016 If BUFFER is omitted or nil, some interesting buffer is returned.
1018 The ordering is for this frame; If second optional argument FRAME
1019 is provided, then the ordering is for that frame. If the second arg
1020 is t, then the global ordering is returned.
1022 Note: In FSF Emacs, this function takes two arguments: BUFFER and
1025 (buffer, frame, visible_ok))
1027 /* This function can GC */
1028 Lisp_Object tail, buf, notsogood, tem;
1034 alist = Vbuffer_alist;
1037 struct frame *f = decode_frame (frame);
1039 XSETFRAME (frame, f);
1040 alist = f->buffer_alist;
1043 for (tail = alist; !NILP (tail); tail = Fcdr (tail))
1045 buf = Fcdr (Fcar (tail));
1046 if (EQ (buf, buffer))
1048 if (string_byte (XSTRING (XBUFFER (buf)->name), 0) == ' ')
1050 /* If FRAME has a buffer_predicate,
1051 disregard buffers that don't fit the predicate. */
1054 tem = XFRAME (frame)->buffer_predicate;
1057 tem = call1 (tem, buf);
1063 if (NILP (visible_ok))
1065 /* get-buffer-window will handle nil or t frame */
1066 tem = Fget_buffer_window (buf, frame, Qnil);
1072 if (NILP (notsogood))
1075 if (!NILP (notsogood))
1077 return Fget_buffer_create (QSscratch);
1080 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, 0, 1, "", /*
1081 Make BUFFER stop keeping undo information.
1082 Any undo records it already has are discarded.
1083 No argument or nil as argument means do this for the current buffer.
1087 /* Allowing nil is an RMSism */
1088 struct buffer *real_buf = decode_buffer (buffer, 1);
1089 real_buf->undo_list = Qt;
1093 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, 0, 1, "", /*
1094 Start keeping undo information for buffer BUFFER.
1095 No argument or nil as argument means do this for the current buffer.
1099 /* Allowing nil is an RMSism */
1100 struct buffer *real_buf = decode_buffer (buffer, 1);
1101 if (EQ (real_buf->undo_list, Qt))
1102 real_buf->undo_list = Qnil;
1107 DEFUN ("kill-buffer", Fkill_buffer, 1, 1, "bKill buffer: ", /*
1108 Kill the buffer BUFFER.
1109 The argument may be a buffer or may be the name of a buffer.
1110 An argument of nil means kill the current buffer.
1112 Value is t if the buffer is actually killed, nil if user says no.
1114 The value of `kill-buffer-hook' (which may be local to that buffer),
1115 if not void, is a list of functions to be called, with no arguments,
1116 before the buffer is actually killed. The buffer to be killed is current
1117 when the hook functions are called.
1119 Any processes that have this buffer as the `process-buffer' are killed
1120 with `delete-process'.
1124 /* This function can call lisp */
1126 REGISTER struct buffer *b;
1127 struct gcpro gcpro1, gcpro2;
1130 buf = Fcurrent_buffer ();
1131 else if (BUFFERP (buffer))
1135 buf = get_buffer (buffer, 0);
1136 if (NILP (buf)) nsberror (buffer);
1141 /* OK to delete an already-deleted buffer. */
1142 if (!BUFFER_LIVE_P (b))
1145 /* Don't kill the minibuffer now current. */
1146 if (EQ (buf, Vminibuffer_zero))
1149 /* Or the echo area. */
1150 if (EQ (buf, Vecho_area_buffer))
1153 /* Query if the buffer is still modified. */
1154 if (INTERACTIVE && !NILP (b->filename)
1155 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
1161 (emacs_doprnt_string_c
1162 ((const Bufbyte *) GETTEXT ("Buffer %s modified; kill anyway? "),
1163 Qnil, -1, XSTRING_DATA (b->name))));
1167 b = XBUFFER (buf); /* Hypothetical relocating GC. */
1170 /* Run hooks with the buffer to be killed temporarily selected,
1171 unless the buffer is already dead (could have been deleted
1172 in the question above).
1174 if (BUFFER_LIVE_P (b))
1176 int speccount = specpdl_depth ();
1177 Lisp_Object tail = Qnil;
1180 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1183 /* First run the query functions; if any query is answered no,
1184 don't kill the buffer. */
1185 EXTERNAL_LIST_LOOP (tail, Vkill_buffer_query_functions)
1187 if (NILP (call0 (Fcar (tail))))
1190 return unbind_to (speccount, Qnil);
1194 /* Then run the hooks. */
1195 run_hook (Qkill_buffer_hook);
1197 /* Inform the selection code that a buffer just got killed.
1198 We do this in C because (a) it's faster, and (b) it needs
1199 to access data internal to select.c that can't be seen from
1200 Lisp (so the Lisp code would just call into C anyway. */
1201 select_notify_buffer_kill (buf);
1203 unbind_to (speccount, Qnil);
1205 b = XBUFFER (buf); /* Hypothetical relocating GC. */
1208 /* We have no more questions to ask. Verify that it is valid
1209 to kill the buffer. This must be done after the questions
1210 since anything can happen within yes-or-no-p. */
1212 /* Might have been deleted during the last question above */
1213 if (!BUFFER_LIVE_P (b))
1216 /* Don't kill the minibuffer now current. */
1217 if (EQ (buf, XWINDOW (minibuf_window)->buffer))
1220 /* When we kill a base buffer, kill all its indirect buffers.
1221 We do it at this stage so nothing terrible happens if they
1222 ask questions or their hooks get errors. */
1223 if (! b->base_buffer)
1229 LIST_LOOP (rest, b->indirect_children)
1231 Fkill_buffer (XCAR (rest));
1232 /* Keep indirect_children updated in case a
1233 query-function/hook throws. */
1234 b->indirect_children = XCDR (rest);
1240 /* Make this buffer not be current.
1241 In the process, notice if this is the sole visible buffer
1242 and give up if so. */
1243 if (b == current_buffer)
1245 Fset_buffer (Fother_buffer (buf, Qnil, Qnil));
1246 if (b == current_buffer)
1250 /* Now there is no question: we can kill the buffer. */
1252 #ifdef CLASH_DETECTION
1253 /* Unlock this buffer's file, if it is locked. unlock_buffer
1254 can both GC and kill the current buffer, and wreak general
1255 havok by running lisp code. */
1261 if (!BUFFER_LIVE_P (b))
1264 if (b == current_buffer)
1266 Fset_buffer (Fother_buffer (buf, Qnil, Qnil));
1267 if (b == current_buffer)
1270 #endif /* CLASH_DETECTION */
1273 int speccount = specpdl_depth ();
1274 specbind (Qinhibit_quit, Qt);
1276 kill_buffer_processes (buf);
1278 delete_from_buffer_alist (buf);
1280 /* #### This is a problem if this buffer is in a dedicated window.
1281 Need to undedicate any windows of this buffer first (and delete them?)
1283 Freplace_buffer_in_windows (buf);
1285 font_lock_buffer_was_killed (b);
1287 /* Delete any auto-save file, if we saved it in this session. */
1288 if (STRINGP (b->auto_save_file_name)
1289 && b->auto_save_modified != 0
1290 && BUF_SAVE_MODIFF (b) < b->auto_save_modified)
1292 if (delete_auto_save_files != 0)
1294 /* deleting the auto save file might kill b! */
1295 /* #### dmoore - fix this crap, we do this same gcpro and
1296 buffer liveness check multiple times. Let's get a
1297 macro or something for it. */
1299 internal_delete_file (b->auto_save_file_name);
1303 if (!BUFFER_LIVE_P (b))
1306 if (b == current_buffer)
1308 Fset_buffer (Fother_buffer (buf, Qnil, Qnil));
1309 if (b == current_buffer)
1315 uninit_buffer_markers (b);
1317 kill_buffer_local_variables (b);
1320 uninit_buffer_text (b);
1321 b->undo_list = Qnil;
1322 uninit_buffer_extents (b);
1325 #ifdef ERROR_CHECK_BUFPOS
1326 assert (!NILP (memq_no_quit (buf, b->base_buffer->indirect_children)));
1328 b->base_buffer->indirect_children =
1329 delq_no_quit (buf, b->base_buffer->indirect_children);
1332 /* Clear away all Lisp objects, so that they
1333 won't be protected from GC. */
1334 nuke_all_buffer_slots (b, Qnil);
1336 unbind_to (speccount, Qnil);
1341 DEFUN ("record-buffer", Frecord_buffer, 1, 1, 0, /*
1342 Place buffer BUFFER first in the buffer order.
1343 Call this function when a buffer is selected "visibly".
1345 This function changes the global buffer order and the per-frame buffer
1346 order for the selected frame. The buffer order keeps track of recency
1347 of selection so that `other-buffer' will return a recently selected
1348 buffer. See `other-buffer' for more information.
1352 REGISTER Lisp_Object lynk, prev;
1353 struct frame *f = selected_frame ();
1356 for (lynk = Vbuffer_alist; CONSP (lynk); lynk = XCDR (lynk))
1358 if (EQ (XCDR (XCAR (lynk)), buffer))
1362 /* Effectively do Vbuffer_alist = delq_no_quit (lynk, Vbuffer_alist) */
1364 Vbuffer_alist = XCDR (Vbuffer_alist);
1366 XCDR (prev) = XCDR (XCDR (prev));
1367 XCDR (lynk) = Vbuffer_alist;
1368 Vbuffer_alist = lynk;
1370 /* That was the global one. Now do the same thing for the
1371 per-frame buffer-alist. */
1373 for (lynk = f->buffer_alist; CONSP (lynk); lynk = XCDR (lynk))
1375 if (EQ (XCDR (XCAR (lynk)), buffer))
1379 /* Effectively do f->buffer_alist = delq_no_quit (lynk, f->buffer_alist) */
1381 f->buffer_alist = XCDR (f->buffer_alist);
1383 XCDR (prev) = XCDR (XCDR (prev));
1384 XCDR (lynk) = f->buffer_alist;
1385 f->buffer_alist = lynk;
1390 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, 1, 1, 0, /*
1391 Set an appropriate major mode for BUFFER, according to `default-major-mode'.
1392 Use this function before selecting the buffer, since it may need to inspect
1393 the current buffer's major mode.
1397 int speccount = specpdl_depth ();
1398 Lisp_Object function = XBUFFER (Vbuffer_defaults)->major_mode;
1400 if (NILP (function))
1402 Lisp_Object tem = Fget (current_buffer->major_mode, Qmode_class, Qnil);
1404 function = current_buffer->major_mode;
1407 if (NILP (function) || EQ (function, Qfundamental_mode))
1410 /* To select a nonfundamental mode,
1411 select the buffer temporarily and then call the mode function. */
1413 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
1415 Fset_buffer (buffer);
1418 return unbind_to (speccount, Qnil);
1422 switch_to_buffer (Lisp_Object bufname, Lisp_Object norecord)
1424 call2 (Qswitch_to_buffer, bufname, norecord);
1428 DEFUN ("current-buffer", Fcurrent_buffer, 0, 0, 0, /*
1429 Return the current buffer as a Lisp object.
1434 XSETBUFFER (buffer, current_buffer);
1438 /* Set the current buffer to B. */
1441 set_buffer_internal (struct buffer *b)
1443 REGISTER struct buffer *old_buf;
1444 REGISTER Lisp_Object tail;
1446 if (current_buffer == b)
1449 INVALIDATE_PIXEL_TO_GLYPH_CACHE;
1451 old_buf = current_buffer;
1453 invalidate_current_column (); /* invalidate indentation cache */
1457 /* Put the undo list back in the base buffer, so that it appears
1458 that an indirect buffer shares the undo list of its base. */
1459 if (old_buf->base_buffer)
1460 old_buf->base_buffer->undo_list = old_buf->undo_list;
1463 /* Get the undo list from the base buffer, so that it appears
1464 that an indirect buffer shares the undo list of its base. */
1466 b->undo_list = b->base_buffer->undo_list;
1468 /* Look down buffer's list of local Lisp variables
1469 to find and update any that forward into C variables. */
1471 LIST_LOOP (tail, b->local_var_alist)
1473 Lisp_Object sym = XCAR (XCAR (tail));
1474 Lisp_Object valcontents = XSYMBOL (sym)->value;
1475 if (SYMBOL_VALUE_MAGIC_P (valcontents))
1477 /* Just reference the variable
1478 to cause it to become set for this buffer. */
1479 /* Use find_symbol_value_quickly to avoid an unnecessary O(n)
1481 (void) find_symbol_value_quickly (XCAR (tail), 1);
1485 /* Do the same with any others that were local to the previous buffer */
1489 LIST_LOOP (tail, old_buf->local_var_alist)
1491 Lisp_Object sym = XCAR (XCAR (tail));
1492 Lisp_Object valcontents = XSYMBOL (sym)->value;
1494 if (SYMBOL_VALUE_MAGIC_P (valcontents))
1496 /* Just reference the variable
1497 to cause it to become set for this buffer. */
1498 /* Use find_symbol_value_quickly with find_it_p as 0 to avoid an
1499 unnecessary O(n) lookup which is guaranteed to be worst case.
1500 Any symbols which are local are guaranteed to have been
1501 handled in the previous loop, above. */
1502 (void) find_symbol_value_quickly (sym, 0);
1508 DEFUN ("set-buffer", Fset_buffer, 1, 1, 0, /*
1509 Make the buffer BUFFER current for editing operations.
1510 BUFFER may be a buffer or the name of an existing buffer.
1511 See also `save-excursion' when you want to make a buffer current temporarily.
1512 This function does not display the buffer, so its effect ends
1513 when the current command terminates.
1514 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.
1518 buffer = get_buffer (buffer, 0);
1520 error ("Selecting deleted or non-existent buffer");
1521 set_buffer_internal (XBUFFER (buffer));
1526 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, 0, 3, 0, /*
1527 Signal a `buffer-read-only' error if the buffer is read-only.
1528 Optional argument BUFFER defaults to the current buffer.
1530 If optional argument START is non-nil, all extents in the buffer
1531 which overlap that part of the buffer are checked to ensure none has a
1532 `read-only' property. (Extents that lie completely within the range,
1533 however, are not checked.) END defaults to the value of START.
1535 If START and END are equal, the range checked is [START, END] (i.e.
1536 closed on both ends); otherwise, the range checked is (START, END)
1537 \(open on both ends), except that extents that lie completely within
1538 [START, END] are not checked. See `extent-in-region-p' for a fuller
1541 (buffer, start, end))
1543 struct buffer *b = decode_buffer (buffer, 0);
1552 get_buffer_range_char (b, start, end, &s, &e, 0);
1554 barf_if_buffer_read_only (b, s, e);
1560 bury_buffer_1 (Lisp_Object buffer, Lisp_Object before,
1561 Lisp_Object *buffer_alist)
1563 Lisp_Object aelt = rassq_no_quit (buffer, *buffer_alist);
1564 Lisp_Object lynk = memq_no_quit (aelt, *buffer_alist);
1565 Lisp_Object iter, before_before;
1567 *buffer_alist = delq_no_quit (aelt, *buffer_alist);
1568 for (before_before = Qnil, iter = *buffer_alist;
1569 !NILP (iter) && !EQ (XCDR (XCAR (iter)), before);
1570 before_before = iter, iter = XCDR (iter))
1573 if (!NILP (before_before))
1574 XCDR (before_before) = lynk;
1576 *buffer_alist = lynk;
1579 DEFUN ("bury-buffer", Fbury_buffer, 0, 2, "", /*
1580 Put BUFFER at the end of the list of all buffers.
1581 There it is the least likely candidate for `other-buffer' to return;
1582 thus, the least likely buffer for \\[switch-to-buffer] to select by default.
1583 If BUFFER is nil or omitted, bury the current buffer.
1584 Also, if BUFFER is nil or omitted, remove the current buffer from the
1585 selected window if it is displayed there.
1586 Because of this, you may need to specify (current-buffer) as
1587 BUFFER when calling from minibuffer.
1588 If BEFORE is non-nil, it specifies a buffer before which BUFFER
1589 will be placed, instead of being placed at the end.
1593 /* This function can GC */
1594 struct buffer *buf = decode_buffer (buffer, 1);
1595 /* If we're burying the current buffer, unshow it. */
1596 /* Note that the behavior of (bury-buffer nil) and
1597 (bury-buffer (current-buffer)) is not the same.
1598 This is illogical but is historical. Changing it
1599 breaks mh-e and TeX and such packages. */
1601 switch_to_buffer (Fother_buffer (Fcurrent_buffer (), Qnil, Qnil), Qnil);
1602 XSETBUFFER (buffer, buf);
1605 before = get_buffer (before, 1);
1607 if (EQ (before, buffer))
1608 error ("Cannot place a buffer before itself");
1610 bury_buffer_1 (buffer, before, &Vbuffer_alist);
1611 bury_buffer_1 (buffer, before, &selected_frame ()->buffer_alist);
1617 DEFUN ("erase-buffer", Ferase_buffer, 0, 1, "*", /*
1618 Delete the entire contents of the BUFFER.
1619 Any clipping restriction in effect (see `narrow-to-region') is removed,
1620 so the buffer is truly empty after this.
1621 BUFFER defaults to the current buffer if omitted.
1625 /* This function can GC */
1626 struct buffer *b = decode_buffer (buffer, 1);
1627 /* #### yuck yuck yuck. This is gross. The old echo-area code,
1628 however, was the only place that called erase_buffer() with a
1629 non-zero NO_CLIP argument.
1631 Someone needs to fix up the redisplay code so it is smarter
1632 about this, so that the NO_CLIP junk isn't necessary. */
1633 int no_clip = (b == XBUFFER (Vecho_area_buffer));
1635 INVALIDATE_PIXEL_TO_GLYPH_CACHE;
1637 widen_buffer (b, no_clip);
1638 buffer_delete_range (b, BUF_BEG (b), BUF_Z (b), 0);
1639 b->last_window_start = 1;
1641 /* Prevent warnings, or suspension of auto saving, that would happen
1642 if future size is less than past size. Use of erase-buffer
1643 implies that the future text is not really related to the past text. */
1644 b->saved_size = Qzero;
1646 zmacs_region_stays = 0;
1652 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, 0, 0, 0, /*
1653 Switch to Fundamental mode by killing current buffer's local variables.
1654 Most local variable bindings are eliminated so that the default values
1655 become effective once more. Also, the syntax table is set from
1656 `standard-syntax-table', the category table is set from
1657 `standard-category-table' (if support for Mule exists), local keymap is set
1658 to nil, the abbrev table is set from `fundamental-mode-abbrev-table',
1659 and all specifier specifications whose locale is the current buffer
1660 are removed. This function also forces redisplay of the modeline.
1662 Every function to select a new major mode starts by
1663 calling this function.
1665 As a special exception, local variables whose names have
1666 a non-nil `permanent-local' property are not eliminated by this function.
1668 The first thing this function does is run
1669 the normal hook `change-major-mode-hook'.
1673 /* This function can GC */
1674 run_hook (Qchange_major_mode_hook);
1676 reset_buffer_local_variables (current_buffer, 0);
1678 kill_buffer_local_variables (current_buffer);
1680 kill_specifier_buffer_locals (Fcurrent_buffer ());
1682 /* Force modeline redisplay. Useful here because all major mode
1683 commands call this function. */
1684 MARK_MODELINE_CHANGED;
1689 #ifdef MEMORY_USAGE_STATS
1700 compute_buffer_text_usage (struct buffer *b, struct overhead_stats *ovstats)
1702 int was_requested = b->text->z - 1;
1703 size_t gap = b->text->gap_size + b->text->end_gap_size;
1704 size_t malloc_use = malloced_storage_size (b->text->beg, was_requested + gap, 0);
1706 ovstats->gap_overhead += gap;
1707 ovstats->was_requested += was_requested;
1708 ovstats->malloc_overhead += malloc_use - (was_requested + gap);
1713 compute_buffer_usage (struct buffer *b, struct buffer_stats *stats,
1714 struct overhead_stats *ovstats)
1717 stats->other += malloced_storage_size (b, sizeof (*b), ovstats);
1718 stats->text += compute_buffer_text_usage (b, ovstats);
1719 stats->markers += compute_buffer_marker_usage (b, ovstats);
1720 stats->extents += compute_buffer_extent_usage (b, ovstats);
1723 DEFUN ("buffer-memory-usage", Fbuffer_memory_usage, 1, 1, 0, /*
1724 Return stats about the memory usage of buffer BUFFER.
1725 The values returned are in the form of an alist of usage types and byte
1726 counts. The byte counts attempt to encompass all the memory used
1727 by the buffer (separate from the memory logically associated with a
1728 buffer or frame), including internal structures and any malloc()
1729 overhead associated with them. In practice, the byte counts are
1730 underestimated because certain memory usage is very hard to determine
1731 \(e.g. the amount of memory used inside the Xt library or inside the
1732 X server) and because there is other stuff that might logically
1733 be associated with a window, buffer, or frame (e.g. window configurations,
1734 glyphs) but should not obviously be included in the usage counts.
1736 Multiple slices of the total memory usage may be returned, separated
1737 by a nil. Each slice represents a particular view of the memory, a
1738 particular way of partitioning it into groups. Within a slice, there
1739 is no overlap between the groups of memory, and each slice collectively
1740 represents all the memory concerned.
1744 struct buffer_stats stats;
1745 struct overhead_stats ovstats;
1746 Lisp_Object val = Qnil;
1748 CHECK_BUFFER (buffer); /* dead buffers should be allowed, no? */
1750 compute_buffer_usage (XBUFFER (buffer), &stats, &ovstats);
1752 val = acons (Qtext, make_int (stats.text), val);
1753 val = acons (Qmarkers, make_int (stats.markers), val);
1754 val = acons (Qextents, make_int (stats.extents), val);
1755 val = acons (Qother, make_int (stats.other), val);
1756 val = Fcons (Qnil, val);
1757 val = acons (Qactually_requested, make_int (ovstats.was_requested), val);
1758 val = acons (Qmalloc_overhead, make_int (ovstats.malloc_overhead), val);
1759 val = acons (Qgap_overhead, make_int (ovstats.gap_overhead), val);
1760 val = acons (Qdynarr_overhead, make_int (ovstats.dynarr_overhead), val);
1762 return Fnreverse (val);
1765 #endif /* MEMORY_USAGE_STATS */
1768 /************************************************************************/
1769 /* Implement TO_EXTERNAL_FORMAT, TO_INTERNAL_FORMAT */
1770 /************************************************************************/
1772 /* This implementation should probably be elsewhere, but it can't be
1773 in file-coding.c since that file is only available if FILE_CODING
1777 coding_system_is_binary (Lisp_Object coding_system)
1779 Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system);
1781 (CODING_SYSTEM_TYPE (cs) == CODESYS_NO_CONVERSION &&
1782 CODING_SYSTEM_EOL_TYPE (cs) == EOL_LF &&
1783 EQ (CODING_SYSTEM_POST_READ_CONVERSION (cs), Qnil) &&
1784 EQ (CODING_SYSTEM_PRE_WRITE_CONVERSION (cs), Qnil));
1787 #define coding_system_is_binary(coding_system) 1
1792 Dynarr_declare (Bufbyte_dynarr *);
1793 } Bufbyte_dynarr_dynarr;
1797 Dynarr_declare (Extbyte_dynarr *);
1798 } Extbyte_dynarr_dynarr;
1800 static Extbyte_dynarr_dynarr *conversion_out_dynarr_list;
1801 static Bufbyte_dynarr_dynarr *conversion_in_dynarr_list;
1803 static int dfc_convert_to_external_format_in_use;
1804 static int dfc_convert_to_internal_format_in_use;
1807 dfc_convert_to_external_format_reset_in_use (Lisp_Object value)
1809 dfc_convert_to_external_format_in_use = XINT (value);
1814 dfc_convert_to_internal_format_reset_in_use (Lisp_Object value)
1816 dfc_convert_to_internal_format_in_use = XINT (value);
1821 dfc_convert_to_external_format (dfc_conversion_type source_type,
1822 dfc_conversion_data *source,
1824 Lisp_Object coding_system,
1826 dfc_conversion_type sink_type,
1827 dfc_conversion_data *sink)
1829 int count = specpdl_depth ();
1830 Extbyte_dynarr *conversion_out_dynarr;
1832 type_checking_assert
1833 (((source_type == DFC_TYPE_DATA) ||
1834 (source_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object)) ||
1835 (source_type == DFC_TYPE_LISP_STRING && STRINGP (source->lisp_object)))
1837 ((sink_type == DFC_TYPE_DATA) ||
1838 (sink_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object))));
1840 record_unwind_protect (dfc_convert_to_external_format_reset_in_use,
1841 make_int (dfc_convert_to_external_format_in_use));
1842 if (Dynarr_length (conversion_out_dynarr_list) <=
1843 dfc_convert_to_external_format_in_use)
1844 Dynarr_add (conversion_out_dynarr_list, Dynarr_new (Extbyte));
1845 conversion_out_dynarr = Dynarr_at (conversion_out_dynarr_list,
1846 dfc_convert_to_external_format_in_use);
1847 dfc_convert_to_external_format_in_use++;
1848 Dynarr_reset (conversion_out_dynarr);
1851 coding_system = Fget_coding_system (coding_system);
1854 /* Here we optimize in the case where the coding system does no
1855 conversion. However, we don't want to optimize in case the source
1856 or sink is an lstream, since writing to an lstream can cause a
1857 garbage collection, and this could be problematic if the source
1858 is a lisp string. */
1859 if (source_type != DFC_TYPE_LISP_LSTREAM &&
1860 sink_type != DFC_TYPE_LISP_LSTREAM &&
1861 coding_system_is_binary (coding_system))
1866 if (source_type == DFC_TYPE_LISP_STRING)
1868 ptr = XSTRING_DATA (source->lisp_object);
1869 len = XSTRING_LENGTH (source->lisp_object);
1873 ptr = (Bufbyte *) source->data.ptr;
1874 len = source->data.len;
1880 for (end = ptr + len; ptr < end;)
1884 (*ptr < 0xc0) ? *ptr :
1885 ((*ptr & 0x1f) << 6) | (*(ptr+1) & 0x3f);
1888 (BYTE_ASCII_P (*ptr)) ? *ptr :
1889 (*ptr == LEADING_BYTE_CONTROL_1) ? (*(ptr+1) - 0x20) :
1890 (*ptr == LEADING_BYTE_LATIN_ISO8859_1) ? (*(ptr+1)) :
1894 Dynarr_add (conversion_out_dynarr, (Extbyte) c);
1897 bufpos_checking_assert (ptr == end);
1900 Dynarr_add_many (conversion_out_dynarr, ptr, len);
1906 Lisp_Object streams_to_delete[3];
1907 int delete_count = 0;
1908 Lisp_Object instream, outstream;
1909 Lstream *reader, *writer;
1910 struct gcpro gcpro1, gcpro2;
1912 if (source_type == DFC_TYPE_LISP_LSTREAM)
1913 instream = source->lisp_object;
1914 else if (source_type == DFC_TYPE_DATA)
1915 streams_to_delete[delete_count++] = instream =
1916 make_fixed_buffer_input_stream (source->data.ptr, source->data.len);
1919 type_checking_assert (source_type == DFC_TYPE_LISP_STRING);
1920 streams_to_delete[delete_count++] = instream =
1921 make_lisp_string_input_stream (source->lisp_object, 0, -1);
1924 if (sink_type == DFC_TYPE_LISP_LSTREAM)
1925 outstream = sink->lisp_object;
1928 type_checking_assert (sink_type == DFC_TYPE_DATA);
1929 streams_to_delete[delete_count++] = outstream =
1930 make_dynarr_output_stream
1931 ((unsigned_char_dynarr *) conversion_out_dynarr);
1935 streams_to_delete[delete_count++] = outstream =
1936 make_encoding_output_stream (XLSTREAM (outstream), coding_system);
1939 reader = XLSTREAM (instream);
1940 writer = XLSTREAM (outstream);
1941 /* decoding_stream will gc-protect outstream */
1942 GCPRO2 (instream, outstream);
1946 ssize_t size_in_bytes;
1947 char tempbuf[1024]; /* some random amount */
1949 size_in_bytes = Lstream_read (reader, tempbuf, sizeof (tempbuf));
1951 if (size_in_bytes == 0)
1953 else if (size_in_bytes < 0)
1954 error ("Error converting to external format");
1956 size_in_bytes = Lstream_write (writer, tempbuf, size_in_bytes);
1958 if (size_in_bytes <= 0)
1959 error ("Error converting to external format");
1962 /* Closing writer will close any stream at the other end of writer. */
1963 Lstream_close (writer);
1964 Lstream_close (reader);
1967 /* The idea is that this function will create no garbage. */
1968 while (delete_count)
1969 Lstream_delete (XLSTREAM (streams_to_delete [--delete_count]));
1972 unbind_to (count, Qnil);
1974 if (sink_type != DFC_TYPE_LISP_LSTREAM)
1976 sink->data.len = Dynarr_length (conversion_out_dynarr);
1977 Dynarr_add (conversion_out_dynarr, 0);
1978 sink->data.ptr = Dynarr_atp (conversion_out_dynarr, 0);
1983 dfc_convert_to_internal_format (dfc_conversion_type source_type,
1984 dfc_conversion_data *source,
1986 Lisp_Object coding_system,
1988 dfc_conversion_type sink_type,
1989 dfc_conversion_data *sink)
1991 int count = specpdl_depth ();
1992 Bufbyte_dynarr *conversion_in_dynarr;
1994 type_checking_assert
1995 ((source_type == DFC_TYPE_DATA ||
1996 source_type == DFC_TYPE_LISP_LSTREAM)
1998 (sink_type == DFC_TYPE_DATA ||
1999 sink_type == DFC_TYPE_LISP_LSTREAM));
2001 record_unwind_protect (dfc_convert_to_internal_format_reset_in_use,
2002 make_int (dfc_convert_to_internal_format_in_use));
2003 if (Dynarr_length (conversion_in_dynarr_list) <=
2004 dfc_convert_to_internal_format_in_use)
2005 Dynarr_add (conversion_in_dynarr_list, Dynarr_new (Bufbyte));
2006 conversion_in_dynarr = Dynarr_at (conversion_in_dynarr_list,
2007 dfc_convert_to_internal_format_in_use);
2008 dfc_convert_to_internal_format_in_use++;
2009 Dynarr_reset (conversion_in_dynarr);
2012 coding_system = Fget_coding_system (coding_system);
2015 if (source_type != DFC_TYPE_LISP_LSTREAM &&
2016 sink_type != DFC_TYPE_LISP_LSTREAM &&
2017 coding_system_is_binary (coding_system))
2020 const Bufbyte *ptr = (const Bufbyte *) source->data.ptr;
2021 Bytecount len = source->data.len;
2022 const Bufbyte *end = ptr + len;
2024 for (; ptr < end; ptr++)
2029 if (BYTE_ASCII_P (c))
2030 Dynarr_add (conversion_in_dynarr, c);
2033 Dynarr_add (conversion_in_dynarr, (c >> 6) | 0xC0);
2034 Dynarr_add (conversion_in_dynarr, (c & 0x3F) | 0x80);
2037 if (BYTE_ASCII_P (c))
2038 Dynarr_add (conversion_in_dynarr, c);
2039 else if (BYTE_C1_P (c))
2041 Dynarr_add (conversion_in_dynarr, LEADING_BYTE_CONTROL_1);
2042 Dynarr_add (conversion_in_dynarr, c + 0x20);
2046 Dynarr_add (conversion_in_dynarr, LEADING_BYTE_LATIN_ISO8859_1);
2047 Dynarr_add (conversion_in_dynarr, c);
2052 Dynarr_add_many (conversion_in_dynarr, source->data.ptr, source->data.len);
2057 Lisp_Object streams_to_delete[3];
2058 int delete_count = 0;
2059 Lisp_Object instream, outstream;
2060 Lstream *reader, *writer;
2061 struct gcpro gcpro1, gcpro2;
2063 if (source_type == DFC_TYPE_LISP_LSTREAM)
2064 instream = source->lisp_object;
2067 type_checking_assert (source_type == DFC_TYPE_DATA);
2068 streams_to_delete[delete_count++] = instream =
2069 make_fixed_buffer_input_stream (source->data.ptr, source->data.len);
2072 if (sink_type == DFC_TYPE_LISP_LSTREAM)
2073 outstream = sink->lisp_object;
2076 type_checking_assert (sink_type == DFC_TYPE_DATA);
2077 streams_to_delete[delete_count++] = outstream =
2078 make_dynarr_output_stream
2079 ((unsigned_char_dynarr *) conversion_in_dynarr);
2083 streams_to_delete[delete_count++] = outstream =
2084 make_decoding_output_stream (XLSTREAM (outstream), coding_system);
2087 reader = XLSTREAM (instream);
2088 writer = XLSTREAM (outstream);
2089 /* outstream will gc-protect its sink stream, if necessary */
2090 GCPRO2 (instream, outstream);
2094 ssize_t size_in_bytes;
2095 char tempbuf[1024]; /* some random amount */
2097 size_in_bytes = Lstream_read (reader, tempbuf, sizeof (tempbuf));
2099 if (size_in_bytes == 0)
2101 else if (size_in_bytes < 0)
2102 error ("Error converting to internal format");
2104 size_in_bytes = Lstream_write (writer, tempbuf, size_in_bytes);
2106 if (size_in_bytes <= 0)
2107 error ("Error converting to internal format");
2110 /* Closing writer will close any stream at the other end of writer. */
2111 Lstream_close (writer);
2112 Lstream_close (reader);
2115 /* The idea is that this function will create no garbage. */
2116 while (delete_count)
2117 Lstream_delete (XLSTREAM (streams_to_delete [--delete_count]));
2120 unbind_to (count, Qnil);
2122 if (sink_type != DFC_TYPE_LISP_LSTREAM)
2124 sink->data.len = Dynarr_length (conversion_in_dynarr);
2125 Dynarr_add (conversion_in_dynarr, 0); /* remember to zero-terminate! */
2126 sink->data.ptr = Dynarr_atp (conversion_in_dynarr, 0);
2132 syms_of_buffer (void)
2134 INIT_LRECORD_IMPLEMENTATION (buffer);
2136 defsymbol (&Qbuffer_live_p, "buffer-live-p");
2137 defsymbol (&Qbuffer_or_string_p, "buffer-or-string-p");
2138 defsymbol (&Qmode_class, "mode-class");
2139 defsymbol (&Qrename_auto_save_file, "rename-auto-save-file");
2140 defsymbol (&Qkill_buffer_hook, "kill-buffer-hook");
2141 defsymbol (&Qpermanent_local, "permanent-local");
2143 defsymbol (&Qfirst_change_hook, "first-change-hook");
2144 defsymbol (&Qbefore_change_functions, "before-change-functions");
2145 defsymbol (&Qafter_change_functions, "after-change-functions");
2147 /* #### Obsolete, for compatibility */
2148 defsymbol (&Qbefore_change_function, "before-change-function");
2149 defsymbol (&Qafter_change_function, "after-change-function");
2151 defsymbol (&Qdefault_directory, "default-directory");
2153 defsymbol (&Qget_file_buffer, "get-file-buffer");
2154 defsymbol (&Qchange_major_mode_hook, "change-major-mode-hook");
2156 defsymbol (&Qfundamental_mode, "fundamental-mode");
2158 defsymbol (&Qfind_file_compare_truenames, "find-file-compare-truenames");
2160 defsymbol (&Qswitch_to_buffer, "switch-to-buffer");
2163 DEFSUBR (Fbuffer_live_p);
2164 DEFSUBR (Fbuffer_list);
2165 DEFSUBR (Fdecode_buffer);
2166 DEFSUBR (Fget_buffer);
2167 DEFSUBR (Fget_file_buffer);
2168 DEFSUBR (Fget_buffer_create);
2169 DEFSUBR (Fmake_indirect_buffer);
2171 DEFSUBR (Fgenerate_new_buffer_name);
2172 DEFSUBR (Fbuffer_name);
2173 DEFSUBR (Fbuffer_file_name);
2174 DEFSUBR (Fbuffer_base_buffer);
2175 DEFSUBR (Fbuffer_indirect_children);
2176 DEFSUBR (Fbuffer_local_variables);
2177 DEFSUBR (Fbuffer_modified_p);
2178 DEFSUBR (Fset_buffer_modified_p);
2179 DEFSUBR (Fbuffer_modified_tick);
2180 DEFSUBR (Frename_buffer);
2181 DEFSUBR (Fother_buffer);
2182 DEFSUBR (Fbuffer_disable_undo);
2183 DEFSUBR (Fbuffer_enable_undo);
2184 DEFSUBR (Fkill_buffer);
2185 DEFSUBR (Ferase_buffer);
2186 DEFSUBR (Frecord_buffer);
2187 DEFSUBR (Fset_buffer_major_mode);
2188 DEFSUBR (Fcurrent_buffer);
2189 DEFSUBR (Fset_buffer);
2190 DEFSUBR (Fbarf_if_buffer_read_only);
2191 DEFSUBR (Fbury_buffer);
2192 DEFSUBR (Fkill_all_local_variables);
2193 #ifdef MEMORY_USAGE_STATS
2194 DEFSUBR (Fbuffer_memory_usage);
2197 DEFERROR (Qprotected_field, "Attempt to modify a protected field",
2202 reinit_vars_of_buffer (void)
2204 conversion_in_dynarr_list = Dynarr_new2 (Bufbyte_dynarr_dynarr,
2206 conversion_out_dynarr_list = Dynarr_new2 (Extbyte_dynarr_dynarr,
2209 staticpro_nodump (&Vbuffer_alist);
2210 Vbuffer_alist = Qnil;
2214 /* initialize the buffer routines */
2216 vars_of_buffer (void)
2218 /* This function can GC */
2219 reinit_vars_of_buffer ();
2221 staticpro (&QSFundamental);
2222 staticpro (&QSscratch);
2224 QSFundamental = build_string ("Fundamental");
2225 QSscratch = build_string (DEFER_GETTEXT ("*scratch*"));
2227 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook /*
2228 List of hooks to be run before killing local variables in a buffer.
2229 This should be used by any mode that temporarily alters the contents or
2230 the read-only state of the buffer. See also `kill-all-local-variables'.
2232 Vchange_major_mode_hook = Qnil;
2234 DEFVAR_BOOL ("find-file-compare-truenames", &find_file_compare_truenames /*
2235 If this is true, then the find-file command will check the truenames
2236 of all visited files when deciding whether a given file is already in
2237 a buffer, instead of just the buffer-file-name. This means that if you
2238 attempt to visit another file which is a symbolic-link to a file which is
2239 already in a buffer, the existing buffer will be found instead of a newly-
2240 created one. This works if any component of the pathname (including a non-
2241 terminal component) is a symbolic link as well, but doesn't work with hard
2242 links (nothing does).
2244 See also the variable find-file-use-truenames.
2246 find_file_compare_truenames = 0;
2248 DEFVAR_BOOL ("find-file-use-truenames", &find_file_use_truenames /*
2249 If this is true, then a buffer's visited file-name will always be
2250 chased back to the real file; it will never be a symbolic link, and there
2251 will never be a symbolic link anywhere in its directory path.
2252 That is, the buffer-file-name and buffer-file-truename will be equal.
2253 This doesn't work with hard links.
2255 See also the variable find-file-compare-truenames.
2257 find_file_use_truenames = 0;
2259 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions /*
2260 List of functions to call before each text change.
2261 Two arguments are passed to each function: the positions of
2262 the beginning and end of the range of old text to be changed.
2263 \(For an insertion, the beginning and end are at the same place.)
2264 No information is given about the length of the text after the change.
2266 Buffer changes made while executing the `before-change-functions'
2267 don't call any before-change or after-change functions.
2269 Vbefore_change_functions = Qnil;
2271 /* FSF Emacs has the following additional doc at the end of
2272 before-change-functions and after-change-functions:
2274 That's because these variables are temporarily set to nil.
2275 As a result, a hook function cannot straightforwardly alter the value of
2276 these variables. See the Emacs Lisp manual for a way of
2277 accomplishing an equivalent result by using other variables.
2279 But this doesn't apply under XEmacs because things are
2282 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions /*
2283 List of functions to call after each text change.
2284 Three arguments are passed to each function: the positions of
2285 the beginning and end of the range of changed text,
2286 and the length of the pre-change text replaced by that range.
2287 \(For an insertion, the pre-change length is zero;
2288 for a deletion, that length is the number of characters deleted,
2289 and the post-change beginning and end are at the same place.)
2291 Buffer changes made while executing `after-change-functions'
2292 don't call any before-change or after-change functions.
2294 Vafter_change_functions = Qnil;
2296 DEFVAR_LISP ("before-change-function", &Vbefore_change_function /*
2298 */ ); /* obsoleteness will be documented */
2299 Vbefore_change_function = Qnil;
2301 DEFVAR_LISP ("after-change-function", &Vafter_change_function /*
2303 */ ); /* obsoleteness will be documented */
2304 Vafter_change_function = Qnil;
2306 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook /*
2307 A list of functions to call before changing a buffer which is unmodified.
2308 The functions are run using the `run-hooks' function.
2310 Vfirst_change_hook = Qnil;
2313 xxDEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode /*
2314 *Non-nil means deactivate the mark when the buffer contents change.
2316 Vtransient_mark_mode = Qnil;
2317 #endif /* FSFmacs */
2319 DEFVAR_INT ("undo-threshold", &undo_threshold /*
2320 Keep no more undo information once it exceeds this size.
2321 This threshold is applied when garbage collection happens.
2322 The size is counted as the number of bytes occupied,
2323 which includes both saved text and other data.
2325 undo_threshold = 20000;
2327 DEFVAR_INT ("undo-high-threshold", &undo_high_threshold /*
2328 Don't keep more than this much size of undo information.
2329 A command which pushes past this size is itself forgotten.
2330 This threshold is applied when garbage collection happens.
2331 The size is counted as the number of bytes occupied,
2332 which includes both saved text and other data.
2334 undo_high_threshold = 30000;
2336 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only /*
2337 *Non-nil means disregard read-only status of buffers or characters.
2338 If the value is t, disregard `buffer-read-only' and all `read-only'
2339 text properties. If the value is a list, disregard `buffer-read-only'
2340 and disregard a `read-only' extent property or text property if the
2341 property value is a member of the list.
2343 Vinhibit_read_only = Qnil;
2345 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions /*
2346 List of functions called with no args to query before killing a buffer.
2348 Vkill_buffer_query_functions = Qnil;
2350 DEFVAR_BOOL ("delete-auto-save-files", &delete_auto_save_files /*
2351 *Non-nil means delete auto-save file when a buffer is saved or killed.
2353 delete_auto_save_files = 1;
2356 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */
2358 /* Renamed from DEFVAR_PER_BUFFER because FSFmacs D_P_B takes
2359 a bogus extra arg, which confuses an otherwise identical make-docfile.c */
2360 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magicfun) do { \
2361 static const struct symbol_value_forward I_hate_C = \
2362 { /* struct symbol_value_forward */ \
2363 { /* struct symbol_value_magic */ \
2364 { /* struct lcrecord_header */ \
2365 { /* struct lrecord_header */ \
2366 lrecord_type_symbol_value_forward, /* lrecord_type_index */ \
2368 1, /* c_readonly bit */ \
2369 1 /* lisp_readonly bit */ \
2375 &(buffer_local_flags.field_name), \
2382 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) - \
2383 (char *)&buffer_local_flags); \
2384 defvar_magic (lname, &I_hate_C); \
2386 *((Lisp_Object *)(offset + (char *)XBUFFER (Vbuffer_local_symbols))) \
2391 #define DEFVAR_BUFFER_LOCAL_MAGIC(lname, field_name, magicfun) \
2392 DEFVAR_BUFFER_LOCAL_1 (lname, field_name, \
2393 SYMVAL_CURRENT_BUFFER_FORWARD, magicfun)
2394 #define DEFVAR_BUFFER_LOCAL(lname, field_name) \
2395 DEFVAR_BUFFER_LOCAL_MAGIC (lname, field_name, 0)
2396 #define DEFVAR_CONST_BUFFER_LOCAL_MAGIC(lname, field_name, magicfun) \
2397 DEFVAR_BUFFER_LOCAL_1 (lname, field_name, \
2398 SYMVAL_CONST_CURRENT_BUFFER_FORWARD, magicfun)
2399 #define DEFVAR_CONST_BUFFER_LOCAL(lname, field_name) \
2400 DEFVAR_CONST_BUFFER_LOCAL_MAGIC (lname, field_name, 0)
2402 #define DEFVAR_BUFFER_DEFAULTS_MAGIC(lname, field_name, magicfun) \
2403 DEFVAR_SYMVAL_FWD (lname, &(buffer_local_flags.field_name), \
2404 SYMVAL_DEFAULT_BUFFER_FORWARD, magicfun)
2405 #define DEFVAR_BUFFER_DEFAULTS(lname, field_name) \
2406 DEFVAR_BUFFER_DEFAULTS_MAGIC (lname, field_name, 0)
2409 nuke_all_buffer_slots (struct buffer *b, Lisp_Object zap)
2413 b->extent_info = Qnil;
2414 b->indirect_children = Qnil;
2415 b->own_text.line_number_cache = Qnil;
2417 #define MARKED_SLOT(x) b->x = zap
2418 #include "bufslots.h"
2423 common_init_complex_vars_of_buffer (void)
2425 /* Make sure all markable slots in buffer_defaults
2426 are initialized reasonably, so mark_buffer won't choke. */
2427 struct buffer *defs = alloc_lcrecord_type (struct buffer, &lrecord_buffer);
2428 struct buffer *syms = alloc_lcrecord_type (struct buffer, &lrecord_buffer);
2430 staticpro_nodump (&Vbuffer_defaults);
2431 staticpro_nodump (&Vbuffer_local_symbols);
2432 XSETBUFFER (Vbuffer_defaults, defs);
2433 XSETBUFFER (Vbuffer_local_symbols, syms);
2435 nuke_all_buffer_slots (syms, Qnil);
2436 nuke_all_buffer_slots (defs, Qnil);
2437 defs->text = &defs->own_text;
2438 syms->text = &syms->own_text;
2440 /* Set up the non-nil default values of various buffer slots.
2441 Must do these before making the first buffer. */
2442 defs->major_mode = Qfundamental_mode;
2443 defs->mode_name = QSFundamental;
2444 defs->abbrev_table = Qnil; /* real default setup by Lisp code */
2446 defs->downcase_table = Vascii_downcase_table;
2447 defs->upcase_table = Vascii_upcase_table;
2448 defs->case_canon_table = Vascii_canon_table;
2449 defs->case_eqv_table = Vascii_eqv_table;
2451 defs->mirror_downcase_table = Vmirror_ascii_downcase_table;
2452 defs->mirror_upcase_table = Vmirror_ascii_upcase_table;
2453 defs->mirror_case_canon_table = Vmirror_ascii_canon_table;
2454 defs->mirror_case_eqv_table = Vmirror_ascii_eqv_table;
2456 defs->category_table = Vstandard_category_table;
2458 defs->syntax_table = Vstandard_syntax_table;
2459 defs->mirror_syntax_table =
2460 XCHAR_TABLE (Vstandard_syntax_table)->mirror_table;
2461 defs->modeline_format = build_string ("%-"); /* reset in loaddefs.el */
2462 defs->case_fold_search = Qt;
2463 defs->selective_display_ellipses = Qt;
2464 defs->tab_width = make_int (8);
2465 defs->ctl_arrow = Qt;
2466 defs->fill_column = make_int (70);
2467 defs->left_margin = Qzero;
2468 defs->saved_size = Qzero; /* lisp code wants int-or-nil */
2470 defs->auto_save_modified = 0;
2471 defs->auto_save_failure_time = -1;
2472 defs->invisibility_spec = Qt;
2474 defs->indirect_children = Qnil;
2475 syms->indirect_children = Qnil;
2478 /* 0 means var is always local. Default used only at creation.
2479 * -1 means var is always local. Default used only at reset and
2481 * -2 means there's no lisp variable corresponding to this slot
2482 * and the default is only used at creation.
2483 * -3 means no Lisp variable. Default used only at reset and creation.
2484 * >0 is mask. Var is local if ((buffer->local_var_flags & mask) != 0)
2485 * Otherwise default is used.
2487 Lisp_Object always_local_no_default = make_int (0);
2488 Lisp_Object always_local_resettable = make_int (-1);
2489 Lisp_Object resettable = make_int (-3);
2491 /* Assign the local-flags to the slots that have default values.
2492 The local flag is a bit that is used in the buffer
2493 to say that it has its own local value for the slot.
2494 The local flag bits are in the local_var_flags slot of the
2497 nuke_all_buffer_slots (&buffer_local_flags, make_int (-2));
2498 buffer_local_flags.filename = always_local_no_default;
2499 buffer_local_flags.directory = always_local_no_default;
2500 buffer_local_flags.backed_up = always_local_no_default;
2501 buffer_local_flags.saved_size = always_local_no_default;
2502 buffer_local_flags.auto_save_file_name = always_local_no_default;
2503 buffer_local_flags.read_only = always_local_no_default;
2505 buffer_local_flags.major_mode = always_local_resettable;
2506 buffer_local_flags.mode_name = always_local_resettable;
2507 buffer_local_flags.undo_list = always_local_no_default;
2509 buffer_local_flags.mark_active = always_local_resettable;
2511 buffer_local_flags.point_before_scroll = always_local_resettable;
2512 buffer_local_flags.file_truename = always_local_no_default;
2513 buffer_local_flags.invisibility_spec = always_local_resettable;
2514 buffer_local_flags.file_format = always_local_resettable;
2515 buffer_local_flags.generated_modeline_string = always_local_no_default;
2517 buffer_local_flags.keymap = resettable;
2518 buffer_local_flags.downcase_table = resettable;
2519 buffer_local_flags.upcase_table = resettable;
2520 buffer_local_flags.case_canon_table = resettable;
2521 buffer_local_flags.case_eqv_table = resettable;
2522 buffer_local_flags.syntax_table = resettable;
2524 buffer_local_flags.category_table = resettable;
2527 buffer_local_flags.modeline_format = make_int (1<<0);
2528 buffer_local_flags.abbrev_mode = make_int (1<<1);
2529 buffer_local_flags.overwrite_mode = make_int (1<<2);
2530 buffer_local_flags.case_fold_search = make_int (1<<3);
2531 buffer_local_flags.auto_fill_function = make_int (1<<4);
2532 buffer_local_flags.selective_display = make_int (1<<5);
2533 buffer_local_flags.selective_display_ellipses = make_int (1<<6);
2534 buffer_local_flags.tab_width = make_int (1<<7);
2535 buffer_local_flags.truncate_lines = make_int (1<<8);
2536 buffer_local_flags.ctl_arrow = make_int (1<<9);
2537 buffer_local_flags.fill_column = make_int (1<<10);
2538 buffer_local_flags.left_margin = make_int (1<<11);
2539 buffer_local_flags.abbrev_table = make_int (1<<12);
2540 #ifdef REGION_CACHE_NEEDS_WORK
2541 buffer_local_flags.cache_long_line_scans = make_int (1<<13);
2544 buffer_local_flags.buffer_file_coding_system = make_int (1<<14);
2547 /* #### Warning: 1<<31 is the largest number currently allowable
2548 due to the XINT() handling of this value. With some
2549 rearrangement you can get 3 more bits. */
2553 #define BUFFER_SLOTS_SIZE (offsetof (struct buffer, BUFFER_SLOTS_LAST_NAME) - offsetof (struct buffer, BUFFER_SLOTS_FIRST_NAME) + sizeof (Lisp_Object))
2554 #define BUFFER_SLOTS_COUNT (BUFFER_SLOTS_SIZE / sizeof (Lisp_Object))
2557 reinit_complex_vars_of_buffer (void)
2559 struct buffer *defs, *syms;
2561 common_init_complex_vars_of_buffer ();
2563 defs = XBUFFER (Vbuffer_defaults);
2564 syms = XBUFFER (Vbuffer_local_symbols);
2565 memcpy (&defs->BUFFER_SLOTS_FIRST_NAME,
2566 buffer_defaults_saved_slots,
2568 memcpy (&syms->BUFFER_SLOTS_FIRST_NAME,
2569 buffer_local_symbols_saved_slots,
2574 static const struct lrecord_description buffer_slots_description_1[] = {
2575 { XD_LISP_OBJECT_ARRAY, 0, BUFFER_SLOTS_COUNT },
2579 static const struct struct_description buffer_slots_description = {
2581 buffer_slots_description_1
2585 complex_vars_of_buffer (void)
2587 struct buffer *defs, *syms;
2589 common_init_complex_vars_of_buffer ();
2591 defs = XBUFFER (Vbuffer_defaults);
2592 syms = XBUFFER (Vbuffer_local_symbols);
2593 buffer_defaults_saved_slots = &defs->BUFFER_SLOTS_FIRST_NAME;
2594 buffer_local_symbols_saved_slots = &syms->BUFFER_SLOTS_FIRST_NAME;
2595 dumpstruct (&buffer_defaults_saved_slots, &buffer_slots_description);
2596 dumpstruct (&buffer_local_symbols_saved_slots, &buffer_slots_description);
2598 DEFVAR_BUFFER_DEFAULTS ("default-modeline-format", modeline_format /*
2599 Default value of `modeline-format' for buffers that don't override it.
2600 This is the same as (default-value 'modeline-format).
2603 DEFVAR_BUFFER_DEFAULTS ("default-abbrev-mode", abbrev_mode /*
2604 Default value of `abbrev-mode' for buffers that do not override it.
2605 This is the same as (default-value 'abbrev-mode).
2608 DEFVAR_BUFFER_DEFAULTS ("default-ctl-arrow", ctl_arrow /*
2609 Default value of `ctl-arrow' for buffers that do not override it.
2610 This is the same as (default-value 'ctl-arrow).
2613 #if 0 /* #### make this a specifier! */
2614 DEFVAR_BUFFER_DEFAULTS ("default-display-direction", display_direction /*
2615 Default display-direction for buffers that do not override it.
2616 This is the same as (default-value 'display-direction).
2617 Note: This is not yet implemented.
2621 DEFVAR_BUFFER_DEFAULTS ("default-truncate-lines", truncate_lines /*
2622 Default value of `truncate-lines' for buffers that do not override it.
2623 This is the same as (default-value 'truncate-lines).
2626 DEFVAR_BUFFER_DEFAULTS ("default-fill-column", fill_column /*
2627 Default value of `fill-column' for buffers that do not override it.
2628 This is the same as (default-value 'fill-column).
2631 DEFVAR_BUFFER_DEFAULTS ("default-left-margin", left_margin /*
2632 Default value of `left-margin' for buffers that do not override it.
2633 This is the same as (default-value 'left-margin).
2636 DEFVAR_BUFFER_DEFAULTS ("default-tab-width", tab_width /*
2637 Default value of `tab-width' for buffers that do not override it.
2638 This is the same as (default-value 'tab-width).
2641 DEFVAR_BUFFER_DEFAULTS ("default-case-fold-search", case_fold_search /*
2642 Default value of `case-fold-search' for buffers that don't override it.
2643 This is the same as (default-value 'case-fold-search).
2646 DEFVAR_BUFFER_LOCAL ("modeline-format", modeline_format /*
2647 Template for displaying modeline for current buffer.
2648 Each buffer has its own value of this variable.
2649 Value may be a string, symbol, glyph, generic specifier, list or cons cell.
2650 For a symbol, its value is processed (but it is ignored if t or nil).
2651 A string appearing directly as the value of a symbol is processed verbatim
2652 in that the %-constructs below are not recognized.
2653 For a glyph, it is inserted as is.
2654 For a generic specifier (i.e. a specifier of type `generic'), its instance
2655 is computed in the current window using the equivalent of `specifier-instance'
2656 and the value is processed.
2657 For a list whose car is a symbol, the symbol's value is taken,
2658 and if that is non-nil, the cadr of the list is processed recursively.
2659 Otherwise, the caddr of the list (if there is one) is processed.
2660 For a list whose car is a string or list, each element is processed
2661 recursively and the results are effectively concatenated.
2662 For a list whose car is an integer, the cdr of the list is processed
2663 and padded (if the number is positive) or truncated (if negative)
2664 to the width specified by that number.
2665 For a list whose car is an extent, the cdr of the list is processed
2666 normally but the results are displayed using the face of the
2667 extent, and mouse clicks over this section are processed using the
2668 keymap of the extent. (In addition, if the extent has a help-echo
2669 property, that string will be echoed when the mouse moves over this
2670 section.) If extents are nested, all keymaps are properly consulted
2671 when processing mouse clicks, but multiple faces are not correctly
2672 merged (only the first face is used), and lists of faces are not
2673 correctly handled. See `generated-modeline-string' for more information.
2674 A string is printed verbatim in the modeline except for %-constructs:
2675 (%-constructs are processed when the string is the entire modeline-format
2676 or when it is found in a cons-cell or a list)
2677 %b -- print buffer name. %c -- print the current column number.
2678 %f -- print visited file name.
2679 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.
2680 % means buffer is read-only and * means it is modified.
2681 For a modified read-only buffer, %* gives % and %+ gives *.
2682 %s -- print process status. %l -- print the current line number.
2683 %S -- print name of selected frame (only meaningful under X Windows).
2684 %p -- print percent of buffer above top of window, or Top, Bot or All.
2685 %P -- print percent of buffer above bottom of window, perhaps plus Top,
2686 or print Bottom or All.
2687 %n -- print Narrow if appropriate.
2688 %C -- under XEmacs/mule, print the mnemonic for `buffer-file-coding-system'.
2689 %[ -- print one [ for each recursive editing level. %] similar.
2690 %% -- print %. %- -- print infinitely many dashes.
2691 Decimal digits after the % specify field width to which to pad.
2694 DEFVAR_BUFFER_DEFAULTS ("default-major-mode", major_mode /*
2695 *Major mode for new buffers. Defaults to `fundamental-mode'.
2696 nil here means use current buffer's major mode.
2699 DEFVAR_BUFFER_DEFAULTS ("fundamental-mode-abbrev-table", abbrev_table /*
2700 The abbrev table of mode-specific abbrevs for Fundamental Mode.
2703 DEFVAR_BUFFER_LOCAL ("major-mode", major_mode /*
2704 Symbol for current buffer's major mode.
2707 DEFVAR_BUFFER_LOCAL ("mode-name", mode_name /*
2708 Pretty name of current buffer's major mode (a string).
2711 DEFVAR_BUFFER_LOCAL ("abbrev-mode", abbrev_mode /*
2712 Non-nil turns on automatic expansion of abbrevs as they are inserted.
2713 Automatically becomes buffer-local when set in any fashion.
2716 DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search /*
2717 *Non-nil if searches should ignore case.
2718 Automatically becomes buffer-local when set in any fashion.
2720 BUG: Under XEmacs/Mule, translations to or from non-ASCII characters
2721 (this includes chars in the range 128 - 255) are ignored by
2722 the string/buffer-searching routines. Thus, `case-fold-search'
2723 will not correctly conflate a-umlaut and A-umlaut even if the
2724 case tables call for this.
2727 DEFVAR_BUFFER_LOCAL ("fill-column", fill_column /*
2728 *Column beyond which automatic line-wrapping should happen.
2729 Automatically becomes buffer-local when set in any fashion.
2732 DEFVAR_BUFFER_LOCAL ("left-margin", left_margin /*
2733 *Column for the default indent-line-function to indent to.
2734 Linefeed indents to this column in Fundamental mode.
2735 Automatically becomes buffer-local when set in any fashion.
2736 Do not confuse this with the specifier `left-margin-width';
2737 that controls the size of a margin that is displayed outside
2741 DEFVAR_BUFFER_LOCAL_MAGIC ("tab-width", tab_width /*
2742 *Distance between tab stops (for display of tab characters), in columns.
2743 Automatically becomes buffer-local when set in any fashion.
2744 */ , redisplay_variable_changed);
2746 DEFVAR_BUFFER_LOCAL_MAGIC ("ctl-arrow", ctl_arrow /*
2747 *Non-nil means display control chars with uparrow.
2748 Nil means use backslash and octal digits.
2749 An integer means characters >= ctl-arrow are assumed to be printable, and
2750 will be displayed as a single glyph.
2751 Any other value is the same as 160 - the code SPC with the high bit on.
2753 The interpretation of this variable is likely to change in the future.
2755 Automatically becomes buffer-local when set in any fashion.
2756 This variable does not apply to characters whose display is specified
2757 in the current display table (if there is one).
2758 */ , redisplay_variable_changed);
2760 #if 0 /* #### Make this a specifier! */
2761 xxDEFVAR_BUFFER_LOCAL ("display-direction", display_direction /*
2762 *Non-nil means lines in the buffer are displayed right to left.
2763 Nil means left to right. (Not yet implemented.)
2765 #endif /* Not yet implemented */
2767 DEFVAR_BUFFER_LOCAL_MAGIC ("truncate-lines", truncate_lines /*
2768 *Non-nil means do not display continuation lines;
2769 give each line of text one frame line.
2770 Automatically becomes buffer-local when set in any fashion.
2772 Note that this is overridden by the variable
2773 `truncate-partial-width-windows' if that variable is non-nil
2774 and this buffer is not full-frame width.
2775 */ , redisplay_variable_changed);
2777 DEFVAR_BUFFER_LOCAL ("default-directory", directory /*
2778 Name of default directory of current buffer. Should end with slash.
2779 Each buffer has its own value of this variable.
2783 DEFVAR_BUFFER_DEFAULTS ("default-buffer-file-coding-system", buffer_file_coding_system /*
2784 Default value of `buffer-file-coding-system' for buffers that do not override it.
2785 This is the same as (default-value 'buffer-file-coding-system).
2786 This value is used both for buffers without associated files and
2787 for buffers whose files do not have any apparent coding system.
2788 See `buffer-file-coding-system'.
2791 DEFVAR_BUFFER_LOCAL ("buffer-file-coding-system", buffer_file_coding_system /*
2792 *Current coding system for the current buffer.
2793 When the buffer is written out into a file, this coding system will be
2794 used for the encoding. Automatically buffer-local when set in any
2795 fashion. This is normally set automatically when a file is loaded in
2796 based on the determined coding system of the file (assuming that
2797 `buffer-file-coding-system-for-read' is set to `undecided', which
2798 calls for automatic determination of the file's coding system).
2799 Normally the modeline indicates the current file coding system using
2800 its mnemonic abbreviation.
2802 The default value for this variable (which is normally used for
2803 buffers without associated files) is also used when automatic
2804 detection of a file's encoding is called for and there was no
2805 discernible encoding in the file (i.e. it was entirely or almost
2806 entirely ASCII). The default value should generally *not* be set to
2807 nil (equivalent to `no-conversion'), because if extended characters
2808 are ever inserted into the buffer, they will be lost when the file is
2809 written out. A good choice is `iso-2022-8' (the simple ISO 2022 8-bit
2810 encoding), which will write out ASCII and Latin-1 characters in the
2811 standard (and highly portable) fashion and use standard escape
2812 sequences for other charsets. Another reasonable choice is
2813 `escape-quoted', which is equivalent to `iso-2022-8' but prefixes
2814 certain control characters with ESC to make sure they are not
2815 interpreted as escape sequences when read in. This latter coding
2816 system results in more "correct" output in the presence of control
2817 characters in the buffer, in the sense that when read in again using
2818 the same coding system, the result will virtually always match the
2819 original contents of the buffer, which is not the case with
2820 `iso-2022-8'; but the output is less portable when dealing with binary
2821 data -- there may be stray ESC characters when the file is read by
2824 `buffer-file-coding-system' does *not* control the coding system used when
2825 a file is read in. Use the variables `buffer-file-coding-system-for-read'
2826 and `buffer-file-coding-system-alist' for that. From a Lisp program, if
2827 you wish to unilaterally specify the coding system used for one
2828 particular operation, you should bind the variable
2829 `coding-system-for-read' rather than changing the other two
2830 variables just mentioned, which are intended to be used for
2831 global environment specification.
2833 #endif /* FILE_CODING */
2835 DEFVAR_BUFFER_LOCAL ("auto-fill-function", auto_fill_function /*
2836 Function called (if non-nil) to perform auto-fill.
2837 It is called after self-inserting a space at a column beyond `fill-column'.
2838 Each buffer has its own value of this variable.
2839 NOTE: This variable is not an ordinary hook;
2840 It may not be a list of functions.
2843 DEFVAR_BUFFER_LOCAL ("buffer-file-name", filename /*
2844 Name of file visited in current buffer, or nil if not visiting a file.
2845 Each buffer has its own value of this variable.
2850 Abbreviated truename of file visited in current buffer, or nil if none.
2851 The truename of a file is calculated by `file-truename'
2852 and then abbreviated with `abbreviate-file-name'.
2853 Each buffer has its own value of this variable.
2855 #endif /* FSFmacs */
2857 DEFVAR_BUFFER_LOCAL ("buffer-file-truename", file_truename /*
2858 The real name of the file visited in the current buffer,
2859 or nil if not visiting a file. This is the result of passing
2860 buffer-file-name to the `file-truename' function. Every buffer has
2861 its own value of this variable. This variable is automatically
2862 maintained by the functions that change the file name associated
2866 DEFVAR_BUFFER_LOCAL ("buffer-auto-save-file-name", auto_save_file_name /*
2867 Name of file for auto-saving current buffer,
2868 or nil if buffer should not be auto-saved.
2869 Each buffer has its own value of this variable.
2872 DEFVAR_BUFFER_LOCAL ("buffer-read-only", read_only /*
2873 Non-nil if this buffer is read-only.
2874 Each buffer has its own value of this variable.
2877 DEFVAR_BUFFER_LOCAL ("buffer-backed-up", backed_up /*
2878 Non-nil if this buffer's file has been backed up.
2879 Backing up is done before the first time the file is saved.
2880 Each buffer has its own value of this variable.
2883 DEFVAR_BUFFER_LOCAL ("buffer-saved-size", saved_size /*
2884 Length of current buffer when last read in, saved or auto-saved.
2886 Each buffer has its own value of this variable.
2889 DEFVAR_BUFFER_LOCAL_MAGIC ("selective-display", selective_display /*
2890 Non-nil enables selective display:
2891 Integer N as value means display only lines
2892 that start with less than n columns of space.
2893 A value of t means, after a ^M, all the rest of the line is invisible.
2894 Then ^M's in the file are written into files as newlines.
2896 Automatically becomes buffer-local when set in any fashion.
2897 */, redisplay_variable_changed);
2900 DEFVAR_BUFFER_LOCAL_MAGIC ("selective-display-ellipses",
2901 selective_display_ellipses /*
2902 t means display ... on previous line when a line is invisible.
2903 Automatically becomes buffer-local when set in any fashion.
2904 */, redisplay_variable_changed);
2907 DEFVAR_BUFFER_LOCAL ("local-abbrev-table", abbrev_table /*
2908 Local (mode-specific) abbrev table of current buffer.
2911 DEFVAR_BUFFER_LOCAL ("overwrite-mode", overwrite_mode /*
2912 Non-nil if self-insertion should replace existing text.
2913 The value should be one of `overwrite-mode-textual',
2914 `overwrite-mode-binary', or nil.
2915 If it is `overwrite-mode-textual', self-insertion still
2916 inserts at the end of a line, and inserts when point is before a tab,
2917 until the tab is filled in.
2918 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.
2919 Automatically becomes buffer-local when set in any fashion.
2921 Normally, you shouldn't modify this variable by hand, but use the functions
2922 `overwrite-mode' and `binary-overwrite-mode' instead. However, you can
2923 customize the default value from the options menu.
2927 /* Adds the following to the doc string for buffer-undo-list:
2929 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property
2930 was modified between BEG and END. PROPERTY is the property name,
2931 and VALUE is the old value.
2933 #endif /* FSFmacs */
2935 DEFVAR_BUFFER_LOCAL ("buffer-undo-list", undo_list /*
2936 List of undo entries in current buffer.
2937 Recent changes come first; older changes follow newer.
2939 An entry (BEG . END) represents an insertion which begins at
2940 position BEG and ends at position END.
2942 An entry (TEXT . POSITION) represents the deletion of the string TEXT
2943 from (abs POSITION). If POSITION is positive, point was at the front
2944 of the text being deleted; if negative, point was at the end.
2946 An entry (t HIGH . LOW) indicates that the buffer previously had
2947 "unmodified" status. HIGH and LOW are the high and low 16-bit portions
2948 of the visited file's modification time, as of that time. If the
2949 modification time of the most recent save is different, this entry is
2952 An entry of the form EXTENT indicates that EXTENT was attached in
2953 the buffer. Undoing an entry of this form detaches EXTENT.
2955 An entry of the form (EXTENT START END) indicates that EXTENT was
2956 detached from the buffer. Undoing an entry of this form attaches
2957 EXTENT from START to END.
2959 An entry of the form POSITION indicates that point was at the buffer
2960 location given by the integer. Undoing an entry of this form places
2963 nil marks undo boundaries. The undo command treats the changes
2964 between two undo boundaries as a single step to be undone.
2966 If the value of the variable is t, undo information is not recorded.
2970 xxDEFVAR_BUFFER_LOCAL ("mark-active", mark_active /*
2971 Non-nil means the mark and region are currently active in this buffer.
2972 Automatically local in all buffers.
2974 #endif /* FSFmacs */
2976 #ifdef REGION_CACHE_NEEDS_WORK
2977 xxDEFVAR_BUFFER_LOCAL ("cache-long-line-scans", cache_long_line_scans /*
2978 Non-nil means that Emacs should use caches to handle long lines more quickly.
2979 This variable is buffer-local, in all buffers.
2981 Normally, the line-motion functions work by scanning the buffer for
2982 newlines. Columnar operations (like move-to-column and
2983 compute-motion) also work by scanning the buffer, summing character
2984 widths as they go. This works well for ordinary text, but if the
2985 buffer's lines are very long (say, more than 500 characters), these
2986 motion functions will take longer to execute. Emacs may also take
2987 longer to update the display.
2989 If cache-long-line-scans is non-nil, these motion functions cache the
2990 results of their scans, and consult the cache to avoid rescanning
2991 regions of the buffer until the text is modified. The caches are most
2992 beneficial when they prevent the most searching---that is, when the
2993 buffer contains long lines and large regions of characters with the
2994 same, fixed screen width.
2996 When cache-long-line-scans is non-nil, processing short lines will
2997 become slightly slower (because of the overhead of consulting the
2998 cache), and the caches will use memory roughly proportional to the
2999 number of newlines and characters whose screen width varies.
3001 The caches require no explicit maintenance; their accuracy is
3002 maintained internally by the Emacs primitives. Enabling or disabling
3003 the cache should not affect the behavior of any of the motion
3004 functions; it should only affect their performance.
3006 #endif /* REGION_CACHE_NEEDS_WORK */
3008 DEFVAR_BUFFER_LOCAL ("point-before-scroll", point_before_scroll /*
3009 Value of point before the last series of scroll operations, or nil.
3012 DEFVAR_BUFFER_LOCAL ("buffer-file-format", file_format /*
3013 List of formats to use when saving this buffer.
3014 Formats are defined by `format-alist'. This variable is
3015 set when a file is visited. Automatically local in all buffers.
3018 DEFVAR_BUFFER_LOCAL_MAGIC ("buffer-invisibility-spec", invisibility_spec /*
3019 Invisibility spec of this buffer.
3020 The default is t, which means that text is invisible
3021 if it has (or is covered by an extent with) a non-nil `invisible' property.
3022 If the value is a list, a text character is invisible if its `invisible'
3023 property is an element in that list.
3024 If an element is a cons cell of the form (PROP . ELLIPSIS),
3025 then characters with property value PROP are invisible,
3026 and they have an ellipsis as well if ELLIPSIS is non-nil.
3027 Note that the actual characters used for the ellipsis are controllable
3028 using `invisible-text-glyph', and default to "...".
3029 */, redisplay_variable_changed);
3031 DEFVAR_CONST_BUFFER_LOCAL ("generated-modeline-string",
3032 generated_modeline_string /*
3033 String of characters in this buffer's modeline as of the last redisplay.
3034 Each time the modeline is recomputed, the resulting characters are
3035 stored in this string, which is resized as necessary. You may not
3036 set this variable, and modifying this string will not change the
3037 modeline; you have to change `modeline-format' if you want that.
3039 For each extent in `modeline-format' that is encountered when
3040 processing the modeline, a corresponding extent is placed in
3041 `generated-modeline-string' and covers the text over which the
3042 extent in `modeline-format' applies. The extent in
3043 `generated-modeline-string' is made a child of the extent in
3044 `modeline-format', which means that it inherits all properties from
3045 that extent. Note that the extents in `generated-modeline-string'
3046 are managed automatically. You should not explicitly put any extents
3047 in `generated-modeline-string'; if you do, they will disappear the
3048 next time the modeline is processed.
3050 For extents in `modeline-format', the following properties are currently
3054 Affects the face of the modeline text. Currently, faces do
3055 not merge properly; only the most recently encountered face
3056 is used. This is a bug.
3059 Affects the disposition of button events over the modeline
3060 text. Multiple applicable keymaps *are* handled properly,
3061 and `modeline-map' still applies to any events that don't
3062 have bindings in extent-specific keymaps.
3065 If a string, causes the string to be displayed when the mouse
3066 moves over the text.
3069 /* Check for DEFVAR_BUFFER_LOCAL without initializing the corresponding
3070 slot of buffer_local_flags and vice-versa. Must be done after all
3071 DEFVAR_BUFFER_LOCAL() calls. */
3072 #define MARKED_SLOT(slot) \
3073 if ((XINT (buffer_local_flags.slot) != -2 && \
3074 XINT (buffer_local_flags.slot) != -3) \
3075 != !(NILP (XBUFFER (Vbuffer_local_symbols)->slot))) \
3077 #include "bufslots.h"
3081 Lisp_Object scratch = Fget_buffer_create (QSscratch);
3082 Fset_buffer (scratch);
3083 /* Want no undo records for *scratch* until after Emacs is dumped */
3084 Fbuffer_disable_undo (scratch);
3088 #ifndef WIN32_NATIVE
3089 /* Is PWD another name for `.' ? */
3091 directory_is_current_directory (Extbyte *pwd)
3093 Bufbyte *pwd_internal;
3094 Bytecount pwd_internal_len;
3095 struct stat dotstat, pwdstat;
3097 TO_INTERNAL_FORMAT (DATA, (pwd, strlen ((char *)pwd) + 1),
3098 ALLOCA, (pwd_internal, pwd_internal_len),
3101 return (IS_DIRECTORY_SEP (*pwd_internal)
3102 && xemacs_stat ((char *) pwd_internal, &pwdstat) == 0
3103 && xemacs_stat (".", &dotstat) == 0
3104 && dotstat.st_ino == pwdstat.st_ino
3105 && dotstat.st_dev == pwdstat.st_dev
3106 && pwd_internal_len < MAXPATHLEN);
3111 init_initial_directory (void)
3113 /* This function can GC */
3115 #ifndef WIN32_NATIVE
3119 initial_directory[0] = 0;
3121 /* If PWD is accurate, use it instead of calling getcwd. This is faster
3122 when PWD is right, and may avoid a fatal error. */
3123 #ifndef WIN32_NATIVE
3124 if ((pwd = (Extbyte *) getenv ("PWD")) != NULL
3125 && directory_is_current_directory (pwd))
3126 strcpy (initial_directory, (char *) pwd);
3129 if (getcwd (initial_directory, MAXPATHLEN) == NULL)
3130 fatal ("`getcwd' failed: %s\n", strerror (errno));
3132 /* Make sure pwd is DIRECTORY_SEP-terminated.
3133 Maybe this should really use some standard subroutine
3134 whose definition is filename syntax dependent. */
3136 int len = strlen (initial_directory);
3138 if (! IS_DIRECTORY_SEP (initial_directory[len - 1]))
3140 initial_directory[len] = DIRECTORY_SEP;
3141 initial_directory[len + 1] = '\0';
3145 #ifdef CORRECT_DIR_SEPS
3146 CORRECT_DIR_SEPS (initial_directory);
3153 /* This function can GC */
3155 Fset_buffer (Fget_buffer_create (QSscratch));
3157 current_buffer->directory =
3158 build_ext_string (initial_directory, Qfile_name);
3161 /* #### is this correct? */
3162 temp = get_minibuffer (0);
3163 XBUFFER (temp)->directory = current_buffer->directory;
3164 #endif /* FSFmacs */