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 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"
45 #include "character.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 /* List of functions to call before changing an unmodified buffer. */
150 Lisp_Object Vfirst_change_hook
;
152 Lisp_Object Qfirst_change_hook
;
153 Lisp_Object Qbefore_change_functions
;
154 Lisp_Object Qafter_change_functions
;
155 Lisp_Object Qucs_set_table_for_input
;
157 /* If nonzero, all modification hooks are suppressed. */
158 int inhibit_modification_hooks
;
160 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
162 Lisp_Object Qprotected_field
;
164 Lisp_Object QSFundamental
; /* A string "Fundamental" */
166 Lisp_Object Qkill_buffer_hook
;
168 Lisp_Object Qget_file_buffer
;
170 Lisp_Object Qoverlayp
;
172 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
174 Lisp_Object Qmodification_hooks
;
175 Lisp_Object Qinsert_in_front_hooks
;
176 Lisp_Object Qinsert_behind_hooks
;
178 static void alloc_buffer_text
P_ ((struct buffer
*, size_t));
179 static void free_buffer_text
P_ ((struct buffer
*b
));
180 static struct Lisp_Overlay
* copy_overlays
P_ ((struct buffer
*, struct Lisp_Overlay
*));
181 static void modify_overlay
P_ ((struct buffer
*, EMACS_INT
, EMACS_INT
));
182 static Lisp_Object buffer_lisp_local_variables
P_ ((struct buffer
*));
184 extern char * emacs_strerror
P_ ((int));
186 /* For debugging; temporary. See set_buffer_internal. */
187 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
194 error ("No buffer named %s", SDATA (spec
));
195 error ("Invalid buffer argument");
198 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
199 doc
: /* Return non-nil if OBJECT is a buffer which has not been killed.
200 Value is nil if OBJECT is not a buffer or if it has been killed. */)
204 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
208 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
209 doc
: /* Return a list of all existing live buffers.
210 If the optional arg FRAME is a frame, we return the buffer list
211 in the proper order for that frame: the buffers in FRAME's `buffer-list'
212 frame parameter come first, followed by the rest of the buffers. */)
216 Lisp_Object framelist
, general
;
217 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
225 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
227 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */
229 while (! NILP (tail
))
231 general
= Fdelq (XCAR (tail
), general
);
234 return nconc2 (framelist
, general
);
240 /* Like Fassoc, but use Fstring_equal to compare
241 (which ignores text properties),
242 and don't ever QUIT. */
245 assoc_ignore_text_properties (key
, list
)
246 register Lisp_Object key
;
249 register Lisp_Object tail
;
250 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
252 register Lisp_Object elt
, tem
;
254 tem
= Fstring_equal (Fcar (elt
), key
);
261 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
262 doc
: /* Return the buffer named NAME (a string).
263 If there is no live buffer named NAME, return nil.
264 NAME may also be a buffer; if so, the value is that buffer. */)
266 register Lisp_Object name
;
272 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
275 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
276 doc
: /* Return the buffer visiting file FILENAME (a string).
277 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.
278 If there is no such live buffer, return nil.
279 See also `find-buffer-visiting'. */)
281 register Lisp_Object filename
;
283 register Lisp_Object tail
, buf
, tem
;
286 CHECK_STRING (filename
);
287 filename
= Fexpand_file_name (filename
, Qnil
);
289 /* If the file name has special constructs in it,
290 call the corresponding file handler. */
291 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
293 return call2 (handler
, Qget_file_buffer
, filename
);
295 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
297 buf
= Fcdr (XCAR (tail
));
298 if (!BUFFERP (buf
)) continue;
299 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
300 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
308 get_truename_buffer (filename
)
309 register Lisp_Object filename
;
311 register Lisp_Object tail
, buf
, tem
;
313 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
315 buf
= Fcdr (XCAR (tail
));
316 if (!BUFFERP (buf
)) continue;
317 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
318 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
325 /* Incremented for each buffer created, to assign the buffer number. */
328 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
329 doc
: /* Return the buffer named NAME, or create such a buffer and return it.
330 A new buffer is created if there is no live buffer named NAME.
331 If NAME starts with a space, the new buffer does not keep undo information.
332 If NAME is a buffer instead of a string, then it is the value returned.
333 The value is never nil. */)
335 register Lisp_Object name
;
337 register Lisp_Object buf
;
338 register struct buffer
*b
;
340 buf
= Fget_buffer (name
);
344 if (SCHARS (name
) == 0)
345 error ("Empty string for buffer name is not allowed");
347 b
= (struct buffer
*) allocate_buffer ();
349 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
351 /* An ordinary buffer uses its own struct buffer_text. */
352 b
->text
= &b
->own_text
;
355 BUF_GAP_SIZE (b
) = 20;
357 /* We allocate extra 1-byte at the tail and keep it always '\0' for
358 anchoring a search. */
359 alloc_buffer_text (b
, BUF_GAP_SIZE (b
) + 1);
361 if (! BUF_BEG_ADDR (b
))
362 buffer_memory_full ();
369 BUF_PT_BYTE (b
) = BEG_BYTE
;
370 BUF_GPT_BYTE (b
) = BEG_BYTE
;
371 BUF_BEGV_BYTE (b
) = BEG_BYTE
;
372 BUF_ZV_BYTE (b
) = BEG_BYTE
;
373 BUF_Z_BYTE (b
) = BEG_BYTE
;
375 BUF_OVERLAY_MODIFF (b
) = 1;
376 BUF_SAVE_MODIFF (b
) = 1;
377 BUF_INTERVALS (b
) = 0;
378 BUF_UNCHANGED_MODIFIED (b
) = 1;
379 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = 1;
380 BUF_END_UNCHANGED (b
) = 0;
381 BUF_BEG_UNCHANGED (b
) = 0;
382 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
384 b
->newline_cache
= 0;
385 b
->width_run_cache
= 0;
386 b
->width_table
= Qnil
;
387 b
->prevent_redisplay_optimizations_p
= 1;
389 /* Put this on the chain of all buffers including killed ones. */
390 b
->next
= all_buffers
;
393 /* An ordinary buffer normally doesn't need markers
394 to handle BEGV and ZV. */
396 b
->begv_marker
= Qnil
;
399 name
= Fcopy_sequence (name
);
400 STRING_SET_INTERVALS (name
, NULL_INTERVAL
);
403 if (SREF (name
, 0) != ' ')
409 reset_buffer_local_variables (b
, 1);
411 b
->mark
= Fmake_marker ();
412 BUF_MARKERS (b
) = NULL
;
415 /* Put this in the alist of all live buffers. */
417 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
419 /* An error in calling the function here (should someone redfine it)
420 can lead to infinite regress until you run out of stack. rms
421 says that's not worth protecting against. */
422 if (!NILP (Ffboundp (Qucs_set_table_for_input
)))
423 /* buf is on buffer-alist, so no gcpro. */
424 call1 (Qucs_set_table_for_input
, buf
);
430 /* Return a list of overlays which is a copy of the overlay list
431 LIST, but for buffer B. */
433 static struct Lisp_Overlay
*
434 copy_overlays (b
, list
)
436 struct Lisp_Overlay
*list
;
439 struct Lisp_Overlay
*result
= NULL
, *tail
= NULL
;
441 XSETBUFFER (buffer
, b
);
443 for (; list
; list
= list
->next
)
445 Lisp_Object overlay
, start
, end
, old_overlay
;
448 XSETMISC (old_overlay
, list
);
449 charpos
= marker_position (OVERLAY_START (old_overlay
));
450 start
= Fmake_marker ();
451 Fset_marker (start
, make_number (charpos
), buffer
);
452 XMARKER (start
)->insertion_type
453 = XMARKER (OVERLAY_START (old_overlay
))->insertion_type
;
455 charpos
= marker_position (OVERLAY_END (old_overlay
));
456 end
= Fmake_marker ();
457 Fset_marker (end
, make_number (charpos
), buffer
);
458 XMARKER (end
)->insertion_type
459 = XMARKER (OVERLAY_END (old_overlay
))->insertion_type
;
461 overlay
= allocate_misc ();
462 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
463 OVERLAY_START (overlay
) = start
;
464 OVERLAY_END (overlay
) = end
;
465 OVERLAY_PLIST (overlay
) = Fcopy_sequence (OVERLAY_PLIST (old_overlay
));
466 XOVERLAY (overlay
)->next
= NULL
;
469 tail
= tail
->next
= XOVERLAY (overlay
);
471 result
= tail
= XOVERLAY (overlay
);
478 /* Clone per-buffer values of buffer FROM.
480 Buffer TO gets the same per-buffer values as FROM, with the
481 following exceptions: (1) TO's name is left untouched, (2) markers
482 are copied and made to refer to TO, and (3) overlay lists are
486 clone_per_buffer_values (from
, to
)
487 struct buffer
*from
, *to
;
489 Lisp_Object to_buffer
, tem
;
492 XSETBUFFER (to_buffer
, to
);
494 for (offset
= PER_BUFFER_VAR_OFFSET (name
) + sizeof (Lisp_Object
);
496 offset
+= sizeof (Lisp_Object
))
500 obj
= PER_BUFFER_VALUE (from
, offset
);
503 struct Lisp_Marker
*m
= XMARKER (obj
);
504 obj
= Fmake_marker ();
505 XMARKER (obj
)->insertion_type
= m
->insertion_type
;
506 set_marker_both (obj
, to_buffer
, m
->charpos
, m
->bytepos
);
509 PER_BUFFER_VALUE (to
, offset
) = obj
;
512 bcopy (from
->local_flags
, to
->local_flags
, sizeof to
->local_flags
);
514 to
->overlays_before
= copy_overlays (to
, from
->overlays_before
);
515 to
->overlays_after
= copy_overlays (to
, from
->overlays_after
);
517 /* Get (a copy of) the alist of Lisp-level local variables of FROM
518 and install that in TO. */
519 to
->local_var_alist
= buffer_lisp_local_variables (from
);
522 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
,
524 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
525 doc
: /* Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.
526 BASE-BUFFER should be a live buffer, or the name of an existing buffer.
527 NAME should be a string which is not the name of an existing buffer.
528 Optional argument CLONE non-nil means preserve BASE-BUFFER's state,
529 such as major and minor modes, in the indirect buffer.
530 CLONE nil means the indirect buffer's state is reset to default values. */)
531 (base_buffer
, name
, clone
)
532 Lisp_Object base_buffer
, name
, clone
;
534 Lisp_Object buf
, tem
;
538 buf
= Fget_buffer (name
);
540 error ("Buffer name `%s' is in use", SDATA (name
));
543 base_buffer
= Fget_buffer (base_buffer
);
544 if (NILP (base_buffer
))
545 error ("No such buffer: `%s'", SDATA (tem
));
546 if (NILP (XBUFFER (base_buffer
)->name
))
547 error ("Base buffer has been killed");
549 if (SCHARS (name
) == 0)
550 error ("Empty string for buffer name is not allowed");
552 b
= (struct buffer
*) allocate_buffer ();
553 b
->size
= sizeof (struct buffer
) / sizeof (EMACS_INT
);
555 if (XBUFFER (base_buffer
)->base_buffer
)
556 b
->base_buffer
= XBUFFER (base_buffer
)->base_buffer
;
558 b
->base_buffer
= XBUFFER (base_buffer
);
560 /* Use the base buffer's text object. */
561 b
->text
= b
->base_buffer
->text
;
563 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
564 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
565 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
566 BUF_BEGV_BYTE (b
) = BUF_BEGV_BYTE (b
->base_buffer
);
567 BUF_ZV_BYTE (b
) = BUF_ZV_BYTE (b
->base_buffer
);
568 BUF_PT_BYTE (b
) = BUF_PT_BYTE (b
->base_buffer
);
570 b
->newline_cache
= 0;
571 b
->width_run_cache
= 0;
572 b
->width_table
= Qnil
;
574 /* Put this on the chain of all buffers including killed ones. */
575 b
->next
= all_buffers
;
578 name
= Fcopy_sequence (name
);
579 STRING_SET_INTERVALS (name
, NULL_INTERVAL
);
583 reset_buffer_local_variables (b
, 1);
585 /* Put this in the alist of all live buffers. */
587 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
589 b
->mark
= Fmake_marker ();
592 /* The multibyte status belongs to the base buffer. */
593 b
->enable_multibyte_characters
= b
->base_buffer
->enable_multibyte_characters
;
595 /* Make sure the base buffer has markers for its narrowing. */
596 if (NILP (b
->base_buffer
->pt_marker
))
598 b
->base_buffer
->pt_marker
= Fmake_marker ();
599 set_marker_both (b
->base_buffer
->pt_marker
, base_buffer
,
600 BUF_PT (b
->base_buffer
),
601 BUF_PT_BYTE (b
->base_buffer
));
603 if (NILP (b
->base_buffer
->begv_marker
))
605 b
->base_buffer
->begv_marker
= Fmake_marker ();
606 set_marker_both (b
->base_buffer
->begv_marker
, base_buffer
,
607 BUF_BEGV (b
->base_buffer
),
608 BUF_BEGV_BYTE (b
->base_buffer
));
610 if (NILP (b
->base_buffer
->zv_marker
))
612 b
->base_buffer
->zv_marker
= Fmake_marker ();
613 set_marker_both (b
->base_buffer
->zv_marker
, base_buffer
,
614 BUF_ZV (b
->base_buffer
),
615 BUF_ZV_BYTE (b
->base_buffer
));
616 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
621 /* Give the indirect buffer markers for its narrowing. */
622 b
->pt_marker
= Fmake_marker ();
623 set_marker_both (b
->pt_marker
, buf
, BUF_PT (b
), BUF_PT_BYTE (b
));
624 b
->begv_marker
= Fmake_marker ();
625 set_marker_both (b
->begv_marker
, buf
, BUF_BEGV (b
), BUF_BEGV_BYTE (b
));
626 b
->zv_marker
= Fmake_marker ();
627 set_marker_both (b
->zv_marker
, buf
, BUF_ZV (b
), BUF_ZV_BYTE (b
));
628 XMARKER (b
->zv_marker
)->insertion_type
= 1;
632 struct buffer
*old_b
= current_buffer
;
634 clone_per_buffer_values (b
->base_buffer
, b
);
636 b
->file_truename
= Qnil
;
637 b
->display_count
= make_number (0);
639 b
->auto_save_file_name
= Qnil
;
640 set_buffer_internal_1 (b
);
641 Fset (intern ("buffer-save-without-query"), Qnil
);
642 Fset (intern ("buffer-file-number"), Qnil
);
643 Fset (intern ("buffer-stale-function"), Qnil
);
644 set_buffer_internal_1 (old_b
);
651 delete_all_overlays (b
)
656 /* `reset_buffer' blindly sets the list of overlays to NULL, so we
657 have to empty the list, otherwise we end up with overlays that
658 think they belong to this buffer while the buffer doesn't know about
660 while (b
->overlays_before
)
662 XSETMISC (overlay
, b
->overlays_before
);
663 Fdelete_overlay (overlay
);
665 while (b
->overlays_after
)
667 XSETMISC (overlay
, b
->overlays_after
);
668 Fdelete_overlay (overlay
);
670 eassert (b
->overlays_before
== NULL
);
671 eassert (b
->overlays_after
== NULL
);
674 /* Reinitialize everything about a buffer except its name and contents
676 If called on an already-initialized buffer, the list of overlays
677 should be deleted before calling this function, otherwise we end up
678 with overlays that claim to belong to the buffer but the buffer
679 claims it doesn't belong to it. */
683 register struct buffer
*b
;
686 b
->file_truename
= Qnil
;
687 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
689 XSETFASTINT (b
->save_length
, 0);
690 b
->last_window_start
= 1;
691 /* It is more conservative to start out "changed" than "unchanged". */
693 b
->prevent_redisplay_optimizations_p
= 1;
695 b
->auto_save_modified
= 0;
696 b
->auto_save_failure_time
= -1;
697 b
->auto_save_file_name
= Qnil
;
699 b
->overlays_before
= NULL
;
700 b
->overlays_after
= NULL
;
701 b
->overlay_center
= BEG
;
702 b
->mark_active
= Qnil
;
703 b
->point_before_scroll
= Qnil
;
704 b
->file_format
= Qnil
;
705 b
->auto_save_file_format
= Qt
;
706 b
->last_selected_window
= Qnil
;
707 XSETINT (b
->display_count
, 0);
708 b
->display_time
= Qnil
;
709 b
->enable_multibyte_characters
= buffer_defaults
.enable_multibyte_characters
;
710 b
->cursor_type
= buffer_defaults
.cursor_type
;
711 b
->extra_line_spacing
= buffer_defaults
.extra_line_spacing
;
713 b
->display_error_modiff
= 0;
716 /* Reset buffer B's local variables info.
717 Don't use this on a buffer that has already been in use;
718 it does not treat permanent locals consistently.
719 Instead, use Fkill_all_local_variables.
721 If PERMANENT_TOO is 1, then we reset permanent built-in
722 buffer-local variables. If PERMANENT_TOO is 0,
723 we preserve those. */
726 reset_buffer_local_variables (b
, permanent_too
)
727 register struct buffer
*b
;
733 /* Reset the major mode to Fundamental, together with all the
734 things that depend on the major mode.
735 default-major-mode is handled at a higher level.
736 We ignore it here. */
737 b
->major_mode
= Qfundamental_mode
;
739 b
->mode_name
= QSFundamental
;
740 b
->minor_modes
= Qnil
;
742 /* If the standard case table has been altered and invalidated,
743 fix up its insides first. */
744 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
745 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
746 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
747 Fset_standard_case_table (Vascii_downcase_table
);
749 b
->downcase_table
= Vascii_downcase_table
;
750 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
751 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
752 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
753 b
->invisibility_spec
= Qt
;
755 b
->buffer_file_type
= Qnil
;
758 /* Reset all (or most) per-buffer variables to their defaults. */
759 b
->local_var_alist
= Qnil
;
760 for (i
= 0; i
< last_per_buffer_idx
; ++i
)
761 if (permanent_too
|| buffer_permanent_local_flags
[i
] == 0)
762 SET_PER_BUFFER_VALUE_P (b
, i
, 0);
764 /* For each slot that has a default value,
765 copy that into the slot. */
767 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
769 offset
+= sizeof (Lisp_Object
))
771 int idx
= PER_BUFFER_IDX (offset
);
774 || buffer_permanent_local_flags
[idx
] == 0))
775 /* Is -2 used anywhere? */
777 PER_BUFFER_VALUE (b
, offset
) = PER_BUFFER_DEFAULT (offset
);
781 /* We split this away from generate-new-buffer, because rename-buffer
782 and set-visited-file-name ought to be able to use this to really
783 rename the buffer properly. */
785 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
787 doc
: /* Return a string that is the name of no existing buffer based on NAME.
788 If there is no live buffer named NAME, then return NAME.
789 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
790 \(starting at 2) until an unused name is found, and then return that name.
791 Optional second argument IGNORE specifies a name that is okay to use
792 \(if it is in the sequence to be tried)
793 even if a buffer with that name exists. */)
795 register Lisp_Object name
, ignore
;
797 register Lisp_Object gentemp
, tem
;
803 tem
= Fstring_equal (name
, ignore
);
806 tem
= Fget_buffer (name
);
813 sprintf (number
, "<%d>", ++count
);
814 gentemp
= concat2 (name
, build_string (number
));
815 tem
= Fstring_equal (gentemp
, ignore
);
818 tem
= Fget_buffer (gentemp
);
825 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
826 doc
: /* Return the name of BUFFER, as a string.
827 With no argument or nil as argument, return the name of the current buffer. */)
829 register Lisp_Object buffer
;
832 return current_buffer
->name
;
833 CHECK_BUFFER (buffer
);
834 return XBUFFER (buffer
)->name
;
837 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
838 doc
: /* Return name of file BUFFER is visiting, or nil if none.
839 No argument or nil as argument means use the current buffer. */)
841 register Lisp_Object buffer
;
844 return current_buffer
->filename
;
845 CHECK_BUFFER (buffer
);
846 return XBUFFER (buffer
)->filename
;
849 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
851 doc
: /* Return the base buffer of indirect buffer BUFFER.
852 If BUFFER is not indirect, return nil.
853 BUFFER defaults to the current buffer. */)
855 register Lisp_Object buffer
;
858 Lisp_Object base_buffer
;
861 base
= current_buffer
->base_buffer
;
864 CHECK_BUFFER (buffer
);
865 base
= XBUFFER (buffer
)->base_buffer
;
870 XSETBUFFER (base_buffer
, base
);
874 DEFUN ("buffer-local-value", Fbuffer_local_value
,
875 Sbuffer_local_value
, 2, 2, 0,
876 doc
: /* Return the value of VARIABLE in BUFFER.
877 If VARIABLE does not have a buffer-local binding in BUFFER, the value
878 is the default binding of the variable. */)
880 register Lisp_Object variable
;
881 register Lisp_Object buffer
;
883 register struct buffer
*buf
;
884 register Lisp_Object result
;
886 CHECK_SYMBOL (variable
);
887 CHECK_BUFFER (buffer
);
888 buf
= XBUFFER (buffer
);
890 if (SYMBOLP (variable
))
891 variable
= indirect_variable (variable
);
893 /* Look in local_var_list */
894 result
= Fassoc (variable
, buf
->local_var_alist
);
900 /* Look in special slots */
901 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
902 offset
< sizeof (struct buffer
);
903 /* sizeof EMACS_INT == sizeof Lisp_Object */
904 offset
+= (sizeof (EMACS_INT
)))
906 idx
= PER_BUFFER_IDX (offset
);
907 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
908 && SYMBOLP (PER_BUFFER_SYMBOL (offset
))
909 && EQ (PER_BUFFER_SYMBOL (offset
), variable
))
911 result
= PER_BUFFER_VALUE (buf
, offset
);
918 result
= Fdefault_value (variable
);
922 Lisp_Object valcontents
;
923 Lisp_Object current_alist_element
;
925 /* What binding is loaded right now? */
926 valcontents
= SYMBOL_VALUE (variable
);
927 current_alist_element
928 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
930 /* The value of the currently loaded binding is not
931 stored in it, but rather in the realvalue slot.
932 Store that value into the binding it belongs to
933 in case that is the one we are about to use. */
935 Fsetcdr (current_alist_element
,
936 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
938 /* Now get the (perhaps updated) value out of the binding. */
939 result
= XCDR (result
);
942 if (EQ (result
, Qunbound
))
943 return Fsignal (Qvoid_variable
, Fcons (variable
, Qnil
));
948 /* Return an alist of the Lisp-level buffer-local bindings of
949 buffer BUF. That is, don't include the variables maintained
950 in special slots in the buffer object. */
953 buffer_lisp_local_variables (buf
)
956 Lisp_Object result
= Qnil
;
957 register Lisp_Object tail
;
958 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
960 Lisp_Object val
, elt
;
964 /* Reference each variable in the alist in buf.
965 If inquiring about the current buffer, this gets the current values,
966 so store them into the alist so the alist is up to date.
967 If inquiring about some other buffer, this swaps out any values
968 for that buffer, making the alist up to date automatically. */
969 val
= find_symbol_value (XCAR (elt
));
970 /* Use the current buffer value only if buf is the current buffer. */
971 if (buf
!= current_buffer
)
974 /* If symbol is unbound, put just the symbol in the list. */
975 if (EQ (val
, Qunbound
))
976 result
= Fcons (XCAR (elt
), result
);
977 /* Otherwise, put (symbol . value) in the list. */
979 result
= Fcons (Fcons (XCAR (elt
), val
), result
);
985 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
986 Sbuffer_local_variables
, 0, 1, 0,
987 doc
: /* Return an alist of variables that are buffer-local in BUFFER.
988 Most elements look like (SYMBOL . VALUE), describing one variable.
989 For a symbol that is locally unbound, just the symbol appears in the value.
990 Note that storing new VALUEs in these elements doesn't change the variables.
991 No argument or nil as argument means use current buffer as BUFFER. */)
993 register Lisp_Object buffer
;
995 register struct buffer
*buf
;
996 register Lisp_Object result
;
999 buf
= current_buffer
;
1002 CHECK_BUFFER (buffer
);
1003 buf
= XBUFFER (buffer
);
1006 result
= buffer_lisp_local_variables (buf
);
1008 /* Add on all the variables stored in special slots. */
1012 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
1013 offset
< sizeof (struct buffer
);
1014 /* sizeof EMACS_INT == sizeof Lisp_Object */
1015 offset
+= (sizeof (EMACS_INT
)))
1017 idx
= PER_BUFFER_IDX (offset
);
1018 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
1019 && SYMBOLP (PER_BUFFER_SYMBOL (offset
)))
1020 result
= Fcons (Fcons (PER_BUFFER_SYMBOL (offset
),
1021 PER_BUFFER_VALUE (buf
, offset
)),
1029 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
1031 doc
: /* Return t if BUFFER was modified since its file was last read or saved.
1032 No argument or nil as argument means use current buffer as BUFFER. */)
1034 register Lisp_Object buffer
;
1036 register struct buffer
*buf
;
1038 buf
= current_buffer
;
1041 CHECK_BUFFER (buffer
);
1042 buf
= XBUFFER (buffer
);
1045 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
1048 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
1050 doc
: /* Mark current buffer as modified or unmodified according to FLAG.
1051 A non-nil FLAG means mark the buffer modified. */)
1053 register Lisp_Object flag
;
1055 register int already
;
1056 register Lisp_Object fn
;
1057 Lisp_Object buffer
, window
;
1059 #ifdef CLASH_DETECTION
1060 /* If buffer becoming modified, lock the file.
1061 If buffer becoming unmodified, unlock the file. */
1063 fn
= current_buffer
->file_truename
;
1064 /* Test buffer-file-name so that binding it to nil is effective. */
1065 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
1067 already
= SAVE_MODIFF
< MODIFF
;
1068 if (!already
&& !NILP (flag
))
1070 else if (already
&& NILP (flag
))
1073 #endif /* CLASH_DETECTION */
1075 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
1077 /* Set update_mode_lines only if buffer is displayed in some window.
1078 Packages like jit-lock or lazy-lock preserve a buffer's modified
1079 state by recording/restoring the state around blocks of code.
1080 Setting update_mode_lines makes redisplay consider all windows
1081 (on all frames). Stealth fontification of buffers not displayed
1082 would incur additional redisplay costs if we'd set
1083 update_modes_lines unconditionally.
1085 Ideally, I think there should be another mechanism for fontifying
1086 buffers without "modifying" buffers, or redisplay should be
1087 smarter about updating the `*' in mode lines. --gerd */
1088 XSETBUFFER (buffer
, current_buffer
);
1089 window
= Fget_buffer_window (buffer
, Qt
);
1090 if (WINDOWP (window
))
1092 ++update_mode_lines
;
1093 current_buffer
->prevent_redisplay_optimizations_p
= 1;
1099 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p
,
1100 Srestore_buffer_modified_p
, 1, 1, 0,
1101 doc
: /* Like `set-buffer-modified-p', with a difference concerning redisplay.
1102 It is not ensured that mode lines will be updated to show the modified
1103 state of the current buffer. Use with care. */)
1107 #ifdef CLASH_DETECTION
1110 /* If buffer becoming modified, lock the file.
1111 If buffer becoming unmodified, unlock the file. */
1113 fn
= current_buffer
->file_truename
;
1114 /* Test buffer-file-name so that binding it to nil is effective. */
1115 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
1117 int already
= SAVE_MODIFF
< MODIFF
;
1118 if (!already
&& !NILP (flag
))
1120 else if (already
&& NILP (flag
))
1123 #endif /* CLASH_DETECTION */
1125 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
1129 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
1131 doc
: /* Return BUFFER's tick counter, incremented for each change in text.
1132 Each buffer has a tick counter which is incremented each time the text in
1133 that buffer is changed. It wraps around occasionally.
1134 No argument or nil as argument means use current buffer as BUFFER. */)
1136 register Lisp_Object buffer
;
1138 register struct buffer
*buf
;
1140 buf
= current_buffer
;
1143 CHECK_BUFFER (buffer
);
1144 buf
= XBUFFER (buffer
);
1147 return make_number (BUF_MODIFF (buf
));
1150 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
1151 "sRename buffer (to new name): \nP",
1152 doc
: /* Change current buffer's name to NEWNAME (a string).
1153 If second arg UNIQUE is nil or omitted, it is an error if a
1154 buffer named NEWNAME already exists.
1155 If UNIQUE is non-nil, come up with a new name using
1156 `generate-new-buffer-name'.
1157 Interactively, you can set UNIQUE with a prefix argument.
1158 We return the name we actually gave the buffer.
1159 This does not change the name of the visited file (if any). */)
1161 register Lisp_Object newname
, unique
;
1163 register Lisp_Object tem
, buf
;
1165 CHECK_STRING (newname
);
1167 if (SCHARS (newname
) == 0)
1168 error ("Empty string is invalid as a buffer name");
1170 tem
= Fget_buffer (newname
);
1173 /* Don't short-circuit if UNIQUE is t. That is a useful way to
1174 rename the buffer automatically so you can create another
1175 with the original name. It makes UNIQUE equivalent to
1176 (rename-buffer (generate-new-buffer-name NEWNAME)). */
1177 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
1178 return current_buffer
->name
;
1180 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
1182 error ("Buffer name `%s' is in use", SDATA (newname
));
1185 current_buffer
->name
= newname
;
1187 /* Catch redisplay's attention. Unless we do this, the mode lines for
1188 any windows displaying current_buffer will stay unchanged. */
1189 update_mode_lines
++;
1191 XSETBUFFER (buf
, current_buffer
);
1192 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
1193 if (NILP (current_buffer
->filename
)
1194 && !NILP (current_buffer
->auto_save_file_name
))
1195 call0 (intern ("rename-auto-save-file"));
1196 /* Refetch since that last call may have done GC. */
1197 return current_buffer
->name
;
1200 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 3, 0,
1201 doc
: /* Return most recently selected buffer other than BUFFER.
1202 Buffers not visible in windows are preferred to visible buffers,
1203 unless optional second argument VISIBLE-OK is non-nil.
1204 If the optional third argument FRAME is non-nil, use that frame's
1205 buffer list instead of the selected frame's buffer list.
1206 If no other buffer exists, the buffer `*scratch*' is returned.
1207 If BUFFER is omitted or nil, some interesting buffer is returned. */)
1208 (buffer
, visible_ok
, frame
)
1209 register Lisp_Object buffer
, visible_ok
, frame
;
1211 Lisp_Object
Fset_buffer_major_mode ();
1212 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
1216 frame
= selected_frame
;
1218 tail
= Vbuffer_alist
;
1219 pred
= frame_buffer_predicate (frame
);
1221 /* Consider buffers that have been seen in the selected frame
1222 before other buffers. */
1224 tem
= frame_buffer_list (frame
);
1228 if (BUFFERP (XCAR (tem
)))
1229 add_ons
= Fcons (Fcons (Qnil
, XCAR (tem
)), add_ons
);
1232 tail
= nconc2 (Fnreverse (add_ons
), tail
);
1234 for (; CONSP (tail
); tail
= XCDR (tail
))
1236 buf
= Fcdr (XCAR (tail
));
1237 if (EQ (buf
, buffer
))
1241 if (NILP (XBUFFER (buf
)->name
))
1243 if (SREF (XBUFFER (buf
)->name
, 0) == ' ')
1245 /* If the selected frame has a buffer_predicate,
1246 disregard buffers that don't fit the predicate. */
1249 tem
= call1 (pred
, buf
);
1254 if (NILP (visible_ok
))
1255 tem
= Fget_buffer_window (buf
, Qvisible
);
1260 if (NILP (notsogood
))
1263 if (!NILP (notsogood
))
1265 buf
= Fget_buffer (build_string ("*scratch*"));
1268 buf
= Fget_buffer_create (build_string ("*scratch*"));
1269 Fset_buffer_major_mode (buf
);
1274 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
1276 doc
: /* Start keeping undo information for buffer BUFFER.
1277 No argument or nil as argument means do this for the current buffer. */)
1279 register Lisp_Object buffer
;
1281 Lisp_Object real_buffer
;
1284 XSETBUFFER (real_buffer
, current_buffer
);
1287 real_buffer
= Fget_buffer (buffer
);
1288 if (NILP (real_buffer
))
1292 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
1293 XBUFFER (real_buffer
)->undo_list
= Qnil
;
1299 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
1300 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1301 The buffer being killed will be current while the hook is running.\n\
1304 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
1305 doc
: /* Kill the buffer BUFFER.
1306 The argument may be a buffer or may be the name of a buffer.
1307 An argument of nil means kill the current buffer.
1309 Value is t if the buffer is actually killed, nil if user says no.
1311 The value of `kill-buffer-hook' (which may be local to that buffer),
1312 if not void, is a list of functions to be called, with no arguments,
1313 before the buffer is actually killed. The buffer to be killed is current
1314 when the hook functions are called.
1316 Any processes that have this buffer as the `process-buffer' are killed
1322 register struct buffer
*b
;
1323 register Lisp_Object tem
;
1324 register struct Lisp_Marker
*m
;
1325 struct gcpro gcpro1
;
1328 buf
= Fcurrent_buffer ();
1330 buf
= Fget_buffer (buffer
);
1336 /* Avoid trouble for buffer already dead. */
1340 /* Query if the buffer is still modified. */
1341 if (INTERACTIVE
&& !NILP (b
->filename
)
1342 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1345 tem
= do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
1346 b
->name
, make_number (0)));
1352 /* Run hooks with the buffer to be killed the current buffer. */
1354 int count
= SPECPDL_INDEX ();
1355 Lisp_Object arglist
[1];
1357 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1358 set_buffer_internal (b
);
1360 /* First run the query functions; if any query is answered no,
1361 don't kill the buffer. */
1362 arglist
[0] = Qkill_buffer_query_functions
;
1363 if (NILP (Frun_hook_with_args_until_failure (1, arglist
)))
1364 return unbind_to (count
, Qnil
);
1366 /* Then run the hooks. */
1367 Frun_hooks (1, &Qkill_buffer_hook
);
1368 unbind_to (count
, Qnil
);
1371 /* We have no more questions to ask. Verify that it is valid
1372 to kill the buffer. This must be done after the questions
1373 since anything can happen within do_yes_or_no_p. */
1375 /* Don't kill the minibuffer now current. */
1376 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1382 /* When we kill a base buffer, kill all its indirect buffers.
1383 We do it at this stage so nothing terrible happens if they
1384 ask questions or their hooks get errors. */
1385 if (! b
->base_buffer
)
1387 struct buffer
*other
;
1391 for (other
= all_buffers
; other
; other
= other
->next
)
1392 /* all_buffers contains dead buffers too;
1393 don't re-kill them. */
1394 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1397 XSETBUFFER (buf
, other
);
1404 /* Make this buffer not be current.
1405 In the process, notice if this is the sole visible buffer
1406 and give up if so. */
1407 if (b
== current_buffer
)
1409 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1411 if (b
== current_buffer
)
1415 /* Notice if the buffer to kill is the sole visible buffer
1416 when we're currently in the mini-buffer, and give up if so. */
1417 XSETBUFFER (tem
, current_buffer
);
1418 if (EQ (tem
, XWINDOW (minibuf_window
)->buffer
))
1420 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1425 /* Now there is no question: we can kill the buffer. */
1427 #ifdef CLASH_DETECTION
1428 /* Unlock this buffer's file, if it is locked. */
1430 #endif /* CLASH_DETECTION */
1432 kill_buffer_processes (buf
);
1433 clear_charpos_cache (b
);
1435 tem
= Vinhibit_quit
;
1437 replace_buffer_in_all_windows (buf
);
1438 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1439 frames_discard_buffer (buf
);
1440 Vinhibit_quit
= tem
;
1442 /* Delete any auto-save file, if we saved it in this session.
1443 But not if the buffer is modified. */
1444 if (STRINGP (b
->auto_save_file_name
)
1445 && b
->auto_save_modified
!= 0
1446 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
1447 && BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)
1448 && NILP (Fsymbol_value (intern ("auto-save-visited-file-name"))))
1451 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1453 internal_delete_file (b
->auto_save_file_name
);
1458 /* Unchain all markers that belong to this indirect buffer.
1459 Don't unchain the markers that belong to the base buffer
1460 or its other indirect buffers. */
1461 for (m
= BUF_MARKERS (b
); m
; )
1463 struct Lisp_Marker
*next
= m
->next
;
1471 /* Unchain all markers of this buffer and its indirect buffers.
1472 and leave them pointing nowhere. */
1473 for (m
= BUF_MARKERS (b
); m
; )
1475 struct Lisp_Marker
*next
= m
->next
;
1480 BUF_MARKERS (b
) = NULL
;
1481 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1483 /* Perhaps we should explicitly free the interval tree here... */
1486 /* Reset the local variables, so that this buffer's local values
1487 won't be protected from GC. They would be protected
1488 if they happened to remain encached in their symbols.
1489 This gets rid of them for certain. */
1490 swap_out_buffer_local_variables (b
);
1491 reset_buffer_local_variables (b
, 1);
1496 if (! b
->base_buffer
)
1497 free_buffer_text (b
);
1499 if (b
->newline_cache
)
1501 free_region_cache (b
->newline_cache
);
1502 b
->newline_cache
= 0;
1504 if (b
->width_run_cache
)
1506 free_region_cache (b
->width_run_cache
);
1507 b
->width_run_cache
= 0;
1509 b
->width_table
= Qnil
;
1511 b
->undo_list
= Qnil
;
1516 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1517 we do this each time BUF is selected visibly, the more recently
1518 selected buffers are always closer to the front of the list. This
1519 means that other_buffer is more likely to choose a relevant buffer. */
1525 register Lisp_Object link
, prev
;
1527 frame
= selected_frame
;
1530 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCDR (link
))
1532 if (EQ (XCDR (XCAR (link
)), buf
))
1537 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1538 we cannot use Fdelq itself here because it allows quitting. */
1541 Vbuffer_alist
= XCDR (Vbuffer_alist
);
1543 XSETCDR (prev
, XCDR (XCDR (prev
)));
1545 XSETCDR (link
, Vbuffer_alist
);
1546 Vbuffer_alist
= link
;
1548 /* Now move this buffer to the front of frame_buffer_list also. */
1551 for (link
= frame_buffer_list (frame
); CONSP (link
);
1554 if (EQ (XCAR (link
), buf
))
1559 /* Effectively do delq. */
1564 set_frame_buffer_list (frame
,
1565 XCDR (frame_buffer_list (frame
)));
1567 XSETCDR (prev
, XCDR (XCDR (prev
)));
1569 XSETCDR (link
, frame_buffer_list (frame
));
1570 set_frame_buffer_list (frame
, link
);
1573 set_frame_buffer_list (frame
, Fcons (buf
, frame_buffer_list (frame
)));
1576 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1577 doc
: /* Set an appropriate major mode for BUFFER.
1578 For the *scratch* buffer, use `initial-major-mode', otherwise choose a mode
1579 according to `default-major-mode'.
1580 Use this function before selecting the buffer, since it may need to inspect
1581 the current buffer's major mode. */)
1586 Lisp_Object function
;
1588 if (STRINGP (XBUFFER (buffer
)->name
)
1589 && strcmp (SDATA (XBUFFER (buffer
)->name
), "*scratch*") == 0)
1590 function
= find_symbol_value (intern ("initial-major-mode"));
1593 function
= buffer_defaults
.major_mode
;
1595 && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1596 function
= current_buffer
->major_mode
;
1599 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1602 count
= SPECPDL_INDEX ();
1604 /* To select a nonfundamental mode,
1605 select the buffer temporarily and then call the mode function. */
1607 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1609 Fset_buffer (buffer
);
1612 return unbind_to (count
, Qnil
);
1615 /* If switching buffers in WINDOW would be an error, return
1616 a C string saying what the error would be. */
1619 no_switch_window (window
)
1623 if (EQ (minibuf_window
, window
))
1624 return "Cannot switch buffers in minibuffer window";
1625 tem
= Fwindow_dedicated_p (window
);
1627 return "Cannot switch buffers in a dedicated window";
1631 /* Switch to buffer BUFFER in the selected window.
1632 If NORECORD is non-nil, don't call record_buffer. */
1635 switch_to_buffer_1 (buffer
, norecord
)
1636 Lisp_Object buffer
, norecord
;
1638 register Lisp_Object buf
;
1641 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1644 buf
= Fget_buffer (buffer
);
1647 buf
= Fget_buffer_create (buffer
);
1648 Fset_buffer_major_mode (buf
);
1652 if (NILP (norecord
))
1653 record_buffer (buf
);
1655 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1656 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1663 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1664 doc
: /* Select buffer BUFFER in the current window.
1665 If BUFFER does not identify an existing buffer,
1666 then this function creates a buffer with that name.
1668 When called from Lisp, BUFFER may be a buffer, a string \(a buffer name),
1669 or nil. If BUFFER is nil, then this function chooses a buffer
1670 using `other-buffer'.
1671 Optional second arg NORECORD non-nil means
1672 do not put this buffer at the front of the list of recently selected ones.
1673 This function returns the buffer it switched to.
1675 WARNING: This is NOT the way to work on another buffer temporarily
1676 within a Lisp program! Use `set-buffer' instead. That avoids messing with
1677 the window-buffer correspondences. */)
1679 Lisp_Object buffer
, norecord
;
1683 if (EQ (buffer
, Fwindow_buffer (selected_window
)))
1684 /* Basically a NOP. Avoid signalling an error if the selected window
1685 is dedicated, or a minibuffer, ... */
1686 return Fset_buffer (buffer
);
1688 err
= no_switch_window (selected_window
);
1689 if (err
) error (err
);
1691 return switch_to_buffer_1 (buffer
, norecord
);
1694 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1695 doc
: /* Select buffer BUFFER in some window, preferably a different one.
1696 BUFFER may be a buffer, a string \(a buffer name), or nil.
1697 If BUFFER is a string which is not the name of an existing buffer,
1698 then this function creates a buffer with that name.
1699 If BUFFER is nil, then it chooses some other buffer.
1700 If `pop-up-windows' is non-nil, windows can be split to do this.
1701 If optional second arg OTHER-WINDOW is non-nil, insist on finding another
1702 window even if BUFFER is already visible in the selected window,
1703 and ignore `same-window-regexps' and `same-window-buffer-names'.
1704 This function returns the buffer it switched to.
1705 This uses the function `display-buffer' as a subroutine; see the documentation
1706 of `display-buffer' for additional customization information.
1708 Optional third arg NORECORD non-nil means
1709 do not put this buffer at the front of the list of recently selected ones. */)
1710 (buffer
, other_window
, norecord
)
1711 Lisp_Object buffer
, other_window
, norecord
;
1713 register Lisp_Object buf
;
1715 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1718 buf
= Fget_buffer (buffer
);
1721 buf
= Fget_buffer_create (buffer
);
1722 Fset_buffer_major_mode (buf
);
1726 if (NILP (norecord
))
1727 /* Why bother ? Fselect_window will do it for us anyway. -stef */
1728 record_buffer (buf
);
1729 Fselect_window (Fdisplay_buffer (buf
, other_window
, Qnil
), norecord
);
1733 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1734 doc
: /* Return the current buffer as a Lisp object. */)
1737 register Lisp_Object buf
;
1738 XSETBUFFER (buf
, current_buffer
);
1742 /* Set the current buffer to B.
1744 We previously set windows_or_buffers_changed here to invalidate
1745 global unchanged information in beg_unchanged and end_unchanged.
1746 This is no longer necessary because we now compute unchanged
1747 information on a buffer-basis. Every action affecting other
1748 windows than the selected one requires a select_window at some
1749 time, and that increments windows_or_buffers_changed. */
1752 set_buffer_internal (b
)
1753 register struct buffer
*b
;
1755 if (current_buffer
!= b
)
1756 set_buffer_internal_1 (b
);
1759 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1760 This is used by redisplay. */
1763 set_buffer_internal_1 (b
)
1764 register struct buffer
*b
;
1766 register struct buffer
*old_buf
;
1767 register Lisp_Object tail
, valcontents
;
1770 #ifdef USE_MMAP_FOR_BUFFERS
1771 if (b
->text
->beg
== NULL
)
1772 enlarge_buffer_text (b
, 0);
1773 #endif /* USE_MMAP_FOR_BUFFERS */
1775 if (current_buffer
== b
)
1778 old_buf
= current_buffer
;
1780 last_known_column_point
= -1; /* invalidate indentation cache */
1784 /* Put the undo list back in the base buffer, so that it appears
1785 that an indirect buffer shares the undo list of its base. */
1786 if (old_buf
->base_buffer
)
1787 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1789 /* If the old current buffer has markers to record PT, BEGV and ZV
1790 when it is not current, update them now. */
1791 if (! NILP (old_buf
->pt_marker
))
1794 XSETBUFFER (obuf
, old_buf
);
1795 set_marker_both (old_buf
->pt_marker
, obuf
,
1796 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1798 if (! NILP (old_buf
->begv_marker
))
1801 XSETBUFFER (obuf
, old_buf
);
1802 set_marker_both (old_buf
->begv_marker
, obuf
,
1803 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1805 if (! NILP (old_buf
->zv_marker
))
1808 XSETBUFFER (obuf
, old_buf
);
1809 set_marker_both (old_buf
->zv_marker
, obuf
,
1810 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1814 /* Get the undo list from the base buffer, so that it appears
1815 that an indirect buffer shares the undo list of its base. */
1817 b
->undo_list
= b
->base_buffer
->undo_list
;
1819 /* If the new current buffer has markers to record PT, BEGV and ZV
1820 when it is not current, fetch them now. */
1821 if (! NILP (b
->pt_marker
))
1823 BUF_PT (b
) = marker_position (b
->pt_marker
);
1824 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1826 if (! NILP (b
->begv_marker
))
1828 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1829 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1831 if (! NILP (b
->zv_marker
))
1833 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1834 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1837 /* Look down buffer's list of local Lisp variables
1838 to find and update any that forward into C variables. */
1840 for (tail
= b
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1842 valcontents
= SYMBOL_VALUE (XCAR (XCAR (tail
)));
1843 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1844 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1845 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1846 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1847 /* Just reference the variable
1848 to cause it to become set for this buffer. */
1849 Fsymbol_value (XCAR (XCAR (tail
)));
1852 /* Do the same with any others that were local to the previous buffer */
1855 for (tail
= old_buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1857 valcontents
= SYMBOL_VALUE (XCAR (XCAR (tail
)));
1858 if ((BUFFER_LOCAL_VALUEP (valcontents
)
1859 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1860 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1861 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1862 /* Just reference the variable
1863 to cause it to become set for this buffer. */
1864 Fsymbol_value (XCAR (XCAR (tail
)));
1868 /* Switch to buffer B temporarily for redisplay purposes.
1869 This avoids certain things that don't need to be done within redisplay. */
1875 register struct buffer
*old_buf
;
1877 if (current_buffer
== b
)
1880 old_buf
= current_buffer
;
1885 /* If the old current buffer has markers to record PT, BEGV and ZV
1886 when it is not current, update them now. */
1887 if (! NILP (old_buf
->pt_marker
))
1890 XSETBUFFER (obuf
, old_buf
);
1891 set_marker_both (old_buf
->pt_marker
, obuf
,
1892 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1894 if (! NILP (old_buf
->begv_marker
))
1897 XSETBUFFER (obuf
, old_buf
);
1898 set_marker_both (old_buf
->begv_marker
, obuf
,
1899 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1901 if (! NILP (old_buf
->zv_marker
))
1904 XSETBUFFER (obuf
, old_buf
);
1905 set_marker_both (old_buf
->zv_marker
, obuf
,
1906 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1910 /* If the new current buffer has markers to record PT, BEGV and ZV
1911 when it is not current, fetch them now. */
1912 if (! NILP (b
->pt_marker
))
1914 BUF_PT (b
) = marker_position (b
->pt_marker
);
1915 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1917 if (! NILP (b
->begv_marker
))
1919 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1920 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1922 if (! NILP (b
->zv_marker
))
1924 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1925 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1929 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1930 doc
: /* Make the buffer BUFFER current for editing operations.
1931 BUFFER may be a buffer or the name of an existing buffer.
1932 See also `save-excursion' when you want to make a buffer current temporarily.
1933 This function does not display the buffer, so its effect ends
1934 when the current command terminates.
1935 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently. */)
1937 register Lisp_Object buffer
;
1939 register Lisp_Object buf
;
1940 buf
= Fget_buffer (buffer
);
1943 if (NILP (XBUFFER (buf
)->name
))
1944 error ("Selecting deleted buffer");
1945 set_buffer_internal (XBUFFER (buf
));
1949 /* Set the current buffer to BUFFER provided it is alive. */
1952 set_buffer_if_live (buffer
)
1955 if (! NILP (XBUFFER (buffer
)->name
))
1956 Fset_buffer (buffer
);
1960 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
1961 Sbarf_if_buffer_read_only
, 0, 0, 0,
1962 doc
: /* Signal a `buffer-read-only' error if the current buffer is read-only. */)
1965 if (!NILP (current_buffer
->read_only
)
1966 && NILP (Vinhibit_read_only
))
1967 Fsignal (Qbuffer_read_only
, (Fcons (Fcurrent_buffer (), Qnil
)));
1971 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
1972 doc
: /* Put BUFFER at the end of the list of all buffers.
1973 There it is the least likely candidate for `other-buffer' to return;
1974 thus, the least likely buffer for \\[switch-to-buffer] to select by default.
1975 You can specify a buffer name as BUFFER, or an actual buffer object.
1976 If BUFFER is nil or omitted, bury the current buffer.
1977 Also, if BUFFER is nil or omitted, remove the current buffer from the
1978 selected window if it is displayed there. */)
1980 register Lisp_Object buffer
;
1982 /* Figure out what buffer we're going to bury. */
1986 XSETBUFFER (buffer
, current_buffer
);
1988 tem
= Fwindow_buffer (selected_window
);
1989 /* If we're burying the current buffer, unshow it. */
1990 if (EQ (buffer
, tem
))
1992 if (NILP (Fwindow_dedicated_p (selected_window
)))
1993 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
, Qnil
), Qnil
);
1994 else if (NILP (XWINDOW (selected_window
)->parent
))
1995 Ficonify_frame (Fwindow_frame (selected_window
));
1997 Fdelete_window (selected_window
);
2004 buf1
= Fget_buffer (buffer
);
2010 /* Move buffer to the end of the buffer list. Do nothing if the
2011 buffer is killed. */
2012 if (!NILP (XBUFFER (buffer
)->name
))
2014 Lisp_Object aelt
, link
;
2016 aelt
= Frassq (buffer
, Vbuffer_alist
);
2017 link
= Fmemq (aelt
, Vbuffer_alist
);
2018 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
2019 XSETCDR (link
, Qnil
);
2020 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
2022 /* Removing BUFFER from frame-specific lists
2023 has the effect of putting BUFFER at the end
2024 of the combined list in each frame. */
2025 frames_discard_buffer (buffer
);
2031 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
2032 doc
: /* Delete the entire contents of the current buffer.
2033 Any narrowing restriction in effect (see `narrow-to-region') is removed,
2034 so the buffer is truly empty after this. */)
2041 current_buffer
->last_window_start
= 1;
2042 /* Prevent warnings, or suspension of auto saving, that would happen
2043 if future size is less than past size. Use of erase-buffer
2044 implies that the future text is not really related to the past text. */
2045 XSETFASTINT (current_buffer
->save_length
, 0);
2050 validate_region (b
, e
)
2051 register Lisp_Object
*b
, *e
;
2053 CHECK_NUMBER_COERCE_MARKER (*b
);
2054 CHECK_NUMBER_COERCE_MARKER (*e
);
2056 if (XINT (*b
) > XINT (*e
))
2059 tem
= *b
; *b
= *e
; *e
= tem
;
2062 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
2063 && XINT (*e
) <= ZV
))
2064 args_out_of_range (*b
, *e
);
2067 /* Advance BYTE_POS up to a character boundary
2068 and return the adjusted position. */
2071 advance_to_char_boundary (byte_pos
)
2076 if (byte_pos
== BEG
)
2077 /* Beginning of buffer is always a character boundary. */
2080 c
= FETCH_BYTE (byte_pos
);
2081 if (! CHAR_HEAD_P (c
))
2083 /* We should advance BYTE_POS only when C is a constituent of a
2084 multibyte sequence. */
2085 int orig_byte_pos
= byte_pos
;
2090 c
= FETCH_BYTE (byte_pos
);
2092 while (! CHAR_HEAD_P (c
) && byte_pos
> BEG
);
2094 if (byte_pos
< orig_byte_pos
)
2095 byte_pos
= orig_byte_pos
;
2096 /* If C is a constituent of a multibyte sequence, BYTE_POS was
2097 surely advance to the correct character boundary. If C is
2098 not, BYTE_POS was unchanged. */
2104 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte
, Sset_buffer_multibyte
,
2106 doc
: /* Set the multibyte flag of the current buffer to FLAG.
2107 If FLAG is t, this makes the buffer a multibyte buffer.
2108 If FLAG is nil, this makes the buffer a single-byte buffer.
2109 In these cases, the buffer contents remain unchanged as a sequence of
2110 bytes but the contents viewed as characters do change.
2111 If FLAG is `to', this makes the buffer a multibyte buffer by changing
2112 all eight-bit bytes to eight-bit characters.
2113 If the multibyte flag was really changed, undo information of the
2114 current buffer is cleared. */)
2118 struct Lisp_Marker
*tail
, *markers
;
2119 struct buffer
*other
;
2120 int undo_enabled_p
= !EQ (current_buffer
->undo_list
, Qt
);
2122 int narrowed
= (BEG
!= BEGV
|| Z
!= ZV
);
2123 int modified_p
= !NILP (Fbuffer_modified_p (Qnil
));
2125 if (current_buffer
->base_buffer
)
2126 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
2128 /* Do nothing if nothing actually changes. */
2129 if (NILP (flag
) == NILP (current_buffer
->enable_multibyte_characters
))
2132 /* It would be better to update the list,
2133 but this is good enough for now. */
2135 current_buffer
->undo_list
= Qt
;
2137 /* If the cached position is for this buffer, clear it out. */
2138 clear_charpos_cache (current_buffer
);
2141 begv
= BEGV_BYTE
, zv
= ZV_BYTE
;
2143 begv
= BEGV
, zv
= ZV
;
2153 /* Do this first, so it can use CHAR_TO_BYTE
2154 to calculate the old correspondences. */
2155 set_intervals_multibyte (0);
2157 current_buffer
->enable_multibyte_characters
= Qnil
;
2163 TEMP_SET_PT_BOTH (PT_BYTE
, PT_BYTE
);
2166 for (tail
= BUF_MARKERS (current_buffer
); tail
; tail
= tail
->next
)
2167 tail
->charpos
= tail
->bytepos
;
2169 /* Convert multibyte form of 8-bit characters to unibyte. */
2184 if (ASCII_BYTE_P (*p
))
2186 else if (CHAR_BYTE8_HEAD_P (*p
))
2188 c
= STRING_CHAR_AND_LENGTH (p
, stop
- pos
, bytes
);
2189 /* Delete all bytes for this 8-bit character but the
2190 last one, and change the last one to the charcter
2193 del_range_2 (pos
, pos
, pos
+ bytes
, pos
+ bytes
, 0);
2205 bytes
= BYTES_BY_CHAR_HEAD (*p
);
2206 p
+= bytes
, pos
+= bytes
;
2210 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2216 unsigned char *p
, *pend
;
2218 /* Be sure not to have a multibyte sequence striding over the GAP.
2219 Ex: We change this: "...abc\302 _GAP_ \241def..."
2220 to: "...abc _GAP_ \302\241def..." */
2223 && GPT_BYTE
> 1 && GPT_BYTE
< Z_BYTE
2224 && ! CHAR_HEAD_P (*(GAP_END_ADDR
)))
2226 unsigned char *p
= GPT_ADDR
- 1;
2228 while (! CHAR_HEAD_P (*p
) && p
> BEG_ADDR
) p
--;
2229 if (BASE_LEADING_CODE_P (*p
))
2231 int new_gpt
= GPT_BYTE
- (GPT_ADDR
- p
);
2233 move_gap_both (new_gpt
, new_gpt
);
2237 /* Make the buffer contents valid as multibyte by converting
2238 8-bit characters to multibyte form. */
2256 if (ASCII_BYTE_P (*p
))
2258 else if (EQ (flag
, Qt
) && (bytes
= MULTIBYTE_LENGTH (p
, pend
)) > 0)
2259 p
+= bytes
, pos
+= bytes
;
2262 unsigned char tmp
[MAX_MULTIBYTE_LENGTH
];
2265 c
= BYTE8_TO_CHAR (*p
);
2266 bytes
= CHAR_STRING (c
, tmp
);
2268 TEMP_SET_PT_BOTH (pos
+ 1, pos
+ 1);
2270 insert_1_both (tmp
+ 1, bytes
, bytes
, 1, 0, 0);
2271 /* Now the gap is after the just inserted data. */
2289 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2291 /* Do this first, so that chars_in_text asks the right question.
2292 set_intervals_multibyte needs it too. */
2293 current_buffer
->enable_multibyte_characters
= Qt
;
2295 GPT_BYTE
= advance_to_char_boundary (GPT_BYTE
);
2296 GPT
= chars_in_text (BEG_ADDR
, GPT_BYTE
- BEG_BYTE
) + BEG
;
2298 Z
= chars_in_text (GAP_END_ADDR
, Z_BYTE
- GPT_BYTE
) + GPT
;
2300 BEGV_BYTE
= advance_to_char_boundary (BEGV_BYTE
);
2301 if (BEGV_BYTE
> GPT_BYTE
)
2302 BEGV
= chars_in_text (GAP_END_ADDR
, BEGV_BYTE
- GPT_BYTE
) + GPT
;
2304 BEGV
= chars_in_text (BEG_ADDR
, BEGV_BYTE
- BEG_BYTE
) + BEG
;
2306 ZV_BYTE
= advance_to_char_boundary (ZV_BYTE
);
2307 if (ZV_BYTE
> GPT_BYTE
)
2308 ZV
= chars_in_text (GAP_END_ADDR
, ZV_BYTE
- GPT_BYTE
) + GPT
;
2310 ZV
= chars_in_text (BEG_ADDR
, ZV_BYTE
- BEG_BYTE
) + BEG
;
2313 int pt_byte
= advance_to_char_boundary (PT_BYTE
);
2316 if (pt_byte
> GPT_BYTE
)
2317 pt
= chars_in_text (GAP_END_ADDR
, pt_byte
- GPT_BYTE
) + GPT
;
2319 pt
= chars_in_text (BEG_ADDR
, pt_byte
- BEG_BYTE
) + BEG
;
2320 TEMP_SET_PT_BOTH (pt
, pt_byte
);
2323 tail
= markers
= BUF_MARKERS (current_buffer
);
2325 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
2326 getting confused by the markers that have not yet been updated.
2327 It is also a signal that it should never create a marker. */
2328 BUF_MARKERS (current_buffer
) = NULL
;
2330 for (; tail
; tail
= tail
->next
)
2332 tail
->bytepos
= advance_to_char_boundary (tail
->bytepos
);
2333 tail
->charpos
= BYTE_TO_CHAR (tail
->bytepos
);
2336 /* Make sure no markers were put on the chain
2337 while the chain value was incorrect. */
2338 if (BUF_MARKERS (current_buffer
))
2341 BUF_MARKERS (current_buffer
) = markers
;
2343 /* Do this last, so it can calculate the new correspondences
2344 between chars and bytes. */
2345 set_intervals_multibyte (1);
2349 current_buffer
->undo_list
= Qnil
;
2351 /* Changing the multibyteness of a buffer means that all windows
2352 showing that buffer must be updated thoroughly. */
2353 current_buffer
->prevent_redisplay_optimizations_p
= 1;
2354 ++windows_or_buffers_changed
;
2356 /* Copy this buffer's new multibyte status
2357 into all of its indirect buffers. */
2358 for (other
= all_buffers
; other
; other
= other
->next
)
2359 if (other
->base_buffer
== current_buffer
&& !NILP (other
->name
))
2361 other
->enable_multibyte_characters
2362 = current_buffer
->enable_multibyte_characters
;
2363 other
->prevent_redisplay_optimizations_p
= 1;
2366 /* Restore the modifiedness of the buffer. */
2367 if (!modified_p
&& !NILP (Fbuffer_modified_p (Qnil
)))
2368 Fset_buffer_modified_p (Qnil
);
2371 /* Update coding systems of this buffer's process (if any). */
2373 Lisp_Object process
;
2375 process
= Fget_buffer_process (Fcurrent_buffer ());
2376 if (PROCESSP (process
))
2377 setup_process_coding_systems (process
);
2379 #endif /* subprocesses */
2384 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
2386 doc
: /* Switch to Fundamental mode by killing current buffer's local variables.
2387 Most local variable bindings are eliminated so that the default values
2388 become effective once more. Also, the syntax table is set from
2389 `standard-syntax-table', the local keymap is set to nil,
2390 and the abbrev table from `fundamental-mode-abbrev-table'.
2391 This function also forces redisplay of the mode line.
2393 Every function to select a new major mode starts by
2394 calling this function.
2396 As a special exception, local variables whose names have
2397 a non-nil `permanent-local' property are not eliminated by this function.
2399 The first thing this function does is run
2400 the normal hook `change-major-mode-hook'. */)
2403 register Lisp_Object alist
, sym
, tem
;
2406 if (!NILP (Vrun_hooks
))
2407 call1 (Vrun_hooks
, intern ("change-major-mode-hook"));
2408 oalist
= current_buffer
->local_var_alist
;
2410 /* Make sure none of the bindings in oalist
2411 remain swapped in, in their symbols. */
2413 swap_out_buffer_local_variables (current_buffer
);
2415 /* Actually eliminate all local bindings of this buffer. */
2417 reset_buffer_local_variables (current_buffer
, 0);
2419 /* Any which are supposed to be permanent,
2420 make local again, with the same values they had. */
2422 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
2424 sym
= XCAR (XCAR (alist
));
2425 tem
= Fget (sym
, Qpermanent_local
);
2428 Fmake_local_variable (sym
);
2429 Fset (sym
, XCDR (XCAR (alist
)));
2433 /* Force mode-line redisplay. Useful here because all major mode
2434 commands call this function. */
2435 update_mode_lines
++;
2440 /* Make sure no local variables remain set up with buffer B
2441 for their current values. */
2444 swap_out_buffer_local_variables (b
)
2447 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
2449 XSETBUFFER (buffer
, b
);
2450 oalist
= b
->local_var_alist
;
2452 for (alist
= oalist
; !NILP (alist
); alist
= XCDR (alist
))
2454 sym
= XCAR (XCAR (alist
));
2456 /* Need not do anything if some other buffer's binding is now encached. */
2457 tem
= XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->buffer
;
2458 if (BUFFERP (tem
) && XBUFFER (tem
) == current_buffer
)
2460 /* Symbol is set up for this buffer's old local value.
2461 Set it up for the current buffer with the default value. */
2463 tem
= XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->cdr
;
2464 /* Store the symbol's current value into the alist entry
2465 it is currently set up for. This is so that, if the
2466 local is marked permanent, and we make it local again
2467 later in Fkill_all_local_variables, we don't lose the value. */
2468 XSETCDR (XCAR (tem
),
2469 do_symval_forwarding (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->realvalue
));
2470 /* Switch to the symbol's default-value alist entry. */
2472 /* Mark it as current for buffer B. */
2473 XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->buffer
= buffer
;
2474 /* Store the current value into any forwarding in the symbol. */
2475 store_symval_forwarding (sym
,
2476 XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->realvalue
,
2482 /* Find all the overlays in the current buffer that contain position POS.
2483 Return the number found, and store them in a vector in *VEC_PTR.
2484 Store in *LEN_PTR the size allocated for the vector.
2485 Store in *NEXT_PTR the next position after POS where an overlay starts,
2486 or ZV if there are no more overlays.
2487 Store in *PREV_PTR the previous position before POS where an overlay ends,
2488 or where an overlay starts which ends at or after POS;
2489 or BEGV if there are no such overlays.
2490 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2492 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2493 when this function is called.
2495 If EXTEND is non-zero, we make the vector bigger if necessary.
2496 If EXTEND is zero, we never extend the vector,
2497 and we store only as many overlays as will fit.
2498 But we still return the total number of overlays.
2500 If CHANGE_REQ is true, then any position written into *PREV_PTR or
2501 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2502 default (BEGV or ZV). */
2505 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
, change_req
)
2508 Lisp_Object
**vec_ptr
;
2514 Lisp_Object overlay
, start
, end
;
2515 struct Lisp_Overlay
*tail
;
2518 Lisp_Object
*vec
= *vec_ptr
;
2521 int inhibit_storing
= 0;
2523 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2525 int startpos
, endpos
;
2527 XSETMISC (overlay
, tail
);
2529 start
= OVERLAY_START (overlay
);
2530 end
= OVERLAY_END (overlay
);
2531 endpos
= OVERLAY_POSITION (end
);
2538 startpos
= OVERLAY_POSITION (start
);
2539 /* This one ends at or after POS
2540 so its start counts for PREV_PTR if it's before POS. */
2541 if (prev
< startpos
&& startpos
< pos
)
2545 if (startpos
<= pos
)
2549 /* The supplied vector is full.
2550 Either make it bigger, or don't store any more in it. */
2553 /* Make it work with an initial len == 0. */
2558 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2562 inhibit_storing
= 1;
2565 if (!inhibit_storing
)
2567 /* Keep counting overlays even if we can't return them all. */
2570 else if (startpos
< next
)
2574 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2576 int startpos
, endpos
;
2578 XSETMISC (overlay
, tail
);
2580 start
= OVERLAY_START (overlay
);
2581 end
= OVERLAY_END (overlay
);
2582 startpos
= OVERLAY_POSITION (start
);
2585 if (startpos
< next
)
2589 endpos
= OVERLAY_POSITION (end
);
2596 /* Make it work with an initial len == 0. */
2601 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2605 inhibit_storing
= 1;
2608 if (!inhibit_storing
)
2612 if (startpos
< pos
&& startpos
> prev
)
2615 else if (endpos
< pos
&& endpos
> prev
)
2617 else if (endpos
== pos
&& startpos
> prev
2618 && (!change_req
|| startpos
< pos
))
2629 /* Find all the overlays in the current buffer that overlap the range BEG-END
2630 or are empty at BEG.
2632 Return the number found, and store them in a vector in *VEC_PTR.
2633 Store in *LEN_PTR the size allocated for the vector.
2634 Store in *NEXT_PTR the next position after POS where an overlay starts,
2635 or ZV if there are no more overlays.
2636 Store in *PREV_PTR the previous position before POS where an overlay ends,
2637 or BEGV if there are no previous overlays.
2638 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2640 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2641 when this function is called.
2643 If EXTEND is non-zero, we make the vector bigger if necessary.
2644 If EXTEND is zero, we never extend the vector,
2645 and we store only as many overlays as will fit.
2646 But we still return the total number of overlays. */
2649 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2652 Lisp_Object
**vec_ptr
;
2657 Lisp_Object overlay
, ostart
, oend
;
2658 struct Lisp_Overlay
*tail
;
2661 Lisp_Object
*vec
= *vec_ptr
;
2664 int inhibit_storing
= 0;
2666 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2668 int startpos
, endpos
;
2670 XSETMISC (overlay
, tail
);
2672 ostart
= OVERLAY_START (overlay
);
2673 oend
= OVERLAY_END (overlay
);
2674 endpos
= OVERLAY_POSITION (oend
);
2681 startpos
= OVERLAY_POSITION (ostart
);
2682 /* Count an interval if it either overlaps the range
2683 or is empty at the start of the range. */
2684 if ((beg
< endpos
&& startpos
< end
)
2685 || (startpos
== endpos
&& beg
== endpos
))
2689 /* The supplied vector is full.
2690 Either make it bigger, or don't store any more in it. */
2693 /* Make it work with an initial len == 0. */
2698 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2702 inhibit_storing
= 1;
2705 if (!inhibit_storing
)
2707 /* Keep counting overlays even if we can't return them all. */
2710 else if (startpos
< next
)
2714 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2716 int startpos
, endpos
;
2718 XSETMISC (overlay
, tail
);
2720 ostart
= OVERLAY_START (overlay
);
2721 oend
= OVERLAY_END (overlay
);
2722 startpos
= OVERLAY_POSITION (ostart
);
2725 if (startpos
< next
)
2729 endpos
= OVERLAY_POSITION (oend
);
2730 /* Count an interval if it either overlaps the range
2731 or is empty at the start of the range. */
2732 if ((beg
< endpos
&& startpos
< end
)
2733 || (startpos
== endpos
&& beg
== endpos
))
2739 /* Make it work with an initial len == 0. */
2744 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2748 inhibit_storing
= 1;
2751 if (!inhibit_storing
)
2755 else if (endpos
< beg
&& endpos
> prev
)
2767 /* Return non-zero if there exists an overlay with a non-nil
2768 `mouse-face' property overlapping OVERLAY. */
2771 mouse_face_overlay_overlaps (overlay
)
2772 Lisp_Object overlay
;
2774 int start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2775 int end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2777 Lisp_Object
*v
, tem
;
2780 v
= (Lisp_Object
*) alloca (size
* sizeof *v
);
2781 n
= overlays_in (start
, end
, 0, &v
, &size
, NULL
, NULL
);
2784 v
= (Lisp_Object
*) alloca (n
* sizeof *v
);
2785 overlays_in (start
, end
, 0, &v
, &n
, NULL
, NULL
);
2788 for (i
= 0; i
< n
; ++i
)
2789 if (!EQ (v
[i
], overlay
)
2790 && (tem
= Foverlay_get (overlay
, Qmouse_face
),
2799 /* Fast function to just test if we're at an overlay boundary. */
2801 overlay_touches_p (pos
)
2804 Lisp_Object overlay
;
2805 struct Lisp_Overlay
*tail
;
2807 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2811 XSETMISC (overlay
,tail
);
2812 if (!GC_OVERLAYP (overlay
))
2815 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2818 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2822 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2826 XSETMISC (overlay
, tail
);
2827 if (!GC_OVERLAYP (overlay
))
2830 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2833 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2841 Lisp_Object overlay
;
2847 compare_overlays (v1
, v2
)
2848 const void *v1
, *v2
;
2850 const struct sortvec
*s1
= (const struct sortvec
*) v1
;
2851 const struct sortvec
*s2
= (const struct sortvec
*) v2
;
2852 if (s1
->priority
!= s2
->priority
)
2853 return s1
->priority
- s2
->priority
;
2854 if (s1
->beg
!= s2
->beg
)
2855 return s1
->beg
- s2
->beg
;
2856 if (s1
->end
!= s2
->end
)
2857 return s2
->end
- s1
->end
;
2861 /* Sort an array of overlays by priority. The array is modified in place.
2862 The return value is the new size; this may be smaller than the original
2863 size if some of the overlays were invalid or were window-specific. */
2865 sort_overlays (overlay_vec
, noverlays
, w
)
2866 Lisp_Object
*overlay_vec
;
2871 struct sortvec
*sortvec
;
2872 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2874 /* Put the valid and relevant overlays into sortvec. */
2876 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2879 Lisp_Object overlay
;
2881 overlay
= overlay_vec
[i
];
2882 if (OVERLAY_VALID (overlay
)
2883 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2884 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2886 /* If we're interested in a specific window, then ignore
2887 overlays that are limited to some other window. */
2892 window
= Foverlay_get (overlay
, Qwindow
);
2893 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2897 /* This overlay is good and counts: put it into sortvec. */
2898 sortvec
[j
].overlay
= overlay
;
2899 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2900 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2901 tem
= Foverlay_get (overlay
, Qpriority
);
2903 sortvec
[j
].priority
= XINT (tem
);
2905 sortvec
[j
].priority
= 0;
2911 /* Sort the overlays into the proper order: increasing priority. */
2914 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2916 for (i
= 0; i
< noverlays
; i
++)
2917 overlay_vec
[i
] = sortvec
[i
].overlay
;
2923 Lisp_Object string
, string2
;
2930 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2931 int size
; /* Allocated length of that array. */
2932 int used
; /* How much of the array is currently in use. */
2933 int bytes
; /* Total length of the strings in buf. */
2936 /* Buffers for storing information about the overlays touching a given
2937 position. These could be automatic variables in overlay_strings, but
2938 it's more efficient to hold onto the memory instead of repeatedly
2939 allocating and freeing it. */
2940 static struct sortstrlist overlay_heads
, overlay_tails
;
2941 static unsigned char *overlay_str_buf
;
2943 /* Allocated length of overlay_str_buf. */
2944 static int overlay_str_len
;
2946 /* A comparison function suitable for passing to qsort. */
2948 cmp_for_strings (as1
, as2
)
2951 struct sortstr
*s1
= (struct sortstr
*)as1
;
2952 struct sortstr
*s2
= (struct sortstr
*)as2
;
2953 if (s1
->size
!= s2
->size
)
2954 return s2
->size
- s1
->size
;
2955 if (s1
->priority
!= s2
->priority
)
2956 return s1
->priority
- s2
->priority
;
2961 record_overlay_string (ssl
, str
, str2
, pri
, size
)
2962 struct sortstrlist
*ssl
;
2963 Lisp_Object str
, str2
, pri
;
2968 if (ssl
->used
== ssl
->size
)
2974 ssl
->buf
= ((struct sortstr
*)
2975 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
2977 ssl
->buf
[ssl
->used
].string
= str
;
2978 ssl
->buf
[ssl
->used
].string2
= str2
;
2979 ssl
->buf
[ssl
->used
].size
= size
;
2980 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
2983 if (NILP (current_buffer
->enable_multibyte_characters
))
2984 nbytes
= SCHARS (str
);
2985 else if (! STRING_MULTIBYTE (str
))
2986 nbytes
= count_size_as_multibyte (SDATA (str
),
2989 nbytes
= SBYTES (str
);
2991 ssl
->bytes
+= nbytes
;
2995 if (NILP (current_buffer
->enable_multibyte_characters
))
2996 nbytes
= SCHARS (str2
);
2997 else if (! STRING_MULTIBYTE (str2
))
2998 nbytes
= count_size_as_multibyte (SDATA (str2
),
3001 nbytes
= SBYTES (str2
);
3003 ssl
->bytes
+= nbytes
;
3007 /* Return the concatenation of the strings associated with overlays that
3008 begin or end at POS, ignoring overlays that are specific to a window
3009 other than W. The strings are concatenated in the appropriate order:
3010 shorter overlays nest inside longer ones, and higher priority inside
3011 lower. Normally all of the after-strings come first, but zero-sized
3012 overlays have their after-strings ride along with the before-strings
3013 because it would look strange to print them inside-out.
3015 Returns the string length, and stores the contents indirectly through
3016 PSTR, if that variable is non-null. The string may be overwritten by
3017 subsequent calls. */
3020 overlay_strings (pos
, w
, pstr
)
3023 unsigned char **pstr
;
3025 Lisp_Object overlay
, window
, str
;
3026 struct Lisp_Overlay
*ov
;
3027 int startpos
, endpos
;
3028 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
3030 overlay_heads
.used
= overlay_heads
.bytes
= 0;
3031 overlay_tails
.used
= overlay_tails
.bytes
= 0;
3032 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
3034 XSETMISC (overlay
, ov
);
3035 eassert (OVERLAYP (overlay
));
3037 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3038 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3041 if (endpos
!= pos
&& startpos
!= pos
)
3043 window
= Foverlay_get (overlay
, Qwindow
);
3044 if (WINDOWP (window
) && XWINDOW (window
) != w
)
3047 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
3048 record_overlay_string (&overlay_heads
, str
,
3050 ? Foverlay_get (overlay
, Qafter_string
)
3052 Foverlay_get (overlay
, Qpriority
),
3054 else if (endpos
== pos
3055 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
3056 record_overlay_string (&overlay_tails
, str
, Qnil
,
3057 Foverlay_get (overlay
, Qpriority
),
3060 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
3062 XSETMISC (overlay
, ov
);
3063 eassert (OVERLAYP (overlay
));
3065 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3066 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3069 if (endpos
!= pos
&& startpos
!= pos
)
3071 window
= Foverlay_get (overlay
, Qwindow
);
3072 if (WINDOWP (window
) && XWINDOW (window
) != w
)
3075 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
3076 record_overlay_string (&overlay_heads
, str
,
3078 ? Foverlay_get (overlay
, Qafter_string
)
3080 Foverlay_get (overlay
, Qpriority
),
3082 else if (endpos
== pos
3083 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
3084 record_overlay_string (&overlay_tails
, str
, Qnil
,
3085 Foverlay_get (overlay
, Qpriority
),
3088 if (overlay_tails
.used
> 1)
3089 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
3091 if (overlay_heads
.used
> 1)
3092 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
3094 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
3099 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
3101 if (total
> overlay_str_len
)
3103 overlay_str_len
= total
;
3104 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
3107 p
= overlay_str_buf
;
3108 for (i
= overlay_tails
.used
; --i
>= 0;)
3111 tem
= overlay_tails
.buf
[i
].string
;
3112 nbytes
= copy_text (SDATA (tem
), p
,
3114 STRING_MULTIBYTE (tem
), multibyte
);
3117 for (i
= 0; i
< overlay_heads
.used
; ++i
)
3120 tem
= overlay_heads
.buf
[i
].string
;
3121 nbytes
= copy_text (SDATA (tem
), p
,
3123 STRING_MULTIBYTE (tem
), multibyte
);
3125 tem
= overlay_heads
.buf
[i
].string2
;
3128 nbytes
= copy_text (SDATA (tem
), p
,
3130 STRING_MULTIBYTE (tem
), multibyte
);
3134 if (p
!= overlay_str_buf
+ total
)
3137 *pstr
= overlay_str_buf
;
3143 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3146 recenter_overlay_lists (buf
, pos
)
3150 Lisp_Object overlay
, beg
, end
;
3151 struct Lisp_Overlay
*prev
, *tail
, *next
;
3153 /* See if anything in overlays_before should move to overlays_after. */
3155 /* We don't strictly need prev in this loop; it should always be nil.
3156 But we use it for symmetry and in case that should cease to be true
3157 with some future change. */
3159 for (tail
= buf
->overlays_before
; tail
; prev
= tail
, tail
= next
)
3162 XSETMISC (overlay
, tail
);
3164 /* If the overlay is not valid, get rid of it. */
3165 if (!OVERLAY_VALID (overlay
))
3170 /* Splice the cons cell TAIL out of overlays_before. */
3174 buf
->overlays_before
= next
;
3180 beg
= OVERLAY_START (overlay
);
3181 end
= OVERLAY_END (overlay
);
3183 if (OVERLAY_POSITION (end
) > pos
)
3185 /* OVERLAY needs to be moved. */
3186 int where
= OVERLAY_POSITION (beg
);
3187 struct Lisp_Overlay
*other
, *other_prev
;
3189 /* Splice the cons cell TAIL out of overlays_before. */
3193 buf
->overlays_before
= next
;
3195 /* Search thru overlays_after for where to put it. */
3197 for (other
= buf
->overlays_after
; other
;
3198 other_prev
= other
, other
= other
->next
)
3200 Lisp_Object otherbeg
, otheroverlay
;
3202 XSETMISC (otheroverlay
, other
);
3203 eassert (OVERLAY_VALID (otheroverlay
));
3205 otherbeg
= OVERLAY_START (otheroverlay
);
3206 if (OVERLAY_POSITION (otherbeg
) >= where
)
3210 /* Add TAIL to overlays_after before OTHER. */
3213 other_prev
->next
= tail
;
3215 buf
->overlays_after
= tail
;
3219 /* We've reached the things that should stay in overlays_before.
3220 All the rest of overlays_before must end even earlier,
3225 /* See if anything in overlays_after should be in overlays_before. */
3227 for (tail
= buf
->overlays_after
; tail
; prev
= tail
, tail
= next
)
3230 XSETMISC (overlay
, tail
);
3232 /* If the overlay is not valid, get rid of it. */
3233 if (!OVERLAY_VALID (overlay
))
3238 /* Splice the cons cell TAIL out of overlays_after. */
3242 buf
->overlays_after
= next
;
3248 beg
= OVERLAY_START (overlay
);
3249 end
= OVERLAY_END (overlay
);
3251 /* Stop looking, when we know that nothing further
3252 can possibly end before POS. */
3253 if (OVERLAY_POSITION (beg
) > pos
)
3256 if (OVERLAY_POSITION (end
) <= pos
)
3258 /* OVERLAY needs to be moved. */
3259 int where
= OVERLAY_POSITION (end
);
3260 struct Lisp_Overlay
*other
, *other_prev
;
3262 /* Splice the cons cell TAIL out of overlays_after. */
3266 buf
->overlays_after
= next
;
3268 /* Search thru overlays_before for where to put it. */
3270 for (other
= buf
->overlays_before
; other
;
3271 other_prev
= other
, other
= other
->next
)
3273 Lisp_Object otherend
, otheroverlay
;
3275 XSETMISC (otheroverlay
, other
);
3276 eassert (OVERLAY_VALID (otheroverlay
));
3278 otherend
= OVERLAY_END (otheroverlay
);
3279 if (OVERLAY_POSITION (otherend
) <= where
)
3283 /* Add TAIL to overlays_before before OTHER. */
3286 other_prev
->next
= tail
;
3288 buf
->overlays_before
= tail
;
3293 buf
->overlay_center
= pos
;
3297 adjust_overlays_for_insert (pos
, length
)
3301 /* After an insertion, the lists are still sorted properly,
3302 but we may need to update the value of the overlay center. */
3303 if (current_buffer
->overlay_center
>= pos
)
3304 current_buffer
->overlay_center
+= length
;
3308 adjust_overlays_for_delete (pos
, length
)
3312 if (current_buffer
->overlay_center
< pos
)
3313 /* The deletion was to our right. No change needed; the before- and
3314 after-lists are still consistent. */
3316 else if (current_buffer
->overlay_center
> pos
+ length
)
3317 /* The deletion was to our left. We need to adjust the center value
3318 to account for the change in position, but the lists are consistent
3319 given the new value. */
3320 current_buffer
->overlay_center
-= length
;
3322 /* We're right in the middle. There might be things on the after-list
3323 that now belong on the before-list. Recentering will move them,
3324 and also update the center point. */
3325 recenter_overlay_lists (current_buffer
, pos
);
3328 /* Fix up overlays that were garbled as a result of permuting markers
3329 in the range START through END. Any overlay with at least one
3330 endpoint in this range will need to be unlinked from the overlay
3331 list and reinserted in its proper place.
3332 Such an overlay might even have negative size at this point.
3333 If so, we'll make the overlay empty. */
3335 fix_start_end_in_overlays (start
, end
)
3336 register int start
, end
;
3338 Lisp_Object overlay
;
3339 struct Lisp_Overlay
*before_list
, *after_list
;
3340 /* These are either nil, indicating that before_list or after_list
3341 should be assigned, or the cons cell the cdr of which should be
3343 struct Lisp_Overlay
*beforep
= NULL
, *afterp
= NULL
;
3344 /* 'Parent', likewise, indicates a cons cell or
3345 current_buffer->overlays_before or overlays_after, depending
3346 which loop we're in. */
3347 struct Lisp_Overlay
*tail
, *parent
;
3348 int startpos
, endpos
;
3350 /* This algorithm shifts links around instead of consing and GCing.
3351 The loop invariant is that before_list (resp. after_list) is a
3352 well-formed list except that its last element, the CDR of beforep
3353 (resp. afterp) if beforep (afterp) isn't nil or before_list
3354 (after_list) if it is, is still uninitialized. So it's not a bug
3355 that before_list isn't initialized, although it may look
3357 for (parent
= NULL
, tail
= current_buffer
->overlays_before
; tail
;)
3359 XSETMISC (overlay
, tail
);
3361 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3362 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3364 /* If the overlay is backwards, make it empty. */
3365 if (endpos
< startpos
)
3368 Fset_marker (OVERLAY_START (overlay
), make_number (startpos
),
3376 || (startpos
>= start
&& startpos
< end
))
3378 /* Add it to the end of the wrong list. Later on,
3379 recenter_overlay_lists will move it to the right place. */
3380 if (endpos
< current_buffer
->overlay_center
)
3385 afterp
->next
= tail
;
3393 beforep
->next
= tail
;
3397 current_buffer
->overlays_before
= tail
->next
;
3399 parent
->next
= tail
->next
;
3403 parent
= tail
, tail
= parent
->next
;
3405 for (parent
= NULL
, tail
= current_buffer
->overlays_after
; tail
;)
3407 XSETMISC (overlay
, tail
);
3409 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3410 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3412 /* If the overlay is backwards, make it empty. */
3413 if (endpos
< startpos
)
3416 Fset_marker (OVERLAY_START (overlay
), make_number (startpos
),
3420 if (startpos
>= end
)
3423 if (startpos
>= start
3424 || (endpos
>= start
&& endpos
< end
))
3426 if (endpos
< current_buffer
->overlay_center
)
3431 afterp
->next
= tail
;
3439 beforep
->next
= tail
;
3443 current_buffer
->overlays_after
= tail
->next
;
3445 parent
->next
= tail
->next
;
3449 parent
= tail
, tail
= parent
->next
;
3452 /* Splice the constructed (wrong) lists into the buffer's lists,
3453 and let the recenter function make it sane again. */
3456 beforep
->next
= current_buffer
->overlays_before
;
3457 current_buffer
->overlays_before
= before_list
;
3459 recenter_overlay_lists (current_buffer
, current_buffer
->overlay_center
);
3463 afterp
->next
= current_buffer
->overlays_after
;
3464 current_buffer
->overlays_after
= after_list
;
3466 recenter_overlay_lists (current_buffer
, current_buffer
->overlay_center
);
3469 /* We have two types of overlay: the one whose ending marker is
3470 after-insertion-marker (this is the usual case) and the one whose
3471 ending marker is before-insertion-marker. When `overlays_before'
3472 contains overlays of the latter type and the former type in this
3473 order and both overlays end at inserting position, inserting a text
3474 increases only the ending marker of the latter type, which results
3475 in incorrect ordering of `overlays_before'.
3477 This function fixes ordering of overlays in the slot
3478 `overlays_before' of the buffer *BP. Before the insertion, `point'
3479 was at PREV, and now is at POS. */
3482 fix_overlays_before (bp
, prev
, pos
)
3484 EMACS_INT prev
, pos
;
3486 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3487 struct Lisp_Overlay
*tail
= bp
->overlays_before
, *parent
= NULL
, *right_pair
;
3491 /* After the insertion, the several overlays may be in incorrect
3492 order. The possibility is that, in the list `overlays_before',
3493 an overlay which ends at POS appears after an overlay which ends
3494 at PREV. Since POS is greater than PREV, we must fix the
3495 ordering of these overlays, by moving overlays ends at POS before
3496 the overlays ends at PREV. */
3498 /* At first, find a place where disordered overlays should be linked
3499 in. It is where an overlay which end before POS exists. (i.e. an
3500 overlay whose ending marker is after-insertion-marker if disorder
3503 && (XSETMISC (tem
, tail
),
3504 (end
= OVERLAY_POSITION (OVERLAY_END (tem
))) >= pos
))
3510 /* If we don't find such an overlay,
3511 or the found one ends before PREV,
3512 or the found one is the last one in the list,
3513 we don't have to fix anything. */
3514 if (!tail
|| end
< prev
|| !tail
->next
)
3517 right_pair
= parent
;
3521 /* Now, end position of overlays in the list TAIL should be before
3522 or equal to PREV. In the loop, an overlay which ends at POS is
3523 moved ahead to the place indicated by the CDR of RIGHT_PAIR. If
3524 we found an overlay which ends before PREV, the remaining
3525 overlays are in correct order. */
3528 XSETMISC (tem
, tail
);
3529 end
= OVERLAY_POSITION (OVERLAY_END (tem
));
3532 { /* This overlay is disordered. */
3533 struct Lisp_Overlay
*found
= tail
;
3535 /* Unlink the found overlay. */
3537 parent
->next
= tail
;
3538 /* Move an overlay at RIGHT_PLACE to the next of the found one,
3539 and link it into the right place. */
3542 found
->next
= bp
->overlays_before
;
3543 bp
->overlays_before
= found
;
3547 found
->next
= right_pair
->next
;
3548 right_pair
->next
= found
;
3551 else if (end
== prev
)
3556 else /* No more disordered overlay. */
3561 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
3562 doc
: /* Return t if OBJECT is an overlay. */)
3566 return (OVERLAYP (object
) ? Qt
: Qnil
);
3569 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
3570 doc
: /* Create a new overlay with range BEG to END in BUFFER.
3571 If omitted, BUFFER defaults to the current buffer.
3572 BEG and END may be integers or markers.
3573 The fourth arg FRONT-ADVANCE, if non-nil, makes the marker
3574 for the front of the overlay advance when text is inserted there
3575 (which means the text *is not* included in the overlay).
3576 The fifth arg REAR-ADVANCE, if non-nil, makes the marker
3577 for the rear of the overlay advance when text is inserted there
3578 (which means the text *is* included in the overlay). */)
3579 (beg
, end
, buffer
, front_advance
, rear_advance
)
3580 Lisp_Object beg
, end
, buffer
;
3581 Lisp_Object front_advance
, rear_advance
;
3583 Lisp_Object overlay
;
3587 XSETBUFFER (buffer
, current_buffer
);
3589 CHECK_BUFFER (buffer
);
3591 && ! EQ (Fmarker_buffer (beg
), buffer
))
3592 error ("Marker points into wrong buffer");
3594 && ! EQ (Fmarker_buffer (end
), buffer
))
3595 error ("Marker points into wrong buffer");
3597 CHECK_NUMBER_COERCE_MARKER (beg
);
3598 CHECK_NUMBER_COERCE_MARKER (end
);
3600 if (XINT (beg
) > XINT (end
))
3603 temp
= beg
; beg
= end
; end
= temp
;
3606 b
= XBUFFER (buffer
);
3608 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
3609 end
= Fset_marker (Fmake_marker (), end
, buffer
);
3611 if (!NILP (front_advance
))
3612 XMARKER (beg
)->insertion_type
= 1;
3613 if (!NILP (rear_advance
))
3614 XMARKER (end
)->insertion_type
= 1;
3616 overlay
= allocate_misc ();
3617 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
3618 XOVERLAY (overlay
)->start
= beg
;
3619 XOVERLAY (overlay
)->end
= end
;
3620 XOVERLAY (overlay
)->plist
= Qnil
;
3621 XOVERLAY (overlay
)->next
= NULL
;
3623 /* Put the new overlay on the wrong list. */
3624 end
= OVERLAY_END (overlay
);
3625 if (OVERLAY_POSITION (end
) < b
->overlay_center
)
3627 if (b
->overlays_after
)
3628 XOVERLAY (overlay
)->next
= b
->overlays_after
;
3629 b
->overlays_after
= XOVERLAY (overlay
);
3633 if (b
->overlays_before
)
3634 XOVERLAY (overlay
)->next
= b
->overlays_before
;
3635 b
->overlays_before
= XOVERLAY (overlay
);
3638 /* This puts it in the right list, and in the right order. */
3639 recenter_overlay_lists (b
, b
->overlay_center
);
3641 /* We don't need to redisplay the region covered by the overlay, because
3642 the overlay has no properties at the moment. */
3647 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3650 modify_overlay (buf
, start
, end
)
3652 EMACS_INT start
, end
;
3661 BUF_COMPUTE_UNCHANGED (buf
, start
, end
);
3663 /* If this is a buffer not in the selected window,
3664 we must do other windows. */
3665 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
3666 windows_or_buffers_changed
= 1;
3667 /* If multiple windows show this buffer, we must do other windows. */
3668 else if (buffer_shared
> 1)
3669 windows_or_buffers_changed
= 1;
3671 ++BUF_OVERLAY_MODIFF (buf
);
3675 Lisp_Object
Fdelete_overlay ();
3677 static struct Lisp_Overlay
*
3678 unchain_overlay (list
, overlay
)
3679 struct Lisp_Overlay
*list
, *overlay
;
3681 struct Lisp_Overlay
*tmp
, *prev
;
3682 for (tmp
= list
, prev
= NULL
; tmp
; prev
= tmp
, tmp
= tmp
->next
)
3686 prev
->next
= tmp
->next
;
3689 overlay
->next
= NULL
;
3695 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
3696 doc
: /* Set the endpoints of OVERLAY to BEG and END in BUFFER.
3697 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
3698 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
3700 (overlay
, beg
, end
, buffer
)
3701 Lisp_Object overlay
, beg
, end
, buffer
;
3703 struct buffer
*b
, *ob
;
3704 Lisp_Object obuffer
;
3705 int count
= SPECPDL_INDEX ();
3707 CHECK_OVERLAY (overlay
);
3709 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3711 XSETBUFFER (buffer
, current_buffer
);
3712 CHECK_BUFFER (buffer
);
3715 && ! EQ (Fmarker_buffer (beg
), buffer
))
3716 error ("Marker points into wrong buffer");
3718 && ! EQ (Fmarker_buffer (end
), buffer
))
3719 error ("Marker points into wrong buffer");
3721 CHECK_NUMBER_COERCE_MARKER (beg
);
3722 CHECK_NUMBER_COERCE_MARKER (end
);
3724 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3725 return Fdelete_overlay (overlay
);
3727 if (XINT (beg
) > XINT (end
))
3730 temp
= beg
; beg
= end
; end
= temp
;
3733 specbind (Qinhibit_quit
, Qt
);
3735 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3736 b
= XBUFFER (buffer
);
3737 ob
= BUFFERP (obuffer
) ? XBUFFER (obuffer
) : (struct buffer
*) 0;
3739 /* If the overlay has changed buffers, do a thorough redisplay. */
3740 if (!EQ (buffer
, obuffer
))
3742 /* Redisplay where the overlay was. */
3743 if (!NILP (obuffer
))
3748 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3749 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3751 modify_overlay (ob
, o_beg
, o_end
);
3754 /* Redisplay where the overlay is going to be. */
3755 modify_overlay (b
, XINT (beg
), XINT (end
));
3758 /* Redisplay the area the overlay has just left, or just enclosed. */
3762 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3763 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3765 if (o_beg
== XINT (beg
))
3766 modify_overlay (b
, o_end
, XINT (end
));
3767 else if (o_end
== XINT (end
))
3768 modify_overlay (b
, o_beg
, XINT (beg
));
3771 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
3772 if (XINT (end
) > o_end
) o_end
= XINT (end
);
3773 modify_overlay (b
, o_beg
, o_end
);
3777 if (!NILP (obuffer
))
3780 = unchain_overlay (ob
->overlays_before
, XOVERLAY (overlay
));
3782 = unchain_overlay (ob
->overlays_after
, XOVERLAY (overlay
));
3783 eassert (XOVERLAY (overlay
)->next
== NULL
);
3786 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
3787 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
3789 /* Put the overlay on the wrong list. */
3790 end
= OVERLAY_END (overlay
);
3791 if (OVERLAY_POSITION (end
) < b
->overlay_center
)
3793 XOVERLAY (overlay
)->next
= b
->overlays_after
;
3794 b
->overlays_after
= XOVERLAY (overlay
);
3798 XOVERLAY (overlay
)->next
= b
->overlays_before
;
3799 b
->overlays_before
= XOVERLAY (overlay
);
3802 /* This puts it in the right list, and in the right order. */
3803 recenter_overlay_lists (b
, b
->overlay_center
);
3805 return unbind_to (count
, overlay
);
3808 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
3809 doc
: /* Delete the overlay OVERLAY from its buffer. */)
3811 Lisp_Object overlay
;
3815 int count
= SPECPDL_INDEX ();
3817 CHECK_OVERLAY (overlay
);
3819 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3823 b
= XBUFFER (buffer
);
3824 specbind (Qinhibit_quit
, Qt
);
3826 b
->overlays_before
= unchain_overlay (b
->overlays_before
,XOVERLAY (overlay
));
3827 b
->overlays_after
= unchain_overlay (b
->overlays_after
, XOVERLAY (overlay
));
3828 eassert (XOVERLAY (overlay
)->next
== NULL
);
3830 marker_position (OVERLAY_START (overlay
)),
3831 marker_position (OVERLAY_END (overlay
)));
3832 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
3833 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
3835 /* When deleting an overlay with before or after strings, turn off
3836 display optimizations for the affected buffer, on the basis that
3837 these strings may contain newlines. This is easier to do than to
3838 check for that situation during redisplay. */
3839 if (!windows_or_buffers_changed
3840 && (!NILP (Foverlay_get (overlay
, Qbefore_string
))
3841 || !NILP (Foverlay_get (overlay
, Qafter_string
))))
3842 b
->prevent_redisplay_optimizations_p
= 1;
3844 return unbind_to (count
, Qnil
);
3847 /* Overlay dissection functions. */
3849 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3850 doc
: /* Return the position at which OVERLAY starts. */)
3852 Lisp_Object overlay
;
3854 CHECK_OVERLAY (overlay
);
3856 return (Fmarker_position (OVERLAY_START (overlay
)));
3859 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3860 doc
: /* Return the position at which OVERLAY ends. */)
3862 Lisp_Object overlay
;
3864 CHECK_OVERLAY (overlay
);
3866 return (Fmarker_position (OVERLAY_END (overlay
)));
3869 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3870 doc
: /* Return the buffer OVERLAY belongs to.
3871 Return nil if OVERLAY has been deleted. */)
3873 Lisp_Object overlay
;
3875 CHECK_OVERLAY (overlay
);
3877 return Fmarker_buffer (OVERLAY_START (overlay
));
3880 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3881 doc
: /* Return a list of the properties on OVERLAY.
3882 This is a copy of OVERLAY's plist; modifying its conses has no effect on
3885 Lisp_Object overlay
;
3887 CHECK_OVERLAY (overlay
);
3889 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3893 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3894 doc
: /* Return a list of the overlays that contain position POS. */)
3899 Lisp_Object
*overlay_vec
;
3903 CHECK_NUMBER_COERCE_MARKER (pos
);
3906 /* We can't use alloca here because overlays_at can call xrealloc. */
3907 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3909 /* Put all the overlays we want in a vector in overlay_vec.
3910 Store the length in len. */
3911 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3912 (int *) 0, (int *) 0, 0);
3914 /* Make a list of them all. */
3915 result
= Flist (noverlays
, overlay_vec
);
3917 xfree (overlay_vec
);
3921 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3922 doc
: /* Return a list of the overlays that overlap the region BEG ... END.
3923 Overlap means that at least one character is contained within the overlay
3924 and also contained within the specified region.
3925 Empty overlays are included in the result if they are located at BEG
3926 or between BEG and END. */)
3928 Lisp_Object beg
, end
;
3931 Lisp_Object
*overlay_vec
;
3935 CHECK_NUMBER_COERCE_MARKER (beg
);
3936 CHECK_NUMBER_COERCE_MARKER (end
);
3939 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3941 /* Put all the overlays we want in a vector in overlay_vec.
3942 Store the length in len. */
3943 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3944 (int *) 0, (int *) 0);
3946 /* Make a list of them all. */
3947 result
= Flist (noverlays
, overlay_vec
);
3949 xfree (overlay_vec
);
3953 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3955 doc
: /* Return the next position after POS where an overlay starts or ends.
3956 If there are no more overlay boundaries after POS, return (point-max). */)
3962 Lisp_Object
*overlay_vec
;
3966 CHECK_NUMBER_COERCE_MARKER (pos
);
3969 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3971 /* Put all the overlays we want in a vector in overlay_vec.
3972 Store the length in len.
3973 endpos gets the position where the next overlay starts. */
3974 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3975 &endpos
, (int *) 0, 1);
3977 /* If any of these overlays ends before endpos,
3978 use its ending point instead. */
3979 for (i
= 0; i
< noverlays
; i
++)
3984 oend
= OVERLAY_END (overlay_vec
[i
]);
3985 oendpos
= OVERLAY_POSITION (oend
);
3986 if (oendpos
< endpos
)
3990 xfree (overlay_vec
);
3991 return make_number (endpos
);
3994 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
3995 Sprevious_overlay_change
, 1, 1, 0,
3996 doc
: /* Return the previous position before POS where an overlay starts or ends.
3997 If there are no more overlay boundaries before POS, return (point-min). */)
4003 Lisp_Object
*overlay_vec
;
4006 CHECK_NUMBER_COERCE_MARKER (pos
);
4008 /* At beginning of buffer, we know the answer;
4009 avoid bug subtracting 1 below. */
4010 if (XINT (pos
) == BEGV
)
4014 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
4016 /* Put all the overlays we want in a vector in overlay_vec.
4017 Store the length in len.
4018 prevpos gets the position of the previous change. */
4019 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
4020 (int *) 0, &prevpos
, 1);
4022 xfree (overlay_vec
);
4023 return make_number (prevpos
);
4026 /* These functions are for debugging overlays. */
4028 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
4029 doc
: /* Return a pair of lists giving all the overlays of the current buffer.
4030 The car has all the overlays before the overlay center;
4031 the cdr has all the overlays after the overlay center.
4032 Recentering overlays moves overlays between these lists.
4033 The lists you get are copies, so that changing them has no effect.
4034 However, the overlays you get are the real objects that the buffer uses. */)
4037 struct Lisp_Overlay
*ol
;
4038 Lisp_Object before
= Qnil
, after
= Qnil
, tmp
;
4039 for (ol
= current_buffer
->overlays_before
; ol
; ol
= ol
->next
)
4042 before
= Fcons (tmp
, before
);
4044 for (ol
= current_buffer
->overlays_after
; ol
; ol
= ol
->next
)
4047 after
= Fcons (tmp
, after
);
4049 return Fcons (Fnreverse (before
), Fnreverse (after
));
4052 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
4053 doc
: /* Recenter the overlays of the current buffer around position POS.
4054 That makes overlay lookup faster for positions near POS (but perhaps slower
4055 for positions far away from POS). */)
4059 CHECK_NUMBER_COERCE_MARKER (pos
);
4061 recenter_overlay_lists (current_buffer
, XINT (pos
));
4065 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
4066 doc
: /* Get the property of overlay OVERLAY with property name PROP. */)
4068 Lisp_Object overlay
, prop
;
4070 CHECK_OVERLAY (overlay
);
4071 return lookup_char_property (XOVERLAY (overlay
)->plist
, prop
, 0);
4074 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
4075 doc
: /* Set one property of overlay OVERLAY: give property PROP value VALUE. */)
4076 (overlay
, prop
, value
)
4077 Lisp_Object overlay
, prop
, value
;
4079 Lisp_Object tail
, buffer
;
4082 CHECK_OVERLAY (overlay
);
4084 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
4086 for (tail
= XOVERLAY (overlay
)->plist
;
4087 CONSP (tail
) && CONSP (XCDR (tail
));
4088 tail
= XCDR (XCDR (tail
)))
4089 if (EQ (XCAR (tail
), prop
))
4091 changed
= !EQ (XCAR (XCDR (tail
)), value
);
4092 XSETCAR (XCDR (tail
), value
);
4095 /* It wasn't in the list, so add it to the front. */
4096 changed
= !NILP (value
);
4097 XOVERLAY (overlay
)->plist
4098 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
4100 if (! NILP (buffer
))
4103 modify_overlay (XBUFFER (buffer
),
4104 marker_position (OVERLAY_START (overlay
)),
4105 marker_position (OVERLAY_END (overlay
)));
4106 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
4107 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
4108 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
4109 Fdelete_overlay (overlay
);
4114 /* Subroutine of report_overlay_modification. */
4116 /* Lisp vector holding overlay hook functions to call.
4117 Vector elements come in pairs.
4118 Each even-index element is a list of hook functions.
4119 The following odd-index element is the overlay they came from.
4121 Before the buffer change, we fill in this vector
4122 as we call overlay hook functions.
4123 After the buffer change, we get the functions to call from this vector.
4124 This way we always call the same functions before and after the change. */
4125 static Lisp_Object last_overlay_modification_hooks
;
4127 /* Number of elements actually used in last_overlay_modification_hooks. */
4128 static int last_overlay_modification_hooks_used
;
4130 /* Add one functionlist/overlay pair
4131 to the end of last_overlay_modification_hooks. */
4134 add_overlay_mod_hooklist (functionlist
, overlay
)
4135 Lisp_Object functionlist
, overlay
;
4137 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
4139 if (last_overlay_modification_hooks_used
== oldsize
)
4142 old
= last_overlay_modification_hooks
;
4143 last_overlay_modification_hooks
4144 = Fmake_vector (make_number (oldsize
* 2), Qnil
);
4145 bcopy (XVECTOR (old
)->contents
,
4146 XVECTOR (last_overlay_modification_hooks
)->contents
,
4147 sizeof (Lisp_Object
) * oldsize
);
4149 AREF (last_overlay_modification_hooks
, last_overlay_modification_hooks_used
++) = functionlist
;
4150 AREF (last_overlay_modification_hooks
, last_overlay_modification_hooks_used
++) = overlay
;
4153 /* Run the modification-hooks of overlays that include
4154 any part of the text in START to END.
4155 If this change is an insertion, also
4156 run the insert-before-hooks of overlay starting at END,
4157 and the insert-after-hooks of overlay ending at START.
4159 This is called both before and after the modification.
4160 AFTER is nonzero when we call after the modification.
4162 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
4163 When AFTER is nonzero, they are the start position,
4164 the position after the inserted new text,
4165 and the length of deleted or replaced old text. */
4168 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
4169 Lisp_Object start
, end
;
4171 Lisp_Object arg1
, arg2
, arg3
;
4173 Lisp_Object prop
, overlay
;
4174 struct Lisp_Overlay
*tail
;
4175 /* 1 if this change is an insertion. */
4176 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
4177 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4182 /* We used to run the functions as soon as we found them and only register
4183 them in last_overlay_modification_hooks for the purpose of the `after'
4184 case. But running elisp code as we traverse the list of overlays is
4185 painful because the list can be modified by the elisp code so we had to
4186 copy at several places. We now simply do a read-only traversal that
4187 only collects the functions to run and we run them afterwards. It's
4188 simpler, especially since all the code was already there. -stef */
4192 /* We are being called before a change.
4193 Scan the overlays to find the functions to call. */
4194 last_overlay_modification_hooks_used
= 0;
4195 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
4197 int startpos
, endpos
;
4198 Lisp_Object ostart
, oend
;
4200 XSETMISC (overlay
, tail
);
4202 ostart
= OVERLAY_START (overlay
);
4203 oend
= OVERLAY_END (overlay
);
4204 endpos
= OVERLAY_POSITION (oend
);
4205 if (XFASTINT (start
) > endpos
)
4207 startpos
= OVERLAY_POSITION (ostart
);
4208 if (insertion
&& (XFASTINT (start
) == startpos
4209 || XFASTINT (end
) == startpos
))
4211 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
4213 add_overlay_mod_hooklist (prop
, overlay
);
4215 if (insertion
&& (XFASTINT (start
) == endpos
4216 || XFASTINT (end
) == endpos
))
4218 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
4220 add_overlay_mod_hooklist (prop
, overlay
);
4222 /* Test for intersecting intervals. This does the right thing
4223 for both insertion and deletion. */
4224 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
4226 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
4228 add_overlay_mod_hooklist (prop
, overlay
);
4232 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
4234 int startpos
, endpos
;
4235 Lisp_Object ostart
, oend
;
4237 XSETMISC (overlay
, tail
);
4239 ostart
= OVERLAY_START (overlay
);
4240 oend
= OVERLAY_END (overlay
);
4241 startpos
= OVERLAY_POSITION (ostart
);
4242 endpos
= OVERLAY_POSITION (oend
);
4243 if (XFASTINT (end
) < startpos
)
4245 if (insertion
&& (XFASTINT (start
) == startpos
4246 || XFASTINT (end
) == startpos
))
4248 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
4250 add_overlay_mod_hooklist (prop
, overlay
);
4252 if (insertion
&& (XFASTINT (start
) == endpos
4253 || XFASTINT (end
) == endpos
))
4255 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
4257 add_overlay_mod_hooklist (prop
, overlay
);
4259 /* Test for intersecting intervals. This does the right thing
4260 for both insertion and deletion. */
4261 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
4263 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
4265 add_overlay_mod_hooklist (prop
, overlay
);
4270 GCPRO4 (overlay
, arg1
, arg2
, arg3
);
4272 /* Call the functions recorded in last_overlay_modification_hooks.
4273 First copy the vector contents, in case some of these hooks
4274 do subsequent modification of the buffer. */
4275 int size
= last_overlay_modification_hooks_used
;
4276 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
4279 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
4280 copy
, size
* sizeof (Lisp_Object
));
4282 gcpro1
.nvars
= size
;
4284 for (i
= 0; i
< size
;)
4286 Lisp_Object prop
, overlay
;
4288 overlay
= copy
[i
++];
4289 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
4296 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
4297 Lisp_Object list
, overlay
;
4299 Lisp_Object arg1
, arg2
, arg3
;
4301 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4303 GCPRO4 (list
, arg1
, arg2
, arg3
);
4305 while (CONSP (list
))
4308 call4 (XCAR (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
4310 call5 (XCAR (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
4316 /* Delete any zero-sized overlays at position POS, if the `evaporate'
4319 evaporate_overlays (pos
)
4322 Lisp_Object overlay
, hit_list
;
4323 struct Lisp_Overlay
*tail
;
4326 if (pos
<= current_buffer
->overlay_center
)
4327 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
4330 XSETMISC (overlay
, tail
);
4331 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4334 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
4335 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4336 hit_list
= Fcons (overlay
, hit_list
);
4339 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
4342 XSETMISC (overlay
, tail
);
4343 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4346 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
4347 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4348 hit_list
= Fcons (overlay
, hit_list
);
4350 for (; CONSP (hit_list
); hit_list
= XCDR (hit_list
))
4351 Fdelete_overlay (XCAR (hit_list
));
4354 /* Somebody has tried to store a value with an unacceptable type
4355 in the slot with offset OFFSET. */
4358 buffer_slot_type_mismatch (offset
)
4364 switch (XINT (PER_BUFFER_TYPE (offset
)))
4367 type_name
= "integers";
4371 type_name
= "strings";
4375 type_name
= "symbols";
4382 sym
= PER_BUFFER_SYMBOL (offset
);
4383 error ("Only %s should be stored in the buffer-local variable %s",
4384 type_name
, SDATA (SYMBOL_NAME (sym
)));
4388 /***********************************************************************
4389 Allocation with mmap
4390 ***********************************************************************/
4392 #ifdef USE_MMAP_FOR_BUFFERS
4394 #include <sys/types.h>
4395 #include <sys/mman.h>
4398 #ifdef MAP_ANONYMOUS
4399 #define MAP_ANON MAP_ANONYMOUS
4406 #define MAP_FAILED ((void *) -1)
4419 /* Memory is allocated in regions which are mapped using mmap(2).
4420 The current implementation lets the system select mapped
4421 addresses; we're not using MAP_FIXED in general, except when
4422 trying to enlarge regions.
4424 Each mapped region starts with a mmap_region structure, the user
4425 area starts after that structure, aligned to MEM_ALIGN.
4427 +-----------------------+
4428 | struct mmap_info + |
4430 +-----------------------+
4434 +-----------------------+ */
4438 /* User-specified size. */
4439 size_t nbytes_specified
;
4441 /* Number of bytes mapped */
4442 size_t nbytes_mapped
;
4444 /* Pointer to the location holding the address of the memory
4445 allocated with the mmap'd block. The variable actually points
4446 after this structure. */
4449 /* Next and previous in list of all mmap'd regions. */
4450 struct mmap_region
*next
, *prev
;
4453 /* Doubly-linked list of mmap'd regions. */
4455 static struct mmap_region
*mmap_regions
;
4457 /* File descriptor for mmap. If we don't have anonymous mapping,
4458 /dev/zero will be opened on it. */
4462 /* Temporary storage for mmap_set_vars, see there. */
4464 static struct mmap_region
*mmap_regions_1
;
4465 static int mmap_fd_1
;
4467 /* Page size on this system. */
4469 static int mmap_page_size
;
4471 /* 1 means mmap has been intialized. */
4473 static int mmap_initialized_p
;
4475 /* Value is X rounded up to the next multiple of N. */
4477 #define ROUND(X, N) (((X) + (N) - 1) / (N) * (N))
4479 /* Size of mmap_region structure plus padding. */
4481 #define MMAP_REGION_STRUCT_SIZE \
4482 ROUND (sizeof (struct mmap_region), MEM_ALIGN)
4484 /* Given a pointer P to the start of the user-visible part of a mapped
4485 region, return a pointer to the start of the region. */
4487 #define MMAP_REGION(P) \
4488 ((struct mmap_region *) ((char *) (P) - MMAP_REGION_STRUCT_SIZE))
4490 /* Given a pointer P to the start of a mapped region, return a pointer
4491 to the start of the user-visible part of the region. */
4493 #define MMAP_USER_AREA(P) \
4494 ((POINTER_TYPE *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE))
4496 #define MEM_ALIGN sizeof (double)
4498 /* Predicate returning true if part of the address range [START .. END]
4499 is currently mapped. Used to prevent overwriting an existing
4502 Default is to conservativly assume the address range is occupied by
4503 something else. This can be overridden by system configuration
4504 files if system-specific means to determine this exists. */
4506 #ifndef MMAP_ALLOCATED_P
4507 #define MMAP_ALLOCATED_P(start, end) 1
4510 /* Function prototypes. */
4512 static int mmap_free_1
P_ ((struct mmap_region
*));
4513 static int mmap_enlarge
P_ ((struct mmap_region
*, int));
4514 static struct mmap_region
*mmap_find
P_ ((POINTER_TYPE
*, POINTER_TYPE
*));
4515 static POINTER_TYPE
*mmap_alloc
P_ ((POINTER_TYPE
**, size_t));
4516 static POINTER_TYPE
*mmap_realloc
P_ ((POINTER_TYPE
**, size_t));
4517 static void mmap_free
P_ ((POINTER_TYPE
**ptr
));
4518 static void mmap_init
P_ ((void));
4521 /* Return a region overlapping address range START...END, or null if
4522 none. END is not including, i.e. the last byte in the range
4525 static struct mmap_region
*
4526 mmap_find (start
, end
)
4527 POINTER_TYPE
*start
, *end
;
4529 struct mmap_region
*r
;
4530 char *s
= (char *) start
, *e
= (char *) end
;
4532 for (r
= mmap_regions
; r
; r
= r
->next
)
4534 char *rstart
= (char *) r
;
4535 char *rend
= rstart
+ r
->nbytes_mapped
;
4537 if (/* First byte of range, i.e. START, in this region? */
4538 (s
>= rstart
&& s
< rend
)
4539 /* Last byte of range, i.e. END - 1, in this region? */
4540 || (e
> rstart
&& e
<= rend
)
4541 /* First byte of this region in the range? */
4542 || (rstart
>= s
&& rstart
< e
)
4543 /* Last byte of this region in the range? */
4544 || (rend
> s
&& rend
<= e
))
4552 /* Unmap a region. P is a pointer to the start of the user-araa of
4553 the region. Value is non-zero if successful. */
4557 struct mmap_region
*r
;
4560 r
->next
->prev
= r
->prev
;
4562 r
->prev
->next
= r
->next
;
4564 mmap_regions
= r
->next
;
4566 if (munmap ((POINTER_TYPE
*) r
, r
->nbytes_mapped
) == -1)
4568 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4576 /* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R.
4577 Value is non-zero if successful. */
4580 mmap_enlarge (r
, npages
)
4581 struct mmap_region
*r
;
4584 char *region_end
= (char *) r
+ r
->nbytes_mapped
;
4590 /* Unmap pages at the end of the region. */
4591 nbytes
= - npages
* mmap_page_size
;
4592 if (munmap (region_end
- nbytes
, nbytes
) == -1)
4593 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4596 r
->nbytes_mapped
-= nbytes
;
4600 else if (npages
> 0)
4602 nbytes
= npages
* mmap_page_size
;
4604 /* Try to map additional pages at the end of the region. We
4605 cannot do this if the address range is already occupied by
4606 something else because mmap deletes any previous mapping.
4607 I'm not sure this is worth doing, let's see. */
4608 if (!MMAP_ALLOCATED_P (region_end
, region_end
+ nbytes
))
4612 p
= mmap (region_end
, nbytes
, PROT_READ
| PROT_WRITE
,
4613 MAP_ANON
| MAP_PRIVATE
| MAP_FIXED
, mmap_fd
, 0);
4614 if (p
== MAP_FAILED
)
4615 ; /* fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); */
4616 else if (p
!= (POINTER_TYPE
*) region_end
)
4618 /* Kernels are free to choose a different address. In
4619 that case, unmap what we've mapped above; we have
4621 if (munmap (p
, nbytes
) == -1)
4622 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4626 r
->nbytes_mapped
+= nbytes
;
4636 /* Set or reset variables holding references to mapped regions. If
4637 RESTORE_P is zero, set all variables to null. If RESTORE_P is
4638 non-zero, set all variables to the start of the user-areas
4641 This function is called from Fdump_emacs to ensure that the dumped
4642 Emacs doesn't contain references to memory that won't be mapped
4643 when Emacs starts. */
4646 mmap_set_vars (restore_p
)
4649 struct mmap_region
*r
;
4653 mmap_regions
= mmap_regions_1
;
4654 mmap_fd
= mmap_fd_1
;
4655 for (r
= mmap_regions
; r
; r
= r
->next
)
4656 *r
->var
= MMAP_USER_AREA (r
);
4660 for (r
= mmap_regions
; r
; r
= r
->next
)
4662 mmap_regions_1
= mmap_regions
;
4663 mmap_regions
= NULL
;
4664 mmap_fd_1
= mmap_fd
;
4670 /* Allocate a block of storage large enough to hold NBYTES bytes of
4671 data. A pointer to the data is returned in *VAR. VAR is thus the
4672 address of some variable which will use the data area.
4674 The allocation of 0 bytes is valid.
4676 If we can't allocate the necessary memory, set *VAR to null, and
4679 static POINTER_TYPE
*
4680 mmap_alloc (var
, nbytes
)
4689 map
= ROUND (nbytes
+ MMAP_REGION_STRUCT_SIZE
, mmap_page_size
);
4690 p
= mmap (NULL
, map
, PROT_READ
| PROT_WRITE
, MAP_ANON
| MAP_PRIVATE
,
4693 if (p
== MAP_FAILED
)
4695 if (errno
!= ENOMEM
)
4696 fprintf (stderr
, "mmap: %s\n", emacs_strerror (errno
));
4701 struct mmap_region
*r
= (struct mmap_region
*) p
;
4703 r
->nbytes_specified
= nbytes
;
4704 r
->nbytes_mapped
= map
;
4707 r
->next
= mmap_regions
;
4712 p
= MMAP_USER_AREA (p
);
4719 /* Given a pointer at address VAR to data allocated with mmap_alloc,
4720 resize it to size NBYTES. Change *VAR to reflect the new block,
4721 and return this value. If more memory cannot be allocated, then
4722 leave *VAR unchanged, and return null. */
4724 static POINTER_TYPE
*
4725 mmap_realloc (var
, nbytes
)
4729 POINTER_TYPE
*result
;
4734 result
= mmap_alloc (var
, nbytes
);
4735 else if (nbytes
== 0)
4738 result
= mmap_alloc (var
, nbytes
);
4742 struct mmap_region
*r
= MMAP_REGION (*var
);
4743 size_t room
= r
->nbytes_mapped
- MMAP_REGION_STRUCT_SIZE
;
4748 POINTER_TYPE
*old_ptr
= *var
;
4750 /* Try to map additional pages at the end of the region.
4751 If that fails, allocate a new region, copy data
4752 from the old region, then free it. */
4753 if (mmap_enlarge (r
, (ROUND (nbytes
- room
, mmap_page_size
)
4756 r
->nbytes_specified
= nbytes
;
4757 *var
= result
= old_ptr
;
4759 else if (mmap_alloc (var
, nbytes
))
4761 bcopy (old_ptr
, *var
, r
->nbytes_specified
);
4762 mmap_free_1 (MMAP_REGION (old_ptr
));
4764 r
= MMAP_REGION (result
);
4765 r
->nbytes_specified
= nbytes
;
4773 else if (room
- nbytes
>= mmap_page_size
)
4775 /* Shrinking by at least a page. Let's give some
4776 memory back to the system.
4778 The extra parens are to make the division happens first,
4779 on positive values, so we know it will round towards
4781 mmap_enlarge (r
, - ((room
- nbytes
) / mmap_page_size
));
4783 r
->nbytes_specified
= nbytes
;
4787 /* Leave it alone. */
4789 r
->nbytes_specified
= nbytes
;
4797 /* Free a block of relocatable storage whose data is pointed to by
4798 PTR. Store 0 in *PTR to show there's no block allocated. */
4808 mmap_free_1 (MMAP_REGION (*var
));
4814 /* Perform necessary intializations for the use of mmap. */
4820 /* The value of mmap_fd is initially 0 in temacs, and -1
4821 in a dumped Emacs. */
4824 /* No anonymous mmap -- we need the file descriptor. */
4825 mmap_fd
= open ("/dev/zero", O_RDONLY
);
4827 fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno
));
4829 #endif /* MAP_ANON == 0 */
4831 if (mmap_initialized_p
)
4833 mmap_initialized_p
= 1;
4839 mmap_page_size
= getpagesize ();
4842 #endif /* USE_MMAP_FOR_BUFFERS */
4846 /***********************************************************************
4847 Buffer-text Allocation
4848 ***********************************************************************/
4851 extern POINTER_TYPE
*r_alloc
P_ ((POINTER_TYPE
**, size_t));
4852 extern POINTER_TYPE
*r_re_alloc
P_ ((POINTER_TYPE
**, size_t));
4853 extern void r_alloc_free
P_ ((POINTER_TYPE
**ptr
));
4854 #endif /* REL_ALLOC */
4857 /* Allocate NBYTES bytes for buffer B's text buffer. */
4860 alloc_buffer_text (b
, nbytes
)
4867 #if defined USE_MMAP_FOR_BUFFERS
4868 p
= mmap_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4869 #elif defined REL_ALLOC
4870 p
= r_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4872 p
= xmalloc (nbytes
);
4881 b
->text
->beg
= (unsigned char *) p
;
4885 /* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means
4889 enlarge_buffer_text (b
, delta
)
4894 size_t nbytes
= (BUF_Z_BYTE (b
) - BUF_BEG_BYTE (b
) + BUF_GAP_SIZE (b
) + 1
4897 #if defined USE_MMAP_FOR_BUFFERS
4898 p
= mmap_realloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4899 #elif defined REL_ALLOC
4900 p
= r_re_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4902 p
= xrealloc (b
->text
->beg
, nbytes
);
4911 BUF_BEG_ADDR (b
) = (unsigned char *) p
;
4916 /* Free buffer B's text buffer. */
4919 free_buffer_text (b
)
4924 #if defined USE_MMAP_FOR_BUFFERS
4925 mmap_free ((POINTER_TYPE
**) &b
->text
->beg
);
4926 #elif defined REL_ALLOC
4927 r_alloc_free ((POINTER_TYPE
**) &b
->text
->beg
);
4929 xfree (b
->text
->beg
);
4932 BUF_BEG_ADDR (b
) = NULL
;
4938 /***********************************************************************
4940 ***********************************************************************/
4947 bzero (buffer_permanent_local_flags
, sizeof buffer_permanent_local_flags
);
4949 /* Make sure all markable slots in buffer_defaults
4950 are initialized reasonably, so mark_buffer won't choke. */
4951 reset_buffer (&buffer_defaults
);
4952 reset_buffer_local_variables (&buffer_defaults
, 1);
4953 reset_buffer (&buffer_local_symbols
);
4954 reset_buffer_local_variables (&buffer_local_symbols
, 1);
4955 /* Prevent GC from getting confused. */
4956 buffer_defaults
.text
= &buffer_defaults
.own_text
;
4957 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
4958 BUF_INTERVALS (&buffer_defaults
) = 0;
4959 BUF_INTERVALS (&buffer_local_symbols
) = 0;
4960 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
4961 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
4963 /* Set up the default values of various buffer slots. */
4964 /* Must do these before making the first buffer! */
4966 /* real setup is done in bindings.el */
4967 buffer_defaults
.mode_line_format
= build_string ("%-");
4968 buffer_defaults
.header_line_format
= Qnil
;
4969 buffer_defaults
.abbrev_mode
= Qnil
;
4970 buffer_defaults
.overwrite_mode
= Qnil
;
4971 buffer_defaults
.case_fold_search
= Qt
;
4972 buffer_defaults
.auto_fill_function
= Qnil
;
4973 buffer_defaults
.selective_display
= Qnil
;
4975 buffer_defaults
.selective_display_ellipses
= Qt
;
4977 buffer_defaults
.abbrev_table
= Qnil
;
4978 buffer_defaults
.display_table
= Qnil
;
4979 buffer_defaults
.undo_list
= Qnil
;
4980 buffer_defaults
.mark_active
= Qnil
;
4981 buffer_defaults
.file_format
= Qnil
;
4982 buffer_defaults
.auto_save_file_format
= Qt
;
4983 buffer_defaults
.overlays_before
= NULL
;
4984 buffer_defaults
.overlays_after
= NULL
;
4985 buffer_defaults
.overlay_center
= BEG
;
4987 XSETFASTINT (buffer_defaults
.tab_width
, 8);
4988 buffer_defaults
.truncate_lines
= Qnil
;
4989 buffer_defaults
.ctl_arrow
= Qt
;
4990 buffer_defaults
.direction_reversed
= Qnil
;
4991 buffer_defaults
.cursor_type
= Qt
;
4992 buffer_defaults
.extra_line_spacing
= Qnil
;
4993 buffer_defaults
.cursor_in_non_selected_windows
= Qt
;
4996 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
4998 buffer_defaults
.enable_multibyte_characters
= Qt
;
4999 buffer_defaults
.buffer_file_coding_system
= Qnil
;
5000 XSETFASTINT (buffer_defaults
.fill_column
, 70);
5001 XSETFASTINT (buffer_defaults
.left_margin
, 0);
5002 buffer_defaults
.cache_long_line_scans
= Qnil
;
5003 buffer_defaults
.file_truename
= Qnil
;
5004 XSETFASTINT (buffer_defaults
.display_count
, 0);
5005 XSETFASTINT (buffer_defaults
.left_margin_cols
, 0);
5006 XSETFASTINT (buffer_defaults
.right_margin_cols
, 0);
5007 buffer_defaults
.left_fringe_width
= Qnil
;
5008 buffer_defaults
.right_fringe_width
= Qnil
;
5009 buffer_defaults
.fringes_outside_margins
= Qnil
;
5010 buffer_defaults
.scroll_bar_width
= Qnil
;
5011 buffer_defaults
.vertical_scroll_bar_type
= Qt
;
5012 buffer_defaults
.indicate_empty_lines
= Qnil
;
5013 buffer_defaults
.indicate_buffer_boundaries
= Qnil
;
5014 buffer_defaults
.scroll_up_aggressively
= Qnil
;
5015 buffer_defaults
.scroll_down_aggressively
= Qnil
;
5016 buffer_defaults
.display_time
= Qnil
;
5018 /* Assign the local-flags to the slots that have default values.
5019 The local flag is a bit that is used in the buffer
5020 to say that it has its own local value for the slot.
5021 The local flag bits are in the local_var_flags slot of the buffer. */
5023 /* Nothing can work if this isn't true */
5024 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
5026 /* 0 means not a lisp var, -1 means always local, else mask */
5027 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
5028 XSETINT (buffer_local_flags
.filename
, -1);
5029 XSETINT (buffer_local_flags
.directory
, -1);
5030 XSETINT (buffer_local_flags
.backed_up
, -1);
5031 XSETINT (buffer_local_flags
.save_length
, -1);
5032 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
5033 XSETINT (buffer_local_flags
.read_only
, -1);
5034 XSETINT (buffer_local_flags
.major_mode
, -1);
5035 XSETINT (buffer_local_flags
.mode_name
, -1);
5036 XSETINT (buffer_local_flags
.undo_list
, -1);
5037 XSETINT (buffer_local_flags
.mark_active
, -1);
5038 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
5039 XSETINT (buffer_local_flags
.file_truename
, -1);
5040 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
5041 XSETINT (buffer_local_flags
.file_format
, -1);
5042 XSETINT (buffer_local_flags
.auto_save_file_format
, -1);
5043 XSETINT (buffer_local_flags
.display_count
, -1);
5044 XSETINT (buffer_local_flags
.display_time
, -1);
5045 XSETINT (buffer_local_flags
.enable_multibyte_characters
, -1);
5048 XSETFASTINT (buffer_local_flags
.mode_line_format
, idx
); ++idx
;
5049 XSETFASTINT (buffer_local_flags
.abbrev_mode
, idx
); ++idx
;
5050 XSETFASTINT (buffer_local_flags
.overwrite_mode
, idx
); ++idx
;
5051 XSETFASTINT (buffer_local_flags
.case_fold_search
, idx
); ++idx
;
5052 XSETFASTINT (buffer_local_flags
.auto_fill_function
, idx
); ++idx
;
5053 XSETFASTINT (buffer_local_flags
.selective_display
, idx
); ++idx
;
5055 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, idx
); ++idx
;
5057 XSETFASTINT (buffer_local_flags
.tab_width
, idx
); ++idx
;
5058 XSETFASTINT (buffer_local_flags
.truncate_lines
, idx
); ++idx
;
5059 XSETFASTINT (buffer_local_flags
.ctl_arrow
, idx
); ++idx
;
5060 XSETFASTINT (buffer_local_flags
.fill_column
, idx
); ++idx
;
5061 XSETFASTINT (buffer_local_flags
.left_margin
, idx
); ++idx
;
5062 XSETFASTINT (buffer_local_flags
.abbrev_table
, idx
); ++idx
;
5063 XSETFASTINT (buffer_local_flags
.display_table
, idx
); ++idx
;
5065 XSETFASTINT (buffer_local_flags
.buffer_file_type
, idx
);
5066 /* Make this one a permanent local. */
5067 buffer_permanent_local_flags
[idx
++] = 1;
5069 XSETFASTINT (buffer_local_flags
.syntax_table
, idx
); ++idx
;
5070 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, idx
); ++idx
;
5071 XSETFASTINT (buffer_local_flags
.category_table
, idx
); ++idx
;
5072 XSETFASTINT (buffer_local_flags
.direction_reversed
, idx
); ++idx
;
5073 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, idx
);
5074 /* Make this one a permanent local. */
5075 buffer_permanent_local_flags
[idx
++] = 1;
5076 XSETFASTINT (buffer_local_flags
.left_margin_cols
, idx
); ++idx
;
5077 XSETFASTINT (buffer_local_flags
.right_margin_cols
, idx
); ++idx
;
5078 XSETFASTINT (buffer_local_flags
.left_fringe_width
, idx
); ++idx
;
5079 XSETFASTINT (buffer_local_flags
.right_fringe_width
, idx
); ++idx
;
5080 XSETFASTINT (buffer_local_flags
.fringes_outside_margins
, idx
); ++idx
;
5081 XSETFASTINT (buffer_local_flags
.scroll_bar_width
, idx
); ++idx
;
5082 XSETFASTINT (buffer_local_flags
.vertical_scroll_bar_type
, idx
); ++idx
;
5083 XSETFASTINT (buffer_local_flags
.indicate_empty_lines
, idx
); ++idx
;
5084 XSETFASTINT (buffer_local_flags
.indicate_buffer_boundaries
, idx
); ++idx
;
5085 XSETFASTINT (buffer_local_flags
.scroll_up_aggressively
, idx
); ++idx
;
5086 XSETFASTINT (buffer_local_flags
.scroll_down_aggressively
, idx
); ++idx
;
5087 XSETFASTINT (buffer_local_flags
.header_line_format
, idx
); ++idx
;
5088 XSETFASTINT (buffer_local_flags
.cursor_type
, idx
); ++idx
;
5089 XSETFASTINT (buffer_local_flags
.extra_line_spacing
, idx
); ++idx
;
5090 XSETFASTINT (buffer_local_flags
.cursor_in_non_selected_windows
, idx
); ++idx
;
5092 /* Need more room? */
5093 if (idx
>= MAX_PER_BUFFER_VARS
)
5095 last_per_buffer_idx
= idx
;
5097 Vbuffer_alist
= Qnil
;
5101 QSFundamental
= build_string ("Fundamental");
5103 Qfundamental_mode
= intern ("fundamental-mode");
5104 buffer_defaults
.major_mode
= Qfundamental_mode
;
5106 Qmode_class
= intern ("mode-class");
5108 Qprotected_field
= intern ("protected-field");
5110 Qpermanent_local
= intern ("permanent-local");
5112 Qkill_buffer_hook
= intern ("kill-buffer-hook");
5113 Fput (Qkill_buffer_hook
, Qpermanent_local
, Qt
);
5115 Qucs_set_table_for_input
= intern ("ucs-set-table-for-input");
5117 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
5119 /* super-magic invisible buffer */
5120 Vbuffer_alist
= Qnil
;
5122 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
5124 inhibit_modification_hooks
= 0;
5131 struct stat dotstat
, pwdstat
;
5135 #ifdef USE_MMAP_FOR_BUFFERS
5137 /* When using the ralloc implementation based on mmap(2), buffer
5138 text pointers will have been set to null in the dumped Emacs.
5142 for (b
= all_buffers
; b
; b
= b
->next
)
5143 if (b
->text
->beg
== NULL
)
5144 enlarge_buffer_text (b
, 0);
5146 #endif /* USE_MMAP_FOR_BUFFERS */
5148 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
5149 if (NILP (buffer_defaults
.enable_multibyte_characters
))
5150 Fset_buffer_multibyte (Qnil
);
5152 pwd
= get_current_dir_name ();
5155 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno
));
5158 /* Maybe this should really use some standard subroutine
5159 whose definition is filename syntax dependent. */
5161 if (!(IS_DIRECTORY_SEP (pwd
[rc
- 1])))
5163 /* Grow buffer to add directory separator and '\0'. */
5164 pwd
= (char *) xrealloc (pwd
, rc
+ 2);
5165 pwd
[rc
] = DIRECTORY_SEP
;
5168 #endif /* not VMS */
5170 current_buffer
->directory
= make_unibyte_string (pwd
, strlen (pwd
));
5171 if (! NILP (buffer_defaults
.enable_multibyte_characters
))
5172 /* At this moment, we still don't know how to decode the
5173 directory name. So, we keep the bytes in multibyte form so
5174 that ENCODE_FILE correctly gets the original bytes. */
5175 current_buffer
->directory
5176 = string_to_multibyte (current_buffer
->directory
);
5178 /* Add /: to the front of the name
5179 if it would otherwise be treated as magic. */
5180 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
5182 /* If the default dir is just /, TEMP is non-nil
5183 because of the ange-ftp completion handler.
5184 However, it is not necessary to turn / into /:/.
5185 So avoid doing that. */
5186 && strcmp ("/", SDATA (current_buffer
->directory
)))
5187 current_buffer
->directory
5188 = concat2 (build_string ("/:"), current_buffer
->directory
);
5190 temp
= get_minibuffer (0);
5191 XBUFFER (temp
)->directory
= current_buffer
->directory
;
5196 /* initialize the buffer routines */
5200 staticpro (&last_overlay_modification_hooks
);
5201 last_overlay_modification_hooks
5202 = Fmake_vector (make_number (10), Qnil
);
5204 staticpro (&Vbuffer_defaults
);
5205 staticpro (&Vbuffer_local_symbols
);
5206 staticpro (&Qfundamental_mode
);
5207 staticpro (&Qmode_class
);
5208 staticpro (&QSFundamental
);
5209 staticpro (&Vbuffer_alist
);
5210 staticpro (&Qprotected_field
);
5211 staticpro (&Qpermanent_local
);
5212 staticpro (&Qkill_buffer_hook
);
5213 Qoverlayp
= intern ("overlayp");
5214 staticpro (&Qoverlayp
);
5215 Qevaporate
= intern ("evaporate");
5216 staticpro (&Qevaporate
);
5217 Qmodification_hooks
= intern ("modification-hooks");
5218 staticpro (&Qmodification_hooks
);
5219 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
5220 staticpro (&Qinsert_in_front_hooks
);
5221 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
5222 staticpro (&Qinsert_behind_hooks
);
5223 Qget_file_buffer
= intern ("get-file-buffer");
5224 staticpro (&Qget_file_buffer
);
5225 Qpriority
= intern ("priority");
5226 staticpro (&Qpriority
);
5227 Qwindow
= intern ("window");
5228 staticpro (&Qwindow
);
5229 Qbefore_string
= intern ("before-string");
5230 staticpro (&Qbefore_string
);
5231 Qafter_string
= intern ("after-string");
5232 staticpro (&Qafter_string
);
5233 Qfirst_change_hook
= intern ("first-change-hook");
5234 staticpro (&Qfirst_change_hook
);
5235 Qbefore_change_functions
= intern ("before-change-functions");
5236 staticpro (&Qbefore_change_functions
);
5237 Qafter_change_functions
= intern ("after-change-functions");
5238 staticpro (&Qafter_change_functions
);
5239 staticpro (&Qucs_set_table_for_input
);
5241 Qkill_buffer_query_functions
= intern ("kill-buffer-query-functions");
5242 staticpro (&Qkill_buffer_query_functions
);
5244 Fput (Qprotected_field
, Qerror_conditions
,
5245 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
5246 Fput (Qprotected_field
, Qerror_message
,
5247 build_string ("Attempt to modify a protected field"));
5249 /* All these use DEFVAR_LISP_NOPRO because the slots in
5250 buffer_defaults will all be marked via Vbuffer_defaults. */
5252 DEFVAR_LISP_NOPRO ("default-mode-line-format",
5253 &buffer_defaults
.mode_line_format
,
5254 doc
: /* Default value of `mode-line-format' for buffers that don't override it.
5255 This is the same as (default-value 'mode-line-format). */);
5257 DEFVAR_LISP_NOPRO ("default-header-line-format",
5258 &buffer_defaults
.header_line_format
,
5259 doc
: /* Default value of `header-line-format' for buffers that don't override it.
5260 This is the same as (default-value 'header-line-format). */);
5262 DEFVAR_LISP_NOPRO ("default-cursor-type", &buffer_defaults
.cursor_type
,
5263 doc
: /* Default value of `cursor-type' for buffers that don't override it.
5264 This is the same as (default-value 'cursor-type). */);
5266 DEFVAR_LISP_NOPRO ("default-line-spacing",
5267 &buffer_defaults
.extra_line_spacing
,
5268 doc
: /* Default value of `line-spacing' for buffers that don't override it.
5269 This is the same as (default-value 'line-spacing). */);
5271 DEFVAR_LISP_NOPRO ("default-cursor-in-non-selected-windows",
5272 &buffer_defaults
.cursor_in_non_selected_windows
,
5273 doc
: /* Default value of `cursor-in-non-selected-windows'.
5274 This is the same as (default-value 'cursor-in-non-selected-windows). */);
5276 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
5277 &buffer_defaults
.abbrev_mode
,
5278 doc
: /* Default value of `abbrev-mode' for buffers that do not override it.
5279 This is the same as (default-value 'abbrev-mode). */);
5281 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
5282 &buffer_defaults
.ctl_arrow
,
5283 doc
: /* Default value of `ctl-arrow' for buffers that do not override it.
5284 This is the same as (default-value 'ctl-arrow). */);
5286 DEFVAR_LISP_NOPRO ("default-direction-reversed",
5287 &buffer_defaults
.direction_reversed
,
5288 doc
: /* Default value of `direction-reversed' for buffers that do not override it.
5289 This is the same as (default-value 'direction-reversed). */);
5291 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
5292 &buffer_defaults
.enable_multibyte_characters
,
5293 doc
: /* *Default value of `enable-multibyte-characters' for buffers not overriding it.
5294 This is the same as (default-value 'enable-multibyte-characters). */);
5296 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
5297 &buffer_defaults
.buffer_file_coding_system
,
5298 doc
: /* Default value of `buffer-file-coding-system' for buffers not overriding it.
5299 This is the same as (default-value 'buffer-file-coding-system). */);
5301 DEFVAR_LISP_NOPRO ("default-truncate-lines",
5302 &buffer_defaults
.truncate_lines
,
5303 doc
: /* Default value of `truncate-lines' for buffers that do not override it.
5304 This is the same as (default-value 'truncate-lines). */);
5306 DEFVAR_LISP_NOPRO ("default-fill-column",
5307 &buffer_defaults
.fill_column
,
5308 doc
: /* Default value of `fill-column' for buffers that do not override it.
5309 This is the same as (default-value 'fill-column). */);
5311 DEFVAR_LISP_NOPRO ("default-left-margin",
5312 &buffer_defaults
.left_margin
,
5313 doc
: /* Default value of `left-margin' for buffers that do not override it.
5314 This is the same as (default-value 'left-margin). */);
5316 DEFVAR_LISP_NOPRO ("default-tab-width",
5317 &buffer_defaults
.tab_width
,
5318 doc
: /* Default value of `tab-width' for buffers that do not override it.
5319 This is the same as (default-value 'tab-width). */);
5321 DEFVAR_LISP_NOPRO ("default-case-fold-search",
5322 &buffer_defaults
.case_fold_search
,
5323 doc
: /* Default value of `case-fold-search' for buffers that don't override it.
5324 This is the same as (default-value 'case-fold-search). */);
5327 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
5328 &buffer_defaults
.buffer_file_type
,
5329 doc
: /* Default file type for buffers that do not override it.
5330 This is the same as (default-value 'buffer-file-type).
5331 The file type is nil for text, t for binary. */);
5334 DEFVAR_LISP_NOPRO ("default-left-margin-width",
5335 &buffer_defaults
.left_margin_cols
,
5336 doc
: /* Default value of `left-margin-width' for buffers that don't override it.
5337 This is the same as (default-value 'left-margin-width). */);
5339 DEFVAR_LISP_NOPRO ("default-right-margin-width",
5340 &buffer_defaults
.right_margin_cols
,
5341 doc
: /* Default value of `right-margin-width' for buffers that don't override it.
5342 This is the same as (default-value 'right-margin-width). */);
5344 DEFVAR_LISP_NOPRO ("default-left-fringe-width",
5345 &buffer_defaults
.left_fringe_width
,
5346 doc
: /* Default value of `left-fringe-width' for buffers that don't override it.
5347 This is the same as (default-value 'left-fringe-width). */);
5349 DEFVAR_LISP_NOPRO ("default-right-fringe-width",
5350 &buffer_defaults
.right_fringe_width
,
5351 doc
: /* Default value of `right-fringe-width' for buffers that don't override it.
5352 This is the same as (default-value 'right-fringe-width). */);
5354 DEFVAR_LISP_NOPRO ("default-fringes-outside-margins",
5355 &buffer_defaults
.fringes_outside_margins
,
5356 doc
: /* Default value of `fringes-outside-margins' for buffers that don't override it.
5357 This is the same as (default-value 'fringes-outside-margins). */);
5359 DEFVAR_LISP_NOPRO ("default-scroll-bar-width",
5360 &buffer_defaults
.scroll_bar_width
,
5361 doc
: /* Default value of `scroll-bar-width' for buffers that don't override it.
5362 This is the same as (default-value 'scroll-bar-width). */);
5364 DEFVAR_LISP_NOPRO ("default-vertical-scroll-bar",
5365 &buffer_defaults
.vertical_scroll_bar_type
,
5366 doc
: /* Default value of `vertical-scroll-bar' for buffers that don't override it.
5367 This is the same as (default-value 'vertical-scroll-bar). */);
5369 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines",
5370 &buffer_defaults
.indicate_empty_lines
,
5371 doc
: /* Default value of `indicate-empty-lines' for buffers that don't override it.
5372 This is the same as (default-value 'indicate-empty-lines). */);
5374 DEFVAR_LISP_NOPRO ("default-indicate-buffer-boundaries",
5375 &buffer_defaults
.indicate_buffer_boundaries
,
5376 doc
: /* Default value of `indicate-buffer-boundaries' for buffers that don't override it.
5377 This is the same as (default-value 'indicate-buffer-boundaries). */);
5379 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively",
5380 &buffer_defaults
.scroll_up_aggressively
,
5381 doc
: /* Default value of `scroll-up-aggressively'.
5382 This value applies in buffers that don't have their own local values.
5383 This variable is an alias for (default-value 'scroll-up-aggressively). */);
5385 DEFVAR_LISP_NOPRO ("default-scroll-down-aggressively",
5386 &buffer_defaults
.scroll_down_aggressively
,
5387 doc
: /* Default value of `scroll-down-aggressively'.
5388 This value applies in buffers that don't have their own local values.
5389 This variable is an alias for (default-value 'scroll-down-aggressively). */);
5391 DEFVAR_PER_BUFFER ("header-line-format",
5392 ¤t_buffer
->header_line_format
,
5394 doc
: /* Analogous to `mode-line-format', but controls the header line.
5395 The header line appears, optionally, at the top of a window;
5396 the mode line appears at the bottom. */);
5398 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
5400 doc
: /* Template for displaying mode line for current buffer.
5401 Each buffer has its own value of this variable.
5402 Value may be nil, a string, a symbol or a list or cons cell.
5403 A value of nil means don't display a mode line.
5404 For a symbol, its value is used (but it is ignored if t or nil).
5405 A string appearing directly as the value of a symbol is processed verbatim
5406 in that the %-constructs below are not recognized.
5407 Note that unless the symbol is marked as a `risky-local-variable', all
5408 properties in any strings, as well as all :eval and :propertize forms
5409 in the value of that symbol will be ignored.
5410 For a list of the form `(:eval FORM)', FORM is evaluated and the result
5411 is used as a mode line element. Be careful--FORM should not load any files,
5412 because that can cause an infinite recursion.
5413 For a list of the form `(:propertize ELT PROPS...)', ELT is displayed
5414 with the specified properties PROPS applied.
5415 For a list whose car is a symbol, the symbol's value is taken,
5416 and if that is non-nil, the cadr of the list is processed recursively.
5417 Otherwise, the caddr of the list (if there is one) is processed.
5418 For a list whose car is a string or list, each element is processed
5419 recursively and the results are effectively concatenated.
5420 For a list whose car is an integer, the cdr of the list is processed
5421 and padded (if the number is positive) or truncated (if negative)
5422 to the width specified by that number.
5423 A string is printed verbatim in the mode line except for %-constructs:
5424 (%-constructs are allowed when the string is the entire mode-line-format
5425 or when it is found in a cons-cell or a list)
5426 %b -- print buffer name. %f -- print visited file name.
5427 %F -- print frame name.
5428 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.
5429 %& is like %*, but ignore read-only-ness.
5430 % means buffer is read-only and * means it is modified.
5431 For a modified read-only buffer, %* gives % and %+ gives *.
5432 %s -- print process status. %l -- print the current line number.
5433 %c -- print the current column number (this makes editing slower).
5434 To make the column number update correctly in all cases,
5435 `column-number-mode' must be non-nil.
5436 %i -- print the size of the buffer.
5437 %I -- like %i, but use k, M, G, etc., to abbreviate.
5438 %p -- print percent of buffer above top of window, or Top, Bot or All.
5439 %P -- print percent of buffer above bottom of window, perhaps plus Top,
5440 or print Bottom or All.
5441 %m -- print the mode name.
5442 %n -- print Narrow if appropriate.
5443 %z -- print mnemonics of buffer, terminal, and keyboard coding systems.
5444 %Z -- like %z, but including the end-of-line format.
5445 %[ -- print one [ for each recursive editing level. %] similar.
5446 %% -- print %. %- -- print infinitely many dashes.
5447 Decimal digits after the % specify field width to which to pad. */);
5449 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
5450 doc
: /* *Major mode for new buffers. Defaults to `fundamental-mode'.
5451 nil here means use current buffer's major mode, provided it is not
5452 marked as "special".
5454 When a mode is used by default, `find-file' switches to it
5455 before it reads the contents into the buffer and before
5456 it finishes setting up the buffer. Thus, the mode and
5457 its hooks should not expect certain variables such as
5458 `buffer-read-only' and `buffer-file-coding-system' to be set up. */);
5460 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
5461 make_number (Lisp_Symbol
),
5462 doc
: /* Symbol for current buffer's major mode. */);
5464 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
5466 doc
: /* Pretty name of current buffer's major mode (a string). */);
5468 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
5469 doc
: /* Non-nil turns on automatic expansion of abbrevs as they are inserted. */);
5471 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
5473 doc
: /* *Non-nil if searches and matches should ignore case. */);
5475 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
5476 make_number (Lisp_Int
),
5477 doc
: /* *Column beyond which automatic line-wrapping should happen.
5478 Interactively, you can set the buffer local value using \\[set-fill-column]. */);
5480 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
5481 make_number (Lisp_Int
),
5482 doc
: /* *Column for the default indent-line-function to indent to.
5483 Linefeed indents to this column in Fundamental mode. */);
5485 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
5486 make_number (Lisp_Int
),
5487 doc
: /* *Distance between tab stops (for display of tab characters), in columns. */);
5489 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
5490 doc
: /* *Non-nil means display control chars with uparrow.
5491 A value of nil means use backslash and octal digits.
5492 This variable does not apply to characters whose display is specified
5493 in the current display table (if there is one). */);
5495 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
5496 ¤t_buffer
->enable_multibyte_characters
,
5498 doc
: /* Non-nil means the buffer contents are regarded as multi-byte characters.
5499 Otherwise they are regarded as unibyte. This affects the display,
5500 file I/O and the behavior of various editing commands.
5502 This variable is buffer-local but you cannot set it directly;
5503 use the function `set-buffer-multibyte' to change a buffer's representation.
5504 Changing its default value with `setq-default' is supported.
5505 See also variable `default-enable-multibyte-characters' and Info node
5506 `(elisp)Text Representations'. */);
5507 XSYMBOL (intern ("enable-multibyte-characters"))->constant
= 1;
5509 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
5510 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
5511 doc
: /* Coding system to be used for encoding the buffer contents on saving.
5512 This variable applies to saving the buffer, and also to `write-region'
5513 and other functions that use `write-region'.
5514 It does not apply to sending output to subprocesses, however.
5516 If this is nil, the buffer is saved without any code conversion
5517 unless some coding system is specified in `file-coding-system-alist'
5518 for the buffer file.
5520 If the text to be saved cannot be encoded as specified by this variable,
5521 an alternative encoding is selected by `select-safe-coding-system', which see.
5523 The variable `coding-system-for-write', if non-nil, overrides this variable.
5525 This variable is never applied to a way of decoding a file while reading it. */);
5527 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
5529 doc
: /* *Non-nil means lines in the buffer are displayed right to left. */);
5531 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
5532 doc
: /* *Non-nil means do not display continuation lines.
5533 Instead, give each line of text just one screen line.
5535 Note that this is overridden by the variable
5536 `truncate-partial-width-windows' if that variable is non-nil
5537 and this buffer is not full-frame width. */);
5540 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
5542 doc
: /* Non-nil if the visited file is a binary file.
5543 This variable is meaningful on MS-DOG and Windows NT.
5544 On those systems, it is automatically local in every buffer.
5545 On other systems, this variable is normally always nil. */);
5548 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
5549 make_number (Lisp_String
),
5550 doc
: /* Name of default directory of current buffer. Should end with slash.
5551 To interactively change the default directory, use command `cd'. */);
5553 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
5555 doc
: /* Function called (if non-nil) to perform auto-fill.
5556 It is called after self-inserting any character specified in
5557 the `auto-fill-chars' table.
5558 NOTE: This variable is not a hook;
5559 its value may not be a list of functions. */);
5561 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
5562 make_number (Lisp_String
),
5563 doc
: /* Name of file visited in current buffer, or nil if not visiting a file. */);
5565 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
5566 make_number (Lisp_String
),
5567 doc
: /* Abbreviated truename of file visited in current buffer, or nil if none.
5568 The truename of a file is calculated by `file-truename'
5569 and then abbreviated with `abbreviate-file-name'. */);
5571 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
5572 ¤t_buffer
->auto_save_file_name
,
5573 make_number (Lisp_String
),
5574 doc
: /* Name of file for auto-saving current buffer.
5575 If it is nil, that means don't auto-save this buffer. */);
5577 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
5578 doc
: /* Non-nil if this buffer is read-only. */);
5580 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
5581 doc
: /* Non-nil if this buffer's file has been backed up.
5582 Backing up is done before the first time the file is saved. */);
5584 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
5585 make_number (Lisp_Int
),
5586 doc
: /* Length of current buffer when last read in, saved or auto-saved.
5589 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
5591 doc
: /* Non-nil enables selective display.
5592 An Integer N as value means display only lines
5593 that start with less than n columns of space.
5594 A value of t means that the character ^M makes itself and
5595 all the rest of the line invisible; also, when saving the buffer
5596 in a file, save the ^M as a newline. */);
5599 DEFVAR_PER_BUFFER ("selective-display-ellipses",
5600 ¤t_buffer
->selective_display_ellipses
,
5602 doc
: /* Non-nil means display ... on previous line when a line is invisible. */);
5605 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
5606 doc
: /* Non-nil if self-insertion should replace existing text.
5607 The value should be one of `overwrite-mode-textual',
5608 `overwrite-mode-binary', or nil.
5609 If it is `overwrite-mode-textual', self-insertion still
5610 inserts at the end of a line, and inserts when point is before a tab,
5611 until the tab is filled in.
5612 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too. */);
5614 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
5616 doc
: /* Display table that controls display of the contents of current buffer.
5618 If this variable is nil, the value of `standard-display-table' is used.
5619 Each window can have its own, overriding display table, see
5620 `set-window-display-table' and `window-display-table'.
5622 The display table is a char-table created with `make-display-table'.
5623 A char-table is an array indexed by character codes. Normal array
5624 primitives `aref' and `aset' can be used to access elements of a char-table.
5626 Each of the char-table elements control how to display the corresponding
5627 text character: the element at index C in the table says how to display
5628 the character whose code is C. Each element should be a vector of
5629 characters or nil. nil means display the character in the default fashion;
5630 otherwise, the characters from the vector are delivered to the screen
5631 instead of the original character.
5633 For example, (aset buffer-display-table ?X ?Y) will cause Emacs to display
5634 a capital Y instead of each X character.
5636 In addition, a char-table has six extra slots to control the display of:
5638 the end of a truncated screen line (extra-slot 0, a single character);
5639 the end of a continued line (extra-slot 1, a single character);
5640 the escape character used to display character codes in octal
5641 (extra-slot 2, a single character);
5642 the character used as an arrow for control characters (extra-slot 3,
5643 a single character);
5644 the decoration indicating the presence of invisible lines (extra-slot 4,
5645 a vector of characters);
5646 the character used to draw the border between side-by-side windows
5647 (extra-slot 5, a single character).
5649 See also the functions `display-table-slot' and `set-display-table-slot'. */);
5651 DEFVAR_PER_BUFFER ("left-margin-width", ¤t_buffer
->left_margin_cols
,
5653 doc
: /* *Width of left marginal area for display of a buffer.
5654 A value of nil means no marginal area. */);
5656 DEFVAR_PER_BUFFER ("right-margin-width", ¤t_buffer
->right_margin_cols
,
5658 doc
: /* *Width of right marginal area for display of a buffer.
5659 A value of nil means no marginal area. */);
5661 DEFVAR_PER_BUFFER ("left-fringe-width", ¤t_buffer
->left_fringe_width
,
5663 doc
: /* *Width of this buffer's left fringe (in pixels).
5664 A value of 0 means no left fringe is shown in this buffer's window.
5665 A value of nil means to use the left fringe width from the window's frame. */);
5667 DEFVAR_PER_BUFFER ("right-fringe-width", ¤t_buffer
->right_fringe_width
,
5669 doc
: /* *Width of this buffer's right fringe (in pixels).
5670 A value of 0 means no right fringe is shown in this buffer's window.
5671 A value of nil means to use the right fringe width from the window's frame. */);
5673 DEFVAR_PER_BUFFER ("fringes-outside-margins", ¤t_buffer
->fringes_outside_margins
,
5675 doc
: /* *Non-nil means to display fringes outside display margins.
5676 A value of nil means to display fringes between margins and buffer text. */);
5678 DEFVAR_PER_BUFFER ("scroll-bar-width", ¤t_buffer
->scroll_bar_width
,
5680 doc
: /* *Width of this buffer's scroll bars in pixels.
5681 A value of nil means to use the scroll bar width from the window's frame. */);
5683 DEFVAR_PER_BUFFER ("vertical-scroll-bar", ¤t_buffer
->vertical_scroll_bar_type
,
5685 doc
: /* *Position of this buffer's vertical scroll bar.
5686 The value takes effect whenever you tell a window to display this buffer;
5687 for instance, with `set-window-buffer' or when `display-buffer' displays it.
5689 A value of `left' or `right' means put the vertical scroll bar at that side
5690 of the window; a value of nil means don't show any vertical scroll bars.
5691 A value of t (the default) means do whatever the window's frame specifies. */);
5693 DEFVAR_PER_BUFFER ("indicate-empty-lines",
5694 ¤t_buffer
->indicate_empty_lines
, Qnil
,
5695 doc
: /* *Visually indicate empty lines after the buffer end.
5696 If non-nil, a bitmap is displayed in the left fringe of a window on
5697 window-systems. */);
5699 DEFVAR_PER_BUFFER ("indicate-buffer-boundaries",
5700 ¤t_buffer
->indicate_buffer_boundaries
, Qnil
,
5701 doc
: /* *Visually indicate buffer boundaries and scrolling.
5702 If non-nil, the first and last line of the buffer are marked in the fringe
5703 of a window on window-systems with angle bitmaps, or if the window can be
5704 scrolled, the top and bottom line of the window are marked with up and down
5707 If value is a symbol `left' or `right', both angle and arrow bitmaps
5708 are displayed in the left or right fringe, resp. Any other value
5709 that doesn't look like an alist means display the angle bitmaps in
5710 the left fringe but no arrows.
5712 You can exercise more precise control by using an alist as the
5713 value. Each alist element (INDICATOR . POSITION) specifies
5714 where to show one of the indicators. INDICATOR is one of `top',
5715 `bottom', `up', `down', or t, which specifies the default position,
5716 and POSITION is one of `left', `right', or nil, meaning do not show
5719 For example, ((top . left) (t . right)) places the top angle bitmap in
5720 left fringe, the bottom angle bitmap in right fringe, and both arrow
5721 bitmaps in right fringe. To show just the angle bitmaps in the left
5722 fringe, but no arrow bitmaps, use ((top . left) (bottom . left)). */);
5724 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
5725 ¤t_buffer
->scroll_up_aggressively
, Qnil
,
5726 doc
: /* How far to scroll windows upward.
5727 If you move point off the bottom, the window scrolls automatically.
5728 This variable controls how far it scrolls. nil, the default,
5729 means scroll to center point. A fraction means scroll to put point
5730 that fraction of the window's height from the bottom of the window.
5731 When the value is 0.0, point goes at the bottom line, which in the simple
5732 case that you moved off with C-f means scrolling just one line. 1.0 means
5733 point goes at the top, so that in that simple case, the window
5734 scrolls by a full window height. Meaningful values are
5735 between 0.0 and 1.0, inclusive. */);
5737 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
5738 ¤t_buffer
->scroll_down_aggressively
, Qnil
,
5739 doc
: /* How far to scroll windows downward.
5740 If you move point off the top, the window scrolls automatically.
5741 This variable controls how far it scrolls. nil, the default,
5742 means scroll to center point. A fraction means scroll to put point
5743 that fraction of the window's height from the top of the window.
5744 When the value is 0.0, point goes at the top line, which in the simple
5745 case that you moved off with C-b means scrolling just one line. 1.0 means
5746 point goes at the bottom, so that in that simple case, the window
5747 scrolls by a full window height. Meaningful values are
5748 between 0.0 and 1.0, inclusive. */);
5750 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
5754 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
5755 doc
: /* List of functions to call before each text change.
5756 Two arguments are passed to each function: the positions of
5757 the beginning and end of the range of old text to be changed.
5758 \(For an insertion, the beginning and end are at the same place.)
5759 No information is given about the length of the text after the change.
5761 Buffer changes made while executing the `before-change-functions'
5762 don't call any before-change or after-change functions.
5763 That's because these variables are temporarily set to nil.
5764 As a result, a hook function cannot straightforwardly alter the value of
5765 these variables. See the Emacs Lisp manual for a way of
5766 accomplishing an equivalent result by using other variables.
5768 If an unhandled error happens in running these functions,
5769 the variable's value remains nil. That prevents the error
5770 from happening repeatedly and making Emacs nonfunctional. */);
5771 Vbefore_change_functions
= Qnil
;
5773 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
5774 doc
: /* List of functions to call after each text change.
5775 Three arguments are passed to each function: the positions of
5776 the beginning and end of the range of changed text,
5777 and the length in bytes of the pre-change text replaced by that range.
5778 \(For an insertion, the pre-change length is zero;
5779 for a deletion, that length is the number of bytes deleted,
5780 and the post-change beginning and end are at the same place.)
5782 Buffer changes made while executing the `after-change-functions'
5783 don't call any before-change or after-change functions.
5784 That's because these variables are temporarily set to nil.
5785 As a result, a hook function cannot straightforwardly alter the value of
5786 these variables. See the Emacs Lisp manual for a way of
5787 accomplishing an equivalent result by using other variables.
5789 If an unhandled error happens in running these functions,
5790 the variable's value remains nil. That prevents the error
5791 from happening repeatedly and making Emacs nonfunctional. */);
5792 Vafter_change_functions
= Qnil
;
5794 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
5795 doc
: /* A list of functions to call before changing a buffer which is unmodified.
5796 The functions are run using the `run-hooks' function. */);
5797 Vfirst_change_hook
= Qnil
;
5799 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
5800 doc
: /* List of undo entries in current buffer.
5801 Recent changes come first; older changes follow newer.
5803 An entry (BEG . END) represents an insertion which begins at
5804 position BEG and ends at position END.
5806 An entry (TEXT . POSITION) represents the deletion of the string TEXT
5807 from (abs POSITION). If POSITION is positive, point was at the front
5808 of the text being deleted; if negative, point was at the end.
5810 An entry (t HIGH . LOW) indicates that the buffer previously had
5811 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions
5812 of the visited file's modification time, as of that time. If the
5813 modification time of the most recent save is different, this entry is
5816 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property
5817 was modified between BEG and END. PROPERTY is the property name,
5818 and VALUE is the old value.
5820 An entry (apply FUN-NAME . ARGS) means undo the change with
5821 \(apply FUN-NAME ARGS).
5823 An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo
5824 in the active region. BEG and END is the range affected by this entry
5825 and DELTA is the number of bytes added or deleted in that range by
5828 An entry (MARKER . DISTANCE) indicates that the marker MARKER
5829 was adjusted in position by the offset DISTANCE (an integer).
5831 An entry of the form POSITION indicates that point was at the buffer
5832 location given by the integer. Undoing an entry of this form places
5835 nil marks undo boundaries. The undo command treats the changes
5836 between two undo boundaries as a single step to be undone.
5838 If the value of the variable is t, undo information is not recorded. */);
5840 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
5841 doc
: /* Non-nil means the mark and region are currently active in this buffer. */);
5843 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
5844 doc
: /* Non-nil means that Emacs should use caches to handle long lines more quickly.
5846 Normally, the line-motion functions work by scanning the buffer for
5847 newlines. Columnar operations (like `move-to-column' and
5848 `compute-motion') also work by scanning the buffer, summing character
5849 widths as they go. This works well for ordinary text, but if the
5850 buffer's lines are very long (say, more than 500 characters), these
5851 motion functions will take longer to execute. Emacs may also take
5852 longer to update the display.
5854 If `cache-long-line-scans' is non-nil, these motion functions cache the
5855 results of their scans, and consult the cache to avoid rescanning
5856 regions of the buffer until the text is modified. The caches are most
5857 beneficial when they prevent the most searching---that is, when the
5858 buffer contains long lines and large regions of characters with the
5859 same, fixed screen width.
5861 When `cache-long-line-scans' is non-nil, processing short lines will
5862 become slightly slower (because of the overhead of consulting the
5863 cache), and the caches will use memory roughly proportional to the
5864 number of newlines and characters whose screen width varies.
5866 The caches require no explicit maintenance; their accuracy is
5867 maintained internally by the Emacs primitives. Enabling or disabling
5868 the cache should not affect the behavior of any of the motion
5869 functions; it should only affect their performance. */);
5871 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
5872 doc
: /* Value of point before the last series of scroll operations, or nil. */);
5874 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
5875 doc
: /* List of formats to use when saving this buffer.
5876 Formats are defined by `format-alist'. This variable is
5877 set when a file is visited. */);
5879 DEFVAR_PER_BUFFER ("buffer-auto-save-file-format",
5880 ¤t_buffer
->auto_save_file_format
, Qnil
,
5881 doc
: /* *Format in which to write auto-save files.
5882 Should be a list of symbols naming formats that are defined in `format-alist'.
5883 If it is t, which is the default, auto-save files are written in the
5884 same format as a regular save would use. */);
5886 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
5887 ¤t_buffer
->invisibility_spec
, Qnil
,
5888 doc
: /* Invisibility spec of this buffer.
5889 The default is t, which means that text is invisible
5890 if it has a non-nil `invisible' property.
5891 If the value is a list, a text character is invisible if its `invisible'
5892 property is an element in that list.
5893 If an element is a cons cell of the form (PROP . ELLIPSIS),
5894 then characters with property value PROP are invisible,
5895 and they have an ellipsis as well if ELLIPSIS is non-nil. */);
5897 DEFVAR_PER_BUFFER ("buffer-display-count",
5898 ¤t_buffer
->display_count
, Qnil
,
5899 doc
: /* A number incremented each time this buffer is displayed in a window.
5900 The function `set-window-buffer' increments it. */);
5902 DEFVAR_PER_BUFFER ("buffer-display-time",
5903 ¤t_buffer
->display_time
, Qnil
,
5904 doc
: /* Time stamp updated each time this buffer is displayed in a window.
5905 The function `set-window-buffer' updates this variable
5906 to the value obtained by calling `current-time'.
5907 If the buffer has never been shown in a window, the value is nil. */);
5909 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
5910 doc
: /* *Non-nil means deactivate the mark when the buffer contents change.
5911 Non-nil also enables highlighting of the region whenever the mark is active.
5912 The variable `highlight-nonselected-windows' controls whether to highlight
5913 all windows or just the selected window.
5915 If the value is `lambda', that enables Transient Mark mode temporarily
5916 until the next buffer modification. If a command sets the value to `only',
5917 that enables Transient Mark mode for the following command only.
5918 During that following command, the value of `transient-mark-mode'
5919 is `identity'. If it is still `identity' at the end of that command,
5920 it changes to nil. */);
5921 Vtransient_mark_mode
= Qnil
;
5923 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
5924 doc
: /* *Non-nil means disregard read-only status of buffers or characters.
5925 If the value is t, disregard `buffer-read-only' and all `read-only'
5926 text properties. If the value is a list, disregard `buffer-read-only'
5927 and disregard a `read-only' text property if the property value
5928 is a member of the list. */);
5929 Vinhibit_read_only
= Qnil
;
5931 DEFVAR_PER_BUFFER ("cursor-type", ¤t_buffer
->cursor_type
, Qnil
,
5932 doc
: /* Cursor to use when this buffer is in the selected window.
5933 Values are interpreted as follows:
5935 t use the cursor specified for the frame
5936 nil don't display a cursor
5937 box display a filled box cursor
5938 hollow display a hollow box cursor
5939 bar display a vertical bar cursor with default width
5940 (bar . WIDTH) display a vertical bar cursor with width WIDTH
5941 hbar display a horizontal bar cursor with default height
5942 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
5943 ANYTHING ELSE display a hollow box cursor
5945 When the buffer is displayed in a nonselected window,
5946 this variable has no effect; the cursor appears as a hollow box. */);
5948 DEFVAR_PER_BUFFER ("line-spacing",
5949 ¤t_buffer
->extra_line_spacing
, Qnil
,
5950 doc
: /* Additional space to put between lines when displaying a buffer.
5951 The space is measured in pixels, and put below lines on window systems.
5952 If value is a floating point number, it specifies the spacing relative
5953 to the default frame line height. */);
5955 DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
5956 ¤t_buffer
->cursor_in_non_selected_windows
, Qnil
,
5957 doc
: /* *Cursor type to display in non-selected windows.
5958 t means to use hollow box cursor. See `cursor-type' for other values. */);
5960 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
5961 doc
: /* List of functions called with no args to query before killing a buffer. */);
5962 Vkill_buffer_query_functions
= Qnil
;
5964 defsubr (&Sbuffer_live_p
);
5965 defsubr (&Sbuffer_list
);
5966 defsubr (&Sget_buffer
);
5967 defsubr (&Sget_file_buffer
);
5968 defsubr (&Sget_buffer_create
);
5969 defsubr (&Smake_indirect_buffer
);
5970 defsubr (&Sgenerate_new_buffer_name
);
5971 defsubr (&Sbuffer_name
);
5972 /*defsubr (&Sbuffer_number);*/
5973 defsubr (&Sbuffer_file_name
);
5974 defsubr (&Sbuffer_base_buffer
);
5975 defsubr (&Sbuffer_local_value
);
5976 defsubr (&Sbuffer_local_variables
);
5977 defsubr (&Sbuffer_modified_p
);
5978 defsubr (&Sset_buffer_modified_p
);
5979 defsubr (&Sbuffer_modified_tick
);
5980 defsubr (&Srename_buffer
);
5981 defsubr (&Sother_buffer
);
5982 defsubr (&Sbuffer_enable_undo
);
5983 defsubr (&Skill_buffer
);
5984 defsubr (&Sset_buffer_major_mode
);
5985 defsubr (&Sswitch_to_buffer
);
5986 defsubr (&Spop_to_buffer
);
5987 defsubr (&Scurrent_buffer
);
5988 defsubr (&Sset_buffer
);
5989 defsubr (&Sbarf_if_buffer_read_only
);
5990 defsubr (&Sbury_buffer
);
5991 defsubr (&Serase_buffer
);
5992 defsubr (&Sset_buffer_multibyte
);
5993 defsubr (&Skill_all_local_variables
);
5995 defsubr (&Soverlayp
);
5996 defsubr (&Smake_overlay
);
5997 defsubr (&Sdelete_overlay
);
5998 defsubr (&Smove_overlay
);
5999 defsubr (&Soverlay_start
);
6000 defsubr (&Soverlay_end
);
6001 defsubr (&Soverlay_buffer
);
6002 defsubr (&Soverlay_properties
);
6003 defsubr (&Soverlays_at
);
6004 defsubr (&Soverlays_in
);
6005 defsubr (&Snext_overlay_change
);
6006 defsubr (&Sprevious_overlay_change
);
6007 defsubr (&Soverlay_recenter
);
6008 defsubr (&Soverlay_lists
);
6009 defsubr (&Soverlay_get
);
6010 defsubr (&Soverlay_put
);
6011 defsubr (&Srestore_buffer_modified_p
);
6017 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
6018 initial_define_key (control_x_map
, 'k', "kill-buffer");
6020 /* This must not be in syms_of_buffer, because Qdisabled is not
6021 initialized when that function gets called. */
6022 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);
6025 /* arch-tag: e48569bf-69a9-4b65-a23b-8e68769436e1
6026 (do not change this comment) */