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.
79 #include "process.h" /* for kill_buffer_processes */
80 #ifdef REGION_CACHE_NEEDS_WORK
81 #include "region-cache.h"
83 #include "specifier.h"
85 #include "sysdep.h" /* for getwd */
90 struct buffer *current_buffer; /* the current buffer */
92 /* This structure holds the default values of the buffer-local variables
93 defined with DEFVAR_BUFFER_LOCAL, that have special slots in each buffer.
94 The default value occupies the same slot in this structure
95 as an individual buffer's value occupies in that buffer.
96 Setting the default value also goes through the alist of buffers
97 and stores into each buffer that does not say it has a local value. */
98 Lisp_Object Vbuffer_defaults;
100 /* This structure marks which slots in a buffer have corresponding
101 default values in Vbuffer_defaults.
102 Each such slot has a nonzero value in this structure.
103 The value has only one nonzero bit.
105 When a buffer has its own local value for a slot,
106 the bit for that slot (found in the same slot in this structure)
107 is turned on in the buffer's local_var_flags slot.
109 If a slot in this structure is 0, then there is a DEFVAR_BUFFER_LOCAL
110 for the slot, but there is no default value for it; the corresponding
111 slot in Vbuffer_defaults is not used except to initialize newly-created
114 If a slot is -1, then there is a DEFVAR_BUFFER_LOCAL for it
115 as well as a default value which is used to initialize newly-created
116 buffers and as a reset-value when local-vars are killed.
118 If a slot is -2, there is no DEFVAR_BUFFER_LOCAL for it.
119 (The slot is always local, but there's no lisp variable for it.)
120 The default value is only used to initialize newly-creation buffers.
122 If a slot is -3, then there is no DEFVAR_BUFFER_LOCAL for it but
123 there is a default which is used to initialize newly-creation
124 buffers and as a reset-value when local-vars are killed. */
125 struct buffer buffer_local_flags;
127 /* This is the initial (startup) directory, as used for the *scratch* buffer.
128 We're making this a global to make others aware of the startup directory.
129 `initial_directory' is stored in external format.
131 char initial_directory[MAXPATHLEN+1];
133 /* This structure holds the names of symbols whose values may be
134 buffer-local. It is indexed and accessed in the same way as the above. */
135 static Lisp_Object Vbuffer_local_symbols;
137 /* Alist of all buffer names vs the buffers. */
138 /* This used to be a variable, but is no longer,
139 to prevent lossage due to user rplac'ing this alist or its elements.
140 Note that there is a per-frame copy of this as well; the frame slot
141 and the global variable contain the same data, but possibly in different
142 orders, so that the buffer ordering can be per-frame.
144 Lisp_Object Vbuffer_alist;
146 /* Functions to call before and after each text change. */
147 Lisp_Object Qbefore_change_functions;
148 Lisp_Object Qafter_change_functions;
149 Lisp_Object Vbefore_change_functions;
150 Lisp_Object Vafter_change_functions;
152 /* #### Obsolete, for compatibility */
153 Lisp_Object Qbefore_change_function;
154 Lisp_Object Qafter_change_function;
155 Lisp_Object Vbefore_change_function;
156 Lisp_Object Vafter_change_function;
159 Lisp_Object Vtransient_mark_mode;
162 /* t means ignore all read-only text properties.
163 A list means ignore such a property if its value is a member of the list.
164 Any non-nil value means ignore buffer-read-only. */
165 Lisp_Object Vinhibit_read_only;
167 /* List of functions to call that can query about killing a buffer.
168 If any of these functions returns nil, we don't kill it. */
169 Lisp_Object Vkill_buffer_query_functions;
171 /* Non-nil means delete a buffer's auto-save file when the buffer is saved. */
172 int delete_auto_save_files;
174 Lisp_Object Qbuffer_live_p;
175 Lisp_Object Qbuffer_or_string_p;
177 /* List of functions to call before changing an unmodified buffer. */
178 Lisp_Object Vfirst_change_hook;
179 Lisp_Object Qfirst_change_hook;
181 Lisp_Object Qfundamental_mode;
182 Lisp_Object Qmode_class;
183 Lisp_Object Qpermanent_local;
185 Lisp_Object Qprotected_field;
187 Lisp_Object QSFundamental; /* A string "Fundamental" */
188 Lisp_Object QSscratch; /* "*scratch*" */
189 Lisp_Object Qdefault_directory;
191 Lisp_Object Qkill_buffer_hook;
192 Lisp_Object Qbuffer_file_name, Qbuffer_undo_list;
194 Lisp_Object Qrename_auto_save_file;
196 Lisp_Object Qget_file_buffer;
197 Lisp_Object Qchange_major_mode_hook, Vchange_major_mode_hook;
199 Lisp_Object Qfind_file_compare_truenames;
201 Lisp_Object Qswitch_to_buffer;
203 /* Two thresholds controlling how much undo information to keep. */
205 int undo_high_threshold;
207 int find_file_compare_truenames;
208 int find_file_use_truenames;
211 static void reset_buffer_local_variables (struct buffer *, int first_time);
212 static void nuke_all_buffer_slots (struct buffer *b, Lisp_Object zap);
215 make_buffer (struct buffer *buf)
218 XSETBUFFER (obj, buf);
223 mark_buffer (Lisp_Object obj, void (*markobj) (Lisp_Object))
225 struct buffer *buf = XBUFFER (obj);
227 /* Truncate undo information. */
228 buf->undo_list = truncate_undo_list (buf->undo_list,
230 undo_high_threshold);
232 #define MARKED_SLOT(x) ((void) (markobj (buf->x)));
233 #include "bufslots.h"
236 markobj (buf->extent_info);
238 markobj (buf->text->line_number_cache);
240 /* Don't mark normally through the children slot.
241 (Actually, in this case, it doesn't matter.) */
242 if (! EQ (buf->indirect_children, Qnull_pointer))
243 mark_conses_in_list (buf->indirect_children);
245 return buf->base_buffer ? make_buffer (buf->base_buffer) : Qnil;
249 print_buffer (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
251 struct buffer *b = XBUFFER (obj);
255 if (!BUFFER_LIVE_P (b))
256 error ("printing unreadable object #<killed buffer>");
258 error ("printing unreadable object #<buffer %s>",
259 XSTRING_DATA (b->name));
261 else if (!BUFFER_LIVE_P (b))
262 write_c_string ("#<killed buffer>", printcharfun);
265 write_c_string ("#<buffer ", printcharfun);
266 print_internal (b->name, printcharfun, 1);
267 write_c_string (">", printcharfun);
271 print_internal (b->name, printcharfun, 0);
275 /* We do not need a finalize method to handle a buffer's children list
276 because all buffers have `kill-buffer' applied to them before
277 they disappear, and the children removal happens then. */
278 DEFINE_LRECORD_IMPLEMENTATION ("buffer", buffer,
279 mark_buffer, print_buffer, 0, 0, 0, 0,
282 DEFUN ("bufferp", Fbufferp, 1, 1, 0, /*
283 Return t if OBJECT is an editor buffer.
287 return BUFFERP (object) ? Qt : Qnil;
290 DEFUN ("buffer-live-p", Fbuffer_live_p, 1, 1, 0, /*
291 Return t if OBJECT is an editor buffer that has not been deleted.
295 return BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)) ? Qt : Qnil;
299 nsberror (Lisp_Object spec)
302 error ("No buffer named %s", XSTRING_DATA (spec));
303 signal_simple_error ("Invalid buffer argument", spec);
306 DEFUN ("buffer-list", Fbuffer_list, 0, 1, 0, /*
307 Return a list of all existing live buffers.
308 The order is specific to the selected frame; if the optional FRAME
309 argument is provided, the ordering for that frame is returned instead.
310 If the FRAME argument is t, then the global (non-frame) ordering is
315 return Fmapcar (Qcdr,
316 EQ (frame, Qt) ? Vbuffer_alist :
317 decode_frame (frame)->buffer_alist);
321 get_buffer (Lisp_Object name, int error_if_deleted_or_does_not_exist)
325 if (!BUFFER_LIVE_P (XBUFFER (name)))
327 if (error_if_deleted_or_does_not_exist)
339 name = LISP_GETTEXT (name); /* I18N3 */
341 buf = Fcdr (Fassoc (name, Vbuffer_alist));
343 if (NILP (buf) && error_if_deleted_or_does_not_exist)
350 decode_buffer (Lisp_Object buffer, int allow_string)
353 return current_buffer;
355 if (allow_string && STRINGP (buffer))
356 return XBUFFER (get_buffer (buffer, 1));
358 CHECK_LIVE_BUFFER (buffer);
359 return XBUFFER (buffer);
362 DEFUN ("decode-buffer", Fdecode_buffer, 1, 1, 0, /*
363 Validate BUFFER or if BUFFER is nil, return the current buffer.
364 If BUFFER is a valid buffer or a string representing a valid buffer,
365 the corresponding buffer object will be returned. Otherwise an error
370 struct buffer *b = decode_buffer (buffer, 1);
371 XSETBUFFER (buffer, b);
377 /* Like Fassoc, but use Fstring_equal to compare
378 (which ignores text properties),
379 and don't ever QUIT. */
382 assoc_ignore_text_properties (REGISTER Lisp_Object key, Lisp_Object list)
384 REGISTER Lisp_Object tail;
385 for (tail = list; !NILP (tail); tail = Fcdr (tail))
387 REGISTER Lisp_Object elt, tem;
389 tem = Fstring_equal (Fcar (elt), key);
398 DEFUN ("get-buffer", Fget_buffer, 1, 1, 0, /*
399 Return the buffer named NAME (a string).
400 If there is no live buffer named NAME, return nil.
401 NAME may also be a buffer; if so, the value is that buffer.
406 /* #### Doc string should indicate that the buffer name will get
410 /* #### This might return a dead buffer. This is gross. This is
411 called FSF compatibility. */
414 return get_buffer (name, 0);
415 /* FSFmacs 19.29 calls assoc_ignore_text_properties() here.
420 DEFUN ("get-file-buffer", Fget_file_buffer, 1, 1, 0, /*
421 Return the buffer visiting file FILENAME (a string).
422 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.
423 If there is no such live buffer, return nil.
425 Normally, the comparison is done by canonicalizing FILENAME (using
426 `expand-file-name') and comparing that to the value of `buffer-file-name'
427 for each existing buffer. However, If `find-file-compare-truenames' is
428 non-nil, FILENAME will be converted to its truename and the search will be
429 done on each buffer's value of `buffer-file-truename' instead of
430 `buffer-file-name'. Otherwise, if `find-file-use-truenames' is non-nil,
431 FILENAME will be converted to its truename and used for searching, but
432 the search will still be done on `buffer-file-name'.
436 /* This function can GC. GC checked 1997.04.06. */
437 REGISTER Lisp_Object buf;
441 /* DO NOT translate the filename. */
444 CHECK_STRING (filename);
445 filename = Fexpand_file_name (filename, Qnil);
447 /* If the file name has special constructs in it,
448 call the corresponding file handler. */
449 Lisp_Object handler = Ffind_file_name_handler (filename, Qget_file_buffer);
453 return call2 (handler, Qget_file_buffer, filename);
458 if (find_file_compare_truenames || find_file_use_truenames)
460 struct gcpro ngcpro1, ngcpro2, ngcpro3;
461 Lisp_Object fn = Qnil;
462 Lisp_Object dn = Qnil;
464 NGCPRO3 (fn, dn, filename);
465 fn = Ffile_truename (filename, Qnil);
468 dn = Ffile_name_directory (filename);
469 fn = Ffile_truename (dn, Qnil);
470 if (! NILP (fn)) dn = fn;
471 fn = Fexpand_file_name (Ffile_name_nondirectory (filename),
480 LIST_LOOP_2 (elt, Vbuffer_alist)
483 if (!BUFFERP (buf)) continue;
484 if (!STRINGP (XBUFFER (buf)->filename)) continue;
485 if (!NILP (Fstring_equal (filename,
486 (find_file_compare_truenames
487 ? XBUFFER (buf)->file_truename
488 : XBUFFER (buf)->filename))))
497 push_buffer_alist (Lisp_Object name, Lisp_Object buf)
499 Lisp_Object cons = Fcons (name, buf);
500 Lisp_Object frmcons, devcons, concons;
502 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (cons, Qnil));
503 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
506 f = XFRAME (XCAR (frmcons));
507 f->buffer_alist = nconc2 (f->buffer_alist, Fcons (cons, Qnil));
512 delete_from_buffer_alist (Lisp_Object buf)
514 Lisp_Object cons = Frassq (buf, Vbuffer_alist);
515 Lisp_Object frmcons, devcons, concons;
517 return; /* abort() ? */
518 Vbuffer_alist = delq_no_quit (cons, Vbuffer_alist);
520 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
523 f = XFRAME (XCAR (frmcons));
524 f->buffer_alist = delq_no_quit (cons, f->buffer_alist);
529 get_truename_buffer (REGISTER Lisp_Object filename)
531 /* FSFmacs has its own code here and doesn't call get-file-buffer.
532 That's because their equivalent of find-file-compare-truenames
533 (find-file-existing-other-name) isn't looked at in get-file-buffer.
534 This way is more correct. */
535 int count = specpdl_depth ();
537 specbind (Qfind_file_compare_truenames, Qt);
538 return unbind_to (count, Fget_file_buffer (filename));
541 static struct buffer *
542 allocate_buffer (void)
544 struct buffer *b = alloc_lcrecord_type (struct buffer, &lrecord_buffer);
546 copy_lcrecord (b, XBUFFER (Vbuffer_defaults));
552 finish_init_buffer (struct buffer *b, Lisp_Object name)
558 name = Fcopy_sequence (name);
559 /* #### This really does not need to be called. We already
560 initialized the buffer-local variables in allocate_buffer().
561 local_var_alist is set to Qnil at the same point, in
562 nuke_all_buffer_slots(). */
563 reset_buffer_local_variables (b, 1);
564 b->directory = ((current_buffer) ? current_buffer->directory : Qnil);
566 b->last_window_start = 1;
569 if (string_byte (XSTRING (name), 0) != ' ')
574 /* initialize the extent list */
575 init_buffer_extents (b);
577 /* Put this in the alist of all live buffers. */
578 push_buffer_alist (name, buf);
580 init_buffer_markers (b);
582 b->generated_modeline_string = Fmake_string (make_int (84), make_int (' '));
583 b->modeline_extent_table = make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK,
589 DEFUN ("get-buffer-create", Fget_buffer_create, 1, 1, 0, /*
590 Return the buffer named NAME, or create such a buffer and return it.
591 A new buffer is created if there is no live buffer named NAME.
592 If NAME starts with a space, the new buffer does not keep undo information.
593 If NAME is a buffer instead of a string, then it is the value returned.
594 The value is never nil.
598 /* This function can GC */
600 REGISTER struct buffer *b;
603 /* #### Doc string should indicate that the buffer name will get
607 name = LISP_GETTEXT (name);
608 buf = Fget_buffer (name);
612 if (XSTRING_LENGTH (name) == 0)
613 error ("Empty string for buffer name is not allowed");
615 b = allocate_buffer ();
617 b->text = &b->own_text;
619 b->indirect_children = Qnil;
620 init_buffer_text (b);
622 return finish_init_buffer (b, name);
625 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, 2, 2,
626 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ", /*
627 Create and return an indirect buffer for buffer BASE, named NAME.
628 BASE should be an existing buffer (or buffer name).
629 NAME should be a string which is not the name of an existing buffer.
630 If BASE is an indirect buffer itself, the base buffer for that buffer
631 is made the base buffer for the newly created buffer. (Thus, there will
632 never be indirect buffers whose base buffers are themselves indirect.)
636 /* This function can GC */
638 /* #### The above interactive specification is totally bogus,
639 because it offers an existing buffer as default answer to the
640 second question. However, the second argument may not BE an
644 base_buffer = get_buffer (base_buffer, 1);
647 /* #### Doc string should indicate that the buffer name will get
651 name = LISP_GETTEXT (name);
652 if (!NILP (Fget_buffer (name)))
653 signal_simple_error ("Buffer name already in use", name);
654 if (XSTRING_LENGTH (name) == 0)
655 error ("Empty string for buffer name is not allowed");
657 b = allocate_buffer ();
659 b->base_buffer = BUFFER_BASE_BUFFER (XBUFFER (base_buffer));
661 /* Use the base buffer's text object. */
662 b->text = b->base_buffer->text;
663 b->indirect_children = Qnil;
664 b->base_buffer->indirect_children =
665 Fcons (make_buffer (b), b->base_buffer->indirect_children);
666 init_buffer_text (b);
668 return finish_init_buffer (b, name);
674 reset_buffer_local_variables (struct buffer *b, int first_time)
676 struct buffer *def = XBUFFER (Vbuffer_defaults);
678 b->local_var_flags = 0;
679 /* For each slot that has a default value,
680 copy that into the slot. */
681 #define MARKED_SLOT(slot) \
682 { int mask = XINT (buffer_local_flags.slot); \
683 if ((mask > 0 || mask == -1 || mask == -3) \
685 || NILP (Fget (XBUFFER (Vbuffer_local_symbols)->slot, \
686 Qpermanent_local, Qnil)))) \
687 b->slot = def->slot; \
689 #include "bufslots.h"
692 #define STRING256_P(obj) \
693 (STRINGP (obj) && XSTRING_CHAR_LENGTH (obj) == 256)
694 /* If the standard case table has been altered and invalidated,
695 fix up its insides first. */
696 if (!(STRING256_P(Vascii_upcase_table) &&
697 STRING256_P(Vascii_canon_table) &&
698 STRING256_P(Vascii_eqv_table)))
700 Fset_standard_case_table (Vascii_downcase_table);
702 b->downcase_table = Vascii_downcase_table;
703 b->upcase_table = Vascii_upcase_table;
704 b->case_canon_table = Vascii_canon_table;
705 b->case_eqv_table = Vascii_eqv_table;
707 b->mirror_downcase_table = Vmirror_ascii_downcase_table;
708 b->mirror_upcase_table = Vmirror_ascii_upcase_table;
709 b->mirror_case_canon_table = Vmirror_ascii_canon_table;
710 b->mirror_case_eqv_table = Vmirror_ascii_eqv_table;
716 /* We split this away from generate-new-buffer, because rename-buffer
717 and set-visited-file-name ought to be able to use this to really
718 rename the buffer properly. */
720 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, 1, 2, 0, /*
721 Return a string that is the name of no existing buffer based on NAME.
722 If there is no live buffer named NAME, then return NAME.
723 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
724 until an unused name is found, and then return that name.
725 Optional second argument IGNORE specifies a name that is okay to use
726 \(if it is in the sequence to be tried)
727 even if a buffer with that name exists.
731 REGISTER Lisp_Object gentemp, tem;
737 name = LISP_GETTEXT (name);
739 /* #### Doc string should indicate that the buffer name will get
743 tem = Fget_buffer (name);
750 sprintf (number, "<%d>", ++count);
751 gentemp = concat2 (name, build_string (number));
754 tem = Fstring_equal (gentemp, ignore);
758 tem = Fget_buffer (gentemp);
765 DEFUN ("buffer-name", Fbuffer_name, 0, 1, 0, /*
766 Return the name of BUFFER, as a string.
767 With no argument or nil as argument, return the name of the current buffer.
771 /* For compatibility, we allow a dead buffer here.
772 Earlier versions of Emacs didn't provide buffer-live-p. */
774 return current_buffer->name;
775 CHECK_BUFFER (buffer);
776 return XBUFFER (buffer)->name;
779 DEFUN ("buffer-file-name", Fbuffer_file_name, 0, 1, 0, /*
780 Return name of file BUFFER is visiting, or nil if none.
781 No argument or nil as argument means use the current buffer.
785 /* For compatibility, we allow a dead buffer here. Yuck! */
787 return current_buffer->filename;
788 CHECK_BUFFER (buffer);
789 return XBUFFER (buffer)->filename;
792 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, 0, 1, 0, /*
793 Return the base buffer of indirect buffer BUFFER.
794 If BUFFER is not indirect, return nil.
798 struct buffer *buf = decode_buffer (buffer, 0);
800 return buf->base_buffer ? make_buffer (buf->base_buffer) : Qnil;
803 DEFUN ("buffer-indirect-children", Fbuffer_indirect_children, 0, 1, 0, /*
804 Return a list of all indirect buffers whose base buffer is BUFFER.
805 If BUFFER is indirect, the return value will always be nil; see
806 `make-indirect-buffer'.
810 struct buffer *buf = decode_buffer (buffer, 0);
812 return Fcopy_sequence (buf->indirect_children);
815 DEFUN ("buffer-local-variables", Fbuffer_local_variables, 0, 1, 0, /*
816 Return an alist of variables that are buffer-local in BUFFER.
817 Most elements look like (SYMBOL . VALUE), describing one variable.
818 For a symbol that is locally unbound, just the symbol appears in the value.
819 Note that storing new VALUEs in these elements doesn't change the variables.
820 No argument or nil as argument means use current buffer as BUFFER.
824 struct buffer *buf = decode_buffer (buffer, 0);
825 Lisp_Object result = Qnil;
829 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
831 Lisp_Object elt = XCAR (tail);
832 /* Reference each variable in the alist in buf.
833 If inquiring about the current buffer, this gets the current values,
834 so store them into the alist so the alist is up to date.
835 If inquiring about some other buffer, this swaps out any values
836 for that buffer, making the alist up to date automatically. */
837 Lisp_Object val = find_symbol_value (XCAR (elt));
838 /* Use the current buffer value only if buf is the current buffer. */
839 if (buf != current_buffer)
842 /* If symbol is unbound, put just the symbol in the list. */
844 result = Fcons (XCAR (elt), result);
845 /* Otherwise, put (symbol . value) in the list. */
847 result = Fcons (Fcons (XCAR (elt), val), result);
851 /* Add on all the variables stored in special slots. */
853 struct buffer *syms = XBUFFER (Vbuffer_local_symbols);
854 #define MARKED_SLOT(slot) \
855 { int mask = XINT (buffer_local_flags.slot); \
856 if (mask == 0 || mask == -1 \
857 || ((mask > 0) && (buf->local_var_flags & mask))) \
858 result = Fcons (Fcons (syms->slot, buf->slot), result); \
860 #include "bufslots.h"
866 DEFUN ("buffer-dedicated-frame", Fbuffer_dedicated_frame, 0, 1, 0, /*
867 Return the frame dedicated to this BUFFER, or nil if there is none.
868 No argument or nil as argument means use current buffer as BUFFER.
872 struct buffer *buf = decode_buffer (buffer, 0);
874 /* XEmacs addition: if the frame is dead, silently make it go away. */
875 if (!NILP (buf->dedicated_frame) &&
876 !FRAME_LIVE_P (XFRAME (buf->dedicated_frame)))
877 buf->dedicated_frame = Qnil;
879 return buf->dedicated_frame;
882 DEFUN ("set-buffer-dedicated-frame", Fset_buffer_dedicated_frame, 2, 2, 0, /*
883 For this BUFFER, set the FRAME dedicated to it.
884 FRAME must be a frame or nil.
888 struct buffer *buf = decode_buffer (buffer, 0);
891 CHECK_LIVE_FRAME (frame); /* XEmacs change */
893 return buf->dedicated_frame = frame;
898 DEFUN ("buffer-modified-p", Fbuffer_modified_p, 0, 1, 0, /*
899 Return t if BUFFER was modified since its file was last read or saved.
900 No argument or nil as argument means use current buffer as BUFFER.
904 struct buffer *buf = decode_buffer (buffer, 0);
906 return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil;
909 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, 1, 2, 0, /*
910 Mark BUFFER as modified or unmodified according to FLAG.
911 A non-nil FLAG means mark the buffer modified. No argument or nil
912 as BUFFER means use current buffer.
916 /* This function can GC */
917 struct buffer *buf = decode_buffer (buffer, 0);
919 #ifdef CLASH_DETECTION
920 /* If buffer becoming modified, lock the file.
921 If buffer becoming unmodified, unlock the file. */
923 Lisp_Object fn = buf->file_truename;
926 int already = BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf);
927 if (already == NILP (flag))
929 int count = specpdl_depth ();
930 /* lock_file() and unlock_file() currently use current_buffer */
931 /* #### - dmoore, what if lock_file or unlock_file kill
932 the current buffer? */
933 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
934 set_buffer_internal (buf);
935 if (!already && !NILP (flag))
937 else if (already && NILP (flag))
939 unbind_to (count, Qnil);
942 #endif /* CLASH_DETECTION */
944 /* This is often called when the buffer contents are altered but we
945 don't want to treat the changes that way (e.g. selective
946 display). We still need to make sure redisplay realizes that the
947 contents have potentially altered and it needs to do some
949 buf = decode_buffer(buffer, 0);
951 BUF_SAVE_MODIFF (buf) = NILP (flag) ? BUF_MODIFF (buf) : 0;
952 MARK_MODELINE_CHANGED;
957 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, 0, 1, 0, /*
958 Return BUFFER's tick counter, incremented for each change in text.
959 Each buffer has a tick counter which is incremented each time the text in
960 that buffer is changed. It wraps around occasionally.
961 No argument or nil as argument means use current buffer as BUFFER.
965 struct buffer *buf = decode_buffer (buffer, 0);
967 return make_int (BUF_MODIFF (buf));
970 DEFUN ("rename-buffer", Frename_buffer, 1, 2,
971 "sRename buffer (to new name): \nP", /*
972 Change current buffer's name to NEWNAME (a string).
973 If second arg UNIQUE is nil or omitted, it is an error if a
974 buffer named NEWNAME already exists.
975 If UNIQUE is non-nil, come up with a new name using
976 `generate-new-buffer-name'.
977 Interactively, one can set UNIQUE with a prefix argument.
978 Returns the name we actually gave the buffer.
979 This does not change the name of the visited file (if any).
983 /* This function can GC */
984 Lisp_Object tem, buf;
987 /* #### Doc string should indicate that the buffer name will get
990 CHECK_STRING (newname);
991 newname = LISP_GETTEXT (newname);
993 if (XSTRING_LENGTH (newname) == 0)
994 error ("Empty string is invalid as a buffer name");
996 tem = Fget_buffer (newname);
997 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
998 the buffer automatically so you can create another with the original name.
999 It makes UNIQUE equivalent to
1000 (rename-buffer (generate-new-buffer-name NEWNAME)). */
1001 /* XEmacs change: added check for nil */
1002 if (NILP (unique) && !NILP (tem) && XBUFFER (tem) == current_buffer)
1003 return current_buffer->name;
1007 newname = Fgenerate_new_buffer_name (newname, current_buffer->name);
1009 error ("Buffer name \"%s\" is in use",
1010 XSTRING_DATA (newname));
1013 current_buffer->name = newname;
1015 /* Catch redisplay's attention. Unless we do this, the modelines for
1016 any windows displaying current_buffer will stay unchanged. */
1017 MARK_MODELINE_CHANGED;
1019 buf = Fcurrent_buffer ();
1021 /* The aconses in the Vbuffer_alist are shared with frame->buffer_alist,
1022 so this will change it in the per-frame ordering as well. */
1023 Fsetcar (Frassq (buf, Vbuffer_alist), newname);
1024 if (NILP (current_buffer->filename)
1025 && !NILP (current_buffer->auto_save_file_name))
1026 call0 (Qrename_auto_save_file);
1027 /* refetch since that last call may have done GC */
1028 /* (hypothetical relocating GC) */
1029 return current_buffer->name;
1032 DEFUN ("other-buffer", Fother_buffer, 0, 3, 0, /*
1033 Return most recently selected buffer other than BUFFER.
1034 Buffers not visible in windows are preferred to visible buffers,
1035 unless optional third argument VISIBLE-OK is non-nil.
1036 If no other buffer exists, the buffer `*scratch*' is returned.
1037 If BUFFER is omitted or nil, some interesting buffer is returned.
1039 The ordering is for this frame; If second optional argument FRAME
1040 is provided, then the ordering is for that frame. If the second arg
1041 is t, then the global ordering is returned.
1043 Note: In FSF Emacs, this function takes two arguments: BUFFER and
1046 (buffer, frame, visible_ok))
1048 /* This function can GC */
1049 Lisp_Object tail, buf, notsogood, tem;
1055 alist = Vbuffer_alist;
1058 struct frame *f = decode_frame (frame);
1060 XSETFRAME (frame, f);
1061 alist = f->buffer_alist;
1064 for (tail = alist; !NILP (tail); tail = Fcdr (tail))
1066 buf = Fcdr (Fcar (tail));
1067 if (EQ (buf, buffer))
1069 if (string_byte (XSTRING (XBUFFER (buf)->name), 0) == ' ')
1071 /* If FRAME has a buffer_predicate,
1072 disregard buffers that don't fit the predicate. */
1075 tem = XFRAME (frame)->buffer_predicate;
1078 tem = call1 (tem, buf);
1084 if (NILP (visible_ok))
1086 /* get-buffer-window will handle nil or t frame */
1087 tem = Fget_buffer_window (buf, frame, Qnil);
1093 if (NILP (notsogood))
1096 if (!NILP (notsogood))
1098 return Fget_buffer_create (QSscratch);
1101 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, 0, 1, "", /*
1102 Make BUFFER stop keeping undo information.
1103 Any undo records it already has are discarded.
1104 No argument or nil as argument means do this for the current buffer.
1108 /* Allowing nil is an RMSism */
1109 struct buffer *real_buf = decode_buffer (buffer, 1);
1110 real_buf->undo_list = Qt;
1114 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, 0, 1, "", /*
1115 Start keeping undo information for buffer BUFFER.
1116 No argument or nil as argument means do this for the current buffer.
1120 /* Allowing nil is an RMSism */
1121 struct buffer *real_buf = decode_buffer (buffer, 1);
1122 if (EQ (real_buf->undo_list, Qt))
1123 real_buf->undo_list = Qnil;
1128 DEFUN ("kill-buffer", Fkill_buffer, 1, 1, "bKill buffer: ", /*
1129 Kill the buffer BUFFER.
1130 The argument may be a buffer or may be the name of a buffer.
1131 An argument of nil means kill the current buffer.
1133 Value is t if the buffer is actually killed, nil if user says no.
1135 The value of `kill-buffer-hook' (which may be local to that buffer),
1136 if not void, is a list of functions to be called, with no arguments,
1137 before the buffer is actually killed. The buffer to be killed is current
1138 when the hook functions are called.
1140 Any processes that have this buffer as the `process-buffer' are killed
1141 with `delete-process'.
1145 /* This function can call lisp */
1147 REGISTER struct buffer *b;
1148 struct gcpro gcpro1, gcpro2;
1151 buf = Fcurrent_buffer ();
1152 else if (BUFFERP (buffer))
1156 b
\rf = get_buffer (buffer, 0);
1157 if (NILP (buf)) nsberror (buf@er);
1162 /* OK to delete an alr%ady-ÿeleted buffer. */
1163 if (!BUFFER_LIVE_P (b))
1166 /* Don't kill the minibuffer now current. */
1167 if (EQ (buf, Vminibuffer_zero))
1170 /* Or the echo area. */
1171 if (EQ (buf, Vecho_area_buffer))
1174 /* Query i¸ the buffer is still modified. */
1175 if (INTERACTIVE && !NILP (~->filename)
1176 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
1182 (emacs_doprnt_string_c
1183 ((CONST Bufbyte *) GETTEXT ("Buffer %s modified; kill anyway? "),
1184 Qnil, -1, XSTRING_DATA (b->name))));
1186 if (NILP (killp))Ü return Qnil;
1187 b = XBUFFER (buf); /* Hypothetical râlocating GC. */
1190 /* Run hooks with the buffer to be killed temporarily selected,
1191 unless the buffer is already dead (could have been deleted
1192 in the question above).
1194 i
\r (BUFFER_LIVE_P (b))
1196 int speccount = specpdl_depth Á){
1197 Lisp_Object tail = Qnil;
1199 GCPRO2 (buf, tail);
\ e q record_unwind_protect (save_excursion_restore, save_excursioz_save ());
1202 /* First run the query functions; if any query is answered no,
1203 don't kill the buffer. */
1204 EXTERNAL_LIST_LOOP (tail, Vkill_buffer_querú_functions)
1206 if (NILP (call0 (Fcar (tail))))
1209 return unbind_to (speccount, Qnil);
1213 /* Then run the hooks. */
1214 run_hook (Qkill_buffer_hook);
1215 #ifdef HAVE_X_WINDOWS
1216 /* If an X selection was in this buffer, disown it.
1217 We could have done this by simply adding this function to the
1218 kill-buffer-hook, but the user might messàthat up.
1220 if (EQ (Vwindow_system, Qx))
1221 call0 (internX("xselect-kill-buffer-hook"));
1222 /* #### generalize me! */
1223 #endif /* HAVE_X_WINDOWS */
1224 unbind_to (speccount, Qnil);
1226 b = XBUFFER (buf); /* Hypothetical re
\14ocating GC. */
1229 /* We have no more questions to ask. Verefy that it is valid
1230 to kill the buffer. This must be dgneáafter the questions
1231 since anything can happen within yew-o[-no-p. */
1233 /* Might have been deleted during the last question above */
1234 if (!BUFFER_LIVE_P (b))
1237 /* Don't kill the minibuffer now current. */
1238 if (EQ (buf, XWINDOW 8jinibuf_window)->buffer))
1241 /* When we kill a
\1fase buffer, kill all its indirect buffers.
1242 We do it at this stage so nothing terrible happens if they
1243 ask questions or their hooks get errors. */
1244 if (! b->base_buffer)
1250 LIST_LOOP (rest, b->indirect_children)
1252 Fkill_buffer (XCAR (rest));
1253 /* Keep indirect_children updated in case a
1254 query-funct
\9fon/hook throws. */
1255 b->indirect_children = XCDR (rest);
1261 /* Make this buffer not be current.
1262 In the process, notice if this is the sole visible buffer
1263 End give up if so. */
1264 if (b == current_buffer)
1266 Fs
\9ct_buffer (Fother_buffer (buf, Qnil, Qnil));
1267 if (b == currsnt_buffer)
1271 /* Now there is no question: ¤e can kill the buffer. */
1273 #ifdef CLASH_DETECTION
1274 /* Unlock this buffer's file, if it is locked. unlock_buffer
1275 can both GC and kill the current buffer, and wreak general
1276 havok by running lisp code. */
1282 if (!BUFFER_LIVE_P (b))
1285 if (b == current_buffer)
1287 Fset_buffer (Fother_buffer (buf, Qnil, Qnil));
1288 if (b == current_buffer)
1291 #endif /* CLASH_DETECTION */
1294 int speccount = specpdl_depth ();
1295 specbind (Qinhibit_quit, Qt);
1297 à kill_buffer_processes (buf);
1299 /* #### This is a problem if
\15this buffer is in a dedicated window.
1300 Need to undedicate any windows of this buffer first (and delete them?)
1302 Freplace_buffer_in_windows (buf);
1304 delete_from_buffer_alist (buf);
1306 font_lock_buffer_was_killed (b);
1308 /* Delete any auto-save file, if we saved it in this session. */
1309 if (STRINGP (b->auto_save_file_name)
1310 && b->auto_save_modified != 0
1311 && BUF_SAVE_MODIFF (b) < b->auto_save_modified)
1313 if (delete_auto_save_files != 0)
1315 /* deleting the auto save file might kill b! */
1316 /* #### dmoore - fix this crap, we do this same gcpro and
1317 buffer liveness check multiple times. Let's get a
1318 macro or something for it. */
1320 internal_delete_file (b->auto_save_file_name);
1324 if (!BUFFER_LIVE_P (b))
1327 if (b == current_buffer)
1329 Fset_buffer (Fother_buffer (buf, Qnil, Qnil));
1330 if (b == current_buffer)
1336 uninit_buffer_markers (b);
1338 kill_buffer_local_variables (b);
1341 uninit_buffer_text (b);
1342 b->undo_list = Qnil;
1343 uninit_buffer_extents (b);
1346 #ifdef ERROR_CHECK_BUFPOS
1347 assert (!NILP (memq_no_quit (buf, b->base_buffer->indirect_children)));
1349 b->base_buffer->indirect_children =
1350 delq_no_quit (buf, b->base_buffer->indirect_children);
1353 /* Clear away all Lisp objects, so that they
1354 won't be protected from GC. */
1355 nuke_all_buffer_slots (b, Qnil);
1357 unbind_to (speccount, Qnil);
1362 DEFUN ("record-buffer", Frecord_buffer, 1, 1, 0, /*
1363 Place buffer BUFFER first in the buffer order.
1364 Call this function when a buffer is selected "visibly".
1366 This function changes the global buffer order and the per-frame buffer
1367 order for the selected frame. The buffer order keeps track of recency
1368 of selection so that `other-buffer' will return a recently selected
1369 buffer. See `other-buffer' for more information.
1373 REGISTER Lisp_Object lynk, prev;
1374 struct frame *f = selected_frame ();
1377 for (lynk = Vbuffer_alist; CONSP (lynk); lynk = XCDR (lynk))
1379 if (EQ (XCDR (XCAR (lynk)), buffer))
1383 /* Effectively do Vbuffer_alist = delq_no_quit (lynk, Vbuffer_alist) */
1385 Vbuffer_alist = XCDR (Vbuffer_alist);
1387 XCDR (prev) = XCDR (XCDR (prev));
1388 XCDR (lynk) = Vbuffer_alist;
1389 Vbuffer_alist = lynk;
1391 /* That was the global one. Now do the same thing for the
1392 per-frame buffer-alist. */
1394 for (lynk = f->buffer_alist; CONSP (lynk); lynk = XCDR (lynk))
1396 if (EQ (XCDR (XCAR (lynk)), buffer))
1400 /* Effectively do f->buffer_alist = delq_no_quit (lynk, f->buffer_alist) */
1402 f->buffer_alist = XCDR (f->buffer_alist);
1404 XCDR (prev) = XCDR (XCDR (prev));
1405 XCDR (lynk) = f->buffer_alist;
1406 f->buffer_alist = lynk;
1410 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, 1, 1, 0, /*
1411 Set an appropriate major mode for BUFFER, according to `default-major-mode'.
1412 Use this function before selecting the buffer, since it may need to inspect
1413 the current buffer's major mode.
1417 int speccount = specpdl_depth ();
1418 Lisp_Object function = XBUFFER (Vbuffer_defaults)->major_mode;
1420 if (NILP (function))
1422 Lisp_Object tem = Fget (current_buffer->major_mode, Qmode_class, Qnil);
1424 function = current_buffer->major_mode;
1427 if (NILP (function) || EQ (function, Qfundamental_mode))
1430 /* To select a nonfundamental mode,
1431 select the buffer temporarily and then call the mode function. */
1433 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
1435 Fset_buffer (buffer);
1438 return unbind_to (speccount, Qnil);
1442 switch_to_buffer (Lisp_Object bufname, Lisp_Object norecord)
1444 call2 (Qswitch_to_buffer, bufname, norecord);
1448 DEFUN ("current-buffer", Fcurrent_buffer, 0, 0, 0, /*
1449 Return the current buffer as a Lisp object.
1454 XSETBUFFER (buffer, current_buffer);
1458 /* Set the current buffer to B. */
1461 set_buffer_internal (struct buffer *b)
1463 REGISTER struct buffer *old_buf;
1464 REGISTER Lisp_Object tail;
1466 if (current_buffer == b)
1469 INVALIDATE_PIXEL_TO_GLYPH_CACHE;
1471 old_buf = current_buffer;
1473 invalidate_current_column (); /* invalidate indentation cache */
1476 if (!noninteractive && initialized)
1478 extern Lisp_Object Ffep_force_on (), Ffep_force_off (), Ffep_get_mode ();
1480 old_buf->fep_mode = Ffep_get_mode ();
1482 if (!NILP (current_buffer->fep_mode))
1487 #endif /* HAVE_FEP */
1491 /* Put the undo list back in the base buffer, so that it appears
1492 that an indirect buffer shares the undo list of its base. */
1493 if (old_buf->base_buffer)
1494 old_buf->base_buffer->undo_list = old_buf->undo_list;
1497 /* Get the undo list from the base buffer, so that it appears
1498 that an indirect buffer shares the undo list of its base. */
1500 b->undo_list = b->base_buffer->undo_list;
1502 /* Look down buffer's list of local Lisp variables
1503 to find and update any that forward into C variables. */
1505 LIST_LOOP (tail, b->local_var_alist)
1507 Lisp_Object sym = XCAR (XCAR (tail));
1508 Lisp_Object valcontents = XSYMBOL (sym)->value;
1509 if (SYMBOL_VALUE_MAGIC_P (valcontents))
1511 /* Just reference the variable
1512 to cause it to become set for this buffer. */
1513 /* Use find_symbol_value_quickly to avoid an unnecessary O(n)
1515 (void) find_symbol_value_quickly (XCAR (tail), 1);
1519 /* Do the same with any others that were local to the previous buffer */
1523 LIST_LOOP (tail, old_buf->local_var_alist)
1525 Lisp_Object sym = XCAR (XCAR (tail));
1526 Lisp_Object valcontents = XSYMBOL (sym)->value;
1528 if (SYMBOL_VALUE_MAGIC_P (valcontents))
1530 /* Just reference the variable
1531 to cause it to become set for this buffer. */
1532 /* Use find_symbol_value_quickly with find_it_p as 0 to avoid an
1533 unnecessary O(n) lookup which is guaranteed to be worst case.
1534 Any symbols which are local are guaranteed to have been
1535 handled in the previous loop, above. */
1536 (void) find_symbol_value_quickly (sym, 0);
1542 DEFUN ("set-buffer", Fset_buffer, 1, 1, 0, /*
1543 Make the buffer BUFFER current for editing operations.
1544 BUFFER may be a buffer or the name of an existing buffer.
1545 See also `save-excursion' when you want to make a buffer current temporarily.
1546 This function does not display the buffer, so its effect ends
1547 when the current command terminates.
1548 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.
1552 buffer = get_buffer (buffer, 0);
1554 error ("Selecting deleted or non-existent buffer");
1555 set_buffer_internal (XBUFFER (buffer));
1560 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, 0, 3, 0, /*
1561 Signal a `buffer-read-only' error if the buffer is read-only.
1562 Optional argument BUFFER defaults to the current buffer.
1564 If optional argument START is non-nil, all extents in the buffer
1565 which overlap that part of the buffer are checked to ensure none has a
1566 `read-only' property. (Extents that lie completely within the range,
1567 however, are not checked.) END defaults to the value of START.
1569 If START and END are equal, the range checked is [START, END] (i.e.
1570 closed on both ends); otherwise, the range checked is (START, END)
1571 \(open on both ends), except that extents that lie completely within
1572 [START, END] are not checked. See `extent-in-region-p' for a fuller
1575 (buffer, start, end))
1577 struct buffer *b = decode_buffer (buffer, 0);
1586 get_buffer_range_char (b, start, end, &s, &e, 0);
1588 barf_if_buffer_read_only (b, s, e);
1594 bury_buffer_1 (Lisp_Object buffer, Lisp_Object before,
1595 Lisp_Object *buffer_alist)
1597 Lisp_Object aelt = rassq_no_quit (buffer, *buffer_alist);
1598 Lisp_Object lynk = memq_no_quit (aelt, *buffer_alist);
1599 Lisp_Object iter, before_before;
1601 *buffer_alist = delq_no_quit (aelt, *buffer_alist);
1602 for (before_before = Qnil, iter = *buffer_alist;
1603 !NILP (iter) && !EQ (XCDR (XCAR (iter)), before);
1604 before_before = iter, iter = XCDR (iter))
1607 if (!NILP (before_before))
1608 XCDR (before_before) = lynk;
1610 *buffer_alist = lynk;
1613 DEFUN ("bury-buffer", Fbury_buffer, 0, 2, "", /*
1614 Put BUFFER at the end of the list of all buffers.
1615 There it is the least likely candidate for `other-buffer' to return;
1616 thus, the least likely buffer for \\[switch-to-buffer] to select by default.
1617 If BUFFER is nil or omitted, bury the current buffer.
1618 Also, if BUFFER is nil or omitted, remove the current buffer from the
1619 selected window if it is displayed there.
1620 If BEFORE is non-nil, it specifies a buffer before which BUFFER
1621 will be placed, instead of being placed at the end.
1625 /* This function can GC */
1626 struct buffer *buf = decode_buffer (buffer, 1);
1627 /* If we're burying the current buffer, unshow it. */
1628 /* Note that the behavior of (bury-buffer nil) and
1629 (bury-buffer (current-buffer)) is not the same.
1630 This is illogical but is historical. Changing it
1631 breaks mh-e and TeX and such packages. */
1633 switch_to_buffer (Fother_buffer (Fcurrent_buffer (), Qnil, Qnil), Qnil);
1634 XSETBUFFER (buffer, buf);
1637 before = get_buffer (before, 1);
1639 if (EQ (before, buffer))
1640 error ("Cannot place a buffer before itself");
1642 bury_buffer_1 (buffer, before, &Vbuffer_alist);
1643 bury_buffer_1 (buffer, before, &selected_frame ()->buffer_alist);
1649 DEFUN ("erase-buffer", Ferase_buffer, 0, 1, "*", /*
1650 Delete the entire contents of the BUFFER.
1651 Any clipping restriction in effect (see `narrow-to-region') is removed,
1652 so the buffer is truly empty after this.
1653 BUFFER defaults to the current buffer if omitted.
1657 /* This function can GC */
1658 struct buffer *b = decode_buffer (buffer, 1);
1659 /* #### yuck yuck yuck. This is gross. The old echo-area code,
1660 however, was the only place that called erase_buffer() with a
1661 non-zero NO_CLIP argument.
1663 Someone needs to fix up the redisplay code so it is smarter
1664 about this, so that the NO_CLIP junk isn't necessary. */
1665 int no_clip = (b == XBUFFER (Vecho_area_buffer));
1667 INVALIDATE_PIXEL_TO_GLYPH_CACHE;
1669 widen_buffer (b, no_clip);
1670 buffer_delete_range (b, BUF_BEG (b), BUF_Z (b), 0);
1671 b->last_window_start = 1;
1673 /* Prevent warnings, or suspension of auto saving, that would happen
1674 if future size is less than past size. Use of erase-buffer
1675 implies that the future text is not really related to the past text. */
1676 b->saved_size = Qzero;
1678 zmacs_region_stays = 0;
1684 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, 0, 0, 0, /*
1685 Switch to Fundamental mode by killing current buffer's local variables.
1686 Most local variable bindings are eliminated so that the default values
1687 become effective once more. Also, the syntax table is set from
1688 `standard-syntax-table', the category table is set from
1689 `standard-category-table' (if support for Mule exists), local keymap is set
1690 to nil, the abbrev table is set from `fundamental-mode-abbrev-table',
1691 and all specifier specifications whose locale is the current buffer
1692 are removed. This function also forces redisplay of the modeline.
1694 Every function to select a new major mode starts by
1695 calling this function.
1697 As a special exception, local variables whose names have
1698 a non-nil `permanent-local' property are not eliminated by this function.
1700 The first thing this function does is run
1701 the normal hook `change-major-mode-hook'.
1705 /* This function can GC */
1706 run_hook (Qchange_major_mode_hook);
1708 reset_buffer_local_variables (current_buffer, 0);
1710 kill_buffer_local_variables (current_buffer);
1712 kill_specifier_buffer_locals (Fcurrent_buffer ());
1714 /* Force modeline redisplay. Useful here because all major mode
1715 commands call this function. */
1716 MARK_MODELINE_CHANGED;
1721 #ifdef MEMORY_USAGE_STATS
1732 compute_buffer_text_usage (struct buffer *b, struct overhead_stats *ovstats)
1734 int was_requested = b->text->z - 1;
1735 size_t gap = b->text->gap_size + b->text->end_gap_size;
1736 size_t malloc_use = malloced_storage_size (b->text->beg, was_requested + gap, 0);
1738 ovstats->gap_overhead += gap;
1739 ovstats->was_requested += was_requested;
1740 ovstats->malloc_overhead += malloc_use - (was_requested + gap);
1745 compute_buffer_usage (struct buffer *b, struct buffer_stats *stats,
1746 struct overhead_stats *ovstats)
1749 stats->other += malloced_storage_size (b, sizeof (*b), ovstats);
1750 stats->text += compute_buffer_text_usage (b, ovstats);
1751 stats->markers += compute_buffer_marker_usage (b, ovstats);
1752 stats->extents += compute_buffer_extent_usage (b, ovstats);
1755 DEFUN ("buffer-memory-usage", Fbuffer_memory_usage, 1, 1, 0, /*
1756 Return stats about the memory usage of buffer BUFFER.
1757 The values returned are in the form of an alist of usage types and byte
1758 counts. The byte counts attempt to encompass all the memory used
1759 by the buffer (separate from the memory logically associated with a
1760 buffer or frame), including internal structures and any malloc()
1761 overhead associated with them. In practice, the byte counts are
1762 underestimated because certain memory usage is very hard to determine
1763 \(e.g. the amount of memory used inside the Xt library or inside the
1764 X server) and because there is other stuff that might logically
1765 be associated with a window, buffer, or frame (e.g. window configurations,
1766 glyphs) but should not obviously be included in the usage counts.
1768 Multiple slices of the total memory usage may be returned, separated
1769 by a nil. Each slice represents a particular view of the memory, a
1770 particular way of partitioning it into groups. Within a slice, there
1771 is no overlap between the groups of memory, and each slice collectively
1772 represents all the memory concerned.
1776 struct buffer_stats stats;
1777 struct overhead_stats ovstats;
1778 Lisp_Object val = Qnil;
1780 CHECK_BUFFER (buffer); /* dead buffers should be allowed, no? */
1782 compute_buffer_usage (XBUFFER (buffer), &stats, &ovstats);
1784 val = acons (Qtext, make_int (stats.text), val);
1785 val = acons (Qmarkers, make_int (stats.markers), val);
1786 val = acons (Qextents, make_int (stats.extents), val);
1787 val = acons (Qother, make_int (stats.other), val);
1788 val = Fcons (Qnil, val);
1789 val = acons (Qactually_requested, make_int (ovstats.was_requested), val);
1790 val = acons (Qmalloc_overhead, make_int (ovstats.malloc_overhead), val);
1791 val = acons (Qgap_overhead, make_int (ovstats.gap_overhead), val);
1792 val = acons (Qdynarr_overhead, make_int (ovstats.dynarr_overhead), val);
1794 return Fnreverse (val);
1797 #endif /* MEMORY_USAGE_STATS */
1800 syms_of_buffer (void)
1802 defsymbol (&Qbuffer_live_p, "buffer-live-p");
1803 defsymbol (&Qbuffer_or_string_p, "buffer-or-string-p");
1804 defsymbol (&Qmode_class, "mode-class");
1805 defsymbol (&Qrename_auto_save_file, "rename-auto-save-file");
1806 defsymbol (&Qkill_buffer_hook, "kill-buffer-hook");
1807 defsymbol (&Qpermanent_local, "permanent-local");
1809 defsymbol (&Qfirst_change_hook, "first-change-hook");
1810 defsymbol (&Qbefore_change_functions, "before-change-functions");
1811 defsymbol (&Qafter_change_functions, "after-change-functions");
1813 /* #### Obsolete, for compatibility */
1814 defsymbol (&Qbefore_change_function, "before-change-function");
1815 defsymbol (&Qafter_change_function, "after-change-function");
1817 defsymbol (&Qbuffer_file_name, "buffer-file-name");
1818 defsymbol (&Qbuffer_undo_list, "buffer-undo-list");
1819 defsymbol (&Qdefault_directory, "default-directory");
1821 defsymbol (&Qget_file_buffer, "get-file-buffer");
1822 defsymbol (&Qchange_major_mode_hook, "change-major-mode-hook");
1824 defsymbol (&Qfundamental_mode, "fundamental-mode");
1826 defsymbol (&Qfind_file_compare_truenames, "find-file-compare-truenames");
1828 defsymbol (&Qswitch_to_buffer, "switch-to-buffer");
1831 DEFSUBR (Fbuffer_live_p);
1832 DEFSUBR (Fbuffer_list);
1833 DEFSUBR (Fdecode_buffer);
1834 DEFSUBR (Fget_buffer);
1835 DEFSUBR (Fget_file_buffer);
1836 DEFSUBR (Fget_buffer_create);
1837 DEFSUBR (Fmake_indirect_buffer);
1839 DEFSUBR (Fgenerate_new_buffer_name);
1840 DEFSUBR (Fbuffer_name);
1841 DEFSUBR (Fbuffer_file_name);
1842 DEFSUBR (Fbuffer_base_buffer);
1843 DEFSUBR (Fbuffer_indirect_children);
1844 DEFSUBR (Fbuffer_local_variables);
1845 DEFSUBR (Fbuffer_dedicated_frame);
1846 DEFSUBR (Fset_buffer_dedicated_frame);
1847 DEFSUBR (Fbuffer_modified_p);
1848 DEFSUBR (Fset_buffer_modified_p);
1849 DEFSUBR (Fbuffer_modified_tick);
1850 DEFSUBR (Frename_buffer);
1851 DEFSUBR (Fother_buffer);
1852 DEFSUBR (Fbuffer_disable_undo);
1853 DEFSUBR (Fbuffer_enable_undo);
1854 DEFSUBR (Fkill_buffer);
1855 DEFSUBR (Ferase_buffer);
1856 DEFSUBR (Frecord_buffer);
1857 DEFSUBR (Fset_buffer_major_mode);
1858 DEFSUBR (Fcurrent_buffer);
1859 DEFSUBR (Fset_buffer);
1860 DEFSUBR (Fbarf_if_buffer_read_only);
1861 DEFSUBR (Fbury_buffer);
1862 DEFSUBR (Fkill_all_local_variables);
1863 #ifdef MEMORY_USAGE_STATS
1864 DEFSUBR (Fbuffer_memory_usage);
1867 deferror (&Qprotected_field, "protected-field",
1868 "Attempt to modify a protected field", Qerror);
1871 /* initialize the buffer routines */
1873 vars_of_buffer (void)
1875 /* This function can GC */
1876 staticpro (&QSFundamental);
1877 staticpro (&QSscratch);
1878 staticpro (&Vbuffer_alist);
1880 QSFundamental = Fpurecopy (build_string ("Fundamental"));
1881 QSscratch = Fpurecopy (build_string (DEFER_GETTEXT ("*scratch*")));
1883 Vbuffer_alist = Qnil;
1886 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook /*
1887 List of hooks to be run before killing local variables in a buffer.
1888 This should be used by any mode that temporarily alters the contents or
1889 the read-only state of the buffer. See also `kill-all-local-variables'.
1891 Vchange_major_mode_hook = Qnil;
1893 DEFVAR_BOOL ("find-file-compare-truenames", &find_file_compare_truenames /*
1894 If this is true, then the find-file command will check the truenames
1895 of all visited files when deciding whether a given file is already in
1896 a buffer, instead of just the buffer-file-name. This means that if you
1897 attempt to visit another file which is a symbolic-link to a file which is
1898 already in a buffer, the existing buffer will be found instead of a newly-
1899 created one. This works if any component of the pathname (including a non-
1900 terminal component) is a symbolic link as well, but doesn't work with hard
1901 links (nothing does).
1903 See also the variable find-file-use-truenames.
1905 find_file_compare_truenames = 0;
1907 DEFVAR_BOOL ("find-file-use-truenames", &find_file_use_truenames /*
1908 If this is true, then a buffer's visited file-name will always be
1909 chased back to the real file; it will never be a symbolic link, and there
1910 will never be a symbolic link anywhere in its directory path.
1911 That is, the buffer-file-name and buffer-file-truename will be equal.
1912 This doesn't work with hard links.
1914 See also the variable find-file-compare-truenames.
1916 find_file_use_truenames = 0;
1918 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions /*
1919 List of functions to call before each text change.
1920 Two arguments are passed to each function: the positions of
1921 the beginning and end of the range of old text to be changed.
1922 \(For an insertion, the beginning and end are at the same place.)
1923 No information is given about the length of the text after the change.
1925 Buffer changes made while executing the `before-change-functions'
1926 don't call any before-change or after-change functions.
1928 Vbefore_change_functions = Qnil;
1930 /* FSF Emacs has the following additional doc at the end of
1931 before-change-functions and after-change-functions:
1933 That's because these variables are temporarily set to nil.
1934 As a result, a hook function cannot straightforwardly alter the value of
1935 these variables. See the Emacs Lisp manual for a way of
1936 accomplishing an equivalent result by using other variables.
1938 But this doesn't apply under XEmacs because things are
1941 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions /*
1942 List of functions to call after each text change.
1943 Three arguments are passed to each function: the positions of
1944 the beginning and end of the range of changed text,
1945 and the length of the pre-change text replaced by that range.
1946 \(For an insertion, the pre-change length is zero;
1947 for a deletion, that length is the number of characters deleted,
1948 and the post-change beginning and end are at the same place.)
1950 Buffer changes made while executing `after-change-functions'
1951 don't call any before-change or after-change functions.
1953 Vafter_change_functions = Qnil;
1955 DEFVAR_LISP ("before-change-function", &Vbefore_change_function /*
1957 */ ); /* obsoleteness will be documented */
1958 Vbefore_change_function = Qnil;
1960 DEFVAR_LISP ("after-change-function", &Vafter_change_function /*
1962 */ ); /* obsoleteness will be documented */
1963 Vafter_change_function = Qnil;
1965 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook /*
1966 A list of functions to call before changing a buffer which is unmodified.
1967 The functions are run using the `run-hooks' function.
1969 Vfirst_change_hook = Qnil;
1972 xxDEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode /*
1973 *Non-nil means deactivate the mark when the buffer contents change.
1975 Vtransient_mark_mode = Qnil;
1976 #endif /* FSFmacs */
1978 DEFVAR_INT ("undo-threshold", &undo_threshold /*
1979 Keep no more undo information once it exceeds this size.
1980 This threshold is applied when garbage collection happens.
1981 The size is counted as the number of bytes occupied,
1982 which includes both saved text and other data.
1984 undo_threshold = 20000;
1986 DEFVAR_INT ("undo-high-threshold", &undo_high_threshold /*
1987 Don't keep more than this much size of undo information.
1988 A command which pushes past this size is itself forgotten.
1989 This threshold is applied when garbage collection happens.
1990 The size is counted as the number of bytes occupied,
1991 which includes both saved text and other data.
1993 undo_high_threshold = 30000;
1995 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only /*
1996 *Non-nil means disregard read-only status of buffers or characters.
1997 If the value is t, disregard `buffer-read-only' and all `read-only'
1998 text properties. If the value is a list, disregard `buffer-read-only'
1999 and disregard a `read-only' extent property or text property if the
2000 property value is a member of the list.
2002 Vinhibit_read_only = Qnil;
2004 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions /*
2005 List of functions called with no args to query before killing a buffer.
2007 Vkill_buffer_query_functions = Qnil;
2009 DEFVAR_BOOL ("delete-auto-save-files", &delete_auto_save_files /*
2010 *Non-nil means delete auto-save file when a buffer is saved or killed.
2012 delete_auto_save_files = 1;
2015 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */
2017 /* Renamed from DEFVAR_PER_BUFFER because FSFmacs D_P_B takes
2018 a bogus extra arg, which confuses an otherwise identical make-docfile.c */
2020 /* Declaring this stuff as const produces 'Cannot reinitialize' messages
2021 from SunPro C's fix-and-continue feature (a way neato feature that
2022 makes debugging unbelievably more bearable) */
2023 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magicfun) do { \
2024 static CONST_IF_NOT_DEBUG struct symbol_value_forward I_hate_C \
2025 = { { { symbol_value_forward_lheader_initializer, \
2026 (struct lcrecord_header *) &(buffer_local_flags.field_name), 69 }, \
2027 forward_type }, magicfun }; \
2029 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) - \
2030 (char *)&buffer_local_flags); \
2031 defvar_magic (lname, &I_hate_C); \
2033 *((Lisp_Object *)(offset + (char *)XBUFFER (Vbuffer_local_symbols))) \
2038 #define DEFVAR_BUFFER_LOCAL_MAGIC(lname, field_name, magicfun) \
2039 DEFVAR_BUFFER_LOCAL_1 (lname, field_name, \
2040 SYMVAL_CURRENT_BUFFER_FORWARD, magicfun)
2041 #define DEFVAR_BUFFER_LOCAL(lname, field_name) \
2042 DEFVAR_BUFFER_LOCAL_MAGIC (lname, field_name, 0)
2043 #define DEFVAR_CONST_BUFFER_LOCAL_MAGIC(lname, field_name, magicfun) \
2044 DEFVAR_BUFFER_LOCAL_1 (lname, field_name, \
2045 SYMVAL_CONST_CURRENT_BUFFER_FORWARD, magicfun)
2046 #define DEFVAR_CONST_BUFFER_LOCAL(lname, field_name) \
2047 DEFVAR_CONST_BUFFER_LOCAL_MAGIC (lname, field_name, 0)
2049 #define DEFVAR_BUFFER_DEFAULTS_MAGIC(lname, field_name, magicfun) \
2050 DEFVAR_SYMVAL_FWD (lname, &(buffer_local_flags.field_name), \
2051 SYMVAL_DEFAULT_BUFFER_FORWARD, magicfun)
2052 #define DEFVAR_BUFFER_DEFAULTS(lname, field_name) \
2053 DEFVAR_BUFFER_DEFAULTS_MAGIC (lname, field_name, 0)
2056 nuke_all_buffer_slots (struct buffer *b, Lisp_Object zap)
2060 b->extent_info = Qnil;
2061 b->indirect_children = Qnil;
2062 b->own_text.line_number_cache = Qnil;
2064 #define MARKED_SLOT(x) b->x = (zap);
2065 #include "bufslots.h"
2070 complex_vars_of_buffer (void)
2072 /* Make sure all markable slots in buffer_defaults
2073 are initialized reasonably, so mark_buffer won't choke. */
2074 struct buffer *defs = alloc_lcrecord_type (struct buffer, &lrecord_buffer);
2075 struct buffer *syms = alloc_lcrecord_type (struct buffer, &lrecord_buffer);
2077 staticpro (&Vbuffer_defaults);
2078 staticpro (&Vbuffer_local_symbols);
2079 XSETBUFFER (Vbuffer_defaults, defs);
2080 XSETBUFFER (Vbuffer_local_symbols, syms);
2082 nuke_all_buffer_slots (syms, Qnil);
2083 nuke_all_buffer_slots (defs, Qnil);
2084 defs->text = &defs->own_text;
2085 syms->text = &syms->own_text;
2087 /* Set up the non-nil default values of various buffer slots.
2088 Must do these before making the first buffer. */
2089 defs->major_mode = Qfundamental_mode;
2090 defs->mode_name = QSFundamental;
2091 defs->abbrev_table = Qnil; /* real default setup by Lisp code */
2093 defs->downcase_table = Vascii_downcase_table;
2094 defs->upcase_table = Vascii_upcase_table;
2095 defs->case_canon_table = Vascii_canon_table;
2096 defs->case_eqv_table = Vascii_eqv_table;
2098 defs->mirror_downcase_table = Vmirror_ascii_downcase_table;
2099 defs->mirror_upcase_table = Vmirror_ascii_upcase_table;
2100 defs->mirror_case_canon_table = Vmirror_ascii_canon_table;
2101 defs->mirror_case_eqv_table = Vmirror_ascii_eqv_table;
2103 defs->category_table = Vstandard_category_table;
2105 defs->syntax_table = Vstandard_syntax_table;
2106 defs->mirror_syntax_table =
2107 XCHAR_TABLE (Vstandard_syntax_table)->mirror_table;
2108 defs->modeline_format = build_string ("%-"); /* reset in loaddefs.el */
2109 defs->case_fold_search = Qt;
2110 defs->selective_display_ellipses = Qt;
2111 defs->tab_width = make_int (8);
2112 defs->ctl_arrow = Qt;
2113 defs->fill_column = make_int (70);
2114 defs->left_margin = Qzero;
2115 defs->saved_size = Qzero; /* lisp code wants int-or-nil */
2117 defs->auto_save_modified = 0;
2118 defs->auto_save_failure_time = -1;
2119 defs->invisibility_spec = Qt;
2121 defs->indirect_children = Qnil;
2122 syms->indirect_children = Qnil;
2125 /* 0 means var is always local. Default used only at creation.
2126 * -1 means var is always local. Default used only at reset and
2128 * -2 means there's no lisp variable corresponding to this slot
2129 * and the default is only used at creation.
2130 * -3 means no Lisp variable. Default used only at reset and creation.
2131 * >0 is mask. Var is local if ((buffer->local_var_flags & mask) != 0)
2132 * Otherwise default is used.
2134 Lisp_Object always_local_no_default = make_int (0);
2135 Lisp_Object always_local_resettable = make_int (-1);
2136 Lisp_Object resettable = make_int (-3);
2138 /* Assign the local-flags to the slots that have default values.
2139 The local flag is a bit that is used in the buffer
2140 to say that it has its own local value for the slot.
2141 The local flag bits are in the local_var_flags slot of the
2144 nuke_all_buffer_slots (&buffer_local_flags, make_int (-2));
2145 buffer_local_flags.filename = always_local_no_default;
2146 buffer_local_flags.directory = always_local_no_default;
2147 buffer_local_flags.backed_up = always_local_no_default;
2148 buffer_local_flags.saved_size = always_local_no_default;
2149 buffer_local_flags.auto_save_file_name = always_local_no_default;
2150 buffer_local_flags.read_only = always_local_no_default;
2152 buffer_local_flags.major_mode = always_local_resettable;
2153 buffer_local_flags.mode_name = always_local_resettable;
2154 buffer_local_flags.undo_list = always_local_no_default;
2156 buffer_local_flags.mark_active = always_local_resettable;
2158 buffer_local_flags.point_before_scroll = always_local_resettable;
2159 buffer_local_flags.file_truename = always_local_no_default;
2160 buffer_local_flags.invisibility_spec = always_local_resettable;
2161 buffer_local_flags.file_format = always_local_resettable;
2162 buffer_local_flags.generated_modeline_string = always_local_no_default;
2164 buffer_local_flags.keymap = resettable;
2165 buffer_local_flags.downcase_table = resettable;
2166 buffer_local_flags.upcase_table = resettable;
2167 buffer_local_flags.case_canon_table = resettable;
2168 buffer_local_flags.case_eqv_table = resettable;
2169 buffer_local_flags.syntax_table = resettable;
2171 buffer_local_flags.category_table = resettable;
2174 buffer_local_flags.modeline_format = make_int (1<<0);
2175 buffer_local_flags.abbrev_mode = make_int (1<<1);
2176 buffer_local_flags.overwrite_mode = make_int (1<<2);
2177 buffer_local_flags.case_fold_search = make_int (1<<3);
2178 buffer_local_flags.auto_fill_function = make_int (1<<4);
2179 buffer_local_flags.selective_display = make_int (1<<5);
2180 buffer_local_flags.selective_display_ellipses = make_int (1<<6);
2181 buffer_local_flags.tab_width = make_int (1<<7);
2182 buffer_local_flags.truncate_lines = make_int (1<<8);
2183 buffer_local_flags.ctl_arrow = make_int (1<<9);
2184 buffer_local_flags.fill_column = make_int (1<<10);
2185 buffer_local_flags.left_margin = make_int (1<<11);
2186 buffer_local_flags.abbrev_table = make_int (1<<12);
2187 #ifdef REGION_CACHE_NEEDS_WORK
2188 buffer_local_flags.cache_long_line_scans = make_int (1<<13);
2191 buffer_local_flags.buffer_file_coding_system = make_int (1<<14);
2194 /* #### Warning: 1<<28 is the largest number currently allowable
2195 due to the XINT() handling of this value. With some
2196 rearrangement you can get 3 more bits. */
2199 DEFVAR_BUFFER_DEFAULTS ("default-modeline-format", modeline_format /*
2200 Default value of `modeline-format' for buffers that don't override it.
2201 This is the same as (default-value 'modeline-format).
2204 DEFVAR_BUFFER_DEFAULTS ("default-abbrev-mode", abbrev_mode /*
2205 Default value of `abbrev-mode' for buffers that do not override it.
2206 This is the same as (default-value 'abbrev-mode).
2209 DEFVAR_BUFFER_DEFAULTS ("default-ctl-arrow", ctl_arrow /*
2210 Default value of `ctl-arrow' for buffers that do not override it.
2211 This is the same as (default-value 'ctl-arrow).
2214 #if 0 /* #### make this a specifier! */
2215 DEFVAR_BUFFER_DEFAULTS ("default-display-direction", display_direction /*
2216 Default display-direction for buffers that do not override it.
2217 This is the same as (default-value 'display-direction).
2218 Note: This is not yet implemented.
2222 DEFVAR_BUFFER_DEFAULTS ("default-truncate-lines", truncate_lines /*
2223 Default value of `truncate-lines' for buffers that do not override it.
2224 This is the same as (default-value 'truncate-lines).
2227 DEFVAR_BUFFER_DEFAULTS ("default-fill-column", fill_column /*
2228 Default value of `fill-column' for buffers that do not override it.
2229 This is the same as (default-value 'fill-column).
2232 DEFVAR_BUFFER_DEFAULTS ("default-left-margin", left_margin /*
2233 Default value of `left-margin' for buffers that do not override it.
2234 This is the same as (default-value 'left-margin).
2237 DEFVAR_BUFFER_DEFAULTS ("default-tab-width", tab_width /*
2238 Default value of `tab-width' for buffers that do not override it.
2239 This is the same as (default-value 'tab-width).
2242 DEFVAR_BUFFER_DEFAULTS ("default-case-fold-search", case_fold_search /*
2243 Default value of `case-fold-search' for buffers that don't override it.
2244 This is the same as (default-value 'case-fold-search).
2247 DEFVAR_BUFFER_LOCAL ("modeline-format", modeline_format /*
2248 Template for displaying modeline for current buffer.
2249 Each buffer has its own value of this variable.
2250 Value may be a string, a symbol or a list or cons cell.
2251 For a symbol, its value is used (but it is ignored if t or nil).
2252 A string appearing directly as the value of a symbol is processed verbatim
2253 in that the %-constructs below are not recognized.
2254 For a glyph, it is inserted as is.
2255 For a list whose car is a symbol, the symbol's value is taken,
2256 and if that is non-nil, the cadr of the list is processed recursively.
2257 Otherwise, the caddr of the list (if there is one) is processed.
2258 For a list whose car is a string or list, each element is processed
2259 recursively and the results are effectively concatenated.
2260 For a list whose car is an integer, the cdr of the list is processed
2261 and padded (if the number is positive) or truncated (if negative)
2262 to the width specified by that number.
2263 For a list whose car is an extent, the cdr of the list is processed
2264 normally but the results are displayed using the face of the
2265 extent, and mouse clicks over this section are processed using the
2266 keymap of the extent. (In addition, if the extent has a help-echo
2267 property, that string will be echoed when the mouse moves over this
2268 section.) See `generated-modeline-string' for more information.
2269 For a list whose car is a face, the cdr of the list is processed
2270 normally but the results will be displayed using the face in the car.
2271 For a list whose car is a keymap, the cdr of the list is processed
2272 normally but the keymap will apply for mouse clicks over the results,
2273 in addition to `modeline-map'. Nested keymap specifications are
2275 A string is printed verbatim in the modeline except for %-constructs:
2276 (%-constructs are processed when the string is the entire modeline-format
2277 or when it is found in a cons-cell or a list)
2278 %b -- print buffer name. %c -- print the current column number.
2279 %f -- print visited file name.
2280 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.
2281 % means buffer is read-only and * means it is modified.
2282 For a modified read-only buffer, %* gives % and %+ gives *.
2283 %s -- print process status. %l -- print the current line number.
2284 %S -- print name of selected frame (only meaningful under X Windows).
2285 %p -- print percent of buffer above top of window, or Top, Bot or All.
2286 %P -- print percent of buffer above bottom of window, perhaps plus Top,
2287 or print Bottom or All.
2288 %n -- print Narrow if appropriate.
2289 %C -- under XEmacs/mule, print the mnemonic for `buffer-file-coding-system'.
2290 %[ -- print one [ for each recursive editing level. %] similar.
2291 %% -- print %. %- -- print infinitely many dashes.
2292 Decimal digits after the % specify field width to which to pad.
2295 DEFVAR_BUFFER_DEFAULTS ("default-major-mode", major_mode /*
2296 *Major mode for new buffers. Defaults to `fundamental-mode'.
2297 nil here means use current buffer's major mode.
2300 DEFVAR_BUFFER_DEFAULTS ("fundamental-mode-abbrev-table", abbrev_table /*
2301 The abbrev table of mode-specific abbrevs for Fundamental Mode.
2304 DEFVAR_BUFFER_LOCAL ("major-mode", major_mode /*
2305 Symbol for current buffer's major mode.
2308 DEFVAR_BUFFER_LOCAL ("mode-name", mode_name /*
2309 Pretty name of current buffer's major mode (a string).
2312 DEFVAR_BUFFER_LOCAL ("abbrev-mode", abbrev_mode /*
2313 Non-nil turns on automatic expansion of abbrevs as they are inserted.
2314 Automatically becomes buffer-local when set in any fashion.
2317 DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search /*
2318 *Non-nil if searches should ignore case.
2319 Automatically becomes buffer-local when set in any fashion.
2321 BUG: Under XEmacs/Mule, translations to or from non-ASCII characters
2322 (this includes chars in the range 128 - 255) are ignored by
2323 the string/buffer-searching routines. Thus, `case-fold-search'
2324 will not correctly conflate a-umlaut and A-umlaut even if the
2325 case tables call for this.
2328 DEFVAR_BUFFER_LOCAL ("fill-column", fill_column /*
2329 *Column beyond which automatic line-wrapping should happen.
2330 Automatically becomes buffer-local when set in any fashion.
2333 DEFVAR_BUFFER_LOCAL ("left-margin", left_margin /*
2334 *Column for the default indent-line-function to indent to.
2335 Linefeed indents to this column in Fundamental mode.
2336 Automatically becomes buffer-local when set in any fashion.
2337 Do not confuse this with the specifier `left-margin-width';
2338 that controls the size of a margin that is displayed outside
2342 DEFVAR_BUFFER_LOCAL_MAGIC ("tab-width", tab_width /*
2343 *Distance between tab stops (for display of tab characters), in columns.
2344 Automatically becomes buffer-local when set in any fashion.
2345 */ , redisplay_variable_changed);
2347 DEFVAR_BUFFER_LOCAL_MAGIC ("ctl-arrow", ctl_arrow /*
2348 *Non-nil means display control chars with uparrow.
2349 Nil means use backslash and octal digits.
2350 An integer means characters >= ctl-arrow are assumed to be printable, and
2351 will be displayed as a single glyph.
2352 Any other value is the same as 160 - the code SPC with the high bit on.
2354 The interpretation of this variable is likely to change in the future.
2356 Automatically becomes buffer-local when set in any fashion.
2357 This variable does not apply to characters whose display is specified
2358 in the current display table (if there is one).
2359 */ , redisplay_variable_changed);
2361 #if 0 /* #### Make this a specifier! */
2362 xxDEFVAR_BUFFER_LOCAL ("display-direction", display_direction /*
2363 *Non-nil means lines in the buffer are displayed right to left.
2364 Nil means left to right. (Not yet implemented.)
2366 #endif /* Not yet implemented */
2368 DEFVAR_BUFFER_LOCAL_MAGIC ("truncate-lines", truncate_lines /*
2369 *Non-nil means do not display continuation lines;
2370 give each line of text one frame line.
2371 Automatically becomes buffer-local when set in any fashion.
2373 Note that this is overridden by the variable
2374 `truncate-partial-width-windows' if that variable is non-nil
2375 and this buffer is not full-frame width.
2376 */ , redisplay_variable_changed);
2378 DEFVAR_BUFFER_LOCAL ("default-directory", directory /*
2379 Name of default directory of current buffer. Should end with slash.
2380 Each buffer has its own value of this variable.
2384 DEFVAR_BUFFER_DEFAULTS ("default-buffer-file-coding-system", buffer_file_coding_system /*
2385 Default value of `buffer-file-coding-system' for buffers that do not override it.
2386 This is the same as (default-value 'buffer-file-coding-system).
2387 This value is used both for buffers without associated files and
2388 for buffers whose files do not have any apparent coding system.
2389 See `buffer-file-coding-system'.
2392 DEFVAR_BUFFER_LOCAL ("buffer-file-coding-system", buffer_file_coding_system /*
2393 *Current coding system for the current buffer.
2394 When the buffer is written out into a file, this coding system will be
2395 used for the encoding. Automatically buffer-local when set in any
2396 fashion. This is normally set automatically when a file is loaded in
2397 based on the determined coding system of the file (assuming that
2398 `buffer-file-coding-system-for-read' is set to `undecided', which
2399 calls for automatic determination of the file's coding system).
2400 Normally the modeline indicates the current file coding system using
2401 its mnemonic abbreviation.
2403 The default value for this variable (which is normally used for
2404 buffers without associated files) is also used when automatic
2405 detection of a file's encoding is called for and there was no
2406 discernible encoding in the file (i.e. it was entirely or almost
2407 entirely ASCII). The default value should generally *not* be set to
2408 nil (equivalent to `no-conversion'), because if extended characters
2409 are ever inserted into the buffer, they will be lost when the file is
2410 written out. A good choice is `iso-2022-8' (the simple ISO 2022 8-bit
2411 encoding), which will write out ASCII and Latin-1 characters in the
2412 standard (and highly portable) fashion and use standard escape
2413 sequences for other charsets. Another reasonable choice is
2414 `escape-quoted', which is equivalent to `iso-2022-8' but prefixes
2415 certain control characters with ESC to make sure they are not
2416 interpreted as escape sequences when read in. This latter coding
2417 system results in more "correct" output in the presence of control
2418 characters in the buffer, in the sense that when read in again using
2419 the same coding system, the result will virtually always match the
2420 original contents of the buffer, which is not the case with
2421 `iso-2022-8'; but the output is less portable when dealing with binary
2422 data -- there may be stray ESC characters when the file is read by
2425 `buffer-file-coding-system' does *not* control the coding system used when
2426 a file is read in. Use the variables `buffer-file-coding-system-for-read'
2427 and `buffer-file-coding-system-alist' for that. From a Lisp program, if
2428 you wish to unilaterally specify the coding system used for one
2429 particular operation, you should bind the variable
2430 `coding-system-for-read' rather than changing the other two
2431 variables just mentioned, which are intended to be used for
2432 global environment specification.
2434 #endif /* FILE_CODING */
2436 DEFVAR_BUFFER_LOCAL ("auto-fill-function", auto_fill_function /*
2437 Function called (if non-nil) to perform auto-fill.
2438 It is called after self-inserting a space at a column beyond `fill-column'.
2439 Each buffer has its own value of this variable.
2440 NOTE: This variable is not an ordinary hook;
2441 It may not be a list of functions.
2444 DEFVAR_BUFFER_LOCAL ("buffer-file-name", filename /*
2445 Name of file visited in current buffer, or nil if not visiting a file.
2446 Each buffer has its own value of this variable.
2451 Abbreviated truename of file visited in current buffer, or nil if none.
2452 The truename of a file is calculated by `file-truename'
2453 and then abbreviated with `abbreviate-file-name'.
2454 Each buffer has its own value of this variable.
2456 #endif /* FSFmacs */
2458 DEFVAR_BUFFER_LOCAL ("buffer-file-truename", file_truename /*
2459 The real name of the file visited in the current buffer,
2460 or nil if not visiting a file. This is the result of passing
2461 buffer-file-name to the `file-truename' function. Every buffer has
2462 its own value of this variable. This variable is automatically
2463 maintained by the functions that change the file name associated
2467 DEFVAR_BUFFER_LOCAL ("buffer-auto-save-file-name", auto_save_file_name /*
2468 Name of file for auto-saving current buffer,
2469 or nil if buffer should not be auto-saved.
2470 Each buffer has its own value of this variable.
2473 DEFVAR_BUFFER_LOCAL ("buffer-read-only", read_only /*
2474 Non-nil if this buffer is read-only.
2475 Each buffer has its own value of this variable.
2478 DEFVAR_BUFFER_LOCAL ("buffer-backed-up", backed_up /*
2479 Non-nil if this buffer's file has been backed up.
2480 Backing up is done before the first time the file is saved.
2481 Each buffer has its own value of this variable.
2484 DEFVAR_BUFFER_LOCAL ("buffer-saved-size", saved_size /*
2485 Length of current buffer when last read in, saved or auto-saved.
2487 Each buffer has its own value of this variable.
2490 DEFVAR_BUFFER_LOCAL_MAGIC ("selective-display", selective_display /*
2491 Non-nil enables selective display:
2492 Integer N as value means display only lines
2493 that start with less than n columns of space.
2494 A value of t means, after a ^M, all the rest of the line is invisible.
2495 Then ^M's in the file are written into files as newlines.
2497 Automatically becomes buffer-local when set in any fashion.
2498 */, redisplay_variable_changed);
2501 DEFVAR_BUFFER_LOCAL_MAGIC ("selective-display-ellipses",
2502 selective_display_ellipses /*
2503 t means display ... on previous line when a line is invisible.
2504 Automatically becomes buffer-local when set in any fashion.
2505 */, redisplay_variable_changed);
2508 DEFVAR_BUFFER_LOCAL ("local-abbrev-table", abbrev_table /*
2509 Local (mode-specific) abbrev table of current buffer.
2512 DEFVAR_BUFFER_LOCAL ("overwrite-mode", overwrite_mode /*
2513 Non-nil if self-insertion should replace existing text.
2514 The value should be one of `overwrite-mode-textual',
2515 `overwrite-mode-binary', or nil.
2516 If it is `overwrite-mode-textual', self-insertion still
2517 inserts at the end of a line, and inserts when point is before a tab,
2518 until the tab is filled in.
2519 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.
2520 Automatically becomes buffer-local when set in any fashion.
2522 Normally, you shouldn't modify this variable by hand, but use the functions
2523 `overwrite-mode' and `binary-overwrite-mode' instead. However, you can
2524 customize the default value from the options menu.
2528 /* Adds the following to the doc string for buffer-undo-list:
2530 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property
2531 was modified between BEG and END. PROPERTY is the property name,
2532 and VALUE is the old value.
2534 #endif /* FSFmacs */
2536 DEFVAR_BUFFER_LOCAL ("buffer-undo-list", undo_list /*
2537 List of undo entries in current buffer.
2538 Recent changes come first; older changes follow newer.
2540 An entry (BEG . END) represents an insertion which begins at
2541 position BEG and ends at position END.
2543 An entry (TEXT . POSITION) represents the deletion of the string TEXT
2544 from (abs POSITION). If POSITION is positive, point was at the front
2545 of the text being deleted; if negative, point was at the end.
2547 An entry (t HIGH . LOW) indicates that the buffer previously had
2548 "unmodified" status. HIGH and LOW are the high and low 16-bit portions
2549 of the visited file's modification time, as of that time. If the
2550 modification time of the most recent save is different, this entry is
2553 An entry of the form EXTENT indicates that EXTENT was attached in
2554 the buffer. Undoing an entry of this form detaches EXTENT.
2556 An entry of the form (EXTENT START END) indicates that EXTENT was
2557 detached from the buffer. Undoing an entry of this form attaches
2558 EXTENT from START to END.
2560 An entry of the form POSITION indicates that point was at the buffer
2561 location given by the integer. Undoing an entry of this form places
2564 nil marks undo boundaries. The undo command treats the changes
2565 between two undo boundaries as a single step to be undone.
2567 If the value of the variable is t, undo information is not recorded.
2571 xxDEFVAR_BUFFER_LOCAL ("mark-active", mark_active /*
2572 Non-nil means the mark and region are currently active in this buffer.
2573 Automatically local in all buffers.
2575 #endif /* FSFmacs */
2577 #ifdef REGION_CACHE_NEEDS_WORK
2578 xxDEFVAR_BUFFER_LOCAL ("cache-long-line-scans", cache_long_line_scans /*
2579 Non-nil means that Emacs should use caches to handle long lines more quickly.
2580 This variable is buffer-local, in all buffers.
2582 Normally, the line-motion functions work by scanning the buffer for
2583 newlines. Columnar operations (like move-to-column and
2584 compute-motion) also work by scanning the buffer, summing character
2585 widths as they go. This works well for ordinary text, but if the
2586 buffer's lines are very long (say, more than 500 characters), these
2587 motion functions will take longer to execute. Emacs may also take
2588 longer to update the display.
2590 If cache-long-line-scans is non-nil, these motion functions cache the
2591 results of their scans, and consult the cache to avoid rescanning
2592 regions of the buffer until the text is modified. The caches are most
2593 beneficial when they prevent the most searching---that is, when the
2594 buffer contains long lines and large regions of characters with the
2595 same, fixed screen width.
2597 When cache-long-line-scans is non-nil, processing short lines will
2598 become slightly slower (because of the overhead of consulting the
2599 cache), and the caches will use memory roughly proportional to the
2600 number of newlines and characters whose screen width varies.
2602 The caches require no explicit maintenance; their accuracy is
2603 maintained internally by the Emacs primitives. Enabling or disabling
2604 the cache should not affect the behavior of any of the motion
2605 functions; it should only affect their performance.
2607 #endif /* REGION_CACHE_NEEDS_WORK */
2609 DEFVAR_BUFFER_LOCAL ("point-before-scroll", point_before_scroll /*
2610 Value of point before the last series of scroll operations, or nil.
2613 DEFVAR_BUFFER_LOCAL ("buffer-file-format", file_format /*
2614 List of formats to use when saving this buffer.
2615 Formats are defined by `format-alist'. This variable is
2616 set when a file is visited. Automatically local in all buffers.
2619 DEFVAR_BUFFER_LOCAL_MAGIC ("buffer-invisibility-spec", invisibility_spec /*
2620 Invisibility spec of this buffer.
2621 The default is t, which means that text is invisible
2622 if it has (or is covered by an extent with) a non-nil `invisible' property.
2623 If the value is a list, a text character is invisible if its `invisible'
2624 property is an element in that list.
2625 If an element is a cons cell of the form (PROP . ELLIPSIS),
2626 then characters with property value PROP are invisible,
2627 and they have an ellipsis as well if ELLIPSIS is non-nil.
2628 Note that the actual characters used for the ellipsis are controllable
2629 using `invisible-text-glyph', and default to "...".
2630 */, redisplay_variable_changed);
2632 DEFVAR_CONST_BUFFER_LOCAL ("generated-modeline-string",
2633 generated_modeline_string /*
2634 String of characters in this buffer's modeline as of the last redisplay.
2635 Each time the modeline is recomputed, the resulting characters are
2636 stored in this string, which is resized as necessary. You may not
2637 set this variable, and modifying this string will not change the
2638 modeline; you have to change `modeline-format' if you want that.
2640 For each extent in `modeline-format' that is encountered when
2641 processing the modeline, a corresponding extent is placed in
2642 `generated-modeline-string' and covers the text over which the
2643 extent in `modeline-format' applies. The extent in
2644 `generated-modeline-string' is made a child of the extent in
2645 `modeline-format', which means that it inherits all properties from
2646 that extent. Note that the extents in `generated-modeline-string'
2647 are managed automatically. You should not explicitly put any extents
2648 in `generated-modeline-string'; if you do, they will disappear the
2649 next time the modeline is processed.
2651 For extents in `modeline-format', the following properties are currently
2655 Affects the face of the modeline text. Currently, faces do
2656 not merge properly; only the most recently encountered face
2657 is used. This is a bug.
2660 Affects the disposition of button events over the modeline
2661 text. Multiple applicable keymaps *are* handled properly,
2662 and `modeline-map' still applies to any events that don't
2663 have bindings in extent-specific keymaps.
2666 If a string, causes the string to be displayed when the mouse
2667 moves over the text.
2670 /* Check for DEFVAR_BUFFER_LOCAL without initializing the corresponding
2671 slot of buffer_local_flags and vice-versa. Must be done after all
2672 DEFVAR_BUFFER_LOCAL() calls. */
2673 #define MARKED_SLOT(slot) \
2674 if ((XINT (buffer_local_flags.slot) != -2 && \
2675 XINT (buffer_local_flags.slot) != -3) \
2676 != !(NILP (XBUFFER (Vbuffer_local_symbols)->slot))) \
2678 #include "bufslots.h"
2682 Lisp_Object scratch = Fget_buffer_create (QSscratch);
2683 Fset_buffer (scratch);
2684 /* Want no undo records for *scratch* until after Emacs is dumped */
2685 Fbuffer_disable_undo (scratch);
2689 /* Is PWD another name for `.' ? */
2691 directory_is_current_directory (char *pwd)
2693 Bufbyte *pwd_internal;
2694 struct stat dotstat, pwdstat;
2696 GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA (pwd, pwd_internal);
2698 return (IS_DIRECTORY_SEP (*pwd_internal)
2699 && stat ((char *) pwd_internal, &pwdstat) == 0
2700 && stat (".", &dotstat) == 0
2701 && dotstat.st_ino == pwdstat.st_ino
2702 && dotstat.st_dev == pwdstat.st_dev
2703 && (int) strlen ((char *) pwd_internal) < MAXPATHLEN);
2707 init_initial_directory (void)
2709 /* This function can GC */
2713 initial_directory[0] = 0;
2715 /* If PWD is accurate, use it instead of calling getcwd. This is faster
2716 when PWD is right, and may avoid a fatal error. */
2717 if ((pwd = getenv ("PWD")) != NULL
2718 && directory_is_current_directory (pwd))
2719 strcpy (initial_directory, pwd);
2720 else if (getcwd (initial_directory, MAXPATHLEN) == NULL)
2721 fatal ("`getcwd' failed: %s\n", strerror (errno));
2723 /* Make sure pwd is DIRECTORY_SEP-terminated.
2724 Maybe this should really use some standard subroutine
2725 whose definition is filename syntax dependent. */
2727 int len = strlen (initial_directory);
2729 if (! IS_DIRECTORY_SEP (initial_directory[len - 1]))
2731 initial_directory[len] = DIRECTORY_SEP;
2732 initial_directory[len + 1] = '\0';
2736 /* XEmacs change: store buffer's default directory
2737 using preferred (i.e. as defined at compile-time)
2738 directory separator. --marcpa */
2740 #define CORRECT_DIR_SEPS(s) \
2741 do { if ('/' == DIRECTORY_SEP) dostounix_filename (s); \
2742 else unixtodos_filename (s); \
2745 CORRECT_DIR_SEPS(initial_directory);
2752 /* This function can GC */
2754 Fset_buffer (Fget_buffer_create (QSscratch));
2756 current_buffer->directory =
2757 build_ext_string (initial_directory, FORMAT_FILENAME);
2760 /* #### is this correct? */
2761 temp = get_minibuffer (0);
2762 XBUFFER (temp)->directory = current_buffer->directory;
2763 #endif /* FSFmacs */