1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995, 1997
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <sys/types.h>
25 #include <sys/param.h>
31 /* in 4.1, param.h fails to define this. */
32 #define MAXPATHLEN 1024
33 #endif /* not MAXPATHLEN */
37 #include "intervals.h"
42 #include "region-cache.h"
44 #include "blockinput.h"
47 struct buffer
*current_buffer
; /* the current buffer */
49 /* First buffer in chain of all buffers (in reverse order of creation).
50 Threaded through ->next. */
52 struct buffer
*all_buffers
;
54 /* This structure holds the default values of the buffer-local variables
55 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
56 The default value occupies the same slot in this structure
57 as an individual buffer's value occupies in that buffer.
58 Setting the default value also goes through the alist of buffers
59 and stores into each buffer that does not say it has a local value. */
61 struct buffer buffer_defaults
;
63 /* A Lisp_Object pointer to the above, used for staticpro */
65 static Lisp_Object Vbuffer_defaults
;
67 /* This structure marks which slots in a buffer have corresponding
68 default values in buffer_defaults.
69 Each such slot has a nonzero value in this structure.
70 The value has only one nonzero bit.
72 When a buffer has its own local value for a slot,
73 the bit for that slot (found in the same slot in this structure)
74 is turned on in the buffer's local_var_flags slot.
76 If a slot in this structure is -1, then even though there may
77 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
78 and the corresponding slot in buffer_defaults is not used.
80 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
81 but there is a default value which is copied into each buffer.
83 If a slot in this structure is negative, then even though there may
84 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
85 and the corresponding slot in buffer_defaults is not used.
87 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
88 zero, that is a bug */
90 struct buffer buffer_local_flags
;
92 /* This structure holds the names of symbols whose values may be
93 buffer-local. It is indexed and accessed in the same way as the above. */
95 struct buffer buffer_local_symbols
;
96 /* A Lisp_Object pointer to the above, used for staticpro */
97 static Lisp_Object Vbuffer_local_symbols
;
99 /* This structure holds the required types for the values in the
100 buffer-local slots. If a slot contains Qnil, then the
101 corresponding buffer slot may contain a value of any type. If a
102 slot contains an integer, then prospective values' tags must be
103 equal to that integer. When a tag does not match, the function
104 buffer_slot_type_mismatch will signal an error. */
105 struct buffer buffer_local_types
;
107 /* Flags indicating which built-in buffer-local variables
108 are permanent locals. */
109 static int buffer_permanent_local_flags
;
111 Lisp_Object
Fset_buffer ();
112 void set_buffer_internal ();
113 void set_buffer_internal_1 ();
114 static void call_overlay_mod_hooks ();
115 static void swap_out_buffer_local_variables ();
116 static void reset_buffer_local_variables ();
118 /* Alist of all buffer names vs the buffers. */
119 /* This used to be a variable, but is no longer,
120 to prevent lossage due to user rplac'ing this alist or its elements. */
121 Lisp_Object Vbuffer_alist
;
123 /* Functions to call before and after each text change. */
124 Lisp_Object Vbefore_change_function
;
125 Lisp_Object Vafter_change_function
;
126 Lisp_Object Vbefore_change_functions
;
127 Lisp_Object Vafter_change_functions
;
129 Lisp_Object Vtransient_mark_mode
;
131 /* t means ignore all read-only text properties.
132 A list means ignore such a property if its value is a member of the list.
133 Any non-nil value means ignore buffer-read-only. */
134 Lisp_Object Vinhibit_read_only
;
136 /* List of functions to call that can query about killing a buffer.
137 If any of these functions returns nil, we don't kill it. */
138 Lisp_Object Vkill_buffer_query_functions
;
140 /* List of functions to call before changing an unmodified buffer. */
141 Lisp_Object Vfirst_change_hook
;
143 Lisp_Object Qfirst_change_hook
;
144 Lisp_Object Qbefore_change_functions
;
145 Lisp_Object Qafter_change_functions
;
147 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
149 Lisp_Object Qprotected_field
;
151 Lisp_Object QSFundamental
; /* A string "Fundamental" */
153 Lisp_Object Qkill_buffer_hook
;
155 Lisp_Object Qget_file_buffer
;
157 Lisp_Object Qoverlayp
;
159 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
161 Lisp_Object Qmodification_hooks
;
162 Lisp_Object Qinsert_in_front_hooks
;
163 Lisp_Object Qinsert_behind_hooks
;
165 /* For debugging; temporary. See set_buffer_internal. */
166 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
173 error ("No buffer named %s", XSTRING (spec
)->data
);
174 error ("Invalid buffer argument");
177 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
178 "Return non-nil if OBJECT is a buffer which has not been killed.\n\
179 Value is nil if OBJECT is not a buffer or if it has been killed.")
183 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
187 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
188 "Return a list of all existing live buffers.\n\
189 If the optional arg FRAME is a frame, we return that frame's buffer list.")
193 Lisp_Object framelist
, general
;
194 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
200 CHECK_FRAME (frame
, 1);
202 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
204 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */
206 while (! NILP (tail
))
208 general
= Fdelq (XCONS (tail
)->car
, general
);
209 tail
= XCONS (tail
)->cdr
;
211 return nconc2 (framelist
, general
);
217 /* Like Fassoc, but use Fstring_equal to compare
218 (which ignores text properties),
219 and don't ever QUIT. */
222 assoc_ignore_text_properties (key
, list
)
223 register Lisp_Object key
;
226 register Lisp_Object tail
;
227 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
229 register Lisp_Object elt
, tem
;
231 tem
= Fstring_equal (Fcar (elt
), key
);
238 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
239 "Return the buffer named NAME (a string).\n\
240 If there is no live buffer named NAME, return nil.\n\
241 NAME may also be a buffer; if so, the value is that buffer.")
243 register Lisp_Object name
;
247 CHECK_STRING (name
, 0);
249 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
252 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
253 "Return the buffer visiting file FILENAME (a string).\n\
254 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\
255 If there is no such live buffer, return nil.\n\
256 See also `find-buffer-visiting'.")
258 register Lisp_Object filename
;
260 register Lisp_Object tail
, buf
, tem
;
263 CHECK_STRING (filename
, 0);
264 filename
= Fexpand_file_name (filename
, Qnil
);
266 /* If the file name has special constructs in it,
267 call the corresponding file handler. */
268 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
270 return call2 (handler
, Qget_file_buffer
, filename
);
272 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
274 buf
= Fcdr (XCONS (tail
)->car
);
275 if (!BUFFERP (buf
)) continue;
276 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
277 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
285 get_truename_buffer (filename
)
286 register Lisp_Object filename
;
288 register Lisp_Object tail
, buf
, tem
;
290 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
292 buf
= Fcdr (XCONS (tail
)->car
);
293 if (!BUFFERP (buf
)) continue;
294 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
295 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
302 /* Incremented for each buffer created, to assign the buffer number. */
305 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
306 "Return the buffer named NAME, or create such a buffer and return it.\n\
307 A new buffer is created if there is no live buffer named NAME.\n\
308 If NAME starts with a space, the new buffer does not keep undo information.\n\
309 If NAME is a buffer instead of a string, then it is the value returned.\n\
310 The value is never nil.")
312 register Lisp_Object name
;
314 register Lisp_Object buf
;
315 register struct buffer
*b
;
317 buf
= Fget_buffer (name
);
321 if (XSTRING (name
)->size
== 0)
322 error ("Empty string for buffer name is not allowed");
324 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
326 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
328 /* An ordinary buffer uses its own struct buffer_text. */
329 b
->text
= &b
->own_text
;
332 BUF_GAP_SIZE (b
) = 20;
334 /* We allocate extra 1-byte at the tail and keep it always '\0' for
335 anchoring a search. */
336 BUFFER_ALLOC (BUF_BEG_ADDR (b
), (BUF_GAP_SIZE (b
) + 1));
338 if (! BUF_BEG_ADDR (b
))
339 buffer_memory_full ();
347 BUF_GPT_BYTE (b
) = 1;
348 BUF_BEGV_BYTE (b
) = 1;
352 BUF_OVERLAY_MODIFF (b
) = 1;
353 BUF_SAVE_MODIFF (b
) = 1;
354 BUF_INTERVALS (b
) = 0;
355 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
357 b
->newline_cache
= 0;
358 b
->width_run_cache
= 0;
359 b
->width_table
= Qnil
;
361 /* Put this on the chain of all buffers including killed ones. */
362 b
->next
= all_buffers
;
365 /* An ordinary buffer normally doesn't need markers
366 to handle BEGV and ZV. */
368 b
->begv_marker
= Qnil
;
371 name
= Fcopy_sequence (name
);
372 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
375 if (XSTRING (name
)->data
[0] != ' ')
381 reset_buffer_local_variables (b
, 1);
383 /* Put this in the alist of all live buffers. */
385 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
387 b
->mark
= Fmake_marker ();
388 BUF_MARKERS (b
) = Qnil
;
393 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
, 2, 2,
394 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
395 "Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.\n\
396 BASE-BUFFER should be an existing buffer (or buffer name).\n\
397 NAME should be a string which is not the name of an existing buffer.")
399 register Lisp_Object base_buffer
, name
;
401 register Lisp_Object buf
;
402 register struct buffer
*b
;
404 buf
= Fget_buffer (name
);
406 error ("Buffer name `%s' is in use", XSTRING (name
)->data
);
408 base_buffer
= Fget_buffer (base_buffer
);
409 if (NILP (base_buffer
))
410 error ("No such buffer: `%s'",
411 XSTRING (XBUFFER (base_buffer
)->name
)->data
);
413 if (XSTRING (name
)->size
== 0)
414 error ("Empty string for buffer name is not allowed");
416 b
= (struct buffer
*) xmalloc (sizeof (struct buffer
));
418 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
420 if (XBUFFER (base_buffer
)->base_buffer
)
421 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
423 b
->base_buffer
= XBUFFER (base_buffer
);
425 /* Use the base buffer's text object. */
426 b
->text
= b
->base_buffer
->text
;
428 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
429 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
430 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
431 BUF_BEGV_BYTE (b
) = BUF_BEGV_BYTE (b
->base_buffer
);
432 BUF_ZV_BYTE (b
) = BUF_ZV_BYTE (b
->base_buffer
);
433 BUF_PT_BYTE (b
) = BUF_PT_BYTE (b
->base_buffer
);
435 b
->newline_cache
= 0;
436 b
->width_run_cache
= 0;
437 b
->width_table
= Qnil
;
439 /* Put this on the chain of all buffers including killed ones. */
440 b
->next
= all_buffers
;
443 name
= Fcopy_sequence (name
);
444 INITIALIZE_INTERVAL (XSTRING (name
), NULL_INTERVAL
);
448 reset_buffer_local_variables (b
, 1);
450 /* Put this in the alist of all live buffers. */
452 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
454 b
->mark
= Fmake_marker ();
457 /* Make sure the base buffer has markers for its narrowing. */
458 if (NILP (b
->base_buffer
->pt_marker
))
460 b
->base_buffer
->pt_marker
= Fmake_marker ();
461 set_marker_both (b
->base_buffer
->pt_marker
, base_buffer
,
462 BUF_PT (b
->base_buffer
),
463 BUF_PT_BYTE (b
->base_buffer
));
465 if (NILP (b
->base_buffer
->begv_marker
))
467 b
->base_buffer
->begv_marker
= Fmake_marker ();
468 set_marker_both (b
->base_buffer
->begv_marker
, base_buffer
,
469 BUF_BEGV (b
->base_buffer
),
470 BUF_BEGV_BYTE (b
->base_buffer
));
472 if (NILP (b
->base_buffer
->zv_marker
))
474 b
->base_buffer
->zv_marker
= Fmake_marker ();
475 set_marker_both (b
->base_buffer
->zv_marker
, base_buffer
,
476 BUF_ZV (b
->base_buffer
),
477 BUF_ZV_BYTE (b
->base_buffer
));
478 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
481 /* Give the indirect buffer markers for its narrowing. */
482 b
->pt_marker
= Fmake_marker ();
483 set_marker_both (b
->pt_marker
, buf
, BUF_PT (b
), BUF_PT_BYTE (b
));
484 b
->begv_marker
= Fmake_marker ();
485 set_marker_both (b
->begv_marker
, buf
, BUF_BEGV (b
), BUF_BEGV_BYTE (b
));
486 b
->zv_marker
= Fmake_marker ();
487 set_marker_both (b
->zv_marker
, buf
, BUF_ZV (b
), BUF_ZV_BYTE (b
));
488 XMARKER (b
->zv_marker
)->insertion_type
= 1;
493 /* Reinitialize everything about a buffer except its name and contents
494 and local variables. */
498 register struct buffer
*b
;
501 b
->file_truename
= Qnil
;
502 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
504 XSETFASTINT (b
->save_length
, 0);
505 b
->last_window_start
= 1;
506 /* It is more conservative to start out "changed" than "unchanged". */
509 b
->auto_save_modified
= 0;
510 b
->auto_save_failure_time
= -1;
511 b
->auto_save_file_name
= Qnil
;
513 b
->overlays_before
= Qnil
;
514 b
->overlays_after
= Qnil
;
515 XSETFASTINT (b
->overlay_center
, 1);
516 b
->mark_active
= Qnil
;
517 b
->point_before_scroll
= Qnil
;
518 b
->file_format
= Qnil
;
519 b
->last_selected_window
= Qnil
;
520 XSETINT (b
->display_count
, 0);
525 /* Reset buffer B's local variables info.
526 Don't use this on a buffer that has already been in use;
527 it does not treat permanent locals consistently.
528 Instead, use Fkill_all_local_variables.
530 If PERMANENT_TOO is 1, then we reset permanent built-in
531 buffer-local variables. If PERMANENT_TOO is 0,
532 we preserve those. */
535 reset_buffer_local_variables (b
, permanent_too
)
536 register struct buffer
*b
;
542 /* Decide which built-in local variables to reset. */
546 dont_reset
= buffer_permanent_local_flags
;
548 /* Reset the major mode to Fundamental, together with all the
549 things that depend on the major mode.
550 default-major-mode is handled at a higher level.
551 We ignore it here. */
552 b
->major_mode
= Qfundamental_mode
;
554 b
->abbrev_table
= Vfundamental_mode_abbrev_table
;
555 b
->mode_name
= QSFundamental
;
556 b
->minor_modes
= Qnil
;
558 /* If the standard case table has been altered and invalidated,
559 fix up its insides first. */
560 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
561 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
562 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
563 Fset_standard_case_table (Vascii_downcase_table
);
565 b
->downcase_table
= Vascii_downcase_table
;
566 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
567 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
568 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
569 b
->invisibility_spec
= Qt
;
571 b
->buffer_file_type
= Qnil
;
575 b
->sort_table
= XSTRING (Vascii_sort_table
);
576 b
->folding_sort_table
= XSTRING (Vascii_folding_sort_table
);
579 /* Reset all (or most) per-buffer variables to their defaults. */
580 b
->local_var_alist
= Qnil
;
581 b
->local_var_flags
&= dont_reset
;
583 /* For each slot that has a default value,
584 copy that into the slot. */
586 for (offset
= (char *)&buffer_local_flags
.name
- (char *)&buffer_local_flags
;
587 offset
< sizeof (struct buffer
);
588 offset
+= sizeof (Lisp_Object
)) /* sizeof EMACS_INT == sizeof Lisp_Object */
590 int flag
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
592 /* Don't reset a permanent local. */
593 && ! (dont_reset
& flag
))
595 *(Lisp_Object
*)(offset
+ (char *)b
)
596 = *(Lisp_Object
*)(offset
+ (char *)&buffer_defaults
);
600 /* We split this away from generate-new-buffer, because rename-buffer
601 and set-visited-file-name ought to be able to use this to really
602 rename the buffer properly. */
604 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
606 "Return a string that is the name of no existing buffer based on NAME.\n\
607 If there is no live buffer named NAME, then return NAME.\n\
608 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\
609 until an unused name is found, and then return that name.\n\
610 Optional second argument IGNORE specifies a name that is okay to use\n\
611 \(if it is in the sequence to be tried)\n\
612 even if a buffer with that name exists.")
614 register Lisp_Object name
, ignore
;
616 register Lisp_Object gentemp
, tem
;
620 CHECK_STRING (name
, 0);
622 tem
= Fget_buffer (name
);
629 sprintf (number
, "<%d>", ++count
);
630 gentemp
= concat2 (name
, build_string (number
));
631 tem
= Fstring_equal (gentemp
, ignore
);
634 tem
= Fget_buffer (gentemp
);
641 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
642 "Return the name of BUFFER, as a string.\n\
643 With no argument or nil as argument, return the name of the current buffer.")
645 register Lisp_Object buffer
;
648 return current_buffer
->name
;
649 CHECK_BUFFER (buffer
, 0);
650 return XBUFFER (buffer
)->name
;
653 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
654 "Return name of file BUFFER is visiting, or nil if none.\n\
655 No argument or nil as argument means use the current buffer.")
657 register Lisp_Object buffer
;
660 return current_buffer
->filename
;
661 CHECK_BUFFER (buffer
, 0);
662 return XBUFFER (buffer
)->filename
;
665 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
667 "Return the base buffer of indirect buffer BUFFER.\n\
668 If BUFFER is not indirect, return nil.")
670 register Lisp_Object buffer
;
673 Lisp_Object base_buffer
;
676 base
= current_buffer
->base_buffer
;
679 CHECK_BUFFER (buffer
, 0);
680 base
= XBUFFER (buffer
)->base_buffer
;
685 XSETBUFFER (base_buffer
, base
);
689 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
690 Sbuffer_local_variables
, 0, 1, 0,
691 "Return an alist of variables that are buffer-local in BUFFER.\n\
692 Most elements look like (SYMBOL . VALUE), describing one variable.\n\
693 For a symbol that is locally unbound, just the symbol appears in the value.\n\
694 Note that storing new VALUEs in these elements doesn't change the variables.\n\
695 No argument or nil as argument means use current buffer as BUFFER.")
697 register Lisp_Object buffer
;
699 register struct buffer
*buf
;
700 register Lisp_Object result
;
703 buf
= current_buffer
;
706 CHECK_BUFFER (buffer
, 0);
707 buf
= XBUFFER (buffer
);
713 register Lisp_Object tail
;
714 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
716 Lisp_Object val
, elt
;
718 elt
= XCONS (tail
)->car
;
720 /* Reference each variable in the alist in buf.
721 If inquiring about the current buffer, this gets the current values,
722 so store them into the alist so the alist is up to date.
723 If inquiring about some other buffer, this swaps out any values
724 for that buffer, making the alist up to date automatically. */
725 val
= find_symbol_value (XCONS (elt
)->car
);
726 /* Use the current buffer value only if buf is the current buffer. */
727 if (buf
!= current_buffer
)
728 val
= XCONS (elt
)->cdr
;
730 /* If symbol is unbound, put just the symbol in the list. */
731 if (EQ (val
, Qunbound
))
732 result
= Fcons (XCONS (elt
)->car
, result
);
733 /* Otherwise, put (symbol . value) in the list. */
735 result
= Fcons (Fcons (XCONS (elt
)->car
, val
), result
);
739 /* Add on all the variables stored in special slots. */
741 register int offset
, mask
;
743 for (offset
= (char *)&buffer_local_symbols
.name
- (char *)&buffer_local_symbols
;
744 offset
< sizeof (struct buffer
);
745 offset
+= (sizeof (EMACS_INT
))) /* sizeof EMACS_INT == sizeof Lisp_Object */
747 mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
748 if (mask
== -1 || (buf
->local_var_flags
& mask
))
749 if (SYMBOLP (*(Lisp_Object
*)(offset
750 + (char *)&buffer_local_symbols
)))
751 result
= Fcons (Fcons (*((Lisp_Object
*)
752 (offset
+ (char *)&buffer_local_symbols
)),
753 *(Lisp_Object
*)(offset
+ (char *)buf
)),
762 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
764 "Return t if BUFFER was modified since its file was last read or saved.\n\
765 No argument or nil as argument means use current buffer as BUFFER.")
767 register Lisp_Object buffer
;
769 register struct buffer
*buf
;
771 buf
= current_buffer
;
774 CHECK_BUFFER (buffer
, 0);
775 buf
= XBUFFER (buffer
);
778 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
781 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
783 "Mark current buffer as modified or unmodified according to FLAG.\n\
784 A non-nil FLAG means mark the buffer modified.")
786 register Lisp_Object flag
;
788 register int already
;
789 register Lisp_Object fn
;
791 #ifdef CLASH_DETECTION
792 /* If buffer becoming modified, lock the file.
793 If buffer becoming unmodified, unlock the file. */
795 fn
= current_buffer
->file_truename
;
798 already
= SAVE_MODIFF
< MODIFF
;
799 if (!already
&& !NILP (flag
))
801 else if (already
&& NILP (flag
))
804 #endif /* CLASH_DETECTION */
806 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
811 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
813 "Return BUFFER's tick counter, incremented for each change in text.\n\
814 Each buffer has a tick counter which is incremented each time the text in\n\
815 that buffer is changed. It wraps around occasionally.\n\
816 No argument or nil as argument means use current buffer as BUFFER.")
818 register Lisp_Object buffer
;
820 register struct buffer
*buf
;
822 buf
= current_buffer
;
825 CHECK_BUFFER (buffer
, 0);
826 buf
= XBUFFER (buffer
);
829 return make_number (BUF_MODIFF (buf
));
832 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
833 "sRename buffer (to new name): \nP",
834 "Change current buffer's name to NEWNAME (a string).\n\
835 If second arg UNIQUE is nil or omitted, it is an error if a\n\
836 buffer named NEWNAME already exists.\n\
837 If UNIQUE is non-nil, come up with a new name using\n\
838 `generate-new-buffer-name'.\n\
839 Interactively, you can set UNIQUE with a prefix argument.\n\
840 We return the name we actually gave the buffer.\n\
841 This does not change the name of the visited file (if any).")
843 register Lisp_Object newname
, unique
;
845 register Lisp_Object tem
, buf
;
847 CHECK_STRING (newname
, 0);
849 if (XSTRING (newname
)->size
== 0)
850 error ("Empty string is invalid as a buffer name");
852 tem
= Fget_buffer (newname
);
853 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename
854 the buffer automatically so you can create another with the original name.
855 It makes UNIQUE equivalent to
856 (rename-buffer (generate-new-buffer-name NEWNAME)). */
857 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
858 return current_buffer
->name
;
862 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
864 error ("Buffer name `%s' is in use", XSTRING (newname
)->data
);
867 current_buffer
->name
= newname
;
869 /* Catch redisplay's attention. Unless we do this, the mode lines for
870 any windows displaying current_buffer will stay unchanged. */
873 XSETBUFFER (buf
, current_buffer
);
874 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
875 if (NILP (current_buffer
->filename
)
876 && !NILP (current_buffer
->auto_save_file_name
))
877 call0 (intern ("rename-auto-save-file"));
878 /* Refetch since that last call may have done GC. */
879 return current_buffer
->name
;
882 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 2, 0,
883 "Return most recently selected buffer other than BUFFER.\n\
884 Buffers not visible in windows are preferred to visible buffers,\n\
885 unless optional second argument VISIBLE-OK is non-nil.\n\
886 If no other buffer exists, the buffer `*scratch*' is returned.\n\
887 If BUFFER is omitted or nil, some interesting buffer is returned.")
889 register Lisp_Object buffer
, visible_ok
;
891 Lisp_Object
Fset_buffer_major_mode ();
892 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
895 tail
= Vbuffer_alist
;
896 pred
= frame_buffer_predicate ();
898 /* Consider buffers that have been seen in the selected frame
899 before other buffers. */
901 tem
= frame_buffer_list ();
905 if (BUFFERP (XCONS (tem
)->car
))
906 add_ons
= Fcons (Fcons (Qnil
, XCONS (tem
)->car
), add_ons
);
907 tem
= XCONS (tem
)->cdr
;
909 tail
= nconc2 (Fnreverse (add_ons
), tail
);
911 for (; !NILP (tail
); tail
= Fcdr (tail
))
913 buf
= Fcdr (Fcar (tail
));
914 if (EQ (buf
, buffer
))
916 if (XSTRING (XBUFFER (buf
)->name
)->data
[0] == ' ')
918 /* If the selected frame has a buffer_predicate,
919 disregard buffers that don't fit the predicate. */
922 tem
= call1 (pred
, buf
);
927 if (NILP (visible_ok
))
928 tem
= Fget_buffer_window (buf
, Qt
);
933 if (NILP (notsogood
))
936 if (!NILP (notsogood
))
938 buf
= Fget_buffer_create (build_string ("*scratch*"));
939 Fset_buffer_major_mode (buf
);
943 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo
, Sbuffer_disable_undo
,
945 "Make BUFFER stop keeping undo information.\n\
946 No argument or nil as argument means do this for the current buffer.")
948 register Lisp_Object buffer
;
950 Lisp_Object real_buffer
;
953 XSETBUFFER (real_buffer
, current_buffer
);
956 real_buffer
= Fget_buffer (buffer
);
957 if (NILP (real_buffer
))
961 XBUFFER (real_buffer
)->undo_list
= Qt
;
966 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
968 "Start keeping undo information for buffer BUFFER.\n\
969 No argument or nil as argument means do this for the current buffer.")
971 register Lisp_Object buffer
;
973 Lisp_Object real_buffer
;
976 XSETBUFFER (real_buffer
, current_buffer
);
979 real_buffer
= Fget_buffer (buffer
);
980 if (NILP (real_buffer
))
984 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
985 XBUFFER (real_buffer
)->undo_list
= Qnil
;
991 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
992 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
993 The buffer being killed will be current while the hook is running.\n\
996 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
997 "Kill the buffer BUFFER.\n\
998 The argument may be a buffer or may be the name of a buffer.\n\
999 An argument of nil means kill the current buffer.\n\n\
1000 Value is t if the buffer is actually killed, nil if user says no.\n\n\
1001 The value of `kill-buffer-hook' (which may be local to that buffer),\n\
1002 if not void, is a list of functions to be called, with no arguments,\n\
1003 before the buffer is actually killed. The buffer to be killed is current\n\
1004 when the hook functions are called.\n\n\
1005 Any processes that have this buffer as the `process-buffer' are killed\n\
1011 register struct buffer
*b
;
1012 register Lisp_Object tem
;
1013 register struct Lisp_Marker
*m
;
1014 struct gcpro gcpro1
, gcpro2
;
1017 buf
= Fcurrent_buffer ();
1019 buf
= Fget_buffer (buffer
);
1025 /* Avoid trouble for buffer already dead. */
1029 /* Query if the buffer is still modified. */
1030 if (INTERACTIVE
&& !NILP (b
->filename
)
1031 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1034 tem
= do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
1035 XSTRING (b
->name
)->data
));
1041 /* Run hooks with the buffer to be killed the current buffer. */
1043 register Lisp_Object val
;
1044 int count
= specpdl_ptr
- specpdl
;
1047 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1048 set_buffer_internal (b
);
1050 /* First run the query functions; if any query is answered no,
1051 don't kill the buffer. */
1052 for (list
= Vkill_buffer_query_functions
; !NILP (list
); list
= Fcdr (list
))
1054 tem
= call0 (Fcar (list
));
1056 return unbind_to (count
, Qnil
);
1059 /* Then run the hooks. */
1060 if (!NILP (Vrun_hooks
))
1061 call1 (Vrun_hooks
, Qkill_buffer_hook
);
1062 unbind_to (count
, Qnil
);
1065 /* We have no more questions to ask. Verify that it is valid
1066 to kill the buffer. This must be done after the questions
1067 since anything can happen within do_yes_or_no_p. */
1069 /* Don't kill the minibuffer now current. */
1070 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1076 /* When we kill a base buffer, kill all its indirect buffers.
1077 We do it at this stage so nothing terrible happens if they
1078 ask questions or their hooks get errors. */
1079 if (! b
->base_buffer
)
1081 struct buffer
*other
;
1085 for (other
= all_buffers
; other
; other
= other
->next
)
1086 /* all_buffers contains dead buffers too;
1087 don't re-kill them. */
1088 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1091 XSETBUFFER (buf
, other
);
1098 /* Make this buffer not be current.
1099 In the process, notice if this is the sole visible buffer
1100 and give up if so. */
1101 if (b
== current_buffer
)
1103 tem
= Fother_buffer (buf
, Qnil
);
1105 if (b
== current_buffer
)
1109 /* Now there is no question: we can kill the buffer. */
1111 #ifdef CLASH_DETECTION
1112 /* Unlock this buffer's file, if it is locked. */
1114 #endif /* CLASH_DETECTION */
1116 kill_buffer_processes (buf
);
1118 tem
= Vinhibit_quit
;
1120 replace_buffer_in_all_windows (buf
);
1121 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1122 frames_discard_buffer (buf
);
1123 Vinhibit_quit
= tem
;
1125 /* Delete any auto-save file, if we saved it in this session. */
1126 if (STRINGP (b
->auto_save_file_name
)
1127 && b
->auto_save_modified
!= 0
1128 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
)
1131 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1133 internal_delete_file (b
->auto_save_file_name
);
1138 /* Unchain all markers that belong to this indirect buffer.
1139 Don't unchain the markers that belong to the base buffer
1140 or its other indirect buffers. */
1141 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1147 unchain_marker (tem
);
1153 /* Unchain all markers of this buffer and its indirect buffers.
1154 and leave them pointing nowhere. */
1155 for (tem
= BUF_MARKERS (b
); !NILP (tem
); )
1162 BUF_MARKERS (b
) = Qnil
;
1164 #ifdef USE_TEXT_PROPERTIES
1165 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1168 /* Perhaps we should explicitly free the interval tree here... */
1171 /* Reset the local variables, so that this buffer's local values
1172 won't be protected from GC. They would be protected
1173 if they happened to remain encached in their symbols.
1174 This gets rid of them for certain. */
1175 swap_out_buffer_local_variables (b
);
1176 reset_buffer_local_variables (b
, 1);
1181 if (! b
->base_buffer
)
1182 BUFFER_FREE (BUF_BEG_ADDR (b
));
1184 if (b
->newline_cache
)
1186 free_region_cache (b
->newline_cache
);
1187 b
->newline_cache
= 0;
1189 if (b
->width_run_cache
)
1191 free_region_cache (b
->width_run_cache
);
1192 b
->width_run_cache
= 0;
1194 b
->width_table
= Qnil
;
1196 b
->undo_list
= Qnil
;
1201 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1202 we do this each time BUF is selected visibly, the more recently
1203 selected buffers are always closer to the front of the list. This
1204 means that other_buffer is more likely to choose a relevant buffer. */
1210 register Lisp_Object link
, prev
;
1213 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCONS (link
)->cdr
)
1215 if (EQ (XCONS (XCONS (link
)->car
)->cdr
, buf
))
1220 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1221 we cannot use Fdelq itself here because it allows quitting. */
1224 Vbuffer_alist
= XCONS (Vbuffer_alist
)->cdr
;
1226 XCONS (prev
)->cdr
= XCONS (XCONS (prev
)->cdr
)->cdr
;
1228 XCONS (link
)->cdr
= Vbuffer_alist
;
1229 Vbuffer_alist
= link
;
1231 /* Now move this buffer to the front of frame_buffer_list also. */
1234 for (link
= frame_buffer_list (); CONSP (link
); link
= XCONS (link
)->cdr
)
1236 if (EQ (XCONS (link
)->car
, buf
))
1241 /* Effectively do delq. */
1246 set_frame_buffer_list (XCONS (frame_buffer_list ())->cdr
);
1248 XCONS (prev
)->cdr
= XCONS (XCONS (prev
)->cdr
)->cdr
;
1250 XCONS (link
)->cdr
= frame_buffer_list ();
1251 set_frame_buffer_list (link
);
1254 set_frame_buffer_list (Fcons (buf
, frame_buffer_list ()));
1257 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1258 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
1259 Use this function before selecting the buffer, since it may need to inspect\n\
1260 the current buffer's major mode.")
1265 Lisp_Object function
;
1267 function
= buffer_defaults
.major_mode
;
1268 if (NILP (function
) && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1269 function
= current_buffer
->major_mode
;
1271 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1274 count
= specpdl_ptr
- specpdl
;
1276 /* To select a nonfundamental mode,
1277 select the buffer temporarily and then call the mode function. */
1279 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1281 Fset_buffer (buffer
);
1284 return unbind_to (count
, Qnil
);
1287 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1288 "Select buffer BUFFER in the current window.\n\
1289 BUFFER may be a buffer or a buffer name.\n\
1290 Optional second arg NORECORD non-nil means\n\
1291 do not put this buffer at the front of the list of recently selected ones.\n\
1293 WARNING: This is NOT the way to work on another buffer temporarily\n\
1294 within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\
1295 the window-buffer correspondences.")
1297 Lisp_Object buffer
, norecord
;
1299 register Lisp_Object buf
;
1302 if (EQ (minibuf_window
, selected_window
))
1303 error ("Cannot switch buffers in minibuffer window");
1304 tem
= Fwindow_dedicated_p (selected_window
);
1306 error ("Cannot switch buffers in a dedicated window");
1309 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1312 buf
= Fget_buffer (buffer
);
1315 buf
= Fget_buffer_create (buffer
);
1316 Fset_buffer_major_mode (buf
);
1320 if (NILP (norecord
))
1321 record_buffer (buf
);
1323 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1324 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1331 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1332 "Select buffer BUFFER in some window, preferably a different one.\n\
1333 If BUFFER is nil, then some other buffer is chosen.\n\
1334 If `pop-up-windows' is non-nil, windows can be split to do this.\n\
1335 If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\
1336 window even if BUFFER is already visible in the selected window.\n\
1337 This uses the function `display-buffer' as a subroutine; see the documentation\n\
1338 of `display-buffer' for additional customization information.\n\
1340 Optional third arg NORECORD non-nil means\n\
1341 do not put this buffer at the front of the list of recently selected ones.")
1342 (buffer
, other_window
, norecord
)
1343 Lisp_Object buffer
, other_window
, norecord
;
1345 register Lisp_Object buf
;
1347 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
);
1350 buf
= Fget_buffer (buffer
);
1353 buf
= Fget_buffer_create (buffer
);
1354 Fset_buffer_major_mode (buf
);
1358 if (NILP (norecord
))
1359 record_buffer (buf
);
1360 Fselect_window (Fdisplay_buffer (buf
, other_window
));
1364 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1365 "Return the current buffer as a Lisp object.")
1368 register Lisp_Object buf
;
1369 XSETBUFFER (buf
, current_buffer
);
1373 /* Set the current buffer to B. */
1376 set_buffer_internal (b
)
1377 register struct buffer
*b
;
1379 register struct buffer
*old_buf
;
1380 register Lisp_Object tail
, valcontents
;
1383 if (current_buffer
== b
)
1386 windows_or_buffers_changed
= 1;
1387 set_buffer_internal_1 (b
);
1390 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1391 This is used by redisplay. */
1394 set_buffer_internal_1 (b
)
1395 register struct buffer
*b
;
1397 register struct buffer
*old_buf
;
1398 register Lisp_Object tail
, valcontents
;
1401 if (current_buffer
== b
)
1404 old_buf
= current_buffer
;
1406 last_known_column_point
= -1; /* invalidate indentation cache */
1410 /* Put the undo list back in the base buffer, so that it appears
1411 that an indirect buffer shares the undo list of its base. */
1412 if (old_buf
->base_buffer
)
1413 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1415 /* If the old current buffer has markers to record PT, BEGV and ZV
1416 when it is not current, update them now. */
1417 if (! NILP (old_buf
->pt_marker
))
1420 XSETBUFFER (obuf
, old_buf
);
1421 set_marker_both (old_buf
->pt_marker
, obuf
,
1422 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1424 if (! NILP (old_buf
->begv_marker
))
1427 XSETBUFFER (obuf
, old_buf
);
1428 set_marker_both (old_buf
->begv_marker
, obuf
,
1429 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1431 if (! NILP (old_buf
->zv_marker
))
1434 XSETBUFFER (obuf
, old_buf
);
1435 set_marker_both (old_buf
->zv_marker
, obuf
,
1436 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1440 /* Get the undo list from the base buffer, so that it appears
1441 that an indirect buffer shares the undo list of its base. */
1443 b
->undo_list
= b
->base_buffer
->undo_list
;
1445 /* If the new current buffer has markers to record PT, BEGV and ZV
1446 when it is not current, fetch them now. */
1447 if (! NILP (b
->pt_marker
))
1449 BUF_PT (b
) = marker_position (b
->pt_marker
);
1450 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1452 if (! NILP (b
->begv_marker
))
1454 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1455 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1457 if (! NILP (b
->zv_marker
))
1459 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1460 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1463 /* Look down buffer's list of local Lisp variables
1464 to find and update any that forward into C variables. */
1466 for (tail
= b
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1468 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1469 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1470 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1471 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1472 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1473 /* Just reference the variable
1474 to cause it to become set for this buffer. */
1475 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1478 /* Do the same with any others that were local to the previous buffer */
1481 for (tail
= old_buf
->local_var_alist
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
1483 valcontents
= XSYMBOL (XCONS (XCONS (tail
)->car
)->car
)->value
;
1484 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1485 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1486 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1487 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1488 /* Just reference the variable
1489 to cause it to become set for this buffer. */
1490 Fsymbol_value (XCONS (XCONS (tail
)->car
)->car
);
1494 /* Switch to buffer B temporarily for redisplay purposes.
1495 This avoids certain things that don't need to be done within redisplay. */
1501 register struct buffer
*old_buf
;
1503 if (current_buffer
== b
)
1506 old_buf
= current_buffer
;
1511 /* If the old current buffer has markers to record PT, BEGV and ZV
1512 when it is not current, update them now. */
1513 if (! NILP (old_buf
->pt_marker
))
1516 XSETBUFFER (obuf
, old_buf
);
1517 set_marker_both (old_buf
->pt_marker
, obuf
,
1518 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1520 if (! NILP (old_buf
->begv_marker
))
1523 XSETBUFFER (obuf
, old_buf
);
1524 set_marker_both (old_buf
->begv_marker
, obuf
,
1525 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1527 if (! NILP (old_buf
->zv_marker
))
1530 XSETBUFFER (obuf
, old_buf
);
1531 set_marker_both (old_buf
->zv_marker
, obuf
,
1532 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1536 /* If the new current buffer has markers to record PT, BEGV and ZV
1537 when it is not current, fetch them now. */
1538 if (! NILP (b
->pt_marker
))
1540 BUF_PT (b
) = marker_position (b
->pt_marker
);
1541 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1543 if (! NILP (b
->begv_marker
))
1545 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1546 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1548 if (! NILP (b
->zv_marker
))
1550 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1551 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1555 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1556 "Make the buffer BUFFER current for editing operations.\n\
1557 BUFFER may be a buffer or the name of an existing buffer.\n\
1558 See also `save-excursion' when you want to make a buffer current temporarily.\n\
1559 This function does not display the buffer, so its effect ends\n\
1560 when the current command terminates.\n\
1561 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.")
1563 register Lisp_Object buffer
;
1565 register Lisp_Object buf
;
1566 buf
= Fget_buffer (buffer
);
1569 if (NILP (XBUFFER (buf
)->name
))
1570 error ("Selecting deleted buffer");
1571 set_buffer_internal (XBUFFER (buf
));
1575 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1576 Sbarf_if_buffer_read_only
, 0, 0, 0,
1577 "Signal a `buffer-read-only' error if the current buffer is read-only.")
1580 if (!NILP (current_buffer
->read_only
)
1581 && NILP (Vinhibit_read_only
))
1582 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1586 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1587 "Put BUFFER at the end of the list of all buffers.\n\
1588 There it is the least likely candidate for `other-buffer' to return;\n\
1589 thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
1590 If BUFFER is nil or omitted, bury the current buffer.\n\
1591 Also, if BUFFER is nil or omitted, remove the current buffer from the\n\
1592 selected window if it is displayed there.")
1594 register Lisp_Object buffer
;
1596 /* Figure out what buffer we're going to bury. */
1599 XSETBUFFER (buffer
, current_buffer
);
1601 /* If we're burying the current buffer, unshow it. */
1602 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
), Qnil
);
1608 buf1
= Fget_buffer (buffer
);
1614 /* Move buffer to the end of the buffer list. */
1616 register Lisp_Object aelt
, link
;
1618 aelt
= Frassq (buffer
, Vbuffer_alist
);
1619 link
= Fmemq (aelt
, Vbuffer_alist
);
1620 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1621 XCONS (link
)->cdr
= Qnil
;
1622 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
1625 frames_bury_buffer (buffer
);
1630 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
1631 "Delete the entire contents of the current buffer.\n\
1632 Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\
1633 so the buffer is truly empty after this.")
1638 current_buffer
->last_window_start
= 1;
1639 /* Prevent warnings, or suspension of auto saving, that would happen
1640 if future size is less than past size. Use of erase-buffer
1641 implies that the future text is not really related to the past text. */
1642 XSETFASTINT (current_buffer
->save_length
, 0);
1647 validate_region (b
, e
)
1648 register Lisp_Object
*b
, *e
;
1650 CHECK_NUMBER_COERCE_MARKER (*b
, 0);
1651 CHECK_NUMBER_COERCE_MARKER (*e
, 1);
1653 if (XINT (*b
) > XINT (*e
))
1656 tem
= *b
; *b
= *e
; *e
= tem
;
1659 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
1660 && XINT (*e
) <= ZV
))
1661 args_out_of_range (*b
, *e
);
1664 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
1666 "Switch to Fundamental mode by killing current buffer's local variables.\n\
1667 Most local variable bindings are eliminated so that the default values\n\
1668 become effective once more. Also, the syntax table is set from\n\
1669 `standard-syntax-table', the local keymap is set to nil,\n\
1670 and the abbrev table from `fundamental-mode-abbrev-table'.\n\
1671 This function also forces redisplay of the mode line.\n\
1673 Every function to select a new major mode starts by\n\
1674 calling this function.\n\n\
1675 As a special exception, local variables whose names have\n\
1676 a non-nil `permanent-local' property are not eliminated by this function.\n\
1678 The first thing this function does is run\n\
1679 the normal hook `change-major-mode-hook'.")
1682 register Lisp_Object alist
, sym
, tem
;
1685 if (!NILP (Vrun_hooks
))
1686 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
1687 oalist
= current_buffer
->local_var_alist
;
1689 /* Make sure none of the bindings in oalist
1690 remain swapped in, in their symbols. */
1692 swap_out_buffer_local_variables (current_buffer
);
1694 /* Actually eliminate all local bindings of this buffer. */
1696 reset_buffer_local_variables (current_buffer
, 0);
1698 /* Redisplay mode lines; we are changing major mode. */
1700 update_mode_lines
++;
1702 /* Any which are supposed to be permanent,
1703 make local again, with the same values they had. */
1705 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1707 sym
= XCONS (XCONS (alist
)->car
)->car
;
1708 tem
= Fget (sym
, Qpermanent_local
);
1711 Fmake_local_variable (sym
);
1712 Fset (sym
, XCONS (XCONS (alist
)->car
)->cdr
);
1716 /* Force mode-line redisplay. Useful here because all major mode
1717 commands call this function. */
1718 update_mode_lines
++;
1723 /* Make sure no local variables remain set up with buffer B
1724 for their current values. */
1727 swap_out_buffer_local_variables (b
)
1730 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
1732 XSETBUFFER (buffer
, b
);
1733 oalist
= b
->local_var_alist
;
1735 for (alist
= oalist
; !NILP (alist
); alist
= XCONS (alist
)->cdr
)
1737 sym
= XCONS (XCONS (alist
)->car
)->car
;
1739 /* Need not do anything if some other buffer's binding is now encached. */
1740 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
;
1741 if (XBUFFER (tem
) == current_buffer
)
1743 /* Symbol is set up for this buffer's old local value.
1744 Set it up for the current buffer with the default value. */
1746 tem
= XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->cdr
;
1747 /* Store the symbol's current value into the alist entry
1748 it is currently set up for. This is so that, if the
1749 local is marked permanent, and we make it local again
1750 later in Fkill_all_local_variables, we don't lose the value. */
1751 XCONS (XCONS (tem
)->car
)->cdr
1752 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
);
1753 /* Switch to the symbol's default-value alist entry. */
1754 XCONS (tem
)->car
= tem
;
1755 /* Mark it as current for buffer B. */
1756 XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->cdr
)->car
1758 /* Store the current value into any forwarding in the symbol. */
1759 store_symval_forwarding (sym
, XBUFFER_LOCAL_VALUE (XSYMBOL (sym
)->value
)->car
,
1765 /* Find all the overlays in the current buffer that contain position POS.
1766 Return the number found, and store them in a vector in *VEC_PTR.
1767 Store in *LEN_PTR the size allocated for the vector.
1768 Store in *NEXT_PTR the next position after POS where an overlay starts,
1769 or ZV if there are no more overlays.
1770 Store in *PREV_PTR the previous position before POS where an overlay ends,
1771 or BEGV if there are no previous overlays.
1772 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1774 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1775 when this function is called.
1777 If EXTEND is non-zero, we make the vector bigger if necessary.
1778 If EXTEND is zero, we never extend the vector,
1779 and we store only as many overlays as will fit.
1780 But we still return the total number of overlays. */
1783 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1786 Lisp_Object
**vec_ptr
;
1791 Lisp_Object tail
, overlay
, start
, end
, result
;
1794 Lisp_Object
*vec
= *vec_ptr
;
1797 int inhibit_storing
= 0;
1799 for (tail
= current_buffer
->overlays_before
;
1801 tail
= XCONS (tail
)->cdr
)
1803 int startpos
, endpos
;
1805 overlay
= XCONS (tail
)->car
;
1807 start
= OVERLAY_START (overlay
);
1808 end
= OVERLAY_END (overlay
);
1809 endpos
= OVERLAY_POSITION (end
);
1818 startpos
= OVERLAY_POSITION (start
);
1819 if (startpos
<= pos
)
1823 /* The supplied vector is full.
1824 Either make it bigger, or don't store any more in it. */
1827 *len_ptr
= len
*= 2;
1828 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1832 inhibit_storing
= 1;
1835 if (!inhibit_storing
)
1837 /* Keep counting overlays even if we can't return them all. */
1840 else if (startpos
< next
)
1844 for (tail
= current_buffer
->overlays_after
;
1846 tail
= XCONS (tail
)->cdr
)
1848 int startpos
, endpos
;
1850 overlay
= XCONS (tail
)->car
;
1852 start
= OVERLAY_START (overlay
);
1853 end
= OVERLAY_END (overlay
);
1854 startpos
= OVERLAY_POSITION (start
);
1857 if (startpos
< next
)
1861 endpos
= OVERLAY_POSITION (end
);
1868 *len_ptr
= len
*= 2;
1869 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1873 inhibit_storing
= 1;
1876 if (!inhibit_storing
)
1880 else if (endpos
< pos
&& endpos
> prev
)
1891 /* Find all the overlays in the current buffer that overlap the range BEG-END
1892 or are empty at BEG.
1894 Return the number found, and store them in a vector in *VEC_PTR.
1895 Store in *LEN_PTR the size allocated for the vector.
1896 Store in *NEXT_PTR the next position after POS where an overlay starts,
1897 or ZV if there are no more overlays.
1898 Store in *PREV_PTR the previous position before POS where an overlay ends,
1899 or BEGV if there are no previous overlays.
1900 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1902 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1903 when this function is called.
1905 If EXTEND is non-zero, we make the vector bigger if necessary.
1906 If EXTEND is zero, we never extend the vector,
1907 and we store only as many overlays as will fit.
1908 But we still return the total number of overlays. */
1911 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
1914 Lisp_Object
**vec_ptr
;
1919 Lisp_Object tail
, overlay
, ostart
, oend
, result
;
1922 Lisp_Object
*vec
= *vec_ptr
;
1925 int inhibit_storing
= 0;
1927 for (tail
= current_buffer
->overlays_before
;
1929 tail
= XCONS (tail
)->cdr
)
1931 int startpos
, endpos
;
1933 overlay
= XCONS (tail
)->car
;
1935 ostart
= OVERLAY_START (overlay
);
1936 oend
= OVERLAY_END (overlay
);
1937 endpos
= OVERLAY_POSITION (oend
);
1944 startpos
= OVERLAY_POSITION (ostart
);
1945 /* Count an interval if it either overlaps the range
1946 or is empty at the start of the range. */
1947 if ((beg
< endpos
&& startpos
< end
)
1948 || (startpos
== endpos
&& beg
== endpos
))
1952 /* The supplied vector is full.
1953 Either make it bigger, or don't store any more in it. */
1956 *len_ptr
= len
*= 2;
1957 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
1961 inhibit_storing
= 1;
1964 if (!inhibit_storing
)
1966 /* Keep counting overlays even if we can't return them all. */
1969 else if (startpos
< next
)
1973 for (tail
= current_buffer
->overlays_after
;
1975 tail
= XCONS (tail
)->cdr
)
1977 int startpos
, endpos
;
1979 overlay
= XCONS (tail
)->car
;
1981 ostart
= OVERLAY_START (overlay
);
1982 oend
= OVERLAY_END (overlay
);
1983 startpos
= OVERLAY_POSITION (ostart
);
1986 if (startpos
< next
)
1990 endpos
= OVERLAY_POSITION (oend
);
1991 /* Count an interval if it either overlaps the range
1992 or is empty at the start of the range. */
1993 if ((beg
< endpos
&& startpos
< end
)
1994 || (startpos
== endpos
&& beg
== endpos
))
2000 *len_ptr
= len
*= 2;
2001 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2005 inhibit_storing
= 1;
2008 if (!inhibit_storing
)
2012 else if (endpos
< beg
&& endpos
> prev
)
2023 /* Fast function to just test if we're at an overlay boundary. */
2025 overlay_touches_p (pos
)
2028 Lisp_Object tail
, overlay
;
2030 for (tail
= current_buffer
->overlays_before
; GC_CONSP (tail
);
2031 tail
= XCONS (tail
)->cdr
)
2035 overlay
= XCONS (tail
)->car
;
2036 if (!GC_OVERLAYP (overlay
))
2039 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2042 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2046 for (tail
= current_buffer
->overlays_after
; GC_CONSP (tail
);
2047 tail
= XCONS (tail
)->cdr
)
2051 overlay
= XCONS (tail
)->car
;
2052 if (!GC_OVERLAYP (overlay
))
2055 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2058 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2066 Lisp_Object overlay
;
2072 compare_overlays (s1
, s2
)
2073 struct sortvec
*s1
, *s2
;
2075 if (s1
->priority
!= s2
->priority
)
2076 return s1
->priority
- s2
->priority
;
2077 if (s1
->beg
!= s2
->beg
)
2078 return s1
->beg
- s2
->beg
;
2079 if (s1
->end
!= s2
->end
)
2080 return s2
->end
- s1
->end
;
2084 /* Sort an array of overlays by priority. The array is modified in place.
2085 The return value is the new size; this may be smaller than the original
2086 size if some of the overlays were invalid or were window-specific. */
2088 sort_overlays (overlay_vec
, noverlays
, w
)
2089 Lisp_Object
*overlay_vec
;
2094 struct sortvec
*sortvec
;
2095 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2097 /* Put the valid and relevant overlays into sortvec. */
2099 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2102 Lisp_Object overlay
;
2104 overlay
= overlay_vec
[i
];
2105 if (OVERLAY_VALID (overlay
)
2106 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2107 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2109 /* If we're interested in a specific window, then ignore
2110 overlays that are limited to some other window. */
2115 window
= Foverlay_get (overlay
, Qwindow
);
2116 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2120 /* This overlay is good and counts: put it into sortvec. */
2121 sortvec
[j
].overlay
= overlay
;
2122 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2123 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2124 tem
= Foverlay_get (overlay
, Qpriority
);
2126 sortvec
[j
].priority
= XINT (tem
);
2128 sortvec
[j
].priority
= 0;
2134 /* Sort the overlays into the proper order: increasing priority. */
2137 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2139 for (i
= 0; i
< noverlays
; i
++)
2140 overlay_vec
[i
] = sortvec
[i
].overlay
;
2146 Lisp_Object string
, string2
;
2153 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2154 int size
; /* Allocated length of that array. */
2155 int used
; /* How much of the array is currently in use. */
2156 int bytes
; /* Total length of the strings in buf. */
2159 /* Buffers for storing information about the overlays touching a given
2160 position. These could be automatic variables in overlay_strings, but
2161 it's more efficient to hold onto the memory instead of repeatedly
2162 allocating and freeing it. */
2163 static struct sortstrlist overlay_heads
, overlay_tails
;
2164 static unsigned char *overlay_str_buf
;
2166 /* Allocated length of overlay_str_buf. */
2167 static int overlay_str_len
;
2169 /* A comparison function suitable for passing to qsort. */
2171 cmp_for_strings (as1
, as2
)
2174 struct sortstr
*s1
= (struct sortstr
*)as1
;
2175 struct sortstr
*s2
= (struct sortstr
*)as2
;
2176 if (s1
->size
!= s2
->size
)
2177 return s2
->size
- s1
->size
;
2178 if (s1
->priority
!= s2
->priority
)
2179 return s1
->priority
- s2
->priority
;
2184 record_overlay_string (ssl
, str
, str2
, pri
, size
)
2185 struct sortstrlist
*ssl
;
2186 Lisp_Object str
, str2
, pri
;
2191 if (ssl
->used
== ssl
->size
)
2197 ssl
->buf
= ((struct sortstr
*)
2198 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2200 ssl
->buf
[ssl
->used
].string
= str
;
2201 ssl
->buf
[ssl
->used
].string2
= str2
;
2202 ssl
->buf
[ssl
->used
].size
= size
;
2203 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2206 if (NILP (current_buffer
->enable_multibyte_characters
))
2207 nbytes
= XSTRING (str
)->size
;
2208 else if (! STRING_MULTIBYTE (str
))
2209 nbytes
= count_size_as_multibyte (XSTRING (str
)->data
,
2210 XSTRING (str
)->size_byte
);
2212 nbytes
= XSTRING (str
)->size_byte
;
2214 ssl
->bytes
+= nbytes
;
2218 if (NILP (current_buffer
->enable_multibyte_characters
))
2219 nbytes
= XSTRING (str2
)->size
;
2220 else if (! STRING_MULTIBYTE (str2
))
2221 nbytes
= count_size_as_multibyte (XSTRING (str2
)->data
,
2222 XSTRING (str2
)->size_byte
);
2224 nbytes
= XSTRING (str2
)->size_byte
;
2226 ssl
->bytes
+= nbytes
;
2230 /* Return the concatenation of the strings associated with overlays that
2231 begin or end at POS, ignoring overlays that are specific to a window
2232 other than W. The strings are concatenated in the appropriate order:
2233 shorter overlays nest inside longer ones, and higher priority inside
2234 lower. Normally all of the after-strings come first, but zero-sized
2235 overlays have their after-strings ride along with the before-strings
2236 because it would look strange to print them inside-out.
2238 Returns the string length, and stores the contents indirectly through
2239 PSTR, if that variable is non-null. The string may be overwritten by
2240 subsequent calls. */
2243 overlay_strings (pos
, w
, pstr
)
2246 unsigned char **pstr
;
2248 Lisp_Object ov
, overlay
, window
, str
;
2249 int startpos
, endpos
;
2250 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
2252 overlay_heads
.used
= overlay_heads
.bytes
= 0;
2253 overlay_tails
.used
= overlay_tails
.bytes
= 0;
2254 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCONS (ov
)->cdr
)
2256 overlay
= XCONS (ov
)->car
;
2257 if (!OVERLAYP (overlay
))
2260 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2261 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2264 if (endpos
!= pos
&& startpos
!= pos
)
2266 window
= Foverlay_get (overlay
, Qwindow
);
2267 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2270 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2271 record_overlay_string (&overlay_heads
, str
,
2273 ? Foverlay_get (overlay
, Qafter_string
)
2275 Foverlay_get (overlay
, Qpriority
),
2277 else if (endpos
== pos
2278 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2279 record_overlay_string (&overlay_tails
, str
, Qnil
,
2280 Foverlay_get (overlay
, Qpriority
),
2283 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCONS (ov
)->cdr
)
2285 overlay
= XCONS (ov
)->car
;
2286 if (!OVERLAYP (overlay
))
2289 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2290 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2293 if (endpos
!= pos
&& startpos
!= pos
)
2295 window
= Foverlay_get (overlay
, Qwindow
);
2296 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2299 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
2300 record_overlay_string (&overlay_heads
, str
,
2302 ? Foverlay_get (overlay
, Qafter_string
)
2304 Foverlay_get (overlay
, Qpriority
),
2306 else if (endpos
== pos
2307 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
2308 record_overlay_string (&overlay_tails
, str
, Qnil
,
2309 Foverlay_get (overlay
, Qpriority
),
2312 if (overlay_tails
.used
> 1)
2313 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
2315 if (overlay_heads
.used
> 1)
2316 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
2318 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
2323 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
2325 if (total
> overlay_str_len
)
2327 overlay_str_len
= total
;
2328 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
2331 p
= overlay_str_buf
;
2332 for (i
= overlay_tails
.used
; --i
>= 0;)
2335 tem
= overlay_tails
.buf
[i
].string
;
2336 nbytes
= copy_text (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size_byte
,
2337 STRING_MULTIBYTE (tem
), multibyte
);
2340 for (i
= 0; i
< overlay_heads
.used
; ++i
)
2343 tem
= overlay_heads
.buf
[i
].string
;
2344 nbytes
= copy_text (XSTRING (tem
)->data
, p
, XSTRING (tem
)->size_byte
,
2345 STRING_MULTIBYTE (tem
), multibyte
);
2347 tem
= overlay_heads
.buf
[i
].string2
;
2350 nbytes
= copy_text (XSTRING (tem
)->data
, p
,
2351 XSTRING (tem
)->size_byte
,
2352 STRING_MULTIBYTE (tem
), multibyte
);
2356 if (p
!= overlay_str_buf
+ total
)
2359 *pstr
= overlay_str_buf
;
2365 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
2368 recenter_overlay_lists (buf
, pos
)
2372 Lisp_Object overlay
, tail
, next
, prev
, beg
, end
;
2374 /* See if anything in overlays_before should move to overlays_after. */
2376 /* We don't strictly need prev in this loop; it should always be nil.
2377 But we use it for symmetry and in case that should cease to be true
2378 with some future change. */
2380 for (tail
= buf
->overlays_before
;
2382 prev
= tail
, tail
= next
)
2384 next
= XCONS (tail
)->cdr
;
2385 overlay
= XCONS (tail
)->car
;
2387 /* If the overlay is not valid, get rid of it. */
2388 if (!OVERLAY_VALID (overlay
))
2393 /* Splice the cons cell TAIL out of overlays_before. */
2395 XCONS (prev
)->cdr
= next
;
2397 buf
->overlays_before
= next
;
2403 beg
= OVERLAY_START (overlay
);
2404 end
= OVERLAY_END (overlay
);
2406 if (OVERLAY_POSITION (end
) > pos
)
2408 /* OVERLAY needs to be moved. */
2409 int where
= OVERLAY_POSITION (beg
);
2410 Lisp_Object other
, other_prev
;
2412 /* Splice the cons cell TAIL out of overlays_before. */
2414 XCONS (prev
)->cdr
= next
;
2416 buf
->overlays_before
= next
;
2418 /* Search thru overlays_after for where to put it. */
2420 for (other
= buf
->overlays_after
;
2422 other_prev
= other
, other
= XCONS (other
)->cdr
)
2424 Lisp_Object otherbeg
, otheroverlay
, follower
;
2427 otheroverlay
= XCONS (other
)->car
;
2428 if (! OVERLAY_VALID (otheroverlay
))
2431 otherbeg
= OVERLAY_START (otheroverlay
);
2432 if (OVERLAY_POSITION (otherbeg
) >= where
)
2436 /* Add TAIL to overlays_after before OTHER. */
2437 XCONS (tail
)->cdr
= other
;
2438 if (!NILP (other_prev
))
2439 XCONS (other_prev
)->cdr
= tail
;
2441 buf
->overlays_after
= tail
;
2445 /* We've reached the things that should stay in overlays_before.
2446 All the rest of overlays_before must end even earlier,
2451 /* See if anything in overlays_after should be in overlays_before. */
2453 for (tail
= buf
->overlays_after
;
2455 prev
= tail
, tail
= next
)
2457 next
= XCONS (tail
)->cdr
;
2458 overlay
= XCONS (tail
)->car
;
2460 /* If the overlay is not valid, get rid of it. */
2461 if (!OVERLAY_VALID (overlay
))
2466 /* Splice the cons cell TAIL out of overlays_after. */
2468 XCONS (prev
)->cdr
= next
;
2470 buf
->overlays_after
= next
;
2476 beg
= OVERLAY_START (overlay
);
2477 end
= OVERLAY_END (overlay
);
2479 /* Stop looking, when we know that nothing further
2480 can possibly end before POS. */
2481 if (OVERLAY_POSITION (beg
) > pos
)
2484 if (OVERLAY_POSITION (end
) <= pos
)
2486 /* OVERLAY needs to be moved. */
2487 int where
= OVERLAY_POSITION (end
);
2488 Lisp_Object other
, other_prev
;
2490 /* Splice the cons cell TAIL out of overlays_after. */
2492 XCONS (prev
)->cdr
= next
;
2494 buf
->overlays_after
= next
;
2496 /* Search thru overlays_before for where to put it. */
2498 for (other
= buf
->overlays_before
;
2500 other_prev
= other
, other
= XCONS (other
)->cdr
)
2502 Lisp_Object otherend
, otheroverlay
;
2505 otheroverlay
= XCONS (other
)->car
;
2506 if (! OVERLAY_VALID (otheroverlay
))
2509 otherend
= OVERLAY_END (otheroverlay
);
2510 if (OVERLAY_POSITION (otherend
) <= where
)
2514 /* Add TAIL to overlays_before before OTHER. */
2515 XCONS (tail
)->cdr
= other
;
2516 if (!NILP (other_prev
))
2517 XCONS (other_prev
)->cdr
= tail
;
2519 buf
->overlays_before
= tail
;
2524 XSETFASTINT (buf
->overlay_center
, pos
);
2528 adjust_overlays_for_insert (pos
, length
)
2532 /* After an insertion, the lists are still sorted properly,
2533 but we may need to update the value of the overlay center. */
2534 if (XFASTINT (current_buffer
->overlay_center
) >= pos
)
2535 XSETFASTINT (current_buffer
->overlay_center
,
2536 XFASTINT (current_buffer
->overlay_center
) + length
);
2540 adjust_overlays_for_delete (pos
, length
)
2544 if (XFASTINT (current_buffer
->overlay_center
) < pos
)
2545 /* The deletion was to our right. No change needed; the before- and
2546 after-lists are still consistent. */
2548 else if (XFASTINT (current_buffer
->overlay_center
) > pos
+ length
)
2549 /* The deletion was to our left. We need to adjust the center value
2550 to account for the change in position, but the lists are consistent
2551 given the new value. */
2552 XSETFASTINT (current_buffer
->overlay_center
,
2553 XFASTINT (current_buffer
->overlay_center
) - length
);
2555 /* We're right in the middle. There might be things on the after-list
2556 that now belong on the before-list. Recentering will move them,
2557 and also update the center point. */
2558 recenter_overlay_lists (current_buffer
, pos
);
2561 /* Fix up overlays that were garbled as a result of permuting markers
2562 in the range START through END. Any overlay with at least one
2563 endpoint in this range will need to be unlinked from the overlay
2564 list and reinserted in its proper place.
2565 Such an overlay might even have negative size at this point.
2566 If so, we'll reverse the endpoints. Can you think of anything
2567 better to do in this situation? */
2569 fix_overlays_in_range (start
, end
)
2570 register int start
, end
;
2572 Lisp_Object tem
, overlay
;
2573 Lisp_Object before_list
, after_list
;
2574 Lisp_Object
*ptail
, *pbefore
= &before_list
, *pafter
= &after_list
;
2575 int startpos
, endpos
;
2577 /* This algorithm shifts links around instead of consing and GCing.
2578 The loop invariant is that before_list (resp. after_list) is a
2579 well-formed list except that its last element, the one that
2580 *pbefore (resp. *pafter) points to, is still uninitialized.
2581 So it's not a bug that before_list isn't initialized, although
2582 it may look strange. */
2583 for (ptail
= ¤t_buffer
->overlays_before
; CONSP (*ptail
);)
2585 overlay
= XCONS (*ptail
)->car
;
2586 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2589 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2591 || (startpos
>= start
&& startpos
< end
))
2593 /* If the overlay is backwards, fix that now. */
2594 if (startpos
> endpos
)
2597 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
2599 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
2601 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2603 /* Add it to the end of the wrong list. Later on,
2604 recenter_overlay_lists will move it to the right place. */
2605 if (endpos
< XINT (current_buffer
->overlay_center
))
2608 pafter
= &XCONS (*ptail
)->cdr
;
2613 pbefore
= &XCONS (*ptail
)->cdr
;
2615 *ptail
= XCONS (*ptail
)->cdr
;
2618 ptail
= &XCONS (*ptail
)->cdr
;
2620 for (ptail
= ¤t_buffer
->overlays_after
; CONSP (*ptail
);)
2622 overlay
= XCONS (*ptail
)->car
;
2623 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2624 if (startpos
>= end
)
2626 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2627 if (startpos
>= start
2628 || (endpos
>= start
&& endpos
< end
))
2630 if (startpos
> endpos
)
2633 Fset_marker (OVERLAY_START (overlay
), make_number (endpos
),
2635 Fset_marker (OVERLAY_END (overlay
), make_number (startpos
),
2637 tem
= startpos
; startpos
= endpos
; endpos
= tem
;
2639 if (endpos
< XINT (current_buffer
->overlay_center
))
2642 pafter
= &XCONS (*ptail
)->cdr
;
2647 pbefore
= &XCONS (*ptail
)->cdr
;
2649 *ptail
= XCONS (*ptail
)->cdr
;
2652 ptail
= &XCONS (*ptail
)->cdr
;
2655 /* Splice the constructed (wrong) lists into the buffer's lists,
2656 and let the recenter function make it sane again. */
2657 *pbefore
= current_buffer
->overlays_before
;
2658 current_buffer
->overlays_before
= before_list
;
2659 recenter_overlay_lists (current_buffer
,
2660 XINT (current_buffer
->overlay_center
));
2662 *pafter
= current_buffer
->overlays_after
;
2663 current_buffer
->overlays_after
= after_list
;
2664 recenter_overlay_lists (current_buffer
,
2665 XINT (current_buffer
->overlay_center
));
2668 /* We have two types of overlay: the one whose ending marker is
2669 after-insertion-marker (this is the usual case) and the one whose
2670 ending marker is before-insertion-marker. When `overlays_before'
2671 contains overlays of the latter type and the former type in this
2672 order and both overlays end at inserting position, inserting a text
2673 increases only the ending marker of the latter type, which results
2674 in incorrect ordering of `overlays_before'.
2676 This function fixes ordering of overlays in the slot
2677 `overlays_before' of the buffer *BP. Before the insertion, `point'
2678 was at PREV, and now is at POS. */
2681 fix_overlays_before (bp
, prev
, pos
)
2685 Lisp_Object
*tailp
= &bp
->overlays_before
;
2686 Lisp_Object
*right_place
;
2689 /* After the insertion, the several overlays may be in incorrect
2690 order. The possibility is that, in the list `overlays_before',
2691 an overlay which ends at POS appears after an overlay which ends
2692 at PREV. Since POS is greater than PREV, we must fix the
2693 ordering of these overlays, by moving overlays ends at POS before
2694 the overlays ends at PREV. */
2696 /* At first, find a place where disordered overlays should be linked
2697 in. It is where an overlay which end before POS exists. (i.e. an
2698 overlay whose ending marker is after-insertion-marker if disorder
2700 while (!NILP (*tailp
)
2701 && ((end
= OVERLAY_POSITION (OVERLAY_END (XCONS (*tailp
)->car
)))
2703 tailp
= &XCONS (*tailp
)->cdr
;
2705 /* If we don't find such an overlay,
2706 or the found one ends before PREV,
2707 or the found one is the last one in the list,
2708 we don't have to fix anything. */
2711 || NILP (XCONS (*tailp
)->cdr
))
2714 right_place
= tailp
;
2715 tailp
= &XCONS (*tailp
)->cdr
;
2717 /* Now, end position of overlays in the list *TAILP should be before
2718 or equal to PREV. In the loop, an overlay which ends at POS is
2719 moved ahead to the place pointed by RIGHT_PLACE. If we found an
2720 overlay which ends before PREV, the remaining overlays are in
2722 while (!NILP (*tailp
))
2724 end
= OVERLAY_POSITION (OVERLAY_END (XCONS (*tailp
)->car
));
2727 { /* This overlay is disordered. */
2728 Lisp_Object found
= *tailp
;
2730 /* Unlink the found overlay. */
2731 *tailp
= XCONS (found
)->cdr
;
2732 /* Move an overlay at RIGHT_PLACE to the next of the found one. */
2733 XCONS (found
)->cdr
= *right_place
;
2734 /* Link it into the right place. */
2735 *right_place
= found
;
2737 else if (end
== prev
)
2738 tailp
= &XCONS (*tailp
)->cdr
;
2739 else /* No more disordered overlay. */
2744 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
2745 "Return t if OBJECT is an overlay.")
2749 return (OVERLAYP (object
) ? Qt
: Qnil
);
2752 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
2753 "Create a new overlay with range BEG to END in BUFFER.\n\
2754 If omitted, BUFFER defaults to the current buffer.\n\
2755 BEG and END may be integers or markers.\n\
2756 The fourth arg FRONT-ADVANCE, if non-nil, makes the\n\
2757 front delimiter advance when text is inserted there.\n\
2758 The fifth arg REAR-ADVANCE, if non-nil, makes the\n\
2759 rear delimiter advance when text is inserted there.")
2760 (beg
, end
, buffer
, front_advance
, rear_advance
)
2761 Lisp_Object beg
, end
, buffer
;
2762 Lisp_Object front_advance
, rear_advance
;
2764 Lisp_Object overlay
;
2768 XSETBUFFER (buffer
, current_buffer
);
2770 CHECK_BUFFER (buffer
, 2);
2772 && ! EQ (Fmarker_buffer (beg
), buffer
))
2773 error ("Marker points into wrong buffer");
2775 && ! EQ (Fmarker_buffer (end
), buffer
))
2776 error ("Marker points into wrong buffer");
2778 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2779 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2781 if (XINT (beg
) > XINT (end
))
2784 temp
= beg
; beg
= end
; end
= temp
;
2787 b
= XBUFFER (buffer
);
2789 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
2790 end
= Fset_marker (Fmake_marker (), end
, buffer
);
2792 if (!NILP (front_advance
))
2793 XMARKER (beg
)->insertion_type
= 1;
2794 if (!NILP (rear_advance
))
2795 XMARKER (end
)->insertion_type
= 1;
2797 overlay
= allocate_misc ();
2798 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
2799 XOVERLAY (overlay
)->start
= beg
;
2800 XOVERLAY (overlay
)->end
= end
;
2801 XOVERLAY (overlay
)->plist
= Qnil
;
2803 /* Put the new overlay on the wrong list. */
2804 end
= OVERLAY_END (overlay
);
2805 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2806 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2808 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2810 /* This puts it in the right list, and in the right order. */
2811 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2813 /* We don't need to redisplay the region covered by the overlay, because
2814 the overlay has no properties at the moment. */
2819 /* Mark a section of BUF as needing redisplay because of overlays changes. */
2822 modify_overlay (buf
, start
, end
)
2832 start
= end
; end
= temp
;
2835 /* If this is a buffer not in the selected window,
2836 we must do other windows. */
2837 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
2838 windows_or_buffers_changed
= 1;
2839 /* If it's not current, we can't use beg_unchanged, end_unchanged for it. */
2840 else if (buf
!= current_buffer
)
2841 windows_or_buffers_changed
= 1;
2842 /* If multiple windows show this buffer, we must do other windows. */
2843 else if (buffer_shared
> 1)
2844 windows_or_buffers_changed
= 1;
2847 if (unchanged_modified
== MODIFF
2848 && overlay_unchanged_modified
== OVERLAY_MODIFF
)
2850 beg_unchanged
= start
- BEG
;
2851 end_unchanged
= Z
- end
;
2855 if (Z
- end
< end_unchanged
)
2856 end_unchanged
= Z
- end
;
2857 if (start
- BEG
< beg_unchanged
)
2858 beg_unchanged
= start
- BEG
;
2862 ++BUF_OVERLAY_MODIFF (buf
);
2866 Lisp_Object
Fdelete_overlay ();
2868 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
2869 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\
2870 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\
2871 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\
2873 (overlay
, beg
, end
, buffer
)
2874 Lisp_Object overlay
, beg
, end
, buffer
;
2876 struct buffer
*b
, *ob
;
2877 Lisp_Object obuffer
;
2878 int count
= specpdl_ptr
- specpdl
;
2880 CHECK_OVERLAY (overlay
, 0);
2882 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2884 XSETBUFFER (buffer
, current_buffer
);
2885 CHECK_BUFFER (buffer
, 3);
2888 && ! EQ (Fmarker_buffer (beg
), buffer
))
2889 error ("Marker points into wrong buffer");
2891 && ! EQ (Fmarker_buffer (end
), buffer
))
2892 error ("Marker points into wrong buffer");
2894 CHECK_NUMBER_COERCE_MARKER (beg
, 1);
2895 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2897 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
2898 return Fdelete_overlay (overlay
);
2900 if (XINT (beg
) > XINT (end
))
2903 temp
= beg
; beg
= end
; end
= temp
;
2906 specbind (Qinhibit_quit
, Qt
);
2908 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2909 b
= XBUFFER (buffer
);
2910 ob
= XBUFFER (obuffer
);
2912 /* If the overlay has changed buffers, do a thorough redisplay. */
2913 if (!EQ (buffer
, obuffer
))
2915 /* Redisplay where the overlay was. */
2916 if (!NILP (obuffer
))
2921 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2922 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2924 modify_overlay (ob
, o_beg
, o_end
);
2927 /* Redisplay where the overlay is going to be. */
2928 modify_overlay (b
, XINT (beg
), XINT (end
));
2931 /* Redisplay the area the overlay has just left, or just enclosed. */
2934 int change_beg
, change_end
;
2936 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2937 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2939 if (o_beg
== XINT (beg
))
2940 modify_overlay (b
, o_end
, XINT (end
));
2941 else if (o_end
== XINT (end
))
2942 modify_overlay (b
, o_beg
, XINT (beg
));
2945 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
2946 if (XINT (end
) > o_end
) o_end
= XINT (end
);
2947 modify_overlay (b
, o_beg
, o_end
);
2951 if (!NILP (obuffer
))
2953 ob
->overlays_before
= Fdelq (overlay
, ob
->overlays_before
);
2954 ob
->overlays_after
= Fdelq (overlay
, ob
->overlays_after
);
2957 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
2958 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
2960 /* Put the overlay on the wrong list. */
2961 end
= OVERLAY_END (overlay
);
2962 if (OVERLAY_POSITION (end
) < XINT (b
->overlay_center
))
2963 b
->overlays_after
= Fcons (overlay
, b
->overlays_after
);
2965 b
->overlays_before
= Fcons (overlay
, b
->overlays_before
);
2967 /* This puts it in the right list, and in the right order. */
2968 recenter_overlay_lists (b
, XINT (b
->overlay_center
));
2970 return unbind_to (count
, overlay
);
2973 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
2974 "Delete the overlay OVERLAY from its buffer.")
2976 Lisp_Object overlay
;
2980 int count
= specpdl_ptr
- specpdl
;
2982 CHECK_OVERLAY (overlay
, 0);
2984 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
2988 b
= XBUFFER (buffer
);
2990 specbind (Qinhibit_quit
, Qt
);
2992 b
->overlays_before
= Fdelq (overlay
, b
->overlays_before
);
2993 b
->overlays_after
= Fdelq (overlay
, b
->overlays_after
);
2996 marker_position (OVERLAY_START (overlay
)),
2997 marker_position (OVERLAY_END (overlay
)));
2999 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
3000 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
3002 return unbind_to (count
, Qnil
);
3005 /* Overlay dissection functions. */
3007 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3008 "Return the position at which OVERLAY starts.")
3010 Lisp_Object overlay
;
3012 CHECK_OVERLAY (overlay
, 0);
3014 return (Fmarker_position (OVERLAY_START (overlay
)));
3017 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3018 "Return the position at which OVERLAY ends.")
3020 Lisp_Object overlay
;
3022 CHECK_OVERLAY (overlay
, 0);
3024 return (Fmarker_position (OVERLAY_END (overlay
)));
3027 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3028 "Return the buffer OVERLAY belongs to.")
3030 Lisp_Object overlay
;
3032 CHECK_OVERLAY (overlay
, 0);
3034 return Fmarker_buffer (OVERLAY_START (overlay
));
3037 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3038 "Return a list of the properties on OVERLAY.\n\
3039 This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\
3042 Lisp_Object overlay
;
3044 CHECK_OVERLAY (overlay
, 0);
3046 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3050 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3051 "Return a list of the overlays that contain position POS.")
3056 Lisp_Object
*overlay_vec
;
3060 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3063 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3065 /* Put all the overlays we want in a vector in overlay_vec.
3066 Store the length in len. */
3067 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3068 (int *) 0, (int *) 0);
3070 /* Make a list of them all. */
3071 result
= Flist (noverlays
, overlay_vec
);
3073 xfree (overlay_vec
);
3077 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3078 "Return a list of the overlays that overlap the region BEG ... END.\n\
3079 Overlap means that at least one character is contained within the overlay\n\
3080 and also contained within the specified region.\n\
3081 Empty overlays are included in the result if they are located at BEG\n\
3082 or between BEG and END.")
3084 Lisp_Object beg
, end
;
3087 Lisp_Object
*overlay_vec
;
3091 CHECK_NUMBER_COERCE_MARKER (beg
, 0);
3092 CHECK_NUMBER_COERCE_MARKER (end
, 0);
3095 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3097 /* Put all the overlays we want in a vector in overlay_vec.
3098 Store the length in len. */
3099 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3100 (int *) 0, (int *) 0);
3102 /* Make a list of them all. */
3103 result
= Flist (noverlays
, overlay_vec
);
3105 xfree (overlay_vec
);
3109 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3111 "Return the next position after POS where an overlay starts or ends.\n\
3112 If there are no more overlay boundaries after POS, return (point-max).")
3118 Lisp_Object
*overlay_vec
;
3122 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3125 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3127 /* Put all the overlays we want in a vector in overlay_vec.
3128 Store the length in len.
3129 endpos gets the position where the next overlay starts. */
3130 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3131 &endpos
, (int *) 0);
3133 /* If any of these overlays ends before endpos,
3134 use its ending point instead. */
3135 for (i
= 0; i
< noverlays
; i
++)
3140 oend
= OVERLAY_END (overlay_vec
[i
]);
3141 oendpos
= OVERLAY_POSITION (oend
);
3142 if (oendpos
< endpos
)
3146 xfree (overlay_vec
);
3147 return make_number (endpos
);
3150 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
3151 Sprevious_overlay_change
, 1, 1, 0,
3152 "Return the previous position before POS where an overlay starts or ends.\n\
3153 If there are no more overlay boundaries before POS, return (point-min).")
3159 Lisp_Object
*overlay_vec
;
3164 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3167 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3169 /* At beginning of buffer, we know the answer;
3170 avoid bug subtracting 1 below. */
3171 if (XINT (pos
) == BEGV
)
3174 /* Put all the overlays we want in a vector in overlay_vec.
3175 Store the length in len.
3176 prevpos gets the position of an overlay end. */
3177 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3178 (int *) 0, &prevpos
);
3180 /* If any of these overlays starts after prevpos,
3181 maybe use its starting point instead. */
3182 for (i
= 0; i
< noverlays
; i
++)
3187 ostart
= OVERLAY_START (overlay_vec
[i
]);
3188 ostartpos
= OVERLAY_POSITION (ostart
);
3189 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
3190 prevpos
= ostartpos
;
3193 /* If any overlay ends at pos, consider its starting point too. */
3194 for (tail
= current_buffer
->overlays_before
;
3196 tail
= XCONS (tail
)->cdr
)
3198 Lisp_Object overlay
, ostart
;
3201 overlay
= XCONS (tail
)->car
;
3203 ostart
= OVERLAY_START (overlay
);
3204 ostartpos
= OVERLAY_POSITION (ostart
);
3205 if (ostartpos
> prevpos
&& ostartpos
< XINT (pos
))
3206 prevpos
= ostartpos
;
3209 xfree (overlay_vec
);
3210 return make_number (prevpos
);
3213 /* These functions are for debugging overlays. */
3215 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
3216 "Return a pair of lists giving all the overlays of the current buffer.\n\
3217 The car has all the overlays before the overlay center;\n\
3218 the cdr has all the overlays after the overlay center.\n\
3219 Recentering overlays moves overlays between these lists.\n\
3220 The lists you get are copies, so that changing them has no effect.\n\
3221 However, the overlays you get are the real objects that the buffer uses.")
3224 Lisp_Object before
, after
;
3225 before
= current_buffer
->overlays_before
;
3227 before
= Fcopy_sequence (before
);
3228 after
= current_buffer
->overlays_after
;
3230 after
= Fcopy_sequence (after
);
3232 return Fcons (before
, after
);
3235 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
3236 "Recenter the overlays of the current buffer around position POS.")
3240 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
3242 recenter_overlay_lists (current_buffer
, XINT (pos
));
3246 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
3247 "Get the property of overlay OVERLAY with property name PROP.")
3249 Lisp_Object overlay
, prop
;
3251 Lisp_Object plist
, fallback
;
3253 CHECK_OVERLAY (overlay
, 0);
3257 for (plist
= XOVERLAY (overlay
)->plist
;
3258 CONSP (plist
) && CONSP (XCONS (plist
)->cdr
);
3259 plist
= XCONS (XCONS (plist
)->cdr
)->cdr
)
3261 if (EQ (XCONS (plist
)->car
, prop
))
3262 return XCONS (XCONS (plist
)->cdr
)->car
;
3263 else if (EQ (XCONS (plist
)->car
, Qcategory
))
3266 tem
= Fcar (Fcdr (plist
));
3268 fallback
= Fget (tem
, prop
);
3275 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
3276 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
3277 (overlay
, prop
, value
)
3278 Lisp_Object overlay
, prop
, value
;
3280 Lisp_Object tail
, buffer
;
3283 CHECK_OVERLAY (overlay
, 0);
3285 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3287 for (tail
= XOVERLAY (overlay
)->plist
;
3288 CONSP (tail
) && CONSP (XCONS (tail
)->cdr
);
3289 tail
= XCONS (XCONS (tail
)->cdr
)->cdr
)
3290 if (EQ (XCONS (tail
)->car
, prop
))
3292 changed
= !EQ (XCONS (XCONS (tail
)->cdr
)->car
, value
);
3293 XCONS (XCONS (tail
)->cdr
)->car
= value
;
3296 /* It wasn't in the list, so add it to the front. */
3297 changed
= !NILP (value
);
3298 XOVERLAY (overlay
)->plist
3299 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
3301 if (! NILP (buffer
))
3304 modify_overlay (XBUFFER (buffer
),
3305 marker_position (OVERLAY_START (overlay
)),
3306 marker_position (OVERLAY_END (overlay
)));
3307 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
3308 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
3309 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
3310 Fdelete_overlay (overlay
);
3315 /* Subroutine of report_overlay_modification. */
3317 /* Lisp vector holding overlay hook functions to call.
3318 Vector elements come in pairs.
3319 Each even-index element is a list of hook functions.
3320 The following odd-index element is the overlay they came from.
3322 Before the buffer change, we fill in this vector
3323 as we call overlay hook functions.
3324 After the buffer change, we get the functions to call from this vector.
3325 This way we always call the same functions before and after the change. */
3326 static Lisp_Object last_overlay_modification_hooks
;
3328 /* Number of elements actually used in last_overlay_modification_hooks. */
3329 static int last_overlay_modification_hooks_used
;
3331 /* Add one functionlist/overlay pair
3332 to the end of last_overlay_modification_hooks. */
3335 add_overlay_mod_hooklist (functionlist
, overlay
)
3336 Lisp_Object functionlist
, overlay
;
3338 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
3340 if (last_overlay_modification_hooks_used
== oldsize
)
3343 old
= last_overlay_modification_hooks
;
3344 last_overlay_modification_hooks
3345 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
3346 bcopy (XVECTOR (old
)->contents
,
3347 XVECTOR (last_overlay_modification_hooks
)->contents
,
3348 sizeof (Lisp_Object
) * oldsize
);
3350 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = functionlist
;
3351 XVECTOR (last_overlay_modification_hooks
)->contents
[last_overlay_modification_hooks_used
++] = overlay
;
3354 /* Run the modification-hooks of overlays that include
3355 any part of the text in START to END.
3356 If this change is an insertion, also
3357 run the insert-before-hooks of overlay starting at END,
3358 and the insert-after-hooks of overlay ending at START.
3360 This is called both before and after the modification.
3361 AFTER is nonzero when we call after the modification.
3363 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
3364 When AFTER is nonzero, they are the start position,
3365 the position after the inserted new text,
3366 and the length of deleted or replaced old text. */
3369 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
3370 Lisp_Object start
, end
;
3372 Lisp_Object arg1
, arg2
, arg3
;
3374 Lisp_Object prop
, overlay
, tail
;
3375 /* 1 if this change is an insertion. */
3376 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
3378 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
3382 GCPRO5 (overlay
, tail
, arg1
, arg2
, arg3
);
3386 /* Call the functions recorded in last_overlay_modification_hooks
3387 rather than scanning the overlays again.
3388 First copy the vector contents, in case some of these hooks
3389 do subsequent modification of the buffer. */
3390 int size
= last_overlay_modification_hooks_used
;
3391 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
3394 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
3395 copy
, size
* sizeof (Lisp_Object
));
3397 gcpro1
.nvars
= size
;
3399 for (i
= 0; i
< size
;)
3401 Lisp_Object prop
, overlay
;
3403 overlay
= copy
[i
++];
3404 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3410 /* We are being called before a change.
3411 Scan the overlays to find the functions to call. */
3412 last_overlay_modification_hooks_used
= 0;
3414 for (tail
= current_buffer
->overlays_before
;
3416 tail
= XCONS (tail
)->cdr
)
3418 int startpos
, endpos
;
3419 Lisp_Object ostart
, oend
;
3421 overlay
= XCONS (tail
)->car
;
3423 ostart
= OVERLAY_START (overlay
);
3424 oend
= OVERLAY_END (overlay
);
3425 endpos
= OVERLAY_POSITION (oend
);
3426 if (XFASTINT (start
) > endpos
)
3428 startpos
= OVERLAY_POSITION (ostart
);
3429 if (insertion
&& (XFASTINT (start
) == startpos
3430 || XFASTINT (end
) == startpos
))
3432 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3435 /* Copy TAIL in case the hook recenters the overlay lists. */
3437 tail
= Fcopy_sequence (tail
);
3439 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3442 if (insertion
&& (XFASTINT (start
) == endpos
3443 || XFASTINT (end
) == endpos
))
3445 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3449 tail
= Fcopy_sequence (tail
);
3451 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3454 /* Test for intersecting intervals. This does the right thing
3455 for both insertion and deletion. */
3456 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3458 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3462 tail
= Fcopy_sequence (tail
);
3464 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3470 for (tail
= current_buffer
->overlays_after
;
3472 tail
= XCONS (tail
)->cdr
)
3474 int startpos
, endpos
;
3475 Lisp_Object ostart
, oend
;
3477 overlay
= XCONS (tail
)->car
;
3479 ostart
= OVERLAY_START (overlay
);
3480 oend
= OVERLAY_END (overlay
);
3481 startpos
= OVERLAY_POSITION (ostart
);
3482 endpos
= OVERLAY_POSITION (oend
);
3483 if (XFASTINT (end
) < startpos
)
3485 if (insertion
&& (XFASTINT (start
) == startpos
3486 || XFASTINT (end
) == startpos
))
3488 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
3492 tail
= Fcopy_sequence (tail
);
3494 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3497 if (insertion
&& (XFASTINT (start
) == endpos
3498 || XFASTINT (end
) == endpos
))
3500 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
3504 tail
= Fcopy_sequence (tail
);
3506 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3509 /* Test for intersecting intervals. This does the right thing
3510 for both insertion and deletion. */
3511 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
3513 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
3517 tail
= Fcopy_sequence (tail
);
3519 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
3528 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
3529 Lisp_Object list
, overlay
;
3531 Lisp_Object arg1
, arg2
, arg3
;
3533 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3535 GCPRO4 (list
, arg1
, arg2
, arg3
);
3537 add_overlay_mod_hooklist (list
, overlay
);
3539 while (!NILP (list
))
3542 call4 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
3544 call5 (Fcar (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
3550 /* Delete any zero-sized overlays at position POS, if the `evaporate'
3553 evaporate_overlays (pos
)
3556 Lisp_Object tail
, overlay
, hit_list
;
3559 if (pos
<= XFASTINT (current_buffer
->overlay_center
))
3560 for (tail
= current_buffer
->overlays_before
; CONSP (tail
);
3561 tail
= XCONS (tail
)->cdr
)
3564 overlay
= XCONS (tail
)->car
;
3565 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3568 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
3569 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3570 hit_list
= Fcons (overlay
, hit_list
);
3573 for (tail
= current_buffer
->overlays_after
; CONSP (tail
);
3574 tail
= XCONS (tail
)->cdr
)
3577 overlay
= XCONS (tail
)->car
;
3578 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3581 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
3582 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3583 hit_list
= Fcons (overlay
, hit_list
);
3585 for (; CONSP (hit_list
); hit_list
= XCONS (hit_list
)->cdr
)
3586 Fdelete_overlay (XCONS (hit_list
)->car
);
3589 /* Somebody has tried to store a value with an unacceptable type
3590 into the buffer-local slot with offset OFFSET. */
3592 buffer_slot_type_mismatch (offset
)
3597 sym
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
);
3598 switch (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
)))
3600 case Lisp_Int
: type_name
= "integers"; break;
3601 case Lisp_String
: type_name
= "strings"; break;
3602 case Lisp_Symbol
: type_name
= "symbols"; break;
3607 error ("only %s should be stored in the buffer-local variable %s",
3608 type_name
, XSYMBOL (sym
)->name
->data
);
3613 register Lisp_Object tem
;
3615 buffer_permanent_local_flags
= 0;
3617 /* Make sure all markable slots in buffer_defaults
3618 are initialized reasonably, so mark_buffer won't choke. */
3619 reset_buffer (&buffer_defaults
);
3620 reset_buffer_local_variables (&buffer_defaults
, 1);
3621 reset_buffer (&buffer_local_symbols
);
3622 reset_buffer_local_variables (&buffer_local_symbols
, 1);
3623 /* Prevent GC from getting confused. */
3624 buffer_defaults
.text
= &buffer_defaults
.own_text
;
3625 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
3626 #ifdef USE_TEXT_PROPERTIES
3627 BUF_INTERVALS (&buffer_defaults
) = 0;
3628 BUF_INTERVALS (&buffer_local_symbols
) = 0;
3630 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
3631 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
3633 /* Set up the default values of various buffer slots. */
3634 /* Must do these before making the first buffer! */
3636 /* real setup is done in loaddefs.el */
3637 buffer_defaults
.mode_line_format
= build_string ("%-");
3638 buffer_defaults
.abbrev_mode
= Qnil
;
3639 buffer_defaults
.overwrite_mode
= Qnil
;
3640 buffer_defaults
.case_fold_search
= Qt
;
3641 buffer_defaults
.auto_fill_function
= Qnil
;
3642 buffer_defaults
.selective_display
= Qnil
;
3644 buffer_defaults
.selective_display_ellipses
= Qt
;
3646 buffer_defaults
.abbrev_table
= Qnil
;
3647 buffer_defaults
.display_table
= Qnil
;
3648 buffer_defaults
.undo_list
= Qnil
;
3649 buffer_defaults
.mark_active
= Qnil
;
3650 buffer_defaults
.file_format
= Qnil
;
3651 buffer_defaults
.overlays_before
= Qnil
;
3652 buffer_defaults
.overlays_after
= Qnil
;
3653 XSETFASTINT (buffer_defaults
.overlay_center
, BEG
);
3655 XSETFASTINT (buffer_defaults
.tab_width
, 8);
3656 buffer_defaults
.truncate_lines
= Qnil
;
3657 buffer_defaults
.ctl_arrow
= Qt
;
3658 buffer_defaults
.direction_reversed
= Qnil
;
3661 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
3663 buffer_defaults
.enable_multibyte_characters
= Qt
;
3664 buffer_defaults
.buffer_file_coding_system
= Qnil
;
3665 XSETFASTINT (buffer_defaults
.fill_column
, 70);
3666 XSETFASTINT (buffer_defaults
.left_margin
, 0);
3667 buffer_defaults
.cache_long_line_scans
= Qnil
;
3668 buffer_defaults
.file_truename
= Qnil
;
3669 XSETFASTINT (buffer_defaults
.display_count
, 0);
3671 /* Assign the local-flags to the slots that have default values.
3672 The local flag is a bit that is used in the buffer
3673 to say that it has its own local value for the slot.
3674 The local flag bits are in the local_var_flags slot of the buffer. */
3676 /* Nothing can work if this isn't true */
3677 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
3679 /* 0 means not a lisp var, -1 means always local, else mask */
3680 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
3681 XSETINT (buffer_local_flags
.filename
, -1);
3682 XSETINT (buffer_local_flags
.directory
, -1);
3683 XSETINT (buffer_local_flags
.backed_up
, -1);
3684 XSETINT (buffer_local_flags
.save_length
, -1);
3685 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
3686 XSETINT (buffer_local_flags
.read_only
, -1);
3687 XSETINT (buffer_local_flags
.major_mode
, -1);
3688 XSETINT (buffer_local_flags
.mode_name
, -1);
3689 XSETINT (buffer_local_flags
.undo_list
, -1);
3690 XSETINT (buffer_local_flags
.mark_active
, -1);
3691 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
3692 XSETINT (buffer_local_flags
.file_truename
, -1);
3693 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
3694 XSETINT (buffer_local_flags
.file_format
, -1);
3695 XSETINT (buffer_local_flags
.display_count
, -1);
3697 XSETFASTINT (buffer_local_flags
.mode_line_format
, 1);
3698 XSETFASTINT (buffer_local_flags
.abbrev_mode
, 2);
3699 XSETFASTINT (buffer_local_flags
.overwrite_mode
, 4);
3700 XSETFASTINT (buffer_local_flags
.case_fold_search
, 8);
3701 XSETFASTINT (buffer_local_flags
.auto_fill_function
, 0x10);
3702 XSETFASTINT (buffer_local_flags
.selective_display
, 0x20);
3704 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, 0x40);
3706 XSETFASTINT (buffer_local_flags
.tab_width
, 0x80);
3707 XSETFASTINT (buffer_local_flags
.truncate_lines
, 0x100);
3708 XSETFASTINT (buffer_local_flags
.ctl_arrow
, 0x200);
3709 XSETFASTINT (buffer_local_flags
.fill_column
, 0x400);
3710 XSETFASTINT (buffer_local_flags
.left_margin
, 0x800);
3711 XSETFASTINT (buffer_local_flags
.abbrev_table
, 0x1000);
3712 XSETFASTINT (buffer_local_flags
.display_table
, 0x2000);
3714 XSETFASTINT (buffer_local_flags
.buffer_file_type
, 0x4000);
3715 /* Make this one a permanent local. */
3716 buffer_permanent_local_flags
|= 0x4000;
3718 XSETFASTINT (buffer_local_flags
.syntax_table
, 0x8000);
3719 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, 0x10000);
3720 XSETFASTINT (buffer_local_flags
.category_table
, 0x20000);
3721 XSETFASTINT (buffer_local_flags
.direction_reversed
, 0x40000);
3722 XSETFASTINT (buffer_local_flags
.enable_multibyte_characters
, 0x80000);
3723 /* Make this one a permanent local. */
3724 buffer_permanent_local_flags
|= 0x80000;
3725 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, 0x100000);
3726 /* Make this one a permanent local. */
3727 buffer_permanent_local_flags
|= 0x100000;
3729 Vbuffer_alist
= Qnil
;
3733 QSFundamental
= build_string ("Fundamental");
3735 Qfundamental_mode
= intern ("fundamental-mode");
3736 buffer_defaults
.major_mode
= Qfundamental_mode
;
3738 Qmode_class
= intern ("mode-class");
3740 Qprotected_field
= intern ("protected-field");
3742 Qpermanent_local
= intern ("permanent-local");
3744 Qkill_buffer_hook
= intern ("kill-buffer-hook");
3746 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
3748 /* super-magic invisible buffer */
3749 Vbuffer_alist
= Qnil
;
3751 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3756 char buf
[MAXPATHLEN
+1];
3758 struct stat dotstat
, pwdstat
;
3762 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
3764 /* If PWD is accurate, use it instead of calling getwd. This is faster
3765 when PWD is right, and may avoid a fatal error. */
3766 if ((pwd
= getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd
)
3767 && stat (pwd
, &pwdstat
) == 0
3768 && stat (".", &dotstat
) == 0
3769 && dotstat
.st_ino
== pwdstat
.st_ino
3770 && dotstat
.st_dev
== pwdstat
.st_dev
3771 && strlen (pwd
) < MAXPATHLEN
)
3774 else if (getcwd (buf
, MAXPATHLEN
+1) == 0)
3775 fatal ("`getcwd' failed: %s\n", strerror (errno
));
3777 else if (getwd (buf
) == 0)
3778 fatal ("`getwd' failed: %s\n", buf
);
3782 /* Maybe this should really use some standard subroutine
3783 whose definition is filename syntax dependent. */
3785 if (!(IS_DIRECTORY_SEP (buf
[rc
- 1])))
3787 buf
[rc
] = DIRECTORY_SEP
;
3790 #endif /* not VMS */
3792 current_buffer
->directory
= build_string (buf
);
3794 /* Add /: to the front of the name
3795 if it would otherwise be treated as magic. */
3796 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
3798 /* If the default dir is just /, TEMP is non-nil
3799 because of the ange-ftp completion handler.
3800 However, it is not necessary to turn / into /:/.
3801 So avoid doing that. */
3802 && strcmp ("/", XSTRING (current_buffer
->directory
)->data
))
3803 current_buffer
->directory
3804 = concat2 (build_string ("/:"), current_buffer
->directory
);
3806 temp
= get_minibuffer (0);
3807 XBUFFER (temp
)->directory
= current_buffer
->directory
;
3810 /* initialize the buffer routines */
3813 extern Lisp_Object Qdisabled
;
3815 staticpro (&last_overlay_modification_hooks
);
3816 last_overlay_modification_hooks
3817 = Fmake_vector (make_number (10), Qnil
);
3819 staticpro (&Vbuffer_defaults
);
3820 staticpro (&Vbuffer_local_symbols
);
3821 staticpro (&Qfundamental_mode
);
3822 staticpro (&Qmode_class
);
3823 staticpro (&QSFundamental
);
3824 staticpro (&Vbuffer_alist
);
3825 staticpro (&Qprotected_field
);
3826 staticpro (&Qpermanent_local
);
3827 staticpro (&Qkill_buffer_hook
);
3828 Qoverlayp
= intern ("overlayp");
3829 staticpro (&Qoverlayp
);
3830 Qevaporate
= intern ("evaporate");
3831 staticpro (&Qevaporate
);
3832 Qmodification_hooks
= intern ("modification-hooks");
3833 staticpro (&Qmodification_hooks
);
3834 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
3835 staticpro (&Qinsert_in_front_hooks
);
3836 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
3837 staticpro (&Qinsert_behind_hooks
);
3838 Qget_file_buffer
= intern ("get-file-buffer");
3839 staticpro (&Qget_file_buffer
);
3840 Qpriority
= intern ("priority");
3841 staticpro (&Qpriority
);
3842 Qwindow
= intern ("window");
3843 staticpro (&Qwindow
);
3844 Qbefore_string
= intern ("before-string");
3845 staticpro (&Qbefore_string
);
3846 Qafter_string
= intern ("after-string");
3847 staticpro (&Qafter_string
);
3848 Qfirst_change_hook
= intern ("first-change-hook");
3849 staticpro (&Qfirst_change_hook
);
3850 Qbefore_change_functions
= intern ("before-change-functions");
3851 staticpro (&Qbefore_change_functions
);
3852 Qafter_change_functions
= intern ("after-change-functions");
3853 staticpro (&Qafter_change_functions
);
3855 Fput (Qprotected_field
, Qerror_conditions
,
3856 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
3857 Fput (Qprotected_field
, Qerror_message
,
3858 build_string ("Attempt to modify a protected field"));
3860 /* All these use DEFVAR_LISP_NOPRO because the slots in
3861 buffer_defaults will all be marked via Vbuffer_defaults. */
3863 DEFVAR_LISP_NOPRO ("default-mode-line-format",
3864 &buffer_defaults
.mode_line_format
,
3865 "Default value of `mode-line-format' for buffers that don't override it.\n\
3866 This is the same as (default-value 'mode-line-format).");
3868 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
3869 &buffer_defaults
.abbrev_mode
,
3870 "Default value of `abbrev-mode' for buffers that do not override it.\n\
3871 This is the same as (default-value 'abbrev-mode).");
3873 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
3874 &buffer_defaults
.ctl_arrow
,
3875 "Default value of `ctl-arrow' for buffers that do not override it.\n\
3876 This is the same as (default-value 'ctl-arrow).");
3878 DEFVAR_LISP_NOPRO ("default-direction-reversed",
3879 &buffer_defaults
.direction_reversed
,
3880 "Default value of `direction_reversed' for buffers that do not override it.\n\
3881 This is the same as (default-value 'direction-reversed).");
3883 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
3884 &buffer_defaults
.enable_multibyte_characters
,
3885 "Default value of `enable-multibyte-characters' for buffers not overriding it.\n\
3886 This is the same as (default-value 'enable-multibyte-characters).");
3888 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
3889 &buffer_defaults
.buffer_file_coding_system
,
3890 "Default value of `buffer-file-coding-system' for buffers not overriding it.\n\
3891 This is the same as (default-value 'buffer-file-coding-system).");
3893 DEFVAR_LISP_NOPRO ("default-truncate-lines",
3894 &buffer_defaults
.truncate_lines
,
3895 "Default value of `truncate-lines' for buffers that do not override it.\n\
3896 This is the same as (default-value 'truncate-lines).");
3898 DEFVAR_LISP_NOPRO ("default-fill-column",
3899 &buffer_defaults
.fill_column
,
3900 "Default value of `fill-column' for buffers that do not override it.\n\
3901 This is the same as (default-value 'fill-column).");
3903 DEFVAR_LISP_NOPRO ("default-left-margin",
3904 &buffer_defaults
.left_margin
,
3905 "Default value of `left-margin' for buffers that do not override it.\n\
3906 This is the same as (default-value 'left-margin).");
3908 DEFVAR_LISP_NOPRO ("default-tab-width",
3909 &buffer_defaults
.tab_width
,
3910 "Default value of `tab-width' for buffers that do not override it.\n\
3911 This is the same as (default-value 'tab-width).");
3913 DEFVAR_LISP_NOPRO ("default-case-fold-search",
3914 &buffer_defaults
.case_fold_search
,
3915 "Default value of `case-fold-search' for buffers that don't override it.\n\
3916 This is the same as (default-value 'case-fold-search).");
3919 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
3920 &buffer_defaults
.buffer_file_type
,
3921 "Default file type for buffers that do not override it.\n\
3922 This is the same as (default-value 'buffer-file-type).\n\
3923 The file type is nil for text, t for binary.");
3926 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
3929 /* This doc string is too long for cpp; cpp dies if it isn't in a comment.
3930 But make-docfile finds it!
3931 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format,
3933 "Template for displaying mode line for current buffer.\n\
3934 Each buffer has its own value of this variable.\n\
3935 Value may be a string, a symbol or a list or cons cell.\n\
3936 For a symbol, its value is used (but it is ignored if t or nil).\n\
3937 A string appearing directly as the value of a symbol is processed verbatim\n\
3938 in that the %-constructs below are not recognized.\n\
3939 For a list whose car is a symbol, the symbol's value is taken,\n\
3940 and if that is non-nil, the cadr of the list is processed recursively.\n\
3941 Otherwise, the caddr of the list (if there is one) is processed.\n\
3942 For a list whose car is a string or list, each element is processed\n\
3943 recursively and the results are effectively concatenated.\n\
3944 For a list whose car is an integer, the cdr of the list is processed\n\
3945 and padded (if the number is positive) or truncated (if negative)\n\
3946 to the width specified by that number.\n\
3947 A string is printed verbatim in the mode line except for %-constructs:\n\
3948 (%-constructs are allowed when the string is the entire mode-line-format\n\
3949 or when it is found in a cons-cell or a list)\n\
3950 %b -- print buffer name. %f -- print visited file name.\n\
3951 %F -- print frame name.\n\
3952 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\
3953 % means buffer is read-only and * means it is modified.\n\
3954 For a modified read-only buffer, %* gives % and %+ gives *.\n\
3955 %s -- print process status. %l -- print the current line number.\n\
3956 %c -- print the current column number (this makes editing slower).\n\
3957 To make the column number update correctly in all cases,\n\
3958 `column-number-mode' must be non-nil.\n\
3959 %p -- print percent of buffer above top of window, or Top, Bot or All.\n\
3960 %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\
3961 or print Bottom or All.\n\
3962 %n -- print Narrow if appropriate.\n\
3963 %t -- print T if file is text, B if binary.\n\
3964 %[ -- print one [ for each recursive editing level. %] similar.\n\
3965 %% -- print %. %- -- print infinitely many dashes.\n\
3966 Decimal digits after the % specify field width to which to pad.");
3969 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
3970 "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\
3971 nil here means use current buffer's major mode.");
3973 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
3974 make_number (Lisp_Symbol
),
3975 "Symbol for current buffer's major mode.");
3977 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
3978 make_number (Lisp_String
),
3979 "Pretty name of current buffer's major mode (a string).");
3981 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
3982 "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\
3983 Automatically becomes buffer-local when set in any fashion.");
3985 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
3987 "*Non-nil if searches should ignore case.\n\
3988 Automatically becomes buffer-local when set in any fashion.");
3990 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
3991 make_number (Lisp_Int
),
3992 "*Column beyond which automatic line-wrapping should happen.\n\
3993 Automatically becomes buffer-local when set in any fashion.");
3995 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
3996 make_number (Lisp_Int
),
3997 "*Column for the default indent-line-function to indent to.\n\
3998 Linefeed indents to this column in Fundamental mode.\n\
3999 Automatically becomes buffer-local when set in any fashion.");
4001 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
4002 make_number (Lisp_Int
),
4003 "*Distance between tab stops (for display of tab characters), in columns.\n\
4004 Automatically becomes buffer-local when set in any fashion.");
4006 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
4007 "*Non-nil means display control chars with uparrow.\n\
4008 A value of nil means use backslash and octal digits.\n\
4009 Automatically becomes buffer-local when set in any fashion.\n\
4010 This variable does not apply to characters whose display is specified\n\
4011 in the current display table (if there is one).");
4013 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
4014 ¤t_buffer
->enable_multibyte_characters
, Qnil
,
4015 "*Non-nil means the buffer contents are regarded as multi-byte form\n\
4016 of characters, not a binary code. This affects the display, file I/O,\n\
4017 and behaviors of various editing commands.");
4019 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
4020 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
4021 "Coding system to be used for encoding the buffer contents on saving.\n\
4022 If it is nil, the buffer is saved without any code conversion unless\n\
4023 some coding system is specified in file-coding-system-alist\n\
4024 for the buffer file.\n\
4026 This variable is never applied to a way of decoding\n\
4027 a file while reading it.");
4029 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
4031 "*Non-nil means lines in the buffer are displayed right to left.");
4033 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
4034 "*Non-nil means do not display continuation lines;\n\
4035 give each line of text one screen line.\n\
4036 Automatically becomes buffer-local when set in any fashion.\n\
4038 Note that this is overridden by the variable\n\
4039 `truncate-partial-width-windows' if that variable is non-nil\n\
4040 and this buffer is not full-frame width.");
4043 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
4045 "Non-nil if the visited file is a binary file.\n\
4046 This variable is meaningful on MS-DOG and Windows NT.\n\
4047 On those systems, it is automatically local in every buffer.\n\
4048 On other systems, this variable is normally always nil.");
4051 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
4052 make_number (Lisp_String
),
4053 "Name of default directory of current buffer. Should end with slash.\n\
4054 Each buffer has its own value of this variable.");
4056 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
4058 "Function called (if non-nil) to perform auto-fill.\n\
4059 It is called after self-inserting a space or newline.\n\
4060 Each buffer has its own value of this variable.\n\
4061 NOTE: This variable is not a hook;\n\
4062 its value may not be a list of functions.");
4064 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
4065 make_number (Lisp_String
),
4066 "Name of file visited in current buffer, or nil if not visiting a file.\n\
4067 Each buffer has its own value of this variable.");
4069 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
4070 make_number (Lisp_String
),
4071 "Abbreviated truename of file visited in current buffer, or nil if none.\n\
4072 The truename of a file is calculated by `file-truename'\n\
4073 and then abbreviated with `abbreviate-file-name'.\n\
4074 Each buffer has its own value of this variable.");
4076 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
4077 ¤t_buffer
->auto_save_file_name
,
4078 make_number (Lisp_String
),
4079 "Name of file for auto-saving current buffer,\n\
4080 or nil if buffer should not be auto-saved.\n\
4081 Each buffer has its own value of this variable.");
4083 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
4084 "Non-nil if this buffer is read-only.\n\
4085 Each buffer has its own value of this variable.");
4087 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
4088 "Non-nil if this buffer's file has been backed up.\n\
4089 Backing up is done before the first time the file is saved.\n\
4090 Each buffer has its own value of this variable.");
4092 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
4093 make_number (Lisp_Int
),
4094 "Length of current buffer when last read in, saved or auto-saved.\n\
4096 Each buffer has its own value of this variable.");
4098 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
4100 "Non-nil enables selective display:\n\
4101 Integer N as value means display only lines\n\
4102 that start with less than n columns of space.\n\
4103 A value of t means, after a ^M, all the rest of the line is invisible.\n\
4104 Then ^M's in the file are written into files as newlines.\n\n\
4105 Automatically becomes buffer-local when set in any fashion.");
4108 DEFVAR_PER_BUFFER ("selective-display-ellipses",
4109 ¤t_buffer
->selective_display_ellipses
,
4111 "t means display ... on previous line when a line is invisible.\n\
4112 Automatically becomes buffer-local when set in any fashion.");
4115 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
4116 "Non-nil if self-insertion should replace existing text.\n\
4117 The value should be one of `overwrite-mode-textual',\n\
4118 `overwrite-mode-binary', or nil.\n\
4119 If it is `overwrite-mode-textual', self-insertion still\n\
4120 inserts at the end of a line, and inserts when point is before a tab,\n\
4121 until the tab is filled in.\n\
4122 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
4123 Automatically becomes buffer-local when set in any fashion.");
4125 #if 0 /* The doc string is too long for some compilers,
4126 but make-docfile can find it in this comment. */
4127 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4129 "Display table that controls display of the contents of current buffer.\n\
4130 Automatically becomes buffer-local when set in any fashion.\n\
4131 The display table is a char-table created with `make-display-table'.\n\
4132 The ordinary char-table elements control how to display each possible text\n\
4133 character. Each value should be a vector of characters or nil;\n\
4134 nil means display the character in the default fashion.\n\
4135 There are six extra slots to control the display of\n\
4136 the end of a truncated screen line (extra-slot 0, a single character);\n\
4137 the end of a continued line (extra-slot 1, a single character);\n\
4138 the escape character used to display character codes in octal\n\
4139 (extra-slot 2, a single character);\n\
4140 the character used as an arrow for control characters (extra-slot 3,\n\
4141 a single character);\n\
4142 the decoration indicating the presence of invisible lines (extra-slot 4,\n\
4143 a vector of characters);\n\
4144 the character used to draw the border between side-by-side windows\n\
4145 (extra-slot 5, a single character).\n\
4146 See also the functions `display-table-slot' and `set-display-table-slot'.\n\
4147 If this variable is nil, the value of `standard-display-table' is used.\n\
4148 Each window can have its own, overriding display table.");
4150 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
4153 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
4156 DEFVAR_LISP ("before-change-function", &Vbefore_change_function
,
4157 "If non-nil, a function to call before each text change (obsolete).\n\
4158 Two arguments are passed to the function: the positions of\n\
4159 the beginning and end of the range of old text to be changed.\n\
4160 \(For an insertion, the beginning and end are at the same place.)\n\
4161 No information is given about the length of the text after the change.\n\
4163 Buffer changes made while executing the `before-change-function'\n\
4164 don't call any before-change or after-change functions.\n\
4165 That's because these variables are temporarily set to nil.\n\
4166 As a result, a hook function cannot straightforwardly alter the value of\n\
4167 these variables. See the Emacs Lisp manual for a way of\n\
4168 accomplishing an equivalent result by using other variables.\n\n\
4169 This variable is obsolete; use `before-change-functions' instead.");
4170 Vbefore_change_function
= Qnil
;
4172 DEFVAR_LISP ("after-change-function", &Vafter_change_function
,
4173 "If non-nil, a Function to call after each text change (obsolete).\n\
4174 Three arguments are passed to the function: the positions of\n\
4175 the beginning and end of the range of changed text,\n\
4176 and the length of the pre-change text replaced by that range.\n\
4177 \(For an insertion, the pre-change length is zero;\n\
4178 for a deletion, that length is the number of bytes deleted,\n\
4179 and the post-change beginning and end are at the same place.)\n\
4181 Buffer changes made while executing the `after-change-function'\n\
4182 don't call any before-change or after-change functions.\n\
4183 That's because these variables are temporarily set to nil.\n\
4184 As a result, a hook function cannot straightforwardly alter the value of\n\
4185 these variables. See the Emacs Lisp manual for a way of\n\
4186 accomplishing an equivalent result by using other variables.\n\n\
4187 This variable is obsolete; use `after-change-functions' instead.");
4188 Vafter_change_function
= Qnil
;
4190 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
4191 "List of functions to call before each text change.\n\
4192 Two arguments are passed to each function: the positions of\n\
4193 the beginning and end of the range of old text to be changed.\n\
4194 \(For an insertion, the beginning and end are at the same place.)\n\
4195 No information is given about the length of the text after the change.\n\
4197 Buffer changes made while executing the `before-change-functions'\n\
4198 don't call any before-change or after-change functions.\n\
4199 That's because these variables are temporarily set to nil.\n\
4200 As a result, a hook function cannot straightforwardly alter the value of\n\
4201 these variables. See the Emacs Lisp manual for a way of\n\
4202 accomplishing an equivalent result by using other variables.");
4203 Vbefore_change_functions
= Qnil
;
4205 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
4206 "List of function to call after each text change.\n\
4207 Three arguments are passed to each function: the positions of\n\
4208 the beginning and end of the range of changed text,\n\
4209 and the length in bytes of the pre-change text replaced by that range.\n\
4210 \(For an insertion, the pre-change length is zero;\n\
4211 for a deletion, that length is the number of bytes deleted,\n\
4212 and the post-change beginning and end are at the same place.)\n\
4214 Buffer changes made while executing the `after-change-functions'\n\
4215 don't call any before-change or after-change functions.\n\
4216 That's because these variables are temporarily set to nil.\n\
4217 As a result, a hook function cannot straightforwardly alter the value of\n\
4218 these variables. See the Emacs Lisp manual for a way of\n\
4219 accomplishing an equivalent result by using other variables.");
4221 Vafter_change_functions
= Qnil
;
4223 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
4224 "A list of functions to call before changing a buffer which is unmodified.\n\
4225 The functions are run using the `run-hooks' function.");
4226 Vfirst_change_hook
= Qnil
;
4228 #if 0 /* The doc string is too long for some compilers,
4229 but make-docfile can find it in this comment. */
4230 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4231 "List of undo entries in current buffer.\n\
4232 Recent changes come first; older changes follow newer.\n\
4234 An entry (BEG . END) represents an insertion which begins at\n\
4235 position BEG and ends at position END.\n\
4237 An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
4238 from (abs POSITION). If POSITION is positive, point was at the front\n\
4239 of the text being deleted; if negative, point was at the end.\n\
4241 An entry (t HIGH . LOW) indicates that the buffer previously had\n\
4242 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\
4243 of the visited file's modification time, as of that time. If the\n\
4244 modification time of the most recent save is different, this entry is\n\
4247 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
4248 was modified between BEG and END. PROPERTY is the property name,\n\
4249 and VALUE is the old value.\n\
4251 An entry (MARKER . DISTANCE) indicates that the marker MARKER\n\
4252 was adjusted in position by the offset DISTANCE (an integer).\n\
4254 An entry of the form POSITION indicates that point was at the buffer\n\
4255 location given by the integer. Undoing an entry of this form places\n\
4256 point at POSITION.\n\
4258 nil marks undo boundaries. The undo command treats the changes\n\
4259 between two undo boundaries as a single step to be undone.\n\
4261 If the value of the variable is t, undo information is not recorded.");
4263 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
4266 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
4267 "Non-nil means the mark and region are currently active in this buffer.\n\
4268 Automatically local in all buffers.");
4270 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
4271 "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\
4272 This variable is buffer-local, in all buffers.\n\
4274 Normally, the line-motion functions work by scanning the buffer for\n\
4275 newlines. Columnar operations (like move-to-column and\n\
4276 compute-motion) also work by scanning the buffer, summing character\n\
4277 widths as they go. This works well for ordinary text, but if the\n\
4278 buffer's lines are very long (say, more than 500 characters), these\n\
4279 motion functions will take longer to execute. Emacs may also take\n\
4280 longer to update the display.\n\
4282 If cache-long-line-scans is non-nil, these motion functions cache the\n\
4283 results of their scans, and consult the cache to avoid rescanning\n\
4284 regions of the buffer until the text is modified. The caches are most\n\
4285 beneficial when they prevent the most searching---that is, when the\n\
4286 buffer contains long lines and large regions of characters with the\n\
4287 same, fixed screen width.\n\
4289 When cache-long-line-scans is non-nil, processing short lines will\n\
4290 become slightly slower (because of the overhead of consulting the\n\
4291 cache), and the caches will use memory roughly proportional to the\n\
4292 number of newlines and characters whose screen width varies.\n\
4294 The caches require no explicit maintenance; their accuracy is\n\
4295 maintained internally by the Emacs primitives. Enabling or disabling\n\
4296 the cache should not affect the behavior of any of the motion\n\
4297 functions; it should only affect their performance.");
4299 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
4300 "Value of point before the last series of scroll operations, or nil.");
4302 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
4303 "List of formats to use when saving this buffer.\n\
4304 Formats are defined by `format-alist'. This variable is\n\
4305 set when a file is visited. Automatically local in all buffers.");
4307 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
4308 ¤t_buffer
->invisibility_spec
, Qnil
,
4309 "Invisibility spec of this buffer.\n\
4310 The default is t, which means that text is invisible\n\
4311 if it has a non-nil `invisible' property.\n\
4312 If the value is a list, a text character is invisible if its `invisible'\n\
4313 property is an element in that list.\n\
4314 If an element is a cons cell of the form (PROP . ELLIPSIS),\n\
4315 then characters with property value PROP are invisible,\n\
4316 and they have an ellipsis as well if ELLIPSIS is non-nil.");
4318 DEFVAR_PER_BUFFER ("buffer-display-count",
4319 ¤t_buffer
->display_count
, Qnil
,
4320 "A number incremented each time the buffer is displayed in a window.");
4322 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
4323 "*Non-nil means deactivate the mark when the buffer contents change.\n\
4324 Non-nil also enables highlighting of the region whenever the mark is active.\n\
4325 The variable `highlight-nonselected-windows' controls whether to highlight\n\
4326 all windows or just the selected window.");
4327 Vtransient_mark_mode
= Qnil
;
4329 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
4330 "*Non-nil means disregard read-only status of buffers or characters.\n\
4331 If the value is t, disregard `buffer-read-only' and all `read-only'\n\
4332 text properties. If the value is a list, disregard `buffer-read-only'\n\
4333 and disregard a `read-only' text property if the property value\n\
4334 is a member of the list.");
4335 Vinhibit_read_only
= Qnil
;
4337 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
4338 "List of functions called with no args to query before killing a buffer.");
4339 Vkill_buffer_query_functions
= Qnil
;
4341 defsubr (&Sbuffer_live_p
);
4342 defsubr (&Sbuffer_list
);
4343 defsubr (&Sget_buffer
);
4344 defsubr (&Sget_file_buffer
);
4345 defsubr (&Sget_buffer_create
);
4346 defsubr (&Smake_indirect_buffer
);
4347 defsubr (&Sgenerate_new_buffer_name
);
4348 defsubr (&Sbuffer_name
);
4349 /*defsubr (&Sbuffer_number);*/
4350 defsubr (&Sbuffer_file_name
);
4351 defsubr (&Sbuffer_base_buffer
);
4352 defsubr (&Sbuffer_local_variables
);
4353 defsubr (&Sbuffer_modified_p
);
4354 defsubr (&Sset_buffer_modified_p
);
4355 defsubr (&Sbuffer_modified_tick
);
4356 defsubr (&Srename_buffer
);
4357 defsubr (&Sother_buffer
);
4358 defsubr (&Sbuffer_disable_undo
);
4359 defsubr (&Sbuffer_enable_undo
);
4360 defsubr (&Skill_buffer
);
4361 defsubr (&Serase_buffer
);
4362 defsubr (&Sset_buffer_major_mode
);
4363 defsubr (&Sswitch_to_buffer
);
4364 defsubr (&Spop_to_buffer
);
4365 defsubr (&Scurrent_buffer
);
4366 defsubr (&Sset_buffer
);
4367 defsubr (&Sbarf_if_buffer_read_only
);
4368 defsubr (&Sbury_buffer
);
4369 defsubr (&Skill_all_local_variables
);
4371 defsubr (&Soverlayp
);
4372 defsubr (&Smake_overlay
);
4373 defsubr (&Sdelete_overlay
);
4374 defsubr (&Smove_overlay
);
4375 defsubr (&Soverlay_start
);
4376 defsubr (&Soverlay_end
);
4377 defsubr (&Soverlay_buffer
);
4378 defsubr (&Soverlay_properties
);
4379 defsubr (&Soverlays_at
);
4380 defsubr (&Soverlays_in
);
4381 defsubr (&Snext_overlay_change
);
4382 defsubr (&Sprevious_overlay_change
);
4383 defsubr (&Soverlay_recenter
);
4384 defsubr (&Soverlay_lists
);
4385 defsubr (&Soverlay_get
);
4386 defsubr (&Soverlay_put
);
4391 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
4392 initial_define_key (control_x_map
, 'k', "kill-buffer");
4394 /* This must not be in syms_of_buffer, because Qdisabled is not
4395 initialized when that function gets called. */
4396 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);