1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994,
3 1995, 1997, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 #include <sys/types.h>
27 #include <sys/param.h>
41 #include "intervals.h"
46 #include "region-cache.h"
48 #include "blockinput.h"
53 struct buffer
*current_buffer
; /* the current buffer */
55 /* First buffer in chain of all buffers (in reverse order of creation).
56 Threaded through ->next. */
58 struct buffer
*all_buffers
;
60 /* This structure holds the default values of the buffer-local variables
61 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
62 The default value occupies the same slot in this structure
63 as an individual buffer's value occupies in that buffer.
64 Setting the default value also goes through the alist of buffers
65 and stores into each buffer that does not say it has a local value. */
67 DECL_ALIGN (struct buffer
, buffer_defaults
);
69 /* A Lisp_Object pointer to the above, used for staticpro */
71 static Lisp_Object Vbuffer_defaults
;
73 /* This structure marks which slots in a buffer have corresponding
74 default values in buffer_defaults.
75 Each such slot has a nonzero value in this structure.
76 The value has only one nonzero bit.
78 When a buffer has its own local value for a slot,
79 the entry for that slot (found in the same slot in this structure)
80 is turned on in the buffer's local_flags array.
82 If a slot in this structure is -1, then even though there may
83 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
84 and the corresponding slot in buffer_defaults is not used.
86 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
87 but there is a default value which is copied into each buffer.
89 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
90 zero, that is a bug */
92 struct buffer buffer_local_flags
;
94 /* This structure holds the names of symbols whose values may be
95 buffer-local. It is indexed and accessed in the same way as the above. */
97 DECL_ALIGN (struct buffer
, buffer_local_symbols
);
99 /* A Lisp_Object pointer to the above, used for staticpro */
100 static Lisp_Object Vbuffer_local_symbols
;
102 /* This structure holds the required types for the values in the
103 buffer-local slots. If a slot contains Qnil, then the
104 corresponding buffer slot may contain a value of any type. If a
105 slot contains an integer, then prospective values' tags must be
106 equal to that integer (except nil is always allowed).
107 When a tag does not match, the function
108 buffer_slot_type_mismatch will signal an error.
110 If a slot here contains -1, the corresponding variable is read-only. */
111 struct buffer buffer_local_types
;
113 /* Flags indicating which built-in buffer-local variables
114 are permanent locals. */
115 static char buffer_permanent_local_flags
[MAX_PER_BUFFER_VARS
];
117 /* Number of per-buffer variables used. */
119 int last_per_buffer_idx
;
121 Lisp_Object
Fset_buffer ();
122 void set_buffer_internal ();
123 void set_buffer_internal_1 ();
124 static void call_overlay_mod_hooks ();
125 static void swap_out_buffer_local_variables ();
126 static void reset_buffer_local_variables ();
128 /* Alist of all buffer names vs the buffers. */
129 /* This used to be a variable, but is no longer,
130 to prevent lossage due to user rplac'ing this alist or its elements. */
131 Lisp_Object Vbuffer_alist
;
133 /* Functions to call before and after each text change. */
134 Lisp_Object Vbefore_change_functions
;
135 Lisp_Object Vafter_change_functions
;
137 Lisp_Object Vtransient_mark_mode
;
139 /* t means ignore all read-only text properties.
140 A list means ignore such a property if its value is a member of the list.
141 Any non-nil value means ignore buffer-read-only. */
142 Lisp_Object Vinhibit_read_only
;
144 /* List of functions to call that can query about killing a buffer.
145 If any of these functions returns nil, we don't kill it. */
146 Lisp_Object Vkill_buffer_query_functions
;
147 Lisp_Object Qkill_buffer_query_functions
;
149 /* Hook run before changing a major mode. */
150 Lisp_Object Vchange_major_mode_hook
, Qchange_major_mode_hook
;
152 /* List of functions to call before changing an unmodified buffer. */
153 Lisp_Object Vfirst_change_hook
;
155 Lisp_Object Qfirst_change_hook
;
156 Lisp_Object Qbefore_change_functions
;
157 Lisp_Object Qafter_change_functions
;
158 Lisp_Object Qucs_set_table_for_input
;
160 /* If nonzero, all modification hooks are suppressed. */
161 int inhibit_modification_hooks
;
163 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
165 Lisp_Object Qprotected_field
;
167 Lisp_Object QSFundamental
; /* A string "Fundamental" */
169 Lisp_Object Qkill_buffer_hook
;
171 Lisp_Object Qget_file_buffer
;
173 Lisp_Object Qoverlayp
;
175 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
177 Lisp_Object Qmodification_hooks
;
178 Lisp_Object Qinsert_in_front_hooks
;
179 Lisp_Object Qinsert_behind_hooks
;
181 static void alloc_buffer_text
P_ ((struct buffer
*, size_t));
182 static void free_buffer_text
P_ ((struct buffer
*b
));
183 static struct Lisp_Overlay
* copy_overlays
P_ ((struct buffer
*, struct Lisp_Overlay
*));
184 static void modify_overlay
P_ ((struct buffer
*, EMACS_INT
, EMACS_INT
));
185 static Lisp_Object buffer_lisp_local_variables
P_ ((struct buffer
*));
188 /* For debugging; temporary. See set_buffer_internal. */
189 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
196 error ("No buffer named %s", SDATA (spec
));
197 error ("Invalid buffer argument");
200 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
201 doc
: /* Return non-nil if OBJECT is a buffer which has not been killed.
202 Value is nil if OBJECT is not a buffer or if it has been killed. */)
206 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
210 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
211 doc
: /* Return a list of all existing live buffers.
212 If the optional arg FRAME is a frame, we return the buffer list
213 in the proper order for that frame: the buffers in FRAME's `buffer-list'
214 frame parameter come first, followed by the rest of the buffers. */)
219 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
223 Lisp_Object framelist
, prevlist
, tail
;
228 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
229 prevlist
= Fnreverse (Fcopy_sequence (XFRAME (frame
)->buried_buffer_list
));
231 /* Remove from GENERAL any buffer that duplicates one in
232 FRAMELIST or PREVLIST. */
236 general
= Fdelq (XCAR (tail
), general
);
242 general
= Fdelq (XCAR (tail
), general
);
249 return Fnconc (3, args
);
255 /* Like Fassoc, but use Fstring_equal to compare
256 (which ignores text properties),
257 and don't ever QUIT. */
260 assoc_ignore_text_properties (key
, list
)
261 register Lisp_Object key
;
264 register Lisp_Object tail
;
265 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
267 register Lisp_Object elt
, tem
;
269 tem
= Fstring_equal (Fcar (elt
), key
);
276 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
277 doc
: /* Return the buffer named NAME (a string).
278 If there is no live buffer named NAME, return nil.
279 NAME may also be a buffer; if so, the value is that buffer. */)
281 register Lisp_Object name
;
287 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
290 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
291 doc
: /* Return the buffer visiting file FILENAME (a string).
292 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.
293 If there is no such live buffer, return nil.
294 See also `find-buffer-visiting'. */)
296 register Lisp_Object filename
;
298 register Lisp_Object tail
, buf
, tem
;
301 CHECK_STRING (filename
);
302 filename
= Fexpand_file_name (filename
, Qnil
);
304 /* If the file name has special constructs in it,
305 call the corresponding file handler. */
306 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
308 return call2 (handler
, Qget_file_buffer
, filename
);
310 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
312 buf
= Fcdr (XCAR (tail
));
313 if (!BUFFERP (buf
)) continue;
314 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
315 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
323 get_truename_buffer (filename
)
324 register Lisp_Object filename
;
326 register Lisp_Object tail
, buf
, tem
;
328 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
330 buf
= Fcdr (XCAR (tail
));
331 if (!BUFFERP (buf
)) continue;
332 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
333 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
340 /* Incremented for each buffer created, to assign the buffer number. */
343 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
344 doc
: /* Return the buffer named NAME, or create such a buffer and return it.
345 A new buffer is created if there is no live buffer named NAME.
346 If NAME starts with a space, the new buffer does not keep undo information.
347 If NAME is a buffer instead of a string, then it is the value returned.
348 The value is never nil. */)
350 register Lisp_Object name
;
352 register Lisp_Object buf
;
353 register struct buffer
*b
;
355 buf
= Fget_buffer (name
);
359 if (SCHARS (name
) == 0)
360 error ("Empty string for buffer name is not allowed");
362 b
= (struct buffer
*) allocate_buffer ();
364 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
366 /* An ordinary buffer uses its own struct buffer_text. */
367 b
->text
= &b
->own_text
;
370 BUF_GAP_SIZE (b
) = 20;
372 /* We allocate extra 1-byte at the tail and keep it always '\0' for
373 anchoring a search. */
374 alloc_buffer_text (b
, BUF_GAP_SIZE (b
) + 1);
376 if (! BUF_BEG_ADDR (b
))
377 buffer_memory_full ();
384 BUF_PT_BYTE (b
) = BEG_BYTE
;
385 BUF_GPT_BYTE (b
) = BEG_BYTE
;
386 BUF_BEGV_BYTE (b
) = BEG_BYTE
;
387 BUF_ZV_BYTE (b
) = BEG_BYTE
;
388 BUF_Z_BYTE (b
) = BEG_BYTE
;
390 BUF_CHARS_MODIFF (b
) = 1;
391 BUF_OVERLAY_MODIFF (b
) = 1;
392 BUF_SAVE_MODIFF (b
) = 1;
393 BUF_INTERVALS (b
) = 0;
394 BUF_UNCHANGED_MODIFIED (b
) = 1;
395 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = 1;
396 BUF_END_UNCHANGED (b
) = 0;
397 BUF_BEG_UNCHANGED (b
) = 0;
398 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
400 b
->newline_cache
= 0;
401 b
->width_run_cache
= 0;
402 b
->width_table
= Qnil
;
403 b
->prevent_redisplay_optimizations_p
= 1;
405 /* Put this on the chain of all buffers including killed ones. */
406 b
->next
= all_buffers
;
409 /* An ordinary buffer normally doesn't need markers
410 to handle BEGV and ZV. */
412 b
->begv_marker
= Qnil
;
415 name
= Fcopy_sequence (name
);
416 STRING_SET_INTERVALS (name
, NULL_INTERVAL
);
419 if (SREF (name
, 0) != ' ')
425 reset_buffer_local_variables (b
, 1);
427 b
->mark
= Fmake_marker ();
428 BUF_MARKERS (b
) = NULL
;
431 /* Put this in the alist of all live buffers. */
433 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
435 /* An error in calling the function here (should someone redefine it)
436 can lead to infinite regress until you run out of stack. rms
437 says that's not worth protecting against. */
438 if (!NILP (Ffboundp (Qucs_set_table_for_input
)))
439 /* buf is on buffer-alist, so no gcpro. */
440 call1 (Qucs_set_table_for_input
, buf
);
446 /* Return a list of overlays which is a copy of the overlay list
447 LIST, but for buffer B. */
449 static struct Lisp_Overlay
*
450 copy_overlays (b
, list
)
452 struct Lisp_Overlay
*list
;
455 struct Lisp_Overlay
*result
= NULL
, *tail
= NULL
;
457 XSETBUFFER (buffer
, b
);
459 for (; list
; list
= list
->next
)
461 Lisp_Object overlay
, start
, end
, old_overlay
;
464 XSETMISC (old_overlay
, list
);
465 charpos
= marker_position (OVERLAY_START (old_overlay
));
466 start
= Fmake_marker ();
467 Fset_marker (start
, make_number (charpos
), buffer
);
468 XMARKER (start
)->insertion_type
469 = XMARKER (OVERLAY_START (old_overlay
))->insertion_type
;
471 charpos
= marker_position (OVERLAY_END (old_overlay
));
472 end
= Fmake_marker ();
473 Fset_marker (end
, make_number (charpos
), buffer
);
474 XMARKER (end
)->insertion_type
475 = XMARKER (OVERLAY_END (old_overlay
))->insertion_type
;
477 overlay
= allocate_misc ();
478 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
479 OVERLAY_START (overlay
) = start
;
480 OVERLAY_END (overlay
) = end
;
481 OVERLAY_PLIST (overlay
) = Fcopy_sequence (OVERLAY_PLIST (old_overlay
));
482 XOVERLAY (overlay
)->next
= NULL
;
485 tail
= tail
->next
= XOVERLAY (overlay
);
487 result
= tail
= XOVERLAY (overlay
);
494 /* Clone per-buffer values of buffer FROM.
496 Buffer TO gets the same per-buffer values as FROM, with the
497 following exceptions: (1) TO's name is left untouched, (2) markers
498 are copied and made to refer to TO, and (3) overlay lists are
502 clone_per_buffer_values (from
, to
)
503 struct buffer
*from
, *to
;
505 Lisp_Object to_buffer
;
508 XSETBUFFER (to_buffer
, to
);
510 for (offset
= PER_BUFFER_VAR_OFFSET (name
) + sizeof (Lisp_Object
);
512 offset
+= sizeof (Lisp_Object
))
516 obj
= PER_BUFFER_VALUE (from
, offset
);
519 struct Lisp_Marker
*m
= XMARKER (obj
);
520 obj
= Fmake_marker ();
521 XMARKER (obj
)->insertion_type
= m
->insertion_type
;
522 set_marker_both (obj
, to_buffer
, m
->charpos
, m
->bytepos
);
525 PER_BUFFER_VALUE (to
, offset
) = obj
;
528 bcopy (from
->local_flags
, to
->local_flags
, sizeof to
->local_flags
);
530 to
->overlays_before
= copy_overlays (to
, from
->overlays_before
);
531 to
->overlays_after
= copy_overlays (to
, from
->overlays_after
);
533 /* Get (a copy of) the alist of Lisp-level local variables of FROM
534 and install that in TO. */
535 to
->local_var_alist
= buffer_lisp_local_variables (from
);
538 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
,
540 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
541 doc
: /* Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.
542 BASE-BUFFER should be a live buffer, or the name of an existing buffer.
543 NAME should be a string which is not the name of an existing buffer.
544 Optional argument CLONE non-nil means preserve BASE-BUFFER's state,
545 such as major and minor modes, in the indirect buffer.
546 CLONE nil means the indirect buffer's state is reset to default values. */)
547 (base_buffer
, name
, clone
)
548 Lisp_Object base_buffer
, name
, clone
;
550 Lisp_Object buf
, tem
;
554 buf
= Fget_buffer (name
);
556 error ("Buffer name `%s' is in use", SDATA (name
));
559 base_buffer
= Fget_buffer (base_buffer
);
560 if (NILP (base_buffer
))
561 error ("No such buffer: `%s'", SDATA (tem
));
562 if (NILP (XBUFFER (base_buffer
)->name
))
563 error ("Base buffer has been killed");
565 if (SCHARS (name
) == 0)
566 error ("Empty string for buffer name is not allowed");
568 b
= (struct buffer
*) allocate_buffer ();
569 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
571 if (XBUFFER (base_buffer
)->base_buffer
)
572 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
574 b
->base_buffer
= XBUFFER (base_buffer
);
576 /* Use the base buffer's text object. */
577 b
->text
= b
->base_buffer
->text
;
579 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
580 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
581 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
582 BUF_BEGV_BYTE (b
) = BUF_BEGV_BYTE (b
->base_buffer
);
583 BUF_ZV_BYTE (b
) = BUF_ZV_BYTE (b
->base_buffer
);
584 BUF_PT_BYTE (b
) = BUF_PT_BYTE (b
->base_buffer
);
586 b
->newline_cache
= 0;
587 b
->width_run_cache
= 0;
588 b
->width_table
= Qnil
;
590 /* Put this on the chain of all buffers including killed ones. */
591 b
->next
= all_buffers
;
594 name
= Fcopy_sequence (name
);
595 STRING_SET_INTERVALS (name
, NULL_INTERVAL
);
599 reset_buffer_local_variables (b
, 1);
601 /* Put this in the alist of all live buffers. */
603 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
605 b
->mark
= Fmake_marker ();
608 /* The multibyte status belongs to the base buffer. */
609 b
->enable_multibyte_characters
= b
->base_buffer
->enable_multibyte_characters
;
611 /* Make sure the base buffer has markers for its narrowing. */
612 if (NILP (b
->base_buffer
->pt_marker
))
614 b
->base_buffer
->pt_marker
= Fmake_marker ();
615 set_marker_both (b
->base_buffer
->pt_marker
, base_buffer
,
616 BUF_PT (b
->base_buffer
),
617 BUF_PT_BYTE (b
->base_buffer
));
619 if (NILP (b
->base_buffer
->begv_marker
))
621 b
->base_buffer
->begv_marker
= Fmake_marker ();
622 set_marker_both (b
->base_buffer
->begv_marker
, base_buffer
,
623 BUF_BEGV (b
->base_buffer
),
624 BUF_BEGV_BYTE (b
->base_buffer
));
626 if (NILP (b
->base_buffer
->zv_marker
))
628 b
->base_buffer
->zv_marker
= Fmake_marker ();
629 set_marker_both (b
->base_buffer
->zv_marker
, base_buffer
,
630 BUF_ZV (b
->base_buffer
),
631 BUF_ZV_BYTE (b
->base_buffer
));
632 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
637 /* Give the indirect buffer markers for its narrowing. */
638 b
->pt_marker
= Fmake_marker ();
639 set_marker_both (b
->pt_marker
, buf
, BUF_PT (b
), BUF_PT_BYTE (b
));
640 b
->begv_marker
= Fmake_marker ();
641 set_marker_both (b
->begv_marker
, buf
, BUF_BEGV (b
), BUF_BEGV_BYTE (b
));
642 b
->zv_marker
= Fmake_marker ();
643 set_marker_both (b
->zv_marker
, buf
, BUF_ZV (b
), BUF_ZV_BYTE (b
));
644 XMARKER (b
->zv_marker
)->insertion_type
= 1;
648 struct buffer
*old_b
= current_buffer
;
650 clone_per_buffer_values (b
->base_buffer
, b
);
652 b
->file_truename
= Qnil
;
653 b
->display_count
= make_number (0);
655 b
->auto_save_file_name
= Qnil
;
656 set_buffer_internal_1 (b
);
657 Fset (intern ("buffer-save-without-query"), Qnil
);
658 Fset (intern ("buffer-file-number"), Qnil
);
659 Fset (intern ("buffer-stale-function"), Qnil
);
660 set_buffer_internal_1 (old_b
);
667 delete_all_overlays (b
)
672 /* `reset_buffer' blindly sets the list of overlays to NULL, so we
673 have to empty the list, otherwise we end up with overlays that
674 think they belong to this buffer while the buffer doesn't know about
676 while (b
->overlays_before
)
678 XSETMISC (overlay
, b
->overlays_before
);
679 Fdelete_overlay (overlay
);
681 while (b
->overlays_after
)
683 XSETMISC (overlay
, b
->overlays_after
);
684 Fdelete_overlay (overlay
);
686 eassert (b
->overlays_before
== NULL
);
687 eassert (b
->overlays_after
== NULL
);
690 /* Reinitialize everything about a buffer except its name and contents
692 If called on an already-initialized buffer, the list of overlays
693 should be deleted before calling this function, otherwise we end up
694 with overlays that claim to belong to the buffer but the buffer
695 claims it doesn't belong to it. */
699 register struct buffer
*b
;
702 b
->file_truename
= Qnil
;
703 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
705 XSETFASTINT (b
->save_length
, 0);
706 b
->last_window_start
= 1;
707 /* It is more conservative to start out "changed" than "unchanged". */
709 b
->prevent_redisplay_optimizations_p
= 1;
711 b
->auto_save_modified
= 0;
712 b
->auto_save_failure_time
= -1;
713 b
->auto_save_file_name
= Qnil
;
715 b
->overlays_before
= NULL
;
716 b
->overlays_after
= NULL
;
717 b
->overlay_center
= BEG
;
718 b
->mark_active
= Qnil
;
719 b
->point_before_scroll
= Qnil
;
720 b
->file_format
= Qnil
;
721 b
->auto_save_file_format
= Qt
;
722 b
->last_selected_window
= Qnil
;
723 XSETINT (b
->display_count
, 0);
724 b
->display_time
= Qnil
;
725 b
->enable_multibyte_characters
= buffer_defaults
.enable_multibyte_characters
;
726 b
->cursor_type
= buffer_defaults
.cursor_type
;
727 b
->extra_line_spacing
= buffer_defaults
.extra_line_spacing
;
729 b
->display_error_modiff
= 0;
732 /* Reset buffer B's local variables info.
733 Don't use this on a buffer that has already been in use;
734 it does not treat permanent locals consistently.
735 Instead, use Fkill_all_local_variables.
737 If PERMANENT_TOO is 1, then we reset permanent built-in
738 buffer-local variables. If PERMANENT_TOO is 0,
739 we preserve those. */
742 reset_buffer_local_variables (b
, permanent_too
)
743 register struct buffer
*b
;
749 /* Reset the major mode to Fundamental, together with all the
750 things that depend on the major mode.
751 default-major-mode is handled at a higher level.
752 We ignore it here. */
753 b
->major_mode
= Qfundamental_mode
;
755 b
->mode_name
= QSFundamental
;
756 b
->minor_modes
= Qnil
;
758 /* If the standard case table has been altered and invalidated,
759 fix up its insides first. */
760 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
761 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
762 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
763 Fset_standard_case_table (Vascii_downcase_table
);
765 b
->downcase_table
= Vascii_downcase_table
;
766 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
767 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
768 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
769 b
->invisibility_spec
= Qt
;
771 b
->buffer_file_type
= Qnil
;
774 /* Reset all (or most) per-buffer variables to their defaults. */
775 b
->local_var_alist
= Qnil
;
776 for (i
= 0; i
< last_per_buffer_idx
; ++i
)
777 if (permanent_too
|| buffer_permanent_local_flags
[i
] == 0)
778 SET_PER_BUFFER_VALUE_P (b
, i
, 0);
780 /* For each slot that has a default value,
781 copy that into the slot. */
783 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
785 offset
+= sizeof (Lisp_Object
))
787 int idx
= PER_BUFFER_IDX (offset
);
790 || buffer_permanent_local_flags
[idx
] == 0))
791 /* Is -2 used anywhere? */
793 PER_BUFFER_VALUE (b
, offset
) = PER_BUFFER_DEFAULT (offset
);
797 /* We split this away from generate-new-buffer, because rename-buffer
798 and set-visited-file-name ought to be able to use this to really
799 rename the buffer properly. */
801 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
803 doc
: /* Return a string that is the name of no existing buffer based on NAME.
804 If there is no live buffer named NAME, then return NAME.
805 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
806 \(starting at 2) until an unused name is found, and then return that name.
807 Optional second argument IGNORE specifies a name that is okay to use (if
808 it is in the sequence to be tried) even if a buffer with that name exists. */)
810 register Lisp_Object name
, ignore
;
812 register Lisp_Object gentemp
, tem
;
818 tem
= Fstring_equal (name
, ignore
);
821 tem
= Fget_buffer (name
);
828 sprintf (number
, "<%d>", ++count
);
829 gentemp
= concat2 (name
, build_string (number
));
830 tem
= Fstring_equal (gentemp
, ignore
);
833 tem
= Fget_buffer (gentemp
);
840 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
841 doc
: /* Return the name of BUFFER, as a string.
842 With no argument or nil as argument, return the name of the current buffer. */)
844 register Lisp_Object buffer
;
847 return current_buffer
->name
;
848 CHECK_BUFFER (buffer
);
849 return XBUFFER (buffer
)->name
;
852 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
853 doc
: /* Return name of file BUFFER is visiting, or nil if none.
854 No argument or nil as argument means use the current buffer. */)
856 register Lisp_Object buffer
;
859 return current_buffer
->filename
;
860 CHECK_BUFFER (buffer
);
861 return XBUFFER (buffer
)->filename
;
864 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
866 doc
: /* Return the base buffer of indirect buffer BUFFER.
867 If BUFFER is not indirect, return nil.
868 BUFFER defaults to the current buffer. */)
870 register Lisp_Object buffer
;
873 Lisp_Object base_buffer
;
876 base
= current_buffer
->base_buffer
;
879 CHECK_BUFFER (buffer
);
880 base
= XBUFFER (buffer
)->base_buffer
;
885 XSETBUFFER (base_buffer
, base
);
889 DEFUN ("buffer-local-value", Fbuffer_local_value
,
890 Sbuffer_local_value
, 2, 2, 0,
891 doc
: /* Return the value of VARIABLE in BUFFER.
892 If VARIABLE does not have a buffer-local binding in BUFFER, the value
893 is the default binding of the variable. */)
895 register Lisp_Object variable
;
896 register Lisp_Object buffer
;
898 register struct buffer
*buf
;
899 register Lisp_Object result
;
901 CHECK_SYMBOL (variable
);
902 CHECK_BUFFER (buffer
);
903 buf
= XBUFFER (buffer
);
905 if (SYMBOLP (variable
))
906 variable
= indirect_variable (variable
);
908 /* Look in local_var_list */
909 result
= Fassoc (variable
, buf
->local_var_alist
);
915 /* Look in special slots */
916 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
917 offset
< sizeof (struct buffer
);
918 /* sizeof EMACS_INT == sizeof Lisp_Object */
919 offset
+= (sizeof (EMACS_INT
)))
921 idx
= PER_BUFFER_IDX (offset
);
922 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
923 && SYMBOLP (PER_BUFFER_SYMBOL (offset
))
924 && EQ (PER_BUFFER_SYMBOL (offset
), variable
))
926 result
= PER_BUFFER_VALUE (buf
, offset
);
933 result
= Fdefault_value (variable
);
937 Lisp_Object valcontents
;
938 Lisp_Object current_alist_element
;
940 /* What binding is loaded right now? */
941 valcontents
= SYMBOL_VALUE (variable
);
942 current_alist_element
943 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
945 /* The value of the currently loaded binding is not
946 stored in it, but rather in the realvalue slot.
947 Store that value into the binding it belongs to
948 in case that is the one we are about to use. */
950 Fsetcdr (current_alist_element
,
951 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
953 /* Now get the (perhaps updated) value out of the binding. */
954 result
= XCDR (result
);
957 if (!EQ (result
, Qunbound
))
960 xsignal1 (Qvoid_variable
, variable
);
963 /* Return an alist of the Lisp-level buffer-local bindings of
964 buffer BUF. That is, don't include the variables maintained
965 in special slots in the buffer object. */
968 buffer_lisp_local_variables (buf
)
971 Lisp_Object result
= Qnil
;
972 register Lisp_Object tail
;
973 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
975 Lisp_Object val
, elt
;
979 /* Reference each variable in the alist in buf.
980 If inquiring about the current buffer, this gets the current values,
981 so store them into the alist so the alist is up to date.
982 If inquiring about some other buffer, this swaps out any values
983 for that buffer, making the alist up to date automatically. */
984 val
= find_symbol_value (XCAR (elt
));
985 /* Use the current buffer value only if buf is the current buffer. */
986 if (buf
!= current_buffer
)
989 /* If symbol is unbound, put just the symbol in the list. */
990 if (EQ (val
, Qunbound
))
991 result
= Fcons (XCAR (elt
), result
);
992 /* Otherwise, put (symbol . value) in the list. */
994 result
= Fcons (Fcons (XCAR (elt
), val
), result
);
1000 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
1001 Sbuffer_local_variables
, 0, 1, 0,
1002 doc
: /* Return an alist of variables that are buffer-local in BUFFER.
1003 Most elements look like (SYMBOL . VALUE), describing one variable.
1004 For a symbol that is locally unbound, just the symbol appears in the value.
1005 Note that storing new VALUEs in these elements doesn't change the variables.
1006 No argument or nil as argument means use current buffer as BUFFER. */)
1008 register Lisp_Object buffer
;
1010 register struct buffer
*buf
;
1011 register Lisp_Object result
;
1014 buf
= current_buffer
;
1017 CHECK_BUFFER (buffer
);
1018 buf
= XBUFFER (buffer
);
1021 result
= buffer_lisp_local_variables (buf
);
1023 /* Add on all the variables stored in special slots. */
1027 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
1028 offset
< sizeof (struct buffer
);
1029 /* sizeof EMACS_INT == sizeof Lisp_Object */
1030 offset
+= (sizeof (EMACS_INT
)))
1032 idx
= PER_BUFFER_IDX (offset
);
1033 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
1034 && SYMBOLP (PER_BUFFER_SYMBOL (offset
)))
1035 result
= Fcons (Fcons (PER_BUFFER_SYMBOL (offset
),
1036 PER_BUFFER_VALUE (buf
, offset
)),
1044 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
1046 doc
: /* Return t if BUFFER was modified since its file was last read or saved.
1047 No argument or nil as argument means use current buffer as BUFFER. */)
1049 register Lisp_Object buffer
;
1051 register struct buffer
*buf
;
1053 buf
= current_buffer
;
1056 CHECK_BUFFER (buffer
);
1057 buf
= XBUFFER (buffer
);
1060 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
1063 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
1065 doc
: /* Mark current buffer as modified or unmodified according to FLAG.
1066 A non-nil FLAG means mark the buffer modified. */)
1068 register Lisp_Object flag
;
1070 register int already
;
1071 register Lisp_Object fn
;
1072 Lisp_Object buffer
, window
;
1074 #ifdef CLASH_DETECTION
1075 /* If buffer becoming modified, lock the file.
1076 If buffer becoming unmodified, unlock the file. */
1078 fn
= current_buffer
->file_truename
;
1079 /* Test buffer-file-name so that binding it to nil is effective. */
1080 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
1082 already
= SAVE_MODIFF
< MODIFF
;
1083 if (!already
&& !NILP (flag
))
1085 else if (already
&& NILP (flag
))
1088 #endif /* CLASH_DETECTION */
1090 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
1092 /* Set update_mode_lines only if buffer is displayed in some window.
1093 Packages like jit-lock or lazy-lock preserve a buffer's modified
1094 state by recording/restoring the state around blocks of code.
1095 Setting update_mode_lines makes redisplay consider all windows
1096 (on all frames). Stealth fontification of buffers not displayed
1097 would incur additional redisplay costs if we'd set
1098 update_modes_lines unconditionally.
1100 Ideally, I think there should be another mechanism for fontifying
1101 buffers without "modifying" buffers, or redisplay should be
1102 smarter about updating the `*' in mode lines. --gerd */
1103 XSETBUFFER (buffer
, current_buffer
);
1104 window
= Fget_buffer_window (buffer
, Qt
);
1105 if (WINDOWP (window
))
1107 ++update_mode_lines
;
1108 current_buffer
->prevent_redisplay_optimizations_p
= 1;
1114 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p
,
1115 Srestore_buffer_modified_p
, 1, 1, 0,
1116 doc
: /* Like `set-buffer-modified-p', with a difference concerning redisplay.
1117 It is not ensured that mode lines will be updated to show the modified
1118 state of the current buffer. Use with care. */)
1122 #ifdef CLASH_DETECTION
1125 /* If buffer becoming modified, lock the file.
1126 If buffer becoming unmodified, unlock the file. */
1128 fn
= current_buffer
->file_truename
;
1129 /* Test buffer-file-name so that binding it to nil is effective. */
1130 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
1132 int already
= SAVE_MODIFF
< MODIFF
;
1133 if (!already
&& !NILP (flag
))
1135 else if (already
&& NILP (flag
))
1138 #endif /* CLASH_DETECTION */
1140 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
1144 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
1146 doc
: /* Return BUFFER's tick counter, incremented for each change in text.
1147 Each buffer has a tick counter which is incremented each time the
1148 text in that buffer is changed. It wraps around occasionally.
1149 No argument or nil as argument means use current buffer as BUFFER. */)
1151 register Lisp_Object buffer
;
1153 register struct buffer
*buf
;
1155 buf
= current_buffer
;
1158 CHECK_BUFFER (buffer
);
1159 buf
= XBUFFER (buffer
);
1162 return make_number (BUF_MODIFF (buf
));
1165 DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick
,
1166 Sbuffer_chars_modified_tick
, 0, 1, 0,
1167 doc
: /* Return BUFFER's character-change tick counter.
1168 Each buffer has a character-change tick counter, which is set to the
1169 value of the buffer's tick counter \(see `buffer-modified-tick'), each
1170 time text in that buffer is inserted or deleted. By comparing the
1171 values returned by two individual calls of `buffer-chars-modified-tick',
1172 you can tell whether a character change occurred in that buffer in
1173 between these calls. No argument or nil as argument means use current
1174 buffer as BUFFER. */)
1176 register Lisp_Object buffer
;
1178 register struct buffer
*buf
;
1180 buf
= current_buffer
;
1183 CHECK_BUFFER (buffer
);
1184 buf
= XBUFFER (buffer
);
1187 return make_number (BUF_CHARS_MODIFF (buf
));
1190 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
1191 "sRename buffer (to new name): \nP",
1192 doc
: /* Change current buffer's name to NEWNAME (a string).
1193 If second arg UNIQUE is nil or omitted, it is an error if a
1194 buffer named NEWNAME already exists.
1195 If UNIQUE is non-nil, come up with a new name using
1196 `generate-new-buffer-name'.
1197 Interactively, you can set UNIQUE with a prefix argument.
1198 We return the name we actually gave the buffer.
1199 This does not change the name of the visited file (if any). */)
1201 register Lisp_Object newname
, unique
;
1203 register Lisp_Object tem
, buf
;
1205 CHECK_STRING (newname
);
1207 if (SCHARS (newname
) == 0)
1208 error ("Empty string is invalid as a buffer name");
1210 tem
= Fget_buffer (newname
);
1213 /* Don't short-circuit if UNIQUE is t. That is a useful way to
1214 rename the buffer automatically so you can create another
1215 with the original name. It makes UNIQUE equivalent to
1216 (rename-buffer (generate-new-buffer-name NEWNAME)). */
1217 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
1218 return current_buffer
->name
;
1220 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
1222 error ("Buffer name `%s' is in use", SDATA (newname
));
1225 current_buffer
->name
= newname
;
1227 /* Catch redisplay's attention. Unless we do this, the mode lines for
1228 any windows displaying current_buffer will stay unchanged. */
1229 update_mode_lines
++;
1231 XSETBUFFER (buf
, current_buffer
);
1232 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
1233 if (NILP (current_buffer
->filename
)
1234 && !NILP (current_buffer
->auto_save_file_name
))
1235 call0 (intern ("rename-auto-save-file"));
1236 /* Refetch since that last call may have done GC. */
1237 return current_buffer
->name
;
1240 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 3, 0,
1241 doc
: /* Return most recently selected buffer other than BUFFER.
1242 Buffers not visible in windows are preferred to visible buffers,
1243 unless optional second argument VISIBLE-OK is non-nil.
1244 If the optional third argument FRAME is non-nil, use that frame's
1245 buffer list instead of the selected frame's buffer list.
1246 If no other buffer exists, the buffer `*scratch*' is returned.
1247 If BUFFER is omitted or nil, some interesting buffer is returned. */)
1248 (buffer
, visible_ok
, frame
)
1249 register Lisp_Object buffer
, visible_ok
, frame
;
1251 Lisp_Object
Fset_buffer_major_mode ();
1252 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
1256 frame
= selected_frame
;
1258 tail
= Vbuffer_alist
;
1259 pred
= frame_buffer_predicate (frame
);
1261 /* Consider buffers that have been seen in the selected frame
1262 before other buffers. */
1264 tem
= frame_buffer_list (frame
);
1268 if (BUFFERP (XCAR (tem
)))
1269 add_ons
= Fcons (Fcons (Qnil
, XCAR (tem
)), add_ons
);
1272 tail
= nconc2 (Fnreverse (add_ons
), tail
);
1274 for (; CONSP (tail
); tail
= XCDR (tail
))
1276 buf
= Fcdr (XCAR (tail
));
1277 if (EQ (buf
, buffer
))
1281 if (NILP (XBUFFER (buf
)->name
))
1283 if (SREF (XBUFFER (buf
)->name
, 0) == ' ')
1285 /* If the selected frame has a buffer_predicate,
1286 disregard buffers that don't fit the predicate. */
1289 tem
= call1 (pred
, buf
);
1294 if (NILP (visible_ok
))
1295 tem
= Fget_buffer_window (buf
, Qvisible
);
1300 if (NILP (notsogood
))
1303 if (!NILP (notsogood
))
1305 buf
= Fget_buffer (build_string ("*scratch*"));
1308 buf
= Fget_buffer_create (build_string ("*scratch*"));
1309 Fset_buffer_major_mode (buf
);
1314 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
1316 doc
: /* Start keeping undo information for buffer BUFFER.
1317 No argument or nil as argument means do this for the current buffer. */)
1319 register Lisp_Object buffer
;
1321 Lisp_Object real_buffer
;
1324 XSETBUFFER (real_buffer
, current_buffer
);
1327 real_buffer
= Fget_buffer (buffer
);
1328 if (NILP (real_buffer
))
1332 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
1333 XBUFFER (real_buffer
)->undo_list
= Qnil
;
1339 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
1340 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1341 The buffer being killed will be current while the hook is running.\n\
1344 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
1345 doc
: /* Kill the buffer BUFFER.
1346 The argument may be a buffer or the name of a buffer.
1347 With a nil argument, kill the current buffer.
1349 Value is t if the buffer is actually killed, nil otherwise.
1351 The functions in `kill-buffer-query-functions' are called with BUFFER as
1352 the current buffer. If any of them returns nil, the buffer is not killed.
1354 The hook `kill-buffer-hook' is run before the buffer is actually killed.
1355 The buffer being killed will be current while the hook is running.
1357 Any processes that have this buffer as the `process-buffer' are killed
1363 register struct buffer
*b
;
1364 register Lisp_Object tem
;
1365 register struct Lisp_Marker
*m
;
1366 struct gcpro gcpro1
;
1369 buf
= Fcurrent_buffer ();
1371 buf
= Fget_buffer (buffer
);
1377 /* Avoid trouble for buffer already dead. */
1381 /* Query if the buffer is still modified. */
1382 if (INTERACTIVE
&& !NILP (b
->filename
)
1383 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1386 tem
= do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
1387 b
->name
, make_number (0)));
1393 /* Run hooks with the buffer to be killed the current buffer. */
1395 int count
= SPECPDL_INDEX ();
1396 Lisp_Object arglist
[1];
1398 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1399 set_buffer_internal (b
);
1401 /* First run the query functions; if any query is answered no,
1402 don't kill the buffer. */
1403 arglist
[0] = Qkill_buffer_query_functions
;
1404 tem
= Frun_hook_with_args_until_failure (1, arglist
);
1406 return unbind_to (count
, Qnil
);
1408 /* Then run the hooks. */
1409 Frun_hooks (1, &Qkill_buffer_hook
);
1410 unbind_to (count
, Qnil
);
1413 /* We have no more questions to ask. Verify that it is valid
1414 to kill the buffer. This must be done after the questions
1415 since anything can happen within do_yes_or_no_p. */
1417 /* Don't kill the minibuffer now current. */
1418 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1424 /* When we kill a base buffer, kill all its indirect buffers.
1425 We do it at this stage so nothing terrible happens if they
1426 ask questions or their hooks get errors. */
1427 if (! b
->base_buffer
)
1429 struct buffer
*other
;
1433 for (other
= all_buffers
; other
; other
= other
->next
)
1434 /* all_buffers contains dead buffers too;
1435 don't re-kill them. */
1436 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1439 XSETBUFFER (buf
, other
);
1446 /* Make this buffer not be current.
1447 In the process, notice if this is the sole visible buffer
1448 and give up if so. */
1449 if (b
== current_buffer
)
1451 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1453 if (b
== current_buffer
)
1457 /* Notice if the buffer to kill is the sole visible buffer
1458 when we're currently in the mini-buffer, and give up if so. */
1459 XSETBUFFER (tem
, current_buffer
);
1460 if (EQ (tem
, XWINDOW (minibuf_window
)->buffer
))
1462 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1467 /* Now there is no question: we can kill the buffer. */
1469 #ifdef CLASH_DETECTION
1470 /* Unlock this buffer's file, if it is locked. */
1472 #endif /* CLASH_DETECTION */
1474 kill_buffer_processes (buf
);
1475 clear_charpos_cache (b
);
1477 tem
= Vinhibit_quit
;
1479 replace_buffer_in_all_windows (buf
);
1480 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1481 frames_discard_buffer (buf
);
1482 Vinhibit_quit
= tem
;
1484 /* Delete any auto-save file, if we saved it in this session.
1485 But not if the buffer is modified. */
1486 if (STRINGP (b
->auto_save_file_name
)
1487 && b
->auto_save_modified
!= 0
1488 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
1489 && BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)
1490 && NILP (Fsymbol_value (intern ("auto-save-visited-file-name"))))
1493 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1495 internal_delete_file (b
->auto_save_file_name
);
1500 /* Unchain all markers that belong to this indirect buffer.
1501 Don't unchain the markers that belong to the base buffer
1502 or its other indirect buffers. */
1503 for (m
= BUF_MARKERS (b
); m
; )
1505 struct Lisp_Marker
*next
= m
->next
;
1513 /* Unchain all markers of this buffer and its indirect buffers.
1514 and leave them pointing nowhere. */
1515 for (m
= BUF_MARKERS (b
); m
; )
1517 struct Lisp_Marker
*next
= m
->next
;
1522 BUF_MARKERS (b
) = NULL
;
1523 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1525 /* Perhaps we should explicitly free the interval tree here... */
1528 /* Reset the local variables, so that this buffer's local values
1529 won't be protected from GC. They would be protected
1530 if they happened to remain encached in their symbols.
1531 This gets rid of them for certain. */
1532 swap_out_buffer_local_variables (b
);
1533 reset_buffer_local_variables (b
, 1);
1538 if (! b
->base_buffer
)
1539 free_buffer_text (b
);
1541 if (b
->newline_cache
)
1543 free_region_cache (b
->newline_cache
);
1544 b
->newline_cache
= 0;
1546 if (b
->width_run_cache
)
1548 free_region_cache (b
->width_run_cache
);
1549 b
->width_run_cache
= 0;
1551 b
->width_table
= Qnil
;
1553 b
->undo_list
= Qnil
;
1558 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1559 we do this each time BUF is selected visibly, the more recently
1560 selected buffers are always closer to the front of the list. This
1561 means that other_buffer is more likely to choose a relevant buffer. */
1567 register Lisp_Object link
, prev
;
1569 frame
= selected_frame
;
1572 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCDR (link
))
1574 if (EQ (XCDR (XCAR (link
)), buf
))
1579 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1580 we cannot use Fdelq itself here because it allows quitting. */
1583 Vbuffer_alist
= XCDR (Vbuffer_alist
);
1585 XSETCDR (prev
, XCDR (XCDR (prev
)));
1587 XSETCDR (link
, Vbuffer_alist
);
1588 Vbuffer_alist
= link
;
1590 /* Effectively do a delq on buried_buffer_list. */
1593 for (link
= XFRAME (frame
)->buried_buffer_list
; CONSP (link
);
1596 if (EQ (XCAR (link
), buf
))
1599 XFRAME (frame
)->buried_buffer_list
= XCDR (link
);
1601 XSETCDR (prev
, XCDR (XCDR (prev
)));
1607 /* Now move this buffer to the front of frame_buffer_list also. */
1610 for (link
= frame_buffer_list (frame
); CONSP (link
);
1613 if (EQ (XCAR (link
), buf
))
1618 /* Effectively do delq. */
1623 set_frame_buffer_list (frame
,
1624 XCDR (frame_buffer_list (frame
)));
1626 XSETCDR (prev
, XCDR (XCDR (prev
)));
1628 XSETCDR (link
, frame_buffer_list (frame
));
1629 set_frame_buffer_list (frame
, link
);
1632 set_frame_buffer_list (frame
, Fcons (buf
, frame_buffer_list (frame
)));
1635 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1636 doc
: /* Set an appropriate major mode for BUFFER.
1637 For the *scratch* buffer, use `initial-major-mode', otherwise choose a mode
1638 according to `default-major-mode'.
1639 Use this function before selecting the buffer, since it may need to inspect
1640 the current buffer's major mode. */)
1645 Lisp_Object function
;
1647 if (STRINGP (XBUFFER (buffer
)->name
)
1648 && strcmp (SDATA (XBUFFER (buffer
)->name
), "*scratch*") == 0)
1649 function
= find_symbol_value (intern ("initial-major-mode"));
1652 function
= buffer_defaults
.major_mode
;
1654 && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1655 function
= current_buffer
->major_mode
;
1658 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1661 count
= SPECPDL_INDEX ();
1663 /* To select a nonfundamental mode,
1664 select the buffer temporarily and then call the mode function. */
1666 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1668 Fset_buffer (buffer
);
1671 return unbind_to (count
, Qnil
);
1674 /* If switching buffers in WINDOW would be an error, return
1675 a C string saying what the error would be. */
1678 no_switch_window (window
)
1682 if (EQ (minibuf_window
, window
))
1683 return "Cannot switch buffers in minibuffer window";
1684 tem
= Fwindow_dedicated_p (window
);
1686 return "Cannot switch buffers in a dedicated window";
1690 /* Switch to buffer BUFFER in the selected window.
1691 If NORECORD is non-nil, don't call record_buffer. */
1694 switch_to_buffer_1 (buffer
, norecord
)
1695 Lisp_Object buffer
, norecord
;
1697 register Lisp_Object buf
;
1700 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1703 buf
= Fget_buffer (buffer
);
1706 buf
= Fget_buffer_create (buffer
);
1707 Fset_buffer_major_mode (buf
);
1711 if (NILP (norecord
))
1712 record_buffer (buf
);
1714 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1715 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1722 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1723 doc
: /* Select buffer BUFFER in the current window.
1724 If BUFFER does not identify an existing buffer,
1725 then this function creates a buffer with that name.
1727 When called from Lisp, BUFFER may be a buffer, a string \(a buffer name),
1728 or nil. If BUFFER is nil, then this function chooses a buffer
1729 using `other-buffer'.
1730 Optional second arg NORECORD non-nil means
1731 do not put this buffer at the front of the list of recently selected ones.
1732 This function returns the buffer it switched to.
1734 WARNING: This is NOT the way to work on another buffer temporarily
1735 within a Lisp program! Use `set-buffer' instead. That avoids messing with
1736 the window-buffer correspondences. */)
1738 Lisp_Object buffer
, norecord
;
1742 if (EQ (buffer
, Fwindow_buffer (selected_window
)))
1744 /* Basically a NOP. Avoid signalling an error in the case where
1745 the selected window is dedicated, or a minibuffer. */
1747 /* But do put this buffer at the front of the buffer list,
1748 unless that has been inhibited. Note that even if
1749 BUFFER is at the front of the main buffer-list already,
1750 we still want to move it to the front of the frame's buffer list. */
1751 if (NILP (norecord
))
1752 record_buffer (buffer
);
1753 return Fset_buffer (buffer
);
1756 err
= no_switch_window (selected_window
);
1757 if (err
) error (err
);
1759 return switch_to_buffer_1 (buffer
, norecord
);
1762 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1763 doc
: /* Select buffer BUFFER in some window, preferably a different one.
1764 BUFFER may be a buffer, a string \(a buffer name), or nil.
1765 If BUFFER is a string which is not the name of an existing buffer,
1766 then this function creates a buffer with that name.
1767 If BUFFER is nil, then it chooses some other buffer.
1768 If `pop-up-windows' is non-nil, windows can be split to do this.
1769 If optional second arg OTHER-WINDOW is non-nil, insist on finding another
1770 window even if BUFFER is already visible in the selected window,
1771 and ignore `same-window-regexps' and `same-window-buffer-names'.
1772 This function returns the buffer it switched to.
1773 This uses the function `display-buffer' as a subroutine; see the documentation
1774 of `display-buffer' for additional customization information.
1776 Optional third arg NORECORD non-nil means
1777 do not put this buffer at the front of the list of recently selected ones. */)
1778 (buffer
, other_window
, norecord
)
1779 Lisp_Object buffer
, other_window
, norecord
;
1781 register Lisp_Object buf
;
1783 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1786 buf
= Fget_buffer (buffer
);
1789 buf
= Fget_buffer_create (buffer
);
1790 Fset_buffer_major_mode (buf
);
1794 Fselect_window (Fdisplay_buffer (buf
, other_window
, Qnil
), norecord
);
1798 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1799 doc
: /* Return the current buffer as a Lisp object. */)
1802 register Lisp_Object buf
;
1803 XSETBUFFER (buf
, current_buffer
);
1807 /* Set the current buffer to B.
1809 We previously set windows_or_buffers_changed here to invalidate
1810 global unchanged information in beg_unchanged and end_unchanged.
1811 This is no longer necessary because we now compute unchanged
1812 information on a buffer-basis. Every action affecting other
1813 windows than the selected one requires a select_window at some
1814 time, and that increments windows_or_buffers_changed. */
1817 set_buffer_internal (b
)
1818 register struct buffer
*b
;
1820 if (current_buffer
!= b
)
1821 set_buffer_internal_1 (b
);
1824 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1825 This is used by redisplay. */
1828 set_buffer_internal_1 (b
)
1829 register struct buffer
*b
;
1831 register struct buffer
*old_buf
;
1832 register Lisp_Object tail
, valcontents
;
1835 #ifdef USE_MMAP_FOR_BUFFERS
1836 if (b
->text
->beg
== NULL
)
1837 enlarge_buffer_text (b
, 0);
1838 #endif /* USE_MMAP_FOR_BUFFERS */
1840 if (current_buffer
== b
)
1843 old_buf
= current_buffer
;
1845 last_known_column_point
= -1; /* invalidate indentation cache */
1849 /* Put the undo list back in the base buffer, so that it appears
1850 that an indirect buffer shares the undo list of its base. */
1851 if (old_buf
->base_buffer
)
1852 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1854 /* If the old current buffer has markers to record PT, BEGV and ZV
1855 when it is not current, update them now. */
1856 if (! NILP (old_buf
->pt_marker
))
1859 XSETBUFFER (obuf
, old_buf
);
1860 set_marker_both (old_buf
->pt_marker
, obuf
,
1861 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1863 if (! NILP (old_buf
->begv_marker
))
1866 XSETBUFFER (obuf
, old_buf
);
1867 set_marker_both (old_buf
->begv_marker
, obuf
,
1868 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1870 if (! NILP (old_buf
->zv_marker
))
1873 XSETBUFFER (obuf
, old_buf
);
1874 set_marker_both (old_buf
->zv_marker
, obuf
,
1875 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1879 /* Get the undo list from the base buffer, so that it appears
1880 that an indirect buffer shares the undo list of its base. */
1882 b
->undo_list
= b
->base_buffer
->undo_list
;
1884 /* If the new current buffer has markers to record PT, BEGV and ZV
1885 when it is not current, fetch them now. */
1886 if (! NILP (b
->pt_marker
))
1888 BUF_PT (b
) = marker_position (b
->pt_marker
);
1889 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1891 if (! NILP (b
->begv_marker
))
1893 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1894 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1896 if (! NILP (b
->zv_marker
))
1898 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1899 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1902 /* Look down buffer's list of local Lisp variables
1903 to find and update any that forward into C variables. */
1905 for (tail
= b
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1907 valcontents
= SYMBOL_VALUE (XCAR (XCAR (tail
)));
1908 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1909 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1910 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1911 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1912 /* Just reference the variable
1913 to cause it to become set for this buffer. */
1914 Fsymbol_value (XCAR (XCAR (tail
)));
1917 /* Do the same with any others that were local to the previous buffer */
1920 for (tail
= old_buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1922 valcontents
= SYMBOL_VALUE (XCAR (XCAR (tail
)));
1923 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1924 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1925 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1926 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1927 /* Just reference the variable
1928 to cause it to become set for this buffer. */
1929 Fsymbol_value (XCAR (XCAR (tail
)));
1933 /* Switch to buffer B temporarily for redisplay purposes.
1934 This avoids certain things that don't need to be done within redisplay. */
1940 register struct buffer
*old_buf
;
1942 if (current_buffer
== b
)
1945 old_buf
= current_buffer
;
1950 /* If the old current buffer has markers to record PT, BEGV and ZV
1951 when it is not current, update them now. */
1952 if (! NILP (old_buf
->pt_marker
))
1955 XSETBUFFER (obuf
, old_buf
);
1956 set_marker_both (old_buf
->pt_marker
, obuf
,
1957 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1959 if (! NILP (old_buf
->begv_marker
))
1962 XSETBUFFER (obuf
, old_buf
);
1963 set_marker_both (old_buf
->begv_marker
, obuf
,
1964 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1966 if (! NILP (old_buf
->zv_marker
))
1969 XSETBUFFER (obuf
, old_buf
);
1970 set_marker_both (old_buf
->zv_marker
, obuf
,
1971 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1975 /* If the new current buffer has markers to record PT, BEGV and ZV
1976 when it is not current, fetch them now. */
1977 if (! NILP (b
->pt_marker
))
1979 BUF_PT (b
) = marker_position (b
->pt_marker
);
1980 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1982 if (! NILP (b
->begv_marker
))
1984 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1985 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1987 if (! NILP (b
->zv_marker
))
1989 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1990 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1994 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1995 doc
: /* Make the buffer BUFFER current for editing operations.
1996 BUFFER may be a buffer or the name of an existing buffer.
1997 See also `save-excursion' when you want to make a buffer current temporarily.
1998 This function does not display the buffer, so its effect ends
1999 when the current command terminates.
2000 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently. */)
2002 register Lisp_Object buffer
;
2004 register Lisp_Object buf
;
2005 buf
= Fget_buffer (buffer
);
2008 if (NILP (XBUFFER (buf
)->name
))
2009 error ("Selecting deleted buffer");
2010 set_buffer_internal (XBUFFER (buf
));
2014 /* Set the current buffer to BUFFER provided it is alive. */
2017 set_buffer_if_live (buffer
)
2020 if (! NILP (XBUFFER (buffer
)->name
))
2021 Fset_buffer (buffer
);
2025 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
2026 Sbarf_if_buffer_read_only
, 0, 0, 0,
2027 doc
: /* Signal a `buffer-read-only' error if the current buffer is read-only. */)
2030 if (!NILP (current_buffer
->read_only
)
2031 && NILP (Vinhibit_read_only
))
2032 xsignal1 (Qbuffer_read_only
, Fcurrent_buffer ());
2036 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
2037 doc
: /* Put BUFFER at the end of the list of all buffers.
2038 There it is the least likely candidate for `other-buffer' to return;
2039 thus, the least likely buffer for \\[switch-to-buffer] to select by default.
2040 You can specify a buffer name as BUFFER, or an actual buffer object.
2041 If BUFFER is nil or omitted, bury the current buffer.
2042 Also, if BUFFER is nil or omitted, remove the current buffer from the
2043 selected window if it is displayed there. */)
2045 register Lisp_Object buffer
;
2047 /* Figure out what buffer we're going to bury. */
2051 XSETBUFFER (buffer
, current_buffer
);
2053 tem
= Fwindow_buffer (selected_window
);
2054 /* If we're burying the current buffer, unshow it. */
2055 if (EQ (buffer
, tem
))
2057 if (NILP (Fwindow_dedicated_p (selected_window
)))
2058 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
, Qnil
), Qnil
);
2059 else if (NILP (XWINDOW (selected_window
)->parent
))
2060 Ficonify_frame (Fwindow_frame (selected_window
));
2062 Fdelete_window (selected_window
);
2069 buf1
= Fget_buffer (buffer
);
2075 /* Move buffer to the end of the buffer list. Do nothing if the
2076 buffer is killed. */
2077 if (!NILP (XBUFFER (buffer
)->name
))
2079 Lisp_Object aelt
, link
;
2081 aelt
= Frassq (buffer
, Vbuffer_alist
);
2082 link
= Fmemq (aelt
, Vbuffer_alist
);
2083 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
2084 XSETCDR (link
, Qnil
);
2085 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
2087 XFRAME (selected_frame
)->buffer_list
2088 = Fdelq (buffer
, XFRAME (selected_frame
)->buffer_list
);
2089 XFRAME (selected_frame
)->buried_buffer_list
2090 = Fcons (buffer
, Fdelq (buffer
, XFRAME (selected_frame
)->buried_buffer_list
));
2096 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
2097 doc
: /* Delete the entire contents of the current buffer.
2098 Any narrowing restriction in effect (see `narrow-to-region') is removed,
2099 so the buffer is truly empty after this. */)
2106 current_buffer
->last_window_start
= 1;
2107 /* Prevent warnings, or suspension of auto saving, that would happen
2108 if future size is less than past size. Use of erase-buffer
2109 implies that the future text is not really related to the past text. */
2110 XSETFASTINT (current_buffer
->save_length
, 0);
2115 validate_region (b
, e
)
2116 register Lisp_Object
*b
, *e
;
2118 CHECK_NUMBER_COERCE_MARKER (*b
);
2119 CHECK_NUMBER_COERCE_MARKER (*e
);
2121 if (XINT (*b
) > XINT (*e
))
2124 tem
= *b
; *b
= *e
; *e
= tem
;
2127 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
2128 && XINT (*e
) <= ZV
))
2129 args_out_of_range (*b
, *e
);
2132 /* Advance BYTE_POS up to a character boundary
2133 and return the adjusted position. */
2136 advance_to_char_boundary (byte_pos
)
2141 if (byte_pos
== BEG
)
2142 /* Beginning of buffer is always a character boundary. */
2145 c
= FETCH_BYTE (byte_pos
);
2146 if (! CHAR_HEAD_P (c
))
2148 /* We should advance BYTE_POS only when C is a constituent of a
2149 multibyte sequence. */
2150 int orig_byte_pos
= byte_pos
;
2155 c
= FETCH_BYTE (byte_pos
);
2157 while (! CHAR_HEAD_P (c
) && byte_pos
> BEG
);
2159 if (byte_pos
< orig_byte_pos
)
2160 byte_pos
= orig_byte_pos
;
2161 /* If C is a constituent of a multibyte sequence, BYTE_POS was
2162 surely advance to the correct character boundary. If C is
2163 not, BYTE_POS was unchanged. */
2169 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte
, Sset_buffer_multibyte
,
2171 doc
: /* Set the multibyte flag of the current buffer to FLAG.
2172 If FLAG is t, this makes the buffer a multibyte buffer.
2173 If FLAG is nil, this makes the buffer a single-byte buffer.
2174 The buffer contents remain unchanged as a sequence of bytes
2175 but the contents viewed as characters do change.
2176 If the multibyte flag was really changed, undo information of the
2177 current buffer is cleared. */)
2181 struct Lisp_Marker
*tail
, *markers
;
2182 struct buffer
*other
;
2184 int narrowed
= (BEG
!= BEGV
|| Z
!= ZV
);
2185 int modified_p
= !NILP (Fbuffer_modified_p (Qnil
));
2186 Lisp_Object old_undo
= current_buffer
->undo_list
;
2187 struct gcpro gcpro1
;
2189 if (current_buffer
->base_buffer
)
2190 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
2192 /* Do nothing if nothing actually changes. */
2193 if (NILP (flag
) == NILP (current_buffer
->enable_multibyte_characters
))
2198 /* Don't record these buffer changes. We will put a special undo entry
2200 current_buffer
->undo_list
= Qt
;
2202 /* If the cached position is for this buffer, clear it out. */
2203 clear_charpos_cache (current_buffer
);
2206 begv
= BEGV_BYTE
, zv
= ZV_BYTE
;
2208 begv
= BEGV
, zv
= ZV
;
2218 /* Do this first, so it can use CHAR_TO_BYTE
2219 to calculate the old correspondences. */
2220 set_intervals_multibyte (0);
2222 current_buffer
->enable_multibyte_characters
= Qnil
;
2228 TEMP_SET_PT_BOTH (PT_BYTE
, PT_BYTE
);
2231 for (tail
= BUF_MARKERS (current_buffer
); tail
; tail
= tail
->next
)
2232 tail
->charpos
= tail
->bytepos
;
2234 /* Convert multibyte form of 8-bit characters to unibyte. */
2249 if (MULTIBYTE_STR_AS_UNIBYTE_P (p
, bytes
))
2250 p
+= bytes
, pos
+= bytes
;
2253 c
= STRING_CHAR (p
, stop
- pos
);
2254 /* Delete all bytes for this 8-bit character but the
2255 last one, and change the last one to the charcter
2258 del_range_2 (pos
, pos
, pos
+ bytes
, pos
+ bytes
, 0);
2270 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2278 /* Be sure not to have a multibyte sequence striding over the GAP.
2279 Ex: We change this: "...abc\201 _GAP_ \241def..."
2280 to: "...abc _GAP_ \201\241def..." */
2282 if (GPT_BYTE
> 1 && GPT_BYTE
< Z_BYTE
2283 && ! CHAR_HEAD_P (*(GAP_END_ADDR
)))
2285 unsigned char *p
= GPT_ADDR
- 1;
2287 while (! CHAR_HEAD_P (*p
) && p
> BEG_ADDR
) p
--;
2288 if (BASE_LEADING_CODE_P (*p
))
2290 int new_gpt
= GPT_BYTE
- (GPT_ADDR
- p
);
2292 move_gap_both (new_gpt
, new_gpt
);
2296 /* Make the buffer contents valid as multibyte by converting
2297 8-bit characters to multibyte form. */
2313 if (UNIBYTE_STR_AS_MULTIBYTE_P (p
, stop
- pos
, bytes
))
2314 p
+= bytes
, pos
+= bytes
;
2317 unsigned char tmp
[MAX_MULTIBYTE_LENGTH
];
2319 bytes
= CHAR_STRING (*p
, tmp
);
2321 TEMP_SET_PT_BOTH (pos
+ 1, pos
+ 1);
2323 insert_1_both (tmp
+ 1, bytes
, bytes
, 1, 0, 0);
2324 /* Now the gap is after the just inserted data. */
2341 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2343 /* Do this first, so that chars_in_text asks the right question.
2344 set_intervals_multibyte needs it too. */
2345 current_buffer
->enable_multibyte_characters
= Qt
;
2347 GPT_BYTE
= advance_to_char_boundary (GPT_BYTE
);
2348 GPT
= chars_in_text (BEG_ADDR
, GPT_BYTE
- BEG_BYTE
) + BEG
;
2350 Z
= chars_in_text (GAP_END_ADDR
, Z_BYTE
- GPT_BYTE
) + GPT
;
2352 BEGV_BYTE
= advance_to_char_boundary (BEGV_BYTE
);
2353 if (BEGV_BYTE
> GPT_BYTE
)
2354 BEGV
= chars_in_text (GAP_END_ADDR
, BEGV_BYTE
- GPT_BYTE
) + GPT
;
2356 BEGV
= chars_in_text (BEG_ADDR
, BEGV_BYTE
- BEG_BYTE
) + BEG
;
2358 ZV_BYTE
= advance_to_char_boundary (ZV_BYTE
);
2359 if (ZV_BYTE
> GPT_BYTE
)
2360 ZV
= chars_in_text (GAP_END_ADDR
, ZV_BYTE
- GPT_BYTE
) + GPT
;
2362 ZV
= chars_in_text (BEG_ADDR
, ZV_BYTE
- BEG_BYTE
) + BEG
;
2365 int pt_byte
= advance_to_char_boundary (PT_BYTE
);
2368 if (pt_byte
> GPT_BYTE
)
2369 pt
= chars_in_text (GAP_END_ADDR
, pt_byte
- GPT_BYTE
) + GPT
;
2371 pt
= chars_in_text (BEG_ADDR
, pt_byte
- BEG_BYTE
) + BEG
;
2372 TEMP_SET_PT_BOTH (pt
, pt_byte
);
2375 tail
= markers
= BUF_MARKERS (current_buffer
);
2377 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
2378 getting confused by the markers that have not yet been updated.
2379 It is also a signal that it should never create a marker. */
2380 BUF_MARKERS (current_buffer
) = NULL
;
2382 for (; tail
; tail
= tail
->next
)
2384 tail
->bytepos
= advance_to_char_boundary (tail
->bytepos
);
2385 tail
->charpos
= BYTE_TO_CHAR (tail
->bytepos
);
2388 /* Make sure no markers were put on the chain
2389 while the chain value was incorrect. */
2390 if (BUF_MARKERS (current_buffer
))
2393 BUF_MARKERS (current_buffer
) = markers
;
2395 /* Do this last, so it can calculate the new correspondences
2396 between chars and bytes. */
2397 set_intervals_multibyte (1);
2400 if (!EQ (old_undo
, Qt
))
2402 /* Represent all the above changes by a special undo entry. */
2403 extern Lisp_Object Qapply
;
2404 current_buffer
->undo_list
= Fcons (list3 (Qapply
,
2405 intern ("set-buffer-multibyte"),
2406 NILP (flag
) ? Qt
: Qnil
),
2412 /* Changing the multibyteness of a buffer means that all windows
2413 showing that buffer must be updated thoroughly. */
2414 current_buffer
->prevent_redisplay_optimizations_p
= 1;
2415 ++windows_or_buffers_changed
;
2417 /* Copy this buffer's new multibyte status
2418 into all of its indirect buffers. */
2419 for (other
= all_buffers
; other
; other
= other
->next
)
2420 if (other
->base_buffer
== current_buffer
&& !NILP (other
->name
))
2422 other
->enable_multibyte_characters
2423 = current_buffer
->enable_multibyte_characters
;
2424 other
->prevent_redisplay_optimizations_p
= 1;
2427 /* Restore the modifiedness of the buffer. */
2428 if (!modified_p
&& !NILP (Fbuffer_modified_p (Qnil
)))
2429 Fset_buffer_modified_p (Qnil
);
2432 /* Update coding systems of this buffer's process (if any). */
2434 Lisp_Object process
;
2436 process
= Fget_buffer_process (Fcurrent_buffer ());
2437 if (PROCESSP (process
))
2438 setup_process_coding_systems (process
);
2440 #endif /* subprocesses */
2445 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
2447 doc
: /* Switch to Fundamental mode by killing current buffer's local variables.
2448 Most local variable bindings are eliminated so that the default values
2449 become effective once more. Also, the syntax table is set from
2450 `standard-syntax-table', the local keymap is set to nil,
2451 and the abbrev table from `fundamental-mode-abbrev-table'.
2452 This function also forces redisplay of the mode line.
2454 Every function to select a new major mode starts by
2455 calling this function.
2457 As a special exception, local variables whose names have
2458 a non-nil `permanent-local' property are not eliminated by this function.
2460 The first thing this function does is run
2461 the normal hook `change-major-mode-hook'. */)
2464 register Lisp_Object alist
, sym
, tem
;
2467 if (!NILP (Vrun_hooks
))
2468 call1 (Vrun_hooks
, Qchange_major_mode_hook
);
2469 oalist
= current_buffer
->local_var_alist
;
2471 /* Make sure none of the bindings in oalist
2472 remain swapped in, in their symbols. */
2474 swap_out_buffer_local_variables (current_buffer
);
2476 /* Actually eliminate all local bindings of this buffer. */
2478 reset_buffer_local_variables (current_buffer
, 0);
2480 /* Any which are supposed to be permanent,
2481 make local again, with the same values they had. */
2483 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
2485 sym
= XCAR (XCAR (alist
));
2486 tem
= Fget (sym
, Qpermanent_local
);
2489 Fmake_local_variable (sym
);
2490 Fset (sym
, XCDR (XCAR (alist
)));
2494 /* Force mode-line redisplay. Useful here because all major mode
2495 commands call this function. */
2496 update_mode_lines
++;
2501 /* Make sure no local variables remain set up with buffer B
2502 for their current values. */
2505 swap_out_buffer_local_variables (b
)
2508 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
2510 XSETBUFFER (buffer
, b
);
2511 oalist
= b
->local_var_alist
;
2513 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
2515 sym
= XCAR (XCAR (alist
));
2517 /* Need not do anything if some other buffer's binding is now encached. */
2518 tem
= XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->buffer
;
2519 if (BUFFERP (tem
) && XBUFFER (tem
) == current_buffer
)
2521 /* Symbol is set up for this buffer's old local value.
2522 Set it up for the current buffer with the default value. */
2524 tem
= XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->cdr
;
2525 /* Store the symbol's current value into the alist entry
2526 it is currently set up for. This is so that, if the
2527 local is marked permanent, and we make it local again
2528 later in Fkill_all_local_variables, we don't lose the value. */
2529 XSETCDR (XCAR (tem
),
2530 do_symval_forwarding (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->realvalue
));
2531 /* Switch to the symbol's default-value alist entry. */
2533 /* Mark it as current for buffer B. */
2534 XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->buffer
= buffer
;
2535 /* Store the current value into any forwarding in the symbol. */
2536 store_symval_forwarding (sym
,
2537 XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->realvalue
,
2543 /* Find all the overlays in the current buffer that contain position POS.
2544 Return the number found, and store them in a vector in *VEC_PTR.
2545 Store in *LEN_PTR the size allocated for the vector.
2546 Store in *NEXT_PTR the next position after POS where an overlay starts,
2547 or ZV if there are no more overlays between POS and ZV.
2548 Store in *PREV_PTR the previous position before POS where an overlay ends,
2549 or where an overlay starts which ends at or after POS;
2550 or BEGV if there are no such overlays from BEGV to POS.
2551 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2553 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2554 when this function is called.
2556 If EXTEND is non-zero, we make the vector bigger if necessary.
2557 If EXTEND is zero, we never extend the vector,
2558 and we store only as many overlays as will fit.
2559 But we still return the total number of overlays.
2561 If CHANGE_REQ is true, then any position written into *PREV_PTR or
2562 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2563 default (BEGV or ZV). */
2566 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
, change_req
)
2569 Lisp_Object
**vec_ptr
;
2575 Lisp_Object overlay
, start
, end
;
2576 struct Lisp_Overlay
*tail
;
2579 Lisp_Object
*vec
= *vec_ptr
;
2582 int inhibit_storing
= 0;
2584 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2586 int startpos
, endpos
;
2588 XSETMISC (overlay
, tail
);
2590 start
= OVERLAY_START (overlay
);
2591 end
= OVERLAY_END (overlay
);
2592 endpos
= OVERLAY_POSITION (end
);
2599 startpos
= OVERLAY_POSITION (start
);
2600 /* This one ends at or after POS
2601 so its start counts for PREV_PTR if it's before POS. */
2602 if (prev
< startpos
&& startpos
< pos
)
2606 if (startpos
<= pos
)
2610 /* The supplied vector is full.
2611 Either make it bigger, or don't store any more in it. */
2614 /* Make it work with an initial len == 0. */
2619 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2623 inhibit_storing
= 1;
2626 if (!inhibit_storing
)
2628 /* Keep counting overlays even if we can't return them all. */
2631 else if (startpos
< next
)
2635 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2637 int startpos
, endpos
;
2639 XSETMISC (overlay
, tail
);
2641 start
= OVERLAY_START (overlay
);
2642 end
= OVERLAY_END (overlay
);
2643 startpos
= OVERLAY_POSITION (start
);
2646 if (startpos
< next
)
2650 endpos
= OVERLAY_POSITION (end
);
2657 /* Make it work with an initial len == 0. */
2662 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2666 inhibit_storing
= 1;
2669 if (!inhibit_storing
)
2673 if (startpos
< pos
&& startpos
> prev
)
2676 else if (endpos
< pos
&& endpos
> prev
)
2678 else if (endpos
== pos
&& startpos
> prev
2679 && (!change_req
|| startpos
< pos
))
2690 /* Find all the overlays in the current buffer that overlap the range BEG-END
2691 or are empty at BEG.
2693 Return the number found, and store them in a vector in *VEC_PTR.
2694 Store in *LEN_PTR the size allocated for the vector.
2695 Store in *NEXT_PTR the next position after POS where an overlay starts,
2696 or ZV if there are no more overlays.
2697 Store in *PREV_PTR the previous position before POS where an overlay ends,
2698 or BEGV if there are no previous overlays.
2699 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2701 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2702 when this function is called.
2704 If EXTEND is non-zero, we make the vector bigger if necessary.
2705 If EXTEND is zero, we never extend the vector,
2706 and we store only as many overlays as will fit.
2707 But we still return the total number of overlays. */
2710 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2713 Lisp_Object
**vec_ptr
;
2718 Lisp_Object overlay
, ostart
, oend
;
2719 struct Lisp_Overlay
*tail
;
2722 Lisp_Object
*vec
= *vec_ptr
;
2725 int inhibit_storing
= 0;
2727 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2729 int startpos
, endpos
;
2731 XSETMISC (overlay
, tail
);
2733 ostart
= OVERLAY_START (overlay
);
2734 oend
= OVERLAY_END (overlay
);
2735 endpos
= OVERLAY_POSITION (oend
);
2742 startpos
= OVERLAY_POSITION (ostart
);
2743 /* Count an interval if it either overlaps the range
2744 or is empty at the start of the range. */
2745 if ((beg
< endpos
&& startpos
< end
)
2746 || (startpos
== endpos
&& beg
== endpos
))
2750 /* The supplied vector is full.
2751 Either make it bigger, or don't store any more in it. */
2754 /* Make it work with an initial len == 0. */
2759 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2763 inhibit_storing
= 1;
2766 if (!inhibit_storing
)
2768 /* Keep counting overlays even if we can't return them all. */
2771 else if (startpos
< next
)
2775 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2777 int startpos
, endpos
;
2779 XSETMISC (overlay
, tail
);
2781 ostart
= OVERLAY_START (overlay
);
2782 oend
= OVERLAY_END (overlay
);
2783 startpos
= OVERLAY_POSITION (ostart
);
2786 if (startpos
< next
)
2790 endpos
= OVERLAY_POSITION (oend
);
2791 /* Count an interval if it either overlaps the range
2792 or is empty at the start of the range. */
2793 if ((beg
< endpos
&& startpos
< end
)
2794 || (startpos
== endpos
&& beg
== endpos
))
2800 /* Make it work with an initial len == 0. */
2805 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2809 inhibit_storing
= 1;
2812 if (!inhibit_storing
)
2816 else if (endpos
< beg
&& endpos
> prev
)
2828 /* Return non-zero if there exists an overlay with a non-nil
2829 `mouse-face' property overlapping OVERLAY. */
2832 mouse_face_overlay_overlaps (overlay
)
2833 Lisp_Object overlay
;
2835 int start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2836 int end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2838 Lisp_Object
*v
, tem
;
2841 v
= (Lisp_Object
*) alloca (size
* sizeof *v
);
2842 n
= overlays_in (start
, end
, 0, &v
, &size
, NULL
, NULL
);
2845 v
= (Lisp_Object
*) alloca (n
* sizeof *v
);
2846 overlays_in (start
, end
, 0, &v
, &n
, NULL
, NULL
);
2849 for (i
= 0; i
< n
; ++i
)
2850 if (!EQ (v
[i
], overlay
)
2851 && (tem
= Foverlay_get (overlay
, Qmouse_face
),
2860 /* Fast function to just test if we're at an overlay boundary. */
2862 overlay_touches_p (pos
)
2865 Lisp_Object overlay
;
2866 struct Lisp_Overlay
*tail
;
2868 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2872 XSETMISC (overlay
,tail
);
2873 if (!GC_OVERLAYP (overlay
))
2876 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2879 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2883 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2887 XSETMISC (overlay
, tail
);
2888 if (!GC_OVERLAYP (overlay
))
2891 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2894 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2902 Lisp_Object overlay
;
2908 compare_overlays (v1
, v2
)
2909 const void *v1
, *v2
;
2911 const struct sortvec
*s1
= (const struct sortvec
*) v1
;
2912 const struct sortvec
*s2
= (const struct sortvec
*) v2
;
2913 if (s1
->priority
!= s2
->priority
)
2914 return s1
->priority
- s2
->priority
;
2915 if (s1
->beg
!= s2
->beg
)
2916 return s1
->beg
- s2
->beg
;
2917 if (s1
->end
!= s2
->end
)
2918 return s2
->end
- s1
->end
;
2922 /* Sort an array of overlays by priority. The array is modified in place.
2923 The return value is the new size; this may be smaller than the original
2924 size if some of the overlays were invalid or were window-specific. */
2926 sort_overlays (overlay_vec
, noverlays
, w
)
2927 Lisp_Object
*overlay_vec
;
2932 struct sortvec
*sortvec
;
2933 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2935 /* Put the valid and relevant overlays into sortvec. */
2937 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2940 Lisp_Object overlay
;
2942 overlay
= overlay_vec
[i
];
2943 if (OVERLAY_VALID (overlay
)
2944 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2945 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2947 /* If we're interested in a specific window, then ignore
2948 overlays that are limited to some other window. */
2953 window
= Foverlay_get (overlay
, Qwindow
);
2954 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2958 /* This overlay is good and counts: put it into sortvec. */
2959 sortvec
[j
].overlay
= overlay
;
2960 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2961 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2962 tem
= Foverlay_get (overlay
, Qpriority
);
2964 sortvec
[j
].priority
= XINT (tem
);
2966 sortvec
[j
].priority
= 0;
2972 /* Sort the overlays into the proper order: increasing priority. */
2975 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2977 for (i
= 0; i
< noverlays
; i
++)
2978 overlay_vec
[i
] = sortvec
[i
].overlay
;
2984 Lisp_Object string
, string2
;
2991 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2992 int size
; /* Allocated length of that array. */
2993 int used
; /* How much of the array is currently in use. */
2994 int bytes
; /* Total length of the strings in buf. */
2997 /* Buffers for storing information about the overlays touching a given
2998 position. These could be automatic variables in overlay_strings, but
2999 it's more efficient to hold onto the memory instead of repeatedly
3000 allocating and freeing it. */
3001 static struct sortstrlist overlay_heads
, overlay_tails
;
3002 static unsigned char *overlay_str_buf
;
3004 /* Allocated length of overlay_str_buf. */
3005 static int overlay_str_len
;
3007 /* A comparison function suitable for passing to qsort. */
3009 cmp_for_strings (as1
, as2
)
3012 struct sortstr
*s1
= (struct sortstr
*)as1
;
3013 struct sortstr
*s2
= (struct sortstr
*)as2
;
3014 if (s1
->size
!= s2
->size
)
3015 return s2
->size
- s1
->size
;
3016 if (s1
->priority
!= s2
->priority
)
3017 return s1
->priority
- s2
->priority
;
3022 record_overlay_string (ssl
, str
, str2
, pri
, size
)
3023 struct sortstrlist
*ssl
;
3024 Lisp_Object str
, str2
, pri
;
3029 if (ssl
->used
== ssl
->size
)
3035 ssl
->buf
= ((struct sortstr
*)
3036 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
3038 ssl
->buf
[ssl
->used
].string
= str
;
3039 ssl
->buf
[ssl
->used
].string2
= str2
;
3040 ssl
->buf
[ssl
->used
].size
= size
;
3041 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
3044 if (NILP (current_buffer
->enable_multibyte_characters
))
3045 nbytes
= SCHARS (str
);
3046 else if (! STRING_MULTIBYTE (str
))
3047 nbytes
= count_size_as_multibyte (SDATA (str
),
3050 nbytes
= SBYTES (str
);
3052 ssl
->bytes
+= nbytes
;
3056 if (NILP (current_buffer
->enable_multibyte_characters
))
3057 nbytes
= SCHARS (str2
);
3058 else if (! STRING_MULTIBYTE (str2
))
3059 nbytes
= count_size_as_multibyte (SDATA (str2
),
3062 nbytes
= SBYTES (str2
);
3064 ssl
->bytes
+= nbytes
;
3068 /* Return the concatenation of the strings associated with overlays that
3069 begin or end at POS, ignoring overlays that are specific to a window
3070 other than W. The strings are concatenated in the appropriate order:
3071 shorter overlays nest inside longer ones, and higher priority inside
3072 lower. Normally all of the after-strings come first, but zero-sized
3073 overlays have their after-strings ride along with the before-strings
3074 because it would look strange to print them inside-out.
3076 Returns the string length, and stores the contents indirectly through
3077 PSTR, if that variable is non-null. The string may be overwritten by
3078 subsequent calls. */
3081 overlay_strings (pos
, w
, pstr
)
3084 unsigned char **pstr
;
3086 Lisp_Object overlay
, window
, str
;
3087 struct Lisp_Overlay
*ov
;
3088 int startpos
, endpos
;
3089 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
3091 overlay_heads
.used
= overlay_heads
.bytes
= 0;
3092 overlay_tails
.used
= overlay_tails
.bytes
= 0;
3093 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
3095 XSETMISC (overlay
, ov
);
3096 eassert (OVERLAYP (overlay
));
3098 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3099 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3102 if (endpos
!= pos
&& startpos
!= pos
)
3104 window
= Foverlay_get (overlay
, Qwindow
);
3105 if (WINDOWP (window
) && XWINDOW (window
) != w
)
3108 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
3109 record_overlay_string (&overlay_heads
, str
,
3111 ? Foverlay_get (overlay
, Qafter_string
)
3113 Foverlay_get (overlay
, Qpriority
),
3115 else if (endpos
== pos
3116 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
3117 record_overlay_string (&overlay_tails
, str
, Qnil
,
3118 Foverlay_get (overlay
, Qpriority
),
3121 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
3123 XSETMISC (overlay
, ov
);
3124 eassert (OVERLAYP (overlay
));
3126 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3127 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3130 if (endpos
!= pos
&& startpos
!= pos
)
3132 window
= Foverlay_get (overlay
, Qwindow
);
3133 if (WINDOWP (window
) && XWINDOW (window
) != w
)
3136 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
3137 record_overlay_string (&overlay_heads
, str
,
3139 ? Foverlay_get (overlay
, Qafter_string
)
3141 Foverlay_get (overlay
, Qpriority
),
3143 else if (endpos
== pos
3144 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
3145 record_overlay_string (&overlay_tails
, str
, Qnil
,
3146 Foverlay_get (overlay
, Qpriority
),
3149 if (overlay_tails
.used
> 1)
3150 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
3152 if (overlay_heads
.used
> 1)
3153 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
3155 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
3160 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
3162 if (total
> overlay_str_len
)
3164 overlay_str_len
= total
;
3165 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
3168 p
= overlay_str_buf
;
3169 for (i
= overlay_tails
.used
; --i
>= 0;)
3172 tem
= overlay_tails
.buf
[i
].string
;
3173 nbytes
= copy_text (SDATA (tem
), p
,
3175 STRING_MULTIBYTE (tem
), multibyte
);
3178 for (i
= 0; i
< overlay_heads
.used
; ++i
)
3181 tem
= overlay_heads
.buf
[i
].string
;
3182 nbytes
= copy_text (SDATA (tem
), p
,
3184 STRING_MULTIBYTE (tem
), multibyte
);
3186 tem
= overlay_heads
.buf
[i
].string2
;
3189 nbytes
= copy_text (SDATA (tem
), p
,
3191 STRING_MULTIBYTE (tem
), multibyte
);
3195 if (p
!= overlay_str_buf
+ total
)
3198 *pstr
= overlay_str_buf
;
3204 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3207 recenter_overlay_lists (buf
, pos
)
3211 Lisp_Object overlay
, beg
, end
;
3212 struct Lisp_Overlay
*prev
, *tail
, *next
;
3214 /* See if anything in overlays_before should move to overlays_after. */
3216 /* We don't strictly need prev in this loop; it should always be nil.
3217 But we use it for symmetry and in case that should cease to be true
3218 with some future change. */
3220 for (tail
= buf
->overlays_before
; tail
; prev
= tail
, tail
= next
)
3223 XSETMISC (overlay
, tail
);
3225 /* If the overlay is not valid, get rid of it. */
3226 if (!OVERLAY_VALID (overlay
))
3231 /* Splice the cons cell TAIL out of overlays_before. */
3235 buf
->overlays_before
= next
;
3241 beg
= OVERLAY_START (overlay
);
3242 end
= OVERLAY_END (overlay
);
3244 if (OVERLAY_POSITION (end
) > pos
)
3246 /* OVERLAY needs to be moved. */
3247 int where
= OVERLAY_POSITION (beg
);
3248 struct Lisp_Overlay
*other
, *other_prev
;
3250 /* Splice the cons cell TAIL out of overlays_before. */
3254 buf
->overlays_before
= next
;
3256 /* Search thru overlays_after for where to put it. */
3258 for (other
= buf
->overlays_after
; other
;
3259 other_prev
= other
, other
= other
->next
)
3261 Lisp_Object otherbeg
, otheroverlay
;
3263 XSETMISC (otheroverlay
, other
);
3264 eassert (OVERLAY_VALID (otheroverlay
));
3266 otherbeg
= OVERLAY_START (otheroverlay
);
3267 if (OVERLAY_POSITION (otherbeg
) >= where
)
3271 /* Add TAIL to overlays_after before OTHER. */
3274 other_prev
->next
= tail
;
3276 buf
->overlays_after
= tail
;
3280 /* We've reached the things that should stay in overlays_before.
3281 All the rest of overlays_before must end even earlier,
3286 /* See if anything in overlays_after should be in overlays_before. */
3288 for (tail
= buf
->overlays_after
; tail
; prev
= tail
, tail
= next
)
3291 XSETMISC (overlay
, tail
);
3293 /* If the overlay is not valid, get rid of it. */
3294 if (!OVERLAY_VALID (overlay
))
3299 /* Splice the cons cell TAIL out of overlays_after. */
3303 buf
->overlays_after
= next
;
3309 beg
= OVERLAY_START (overlay
);
3310 end
= OVERLAY_END (overlay
);
3312 /* Stop looking, when we know that nothing further
3313 can possibly end before POS. */
3314 if (OVERLAY_POSITION (beg
) > pos
)
3317 if (OVERLAY_POSITION (end
) <= pos
)
3319 /* OVERLAY needs to be moved. */
3320 int where
= OVERLAY_POSITION (end
);
3321 struct Lisp_Overlay
*other
, *other_prev
;
3323 /* Splice the cons cell TAIL out of overlays_after. */
3327 buf
->overlays_after
= next
;
3329 /* Search thru overlays_before for where to put it. */
3331 for (other
= buf
->overlays_before
; other
;
3332 other_prev
= other
, other
= other
->next
)
3334 Lisp_Object otherend
, otheroverlay
;
3336 XSETMISC (otheroverlay
, other
);
3337 eassert (OVERLAY_VALID (otheroverlay
));
3339 otherend
= OVERLAY_END (otheroverlay
);
3340 if (OVERLAY_POSITION (otherend
) <= where
)
3344 /* Add TAIL to overlays_before before OTHER. */
3347 other_prev
->next
= tail
;
3349 buf
->overlays_before
= tail
;
3354 buf
->overlay_center
= pos
;
3358 adjust_overlays_for_insert (pos
, length
)
3362 /* After an insertion, the lists are still sorted properly,
3363 but we may need to update the value of the overlay center. */
3364 if (current_buffer
->overlay_center
>= pos
)
3365 current_buffer
->overlay_center
+= length
;
3369 adjust_overlays_for_delete (pos
, length
)
3373 if (current_buffer
->overlay_center
< pos
)
3374 /* The deletion was to our right. No change needed; the before- and
3375 after-lists are still consistent. */
3377 else if (current_buffer
->overlay_center
> pos
+ length
)
3378 /* The deletion was to our left. We need to adjust the center value
3379 to account for the change in position, but the lists are consistent
3380 given the new value. */
3381 current_buffer
->overlay_center
-= length
;
3383 /* We're right in the middle. There might be things on the after-list
3384 that now belong on the before-list. Recentering will move them,
3385 and also update the center point. */
3386 recenter_overlay_lists (current_buffer
, pos
);
3389 /* Fix up overlays that were garbled as a result of permuting markers
3390 in the range START through END. Any overlay with at least one
3391 endpoint in this range will need to be unlinked from the overlay
3392 list and reinserted in its proper place.
3393 Such an overlay might even have negative size at this point.
3394 If so, we'll make the overlay empty. */
3396 fix_start_end_in_overlays (start
, end
)
3397 register int start
, end
;
3399 Lisp_Object overlay
;
3400 struct Lisp_Overlay
*before_list
, *after_list
;
3401 /* These are either nil, indicating that before_list or after_list
3402 should be assigned, or the cons cell the cdr of which should be
3404 struct Lisp_Overlay
*beforep
= NULL
, *afterp
= NULL
;
3405 /* 'Parent', likewise, indicates a cons cell or
3406 current_buffer->overlays_before or overlays_after, depending
3407 which loop we're in. */
3408 struct Lisp_Overlay
*tail
, *parent
;
3409 int startpos
, endpos
;
3411 /* This algorithm shifts links around instead of consing and GCing.
3412 The loop invariant is that before_list (resp. after_list) is a
3413 well-formed list except that its last element, the CDR of beforep
3414 (resp. afterp) if beforep (afterp) isn't nil or before_list
3415 (after_list) if it is, is still uninitialized. So it's not a bug
3416 that before_list isn't initialized, although it may look
3418 for (parent
= NULL
, tail
= current_buffer
->overlays_before
; tail
;)
3420 XSETMISC (overlay
, tail
);
3422 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3423 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3425 /* If the overlay is backwards, make it empty. */
3426 if (endpos
< startpos
)
3429 Fset_marker (OVERLAY_START (overlay
), make_number (startpos
),
3437 || (startpos
>= start
&& startpos
< end
))
3439 /* Add it to the end of the wrong list. Later on,
3440 recenter_overlay_lists will move it to the right place. */
3441 if (endpos
< current_buffer
->overlay_center
)
3446 afterp
->next
= tail
;
3454 beforep
->next
= tail
;
3458 current_buffer
->overlays_before
= tail
->next
;
3460 parent
->next
= tail
->next
;
3464 parent
= tail
, tail
= parent
->next
;
3466 for (parent
= NULL
, tail
= current_buffer
->overlays_after
; tail
;)
3468 XSETMISC (overlay
, tail
);
3470 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3471 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3473 /* If the overlay is backwards, make it empty. */
3474 if (endpos
< startpos
)
3477 Fset_marker (OVERLAY_START (overlay
), make_number (startpos
),
3481 if (startpos
>= end
)
3484 if (startpos
>= start
3485 || (endpos
>= start
&& endpos
< end
))
3487 if (endpos
< current_buffer
->overlay_center
)
3492 afterp
->next
= tail
;
3500 beforep
->next
= tail
;
3504 current_buffer
->overlays_after
= tail
->next
;
3506 parent
->next
= tail
->next
;
3510 parent
= tail
, tail
= parent
->next
;
3513 /* Splice the constructed (wrong) lists into the buffer's lists,
3514 and let the recenter function make it sane again. */
3517 beforep
->next
= current_buffer
->overlays_before
;
3518 current_buffer
->overlays_before
= before_list
;
3520 recenter_overlay_lists (current_buffer
, current_buffer
->overlay_center
);
3524 afterp
->next
= current_buffer
->overlays_after
;
3525 current_buffer
->overlays_after
= after_list
;
3527 recenter_overlay_lists (current_buffer
, current_buffer
->overlay_center
);
3530 /* We have two types of overlay: the one whose ending marker is
3531 after-insertion-marker (this is the usual case) and the one whose
3532 ending marker is before-insertion-marker. When `overlays_before'
3533 contains overlays of the latter type and the former type in this
3534 order and both overlays end at inserting position, inserting a text
3535 increases only the ending marker of the latter type, which results
3536 in incorrect ordering of `overlays_before'.
3538 This function fixes ordering of overlays in the slot
3539 `overlays_before' of the buffer *BP. Before the insertion, `point'
3540 was at PREV, and now is at POS. */
3543 fix_overlays_before (bp
, prev
, pos
)
3545 EMACS_INT prev
, pos
;
3547 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3548 struct Lisp_Overlay
*tail
= bp
->overlays_before
, *parent
= NULL
, *right_pair
;
3552 /* After the insertion, the several overlays may be in incorrect
3553 order. The possibility is that, in the list `overlays_before',
3554 an overlay which ends at POS appears after an overlay which ends
3555 at PREV. Since POS is greater than PREV, we must fix the
3556 ordering of these overlays, by moving overlays ends at POS before
3557 the overlays ends at PREV. */
3559 /* At first, find a place where disordered overlays should be linked
3560 in. It is where an overlay which end before POS exists. (i.e. an
3561 overlay whose ending marker is after-insertion-marker if disorder
3564 && (XSETMISC (tem
, tail
),
3565 (end
= OVERLAY_POSITION (OVERLAY_END (tem
))) >= pos
))
3571 /* If we don't find such an overlay,
3572 or the found one ends before PREV,
3573 or the found one is the last one in the list,
3574 we don't have to fix anything. */
3575 if (!tail
|| end
< prev
|| !tail
->next
)
3578 right_pair
= parent
;
3582 /* Now, end position of overlays in the list TAIL should be before
3583 or equal to PREV. In the loop, an overlay which ends at POS is
3584 moved ahead to the place indicated by the CDR of RIGHT_PAIR. If
3585 we found an overlay which ends before PREV, the remaining
3586 overlays are in correct order. */
3589 XSETMISC (tem
, tail
);
3590 end
= OVERLAY_POSITION (OVERLAY_END (tem
));
3593 { /* This overlay is disordered. */
3594 struct Lisp_Overlay
*found
= tail
;
3596 /* Unlink the found overlay. */
3598 parent
->next
= tail
;
3599 /* Move an overlay at RIGHT_PLACE to the next of the found one,
3600 and link it into the right place. */
3603 found
->next
= bp
->overlays_before
;
3604 bp
->overlays_before
= found
;
3608 found
->next
= right_pair
->next
;
3609 right_pair
->next
= found
;
3612 else if (end
== prev
)
3617 else /* No more disordered overlay. */
3622 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
3623 doc
: /* Return t if OBJECT is an overlay. */)
3627 return (OVERLAYP (object
) ? Qt
: Qnil
);
3630 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
3631 doc
: /* Create a new overlay with range BEG to END in BUFFER.
3632 If omitted, BUFFER defaults to the current buffer.
3633 BEG and END may be integers or markers.
3634 The fourth arg FRONT-ADVANCE, if non-nil, makes the marker
3635 for the front of the overlay advance when text is inserted there
3636 \(which means the text *is not* included in the overlay).
3637 The fifth arg REAR-ADVANCE, if non-nil, makes the marker
3638 for the rear of the overlay advance when text is inserted there
3639 \(which means the text *is* included in the overlay). */)
3640 (beg
, end
, buffer
, front_advance
, rear_advance
)
3641 Lisp_Object beg
, end
, buffer
;
3642 Lisp_Object front_advance
, rear_advance
;
3644 Lisp_Object overlay
;
3648 XSETBUFFER (buffer
, current_buffer
);
3650 CHECK_BUFFER (buffer
);
3652 && ! EQ (Fmarker_buffer (beg
), buffer
))
3653 error ("Marker points into wrong buffer");
3655 && ! EQ (Fmarker_buffer (end
), buffer
))
3656 error ("Marker points into wrong buffer");
3658 CHECK_NUMBER_COERCE_MARKER (beg
);
3659 CHECK_NUMBER_COERCE_MARKER (end
);
3661 if (XINT (beg
) > XINT (end
))
3664 temp
= beg
; beg
= end
; end
= temp
;
3667 b
= XBUFFER (buffer
);
3669 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
3670 end
= Fset_marker (Fmake_marker (), end
, buffer
);
3672 if (!NILP (front_advance
))
3673 XMARKER (beg
)->insertion_type
= 1;
3674 if (!NILP (rear_advance
))
3675 XMARKER (end
)->insertion_type
= 1;
3677 overlay
= allocate_misc ();
3678 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
3679 XOVERLAY (overlay
)->start
= beg
;
3680 XOVERLAY (overlay
)->end
= end
;
3681 XOVERLAY (overlay
)->plist
= Qnil
;
3682 XOVERLAY (overlay
)->next
= NULL
;
3684 /* Put the new overlay on the wrong list. */
3685 end
= OVERLAY_END (overlay
);
3686 if (OVERLAY_POSITION (end
) < b
->overlay_center
)
3688 if (b
->overlays_after
)
3689 XOVERLAY (overlay
)->next
= b
->overlays_after
;
3690 b
->overlays_after
= XOVERLAY (overlay
);
3694 if (b
->overlays_before
)
3695 XOVERLAY (overlay
)->next
= b
->overlays_before
;
3696 b
->overlays_before
= XOVERLAY (overlay
);
3699 /* This puts it in the right list, and in the right order. */
3700 recenter_overlay_lists (b
, b
->overlay_center
);
3702 /* We don't need to redisplay the region covered by the overlay, because
3703 the overlay has no properties at the moment. */
3708 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3711 modify_overlay (buf
, start
, end
)
3713 EMACS_INT start
, end
;
3722 BUF_COMPUTE_UNCHANGED (buf
, start
, end
);
3724 /* If this is a buffer not in the selected window,
3725 we must do other windows. */
3726 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
3727 windows_or_buffers_changed
= 1;
3728 /* If multiple windows show this buffer, we must do other windows. */
3729 else if (buffer_shared
> 1)
3730 windows_or_buffers_changed
= 1;
3731 /* If we modify an overlay at the end of the buffer, we cannot
3732 be sure that window end is still valid. */
3733 else if (end
>= ZV
&& start
<= ZV
)
3734 windows_or_buffers_changed
= 1;
3736 ++BUF_OVERLAY_MODIFF (buf
);
3740 Lisp_Object
Fdelete_overlay ();
3742 static struct Lisp_Overlay
*
3743 unchain_overlay (list
, overlay
)
3744 struct Lisp_Overlay
*list
, *overlay
;
3746 struct Lisp_Overlay
*tmp
, *prev
;
3747 for (tmp
= list
, prev
= NULL
; tmp
; prev
= tmp
, tmp
= tmp
->next
)
3751 prev
->next
= tmp
->next
;
3754 overlay
->next
= NULL
;
3760 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
3761 doc
: /* Set the endpoints of OVERLAY to BEG and END in BUFFER.
3762 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
3763 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
3765 (overlay
, beg
, end
, buffer
)
3766 Lisp_Object overlay
, beg
, end
, buffer
;
3768 struct buffer
*b
, *ob
;
3769 Lisp_Object obuffer
;
3770 int count
= SPECPDL_INDEX ();
3772 CHECK_OVERLAY (overlay
);
3774 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3776 XSETBUFFER (buffer
, current_buffer
);
3777 CHECK_BUFFER (buffer
);
3780 && ! EQ (Fmarker_buffer (beg
), buffer
))
3781 error ("Marker points into wrong buffer");
3783 && ! EQ (Fmarker_buffer (end
), buffer
))
3784 error ("Marker points into wrong buffer");
3786 CHECK_NUMBER_COERCE_MARKER (beg
);
3787 CHECK_NUMBER_COERCE_MARKER (end
);
3789 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3790 return Fdelete_overlay (overlay
);
3792 if (XINT (beg
) > XINT (end
))
3795 temp
= beg
; beg
= end
; end
= temp
;
3798 specbind (Qinhibit_quit
, Qt
);
3800 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3801 b
= XBUFFER (buffer
);
3802 ob
= BUFFERP (obuffer
) ? XBUFFER (obuffer
) : (struct buffer
*) 0;
3804 /* If the overlay has changed buffers, do a thorough redisplay. */
3805 if (!EQ (buffer
, obuffer
))
3807 /* Redisplay where the overlay was. */
3808 if (!NILP (obuffer
))
3813 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3814 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3816 modify_overlay (ob
, o_beg
, o_end
);
3819 /* Redisplay where the overlay is going to be. */
3820 modify_overlay (b
, XINT (beg
), XINT (end
));
3823 /* Redisplay the area the overlay has just left, or just enclosed. */
3827 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3828 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3830 if (o_beg
== XINT (beg
))
3831 modify_overlay (b
, o_end
, XINT (end
));
3832 else if (o_end
== XINT (end
))
3833 modify_overlay (b
, o_beg
, XINT (beg
));
3836 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
3837 if (XINT (end
) > o_end
) o_end
= XINT (end
);
3838 modify_overlay (b
, o_beg
, o_end
);
3842 if (!NILP (obuffer
))
3845 = unchain_overlay (ob
->overlays_before
, XOVERLAY (overlay
));
3847 = unchain_overlay (ob
->overlays_after
, XOVERLAY (overlay
));
3848 eassert (XOVERLAY (overlay
)->next
== NULL
);
3851 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
3852 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
3854 /* Put the overlay on the wrong list. */
3855 end
= OVERLAY_END (overlay
);
3856 if (OVERLAY_POSITION (end
) < b
->overlay_center
)
3858 XOVERLAY (overlay
)->next
= b
->overlays_after
;
3859 b
->overlays_after
= XOVERLAY (overlay
);
3863 XOVERLAY (overlay
)->next
= b
->overlays_before
;
3864 b
->overlays_before
= XOVERLAY (overlay
);
3867 /* This puts it in the right list, and in the right order. */
3868 recenter_overlay_lists (b
, b
->overlay_center
);
3870 return unbind_to (count
, overlay
);
3873 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
3874 doc
: /* Delete the overlay OVERLAY from its buffer. */)
3876 Lisp_Object overlay
;
3880 int count
= SPECPDL_INDEX ();
3882 CHECK_OVERLAY (overlay
);
3884 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3888 b
= XBUFFER (buffer
);
3889 specbind (Qinhibit_quit
, Qt
);
3891 b
->overlays_before
= unchain_overlay (b
->overlays_before
,XOVERLAY (overlay
));
3892 b
->overlays_after
= unchain_overlay (b
->overlays_after
, XOVERLAY (overlay
));
3893 eassert (XOVERLAY (overlay
)->next
== NULL
);
3895 marker_position (OVERLAY_START (overlay
)),
3896 marker_position (OVERLAY_END (overlay
)));
3897 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
3898 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
3900 /* When deleting an overlay with before or after strings, turn off
3901 display optimizations for the affected buffer, on the basis that
3902 these strings may contain newlines. This is easier to do than to
3903 check for that situation during redisplay. */
3904 if (!windows_or_buffers_changed
3905 && (!NILP (Foverlay_get (overlay
, Qbefore_string
))
3906 || !NILP (Foverlay_get (overlay
, Qafter_string
))))
3907 b
->prevent_redisplay_optimizations_p
= 1;
3909 return unbind_to (count
, Qnil
);
3912 /* Overlay dissection functions. */
3914 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3915 doc
: /* Return the position at which OVERLAY starts. */)
3917 Lisp_Object overlay
;
3919 CHECK_OVERLAY (overlay
);
3921 return (Fmarker_position (OVERLAY_START (overlay
)));
3924 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3925 doc
: /* Return the position at which OVERLAY ends. */)
3927 Lisp_Object overlay
;
3929 CHECK_OVERLAY (overlay
);
3931 return (Fmarker_position (OVERLAY_END (overlay
)));
3934 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3935 doc
: /* Return the buffer OVERLAY belongs to.
3936 Return nil if OVERLAY has been deleted. */)
3938 Lisp_Object overlay
;
3940 CHECK_OVERLAY (overlay
);
3942 return Fmarker_buffer (OVERLAY_START (overlay
));
3945 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3946 doc
: /* Return a list of the properties on OVERLAY.
3947 This is a copy of OVERLAY's plist; modifying its conses has no effect on
3950 Lisp_Object overlay
;
3952 CHECK_OVERLAY (overlay
);
3954 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3958 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3959 doc
: /* Return a list of the overlays that contain position POS. */)
3964 Lisp_Object
*overlay_vec
;
3968 CHECK_NUMBER_COERCE_MARKER (pos
);
3971 /* We can't use alloca here because overlays_at can call xrealloc. */
3972 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3974 /* Put all the overlays we want in a vector in overlay_vec.
3975 Store the length in len. */
3976 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3977 (int *) 0, (int *) 0, 0);
3979 /* Make a list of them all. */
3980 result
= Flist (noverlays
, overlay_vec
);
3982 xfree (overlay_vec
);
3986 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3987 doc
: /* Return a list of the overlays that overlap the region BEG ... END.
3988 Overlap means that at least one character is contained within the overlay
3989 and also contained within the specified region.
3990 Empty overlays are included in the result if they are located at BEG
3991 or between BEG and END. */)
3993 Lisp_Object beg
, end
;
3996 Lisp_Object
*overlay_vec
;
4000 CHECK_NUMBER_COERCE_MARKER (beg
);
4001 CHECK_NUMBER_COERCE_MARKER (end
);
4004 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
4006 /* Put all the overlays we want in a vector in overlay_vec.
4007 Store the length in len. */
4008 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
4009 (int *) 0, (int *) 0);
4011 /* Make a list of them all. */
4012 result
= Flist (noverlays
, overlay_vec
);
4014 xfree (overlay_vec
);
4018 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
4020 doc
: /* Return the next position after POS where an overlay starts or ends.
4021 If there are no overlay boundaries from POS to (point-max),
4022 the value is (point-max). */)
4028 Lisp_Object
*overlay_vec
;
4032 CHECK_NUMBER_COERCE_MARKER (pos
);
4035 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
4037 /* Put all the overlays we want in a vector in overlay_vec.
4038 Store the length in len.
4039 endpos gets the position where the next overlay starts. */
4040 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
4041 &endpos
, (int *) 0, 1);
4043 /* If any of these overlays ends before endpos,
4044 use its ending point instead. */
4045 for (i
= 0; i
< noverlays
; i
++)
4050 oend
= OVERLAY_END (overlay_vec
[i
]);
4051 oendpos
= OVERLAY_POSITION (oend
);
4052 if (oendpos
< endpos
)
4056 xfree (overlay_vec
);
4057 return make_number (endpos
);
4060 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
4061 Sprevious_overlay_change
, 1, 1, 0,
4062 doc
: /* Return the previous position before POS where an overlay starts or ends.
4063 If there are no overlay boundaries from (point-min) to POS,
4064 the value is (point-min). */)
4070 Lisp_Object
*overlay_vec
;
4073 CHECK_NUMBER_COERCE_MARKER (pos
);
4075 /* At beginning of buffer, we know the answer;
4076 avoid bug subtracting 1 below. */
4077 if (XINT (pos
) == BEGV
)
4081 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
4083 /* Put all the overlays we want in a vector in overlay_vec.
4084 Store the length in len.
4085 prevpos gets the position of the previous change. */
4086 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
4087 (int *) 0, &prevpos
, 1);
4089 xfree (overlay_vec
);
4090 return make_number (prevpos
);
4093 /* These functions are for debugging overlays. */
4095 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
4096 doc
: /* Return a pair of lists giving all the overlays of the current buffer.
4097 The car has all the overlays before the overlay center;
4098 the cdr has all the overlays after the overlay center.
4099 Recentering overlays moves overlays between these lists.
4100 The lists you get are copies, so that changing them has no effect.
4101 However, the overlays you get are the real objects that the buffer uses. */)
4104 struct Lisp_Overlay
*ol
;
4105 Lisp_Object before
= Qnil
, after
= Qnil
, tmp
;
4106 for (ol
= current_buffer
->overlays_before
; ol
; ol
= ol
->next
)
4109 before
= Fcons (tmp
, before
);
4111 for (ol
= current_buffer
->overlays_after
; ol
; ol
= ol
->next
)
4114 after
= Fcons (tmp
, after
);
4116 return Fcons (Fnreverse (before
), Fnreverse (after
));
4119 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
4120 doc
: /* Recenter the overlays of the current buffer around position POS.
4121 That makes overlay lookup faster for positions near POS (but perhaps slower
4122 for positions far away from POS). */)
4126 CHECK_NUMBER_COERCE_MARKER (pos
);
4128 recenter_overlay_lists (current_buffer
, XINT (pos
));
4132 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
4133 doc
: /* Get the property of overlay OVERLAY with property name PROP. */)
4135 Lisp_Object overlay
, prop
;
4137 CHECK_OVERLAY (overlay
);
4138 return lookup_char_property (XOVERLAY (overlay
)->plist
, prop
, 0);
4141 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
4142 doc
: /* Set one property of overlay OVERLAY: give property PROP value VALUE. */)
4143 (overlay
, prop
, value
)
4144 Lisp_Object overlay
, prop
, value
;
4146 Lisp_Object tail
, buffer
;
4149 CHECK_OVERLAY (overlay
);
4151 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
4153 for (tail
= XOVERLAY (overlay
)->plist
;
4154 CONSP (tail
) && CONSP (XCDR (tail
));
4155 tail
= XCDR (XCDR (tail
)))
4156 if (EQ (XCAR (tail
), prop
))
4158 changed
= !EQ (XCAR (XCDR (tail
)), value
);
4159 XSETCAR (XCDR (tail
), value
);
4162 /* It wasn't in the list, so add it to the front. */
4163 changed
= !NILP (value
);
4164 XOVERLAY (overlay
)->plist
4165 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
4167 if (! NILP (buffer
))
4170 modify_overlay (XBUFFER (buffer
),
4171 marker_position (OVERLAY_START (overlay
)),
4172 marker_position (OVERLAY_END (overlay
)));
4173 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
4174 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
4175 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
4176 Fdelete_overlay (overlay
);
4182 /* Subroutine of report_overlay_modification. */
4184 /* Lisp vector holding overlay hook functions to call.
4185 Vector elements come in pairs.
4186 Each even-index element is a list of hook functions.
4187 The following odd-index element is the overlay they came from.
4189 Before the buffer change, we fill in this vector
4190 as we call overlay hook functions.
4191 After the buffer change, we get the functions to call from this vector.
4192 This way we always call the same functions before and after the change. */
4193 static Lisp_Object last_overlay_modification_hooks
;
4195 /* Number of elements actually used in last_overlay_modification_hooks. */
4196 static int last_overlay_modification_hooks_used
;
4198 /* Add one functionlist/overlay pair
4199 to the end of last_overlay_modification_hooks. */
4202 add_overlay_mod_hooklist (functionlist
, overlay
)
4203 Lisp_Object functionlist
, overlay
;
4205 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
4207 if (last_overlay_modification_hooks_used
== oldsize
)
4210 old
= last_overlay_modification_hooks
;
4211 last_overlay_modification_hooks
4212 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
4213 bcopy (XVECTOR (old
)->contents
,
4214 XVECTOR (last_overlay_modification_hooks
)->contents
,
4215 sizeof (Lisp_Object
) * oldsize
);
4217 AREF (last_overlay_modification_hooks
, last_overlay_modification_hooks_used
++) = functionlist
;
4218 AREF (last_overlay_modification_hooks
, last_overlay_modification_hooks_used
++) = overlay
;
4221 /* Run the modification-hooks of overlays that include
4222 any part of the text in START to END.
4223 If this change is an insertion, also
4224 run the insert-before-hooks of overlay starting at END,
4225 and the insert-after-hooks of overlay ending at START.
4227 This is called both before and after the modification.
4228 AFTER is nonzero when we call after the modification.
4230 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
4231 When AFTER is nonzero, they are the start position,
4232 the position after the inserted new text,
4233 and the length of deleted or replaced old text. */
4236 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
4237 Lisp_Object start
, end
;
4239 Lisp_Object arg1
, arg2
, arg3
;
4241 Lisp_Object prop
, overlay
;
4242 struct Lisp_Overlay
*tail
;
4243 /* 1 if this change is an insertion. */
4244 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
4245 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4250 /* We used to run the functions as soon as we found them and only register
4251 them in last_overlay_modification_hooks for the purpose of the `after'
4252 case. But running elisp code as we traverse the list of overlays is
4253 painful because the list can be modified by the elisp code so we had to
4254 copy at several places. We now simply do a read-only traversal that
4255 only collects the functions to run and we run them afterwards. It's
4256 simpler, especially since all the code was already there. -stef */
4260 /* We are being called before a change.
4261 Scan the overlays to find the functions to call. */
4262 last_overlay_modification_hooks_used
= 0;
4263 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
4265 int startpos
, endpos
;
4266 Lisp_Object ostart
, oend
;
4268 XSETMISC (overlay
, tail
);
4270 ostart
= OVERLAY_START (overlay
);
4271 oend
= OVERLAY_END (overlay
);
4272 endpos
= OVERLAY_POSITION (oend
);
4273 if (XFASTINT (start
) > endpos
)
4275 startpos
= OVERLAY_POSITION (ostart
);
4276 if (insertion
&& (XFASTINT (start
) == startpos
4277 || XFASTINT (end
) == startpos
))
4279 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
4281 add_overlay_mod_hooklist (prop
, overlay
);
4283 if (insertion
&& (XFASTINT (start
) == endpos
4284 || XFASTINT (end
) == endpos
))
4286 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
4288 add_overlay_mod_hooklist (prop
, overlay
);
4290 /* Test for intersecting intervals. This does the right thing
4291 for both insertion and deletion. */
4292 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
4294 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
4296 add_overlay_mod_hooklist (prop
, overlay
);
4300 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
4302 int startpos
, endpos
;
4303 Lisp_Object ostart
, oend
;
4305 XSETMISC (overlay
, tail
);
4307 ostart
= OVERLAY_START (overlay
);
4308 oend
= OVERLAY_END (overlay
);
4309 startpos
= OVERLAY_POSITION (ostart
);
4310 endpos
= OVERLAY_POSITION (oend
);
4311 if (XFASTINT (end
) < startpos
)
4313 if (insertion
&& (XFASTINT (start
) == startpos
4314 || XFASTINT (end
) == startpos
))
4316 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
4318 add_overlay_mod_hooklist (prop
, overlay
);
4320 if (insertion
&& (XFASTINT (start
) == endpos
4321 || XFASTINT (end
) == endpos
))
4323 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
4325 add_overlay_mod_hooklist (prop
, overlay
);
4327 /* Test for intersecting intervals. This does the right thing
4328 for both insertion and deletion. */
4329 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
4331 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
4333 add_overlay_mod_hooklist (prop
, overlay
);
4338 GCPRO4 (overlay
, arg1
, arg2
, arg3
);
4340 /* Call the functions recorded in last_overlay_modification_hooks.
4341 First copy the vector contents, in case some of these hooks
4342 do subsequent modification of the buffer. */
4343 int size
= last_overlay_modification_hooks_used
;
4344 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
4347 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
4348 copy
, size
* sizeof (Lisp_Object
));
4350 gcpro1
.nvars
= size
;
4352 for (i
= 0; i
< size
;)
4354 Lisp_Object prop
, overlay
;
4356 overlay
= copy
[i
++];
4357 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
4364 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
4365 Lisp_Object list
, overlay
;
4367 Lisp_Object arg1
, arg2
, arg3
;
4369 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4371 GCPRO4 (list
, arg1
, arg2
, arg3
);
4373 while (CONSP (list
))
4376 call4 (XCAR (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
4378 call5 (XCAR (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
4384 /* Delete any zero-sized overlays at position POS, if the `evaporate'
4387 evaporate_overlays (pos
)
4390 Lisp_Object overlay
, hit_list
;
4391 struct Lisp_Overlay
*tail
;
4394 if (pos
<= current_buffer
->overlay_center
)
4395 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
4398 XSETMISC (overlay
, tail
);
4399 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4402 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
4403 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4404 hit_list
= Fcons (overlay
, hit_list
);
4407 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
4410 XSETMISC (overlay
, tail
);
4411 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4414 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
4415 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4416 hit_list
= Fcons (overlay
, hit_list
);
4418 for (; CONSP (hit_list
); hit_list
= XCDR (hit_list
))
4419 Fdelete_overlay (XCAR (hit_list
));
4422 /* Somebody has tried to store a value with an unacceptable type
4423 in the slot with offset OFFSET. */
4426 buffer_slot_type_mismatch (offset
)
4432 switch (XINT (PER_BUFFER_TYPE (offset
)))
4435 type_name
= "integers";
4439 type_name
= "strings";
4443 type_name
= "symbols";
4450 sym
= PER_BUFFER_SYMBOL (offset
);
4451 error ("Only %s should be stored in the buffer-local variable %s",
4452 type_name
, SDATA (SYMBOL_NAME (sym
)));
4456 /***********************************************************************
4457 Allocation with mmap
4458 ***********************************************************************/
4460 #ifdef USE_MMAP_FOR_BUFFERS
4462 #include <sys/types.h>
4463 #include <sys/mman.h>
4466 #ifdef MAP_ANONYMOUS
4467 #define MAP_ANON MAP_ANONYMOUS
4474 #define MAP_FAILED ((void *) -1)
4487 /* Memory is allocated in regions which are mapped using mmap(2).
4488 The current implementation lets the system select mapped
4489 addresses; we're not using MAP_FIXED in general, except when
4490 trying to enlarge regions.
4492 Each mapped region starts with a mmap_region structure, the user
4493 area starts after that structure, aligned to MEM_ALIGN.
4495 +-----------------------+
4496 | struct mmap_info + |
4498 +-----------------------+
4502 +-----------------------+ */
4506 /* User-specified size. */
4507 size_t nbytes_specified
;
4509 /* Number of bytes mapped */
4510 size_t nbytes_mapped
;
4512 /* Pointer to the location holding the address of the memory
4513 allocated with the mmap'd block. The variable actually points
4514 after this structure. */
4517 /* Next and previous in list of all mmap'd regions. */
4518 struct mmap_region
*next
, *prev
;
4521 /* Doubly-linked list of mmap'd regions. */
4523 static struct mmap_region
*mmap_regions
;
4525 /* File descriptor for mmap. If we don't have anonymous mapping,
4526 /dev/zero will be opened on it. */
4530 /* Temporary storage for mmap_set_vars, see there. */
4532 static struct mmap_region
*mmap_regions_1
;
4533 static int mmap_fd_1
;
4535 /* Page size on this system. */
4537 static int mmap_page_size
;
4539 /* 1 means mmap has been intialized. */
4541 static int mmap_initialized_p
;
4543 /* Value is X rounded up to the next multiple of N. */
4545 #define ROUND(X, N) (((X) + (N) - 1) / (N) * (N))
4547 /* Size of mmap_region structure plus padding. */
4549 #define MMAP_REGION_STRUCT_SIZE \
4550 ROUND (sizeof (struct mmap_region), MEM_ALIGN)
4552 /* Given a pointer P to the start of the user-visible part of a mapped
4553 region, return a pointer to the start of the region. */
4555 #define MMAP_REGION(P) \
4556 ((struct mmap_region *) ((char *) (P) - MMAP_REGION_STRUCT_SIZE))
4558 /* Given a pointer P to the start of a mapped region, return a pointer
4559 to the start of the user-visible part of the region. */
4561 #define MMAP_USER_AREA(P) \
4562 ((POINTER_TYPE *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE))
4564 #define MEM_ALIGN sizeof (double)
4566 /* Predicate returning true if part of the address range [START .. END]
4567 is currently mapped. Used to prevent overwriting an existing
4570 Default is to conservativly assume the address range is occupied by
4571 something else. This can be overridden by system configuration
4572 files if system-specific means to determine this exists. */
4574 #ifndef MMAP_ALLOCATED_P
4575 #define MMAP_ALLOCATED_P(start, end) 1
4578 /* Function prototypes. */
4580 static int mmap_free_1
P_ ((struct mmap_region
*));
4581 static int mmap_enlarge
P_ ((struct mmap_region
*, int));
4582 static struct mmap_region
*mmap_find
P_ ((POINTER_TYPE
*, POINTER_TYPE
*));
4583 static POINTER_TYPE
*mmap_alloc
P_ ((POINTER_TYPE
**, size_t));
4584 static POINTER_TYPE
*mmap_realloc
P_ ((POINTER_TYPE
**, size_t));
4585 static void mmap_free
P_ ((POINTER_TYPE
**ptr
));
4586 static void mmap_init
P_ ((void));
4589 /* Return a region overlapping address range START...END, or null if
4590 none. END is not including, i.e. the last byte in the range
4593 static struct mmap_region
*
4594 mmap_find (start
, end
)
4595 POINTER_TYPE
*start
, *end
;
4597 struct mmap_region
*r
;
4598 char *s
= (char *) start
, *e
= (char *) end
;
4600 for (r
= mmap_regions
; r
; r
= r
->next
)
4602 char *rstart
= (char *) r
;
4603 char *rend
= rstart
+ r
->nbytes_mapped
;
4605 if (/* First byte of range, i.e. START, in this region? */
4606 (s
>= rstart
&& s
< rend
)
4607 /* Last byte of range, i.e. END - 1, in this region? */
4608 || (e
> rstart
&& e
<= rend
)
4609 /* First byte of this region in the range? */
4610 || (rstart
>= s
&& rstart
< e
)
4611 /* Last byte of this region in the range? */
4612 || (rend
> s
&& rend
<= e
))
4620 /* Unmap a region. P is a pointer to the start of the user-araa of
4621 the region. Value is non-zero if successful. */
4625 struct mmap_region
*r
;
4628 r
->next
->prev
= r
->prev
;
4630 r
->prev
->next
= r
->next
;
4632 mmap_regions
= r
->next
;
4634 if (munmap ((POINTER_TYPE
*) r
, r
->nbytes_mapped
) == -1)
4636 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4644 /* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R.
4645 Value is non-zero if successful. */
4648 mmap_enlarge (r
, npages
)
4649 struct mmap_region
*r
;
4652 char *region_end
= (char *) r
+ r
->nbytes_mapped
;
4658 /* Unmap pages at the end of the region. */
4659 nbytes
= - npages
* mmap_page_size
;
4660 if (munmap (region_end
- nbytes
, nbytes
) == -1)
4661 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4664 r
->nbytes_mapped
-= nbytes
;
4668 else if (npages
> 0)
4670 nbytes
= npages
* mmap_page_size
;
4672 /* Try to map additional pages at the end of the region. We
4673 cannot do this if the address range is already occupied by
4674 something else because mmap deletes any previous mapping.
4675 I'm not sure this is worth doing, let's see. */
4676 if (!MMAP_ALLOCATED_P (region_end
, region_end
+ nbytes
))
4680 p
= mmap (region_end
, nbytes
, PROT_READ
| PROT_WRITE
,
4681 MAP_ANON
| MAP_PRIVATE
| MAP_FIXED
, mmap_fd
, 0);
4682 if (p
== MAP_FAILED
)
4683 ; /* fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); */
4684 else if (p
!= (POINTER_TYPE
*) region_end
)
4686 /* Kernels are free to choose a different address. In
4687 that case, unmap what we've mapped above; we have
4689 if (munmap (p
, nbytes
) == -1)
4690 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4694 r
->nbytes_mapped
+= nbytes
;
4704 /* Set or reset variables holding references to mapped regions. If
4705 RESTORE_P is zero, set all variables to null. If RESTORE_P is
4706 non-zero, set all variables to the start of the user-areas
4709 This function is called from Fdump_emacs to ensure that the dumped
4710 Emacs doesn't contain references to memory that won't be mapped
4711 when Emacs starts. */
4714 mmap_set_vars (restore_p
)
4717 struct mmap_region
*r
;
4721 mmap_regions
= mmap_regions_1
;
4722 mmap_fd
= mmap_fd_1
;
4723 for (r
= mmap_regions
; r
; r
= r
->next
)
4724 *r
->var
= MMAP_USER_AREA (r
);
4728 for (r
= mmap_regions
; r
; r
= r
->next
)
4730 mmap_regions_1
= mmap_regions
;
4731 mmap_regions
= NULL
;
4732 mmap_fd_1
= mmap_fd
;
4738 /* Allocate a block of storage large enough to hold NBYTES bytes of
4739 data. A pointer to the data is returned in *VAR. VAR is thus the
4740 address of some variable which will use the data area.
4742 The allocation of 0 bytes is valid.
4744 If we can't allocate the necessary memory, set *VAR to null, and
4747 static POINTER_TYPE
*
4748 mmap_alloc (var
, nbytes
)
4757 map
= ROUND (nbytes
+ MMAP_REGION_STRUCT_SIZE
, mmap_page_size
);
4758 p
= mmap (NULL
, map
, PROT_READ
| PROT_WRITE
, MAP_ANON
| MAP_PRIVATE
,
4761 if (p
== MAP_FAILED
)
4763 if (errno
!= ENOMEM
)
4764 fprintf (stderr
, "mmap: %s\n", emacs_strerror (errno
));
4769 struct mmap_region
*r
= (struct mmap_region
*) p
;
4771 r
->nbytes_specified
= nbytes
;
4772 r
->nbytes_mapped
= map
;
4775 r
->next
= mmap_regions
;
4780 p
= MMAP_USER_AREA (p
);
4787 /* Given a pointer at address VAR to data allocated with mmap_alloc,
4788 resize it to size NBYTES. Change *VAR to reflect the new block,
4789 and return this value. If more memory cannot be allocated, then
4790 leave *VAR unchanged, and return null. */
4792 static POINTER_TYPE
*
4793 mmap_realloc (var
, nbytes
)
4797 POINTER_TYPE
*result
;
4802 result
= mmap_alloc (var
, nbytes
);
4803 else if (nbytes
== 0)
4806 result
= mmap_alloc (var
, nbytes
);
4810 struct mmap_region
*r
= MMAP_REGION (*var
);
4811 size_t room
= r
->nbytes_mapped
- MMAP_REGION_STRUCT_SIZE
;
4816 POINTER_TYPE
*old_ptr
= *var
;
4818 /* Try to map additional pages at the end of the region.
4819 If that fails, allocate a new region, copy data
4820 from the old region, then free it. */
4821 if (mmap_enlarge (r
, (ROUND (nbytes
- room
, mmap_page_size
)
4824 r
->nbytes_specified
= nbytes
;
4825 *var
= result
= old_ptr
;
4827 else if (mmap_alloc (var
, nbytes
))
4829 bcopy (old_ptr
, *var
, r
->nbytes_specified
);
4830 mmap_free_1 (MMAP_REGION (old_ptr
));
4832 r
= MMAP_REGION (result
);
4833 r
->nbytes_specified
= nbytes
;
4841 else if (room
- nbytes
>= mmap_page_size
)
4843 /* Shrinking by at least a page. Let's give some
4844 memory back to the system.
4846 The extra parens are to make the division happens first,
4847 on positive values, so we know it will round towards
4849 mmap_enlarge (r
, - ((room
- nbytes
) / mmap_page_size
));
4851 r
->nbytes_specified
= nbytes
;
4855 /* Leave it alone. */
4857 r
->nbytes_specified
= nbytes
;
4865 /* Free a block of relocatable storage whose data is pointed to by
4866 PTR. Store 0 in *PTR to show there's no block allocated. */
4876 mmap_free_1 (MMAP_REGION (*var
));
4882 /* Perform necessary intializations for the use of mmap. */
4888 /* The value of mmap_fd is initially 0 in temacs, and -1
4889 in a dumped Emacs. */
4892 /* No anonymous mmap -- we need the file descriptor. */
4893 mmap_fd
= open ("/dev/zero", O_RDONLY
);
4895 fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno
));
4897 #endif /* MAP_ANON == 0 */
4899 if (mmap_initialized_p
)
4901 mmap_initialized_p
= 1;
4907 mmap_page_size
= getpagesize ();
4910 #endif /* USE_MMAP_FOR_BUFFERS */
4914 /***********************************************************************
4915 Buffer-text Allocation
4916 ***********************************************************************/
4919 extern POINTER_TYPE
*r_alloc
P_ ((POINTER_TYPE
**, size_t));
4920 extern POINTER_TYPE
*r_re_alloc
P_ ((POINTER_TYPE
**, size_t));
4921 extern void r_alloc_free
P_ ((POINTER_TYPE
**ptr
));
4922 #endif /* REL_ALLOC */
4925 /* Allocate NBYTES bytes for buffer B's text buffer. */
4928 alloc_buffer_text (b
, nbytes
)
4935 #if defined USE_MMAP_FOR_BUFFERS
4936 p
= mmap_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4937 #elif defined REL_ALLOC
4938 p
= r_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4940 p
= xmalloc (nbytes
);
4949 b
->text
->beg
= (unsigned char *) p
;
4953 /* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means
4957 enlarge_buffer_text (b
, delta
)
4962 size_t nbytes
= (BUF_Z_BYTE (b
) - BUF_BEG_BYTE (b
) + BUF_GAP_SIZE (b
) + 1
4965 #if defined USE_MMAP_FOR_BUFFERS
4966 p
= mmap_realloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4967 #elif defined REL_ALLOC
4968 p
= r_re_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4970 p
= xrealloc (b
->text
->beg
, nbytes
);
4979 BUF_BEG_ADDR (b
) = (unsigned char *) p
;
4984 /* Free buffer B's text buffer. */
4987 free_buffer_text (b
)
4992 #if defined USE_MMAP_FOR_BUFFERS
4993 mmap_free ((POINTER_TYPE
**) &b
->text
->beg
);
4994 #elif defined REL_ALLOC
4995 r_alloc_free ((POINTER_TYPE
**) &b
->text
->beg
);
4997 xfree (b
->text
->beg
);
5000 BUF_BEG_ADDR (b
) = NULL
;
5006 /***********************************************************************
5008 ***********************************************************************/
5015 bzero (buffer_permanent_local_flags
, sizeof buffer_permanent_local_flags
);
5017 /* Make sure all markable slots in buffer_defaults
5018 are initialized reasonably, so mark_buffer won't choke. */
5019 reset_buffer (&buffer_defaults
);
5020 reset_buffer_local_variables (&buffer_defaults
, 1);
5021 reset_buffer (&buffer_local_symbols
);
5022 reset_buffer_local_variables (&buffer_local_symbols
, 1);
5023 /* Prevent GC from getting confused. */
5024 buffer_defaults
.text
= &buffer_defaults
.own_text
;
5025 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
5026 BUF_INTERVALS (&buffer_defaults
) = 0;
5027 BUF_INTERVALS (&buffer_local_symbols
) = 0;
5028 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
5029 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
5031 /* Set up the default values of various buffer slots. */
5032 /* Must do these before making the first buffer! */
5034 /* real setup is done in bindings.el */
5035 buffer_defaults
.mode_line_format
= build_string ("%-");
5036 buffer_defaults
.header_line_format
= Qnil
;
5037 buffer_defaults
.abbrev_mode
= Qnil
;
5038 buffer_defaults
.overwrite_mode
= Qnil
;
5039 buffer_defaults
.case_fold_search
= Qt
;
5040 buffer_defaults
.auto_fill_function
= Qnil
;
5041 buffer_defaults
.selective_display
= Qnil
;
5043 buffer_defaults
.selective_display_ellipses
= Qt
;
5045 buffer_defaults
.abbrev_table
= Qnil
;
5046 buffer_defaults
.display_table
= Qnil
;
5047 buffer_defaults
.undo_list
= Qnil
;
5048 buffer_defaults
.mark_active
= Qnil
;
5049 buffer_defaults
.file_format
= Qnil
;
5050 buffer_defaults
.auto_save_file_format
= Qt
;
5051 buffer_defaults
.overlays_before
= NULL
;
5052 buffer_defaults
.overlays_after
= NULL
;
5053 buffer_defaults
.overlay_center
= BEG
;
5055 XSETFASTINT (buffer_defaults
.tab_width
, 8);
5056 buffer_defaults
.truncate_lines
= Qnil
;
5057 buffer_defaults
.ctl_arrow
= Qt
;
5058 buffer_defaults
.direction_reversed
= Qnil
;
5059 buffer_defaults
.cursor_type
= Qt
;
5060 buffer_defaults
.extra_line_spacing
= Qnil
;
5061 buffer_defaults
.cursor_in_non_selected_windows
= Qt
;
5064 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
5066 buffer_defaults
.enable_multibyte_characters
= Qt
;
5067 buffer_defaults
.buffer_file_coding_system
= Qnil
;
5068 XSETFASTINT (buffer_defaults
.fill_column
, 70);
5069 XSETFASTINT (buffer_defaults
.left_margin
, 0);
5070 buffer_defaults
.cache_long_line_scans
= Qnil
;
5071 buffer_defaults
.file_truename
= Qnil
;
5072 XSETFASTINT (buffer_defaults
.display_count
, 0);
5073 XSETFASTINT (buffer_defaults
.left_margin_cols
, 0);
5074 XSETFASTINT (buffer_defaults
.right_margin_cols
, 0);
5075 buffer_defaults
.left_fringe_width
= Qnil
;
5076 buffer_defaults
.right_fringe_width
= Qnil
;
5077 buffer_defaults
.fringes_outside_margins
= Qnil
;
5078 buffer_defaults
.scroll_bar_width
= Qnil
;
5079 buffer_defaults
.vertical_scroll_bar_type
= Qt
;
5080 buffer_defaults
.indicate_empty_lines
= Qnil
;
5081 buffer_defaults
.indicate_buffer_boundaries
= Qnil
;
5082 buffer_defaults
.fringe_indicator_alist
= Qnil
;
5083 buffer_defaults
.fringe_cursor_alist
= Qnil
;
5084 buffer_defaults
.scroll_up_aggressively
= Qnil
;
5085 buffer_defaults
.scroll_down_aggressively
= Qnil
;
5086 buffer_defaults
.display_time
= Qnil
;
5088 /* Assign the local-flags to the slots that have default values.
5089 The local flag is a bit that is used in the buffer
5090 to say that it has its own local value for the slot.
5091 The local flag bits are in the local_var_flags slot of the buffer. */
5093 /* Nothing can work if this isn't true */
5094 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
5096 /* 0 means not a lisp var, -1 means always local, else mask */
5097 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
5098 XSETINT (buffer_local_flags
.filename
, -1);
5099 XSETINT (buffer_local_flags
.directory
, -1);
5100 XSETINT (buffer_local_flags
.backed_up
, -1);
5101 XSETINT (buffer_local_flags
.save_length
, -1);
5102 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
5103 XSETINT (buffer_local_flags
.read_only
, -1);
5104 XSETINT (buffer_local_flags
.major_mode
, -1);
5105 XSETINT (buffer_local_flags
.mode_name
, -1);
5106 XSETINT (buffer_local_flags
.undo_list
, -1);
5107 XSETINT (buffer_local_flags
.mark_active
, -1);
5108 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
5109 XSETINT (buffer_local_flags
.file_truename
, -1);
5110 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
5111 XSETINT (buffer_local_flags
.file_format
, -1);
5112 XSETINT (buffer_local_flags
.auto_save_file_format
, -1);
5113 XSETINT (buffer_local_flags
.display_count
, -1);
5114 XSETINT (buffer_local_flags
.display_time
, -1);
5115 XSETINT (buffer_local_flags
.enable_multibyte_characters
, -1);
5118 XSETFASTINT (buffer_local_flags
.mode_line_format
, idx
); ++idx
;
5119 XSETFASTINT (buffer_local_flags
.abbrev_mode
, idx
); ++idx
;
5120 XSETFASTINT (buffer_local_flags
.overwrite_mode
, idx
); ++idx
;
5121 XSETFASTINT (buffer_local_flags
.case_fold_search
, idx
); ++idx
;
5122 XSETFASTINT (buffer_local_flags
.auto_fill_function
, idx
); ++idx
;
5123 XSETFASTINT (buffer_local_flags
.selective_display
, idx
); ++idx
;
5125 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, idx
); ++idx
;
5127 XSETFASTINT (buffer_local_flags
.tab_width
, idx
); ++idx
;
5128 XSETFASTINT (buffer_local_flags
.truncate_lines
, idx
); ++idx
;
5129 XSETFASTINT (buffer_local_flags
.ctl_arrow
, idx
); ++idx
;
5130 XSETFASTINT (buffer_local_flags
.fill_column
, idx
); ++idx
;
5131 XSETFASTINT (buffer_local_flags
.left_margin
, idx
); ++idx
;
5132 XSETFASTINT (buffer_local_flags
.abbrev_table
, idx
); ++idx
;
5133 XSETFASTINT (buffer_local_flags
.display_table
, idx
); ++idx
;
5135 XSETFASTINT (buffer_local_flags
.buffer_file_type
, idx
);
5136 /* Make this one a permanent local. */
5137 buffer_permanent_local_flags
[idx
++] = 1;
5139 XSETFASTINT (buffer_local_flags
.syntax_table
, idx
); ++idx
;
5140 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, idx
); ++idx
;
5141 XSETFASTINT (buffer_local_flags
.category_table
, idx
); ++idx
;
5142 XSETFASTINT (buffer_local_flags
.direction_reversed
, idx
); ++idx
;
5143 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, idx
);
5144 /* Make this one a permanent local. */
5145 buffer_permanent_local_flags
[idx
++] = 1;
5146 XSETFASTINT (buffer_local_flags
.left_margin_cols
, idx
); ++idx
;
5147 XSETFASTINT (buffer_local_flags
.right_margin_cols
, idx
); ++idx
;
5148 XSETFASTINT (buffer_local_flags
.left_fringe_width
, idx
); ++idx
;
5149 XSETFASTINT (buffer_local_flags
.right_fringe_width
, idx
); ++idx
;
5150 XSETFASTINT (buffer_local_flags
.fringes_outside_margins
, idx
); ++idx
;
5151 XSETFASTINT (buffer_local_flags
.scroll_bar_width
, idx
); ++idx
;
5152 XSETFASTINT (buffer_local_flags
.vertical_scroll_bar_type
, idx
); ++idx
;
5153 XSETFASTINT (buffer_local_flags
.indicate_empty_lines
, idx
); ++idx
;
5154 XSETFASTINT (buffer_local_flags
.indicate_buffer_boundaries
, idx
); ++idx
;
5155 XSETFASTINT (buffer_local_flags
.fringe_indicator_alist
, idx
); ++idx
;
5156 XSETFASTINT (buffer_local_flags
.fringe_cursor_alist
, idx
); ++idx
;
5157 XSETFASTINT (buffer_local_flags
.scroll_up_aggressively
, idx
); ++idx
;
5158 XSETFASTINT (buffer_local_flags
.scroll_down_aggressively
, idx
); ++idx
;
5159 XSETFASTINT (buffer_local_flags
.header_line_format
, idx
); ++idx
;
5160 XSETFASTINT (buffer_local_flags
.cursor_type
, idx
); ++idx
;
5161 XSETFASTINT (buffer_local_flags
.extra_line_spacing
, idx
); ++idx
;
5162 XSETFASTINT (buffer_local_flags
.cursor_in_non_selected_windows
, idx
); ++idx
;
5164 /* Need more room? */
5165 if (idx
>= MAX_PER_BUFFER_VARS
)
5167 last_per_buffer_idx
= idx
;
5169 Vbuffer_alist
= Qnil
;
5173 QSFundamental
= build_string ("Fundamental");
5175 Qfundamental_mode
= intern ("fundamental-mode");
5176 buffer_defaults
.major_mode
= Qfundamental_mode
;
5178 Qmode_class
= intern ("mode-class");
5180 Qprotected_field
= intern ("protected-field");
5182 Qpermanent_local
= intern ("permanent-local");
5184 Qkill_buffer_hook
= intern ("kill-buffer-hook");
5185 Fput (Qkill_buffer_hook
, Qpermanent_local
, Qt
);
5187 Qucs_set_table_for_input
= intern ("ucs-set-table-for-input");
5189 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
5191 /* super-magic invisible buffer */
5192 Vbuffer_alist
= Qnil
;
5194 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
5196 inhibit_modification_hooks
= 0;
5206 #ifdef USE_MMAP_FOR_BUFFERS
5208 /* When using the ralloc implementation based on mmap(2), buffer
5209 text pointers will have been set to null in the dumped Emacs.
5213 for (b
= all_buffers
; b
; b
= b
->next
)
5214 if (b
->text
->beg
== NULL
)
5215 enlarge_buffer_text (b
, 0);
5217 #endif /* USE_MMAP_FOR_BUFFERS */
5219 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
5220 if (NILP (buffer_defaults
.enable_multibyte_characters
))
5221 Fset_buffer_multibyte (Qnil
);
5223 pwd
= get_current_dir_name ();
5226 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno
));
5229 /* Maybe this should really use some standard subroutine
5230 whose definition is filename syntax dependent. */
5232 if (!(IS_DIRECTORY_SEP (pwd
[len
- 1])))
5234 /* Grow buffer to add directory separator and '\0'. */
5235 pwd
= (char *) xrealloc (pwd
, len
+ 2);
5236 pwd
[len
] = DIRECTORY_SEP
;
5237 pwd
[len
+ 1] = '\0';
5239 #endif /* not VMS */
5241 current_buffer
->directory
= make_unibyte_string (pwd
, strlen (pwd
));
5242 if (! NILP (buffer_defaults
.enable_multibyte_characters
))
5243 /* At this moment, we still don't know how to decode the
5244 directory name. So, we keep the bytes in multibyte form so
5245 that ENCODE_FILE correctly gets the original bytes. */
5246 current_buffer
->directory
5247 = string_to_multibyte (current_buffer
->directory
);
5249 /* Add /: to the front of the name
5250 if it would otherwise be treated as magic. */
5251 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
5253 /* If the default dir is just /, TEMP is non-nil
5254 because of the ange-ftp completion handler.
5255 However, it is not necessary to turn / into /:/.
5256 So avoid doing that. */
5257 && strcmp ("/", SDATA (current_buffer
->directory
)))
5258 current_buffer
->directory
5259 = concat2 (build_string ("/:"), current_buffer
->directory
);
5261 temp
= get_minibuffer (0);
5262 XBUFFER (temp
)->directory
= current_buffer
->directory
;
5267 /* initialize the buffer routines */
5271 staticpro (&last_overlay_modification_hooks
);
5272 last_overlay_modification_hooks
5273 = Fmake_vector (make_number (10), Qnil
);
5275 staticpro (&Vbuffer_defaults
);
5276 staticpro (&Vbuffer_local_symbols
);
5277 staticpro (&Qfundamental_mode
);
5278 staticpro (&Qmode_class
);
5279 staticpro (&QSFundamental
);
5280 staticpro (&Vbuffer_alist
);
5281 staticpro (&Qprotected_field
);
5282 staticpro (&Qpermanent_local
);
5283 staticpro (&Qkill_buffer_hook
);
5284 Qoverlayp
= intern ("overlayp");
5285 staticpro (&Qoverlayp
);
5286 Qevaporate
= intern ("evaporate");
5287 staticpro (&Qevaporate
);
5288 Qmodification_hooks
= intern ("modification-hooks");
5289 staticpro (&Qmodification_hooks
);
5290 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
5291 staticpro (&Qinsert_in_front_hooks
);
5292 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
5293 staticpro (&Qinsert_behind_hooks
);
5294 Qget_file_buffer
= intern ("get-file-buffer");
5295 staticpro (&Qget_file_buffer
);
5296 Qpriority
= intern ("priority");
5297 staticpro (&Qpriority
);
5298 Qwindow
= intern ("window");
5299 staticpro (&Qwindow
);
5300 Qbefore_string
= intern ("before-string");
5301 staticpro (&Qbefore_string
);
5302 Qafter_string
= intern ("after-string");
5303 staticpro (&Qafter_string
);
5304 Qfirst_change_hook
= intern ("first-change-hook");
5305 staticpro (&Qfirst_change_hook
);
5306 Qbefore_change_functions
= intern ("before-change-functions");
5307 staticpro (&Qbefore_change_functions
);
5308 Qafter_change_functions
= intern ("after-change-functions");
5309 staticpro (&Qafter_change_functions
);
5310 staticpro (&Qucs_set_table_for_input
);
5312 Qkill_buffer_query_functions
= intern ("kill-buffer-query-functions");
5313 staticpro (&Qkill_buffer_query_functions
);
5315 Fput (Qprotected_field
, Qerror_conditions
,
5316 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
5317 Fput (Qprotected_field
, Qerror_message
,
5318 build_string ("Attempt to modify a protected field"));
5320 /* All these use DEFVAR_LISP_NOPRO because the slots in
5321 buffer_defaults will all be marked via Vbuffer_defaults. */
5323 DEFVAR_LISP_NOPRO ("default-mode-line-format",
5324 &buffer_defaults
.mode_line_format
,
5325 doc
: /* Default value of `mode-line-format' for buffers that don't override it.
5326 This is the same as (default-value 'mode-line-format). */);
5328 DEFVAR_LISP_NOPRO ("default-header-line-format",
5329 &buffer_defaults
.header_line_format
,
5330 doc
: /* Default value of `header-line-format' for buffers that don't override it.
5331 This is the same as (default-value 'header-line-format). */);
5333 DEFVAR_LISP_NOPRO ("default-cursor-type", &buffer_defaults
.cursor_type
,
5334 doc
: /* Default value of `cursor-type' for buffers that don't override it.
5335 This is the same as (default-value 'cursor-type). */);
5337 DEFVAR_LISP_NOPRO ("default-line-spacing",
5338 &buffer_defaults
.extra_line_spacing
,
5339 doc
: /* Default value of `line-spacing' for buffers that don't override it.
5340 This is the same as (default-value 'line-spacing). */);
5342 DEFVAR_LISP_NOPRO ("default-cursor-in-non-selected-windows",
5343 &buffer_defaults
.cursor_in_non_selected_windows
,
5344 doc
: /* Default value of `cursor-in-non-selected-windows'.
5345 This is the same as (default-value 'cursor-in-non-selected-windows). */);
5347 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
5348 &buffer_defaults
.abbrev_mode
,
5349 doc
: /* Default value of `abbrev-mode' for buffers that do not override it.
5350 This is the same as (default-value 'abbrev-mode). */);
5352 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
5353 &buffer_defaults
.ctl_arrow
,
5354 doc
: /* Default value of `ctl-arrow' for buffers that do not override it.
5355 This is the same as (default-value 'ctl-arrow). */);
5357 DEFVAR_LISP_NOPRO ("default-direction-reversed",
5358 &buffer_defaults
.direction_reversed
,
5359 doc
: /* Default value of `direction-reversed' for buffers that do not override it.
5360 This is the same as (default-value 'direction-reversed). */);
5362 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
5363 &buffer_defaults
.enable_multibyte_characters
,
5364 doc
: /* *Default value of `enable-multibyte-characters' for buffers not overriding it.
5365 This is the same as (default-value 'enable-multibyte-characters). */);
5367 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
5368 &buffer_defaults
.buffer_file_coding_system
,
5369 doc
: /* Default value of `buffer-file-coding-system' for buffers not overriding it.
5370 This is the same as (default-value 'buffer-file-coding-system). */);
5372 DEFVAR_LISP_NOPRO ("default-truncate-lines",
5373 &buffer_defaults
.truncate_lines
,
5374 doc
: /* Default value of `truncate-lines' for buffers that do not override it.
5375 This is the same as (default-value 'truncate-lines). */);
5377 DEFVAR_LISP_NOPRO ("default-fill-column",
5378 &buffer_defaults
.fill_column
,
5379 doc
: /* Default value of `fill-column' for buffers that do not override it.
5380 This is the same as (default-value 'fill-column). */);
5382 DEFVAR_LISP_NOPRO ("default-left-margin",
5383 &buffer_defaults
.left_margin
,
5384 doc
: /* Default value of `left-margin' for buffers that do not override it.
5385 This is the same as (default-value 'left-margin). */);
5387 DEFVAR_LISP_NOPRO ("default-tab-width",
5388 &buffer_defaults
.tab_width
,
5389 doc
: /* Default value of `tab-width' for buffers that do not override it.
5390 This is the same as (default-value 'tab-width). */);
5392 DEFVAR_LISP_NOPRO ("default-case-fold-search",
5393 &buffer_defaults
.case_fold_search
,
5394 doc
: /* Default value of `case-fold-search' for buffers that don't override it.
5395 This is the same as (default-value 'case-fold-search). */);
5398 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
5399 &buffer_defaults
.buffer_file_type
,
5400 doc
: /* Default file type for buffers that do not override it.
5401 This is the same as (default-value 'buffer-file-type).
5402 The file type is nil for text, t for binary. */);
5405 DEFVAR_LISP_NOPRO ("default-left-margin-width",
5406 &buffer_defaults
.left_margin_cols
,
5407 doc
: /* Default value of `left-margin-width' for buffers that don't override it.
5408 This is the same as (default-value 'left-margin-width). */);
5410 DEFVAR_LISP_NOPRO ("default-right-margin-width",
5411 &buffer_defaults
.right_margin_cols
,
5412 doc
: /* Default value of `right-margin-width' for buffers that don't override it.
5413 This is the same as (default-value 'right-margin-width). */);
5415 DEFVAR_LISP_NOPRO ("default-left-fringe-width",
5416 &buffer_defaults
.left_fringe_width
,
5417 doc
: /* Default value of `left-fringe-width' for buffers that don't override it.
5418 This is the same as (default-value 'left-fringe-width). */);
5420 DEFVAR_LISP_NOPRO ("default-right-fringe-width",
5421 &buffer_defaults
.right_fringe_width
,
5422 doc
: /* Default value of `right-fringe-width' for buffers that don't override it.
5423 This is the same as (default-value 'right-fringe-width). */);
5425 DEFVAR_LISP_NOPRO ("default-fringes-outside-margins",
5426 &buffer_defaults
.fringes_outside_margins
,
5427 doc
: /* Default value of `fringes-outside-margins' for buffers that don't override it.
5428 This is the same as (default-value 'fringes-outside-margins). */);
5430 DEFVAR_LISP_NOPRO ("default-scroll-bar-width",
5431 &buffer_defaults
.scroll_bar_width
,
5432 doc
: /* Default value of `scroll-bar-width' for buffers that don't override it.
5433 This is the same as (default-value 'scroll-bar-width). */);
5435 DEFVAR_LISP_NOPRO ("default-vertical-scroll-bar",
5436 &buffer_defaults
.vertical_scroll_bar_type
,
5437 doc
: /* Default value of `vertical-scroll-bar' for buffers that don't override it.
5438 This is the same as (default-value 'vertical-scroll-bar). */);
5440 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines",
5441 &buffer_defaults
.indicate_empty_lines
,
5442 doc
: /* Default value of `indicate-empty-lines' for buffers that don't override it.
5443 This is the same as (default-value 'indicate-empty-lines). */);
5445 DEFVAR_LISP_NOPRO ("default-indicate-buffer-boundaries",
5446 &buffer_defaults
.indicate_buffer_boundaries
,
5447 doc
: /* Default value of `indicate-buffer-boundaries' for buffers that don't override it.
5448 This is the same as (default-value 'indicate-buffer-boundaries). */);
5450 DEFVAR_LISP_NOPRO ("default-fringe-indicator-alist",
5451 &buffer_defaults
.fringe_indicator_alist
,
5452 doc
: /* Default value of `fringe-indicator-alist' for buffers that don't override it.
5453 This is the same as (default-value 'fringe-indicator-alist'). */);
5455 DEFVAR_LISP_NOPRO ("default-fringe-cursor-alist",
5456 &buffer_defaults
.fringe_cursor_alist
,
5457 doc
: /* Default value of `fringe-cursor-alist' for buffers that don't override it.
5458 This is the same as (default-value 'fringe-cursor-alist'). */);
5460 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively",
5461 &buffer_defaults
.scroll_up_aggressively
,
5462 doc
: /* Default value of `scroll-up-aggressively'.
5463 This value applies in buffers that don't have their own local values.
5464 This is the same as (default-value 'scroll-up-aggressively). */);
5466 DEFVAR_LISP_NOPRO ("default-scroll-down-aggressively",
5467 &buffer_defaults
.scroll_down_aggressively
,
5468 doc
: /* Default value of `scroll-down-aggressively'.
5469 This value applies in buffers that don't have their own local values.
5470 This is the same as (default-value 'scroll-down-aggressively). */);
5472 DEFVAR_PER_BUFFER ("header-line-format",
5473 ¤t_buffer
->header_line_format
,
5475 doc
: /* Analogous to `mode-line-format', but controls the header line.
5476 The header line appears, optionally, at the top of a window;
5477 the mode line appears at the bottom. */);
5479 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
5481 doc
: /* Template for displaying mode line for current buffer.
5482 Each buffer has its own value of this variable.
5483 Value may be nil, a string, a symbol or a list or cons cell.
5484 A value of nil means don't display a mode line.
5485 For a symbol, its value is used (but it is ignored if t or nil).
5486 A string appearing directly as the value of a symbol is processed verbatim
5487 in that the %-constructs below are not recognized.
5488 Note that unless the symbol is marked as a `risky-local-variable', all
5489 properties in any strings, as well as all :eval and :propertize forms
5490 in the value of that symbol will be ignored.
5491 For a list of the form `(:eval FORM)', FORM is evaluated and the result
5492 is used as a mode line element. Be careful--FORM should not load any files,
5493 because that can cause an infinite recursion.
5494 For a list of the form `(:propertize ELT PROPS...)', ELT is displayed
5495 with the specified properties PROPS applied.
5496 For a list whose car is a symbol, the symbol's value is taken,
5497 and if that is non-nil, the cadr of the list is processed recursively.
5498 Otherwise, the caddr of the list (if there is one) is processed.
5499 For a list whose car is a string or list, each element is processed
5500 recursively and the results are effectively concatenated.
5501 For a list whose car is an integer, the cdr of the list is processed
5502 and padded (if the number is positive) or truncated (if negative)
5503 to the width specified by that number.
5504 A string is printed verbatim in the mode line except for %-constructs:
5505 (%-constructs are allowed when the string is the entire mode-line-format
5506 or when it is found in a cons-cell or a list)
5507 %b -- print buffer name. %f -- print visited file name.
5508 %F -- print frame name.
5509 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.
5510 %& is like %*, but ignore read-only-ness.
5511 % means buffer is read-only and * means it is modified.
5512 For a modified read-only buffer, %* gives % and %+ gives *.
5513 %s -- print process status. %l -- print the current line number.
5514 %c -- print the current column number (this makes editing slower).
5515 To make the column number update correctly in all cases,
5516 `column-number-mode' must be non-nil.
5517 %i -- print the size of the buffer.
5518 %I -- like %i, but use k, M, G, etc., to abbreviate.
5519 %p -- print percent of buffer above top of window, or Top, Bot or All.
5520 %P -- print percent of buffer above bottom of window, perhaps plus Top,
5521 or print Bottom or All.
5522 %n -- print Narrow if appropriate.
5523 %t -- visited file is text or binary (if OS supports this distinction).
5524 %z -- print mnemonics of keyboard, terminal, and buffer coding systems.
5525 %Z -- like %z, but including the end-of-line format.
5526 %e -- print error message about full memory.
5527 %[ -- print one [ for each recursive editing level. %] similar.
5528 %% -- print %. %- -- print infinitely many dashes.
5529 Decimal digits after the % specify field width to which to pad. */);
5531 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
5532 doc
: /* *Major mode for new buffers. Defaults to `fundamental-mode'.
5533 A value of nil means use current buffer's major mode,
5534 provided it is not marked as "special".
5536 When a mode is used by default, `find-file' switches to it
5537 before it reads the contents into the buffer and before
5538 it finishes setting up the buffer. Thus, the mode and
5539 its hooks should not expect certain variables such as
5540 `buffer-read-only' and `buffer-file-coding-system' to be set up. */);
5542 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
5543 make_number (Lisp_Symbol
),
5544 doc
: /* Symbol for current buffer's major mode. */);
5546 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
5548 doc
: /* Pretty name of current buffer's major mode (a string). */);
5550 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
5551 doc
: /* Non-nil turns on automatic expansion of abbrevs as they are inserted. */);
5553 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
5555 doc
: /* *Non-nil if searches and matches should ignore case. */);
5557 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
5558 make_number (Lisp_Int
),
5559 doc
: /* *Column beyond which automatic line-wrapping should happen.
5560 Interactively, you can set the buffer local value using \\[set-fill-column]. */);
5562 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
5563 make_number (Lisp_Int
),
5564 doc
: /* *Column for the default `indent-line-function' to indent to.
5565 Linefeed indents to this column in Fundamental mode. */);
5567 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
5568 make_number (Lisp_Int
),
5569 doc
: /* *Distance between tab stops (for display of tab characters), in columns. */);
5571 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
5572 doc
: /* *Non-nil means display control chars with uparrow.
5573 A value of nil means use backslash and octal digits.
5574 This variable does not apply to characters whose display is specified
5575 in the current display table (if there is one). */);
5577 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
5578 ¤t_buffer
->enable_multibyte_characters
,
5580 doc
: /* Non-nil means the buffer contents are regarded as multi-byte characters.
5581 Otherwise they are regarded as unibyte. This affects the display,
5582 file I/O and the behavior of various editing commands.
5584 This variable is buffer-local but you cannot set it directly;
5585 use the function `set-buffer-multibyte' to change a buffer's representation.
5586 Changing its default value with `setq-default' is supported.
5587 See also variable `default-enable-multibyte-characters' and Info node
5588 `(elisp)Text Representations'. */);
5589 XSYMBOL (intern ("enable-multibyte-characters"))->constant
= 1;
5591 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
5592 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
5593 doc
: /* Coding system to be used for encoding the buffer contents on saving.
5594 This variable applies to saving the buffer, and also to `write-region'
5595 and other functions that use `write-region'.
5596 It does not apply to sending output to subprocesses, however.
5598 If this is nil, the buffer is saved without any code conversion
5599 unless some coding system is specified in `file-coding-system-alist'
5600 for the buffer file.
5602 If the text to be saved cannot be encoded as specified by this variable,
5603 an alternative encoding is selected by `select-safe-coding-system', which see.
5605 The variable `coding-system-for-write', if non-nil, overrides this variable.
5607 This variable is never applied to a way of decoding a file while reading it. */);
5609 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
5611 doc
: /* *Non-nil means lines in the buffer are displayed right to left. */);
5613 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
5614 doc
: /* *Non-nil means do not display continuation lines.
5615 Instead, give each line of text just one screen line.
5617 Note that this is overridden by the variable
5618 `truncate-partial-width-windows' if that variable is non-nil
5619 and this buffer is not full-frame width. */);
5622 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
5624 doc
: /* Non-nil if the visited file is a binary file.
5625 This variable is meaningful on MS-DOG and Windows NT.
5626 On those systems, it is automatically local in every buffer.
5627 On other systems, this variable is normally always nil. */);
5630 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
5631 make_number (Lisp_String
),
5632 doc
: /* Name of default directory of current buffer. Should end with slash.
5633 To interactively change the default directory, use command `cd'. */);
5635 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
5637 doc
: /* Function called (if non-nil) to perform auto-fill.
5638 It is called after self-inserting any character specified in
5639 the `auto-fill-chars' table.
5640 NOTE: This variable is not a hook;
5641 its value may not be a list of functions. */);
5643 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
5644 make_number (Lisp_String
),
5645 doc
: /* Name of file visited in current buffer, or nil if not visiting a file. */);
5647 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
5648 make_number (Lisp_String
),
5649 doc
: /* Abbreviated truename of file visited in current buffer, or nil if none.
5650 The truename of a file is calculated by `file-truename'
5651 and then abbreviated with `abbreviate-file-name'. */);
5653 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
5654 ¤t_buffer
->auto_save_file_name
,
5655 make_number (Lisp_String
),
5656 doc
: /* Name of file for auto-saving current buffer.
5657 If it is nil, that means don't auto-save this buffer. */);
5659 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
5660 doc
: /* Non-nil if this buffer is read-only. */);
5662 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
5663 doc
: /* Non-nil if this buffer's file has been backed up.
5664 Backing up is done before the first time the file is saved. */);
5666 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
5667 make_number (Lisp_Int
),
5668 doc
: /* Length of current buffer when last read in, saved or auto-saved.
5671 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
5673 doc
: /* Non-nil enables selective display.
5674 An Integer N as value means display only lines
5675 that start with less than n columns of space.
5676 A value of t means that the character ^M makes itself and
5677 all the rest of the line invisible; also, when saving the buffer
5678 in a file, save the ^M as a newline. */);
5681 DEFVAR_PER_BUFFER ("selective-display-ellipses",
5682 ¤t_buffer
->selective_display_ellipses
,
5684 doc
: /* Non-nil means display ... on previous line when a line is invisible. */);
5687 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
5688 doc
: /* Non-nil if self-insertion should replace existing text.
5689 The value should be one of `overwrite-mode-textual',
5690 `overwrite-mode-binary', or nil.
5691 If it is `overwrite-mode-textual', self-insertion still
5692 inserts at the end of a line, and inserts when point is before a tab,
5693 until the tab is filled in.
5694 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too. */);
5696 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
5698 doc
: /* Display table that controls display of the contents of current buffer.
5700 If this variable is nil, the value of `standard-display-table' is used.
5701 Each window can have its own, overriding display table, see
5702 `set-window-display-table' and `window-display-table'.
5704 The display table is a char-table created with `make-display-table'.
5705 A char-table is an array indexed by character codes. Normal array
5706 primitives `aref' and `aset' can be used to access elements of a char-table.
5708 Each of the char-table elements control how to display the corresponding
5709 text character: the element at index C in the table says how to display
5710 the character whose code is C. Each element should be a vector of
5711 characters or nil. The value nil means display the character in the
5712 default fashion; otherwise, the characters from the vector are delivered
5713 to the screen instead of the original character.
5715 For example, (aset buffer-display-table ?X ?Y) will cause Emacs to display
5716 a capital Y instead of each X character.
5718 In addition, a char-table has six extra slots to control the display of:
5720 the end of a truncated screen line (extra-slot 0, a single character);
5721 the end of a continued line (extra-slot 1, a single character);
5722 the escape character used to display character codes in octal
5723 (extra-slot 2, a single character);
5724 the character used as an arrow for control characters (extra-slot 3,
5725 a single character);
5726 the decoration indicating the presence of invisible lines (extra-slot 4,
5727 a vector of characters);
5728 the character used to draw the border between side-by-side windows
5729 (extra-slot 5, a single character).
5731 See also the functions `display-table-slot' and `set-display-table-slot'. */);
5733 DEFVAR_PER_BUFFER ("left-margin-width", ¤t_buffer
->left_margin_cols
,
5735 doc
: /* *Width of left marginal area for display of a buffer.
5736 A value of nil means no marginal area. */);
5738 DEFVAR_PER_BUFFER ("right-margin-width", ¤t_buffer
->right_margin_cols
,
5740 doc
: /* *Width of right marginal area for display of a buffer.
5741 A value of nil means no marginal area. */);
5743 DEFVAR_PER_BUFFER ("left-fringe-width", ¤t_buffer
->left_fringe_width
,
5745 doc
: /* *Width of this buffer's left fringe (in pixels).
5746 A value of 0 means no left fringe is shown in this buffer's window.
5747 A value of nil means to use the left fringe width from the window's frame. */);
5749 DEFVAR_PER_BUFFER ("right-fringe-width", ¤t_buffer
->right_fringe_width
,
5751 doc
: /* *Width of this buffer's right fringe (in pixels).
5752 A value of 0 means no right fringe is shown in this buffer's window.
5753 A value of nil means to use the right fringe width from the window's frame. */);
5755 DEFVAR_PER_BUFFER ("fringes-outside-margins", ¤t_buffer
->fringes_outside_margins
,
5757 doc
: /* *Non-nil means to display fringes outside display margins.
5758 A value of nil means to display fringes between margins and buffer text. */);
5760 DEFVAR_PER_BUFFER ("scroll-bar-width", ¤t_buffer
->scroll_bar_width
,
5762 doc
: /* *Width of this buffer's scroll bars in pixels.
5763 A value of nil means to use the scroll bar width from the window's frame. */);
5765 DEFVAR_PER_BUFFER ("vertical-scroll-bar", ¤t_buffer
->vertical_scroll_bar_type
,
5767 doc
: /* *Position of this buffer's vertical scroll bar.
5768 The value takes effect whenever you tell a window to display this buffer;
5769 for instance, with `set-window-buffer' or when `display-buffer' displays it.
5771 A value of `left' or `right' means put the vertical scroll bar at that side
5772 of the window; a value of nil means don't show any vertical scroll bars.
5773 A value of t (the default) means do whatever the window's frame specifies. */);
5775 DEFVAR_PER_BUFFER ("indicate-empty-lines",
5776 ¤t_buffer
->indicate_empty_lines
, Qnil
,
5777 doc
: /* *Visually indicate empty lines after the buffer end.
5778 If non-nil, a bitmap is displayed in the left fringe of a window on
5779 window-systems. */);
5781 DEFVAR_PER_BUFFER ("indicate-buffer-boundaries",
5782 ¤t_buffer
->indicate_buffer_boundaries
, Qnil
,
5783 doc
: /* *Visually indicate buffer boundaries and scrolling.
5784 If non-nil, the first and last line of the buffer are marked in the fringe
5785 of a window on window-systems with angle bitmaps, or if the window can be
5786 scrolled, the top and bottom line of the window are marked with up and down
5789 If value is a symbol `left' or `right', both angle and arrow bitmaps
5790 are displayed in the left or right fringe, resp. Any other value
5791 that doesn't look like an alist means display the angle bitmaps in
5792 the left fringe but no arrows.
5794 You can exercise more precise control by using an alist as the
5795 value. Each alist element (INDICATOR . POSITION) specifies
5796 where to show one of the indicators. INDICATOR is one of `top',
5797 `bottom', `up', `down', or t, which specifies the default position,
5798 and POSITION is one of `left', `right', or nil, meaning do not show
5801 For example, ((top . left) (t . right)) places the top angle bitmap in
5802 left fringe, the bottom angle bitmap in right fringe, and both arrow
5803 bitmaps in right fringe. To show just the angle bitmaps in the left
5804 fringe, but no arrow bitmaps, use ((top . left) (bottom . left)). */);
5806 DEFVAR_PER_BUFFER ("fringe-indicator-alist",
5807 ¤t_buffer
->fringe_indicator_alist
, Qnil
,
5808 doc
: /* *Mapping from logical to physical fringe indicator bitmaps.
5809 The value is an alist where each element (INDICATOR . BITMAPS)
5810 specifies the fringe bitmaps used to display a specific logical
5813 INDICATOR specifies the logical indicator type which is one of the
5814 following symbols: `truncation' , `continuation', `overlay-arrow',
5815 `top', `bottom', `up', `down', `one-line', `empty-line', or `unknown'.
5817 BITMAPS is list of symbols (LEFT RIGHT [LEFT1 RIGHT1]) which specifies
5818 the actual bitmap shown in the left or right fringe for the logical
5819 indicator. LEFT and RIGHT are the bitmaps shown in the left and/or
5820 right fringe for the specific indicator. The LEFT1 or RIGHT1 bitmaps
5821 are used only for the `bottom' and `one-line' indicators when the last
5822 \(only) line in has no final newline. BITMAPS may also be a single
5823 symbol which is used in both left and right fringes. */);
5825 DEFVAR_PER_BUFFER ("fringe-cursor-alist",
5826 ¤t_buffer
->fringe_cursor_alist
, Qnil
,
5827 doc
: /* *Mapping from logical to physical fringe cursor bitmaps.
5828 The value is an alist where each element (CURSOR . BITMAP)
5829 specifies the fringe bitmaps used to display a specific logical
5830 cursor type in the fringe.
5832 CURSOR specifies the logical cursor type which is one of the following
5833 symbols: `box' , `hollow', `bar', `hbar', or `hollow-small'. The last
5834 one is used to show a hollow cursor on narrow lines display lines
5835 where the normal hollow cursor will not fit.
5837 BITMAP is the corresponding fringe bitmap shown for the logical
5840 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
5841 ¤t_buffer
->scroll_up_aggressively
, Qnil
,
5842 doc
: /* How far to scroll windows upward.
5843 If you move point off the bottom, the window scrolls automatically.
5844 This variable controls how far it scrolls. The value nil, the default,
5845 means scroll to center point. A fraction means scroll to put point
5846 that fraction of the window's height from the bottom of the window.
5847 When the value is 0.0, point goes at the bottom line, which in the simple
5848 case that you moved off with C-f means scrolling just one line. 1.0 means
5849 point goes at the top, so that in that simple case, the window
5850 scrolls by a full window height. Meaningful values are
5851 between 0.0 and 1.0, inclusive. */);
5853 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
5854 ¤t_buffer
->scroll_down_aggressively
, Qnil
,
5855 doc
: /* How far to scroll windows downward.
5856 If you move point off the top, the window scrolls automatically.
5857 This variable controls how far it scrolls. The value nil, the default,
5858 means scroll to center point. A fraction means scroll to put point
5859 that fraction of the window's height from the top of the window.
5860 When the value is 0.0, point goes at the top line, which in the simple
5861 case that you moved off with C-b means scrolling just one line. 1.0 means
5862 point goes at the bottom, so that in that simple case, the window
5863 scrolls by a full window height. Meaningful values are
5864 between 0.0 and 1.0, inclusive. */);
5866 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
5870 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
5871 doc
: /* List of functions to call before each text change.
5872 Two arguments are passed to each function: the positions of
5873 the beginning and end of the range of old text to be changed.
5874 \(For an insertion, the beginning and end are at the same place.)
5875 No information is given about the length of the text after the change.
5877 Buffer changes made while executing the `before-change-functions'
5878 don't call any before-change or after-change functions.
5879 That's because these variables are temporarily set to nil.
5880 As a result, a hook function cannot straightforwardly alter the value of
5881 these variables. See the Emacs Lisp manual for a way of
5882 accomplishing an equivalent result by using other variables.
5884 If an unhandled error happens in running these functions,
5885 the variable's value remains nil. That prevents the error
5886 from happening repeatedly and making Emacs nonfunctional. */);
5887 Vbefore_change_functions
= Qnil
;
5889 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
5890 doc
: /* List of functions to call after each text change.
5891 Three arguments are passed to each function: the positions of
5892 the beginning and end of the range of changed text,
5893 and the length in bytes of the pre-change text replaced by that range.
5894 \(For an insertion, the pre-change length is zero;
5895 for a deletion, that length is the number of bytes deleted,
5896 and the post-change beginning and end are at the same place.)
5898 Buffer changes made while executing the `after-change-functions'
5899 don't call any before-change or after-change functions.
5900 That's because these variables are temporarily set to nil.
5901 As a result, a hook function cannot straightforwardly alter the value of
5902 these variables. See the Emacs Lisp manual for a way of
5903 accomplishing an equivalent result by using other variables.
5905 If an unhandled error happens in running these functions,
5906 the variable's value remains nil. That prevents the error
5907 from happening repeatedly and making Emacs nonfunctional. */);
5908 Vafter_change_functions
= Qnil
;
5910 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
5911 doc
: /* A list of functions to call before changing a buffer which is unmodified.
5912 The functions are run using the `run-hooks' function. */);
5913 Vfirst_change_hook
= Qnil
;
5915 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
5916 doc
: /* List of undo entries in current buffer.
5917 Recent changes come first; older changes follow newer.
5919 An entry (BEG . END) represents an insertion which begins at
5920 position BEG and ends at position END.
5922 An entry (TEXT . POSITION) represents the deletion of the string TEXT
5923 from (abs POSITION). If POSITION is positive, point was at the front
5924 of the text being deleted; if negative, point was at the end.
5926 An entry (t HIGH . LOW) indicates that the buffer previously had
5927 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions
5928 of the visited file's modification time, as of that time. If the
5929 modification time of the most recent save is different, this entry is
5932 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property
5933 was modified between BEG and END. PROPERTY is the property name,
5934 and VALUE is the old value.
5936 An entry (apply FUN-NAME . ARGS) means undo the change with
5937 \(apply FUN-NAME ARGS).
5939 An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo
5940 in the active region. BEG and END is the range affected by this entry
5941 and DELTA is the number of bytes added or deleted in that range by
5944 An entry (MARKER . DISTANCE) indicates that the marker MARKER
5945 was adjusted in position by the offset DISTANCE (an integer).
5947 An entry of the form POSITION indicates that point was at the buffer
5948 location given by the integer. Undoing an entry of this form places
5951 Entries with value `nil' mark undo boundaries. The undo command treats
5952 the changes between two undo boundaries as a single step to be undone.
5954 If the value of the variable is t, undo information is not recorded. */);
5956 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
5957 doc
: /* Non-nil means the mark and region are currently active in this buffer. */);
5959 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
5960 doc
: /* Non-nil means that Emacs should use caches to handle long lines more quickly.
5962 Normally, the line-motion functions work by scanning the buffer for
5963 newlines. Columnar operations (like `move-to-column' and
5964 `compute-motion') also work by scanning the buffer, summing character
5965 widths as they go. This works well for ordinary text, but if the
5966 buffer's lines are very long (say, more than 500 characters), these
5967 motion functions will take longer to execute. Emacs may also take
5968 longer to update the display.
5970 If `cache-long-line-scans' is non-nil, these motion functions cache the
5971 results of their scans, and consult the cache to avoid rescanning
5972 regions of the buffer until the text is modified. The caches are most
5973 beneficial when they prevent the most searching---that is, when the
5974 buffer contains long lines and large regions of characters with the
5975 same, fixed screen width.
5977 When `cache-long-line-scans' is non-nil, processing short lines will
5978 become slightly slower (because of the overhead of consulting the
5979 cache), and the caches will use memory roughly proportional to the
5980 number of newlines and characters whose screen width varies.
5982 The caches require no explicit maintenance; their accuracy is
5983 maintained internally by the Emacs primitives. Enabling or disabling
5984 the cache should not affect the behavior of any of the motion
5985 functions; it should only affect their performance. */);
5987 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
5988 doc
: /* Value of point before the last series of scroll operations, or nil. */);
5990 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
5991 doc
: /* List of formats to use when saving this buffer.
5992 Formats are defined by `format-alist'. This variable is
5993 set when a file is visited. */);
5995 DEFVAR_PER_BUFFER ("buffer-auto-save-file-format",
5996 ¤t_buffer
->auto_save_file_format
, Qnil
,
5997 doc
: /* *Format in which to write auto-save files.
5998 Should be a list of symbols naming formats that are defined in `format-alist'.
5999 If it is t, which is the default, auto-save files are written in the
6000 same format as a regular save would use. */);
6002 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
6003 ¤t_buffer
->invisibility_spec
, Qnil
,
6004 doc
: /* Invisibility spec of this buffer.
6005 The default is t, which means that text is invisible
6006 if it has a non-nil `invisible' property.
6007 If the value is a list, a text character is invisible if its `invisible'
6008 property is an element in that list.
6009 If an element is a cons cell of the form (PROP . ELLIPSIS),
6010 then characters with property value PROP are invisible,
6011 and they have an ellipsis as well if ELLIPSIS is non-nil. */);
6013 DEFVAR_PER_BUFFER ("buffer-display-count",
6014 ¤t_buffer
->display_count
, Qnil
,
6015 doc
: /* A number incremented each time this buffer is displayed in a window.
6016 The function `set-window-buffer' increments it. */);
6018 DEFVAR_PER_BUFFER ("buffer-display-time",
6019 ¤t_buffer
->display_time
, Qnil
,
6020 doc
: /* Time stamp updated each time this buffer is displayed in a window.
6021 The function `set-window-buffer' updates this variable
6022 to the value obtained by calling `current-time'.
6023 If the buffer has never been shown in a window, the value is nil. */);
6025 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
6026 doc
: /* *Non-nil means deactivate the mark when the buffer contents change.
6027 Non-nil also enables highlighting of the region whenever the mark is active.
6028 The variable `highlight-nonselected-windows' controls whether to highlight
6029 all windows or just the selected window.
6031 If the value is `lambda', that enables Transient Mark mode temporarily
6032 until the next buffer modification. If a command sets the value to `only',
6033 that enables Transient Mark mode for the following command only.
6034 During that following command, the value of `transient-mark-mode'
6035 is `identity'. If it is still `identity' at the end of that command,
6036 it changes to nil. */);
6037 Vtransient_mark_mode
= Qnil
;
6039 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
6040 doc
: /* *Non-nil means disregard read-only status of buffers or characters.
6041 If the value is t, disregard `buffer-read-only' and all `read-only'
6042 text properties. If the value is a list, disregard `buffer-read-only'
6043 and disregard a `read-only' text property if the property value
6044 is a member of the list. */);
6045 Vinhibit_read_only
= Qnil
;
6047 DEFVAR_PER_BUFFER ("cursor-type", ¤t_buffer
->cursor_type
, Qnil
,
6048 doc
: /* Cursor to use when this buffer is in the selected window.
6049 Values are interpreted as follows:
6051 t use the cursor specified for the frame
6052 nil don't display a cursor
6053 box display a filled box cursor
6054 hollow display a hollow box cursor
6055 bar display a vertical bar cursor with default width
6056 (bar . WIDTH) display a vertical bar cursor with width WIDTH
6057 hbar display a horizontal bar cursor with default height
6058 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
6059 ANYTHING ELSE display a hollow box cursor
6061 When the buffer is displayed in a nonselected window,
6062 this variable has no effect; the cursor appears as a hollow box. */);
6064 DEFVAR_PER_BUFFER ("line-spacing",
6065 ¤t_buffer
->extra_line_spacing
, Qnil
,
6066 doc
: /* Additional space to put between lines when displaying a buffer.
6067 The space is measured in pixels, and put below lines on window systems.
6068 If value is a floating point number, it specifies the spacing relative
6069 to the default frame line height. A value of nil means add no extra space. */);
6071 DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
6072 ¤t_buffer
->cursor_in_non_selected_windows
, Qnil
,
6073 doc
: /* *Cursor type to display in non-selected windows.
6074 The value t means to use hollow box cursor. See `cursor-type' for other values. */);
6076 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
6077 doc
: /* List of functions called with no args to query before killing a buffer.
6078 The buffer being killed will be current while the functions are running.
6079 If any of them returns nil, the buffer is not killed. */);
6080 Vkill_buffer_query_functions
= Qnil
;
6082 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook
,
6083 doc
: /* Normal hook run before changing the major mode of a buffer.
6084 The function `kill-all-local-variables' runs this before doing anything else. */);
6085 Vchange_major_mode_hook
= Qnil
;
6086 Qchange_major_mode_hook
= intern ("change-major-mode-hook");
6087 staticpro (&Qchange_major_mode_hook
);
6089 defsubr (&Sbuffer_live_p
);
6090 defsubr (&Sbuffer_list
);
6091 defsubr (&Sget_buffer
);
6092 defsubr (&Sget_file_buffer
);
6093 defsubr (&Sget_buffer_create
);
6094 defsubr (&Smake_indirect_buffer
);
6095 defsubr (&Sgenerate_new_buffer_name
);
6096 defsubr (&Sbuffer_name
);
6097 /*defsubr (&Sbuffer_number);*/
6098 defsubr (&Sbuffer_file_name
);
6099 defsubr (&Sbuffer_base_buffer
);
6100 defsubr (&Sbuffer_local_value
);
6101 defsubr (&Sbuffer_local_variables
);
6102 defsubr (&Sbuffer_modified_p
);
6103 defsubr (&Sset_buffer_modified_p
);
6104 defsubr (&Sbuffer_modified_tick
);
6105 defsubr (&Sbuffer_chars_modified_tick
);
6106 defsubr (&Srename_buffer
);
6107 defsubr (&Sother_buffer
);
6108 defsubr (&Sbuffer_enable_undo
);
6109 defsubr (&Skill_buffer
);
6110 defsubr (&Sset_buffer_major_mode
);
6111 defsubr (&Sswitch_to_buffer
);
6112 defsubr (&Spop_to_buffer
);
6113 defsubr (&Scurrent_buffer
);
6114 defsubr (&Sset_buffer
);
6115 defsubr (&Sbarf_if_buffer_read_only
);
6116 defsubr (&Sbury_buffer
);
6117 defsubr (&Serase_buffer
);
6118 defsubr (&Sset_buffer_multibyte
);
6119 defsubr (&Skill_all_local_variables
);
6121 defsubr (&Soverlayp
);
6122 defsubr (&Smake_overlay
);
6123 defsubr (&Sdelete_overlay
);
6124 defsubr (&Smove_overlay
);
6125 defsubr (&Soverlay_start
);
6126 defsubr (&Soverlay_end
);
6127 defsubr (&Soverlay_buffer
);
6128 defsubr (&Soverlay_properties
);
6129 defsubr (&Soverlays_at
);
6130 defsubr (&Soverlays_in
);
6131 defsubr (&Snext_overlay_change
);
6132 defsubr (&Sprevious_overlay_change
);
6133 defsubr (&Soverlay_recenter
);
6134 defsubr (&Soverlay_lists
);
6135 defsubr (&Soverlay_get
);
6136 defsubr (&Soverlay_put
);
6137 defsubr (&Srestore_buffer_modified_p
);
6143 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
6144 initial_define_key (control_x_map
, 'k', "kill-buffer");
6146 /* This must not be in syms_of_buffer, because Qdisabled is not
6147 initialized when that function gets called. */
6148 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);
6151 /* arch-tag: e48569bf-69a9-4b65-a23b-8e68769436e1
6152 (do not change this comment) */