1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994,
3 1995, 1997, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007, 2008
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
26 #include <sys/types.h>
28 #include <sys/param.h>
42 #include "intervals.h"
47 #include "region-cache.h"
49 #include "blockinput.h"
54 struct buffer
*current_buffer
; /* the current buffer */
56 /* First buffer in chain of all buffers (in reverse order of creation).
57 Threaded through ->next. */
59 struct buffer
*all_buffers
;
61 /* This structure holds the default values of the buffer-local variables
62 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
63 The default value occupies the same slot in this structure
64 as an individual buffer's value occupies in that buffer.
65 Setting the default value also goes through the alist of buffers
66 and stores into each buffer that does not say it has a local value. */
68 DECL_ALIGN (struct buffer
, buffer_defaults
);
70 /* A Lisp_Object pointer to the above, used for staticpro */
72 static Lisp_Object Vbuffer_defaults
;
74 /* This structure marks which slots in a buffer have corresponding
75 default values in buffer_defaults.
76 Each such slot has a nonzero value in this structure.
77 The value has only one nonzero bit.
79 When a buffer has its own local value for a slot,
80 the entry for that slot (found in the same slot in this structure)
81 is turned on in the buffer's local_flags array.
83 If a slot in this structure is -1, then even though there may
84 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
85 and the corresponding slot in buffer_defaults is not used.
87 If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
88 but there is a default value which is copied into each buffer.
90 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
91 zero, that is a bug */
93 struct buffer buffer_local_flags
;
95 /* This structure holds the names of symbols whose values may be
96 buffer-local. It is indexed and accessed in the same way as the above. */
98 DECL_ALIGN (struct buffer
, buffer_local_symbols
);
100 /* A Lisp_Object pointer to the above, used for staticpro */
101 static Lisp_Object Vbuffer_local_symbols
;
103 /* Flags indicating which built-in buffer-local variables
104 are permanent locals. */
105 static char buffer_permanent_local_flags
[MAX_PER_BUFFER_VARS
];
107 /* Number of per-buffer variables used. */
109 int last_per_buffer_idx
;
111 EXFUN (Fset_buffer
, 1);
112 void set_buffer_internal
P_ ((struct buffer
*b
));
113 void set_buffer_internal_1
P_ ((struct buffer
*b
));
114 static void call_overlay_mod_hooks
P_ ((Lisp_Object list
, Lisp_Object overlay
,
115 int after
, Lisp_Object arg1
,
116 Lisp_Object arg2
, Lisp_Object arg3
));
117 static void swap_out_buffer_local_variables
P_ ((struct buffer
*b
));
118 static void reset_buffer_local_variables
P_ ((struct buffer
*b
, int permanent_too
));
120 /* Alist of all buffer names vs the buffers. */
121 /* This used to be a variable, but is no longer,
122 to prevent lossage due to user rplac'ing this alist or its elements. */
123 Lisp_Object Vbuffer_alist
;
125 /* Functions to call before and after each text change. */
126 Lisp_Object Vbefore_change_functions
;
127 Lisp_Object Vafter_change_functions
;
129 Lisp_Object Vtransient_mark_mode
;
131 /* t means ignore all read-only text properties.
132 A list means ignore such a property if its value is a member of the list.
133 Any non-nil value means ignore buffer-read-only. */
134 Lisp_Object Vinhibit_read_only
;
136 /* List of functions to call that can query about killing a buffer.
137 If any of these functions returns nil, we don't kill it. */
138 Lisp_Object Vkill_buffer_query_functions
;
139 Lisp_Object Qkill_buffer_query_functions
;
141 /* Hook run before changing a major mode. */
142 Lisp_Object Vchange_major_mode_hook
, Qchange_major_mode_hook
;
144 /* List of functions to call before changing an unmodified buffer. */
145 Lisp_Object Vfirst_change_hook
;
147 Lisp_Object Qfirst_change_hook
;
148 Lisp_Object Qbefore_change_functions
;
149 Lisp_Object Qafter_change_functions
;
150 Lisp_Object Qucs_set_table_for_input
;
152 /* If nonzero, all modification hooks are suppressed. */
153 int inhibit_modification_hooks
;
155 Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
157 Lisp_Object Qprotected_field
;
159 Lisp_Object QSFundamental
; /* A string "Fundamental" */
161 Lisp_Object Qkill_buffer_hook
;
163 Lisp_Object Qget_file_buffer
;
165 Lisp_Object Qoverlayp
;
167 Lisp_Object Qpriority
, Qwindow
, Qevaporate
, Qbefore_string
, Qafter_string
;
169 Lisp_Object Qmodification_hooks
;
170 Lisp_Object Qinsert_in_front_hooks
;
171 Lisp_Object Qinsert_behind_hooks
;
173 static void alloc_buffer_text
P_ ((struct buffer
*, size_t));
174 static void free_buffer_text
P_ ((struct buffer
*b
));
175 static struct Lisp_Overlay
* copy_overlays
P_ ((struct buffer
*, struct Lisp_Overlay
*));
176 static void modify_overlay
P_ ((struct buffer
*, EMACS_INT
, EMACS_INT
));
177 static Lisp_Object buffer_lisp_local_variables
P_ ((struct buffer
*));
180 /* For debugging; temporary. See set_buffer_internal. */
181 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
188 error ("No buffer named %s", SDATA (spec
));
189 error ("Invalid buffer argument");
192 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
193 doc
: /* Return non-nil if OBJECT is a buffer which has not been killed.
194 Value is nil if OBJECT is not a buffer or if it has been killed. */)
198 return ((BUFFERP (object
) && ! NILP (XBUFFER (object
)->name
))
202 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
203 doc
: /* Return a list of all existing live buffers.
204 If the optional arg FRAME is a frame, we return the buffer list
205 in the proper order for that frame: the buffers in FRAME's `buffer-list'
206 frame parameter come first, followed by the rest of the buffers. */)
211 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
215 Lisp_Object framelist
, prevlist
, tail
;
220 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
221 prevlist
= Fnreverse (Fcopy_sequence (XFRAME (frame
)->buried_buffer_list
));
223 /* Remove from GENERAL any buffer that duplicates one in
224 FRAMELIST or PREVLIST. */
228 general
= Fdelq (XCAR (tail
), general
);
234 general
= Fdelq (XCAR (tail
), general
);
241 return Fnconc (3, args
);
247 /* Like Fassoc, but use Fstring_equal to compare
248 (which ignores text properties),
249 and don't ever QUIT. */
252 assoc_ignore_text_properties (key
, list
)
253 register Lisp_Object key
;
256 register Lisp_Object tail
;
257 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
259 register Lisp_Object elt
, tem
;
261 tem
= Fstring_equal (Fcar (elt
), key
);
268 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
269 doc
: /* Return the buffer named NAME (a string).
270 If there is no live buffer named NAME, return nil.
271 NAME may also be a buffer; if so, the value is that buffer. */)
273 register Lisp_Object name
;
279 return Fcdr (assoc_ignore_text_properties (name
, Vbuffer_alist
));
282 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
283 doc
: /* Return the buffer visiting file FILENAME (a string).
284 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.
285 If there is no such live buffer, return nil.
286 See also `find-buffer-visiting'. */)
288 register Lisp_Object filename
;
290 register Lisp_Object tail
, buf
, tem
;
293 CHECK_STRING (filename
);
294 filename
= Fexpand_file_name (filename
, Qnil
);
296 /* If the file name has special constructs in it,
297 call the corresponding file handler. */
298 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
300 return call2 (handler
, Qget_file_buffer
, filename
);
302 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
304 buf
= Fcdr (XCAR (tail
));
305 if (!BUFFERP (buf
)) continue;
306 if (!STRINGP (XBUFFER (buf
)->filename
)) continue;
307 tem
= Fstring_equal (XBUFFER (buf
)->filename
, filename
);
315 get_truename_buffer (filename
)
316 register Lisp_Object filename
;
318 register Lisp_Object tail
, buf
, tem
;
320 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
322 buf
= Fcdr (XCAR (tail
));
323 if (!BUFFERP (buf
)) continue;
324 if (!STRINGP (XBUFFER (buf
)->file_truename
)) continue;
325 tem
= Fstring_equal (XBUFFER (buf
)->file_truename
, filename
);
332 /* Incremented for each buffer created, to assign the buffer number. */
335 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
336 doc
: /* Return the buffer named NAME, or create such a buffer and return it.
337 A new buffer is created if there is no live buffer named NAME.
338 If NAME starts with a space, the new buffer does not keep undo information.
339 If NAME is a buffer instead of a string, then it is the value returned.
340 The value is never nil. */)
342 register Lisp_Object name
;
344 register Lisp_Object buf
;
345 register struct buffer
*b
;
347 buf
= Fget_buffer (name
);
351 if (SCHARS (name
) == 0)
352 error ("Empty string for buffer name is not allowed");
354 b
= allocate_buffer ();
356 /* An ordinary buffer uses its own struct buffer_text. */
357 b
->text
= &b
->own_text
;
360 BUF_GAP_SIZE (b
) = 20;
362 /* We allocate extra 1-byte at the tail and keep it always '\0' for
363 anchoring a search. */
364 alloc_buffer_text (b
, BUF_GAP_SIZE (b
) + 1);
366 if (! BUF_BEG_ADDR (b
))
367 buffer_memory_full ();
374 BUF_PT_BYTE (b
) = BEG_BYTE
;
375 BUF_GPT_BYTE (b
) = BEG_BYTE
;
376 BUF_BEGV_BYTE (b
) = BEG_BYTE
;
377 BUF_ZV_BYTE (b
) = BEG_BYTE
;
378 BUF_Z_BYTE (b
) = BEG_BYTE
;
380 BUF_CHARS_MODIFF (b
) = 1;
381 BUF_OVERLAY_MODIFF (b
) = 1;
382 BUF_SAVE_MODIFF (b
) = 1;
383 BUF_INTERVALS (b
) = 0;
384 BUF_UNCHANGED_MODIFIED (b
) = 1;
385 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = 1;
386 BUF_END_UNCHANGED (b
) = 0;
387 BUF_BEG_UNCHANGED (b
) = 0;
388 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
390 b
->newline_cache
= 0;
391 b
->width_run_cache
= 0;
392 b
->width_table
= Qnil
;
393 b
->prevent_redisplay_optimizations_p
= 1;
395 /* Put this on the chain of all buffers including killed ones. */
396 b
->next
= all_buffers
;
399 /* An ordinary buffer normally doesn't need markers
400 to handle BEGV and ZV. */
402 b
->begv_marker
= Qnil
;
405 name
= Fcopy_sequence (name
);
406 STRING_SET_INTERVALS (name
, NULL_INTERVAL
);
409 b
->undo_list
= (SREF (name
, 0) != ' ') ? Qnil
: Qt
;
412 reset_buffer_local_variables (b
, 1);
414 b
->mark
= Fmake_marker ();
415 BUF_MARKERS (b
) = NULL
;
418 /* Put this in the alist of all live buffers. */
420 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
422 /* An error in calling the function here (should someone redefine it)
423 can lead to infinite regress until you run out of stack. rms
424 says that's not worth protecting against. */
425 if (!NILP (Ffboundp (Qucs_set_table_for_input
)))
426 /* buf is on buffer-alist, so no gcpro. */
427 call1 (Qucs_set_table_for_input
, buf
);
433 /* Return a list of overlays which is a copy of the overlay list
434 LIST, but for buffer B. */
436 static struct Lisp_Overlay
*
437 copy_overlays (b
, list
)
439 struct Lisp_Overlay
*list
;
442 struct Lisp_Overlay
*result
= NULL
, *tail
= NULL
;
444 XSETBUFFER (buffer
, b
);
446 for (; list
; list
= list
->next
)
448 Lisp_Object overlay
, start
, end
, old_overlay
;
451 XSETMISC (old_overlay
, list
);
452 charpos
= marker_position (OVERLAY_START (old_overlay
));
453 start
= Fmake_marker ();
454 Fset_marker (start
, make_number (charpos
), buffer
);
455 XMARKER (start
)->insertion_type
456 = XMARKER (OVERLAY_START (old_overlay
))->insertion_type
;
458 charpos
= marker_position (OVERLAY_END (old_overlay
));
459 end
= Fmake_marker ();
460 Fset_marker (end
, make_number (charpos
), buffer
);
461 XMARKER (end
)->insertion_type
462 = XMARKER (OVERLAY_END (old_overlay
))->insertion_type
;
464 overlay
= allocate_misc ();
465 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
466 OVERLAY_START (overlay
) = start
;
467 OVERLAY_END (overlay
) = end
;
468 OVERLAY_PLIST (overlay
) = Fcopy_sequence (OVERLAY_PLIST (old_overlay
));
469 XOVERLAY (overlay
)->next
= NULL
;
472 tail
= tail
->next
= XOVERLAY (overlay
);
474 result
= tail
= XOVERLAY (overlay
);
481 /* Clone per-buffer values of buffer FROM.
483 Buffer TO gets the same per-buffer values as FROM, with the
484 following exceptions: (1) TO's name is left untouched, (2) markers
485 are copied and made to refer to TO, and (3) overlay lists are
489 clone_per_buffer_values (from
, to
)
490 struct buffer
*from
, *to
;
492 Lisp_Object to_buffer
;
495 XSETBUFFER (to_buffer
, to
);
497 for (offset
= PER_BUFFER_VAR_OFFSET (name
) + sizeof (Lisp_Object
);
499 offset
+= sizeof (Lisp_Object
))
503 obj
= PER_BUFFER_VALUE (from
, offset
);
506 struct Lisp_Marker
*m
= XMARKER (obj
);
507 obj
= Fmake_marker ();
508 XMARKER (obj
)->insertion_type
= m
->insertion_type
;
509 set_marker_both (obj
, to_buffer
, m
->charpos
, m
->bytepos
);
512 PER_BUFFER_VALUE (to
, offset
) = obj
;
515 bcopy (from
->local_flags
, to
->local_flags
, sizeof to
->local_flags
);
517 to
->overlays_before
= copy_overlays (to
, from
->overlays_before
);
518 to
->overlays_after
= copy_overlays (to
, from
->overlays_after
);
520 /* Get (a copy of) the alist of Lisp-level local variables of FROM
521 and install that in TO. */
522 to
->local_var_alist
= buffer_lisp_local_variables (from
);
525 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
,
527 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
528 doc
: /* Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.
529 BASE-BUFFER should be a live buffer, or the name of an existing buffer.
530 NAME should be a string which is not the name of an existing buffer.
531 Optional argument CLONE non-nil means preserve BASE-BUFFER's state,
532 such as major and minor modes, in the indirect buffer.
533 CLONE nil means the indirect buffer's state is reset to default values. */)
534 (base_buffer
, name
, clone
)
535 Lisp_Object base_buffer
, name
, clone
;
537 Lisp_Object buf
, tem
;
541 buf
= Fget_buffer (name
);
543 error ("Buffer name `%s' is in use", SDATA (name
));
546 base_buffer
= Fget_buffer (base_buffer
);
547 if (NILP (base_buffer
))
548 error ("No such buffer: `%s'", SDATA (tem
));
549 if (NILP (XBUFFER (base_buffer
)->name
))
550 error ("Base buffer has been killed");
552 if (SCHARS (name
) == 0)
553 error ("Empty string for buffer name is not allowed");
555 b
= allocate_buffer ();
557 b
->base_buffer
= (XBUFFER (base_buffer
)->base_buffer
558 ? XBUFFER (base_buffer
)->base_buffer
559 : XBUFFER (base_buffer
));
561 /* Use the base buffer's text object. */
562 b
->text
= b
->base_buffer
->text
;
564 BUF_BEGV (b
) = BUF_BEGV (b
->base_buffer
);
565 BUF_ZV (b
) = BUF_ZV (b
->base_buffer
);
566 BUF_PT (b
) = BUF_PT (b
->base_buffer
);
567 BUF_BEGV_BYTE (b
) = BUF_BEGV_BYTE (b
->base_buffer
);
568 BUF_ZV_BYTE (b
) = BUF_ZV_BYTE (b
->base_buffer
);
569 BUF_PT_BYTE (b
) = BUF_PT_BYTE (b
->base_buffer
);
571 b
->newline_cache
= 0;
572 b
->width_run_cache
= 0;
573 b
->width_table
= Qnil
;
575 /* Put this on the chain of all buffers including killed ones. */
576 b
->next
= all_buffers
;
579 name
= Fcopy_sequence (name
);
580 STRING_SET_INTERVALS (name
, NULL_INTERVAL
);
584 reset_buffer_local_variables (b
, 1);
586 /* Put this in the alist of all live buffers. */
588 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
590 b
->mark
= Fmake_marker ();
593 /* The multibyte status belongs to the base buffer. */
594 b
->enable_multibyte_characters
= b
->base_buffer
->enable_multibyte_characters
;
596 /* Make sure the base buffer has markers for its narrowing. */
597 if (NILP (b
->base_buffer
->pt_marker
))
599 b
->base_buffer
->pt_marker
= Fmake_marker ();
600 set_marker_both (b
->base_buffer
->pt_marker
, base_buffer
,
601 BUF_PT (b
->base_buffer
),
602 BUF_PT_BYTE (b
->base_buffer
));
604 if (NILP (b
->base_buffer
->begv_marker
))
606 b
->base_buffer
->begv_marker
= Fmake_marker ();
607 set_marker_both (b
->base_buffer
->begv_marker
, base_buffer
,
608 BUF_BEGV (b
->base_buffer
),
609 BUF_BEGV_BYTE (b
->base_buffer
));
611 if (NILP (b
->base_buffer
->zv_marker
))
613 b
->base_buffer
->zv_marker
= Fmake_marker ();
614 set_marker_both (b
->base_buffer
->zv_marker
, base_buffer
,
615 BUF_ZV (b
->base_buffer
),
616 BUF_ZV_BYTE (b
->base_buffer
));
617 XMARKER (b
->base_buffer
->zv_marker
)->insertion_type
= 1;
622 /* Give the indirect buffer markers for its narrowing. */
623 b
->pt_marker
= Fmake_marker ();
624 set_marker_both (b
->pt_marker
, buf
, BUF_PT (b
), BUF_PT_BYTE (b
));
625 b
->begv_marker
= Fmake_marker ();
626 set_marker_both (b
->begv_marker
, buf
, BUF_BEGV (b
), BUF_BEGV_BYTE (b
));
627 b
->zv_marker
= Fmake_marker ();
628 set_marker_both (b
->zv_marker
, buf
, BUF_ZV (b
), BUF_ZV_BYTE (b
));
629 XMARKER (b
->zv_marker
)->insertion_type
= 1;
633 struct buffer
*old_b
= current_buffer
;
635 clone_per_buffer_values (b
->base_buffer
, b
);
637 b
->file_truename
= Qnil
;
638 b
->display_count
= make_number (0);
640 b
->auto_save_file_name
= Qnil
;
641 set_buffer_internal_1 (b
);
642 Fset (intern ("buffer-save-without-query"), Qnil
);
643 Fset (intern ("buffer-file-number"), Qnil
);
644 Fset (intern ("buffer-stale-function"), Qnil
);
645 set_buffer_internal_1 (old_b
);
652 delete_all_overlays (b
)
657 /* `reset_buffer' blindly sets the list of overlays to NULL, so we
658 have to empty the list, otherwise we end up with overlays that
659 think they belong to this buffer while the buffer doesn't know about
661 while (b
->overlays_before
)
663 XSETMISC (overlay
, b
->overlays_before
);
664 Fdelete_overlay (overlay
);
666 while (b
->overlays_after
)
668 XSETMISC (overlay
, b
->overlays_after
);
669 Fdelete_overlay (overlay
);
671 eassert (b
->overlays_before
== NULL
);
672 eassert (b
->overlays_after
== NULL
);
675 /* Reinitialize everything about a buffer except its name and contents
677 If called on an already-initialized buffer, the list of overlays
678 should be deleted before calling this function, otherwise we end up
679 with overlays that claim to belong to the buffer but the buffer
680 claims it doesn't belong to it. */
684 register struct buffer
*b
;
687 b
->file_truename
= Qnil
;
688 b
->directory
= (current_buffer
) ? current_buffer
->directory
: Qnil
;
690 XSETFASTINT (b
->save_length
, 0);
691 b
->last_window_start
= 1;
692 /* It is more conservative to start out "changed" than "unchanged". */
694 b
->prevent_redisplay_optimizations_p
= 1;
696 b
->auto_save_modified
= 0;
697 b
->auto_save_failure_time
= -1;
698 b
->auto_save_file_name
= Qnil
;
700 b
->overlays_before
= NULL
;
701 b
->overlays_after
= NULL
;
702 b
->overlay_center
= BEG
;
703 b
->mark_active
= Qnil
;
704 b
->point_before_scroll
= Qnil
;
705 b
->file_format
= Qnil
;
706 b
->auto_save_file_format
= Qt
;
707 b
->last_selected_window
= Qnil
;
708 XSETINT (b
->display_count
, 0);
709 b
->display_time
= Qnil
;
710 b
->enable_multibyte_characters
= buffer_defaults
.enable_multibyte_characters
;
711 b
->cursor_type
= buffer_defaults
.cursor_type
;
712 b
->extra_line_spacing
= buffer_defaults
.extra_line_spacing
;
714 b
->display_error_modiff
= 0;
717 /* Reset buffer B's local variables info.
718 Don't use this on a buffer that has already been in use;
719 it does not treat permanent locals consistently.
720 Instead, use Fkill_all_local_variables.
722 If PERMANENT_TOO is 1, then we reset permanent
723 buffer-local variables. If PERMANENT_TOO is 0,
724 we preserve those. */
727 reset_buffer_local_variables (b
, permanent_too
)
728 register struct buffer
*b
;
734 /* Reset the major mode to Fundamental, together with all the
735 things that depend on the major mode.
736 default-major-mode is handled at a higher level.
737 We ignore it here. */
738 b
->major_mode
= Qfundamental_mode
;
740 b
->mode_name
= QSFundamental
;
741 b
->minor_modes
= Qnil
;
743 /* If the standard case table has been altered and invalidated,
744 fix up its insides first. */
745 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
746 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
747 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
748 Fset_standard_case_table (Vascii_downcase_table
);
750 b
->downcase_table
= Vascii_downcase_table
;
751 b
->upcase_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[0];
752 b
->case_canon_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[1];
753 b
->case_eqv_table
= XCHAR_TABLE (Vascii_downcase_table
)->extras
[2];
754 b
->invisibility_spec
= Qt
;
756 b
->buffer_file_type
= Qnil
;
759 /* Reset all (or most) per-buffer variables to their defaults. */
761 b
->local_var_alist
= Qnil
;
764 Lisp_Object tmp
, last
= Qnil
;
765 for (tmp
= b
->local_var_alist
; CONSP (tmp
); tmp
= XCDR (tmp
))
766 if (CONSP (XCAR (tmp
))
767 && SYMBOLP (XCAR (XCAR (tmp
)))
768 && !NILP (Fget (XCAR (XCAR (tmp
)), Qpermanent_local
)))
769 /* If permanent-local, keep it. */
771 else if (NILP (last
))
772 b
->local_var_alist
= XCDR (tmp
);
774 XSETCDR (last
, XCDR (tmp
));
777 for (i
= 0; i
< last_per_buffer_idx
; ++i
)
778 if (permanent_too
|| buffer_permanent_local_flags
[i
] == 0)
779 SET_PER_BUFFER_VALUE_P (b
, i
, 0);
781 /* For each slot that has a default value,
782 copy that into the slot. */
784 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
786 offset
+= sizeof (Lisp_Object
))
788 int idx
= PER_BUFFER_IDX (offset
);
791 || buffer_permanent_local_flags
[idx
] == 0))
792 /* Is -2 used anywhere? */
794 PER_BUFFER_VALUE (b
, offset
) = PER_BUFFER_DEFAULT (offset
);
798 /* We split this away from generate-new-buffer, because rename-buffer
799 and set-visited-file-name ought to be able to use this to really
800 rename the buffer properly. */
802 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
, Sgenerate_new_buffer_name
,
804 doc
: /* Return a string that is the name of no existing buffer based on NAME.
805 If there is no live buffer named NAME, then return NAME.
806 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
807 \(starting at 2) until an unused name is found, and then return that name.
808 Optional second argument IGNORE specifies a name that is okay to use (if
809 it is in the sequence to be tried) even if a buffer with that name exists. */)
811 register Lisp_Object name
, ignore
;
813 register Lisp_Object gentemp
, tem
;
819 tem
= Fstring_equal (name
, ignore
);
822 tem
= Fget_buffer (name
);
829 sprintf (number
, "<%d>", ++count
);
830 gentemp
= concat2 (name
, build_string (number
));
831 tem
= Fstring_equal (gentemp
, ignore
);
834 tem
= Fget_buffer (gentemp
);
841 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
842 doc
: /* Return the name of BUFFER, as a string.
843 With no argument or nil as argument, return the name of the current buffer. */)
845 register Lisp_Object buffer
;
848 return current_buffer
->name
;
849 CHECK_BUFFER (buffer
);
850 return XBUFFER (buffer
)->name
;
853 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
854 doc
: /* Return name of file BUFFER is visiting, or nil if none.
855 No argument or nil as argument means use the current buffer. */)
857 register Lisp_Object buffer
;
860 return current_buffer
->filename
;
861 CHECK_BUFFER (buffer
);
862 return XBUFFER (buffer
)->filename
;
865 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
867 doc
: /* Return the base buffer of indirect buffer BUFFER.
868 If BUFFER is not indirect, return nil.
869 BUFFER defaults to the current buffer. */)
871 register Lisp_Object buffer
;
874 Lisp_Object base_buffer
;
877 base
= current_buffer
->base_buffer
;
880 CHECK_BUFFER (buffer
);
881 base
= XBUFFER (buffer
)->base_buffer
;
886 XSETBUFFER (base_buffer
, base
);
890 DEFUN ("buffer-local-value", Fbuffer_local_value
,
891 Sbuffer_local_value
, 2, 2, 0,
892 doc
: /* Return the value of VARIABLE in BUFFER.
893 If VARIABLE does not have a buffer-local binding in BUFFER, the value
894 is the default binding of the variable. */)
896 register Lisp_Object variable
;
897 register Lisp_Object buffer
;
899 register struct buffer
*buf
;
900 register Lisp_Object result
;
902 CHECK_SYMBOL (variable
);
903 CHECK_BUFFER (buffer
);
904 buf
= XBUFFER (buffer
);
906 variable
= indirect_variable (variable
);
908 /* Look in local_var_list */
909 result
= Fassoc (variable
, buf
->local_var_alist
);
915 /* Look in special slots */
916 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
917 offset
< sizeof (struct buffer
);
918 /* sizeof EMACS_INT == sizeof Lisp_Object */
919 offset
+= (sizeof (EMACS_INT
)))
921 idx
= PER_BUFFER_IDX (offset
);
922 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
923 && SYMBOLP (PER_BUFFER_SYMBOL (offset
))
924 && EQ (PER_BUFFER_SYMBOL (offset
), variable
))
926 result
= PER_BUFFER_VALUE (buf
, offset
);
933 result
= Fdefault_value (variable
);
937 Lisp_Object valcontents
;
938 Lisp_Object current_alist_element
;
940 /* What binding is loaded right now? */
941 valcontents
= SYMBOL_VALUE (variable
);
942 current_alist_element
943 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
945 /* The value of the currently loaded binding is not
946 stored in it, but rather in the realvalue slot.
947 Store that value into the binding it belongs to
948 in case that is the one we are about to use. */
950 Fsetcdr (current_alist_element
,
951 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
953 /* Now get the (perhaps updated) value out of the binding. */
954 result
= XCDR (result
);
957 if (!EQ (result
, Qunbound
))
960 xsignal1 (Qvoid_variable
, variable
);
963 /* Return an alist of the Lisp-level buffer-local bindings of
964 buffer BUF. That is, don't include the variables maintained
965 in special slots in the buffer object. */
968 buffer_lisp_local_variables (buf
)
971 Lisp_Object result
= Qnil
;
972 register Lisp_Object tail
;
973 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
975 Lisp_Object val
, elt
;
979 /* Reference each variable in the alist in buf.
980 If inquiring about the current buffer, this gets the current values,
981 so store them into the alist so the alist is up to date.
982 If inquiring about some other buffer, this swaps out any values
983 for that buffer, making the alist up to date automatically. */
984 val
= find_symbol_value (XCAR (elt
));
985 /* Use the current buffer value only if buf is the current buffer. */
986 if (buf
!= current_buffer
)
989 /* If symbol is unbound, put just the symbol in the list. */
990 if (EQ (val
, Qunbound
))
991 result
= Fcons (XCAR (elt
), result
);
992 /* Otherwise, put (symbol . value) in the list. */
994 result
= Fcons (Fcons (XCAR (elt
), val
), result
);
1000 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
1001 Sbuffer_local_variables
, 0, 1, 0,
1002 doc
: /* Return an alist of variables that are buffer-local in BUFFER.
1003 Most elements look like (SYMBOL . VALUE), describing one variable.
1004 For a symbol that is locally unbound, just the symbol appears in the value.
1005 Note that storing new VALUEs in these elements doesn't change the variables.
1006 No argument or nil as argument means use current buffer as BUFFER. */)
1008 register Lisp_Object buffer
;
1010 register struct buffer
*buf
;
1011 register Lisp_Object result
;
1014 buf
= current_buffer
;
1017 CHECK_BUFFER (buffer
);
1018 buf
= XBUFFER (buffer
);
1021 result
= buffer_lisp_local_variables (buf
);
1023 /* Add on all the variables stored in special slots. */
1027 for (offset
= PER_BUFFER_VAR_OFFSET (name
);
1028 offset
< sizeof (struct buffer
);
1029 /* sizeof EMACS_INT == sizeof Lisp_Object */
1030 offset
+= (sizeof (EMACS_INT
)))
1032 idx
= PER_BUFFER_IDX (offset
);
1033 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
1034 && SYMBOLP (PER_BUFFER_SYMBOL (offset
)))
1035 result
= Fcons (Fcons (PER_BUFFER_SYMBOL (offset
),
1036 PER_BUFFER_VALUE (buf
, offset
)),
1044 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
1046 doc
: /* Return t if BUFFER was modified since its file was last read or saved.
1047 No argument or nil as argument means use current buffer as BUFFER. */)
1049 register Lisp_Object buffer
;
1051 register struct buffer
*buf
;
1053 buf
= current_buffer
;
1056 CHECK_BUFFER (buffer
);
1057 buf
= XBUFFER (buffer
);
1060 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
1063 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
1065 doc
: /* Mark current buffer as modified or unmodified according to FLAG.
1066 A non-nil FLAG means mark the buffer modified. */)
1068 register Lisp_Object flag
;
1070 register int already
;
1071 register Lisp_Object fn
;
1072 Lisp_Object buffer
, window
;
1074 #ifdef CLASH_DETECTION
1075 /* If buffer becoming modified, lock the file.
1076 If buffer becoming unmodified, unlock the file. */
1078 fn
= current_buffer
->file_truename
;
1079 /* Test buffer-file-name so that binding it to nil is effective. */
1080 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
1082 already
= SAVE_MODIFF
< MODIFF
;
1083 if (!already
&& !NILP (flag
))
1085 else if (already
&& NILP (flag
))
1088 #endif /* CLASH_DETECTION */
1090 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
1092 /* Set update_mode_lines only if buffer is displayed in some window.
1093 Packages like jit-lock or lazy-lock preserve a buffer's modified
1094 state by recording/restoring the state around blocks of code.
1095 Setting update_mode_lines makes redisplay consider all windows
1096 (on all frames). Stealth fontification of buffers not displayed
1097 would incur additional redisplay costs if we'd set
1098 update_modes_lines unconditionally.
1100 Ideally, I think there should be another mechanism for fontifying
1101 buffers without "modifying" buffers, or redisplay should be
1102 smarter about updating the `*' in mode lines. --gerd */
1103 XSETBUFFER (buffer
, current_buffer
);
1104 window
= Fget_buffer_window (buffer
, Qt
);
1105 if (WINDOWP (window
))
1107 ++update_mode_lines
;
1108 current_buffer
->prevent_redisplay_optimizations_p
= 1;
1114 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p
,
1115 Srestore_buffer_modified_p
, 1, 1, 0,
1116 doc
: /* Like `set-buffer-modified-p', with a difference concerning redisplay.
1117 It is not ensured that mode lines will be updated to show the modified
1118 state of the current buffer. Use with care. */)
1122 #ifdef CLASH_DETECTION
1125 /* If buffer becoming modified, lock the file.
1126 If buffer becoming unmodified, unlock the file. */
1128 fn
= current_buffer
->file_truename
;
1129 /* Test buffer-file-name so that binding it to nil is effective. */
1130 if (!NILP (fn
) && ! NILP (current_buffer
->filename
))
1132 int already
= SAVE_MODIFF
< MODIFF
;
1133 if (!already
&& !NILP (flag
))
1135 else if (already
&& NILP (flag
))
1138 #endif /* CLASH_DETECTION */
1140 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
1144 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
1146 doc
: /* Return BUFFER's tick counter, incremented for each change in text.
1147 Each buffer has a tick counter which is incremented each time the
1148 text in that buffer is changed. It wraps around occasionally.
1149 No argument or nil as argument means use current buffer as BUFFER. */)
1151 register Lisp_Object buffer
;
1153 register struct buffer
*buf
;
1155 buf
= current_buffer
;
1158 CHECK_BUFFER (buffer
);
1159 buf
= XBUFFER (buffer
);
1162 return make_number (BUF_MODIFF (buf
));
1165 DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick
,
1166 Sbuffer_chars_modified_tick
, 0, 1, 0,
1167 doc
: /* Return BUFFER's character-change tick counter.
1168 Each buffer has a character-change tick counter, which is set to the
1169 value of the buffer's tick counter \(see `buffer-modified-tick'), each
1170 time text in that buffer is inserted or deleted. By comparing the
1171 values returned by two individual calls of `buffer-chars-modified-tick',
1172 you can tell whether a character change occurred in that buffer in
1173 between these calls. No argument or nil as argument means use current
1174 buffer as BUFFER. */)
1176 register Lisp_Object buffer
;
1178 register struct buffer
*buf
;
1180 buf
= current_buffer
;
1183 CHECK_BUFFER (buffer
);
1184 buf
= XBUFFER (buffer
);
1187 return make_number (BUF_CHARS_MODIFF (buf
));
1190 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
1191 "(list (read-string \"Rename buffer (to new name): \" \
1192 nil 'buffer-name-history (buffer-name (current-buffer))) \
1193 current-prefix-arg)",
1194 doc
: /* Change current buffer's name to NEWNAME (a string).
1195 If second arg UNIQUE is nil or omitted, it is an error if a
1196 buffer named NEWNAME already exists.
1197 If UNIQUE is non-nil, come up with a new name using
1198 `generate-new-buffer-name'.
1199 Interactively, you can set UNIQUE with a prefix argument.
1200 We return the name we actually gave the buffer.
1201 This does not change the name of the visited file (if any). */)
1203 register Lisp_Object newname
, unique
;
1205 register Lisp_Object tem
, buf
;
1207 CHECK_STRING (newname
);
1209 if (SCHARS (newname
) == 0)
1210 error ("Empty string is invalid as a buffer name");
1212 tem
= Fget_buffer (newname
);
1215 /* Don't short-circuit if UNIQUE is t. That is a useful way to
1216 rename the buffer automatically so you can create another
1217 with the original name. It makes UNIQUE equivalent to
1218 (rename-buffer (generate-new-buffer-name NEWNAME)). */
1219 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
1220 return current_buffer
->name
;
1222 newname
= Fgenerate_new_buffer_name (newname
, current_buffer
->name
);
1224 error ("Buffer name `%s' is in use", SDATA (newname
));
1227 current_buffer
->name
= newname
;
1229 /* Catch redisplay's attention. Unless we do this, the mode lines for
1230 any windows displaying current_buffer will stay unchanged. */
1231 update_mode_lines
++;
1233 XSETBUFFER (buf
, current_buffer
);
1234 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
1235 if (NILP (current_buffer
->filename
)
1236 && !NILP (current_buffer
->auto_save_file_name
))
1237 call0 (intern ("rename-auto-save-file"));
1238 /* Refetch since that last call may have done GC. */
1239 return current_buffer
->name
;
1242 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 3, 0,
1243 doc
: /* Return most recently selected buffer other than BUFFER.
1244 Buffers not visible in windows are preferred to visible buffers,
1245 unless optional second argument VISIBLE-OK is non-nil.
1246 If the optional third argument FRAME is non-nil, use that frame's
1247 buffer list instead of the selected frame's buffer list.
1248 If no other buffer exists, the buffer `*scratch*' is returned.
1249 If BUFFER is omitted or nil, some interesting buffer is returned. */)
1250 (buffer
, visible_ok
, frame
)
1251 register Lisp_Object buffer
, visible_ok
, frame
;
1253 Lisp_Object
Fset_buffer_major_mode ();
1254 register Lisp_Object tail
, buf
, notsogood
, tem
, pred
, add_ons
;
1258 frame
= selected_frame
;
1260 tail
= Vbuffer_alist
;
1261 pred
= frame_buffer_predicate (frame
);
1263 /* Consider buffers that have been seen in the selected frame
1264 before other buffers. */
1266 tem
= frame_buffer_list (frame
);
1270 if (BUFFERP (XCAR (tem
)))
1271 add_ons
= Fcons (Fcons (Qnil
, XCAR (tem
)), add_ons
);
1274 tail
= nconc2 (Fnreverse (add_ons
), tail
);
1276 for (; CONSP (tail
); tail
= XCDR (tail
))
1278 buf
= Fcdr (XCAR (tail
));
1279 if (EQ (buf
, buffer
))
1283 if (NILP (XBUFFER (buf
)->name
))
1285 if (SREF (XBUFFER (buf
)->name
, 0) == ' ')
1287 /* If the selected frame has a buffer_predicate,
1288 disregard buffers that don't fit the predicate. */
1291 tem
= call1 (pred
, buf
);
1296 if (NILP (visible_ok
))
1297 tem
= Fget_buffer_window (buf
, Qvisible
);
1302 if (NILP (notsogood
))
1305 if (!NILP (notsogood
))
1307 buf
= Fget_buffer (build_string ("*scratch*"));
1310 buf
= Fget_buffer_create (build_string ("*scratch*"));
1311 Fset_buffer_major_mode (buf
);
1316 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
1318 doc
: /* Start keeping undo information for buffer BUFFER.
1319 No argument or nil as argument means do this for the current buffer. */)
1321 register Lisp_Object buffer
;
1323 Lisp_Object real_buffer
;
1326 XSETBUFFER (real_buffer
, current_buffer
);
1329 real_buffer
= Fget_buffer (buffer
);
1330 if (NILP (real_buffer
))
1334 if (EQ (XBUFFER (real_buffer
)->undo_list
, Qt
))
1335 XBUFFER (real_buffer
)->undo_list
= Qnil
;
1341 DEFVAR_LISP ("kill-buffer-hook", no_cell, "\
1342 Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1343 The buffer being killed will be current while the hook is running.\n\
1346 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 1, 1, "bKill buffer: ",
1347 doc
: /* Kill the buffer BUFFER.
1348 The argument may be a buffer or the name of a buffer.
1349 With a nil argument, kill the current buffer.
1351 Value is t if the buffer is actually killed, nil otherwise.
1353 The functions in `kill-buffer-query-functions' are called with BUFFER as
1354 the current buffer. If any of them returns nil, the buffer is not killed.
1356 The hook `kill-buffer-hook' is run before the buffer is actually killed.
1357 The buffer being killed will be current while the hook is running.
1359 Any processes that have this buffer as the `process-buffer' are killed
1365 register struct buffer
*b
;
1366 register Lisp_Object tem
;
1367 register struct Lisp_Marker
*m
;
1368 struct gcpro gcpro1
;
1371 buf
= Fcurrent_buffer ();
1373 buf
= Fget_buffer (buffer
);
1379 /* Avoid trouble for buffer already dead. */
1383 /* Query if the buffer is still modified. */
1384 if (INTERACTIVE
&& !NILP (b
->filename
)
1385 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1388 tem
= do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
1389 b
->name
, make_number (0)));
1395 /* Run hooks with the buffer to be killed the current buffer. */
1397 int count
= SPECPDL_INDEX ();
1398 Lisp_Object arglist
[1];
1400 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1401 set_buffer_internal (b
);
1403 /* First run the query functions; if any query is answered no,
1404 don't kill the buffer. */
1405 arglist
[0] = Qkill_buffer_query_functions
;
1406 tem
= Frun_hook_with_args_until_failure (1, arglist
);
1408 return unbind_to (count
, Qnil
);
1410 /* Then run the hooks. */
1411 Frun_hooks (1, &Qkill_buffer_hook
);
1412 unbind_to (count
, Qnil
);
1415 /* We have no more questions to ask. Verify that it is valid
1416 to kill the buffer. This must be done after the questions
1417 since anything can happen within do_yes_or_no_p. */
1419 /* Don't kill the minibuffer now current. */
1420 if (EQ (buf
, XWINDOW (minibuf_window
)->buffer
))
1426 /* When we kill a base buffer, kill all its indirect buffers.
1427 We do it at this stage so nothing terrible happens if they
1428 ask questions or their hooks get errors. */
1429 if (! b
->base_buffer
)
1431 struct buffer
*other
;
1435 for (other
= all_buffers
; other
; other
= other
->next
)
1436 /* all_buffers contains dead buffers too;
1437 don't re-kill them. */
1438 if (other
->base_buffer
== b
&& !NILP (other
->name
))
1441 XSETBUFFER (buf
, other
);
1448 /* Make this buffer not be current.
1449 In the process, notice if this is the sole visible buffer
1450 and give up if so. */
1451 if (b
== current_buffer
)
1453 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1455 if (b
== current_buffer
)
1459 /* Notice if the buffer to kill is the sole visible buffer
1460 when we're currently in the mini-buffer, and give up if so. */
1461 XSETBUFFER (tem
, current_buffer
);
1462 if (EQ (tem
, XWINDOW (minibuf_window
)->buffer
))
1464 tem
= Fother_buffer (buf
, Qnil
, Qnil
);
1469 /* Now there is no question: we can kill the buffer. */
1471 #ifdef CLASH_DETECTION
1472 /* Unlock this buffer's file, if it is locked. */
1474 #endif /* CLASH_DETECTION */
1477 kill_buffer_processes (buf
);
1480 /* Killing buffer processes may run sentinels which may
1481 have called kill-buffer. */
1486 clear_charpos_cache (b
);
1488 tem
= Vinhibit_quit
;
1490 replace_buffer_in_all_windows (buf
);
1491 Vbuffer_alist
= Fdelq (Frassq (buf
, Vbuffer_alist
), Vbuffer_alist
);
1492 frames_discard_buffer (buf
);
1493 Vinhibit_quit
= tem
;
1495 /* Delete any auto-save file, if we saved it in this session.
1496 But not if the buffer is modified. */
1497 if (STRINGP (b
->auto_save_file_name
)
1498 && b
->auto_save_modified
!= 0
1499 && BUF_SAVE_MODIFF (b
) < b
->auto_save_modified
1500 && BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)
1501 && NILP (Fsymbol_value (intern ("auto-save-visited-file-name"))))
1504 tem
= Fsymbol_value (intern ("delete-auto-save-files"));
1506 internal_delete_file (b
->auto_save_file_name
);
1511 /* Unchain all markers that belong to this indirect buffer.
1512 Don't unchain the markers that belong to the base buffer
1513 or its other indirect buffers. */
1514 for (m
= BUF_MARKERS (b
); m
; )
1516 struct Lisp_Marker
*next
= m
->next
;
1524 /* Unchain all markers of this buffer and its indirect buffers.
1525 and leave them pointing nowhere. */
1526 for (m
= BUF_MARKERS (b
); m
; )
1528 struct Lisp_Marker
*next
= m
->next
;
1533 BUF_MARKERS (b
) = NULL
;
1534 BUF_INTERVALS (b
) = NULL_INTERVAL
;
1536 /* Perhaps we should explicitly free the interval tree here... */
1539 /* Reset the local variables, so that this buffer's local values
1540 won't be protected from GC. They would be protected
1541 if they happened to remain encached in their symbols.
1542 This gets rid of them for certain. */
1543 swap_out_buffer_local_variables (b
);
1544 reset_buffer_local_variables (b
, 1);
1549 if (! b
->base_buffer
)
1550 free_buffer_text (b
);
1552 if (b
->newline_cache
)
1554 free_region_cache (b
->newline_cache
);
1555 b
->newline_cache
= 0;
1557 if (b
->width_run_cache
)
1559 free_region_cache (b
->width_run_cache
);
1560 b
->width_run_cache
= 0;
1562 b
->width_table
= Qnil
;
1564 b
->undo_list
= Qnil
;
1569 /* Move the assoc for buffer BUF to the front of buffer-alist. Since
1570 we do this each time BUF is selected visibly, the more recently
1571 selected buffers are always closer to the front of the list. This
1572 means that other_buffer is more likely to choose a relevant buffer. */
1578 register Lisp_Object link
, prev
;
1580 frame
= selected_frame
;
1583 for (link
= Vbuffer_alist
; CONSP (link
); link
= XCDR (link
))
1585 if (EQ (XCDR (XCAR (link
)), buf
))
1590 /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist);
1591 we cannot use Fdelq itself here because it allows quitting. */
1594 Vbuffer_alist
= XCDR (Vbuffer_alist
);
1596 XSETCDR (prev
, XCDR (XCDR (prev
)));
1598 XSETCDR (link
, Vbuffer_alist
);
1599 Vbuffer_alist
= link
;
1601 /* Effectively do a delq on buried_buffer_list. */
1604 for (link
= XFRAME (frame
)->buried_buffer_list
; CONSP (link
);
1607 if (EQ (XCAR (link
), buf
))
1610 XFRAME (frame
)->buried_buffer_list
= XCDR (link
);
1612 XSETCDR (prev
, XCDR (XCDR (prev
)));
1618 /* Now move this buffer to the front of frame_buffer_list also. */
1621 for (link
= frame_buffer_list (frame
); CONSP (link
);
1624 if (EQ (XCAR (link
), buf
))
1629 /* Effectively do delq. */
1634 set_frame_buffer_list (frame
,
1635 XCDR (frame_buffer_list (frame
)));
1637 XSETCDR (prev
, XCDR (XCDR (prev
)));
1639 XSETCDR (link
, frame_buffer_list (frame
));
1640 set_frame_buffer_list (frame
, link
);
1643 set_frame_buffer_list (frame
, Fcons (buf
, frame_buffer_list (frame
)));
1646 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1647 doc
: /* Set an appropriate major mode for BUFFER.
1648 For the *scratch* buffer, use `initial-major-mode', otherwise choose a mode
1649 according to `default-major-mode'.
1650 Use this function before selecting the buffer, since it may need to inspect
1651 the current buffer's major mode. */)
1656 Lisp_Object function
;
1658 CHECK_BUFFER (buffer
);
1660 if (STRINGP (XBUFFER (buffer
)->name
)
1661 && strcmp (SDATA (XBUFFER (buffer
)->name
), "*scratch*") == 0)
1662 function
= find_symbol_value (intern ("initial-major-mode"));
1665 function
= buffer_defaults
.major_mode
;
1667 && NILP (Fget (current_buffer
->major_mode
, Qmode_class
)))
1668 function
= current_buffer
->major_mode
;
1671 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1674 count
= SPECPDL_INDEX ();
1676 /* To select a nonfundamental mode,
1677 select the buffer temporarily and then call the mode function. */
1679 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1681 Fset_buffer (buffer
);
1684 return unbind_to (count
, Qnil
);
1687 /* If switching buffers in WINDOW would be an error, return
1688 a C string saying what the error would be. */
1691 no_switch_window (window
)
1695 if (EQ (minibuf_window
, window
))
1696 return "Cannot switch buffers in minibuffer window";
1697 tem
= Fwindow_dedicated_p (window
);
1699 return "Cannot switch buffers in a dedicated window";
1703 /* Switch to buffer BUFFER in the selected window.
1704 If NORECORD is non-nil, don't call record_buffer. */
1707 switch_to_buffer_1 (buffer
, norecord
)
1708 Lisp_Object buffer
, norecord
;
1710 register Lisp_Object buf
;
1713 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1716 buf
= Fget_buffer (buffer
);
1719 buf
= Fget_buffer_create (buffer
);
1720 Fset_buffer_major_mode (buf
);
1724 if (NILP (norecord
))
1725 record_buffer (buf
);
1727 Fset_window_buffer (EQ (selected_window
, minibuf_window
)
1728 ? Fnext_window (minibuf_window
, Qnil
, Qnil
)
1735 DEFUN ("switch-to-buffer", Fswitch_to_buffer
, Sswitch_to_buffer
, 1, 2, "BSwitch to buffer: ",
1736 doc
: /* Select buffer BUFFER in the current window.
1737 If BUFFER does not identify an existing buffer,
1738 then this function creates a buffer with that name.
1740 When called from Lisp, BUFFER may be a buffer, a string \(a buffer name),
1741 or nil. If BUFFER is nil, then this function chooses a buffer
1742 using `other-buffer'.
1743 Optional second arg NORECORD non-nil means
1744 do not put this buffer at the front of the list of recently selected ones.
1745 This function returns the buffer it switched to.
1747 WARNING: This is NOT the way to work on another buffer temporarily
1748 within a Lisp program! Use `set-buffer' instead. That avoids messing with
1749 the window-buffer correspondences. */)
1751 Lisp_Object buffer
, norecord
;
1755 if (EQ (buffer
, Fwindow_buffer (selected_window
)))
1757 /* Basically a NOP. Avoid signalling an error in the case where
1758 the selected window is dedicated, or a minibuffer. */
1760 /* But do put this buffer at the front of the buffer list,
1761 unless that has been inhibited. Note that even if
1762 BUFFER is at the front of the main buffer-list already,
1763 we still want to move it to the front of the frame's buffer list. */
1764 if (NILP (norecord
))
1765 record_buffer (buffer
);
1766 return Fset_buffer (buffer
);
1769 err
= no_switch_window (selected_window
);
1770 if (err
) error (err
);
1772 return switch_to_buffer_1 (buffer
, norecord
);
1775 DEFUN ("pop-to-buffer", Fpop_to_buffer
, Spop_to_buffer
, 1, 3, 0,
1776 doc
: /* Select buffer BUFFER in some window, preferably a different one.
1777 BUFFER may be a buffer, a string \(a buffer name), or nil.
1778 If BUFFER is a string which is not the name of an existing buffer,
1779 then this function creates a buffer with that name.
1780 If BUFFER is nil, then it chooses some other buffer.
1781 If `pop-up-windows' is non-nil, windows can be split to do this.
1782 If optional second arg OTHER-WINDOW is non-nil, insist on finding another
1783 window even if BUFFER is already visible in the selected window,
1784 and ignore `same-window-regexps' and `same-window-buffer-names'.
1785 This function returns the buffer it switched to.
1786 This uses the function `display-buffer' as a subroutine; see the documentation
1787 of `display-buffer' for additional customization information.
1789 Optional third arg NORECORD non-nil means
1790 do not put this buffer at the front of the list of recently selected ones. */)
1791 (buffer
, other_window
, norecord
)
1792 Lisp_Object buffer
, other_window
, norecord
;
1794 register Lisp_Object buf
;
1796 buf
= Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
);
1799 buf
= Fget_buffer (buffer
);
1802 buf
= Fget_buffer_create (buffer
);
1803 Fset_buffer_major_mode (buf
);
1807 Fselect_window (Fdisplay_buffer (buf
, other_window
, Qnil
), norecord
);
1811 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1812 doc
: /* Return the current buffer as a Lisp object. */)
1815 register Lisp_Object buf
;
1816 XSETBUFFER (buf
, current_buffer
);
1820 /* Set the current buffer to B.
1822 We previously set windows_or_buffers_changed here to invalidate
1823 global unchanged information in beg_unchanged and end_unchanged.
1824 This is no longer necessary because we now compute unchanged
1825 information on a buffer-basis. Every action affecting other
1826 windows than the selected one requires a select_window at some
1827 time, and that increments windows_or_buffers_changed. */
1830 set_buffer_internal (b
)
1831 register struct buffer
*b
;
1833 if (current_buffer
!= b
)
1834 set_buffer_internal_1 (b
);
1837 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1838 This is used by redisplay. */
1841 set_buffer_internal_1 (b
)
1842 register struct buffer
*b
;
1844 register struct buffer
*old_buf
;
1845 register Lisp_Object tail
, valcontents
;
1848 #ifdef USE_MMAP_FOR_BUFFERS
1849 if (b
->text
->beg
== NULL
)
1850 enlarge_buffer_text (b
, 0);
1851 #endif /* USE_MMAP_FOR_BUFFERS */
1853 if (current_buffer
== b
)
1856 old_buf
= current_buffer
;
1858 last_known_column_point
= -1; /* invalidate indentation cache */
1862 /* Put the undo list back in the base buffer, so that it appears
1863 that an indirect buffer shares the undo list of its base. */
1864 if (old_buf
->base_buffer
)
1865 old_buf
->base_buffer
->undo_list
= old_buf
->undo_list
;
1867 /* If the old current buffer has markers to record PT, BEGV and ZV
1868 when it is not current, update them now. */
1869 if (! NILP (old_buf
->pt_marker
))
1872 XSETBUFFER (obuf
, old_buf
);
1873 set_marker_both (old_buf
->pt_marker
, obuf
,
1874 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1876 if (! NILP (old_buf
->begv_marker
))
1879 XSETBUFFER (obuf
, old_buf
);
1880 set_marker_both (old_buf
->begv_marker
, obuf
,
1881 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1883 if (! NILP (old_buf
->zv_marker
))
1886 XSETBUFFER (obuf
, old_buf
);
1887 set_marker_both (old_buf
->zv_marker
, obuf
,
1888 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1892 /* Get the undo list from the base buffer, so that it appears
1893 that an indirect buffer shares the undo list of its base. */
1895 b
->undo_list
= b
->base_buffer
->undo_list
;
1897 /* If the new current buffer has markers to record PT, BEGV and ZV
1898 when it is not current, fetch them now. */
1899 if (! NILP (b
->pt_marker
))
1901 BUF_PT (b
) = marker_position (b
->pt_marker
);
1902 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1904 if (! NILP (b
->begv_marker
))
1906 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1907 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1909 if (! NILP (b
->zv_marker
))
1911 BUF_ZV (b
) = marker_position (b
->zv_marker
);
1912 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
1915 /* Look down buffer's list of local Lisp variables
1916 to find and update any that forward into C variables. */
1918 for (tail
= b
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1920 valcontents
= SYMBOL_VALUE (XCAR (XCAR (tail
)));
1921 if ((BUFFER_LOCAL_VALUEP (valcontents
))
1922 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1923 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1924 /* Just reference the variable
1925 to cause it to become set for this buffer. */
1926 Fsymbol_value (XCAR (XCAR (tail
)));
1929 /* Do the same with any others that were local to the previous buffer */
1932 for (tail
= old_buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1934 valcontents
= SYMBOL_VALUE (XCAR (XCAR (tail
)));
1935 if ((BUFFER_LOCAL_VALUEP (valcontents
))
1936 && (tem
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1937 (BOOLFWDP (tem
) || INTFWDP (tem
) || OBJFWDP (tem
))))
1938 /* Just reference the variable
1939 to cause it to become set for this buffer. */
1940 Fsymbol_value (XCAR (XCAR (tail
)));
1944 /* Switch to buffer B temporarily for redisplay purposes.
1945 This avoids certain things that don't need to be done within redisplay. */
1951 register struct buffer
*old_buf
;
1953 if (current_buffer
== b
)
1956 old_buf
= current_buffer
;
1961 /* If the old current buffer has markers to record PT, BEGV and ZV
1962 when it is not current, update them now. */
1963 if (! NILP (old_buf
->pt_marker
))
1966 XSETBUFFER (obuf
, old_buf
);
1967 set_marker_both (old_buf
->pt_marker
, obuf
,
1968 BUF_PT (old_buf
), BUF_PT_BYTE (old_buf
));
1970 if (! NILP (old_buf
->begv_marker
))
1973 XSETBUFFER (obuf
, old_buf
);
1974 set_marker_both (old_buf
->begv_marker
, obuf
,
1975 BUF_BEGV (old_buf
), BUF_BEGV_BYTE (old_buf
));
1977 if (! NILP (old_buf
->zv_marker
))
1980 XSETBUFFER (obuf
, old_buf
);
1981 set_marker_both (old_buf
->zv_marker
, obuf
,
1982 BUF_ZV (old_buf
), BUF_ZV_BYTE (old_buf
));
1986 /* If the new current buffer has markers to record PT, BEGV and ZV
1987 when it is not current, fetch them now. */
1988 if (! NILP (b
->pt_marker
))
1990 BUF_PT (b
) = marker_position (b
->pt_marker
);
1991 BUF_PT_BYTE (b
) = marker_byte_position (b
->pt_marker
);
1993 if (! NILP (b
->begv_marker
))
1995 BUF_BEGV (b
) = marker_position (b
->begv_marker
);
1996 BUF_BEGV_BYTE (b
) = marker_byte_position (b
->begv_marker
);
1998 if (! NILP (b
->zv_marker
))
2000 BUF_ZV (b
) = marker_position (b
->zv_marker
);
2001 BUF_ZV_BYTE (b
) = marker_byte_position (b
->zv_marker
);
2005 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
2006 doc
: /* Make the buffer BUFFER current for editing operations.
2007 BUFFER may be a buffer or the name of an existing buffer.
2008 See also `save-excursion' when you want to make a buffer current temporarily.
2009 This function does not display the buffer, so its effect ends
2010 when the current command terminates.
2011 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently. */)
2013 register Lisp_Object buffer
;
2015 register Lisp_Object buf
;
2016 buf
= Fget_buffer (buffer
);
2019 if (NILP (XBUFFER (buf
)->name
))
2020 error ("Selecting deleted buffer");
2021 set_buffer_internal (XBUFFER (buf
));
2025 /* Set the current buffer to BUFFER provided it is alive. */
2028 set_buffer_if_live (buffer
)
2031 if (! NILP (XBUFFER (buffer
)->name
))
2032 Fset_buffer (buffer
);
2036 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
2037 Sbarf_if_buffer_read_only
, 0, 0, 0,
2038 doc
: /* Signal a `buffer-read-only' error if the current buffer is read-only. */)
2041 if (!NILP (current_buffer
->read_only
)
2042 && NILP (Vinhibit_read_only
))
2043 xsignal1 (Qbuffer_read_only
, Fcurrent_buffer ());
2047 DEFUN ("bury-buffer", Fbury_buffer
, Sbury_buffer
, 0, 1, "",
2048 doc
: /* Put BUFFER at the end of the list of all buffers.
2049 There it is the least likely candidate for `other-buffer' to return;
2050 thus, the least likely buffer for \\[switch-to-buffer] to select by default.
2051 You can specify a buffer name as BUFFER, or an actual buffer object.
2052 If BUFFER is nil or omitted, bury the current buffer.
2053 Also, if BUFFER is nil or omitted, remove the current buffer from the
2054 selected window if it is displayed there. */)
2056 register Lisp_Object buffer
;
2058 /* Figure out what buffer we're going to bury. */
2062 XSETBUFFER (buffer
, current_buffer
);
2064 tem
= Fwindow_buffer (selected_window
);
2065 /* If we're burying the current buffer, unshow it. */
2066 if (EQ (buffer
, tem
))
2068 if (NILP (Fwindow_dedicated_p (selected_window
)))
2069 Fswitch_to_buffer (Fother_buffer (buffer
, Qnil
, Qnil
), Qnil
);
2070 else if (NILP (XWINDOW (selected_window
)->parent
))
2071 Ficonify_frame (Fwindow_frame (selected_window
));
2073 Fdelete_window (selected_window
);
2080 buf1
= Fget_buffer (buffer
);
2086 /* Move buffer to the end of the buffer list. Do nothing if the
2087 buffer is killed. */
2088 if (!NILP (XBUFFER (buffer
)->name
))
2090 Lisp_Object aelt
, link
;
2092 aelt
= Frassq (buffer
, Vbuffer_alist
);
2093 link
= Fmemq (aelt
, Vbuffer_alist
);
2094 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
2095 XSETCDR (link
, Qnil
);
2096 Vbuffer_alist
= nconc2 (Vbuffer_alist
, link
);
2098 XFRAME (selected_frame
)->buffer_list
2099 = Fdelq (buffer
, XFRAME (selected_frame
)->buffer_list
);
2100 XFRAME (selected_frame
)->buried_buffer_list
2101 = Fcons (buffer
, Fdelq (buffer
, XFRAME (selected_frame
)->buried_buffer_list
));
2107 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
2108 doc
: /* Delete the entire contents of the current buffer.
2109 Any narrowing restriction in effect (see `narrow-to-region') is removed,
2110 so the buffer is truly empty after this. */)
2117 current_buffer
->last_window_start
= 1;
2118 /* Prevent warnings, or suspension of auto saving, that would happen
2119 if future size is less than past size. Use of erase-buffer
2120 implies that the future text is not really related to the past text. */
2121 XSETFASTINT (current_buffer
->save_length
, 0);
2126 validate_region (b
, e
)
2127 register Lisp_Object
*b
, *e
;
2129 CHECK_NUMBER_COERCE_MARKER (*b
);
2130 CHECK_NUMBER_COERCE_MARKER (*e
);
2132 if (XINT (*b
) > XINT (*e
))
2135 tem
= *b
; *b
= *e
; *e
= tem
;
2138 if (!(BEGV
<= XINT (*b
) && XINT (*b
) <= XINT (*e
)
2139 && XINT (*e
) <= ZV
))
2140 args_out_of_range (*b
, *e
);
2143 /* Advance BYTE_POS up to a character boundary
2144 and return the adjusted position. */
2147 advance_to_char_boundary (byte_pos
)
2152 if (byte_pos
== BEG
)
2153 /* Beginning of buffer is always a character boundary. */
2156 c
= FETCH_BYTE (byte_pos
);
2157 if (! CHAR_HEAD_P (c
))
2159 /* We should advance BYTE_POS only when C is a constituent of a
2160 multibyte sequence. */
2161 int orig_byte_pos
= byte_pos
;
2166 c
= FETCH_BYTE (byte_pos
);
2168 while (! CHAR_HEAD_P (c
) && byte_pos
> BEG
);
2170 if (byte_pos
< orig_byte_pos
)
2171 byte_pos
= orig_byte_pos
;
2172 /* If C is a constituent of a multibyte sequence, BYTE_POS was
2173 surely advance to the correct character boundary. If C is
2174 not, BYTE_POS was unchanged. */
2180 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte
, Sset_buffer_multibyte
,
2182 doc
: /* Set the multibyte flag of the current buffer to FLAG.
2183 If FLAG is t, this makes the buffer a multibyte buffer.
2184 If FLAG is nil, this makes the buffer a single-byte buffer.
2185 The buffer contents remain unchanged as a sequence of bytes
2186 but the contents viewed as characters do change.
2187 If the multibyte flag was really changed, undo information of the
2188 current buffer is cleared. */)
2192 struct Lisp_Marker
*tail
, *markers
;
2193 struct buffer
*other
;
2195 int narrowed
= (BEG
!= BEGV
|| Z
!= ZV
);
2196 int modified_p
= !NILP (Fbuffer_modified_p (Qnil
));
2197 Lisp_Object old_undo
= current_buffer
->undo_list
;
2198 struct gcpro gcpro1
;
2200 if (current_buffer
->base_buffer
)
2201 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
2203 /* Do nothing if nothing actually changes. */
2204 if (NILP (flag
) == NILP (current_buffer
->enable_multibyte_characters
))
2209 /* Don't record these buffer changes. We will put a special undo entry
2211 current_buffer
->undo_list
= Qt
;
2213 /* If the cached position is for this buffer, clear it out. */
2214 clear_charpos_cache (current_buffer
);
2217 begv
= BEGV_BYTE
, zv
= ZV_BYTE
;
2219 begv
= BEGV
, zv
= ZV
;
2229 /* Do this first, so it can use CHAR_TO_BYTE
2230 to calculate the old correspondences. */
2231 set_intervals_multibyte (0);
2233 current_buffer
->enable_multibyte_characters
= Qnil
;
2239 TEMP_SET_PT_BOTH (PT_BYTE
, PT_BYTE
);
2242 for (tail
= BUF_MARKERS (current_buffer
); tail
; tail
= tail
->next
)
2243 tail
->charpos
= tail
->bytepos
;
2245 /* Convert multibyte form of 8-bit characters to unibyte. */
2260 if (MULTIBYTE_STR_AS_UNIBYTE_P (p
, bytes
))
2261 p
+= bytes
, pos
+= bytes
;
2264 c
= STRING_CHAR (p
, stop
- pos
);
2265 /* Delete all bytes for this 8-bit character but the
2266 last one, and change the last one to the charcter
2269 del_range_2 (pos
, pos
, pos
+ bytes
, pos
+ bytes
, 0);
2281 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2289 /* Be sure not to have a multibyte sequence striding over the GAP.
2290 Ex: We change this: "...abc\201 _GAP_ \241def..."
2291 to: "...abc _GAP_ \201\241def..." */
2293 if (GPT_BYTE
> 1 && GPT_BYTE
< Z_BYTE
2294 && ! CHAR_HEAD_P (*(GAP_END_ADDR
)))
2296 unsigned char *p
= GPT_ADDR
- 1;
2298 while (! CHAR_HEAD_P (*p
) && p
> BEG_ADDR
) p
--;
2299 if (BASE_LEADING_CODE_P (*p
))
2301 int new_gpt
= GPT_BYTE
- (GPT_ADDR
- p
);
2303 move_gap_both (new_gpt
, new_gpt
);
2307 /* Make the buffer contents valid as multibyte by converting
2308 8-bit characters to multibyte form. */
2324 if (UNIBYTE_STR_AS_MULTIBYTE_P (p
, stop
- pos
, bytes
))
2325 p
+= bytes
, pos
+= bytes
;
2328 unsigned char tmp
[MAX_MULTIBYTE_LENGTH
];
2330 bytes
= CHAR_STRING (*p
, tmp
);
2332 TEMP_SET_PT_BOTH (pos
+ 1, pos
+ 1);
2334 insert_1_both (tmp
+ 1, bytes
, bytes
, 1, 0, 0);
2335 /* Now the gap is after the just inserted data. */
2352 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2354 /* Do this first, so that chars_in_text asks the right question.
2355 set_intervals_multibyte needs it too. */
2356 current_buffer
->enable_multibyte_characters
= Qt
;
2358 GPT_BYTE
= advance_to_char_boundary (GPT_BYTE
);
2359 GPT
= chars_in_text (BEG_ADDR
, GPT_BYTE
- BEG_BYTE
) + BEG
;
2361 Z
= chars_in_text (GAP_END_ADDR
, Z_BYTE
- GPT_BYTE
) + GPT
;
2363 BEGV_BYTE
= advance_to_char_boundary (BEGV_BYTE
);
2364 if (BEGV_BYTE
> GPT_BYTE
)
2365 BEGV
= chars_in_text (GAP_END_ADDR
, BEGV_BYTE
- GPT_BYTE
) + GPT
;
2367 BEGV
= chars_in_text (BEG_ADDR
, BEGV_BYTE
- BEG_BYTE
) + BEG
;
2369 ZV_BYTE
= advance_to_char_boundary (ZV_BYTE
);
2370 if (ZV_BYTE
> GPT_BYTE
)
2371 ZV
= chars_in_text (GAP_END_ADDR
, ZV_BYTE
- GPT_BYTE
) + GPT
;
2373 ZV
= chars_in_text (BEG_ADDR
, ZV_BYTE
- BEG_BYTE
) + BEG
;
2376 int pt_byte
= advance_to_char_boundary (PT_BYTE
);
2379 if (pt_byte
> GPT_BYTE
)
2380 pt
= chars_in_text (GAP_END_ADDR
, pt_byte
- GPT_BYTE
) + GPT
;
2382 pt
= chars_in_text (BEG_ADDR
, pt_byte
- BEG_BYTE
) + BEG
;
2383 TEMP_SET_PT_BOTH (pt
, pt_byte
);
2386 tail
= markers
= BUF_MARKERS (current_buffer
);
2388 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
2389 getting confused by the markers that have not yet been updated.
2390 It is also a signal that it should never create a marker. */
2391 BUF_MARKERS (current_buffer
) = NULL
;
2393 for (; tail
; tail
= tail
->next
)
2395 tail
->bytepos
= advance_to_char_boundary (tail
->bytepos
);
2396 tail
->charpos
= BYTE_TO_CHAR (tail
->bytepos
);
2399 /* Make sure no markers were put on the chain
2400 while the chain value was incorrect. */
2401 if (BUF_MARKERS (current_buffer
))
2404 BUF_MARKERS (current_buffer
) = markers
;
2406 /* Do this last, so it can calculate the new correspondences
2407 between chars and bytes. */
2408 set_intervals_multibyte (1);
2411 if (!EQ (old_undo
, Qt
))
2413 /* Represent all the above changes by a special undo entry. */
2414 extern Lisp_Object Qapply
;
2415 current_buffer
->undo_list
= Fcons (list3 (Qapply
,
2416 intern ("set-buffer-multibyte"),
2417 NILP (flag
) ? Qt
: Qnil
),
2423 /* Changing the multibyteness of a buffer means that all windows
2424 showing that buffer must be updated thoroughly. */
2425 current_buffer
->prevent_redisplay_optimizations_p
= 1;
2426 ++windows_or_buffers_changed
;
2428 /* Copy this buffer's new multibyte status
2429 into all of its indirect buffers. */
2430 for (other
= all_buffers
; other
; other
= other
->next
)
2431 if (other
->base_buffer
== current_buffer
&& !NILP (other
->name
))
2433 other
->enable_multibyte_characters
2434 = current_buffer
->enable_multibyte_characters
;
2435 other
->prevent_redisplay_optimizations_p
= 1;
2438 /* Restore the modifiedness of the buffer. */
2439 if (!modified_p
&& !NILP (Fbuffer_modified_p (Qnil
)))
2440 Fset_buffer_modified_p (Qnil
);
2443 /* Update coding systems of this buffer's process (if any). */
2445 Lisp_Object process
;
2447 process
= Fget_buffer_process (Fcurrent_buffer ());
2448 if (PROCESSP (process
))
2449 setup_process_coding_systems (process
);
2451 #endif /* subprocesses */
2456 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
, Skill_all_local_variables
,
2458 doc
: /* Switch to Fundamental mode by killing current buffer's local variables.
2459 Most local variable bindings are eliminated so that the default values
2460 become effective once more. Also, the syntax table is set from
2461 `standard-syntax-table', the local keymap is set to nil,
2462 and the abbrev table from `fundamental-mode-abbrev-table'.
2463 This function also forces redisplay of the mode line.
2465 Every function to select a new major mode starts by
2466 calling this function.
2468 As a special exception, local variables whose names have
2469 a non-nil `permanent-local' property are not eliminated by this function.
2471 The first thing this function does is run
2472 the normal hook `change-major-mode-hook'. */)
2475 if (!NILP (Vrun_hooks
))
2476 call1 (Vrun_hooks
, Qchange_major_mode_hook
);
2478 /* Make sure none of the bindings in local_var_alist
2479 remain swapped in, in their symbols. */
2481 swap_out_buffer_local_variables (current_buffer
);
2483 /* Actually eliminate all local bindings of this buffer. */
2485 reset_buffer_local_variables (current_buffer
, 0);
2487 /* Force mode-line redisplay. Useful here because all major mode
2488 commands call this function. */
2489 update_mode_lines
++;
2494 /* Make sure no local variables remain set up with buffer B
2495 for their current values. */
2498 swap_out_buffer_local_variables (b
)
2501 Lisp_Object oalist
, alist
, sym
, tem
, buffer
;
2503 XSETBUFFER (buffer
, b
);
2504 oalist
= b
->local_var_alist
;
2506 for (alist
= oalist
; CONSP (alist
); alist
= XCDR (alist
))
2508 sym
= XCAR (XCAR (alist
));
2510 /* Need not do anything if some other buffer's binding is now encached. */
2511 tem
= XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym
))->buffer
;
2512 if (EQ (tem
, buffer
))
2514 /* Symbol is set up for this buffer's old local value:
2516 swap_in_global_binding (sym
);
2521 /* Find all the overlays in the current buffer that contain position POS.
2522 Return the number found, and store them in a vector in *VEC_PTR.
2523 Store in *LEN_PTR the size allocated for the vector.
2524 Store in *NEXT_PTR the next position after POS where an overlay starts,
2525 or ZV if there are no more overlays between POS and ZV.
2526 Store in *PREV_PTR the previous position before POS where an overlay ends,
2527 or where an overlay starts which ends at or after POS;
2528 or BEGV if there are no such overlays from BEGV to POS.
2529 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2531 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2532 when this function is called.
2534 If EXTEND is non-zero, we make the vector bigger if necessary.
2535 If EXTEND is zero, we never extend the vector,
2536 and we store only as many overlays as will fit.
2537 But we still return the total number of overlays.
2539 If CHANGE_REQ is true, then any position written into *PREV_PTR or
2540 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2541 default (BEGV or ZV). */
2544 overlays_at (pos
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
, change_req
)
2547 Lisp_Object
**vec_ptr
;
2553 Lisp_Object overlay
, start
, end
;
2554 struct Lisp_Overlay
*tail
;
2557 Lisp_Object
*vec
= *vec_ptr
;
2560 int inhibit_storing
= 0;
2562 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2564 int startpos
, endpos
;
2566 XSETMISC (overlay
, tail
);
2568 start
= OVERLAY_START (overlay
);
2569 end
= OVERLAY_END (overlay
);
2570 endpos
= OVERLAY_POSITION (end
);
2577 startpos
= OVERLAY_POSITION (start
);
2578 /* This one ends at or after POS
2579 so its start counts for PREV_PTR if it's before POS. */
2580 if (prev
< startpos
&& startpos
< pos
)
2584 if (startpos
<= pos
)
2588 /* The supplied vector is full.
2589 Either make it bigger, or don't store any more in it. */
2592 /* Make it work with an initial len == 0. */
2597 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2601 inhibit_storing
= 1;
2604 if (!inhibit_storing
)
2606 /* Keep counting overlays even if we can't return them all. */
2609 else if (startpos
< next
)
2613 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2615 int startpos
, endpos
;
2617 XSETMISC (overlay
, tail
);
2619 start
= OVERLAY_START (overlay
);
2620 end
= OVERLAY_END (overlay
);
2621 startpos
= OVERLAY_POSITION (start
);
2624 if (startpos
< next
)
2628 endpos
= OVERLAY_POSITION (end
);
2635 /* Make it work with an initial len == 0. */
2640 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2644 inhibit_storing
= 1;
2647 if (!inhibit_storing
)
2651 if (startpos
< pos
&& startpos
> prev
)
2654 else if (endpos
< pos
&& endpos
> prev
)
2656 else if (endpos
== pos
&& startpos
> prev
2657 && (!change_req
|| startpos
< pos
))
2668 /* Find all the overlays in the current buffer that overlap the range BEG-END
2669 or are empty at BEG.
2671 Return the number found, and store them in a vector in *VEC_PTR.
2672 Store in *LEN_PTR the size allocated for the vector.
2673 Store in *NEXT_PTR the next position after POS where an overlay starts,
2674 or ZV if there are no more overlays.
2675 Store in *PREV_PTR the previous position before POS where an overlay ends,
2676 or BEGV if there are no previous overlays.
2677 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2679 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2680 when this function is called.
2682 If EXTEND is non-zero, we make the vector bigger if necessary.
2683 If EXTEND is zero, we never extend the vector,
2684 and we store only as many overlays as will fit.
2685 But we still return the total number of overlays. */
2688 overlays_in (beg
, end
, extend
, vec_ptr
, len_ptr
, next_ptr
, prev_ptr
)
2691 Lisp_Object
**vec_ptr
;
2696 Lisp_Object overlay
, ostart
, oend
;
2697 struct Lisp_Overlay
*tail
;
2700 Lisp_Object
*vec
= *vec_ptr
;
2703 int inhibit_storing
= 0;
2705 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2707 int startpos
, endpos
;
2709 XSETMISC (overlay
, tail
);
2711 ostart
= OVERLAY_START (overlay
);
2712 oend
= OVERLAY_END (overlay
);
2713 endpos
= OVERLAY_POSITION (oend
);
2720 startpos
= OVERLAY_POSITION (ostart
);
2721 /* Count an interval if it either overlaps the range
2722 or is empty at the start of the range. */
2723 if ((beg
< endpos
&& startpos
< end
)
2724 || (startpos
== endpos
&& beg
== endpos
))
2728 /* The supplied vector is full.
2729 Either make it bigger, or don't store any more in it. */
2732 /* Make it work with an initial len == 0. */
2737 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2741 inhibit_storing
= 1;
2744 if (!inhibit_storing
)
2746 /* Keep counting overlays even if we can't return them all. */
2749 else if (startpos
< next
)
2753 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2755 int startpos
, endpos
;
2757 XSETMISC (overlay
, tail
);
2759 ostart
= OVERLAY_START (overlay
);
2760 oend
= OVERLAY_END (overlay
);
2761 startpos
= OVERLAY_POSITION (ostart
);
2764 if (startpos
< next
)
2768 endpos
= OVERLAY_POSITION (oend
);
2769 /* Count an interval if it either overlaps the range
2770 or is empty at the start of the range. */
2771 if ((beg
< endpos
&& startpos
< end
)
2772 || (startpos
== endpos
&& beg
== endpos
))
2778 /* Make it work with an initial len == 0. */
2783 vec
= (Lisp_Object
*) xrealloc (vec
, len
* sizeof (Lisp_Object
));
2787 inhibit_storing
= 1;
2790 if (!inhibit_storing
)
2794 else if (endpos
< beg
&& endpos
> prev
)
2806 /* Return non-zero if there exists an overlay with a non-nil
2807 `mouse-face' property overlapping OVERLAY. */
2810 mouse_face_overlay_overlaps (overlay
)
2811 Lisp_Object overlay
;
2813 int start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2814 int end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2816 Lisp_Object
*v
, tem
;
2819 v
= (Lisp_Object
*) alloca (size
* sizeof *v
);
2820 n
= overlays_in (start
, end
, 0, &v
, &size
, NULL
, NULL
);
2823 v
= (Lisp_Object
*) alloca (n
* sizeof *v
);
2824 overlays_in (start
, end
, 0, &v
, &n
, NULL
, NULL
);
2827 for (i
= 0; i
< n
; ++i
)
2828 if (!EQ (v
[i
], overlay
)
2829 && (tem
= Foverlay_get (overlay
, Qmouse_face
),
2838 /* Fast function to just test if we're at an overlay boundary. */
2840 overlay_touches_p (pos
)
2843 Lisp_Object overlay
;
2844 struct Lisp_Overlay
*tail
;
2846 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
2850 XSETMISC (overlay
,tail
);
2851 if (!GC_OVERLAYP (overlay
))
2854 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2857 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2861 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
2865 XSETMISC (overlay
, tail
);
2866 if (!GC_OVERLAYP (overlay
))
2869 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2872 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2880 Lisp_Object overlay
;
2886 compare_overlays (v1
, v2
)
2887 const void *v1
, *v2
;
2889 const struct sortvec
*s1
= (const struct sortvec
*) v1
;
2890 const struct sortvec
*s2
= (const struct sortvec
*) v2
;
2891 if (s1
->priority
!= s2
->priority
)
2892 return s1
->priority
- s2
->priority
;
2893 if (s1
->beg
!= s2
->beg
)
2894 return s1
->beg
- s2
->beg
;
2895 if (s1
->end
!= s2
->end
)
2896 return s2
->end
- s1
->end
;
2900 /* Sort an array of overlays by priority. The array is modified in place.
2901 The return value is the new size; this may be smaller than the original
2902 size if some of the overlays were invalid or were window-specific. */
2904 sort_overlays (overlay_vec
, noverlays
, w
)
2905 Lisp_Object
*overlay_vec
;
2910 struct sortvec
*sortvec
;
2911 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
2913 /* Put the valid and relevant overlays into sortvec. */
2915 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2918 Lisp_Object overlay
;
2920 overlay
= overlay_vec
[i
];
2921 if (OVERLAY_VALID (overlay
)
2922 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2923 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2925 /* If we're interested in a specific window, then ignore
2926 overlays that are limited to some other window. */
2931 window
= Foverlay_get (overlay
, Qwindow
);
2932 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2936 /* This overlay is good and counts: put it into sortvec. */
2937 sortvec
[j
].overlay
= overlay
;
2938 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2939 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2940 tem
= Foverlay_get (overlay
, Qpriority
);
2942 sortvec
[j
].priority
= XINT (tem
);
2944 sortvec
[j
].priority
= 0;
2950 /* Sort the overlays into the proper order: increasing priority. */
2953 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2955 for (i
= 0; i
< noverlays
; i
++)
2956 overlay_vec
[i
] = sortvec
[i
].overlay
;
2962 Lisp_Object string
, string2
;
2969 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
2970 int size
; /* Allocated length of that array. */
2971 int used
; /* How much of the array is currently in use. */
2972 int bytes
; /* Total length of the strings in buf. */
2975 /* Buffers for storing information about the overlays touching a given
2976 position. These could be automatic variables in overlay_strings, but
2977 it's more efficient to hold onto the memory instead of repeatedly
2978 allocating and freeing it. */
2979 static struct sortstrlist overlay_heads
, overlay_tails
;
2980 static unsigned char *overlay_str_buf
;
2982 /* Allocated length of overlay_str_buf. */
2983 static int overlay_str_len
;
2985 /* A comparison function suitable for passing to qsort. */
2987 cmp_for_strings (as1
, as2
)
2990 struct sortstr
*s1
= (struct sortstr
*)as1
;
2991 struct sortstr
*s2
= (struct sortstr
*)as2
;
2992 if (s1
->size
!= s2
->size
)
2993 return s2
->size
- s1
->size
;
2994 if (s1
->priority
!= s2
->priority
)
2995 return s1
->priority
- s2
->priority
;
3000 record_overlay_string (ssl
, str
, str2
, pri
, size
)
3001 struct sortstrlist
*ssl
;
3002 Lisp_Object str
, str2
, pri
;
3007 if (ssl
->used
== ssl
->size
)
3013 ssl
->buf
= ((struct sortstr
*)
3014 xrealloc (ssl
->buf
, ssl
->size
* sizeof (struct sortstr
)));
3016 ssl
->buf
[ssl
->used
].string
= str
;
3017 ssl
->buf
[ssl
->used
].string2
= str2
;
3018 ssl
->buf
[ssl
->used
].size
= size
;
3019 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
3022 if (NILP (current_buffer
->enable_multibyte_characters
))
3023 nbytes
= SCHARS (str
);
3024 else if (! STRING_MULTIBYTE (str
))
3025 nbytes
= count_size_as_multibyte (SDATA (str
),
3028 nbytes
= SBYTES (str
);
3030 ssl
->bytes
+= nbytes
;
3034 if (NILP (current_buffer
->enable_multibyte_characters
))
3035 nbytes
= SCHARS (str2
);
3036 else if (! STRING_MULTIBYTE (str2
))
3037 nbytes
= count_size_as_multibyte (SDATA (str2
),
3040 nbytes
= SBYTES (str2
);
3042 ssl
->bytes
+= nbytes
;
3046 /* Return the concatenation of the strings associated with overlays that
3047 begin or end at POS, ignoring overlays that are specific to a window
3048 other than W. The strings are concatenated in the appropriate order:
3049 shorter overlays nest inside longer ones, and higher priority inside
3050 lower. Normally all of the after-strings come first, but zero-sized
3051 overlays have their after-strings ride along with the before-strings
3052 because it would look strange to print them inside-out.
3054 Returns the string length, and stores the contents indirectly through
3055 PSTR, if that variable is non-null. The string may be overwritten by
3056 subsequent calls. */
3059 overlay_strings (pos
, w
, pstr
)
3062 unsigned char **pstr
;
3064 Lisp_Object overlay
, window
, str
;
3065 struct Lisp_Overlay
*ov
;
3066 int startpos
, endpos
;
3067 int multibyte
= ! NILP (current_buffer
->enable_multibyte_characters
);
3069 overlay_heads
.used
= overlay_heads
.bytes
= 0;
3070 overlay_tails
.used
= overlay_tails
.bytes
= 0;
3071 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
3073 XSETMISC (overlay
, ov
);
3074 eassert (OVERLAYP (overlay
));
3076 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3077 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3080 if (endpos
!= pos
&& startpos
!= pos
)
3082 window
= Foverlay_get (overlay
, Qwindow
);
3083 if (WINDOWP (window
) && XWINDOW (window
) != w
)
3086 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
3087 record_overlay_string (&overlay_heads
, str
,
3089 ? Foverlay_get (overlay
, Qafter_string
)
3091 Foverlay_get (overlay
, Qpriority
),
3093 else if (endpos
== pos
3094 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
3095 record_overlay_string (&overlay_tails
, str
, Qnil
,
3096 Foverlay_get (overlay
, Qpriority
),
3099 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
3101 XSETMISC (overlay
, ov
);
3102 eassert (OVERLAYP (overlay
));
3104 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3105 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3108 if (endpos
!= pos
&& startpos
!= pos
)
3110 window
= Foverlay_get (overlay
, Qwindow
);
3111 if (WINDOWP (window
) && XWINDOW (window
) != w
)
3114 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
3115 record_overlay_string (&overlay_heads
, str
,
3117 ? Foverlay_get (overlay
, Qafter_string
)
3119 Foverlay_get (overlay
, Qpriority
),
3121 else if (endpos
== pos
3122 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
3123 record_overlay_string (&overlay_tails
, str
, Qnil
,
3124 Foverlay_get (overlay
, Qpriority
),
3127 if (overlay_tails
.used
> 1)
3128 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
3130 if (overlay_heads
.used
> 1)
3131 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
3133 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
3138 int total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
3140 if (total
> overlay_str_len
)
3142 overlay_str_len
= total
;
3143 overlay_str_buf
= (unsigned char *)xrealloc (overlay_str_buf
,
3146 p
= overlay_str_buf
;
3147 for (i
= overlay_tails
.used
; --i
>= 0;)
3150 tem
= overlay_tails
.buf
[i
].string
;
3151 nbytes
= copy_text (SDATA (tem
), p
,
3153 STRING_MULTIBYTE (tem
), multibyte
);
3156 for (i
= 0; i
< overlay_heads
.used
; ++i
)
3159 tem
= overlay_heads
.buf
[i
].string
;
3160 nbytes
= copy_text (SDATA (tem
), p
,
3162 STRING_MULTIBYTE (tem
), multibyte
);
3164 tem
= overlay_heads
.buf
[i
].string2
;
3167 nbytes
= copy_text (SDATA (tem
), p
,
3169 STRING_MULTIBYTE (tem
), multibyte
);
3173 if (p
!= overlay_str_buf
+ total
)
3176 *pstr
= overlay_str_buf
;
3182 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3185 recenter_overlay_lists (buf
, pos
)
3189 Lisp_Object overlay
, beg
, end
;
3190 struct Lisp_Overlay
*prev
, *tail
, *next
;
3192 /* See if anything in overlays_before should move to overlays_after. */
3194 /* We don't strictly need prev in this loop; it should always be nil.
3195 But we use it for symmetry and in case that should cease to be true
3196 with some future change. */
3198 for (tail
= buf
->overlays_before
; tail
; prev
= tail
, tail
= next
)
3201 XSETMISC (overlay
, tail
);
3203 /* If the overlay is not valid, get rid of it. */
3204 if (!OVERLAY_VALID (overlay
))
3209 /* Splice the cons cell TAIL out of overlays_before. */
3213 buf
->overlays_before
= next
;
3219 beg
= OVERLAY_START (overlay
);
3220 end
= OVERLAY_END (overlay
);
3222 if (OVERLAY_POSITION (end
) > pos
)
3224 /* OVERLAY needs to be moved. */
3225 int where
= OVERLAY_POSITION (beg
);
3226 struct Lisp_Overlay
*other
, *other_prev
;
3228 /* Splice the cons cell TAIL out of overlays_before. */
3232 buf
->overlays_before
= next
;
3234 /* Search thru overlays_after for where to put it. */
3236 for (other
= buf
->overlays_after
; other
;
3237 other_prev
= other
, other
= other
->next
)
3239 Lisp_Object otherbeg
, otheroverlay
;
3241 XSETMISC (otheroverlay
, other
);
3242 eassert (OVERLAY_VALID (otheroverlay
));
3244 otherbeg
= OVERLAY_START (otheroverlay
);
3245 if (OVERLAY_POSITION (otherbeg
) >= where
)
3249 /* Add TAIL to overlays_after before OTHER. */
3252 other_prev
->next
= tail
;
3254 buf
->overlays_after
= tail
;
3258 /* We've reached the things that should stay in overlays_before.
3259 All the rest of overlays_before must end even earlier,
3264 /* See if anything in overlays_after should be in overlays_before. */
3266 for (tail
= buf
->overlays_after
; tail
; prev
= tail
, tail
= next
)
3269 XSETMISC (overlay
, tail
);
3271 /* If the overlay is not valid, get rid of it. */
3272 if (!OVERLAY_VALID (overlay
))
3277 /* Splice the cons cell TAIL out of overlays_after. */
3281 buf
->overlays_after
= next
;
3287 beg
= OVERLAY_START (overlay
);
3288 end
= OVERLAY_END (overlay
);
3290 /* Stop looking, when we know that nothing further
3291 can possibly end before POS. */
3292 if (OVERLAY_POSITION (beg
) > pos
)
3295 if (OVERLAY_POSITION (end
) <= pos
)
3297 /* OVERLAY needs to be moved. */
3298 int where
= OVERLAY_POSITION (end
);
3299 struct Lisp_Overlay
*other
, *other_prev
;
3301 /* Splice the cons cell TAIL out of overlays_after. */
3305 buf
->overlays_after
= next
;
3307 /* Search thru overlays_before for where to put it. */
3309 for (other
= buf
->overlays_before
; other
;
3310 other_prev
= other
, other
= other
->next
)
3312 Lisp_Object otherend
, otheroverlay
;
3314 XSETMISC (otheroverlay
, other
);
3315 eassert (OVERLAY_VALID (otheroverlay
));
3317 otherend
= OVERLAY_END (otheroverlay
);
3318 if (OVERLAY_POSITION (otherend
) <= where
)
3322 /* Add TAIL to overlays_before before OTHER. */
3325 other_prev
->next
= tail
;
3327 buf
->overlays_before
= tail
;
3332 buf
->overlay_center
= pos
;
3336 adjust_overlays_for_insert (pos
, length
)
3340 /* After an insertion, the lists are still sorted properly,
3341 but we may need to update the value of the overlay center. */
3342 if (current_buffer
->overlay_center
>= pos
)
3343 current_buffer
->overlay_center
+= length
;
3347 adjust_overlays_for_delete (pos
, length
)
3351 if (current_buffer
->overlay_center
< pos
)
3352 /* The deletion was to our right. No change needed; the before- and
3353 after-lists are still consistent. */
3355 else if (current_buffer
->overlay_center
> pos
+ length
)
3356 /* The deletion was to our left. We need to adjust the center value
3357 to account for the change in position, but the lists are consistent
3358 given the new value. */
3359 current_buffer
->overlay_center
-= length
;
3361 /* We're right in the middle. There might be things on the after-list
3362 that now belong on the before-list. Recentering will move them,
3363 and also update the center point. */
3364 recenter_overlay_lists (current_buffer
, pos
);
3367 /* Fix up overlays that were garbled as a result of permuting markers
3368 in the range START through END. Any overlay with at least one
3369 endpoint in this range will need to be unlinked from the overlay
3370 list and reinserted in its proper place.
3371 Such an overlay might even have negative size at this point.
3372 If so, we'll make the overlay empty. */
3374 fix_start_end_in_overlays (start
, end
)
3375 register int start
, end
;
3377 Lisp_Object overlay
;
3378 struct Lisp_Overlay
*before_list
, *after_list
;
3379 /* These are either nil, indicating that before_list or after_list
3380 should be assigned, or the cons cell the cdr of which should be
3382 struct Lisp_Overlay
*beforep
= NULL
, *afterp
= NULL
;
3383 /* 'Parent', likewise, indicates a cons cell or
3384 current_buffer->overlays_before or overlays_after, depending
3385 which loop we're in. */
3386 struct Lisp_Overlay
*tail
, *parent
;
3387 int startpos
, endpos
;
3389 /* This algorithm shifts links around instead of consing and GCing.
3390 The loop invariant is that before_list (resp. after_list) is a
3391 well-formed list except that its last element, the CDR of beforep
3392 (resp. afterp) if beforep (afterp) isn't nil or before_list
3393 (after_list) if it is, is still uninitialized. So it's not a bug
3394 that before_list isn't initialized, although it may look
3396 for (parent
= NULL
, tail
= current_buffer
->overlays_before
; tail
;)
3398 XSETMISC (overlay
, tail
);
3400 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3401 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3403 /* If the overlay is backwards, make it empty. */
3404 if (endpos
< startpos
)
3407 Fset_marker (OVERLAY_START (overlay
), make_number (startpos
),
3415 || (startpos
>= start
&& startpos
< end
))
3417 /* Add it to the end of the wrong list. Later on,
3418 recenter_overlay_lists will move it to the right place. */
3419 if (endpos
< current_buffer
->overlay_center
)
3424 afterp
->next
= tail
;
3432 beforep
->next
= tail
;
3436 current_buffer
->overlays_before
= tail
->next
;
3438 parent
->next
= tail
->next
;
3442 parent
= tail
, tail
= parent
->next
;
3444 for (parent
= NULL
, tail
= current_buffer
->overlays_after
; tail
;)
3446 XSETMISC (overlay
, tail
);
3448 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3449 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3451 /* If the overlay is backwards, make it empty. */
3452 if (endpos
< startpos
)
3455 Fset_marker (OVERLAY_START (overlay
), make_number (startpos
),
3459 if (startpos
>= end
)
3462 if (startpos
>= start
3463 || (endpos
>= start
&& endpos
< end
))
3465 if (endpos
< current_buffer
->overlay_center
)
3470 afterp
->next
= tail
;
3478 beforep
->next
= tail
;
3482 current_buffer
->overlays_after
= tail
->next
;
3484 parent
->next
= tail
->next
;
3488 parent
= tail
, tail
= parent
->next
;
3491 /* Splice the constructed (wrong) lists into the buffer's lists,
3492 and let the recenter function make it sane again. */
3495 beforep
->next
= current_buffer
->overlays_before
;
3496 current_buffer
->overlays_before
= before_list
;
3498 recenter_overlay_lists (current_buffer
, current_buffer
->overlay_center
);
3502 afterp
->next
= current_buffer
->overlays_after
;
3503 current_buffer
->overlays_after
= after_list
;
3505 recenter_overlay_lists (current_buffer
, current_buffer
->overlay_center
);
3508 /* We have two types of overlay: the one whose ending marker is
3509 after-insertion-marker (this is the usual case) and the one whose
3510 ending marker is before-insertion-marker. When `overlays_before'
3511 contains overlays of the latter type and the former type in this
3512 order and both overlays end at inserting position, inserting a text
3513 increases only the ending marker of the latter type, which results
3514 in incorrect ordering of `overlays_before'.
3516 This function fixes ordering of overlays in the slot
3517 `overlays_before' of the buffer *BP. Before the insertion, `point'
3518 was at PREV, and now is at POS. */
3521 fix_overlays_before (bp
, prev
, pos
)
3523 EMACS_INT prev
, pos
;
3525 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3526 struct Lisp_Overlay
*tail
= bp
->overlays_before
, *parent
= NULL
, *right_pair
;
3530 /* After the insertion, the several overlays may be in incorrect
3531 order. The possibility is that, in the list `overlays_before',
3532 an overlay which ends at POS appears after an overlay which ends
3533 at PREV. Since POS is greater than PREV, we must fix the
3534 ordering of these overlays, by moving overlays ends at POS before
3535 the overlays ends at PREV. */
3537 /* At first, find a place where disordered overlays should be linked
3538 in. It is where an overlay which end before POS exists. (i.e. an
3539 overlay whose ending marker is after-insertion-marker if disorder
3542 && (XSETMISC (tem
, tail
),
3543 (end
= OVERLAY_POSITION (OVERLAY_END (tem
))) >= pos
))
3549 /* If we don't find such an overlay,
3550 or the found one ends before PREV,
3551 or the found one is the last one in the list,
3552 we don't have to fix anything. */
3553 if (!tail
|| end
< prev
|| !tail
->next
)
3556 right_pair
= parent
;
3560 /* Now, end position of overlays in the list TAIL should be before
3561 or equal to PREV. In the loop, an overlay which ends at POS is
3562 moved ahead to the place indicated by the CDR of RIGHT_PAIR. If
3563 we found an overlay which ends before PREV, the remaining
3564 overlays are in correct order. */
3567 XSETMISC (tem
, tail
);
3568 end
= OVERLAY_POSITION (OVERLAY_END (tem
));
3571 { /* This overlay is disordered. */
3572 struct Lisp_Overlay
*found
= tail
;
3574 /* Unlink the found overlay. */
3576 parent
->next
= tail
;
3577 /* Move an overlay at RIGHT_PLACE to the next of the found one,
3578 and link it into the right place. */
3581 found
->next
= bp
->overlays_before
;
3582 bp
->overlays_before
= found
;
3586 found
->next
= right_pair
->next
;
3587 right_pair
->next
= found
;
3590 else if (end
== prev
)
3595 else /* No more disordered overlay. */
3600 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
3601 doc
: /* Return t if OBJECT is an overlay. */)
3605 return (OVERLAYP (object
) ? Qt
: Qnil
);
3608 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
3609 doc
: /* Create a new overlay with range BEG to END in BUFFER.
3610 If omitted, BUFFER defaults to the current buffer.
3611 BEG and END may be integers or markers.
3612 The fourth arg FRONT-ADVANCE, if non-nil, makes the marker
3613 for the front of the overlay advance when text is inserted there
3614 \(which means the text *is not* included in the overlay).
3615 The fifth arg REAR-ADVANCE, if non-nil, makes the marker
3616 for the rear of the overlay advance when text is inserted there
3617 \(which means the text *is* included in the overlay). */)
3618 (beg
, end
, buffer
, front_advance
, rear_advance
)
3619 Lisp_Object beg
, end
, buffer
;
3620 Lisp_Object front_advance
, rear_advance
;
3622 Lisp_Object overlay
;
3626 XSETBUFFER (buffer
, current_buffer
);
3628 CHECK_BUFFER (buffer
);
3630 && ! EQ (Fmarker_buffer (beg
), buffer
))
3631 error ("Marker points into wrong buffer");
3633 && ! EQ (Fmarker_buffer (end
), buffer
))
3634 error ("Marker points into wrong buffer");
3636 CHECK_NUMBER_COERCE_MARKER (beg
);
3637 CHECK_NUMBER_COERCE_MARKER (end
);
3639 if (XINT (beg
) > XINT (end
))
3642 temp
= beg
; beg
= end
; end
= temp
;
3645 b
= XBUFFER (buffer
);
3647 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
3648 end
= Fset_marker (Fmake_marker (), end
, buffer
);
3650 if (!NILP (front_advance
))
3651 XMARKER (beg
)->insertion_type
= 1;
3652 if (!NILP (rear_advance
))
3653 XMARKER (end
)->insertion_type
= 1;
3655 overlay
= allocate_misc ();
3656 XMISCTYPE (overlay
) = Lisp_Misc_Overlay
;
3657 XOVERLAY (overlay
)->start
= beg
;
3658 XOVERLAY (overlay
)->end
= end
;
3659 XOVERLAY (overlay
)->plist
= Qnil
;
3660 XOVERLAY (overlay
)->next
= NULL
;
3662 /* Put the new overlay on the wrong list. */
3663 end
= OVERLAY_END (overlay
);
3664 if (OVERLAY_POSITION (end
) < b
->overlay_center
)
3666 if (b
->overlays_after
)
3667 XOVERLAY (overlay
)->next
= b
->overlays_after
;
3668 b
->overlays_after
= XOVERLAY (overlay
);
3672 if (b
->overlays_before
)
3673 XOVERLAY (overlay
)->next
= b
->overlays_before
;
3674 b
->overlays_before
= XOVERLAY (overlay
);
3677 /* This puts it in the right list, and in the right order. */
3678 recenter_overlay_lists (b
, b
->overlay_center
);
3680 /* We don't need to redisplay the region covered by the overlay, because
3681 the overlay has no properties at the moment. */
3686 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3689 modify_overlay (buf
, start
, end
)
3691 EMACS_INT start
, end
;
3700 BUF_COMPUTE_UNCHANGED (buf
, start
, end
);
3702 /* If this is a buffer not in the selected window,
3703 we must do other windows. */
3704 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
3705 windows_or_buffers_changed
= 1;
3706 /* If multiple windows show this buffer, we must do other windows. */
3707 else if (buffer_shared
> 1)
3708 windows_or_buffers_changed
= 1;
3709 /* If we modify an overlay at the end of the buffer, we cannot
3710 be sure that window end is still valid. */
3711 else if (end
>= ZV
&& start
<= ZV
)
3712 windows_or_buffers_changed
= 1;
3714 ++BUF_OVERLAY_MODIFF (buf
);
3718 Lisp_Object
Fdelete_overlay ();
3720 static struct Lisp_Overlay
*
3721 unchain_overlay (list
, overlay
)
3722 struct Lisp_Overlay
*list
, *overlay
;
3724 struct Lisp_Overlay
*tmp
, *prev
;
3725 for (tmp
= list
, prev
= NULL
; tmp
; prev
= tmp
, tmp
= tmp
->next
)
3729 prev
->next
= tmp
->next
;
3732 overlay
->next
= NULL
;
3738 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
3739 doc
: /* Set the endpoints of OVERLAY to BEG and END in BUFFER.
3740 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
3741 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
3743 (overlay
, beg
, end
, buffer
)
3744 Lisp_Object overlay
, beg
, end
, buffer
;
3746 struct buffer
*b
, *ob
;
3747 Lisp_Object obuffer
;
3748 int count
= SPECPDL_INDEX ();
3750 CHECK_OVERLAY (overlay
);
3752 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3754 XSETBUFFER (buffer
, current_buffer
);
3755 CHECK_BUFFER (buffer
);
3758 && ! EQ (Fmarker_buffer (beg
), buffer
))
3759 error ("Marker points into wrong buffer");
3761 && ! EQ (Fmarker_buffer (end
), buffer
))
3762 error ("Marker points into wrong buffer");
3764 CHECK_NUMBER_COERCE_MARKER (beg
);
3765 CHECK_NUMBER_COERCE_MARKER (end
);
3767 if (XINT (beg
) == XINT (end
) && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
3768 return Fdelete_overlay (overlay
);
3770 if (XINT (beg
) > XINT (end
))
3773 temp
= beg
; beg
= end
; end
= temp
;
3776 specbind (Qinhibit_quit
, Qt
);
3778 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3779 b
= XBUFFER (buffer
);
3780 ob
= BUFFERP (obuffer
) ? XBUFFER (obuffer
) : (struct buffer
*) 0;
3782 /* If the overlay has changed buffers, do a thorough redisplay. */
3783 if (!EQ (buffer
, obuffer
))
3785 /* Redisplay where the overlay was. */
3786 if (!NILP (obuffer
))
3791 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3792 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3794 modify_overlay (ob
, o_beg
, o_end
);
3797 /* Redisplay where the overlay is going to be. */
3798 modify_overlay (b
, XINT (beg
), XINT (end
));
3801 /* Redisplay the area the overlay has just left, or just enclosed. */
3805 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3806 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3808 if (o_beg
== XINT (beg
))
3809 modify_overlay (b
, o_end
, XINT (end
));
3810 else if (o_end
== XINT (end
))
3811 modify_overlay (b
, o_beg
, XINT (beg
));
3814 if (XINT (beg
) < o_beg
) o_beg
= XINT (beg
);
3815 if (XINT (end
) > o_end
) o_end
= XINT (end
);
3816 modify_overlay (b
, o_beg
, o_end
);
3820 if (!NILP (obuffer
))
3823 = unchain_overlay (ob
->overlays_before
, XOVERLAY (overlay
));
3825 = unchain_overlay (ob
->overlays_after
, XOVERLAY (overlay
));
3826 eassert (XOVERLAY (overlay
)->next
== NULL
);
3829 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
3830 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
3832 /* Put the overlay on the wrong list. */
3833 end
= OVERLAY_END (overlay
);
3834 if (OVERLAY_POSITION (end
) < b
->overlay_center
)
3836 XOVERLAY (overlay
)->next
= b
->overlays_after
;
3837 b
->overlays_after
= XOVERLAY (overlay
);
3841 XOVERLAY (overlay
)->next
= b
->overlays_before
;
3842 b
->overlays_before
= XOVERLAY (overlay
);
3845 /* This puts it in the right list, and in the right order. */
3846 recenter_overlay_lists (b
, b
->overlay_center
);
3848 return unbind_to (count
, overlay
);
3851 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
3852 doc
: /* Delete the overlay OVERLAY from its buffer. */)
3854 Lisp_Object overlay
;
3858 int count
= SPECPDL_INDEX ();
3860 CHECK_OVERLAY (overlay
);
3862 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3866 b
= XBUFFER (buffer
);
3867 specbind (Qinhibit_quit
, Qt
);
3869 b
->overlays_before
= unchain_overlay (b
->overlays_before
,XOVERLAY (overlay
));
3870 b
->overlays_after
= unchain_overlay (b
->overlays_after
, XOVERLAY (overlay
));
3871 eassert (XOVERLAY (overlay
)->next
== NULL
);
3873 marker_position (OVERLAY_START (overlay
)),
3874 marker_position (OVERLAY_END (overlay
)));
3875 Fset_marker (OVERLAY_START (overlay
), Qnil
, Qnil
);
3876 Fset_marker (OVERLAY_END (overlay
), Qnil
, Qnil
);
3878 /* When deleting an overlay with before or after strings, turn off
3879 display optimizations for the affected buffer, on the basis that
3880 these strings may contain newlines. This is easier to do than to
3881 check for that situation during redisplay. */
3882 if (!windows_or_buffers_changed
3883 && (!NILP (Foverlay_get (overlay
, Qbefore_string
))
3884 || !NILP (Foverlay_get (overlay
, Qafter_string
))))
3885 b
->prevent_redisplay_optimizations_p
= 1;
3887 return unbind_to (count
, Qnil
);
3890 /* Overlay dissection functions. */
3892 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3893 doc
: /* Return the position at which OVERLAY starts. */)
3895 Lisp_Object overlay
;
3897 CHECK_OVERLAY (overlay
);
3899 return (Fmarker_position (OVERLAY_START (overlay
)));
3902 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3903 doc
: /* Return the position at which OVERLAY ends. */)
3905 Lisp_Object overlay
;
3907 CHECK_OVERLAY (overlay
);
3909 return (Fmarker_position (OVERLAY_END (overlay
)));
3912 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3913 doc
: /* Return the buffer OVERLAY belongs to.
3914 Return nil if OVERLAY has been deleted. */)
3916 Lisp_Object overlay
;
3918 CHECK_OVERLAY (overlay
);
3920 return Fmarker_buffer (OVERLAY_START (overlay
));
3923 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3924 doc
: /* Return a list of the properties on OVERLAY.
3925 This is a copy of OVERLAY's plist; modifying its conses has no effect on
3928 Lisp_Object overlay
;
3930 CHECK_OVERLAY (overlay
);
3932 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3936 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3937 doc
: /* Return a list of the overlays that contain the character at POS. */)
3942 Lisp_Object
*overlay_vec
;
3946 CHECK_NUMBER_COERCE_MARKER (pos
);
3949 /* We can't use alloca here because overlays_at can call xrealloc. */
3950 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3952 /* Put all the overlays we want in a vector in overlay_vec.
3953 Store the length in len. */
3954 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3955 (int *) 0, (int *) 0, 0);
3957 /* Make a list of them all. */
3958 result
= Flist (noverlays
, overlay_vec
);
3960 xfree (overlay_vec
);
3964 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3965 doc
: /* Return a list of the overlays that overlap the region BEG ... END.
3966 Overlap means that at least one character is contained within the overlay
3967 and also contained within the specified region.
3968 Empty overlays are included in the result if they are located at BEG
3969 or between BEG and END. */)
3971 Lisp_Object beg
, end
;
3974 Lisp_Object
*overlay_vec
;
3978 CHECK_NUMBER_COERCE_MARKER (beg
);
3979 CHECK_NUMBER_COERCE_MARKER (end
);
3982 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
3984 /* Put all the overlays we want in a vector in overlay_vec.
3985 Store the length in len. */
3986 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3987 (int *) 0, (int *) 0);
3989 /* Make a list of them all. */
3990 result
= Flist (noverlays
, overlay_vec
);
3992 xfree (overlay_vec
);
3996 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3998 doc
: /* Return the next position after POS where an overlay starts or ends.
3999 If there are no overlay boundaries from POS to (point-max),
4000 the value is (point-max). */)
4006 Lisp_Object
*overlay_vec
;
4010 CHECK_NUMBER_COERCE_MARKER (pos
);
4013 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
4015 /* Put all the overlays we want in a vector in overlay_vec.
4016 Store the length in len.
4017 endpos gets the position where the next overlay starts. */
4018 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
4019 &endpos
, (int *) 0, 1);
4021 /* If any of these overlays ends before endpos,
4022 use its ending point instead. */
4023 for (i
= 0; i
< noverlays
; i
++)
4028 oend
= OVERLAY_END (overlay_vec
[i
]);
4029 oendpos
= OVERLAY_POSITION (oend
);
4030 if (oendpos
< endpos
)
4034 xfree (overlay_vec
);
4035 return make_number (endpos
);
4038 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
4039 Sprevious_overlay_change
, 1, 1, 0,
4040 doc
: /* Return the previous position before POS where an overlay starts or ends.
4041 If there are no overlay boundaries from (point-min) to POS,
4042 the value is (point-min). */)
4048 Lisp_Object
*overlay_vec
;
4051 CHECK_NUMBER_COERCE_MARKER (pos
);
4053 /* At beginning of buffer, we know the answer;
4054 avoid bug subtracting 1 below. */
4055 if (XINT (pos
) == BEGV
)
4059 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
4061 /* Put all the overlays we want in a vector in overlay_vec.
4062 Store the length in len.
4063 prevpos gets the position of the previous change. */
4064 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
4065 (int *) 0, &prevpos
, 1);
4067 xfree (overlay_vec
);
4068 return make_number (prevpos
);
4071 /* These functions are for debugging overlays. */
4073 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
4074 doc
: /* Return a pair of lists giving all the overlays of the current buffer.
4075 The car has all the overlays before the overlay center;
4076 the cdr has all the overlays after the overlay center.
4077 Recentering overlays moves overlays between these lists.
4078 The lists you get are copies, so that changing them has no effect.
4079 However, the overlays you get are the real objects that the buffer uses. */)
4082 struct Lisp_Overlay
*ol
;
4083 Lisp_Object before
= Qnil
, after
= Qnil
, tmp
;
4084 for (ol
= current_buffer
->overlays_before
; ol
; ol
= ol
->next
)
4087 before
= Fcons (tmp
, before
);
4089 for (ol
= current_buffer
->overlays_after
; ol
; ol
= ol
->next
)
4092 after
= Fcons (tmp
, after
);
4094 return Fcons (Fnreverse (before
), Fnreverse (after
));
4097 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
4098 doc
: /* Recenter the overlays of the current buffer around position POS.
4099 That makes overlay lookup faster for positions near POS (but perhaps slower
4100 for positions far away from POS). */)
4104 CHECK_NUMBER_COERCE_MARKER (pos
);
4106 recenter_overlay_lists (current_buffer
, XINT (pos
));
4110 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
4111 doc
: /* Get the property of overlay OVERLAY with property name PROP. */)
4113 Lisp_Object overlay
, prop
;
4115 CHECK_OVERLAY (overlay
);
4116 return lookup_char_property (XOVERLAY (overlay
)->plist
, prop
, 0);
4119 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
4120 doc
: /* Set one property of overlay OVERLAY: give property PROP value VALUE. */)
4121 (overlay
, prop
, value
)
4122 Lisp_Object overlay
, prop
, value
;
4124 Lisp_Object tail
, buffer
;
4127 CHECK_OVERLAY (overlay
);
4129 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
4131 for (tail
= XOVERLAY (overlay
)->plist
;
4132 CONSP (tail
) && CONSP (XCDR (tail
));
4133 tail
= XCDR (XCDR (tail
)))
4134 if (EQ (XCAR (tail
), prop
))
4136 changed
= !EQ (XCAR (XCDR (tail
)), value
);
4137 XSETCAR (XCDR (tail
), value
);
4140 /* It wasn't in the list, so add it to the front. */
4141 changed
= !NILP (value
);
4142 XOVERLAY (overlay
)->plist
4143 = Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
));
4145 if (! NILP (buffer
))
4148 modify_overlay (XBUFFER (buffer
),
4149 marker_position (OVERLAY_START (overlay
)),
4150 marker_position (OVERLAY_END (overlay
)));
4151 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
4152 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
4153 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
4154 Fdelete_overlay (overlay
);
4160 /* Subroutine of report_overlay_modification. */
4162 /* Lisp vector holding overlay hook functions to call.
4163 Vector elements come in pairs.
4164 Each even-index element is a list of hook functions.
4165 The following odd-index element is the overlay they came from.
4167 Before the buffer change, we fill in this vector
4168 as we call overlay hook functions.
4169 After the buffer change, we get the functions to call from this vector.
4170 This way we always call the same functions before and after the change. */
4171 static Lisp_Object last_overlay_modification_hooks
;
4173 /* Number of elements actually used in last_overlay_modification_hooks. */
4174 static int last_overlay_modification_hooks_used
;
4176 /* Add one functionlist/overlay pair
4177 to the end of last_overlay_modification_hooks. */
4180 add_overlay_mod_hooklist (functionlist
, overlay
)
4181 Lisp_Object functionlist
, overlay
;
4183 int oldsize
= XVECTOR (last_overlay_modification_hooks
)->size
;
4185 if (last_overlay_modification_hooks_used
== oldsize
)
4186 last_overlay_modification_hooks
= larger_vector
4187 (last_overlay_modification_hooks
, oldsize
* 2, Qnil
);
4188 AREF (last_overlay_modification_hooks
, last_overlay_modification_hooks_used
++) = functionlist
;
4189 AREF (last_overlay_modification_hooks
, last_overlay_modification_hooks_used
++) = overlay
;
4192 /* Run the modification-hooks of overlays that include
4193 any part of the text in START to END.
4194 If this change is an insertion, also
4195 run the insert-before-hooks of overlay starting at END,
4196 and the insert-after-hooks of overlay ending at START.
4198 This is called both before and after the modification.
4199 AFTER is nonzero when we call after the modification.
4201 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
4202 When AFTER is nonzero, they are the start position,
4203 the position after the inserted new text,
4204 and the length of deleted or replaced old text. */
4207 report_overlay_modification (start
, end
, after
, arg1
, arg2
, arg3
)
4208 Lisp_Object start
, end
;
4210 Lisp_Object arg1
, arg2
, arg3
;
4212 Lisp_Object prop
, overlay
;
4213 struct Lisp_Overlay
*tail
;
4214 /* 1 if this change is an insertion. */
4215 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
4216 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4221 /* We used to run the functions as soon as we found them and only register
4222 them in last_overlay_modification_hooks for the purpose of the `after'
4223 case. But running elisp code as we traverse the list of overlays is
4224 painful because the list can be modified by the elisp code so we had to
4225 copy at several places. We now simply do a read-only traversal that
4226 only collects the functions to run and we run them afterwards. It's
4227 simpler, especially since all the code was already there. -stef */
4231 /* We are being called before a change.
4232 Scan the overlays to find the functions to call. */
4233 last_overlay_modification_hooks_used
= 0;
4234 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
4236 int startpos
, endpos
;
4237 Lisp_Object ostart
, oend
;
4239 XSETMISC (overlay
, tail
);
4241 ostart
= OVERLAY_START (overlay
);
4242 oend
= OVERLAY_END (overlay
);
4243 endpos
= OVERLAY_POSITION (oend
);
4244 if (XFASTINT (start
) > endpos
)
4246 startpos
= OVERLAY_POSITION (ostart
);
4247 if (insertion
&& (XFASTINT (start
) == startpos
4248 || XFASTINT (end
) == startpos
))
4250 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
4252 add_overlay_mod_hooklist (prop
, overlay
);
4254 if (insertion
&& (XFASTINT (start
) == endpos
4255 || XFASTINT (end
) == endpos
))
4257 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
4259 add_overlay_mod_hooklist (prop
, overlay
);
4261 /* Test for intersecting intervals. This does the right thing
4262 for both insertion and deletion. */
4263 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
4265 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
4267 add_overlay_mod_hooklist (prop
, overlay
);
4271 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
4273 int startpos
, endpos
;
4274 Lisp_Object ostart
, oend
;
4276 XSETMISC (overlay
, tail
);
4278 ostart
= OVERLAY_START (overlay
);
4279 oend
= OVERLAY_END (overlay
);
4280 startpos
= OVERLAY_POSITION (ostart
);
4281 endpos
= OVERLAY_POSITION (oend
);
4282 if (XFASTINT (end
) < startpos
)
4284 if (insertion
&& (XFASTINT (start
) == startpos
4285 || XFASTINT (end
) == startpos
))
4287 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
4289 add_overlay_mod_hooklist (prop
, overlay
);
4291 if (insertion
&& (XFASTINT (start
) == endpos
4292 || XFASTINT (end
) == endpos
))
4294 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
4296 add_overlay_mod_hooklist (prop
, overlay
);
4298 /* Test for intersecting intervals. This does the right thing
4299 for both insertion and deletion. */
4300 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
4302 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
4304 add_overlay_mod_hooklist (prop
, overlay
);
4309 GCPRO4 (overlay
, arg1
, arg2
, arg3
);
4311 /* Call the functions recorded in last_overlay_modification_hooks.
4312 First copy the vector contents, in case some of these hooks
4313 do subsequent modification of the buffer. */
4314 int size
= last_overlay_modification_hooks_used
;
4315 Lisp_Object
*copy
= (Lisp_Object
*) alloca (size
* sizeof (Lisp_Object
));
4318 bcopy (XVECTOR (last_overlay_modification_hooks
)->contents
,
4319 copy
, size
* sizeof (Lisp_Object
));
4321 gcpro1
.nvars
= size
;
4323 for (i
= 0; i
< size
;)
4325 Lisp_Object prop
, overlay
;
4327 overlay
= copy
[i
++];
4328 call_overlay_mod_hooks (prop
, overlay
, after
, arg1
, arg2
, arg3
);
4335 call_overlay_mod_hooks (list
, overlay
, after
, arg1
, arg2
, arg3
)
4336 Lisp_Object list
, overlay
;
4338 Lisp_Object arg1
, arg2
, arg3
;
4340 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4342 GCPRO4 (list
, arg1
, arg2
, arg3
);
4344 while (CONSP (list
))
4347 call4 (XCAR (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
4349 call5 (XCAR (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
4355 /* Delete any zero-sized overlays at position POS, if the `evaporate'
4358 evaporate_overlays (pos
)
4361 Lisp_Object overlay
, hit_list
;
4362 struct Lisp_Overlay
*tail
;
4365 if (pos
<= current_buffer
->overlay_center
)
4366 for (tail
= current_buffer
->overlays_before
; tail
; tail
= tail
->next
)
4369 XSETMISC (overlay
, tail
);
4370 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4373 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
4374 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4375 hit_list
= Fcons (overlay
, hit_list
);
4378 for (tail
= current_buffer
->overlays_after
; tail
; tail
= tail
->next
)
4381 XSETMISC (overlay
, tail
);
4382 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4385 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
4386 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4387 hit_list
= Fcons (overlay
, hit_list
);
4389 for (; CONSP (hit_list
); hit_list
= XCDR (hit_list
))
4390 Fdelete_overlay (XCAR (hit_list
));
4393 /* Somebody has tried to store a value with an unacceptable type
4394 in the slot with offset OFFSET. */
4397 buffer_slot_type_mismatch (sym
, type
)
4406 type_name
= "integers";
4410 type_name
= "strings";
4414 type_name
= "symbols";
4421 error ("Only %s should be stored in the buffer-local variable %s",
4422 type_name
, SDATA (SYMBOL_NAME (sym
)));
4426 /***********************************************************************
4427 Allocation with mmap
4428 ***********************************************************************/
4430 #ifdef USE_MMAP_FOR_BUFFERS
4432 #include <sys/types.h>
4433 #include <sys/mman.h>
4436 #ifdef MAP_ANONYMOUS
4437 #define MAP_ANON MAP_ANONYMOUS
4444 #define MAP_FAILED ((void *) -1)
4457 /* Memory is allocated in regions which are mapped using mmap(2).
4458 The current implementation lets the system select mapped
4459 addresses; we're not using MAP_FIXED in general, except when
4460 trying to enlarge regions.
4462 Each mapped region starts with a mmap_region structure, the user
4463 area starts after that structure, aligned to MEM_ALIGN.
4465 +-----------------------+
4466 | struct mmap_info + |
4468 +-----------------------+
4472 +-----------------------+ */
4476 /* User-specified size. */
4477 size_t nbytes_specified
;
4479 /* Number of bytes mapped */
4480 size_t nbytes_mapped
;
4482 /* Pointer to the location holding the address of the memory
4483 allocated with the mmap'd block. The variable actually points
4484 after this structure. */
4487 /* Next and previous in list of all mmap'd regions. */
4488 struct mmap_region
*next
, *prev
;
4491 /* Doubly-linked list of mmap'd regions. */
4493 static struct mmap_region
*mmap_regions
;
4495 /* File descriptor for mmap. If we don't have anonymous mapping,
4496 /dev/zero will be opened on it. */
4500 /* Temporary storage for mmap_set_vars, see there. */
4502 static struct mmap_region
*mmap_regions_1
;
4503 static int mmap_fd_1
;
4505 /* Page size on this system. */
4507 static int mmap_page_size
;
4509 /* 1 means mmap has been intialized. */
4511 static int mmap_initialized_p
;
4513 /* Value is X rounded up to the next multiple of N. */
4515 #define ROUND(X, N) (((X) + (N) - 1) / (N) * (N))
4517 /* Size of mmap_region structure plus padding. */
4519 #define MMAP_REGION_STRUCT_SIZE \
4520 ROUND (sizeof (struct mmap_region), MEM_ALIGN)
4522 /* Given a pointer P to the start of the user-visible part of a mapped
4523 region, return a pointer to the start of the region. */
4525 #define MMAP_REGION(P) \
4526 ((struct mmap_region *) ((char *) (P) - MMAP_REGION_STRUCT_SIZE))
4528 /* Given a pointer P to the start of a mapped region, return a pointer
4529 to the start of the user-visible part of the region. */
4531 #define MMAP_USER_AREA(P) \
4532 ((POINTER_TYPE *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE))
4534 #define MEM_ALIGN sizeof (double)
4536 /* Predicate returning true if part of the address range [START .. END]
4537 is currently mapped. Used to prevent overwriting an existing
4540 Default is to conservativly assume the address range is occupied by
4541 something else. This can be overridden by system configuration
4542 files if system-specific means to determine this exists. */
4544 #ifndef MMAP_ALLOCATED_P
4545 #define MMAP_ALLOCATED_P(start, end) 1
4548 /* Function prototypes. */
4550 static int mmap_free_1
P_ ((struct mmap_region
*));
4551 static int mmap_enlarge
P_ ((struct mmap_region
*, int));
4552 static struct mmap_region
*mmap_find
P_ ((POINTER_TYPE
*, POINTER_TYPE
*));
4553 static POINTER_TYPE
*mmap_alloc
P_ ((POINTER_TYPE
**, size_t));
4554 static POINTER_TYPE
*mmap_realloc
P_ ((POINTER_TYPE
**, size_t));
4555 static void mmap_free
P_ ((POINTER_TYPE
**ptr
));
4556 static void mmap_init
P_ ((void));
4559 /* Return a region overlapping address range START...END, or null if
4560 none. END is not including, i.e. the last byte in the range
4563 static struct mmap_region
*
4564 mmap_find (start
, end
)
4565 POINTER_TYPE
*start
, *end
;
4567 struct mmap_region
*r
;
4568 char *s
= (char *) start
, *e
= (char *) end
;
4570 for (r
= mmap_regions
; r
; r
= r
->next
)
4572 char *rstart
= (char *) r
;
4573 char *rend
= rstart
+ r
->nbytes_mapped
;
4575 if (/* First byte of range, i.e. START, in this region? */
4576 (s
>= rstart
&& s
< rend
)
4577 /* Last byte of range, i.e. END - 1, in this region? */
4578 || (e
> rstart
&& e
<= rend
)
4579 /* First byte of this region in the range? */
4580 || (rstart
>= s
&& rstart
< e
)
4581 /* Last byte of this region in the range? */
4582 || (rend
> s
&& rend
<= e
))
4590 /* Unmap a region. P is a pointer to the start of the user-araa of
4591 the region. Value is non-zero if successful. */
4595 struct mmap_region
*r
;
4598 r
->next
->prev
= r
->prev
;
4600 r
->prev
->next
= r
->next
;
4602 mmap_regions
= r
->next
;
4604 if (munmap ((POINTER_TYPE
*) r
, r
->nbytes_mapped
) == -1)
4606 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4614 /* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R.
4615 Value is non-zero if successful. */
4618 mmap_enlarge (r
, npages
)
4619 struct mmap_region
*r
;
4622 char *region_end
= (char *) r
+ r
->nbytes_mapped
;
4628 /* Unmap pages at the end of the region. */
4629 nbytes
= - npages
* mmap_page_size
;
4630 if (munmap (region_end
- nbytes
, nbytes
) == -1)
4631 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4634 r
->nbytes_mapped
-= nbytes
;
4638 else if (npages
> 0)
4640 nbytes
= npages
* mmap_page_size
;
4642 /* Try to map additional pages at the end of the region. We
4643 cannot do this if the address range is already occupied by
4644 something else because mmap deletes any previous mapping.
4645 I'm not sure this is worth doing, let's see. */
4646 if (!MMAP_ALLOCATED_P (region_end
, region_end
+ nbytes
))
4650 p
= mmap (region_end
, nbytes
, PROT_READ
| PROT_WRITE
,
4651 MAP_ANON
| MAP_PRIVATE
| MAP_FIXED
, mmap_fd
, 0);
4652 if (p
== MAP_FAILED
)
4653 ; /* fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); */
4654 else if (p
!= (POINTER_TYPE
*) region_end
)
4656 /* Kernels are free to choose a different address. In
4657 that case, unmap what we've mapped above; we have
4659 if (munmap (p
, nbytes
) == -1)
4660 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4664 r
->nbytes_mapped
+= nbytes
;
4674 /* Set or reset variables holding references to mapped regions. If
4675 RESTORE_P is zero, set all variables to null. If RESTORE_P is
4676 non-zero, set all variables to the start of the user-areas
4679 This function is called from Fdump_emacs to ensure that the dumped
4680 Emacs doesn't contain references to memory that won't be mapped
4681 when Emacs starts. */
4684 mmap_set_vars (restore_p
)
4687 struct mmap_region
*r
;
4691 mmap_regions
= mmap_regions_1
;
4692 mmap_fd
= mmap_fd_1
;
4693 for (r
= mmap_regions
; r
; r
= r
->next
)
4694 *r
->var
= MMAP_USER_AREA (r
);
4698 for (r
= mmap_regions
; r
; r
= r
->next
)
4700 mmap_regions_1
= mmap_regions
;
4701 mmap_regions
= NULL
;
4702 mmap_fd_1
= mmap_fd
;
4708 /* Allocate a block of storage large enough to hold NBYTES bytes of
4709 data. A pointer to the data is returned in *VAR. VAR is thus the
4710 address of some variable which will use the data area.
4712 The allocation of 0 bytes is valid.
4714 If we can't allocate the necessary memory, set *VAR to null, and
4717 static POINTER_TYPE
*
4718 mmap_alloc (var
, nbytes
)
4727 map
= ROUND (nbytes
+ MMAP_REGION_STRUCT_SIZE
, mmap_page_size
);
4728 p
= mmap (NULL
, map
, PROT_READ
| PROT_WRITE
, MAP_ANON
| MAP_PRIVATE
,
4731 if (p
== MAP_FAILED
)
4733 if (errno
!= ENOMEM
)
4734 fprintf (stderr
, "mmap: %s\n", emacs_strerror (errno
));
4739 struct mmap_region
*r
= (struct mmap_region
*) p
;
4741 r
->nbytes_specified
= nbytes
;
4742 r
->nbytes_mapped
= map
;
4745 r
->next
= mmap_regions
;
4750 p
= MMAP_USER_AREA (p
);
4757 /* Given a pointer at address VAR to data allocated with mmap_alloc,
4758 resize it to size NBYTES. Change *VAR to reflect the new block,
4759 and return this value. If more memory cannot be allocated, then
4760 leave *VAR unchanged, and return null. */
4762 static POINTER_TYPE
*
4763 mmap_realloc (var
, nbytes
)
4767 POINTER_TYPE
*result
;
4772 result
= mmap_alloc (var
, nbytes
);
4773 else if (nbytes
== 0)
4776 result
= mmap_alloc (var
, nbytes
);
4780 struct mmap_region
*r
= MMAP_REGION (*var
);
4781 size_t room
= r
->nbytes_mapped
- MMAP_REGION_STRUCT_SIZE
;
4786 POINTER_TYPE
*old_ptr
= *var
;
4788 /* Try to map additional pages at the end of the region.
4789 If that fails, allocate a new region, copy data
4790 from the old region, then free it. */
4791 if (mmap_enlarge (r
, (ROUND (nbytes
- room
, mmap_page_size
)
4794 r
->nbytes_specified
= nbytes
;
4795 *var
= result
= old_ptr
;
4797 else if (mmap_alloc (var
, nbytes
))
4799 bcopy (old_ptr
, *var
, r
->nbytes_specified
);
4800 mmap_free_1 (MMAP_REGION (old_ptr
));
4802 r
= MMAP_REGION (result
);
4803 r
->nbytes_specified
= nbytes
;
4811 else if (room
- nbytes
>= mmap_page_size
)
4813 /* Shrinking by at least a page. Let's give some
4814 memory back to the system.
4816 The extra parens are to make the division happens first,
4817 on positive values, so we know it will round towards
4819 mmap_enlarge (r
, - ((room
- nbytes
) / mmap_page_size
));
4821 r
->nbytes_specified
= nbytes
;
4825 /* Leave it alone. */
4827 r
->nbytes_specified
= nbytes
;
4835 /* Free a block of relocatable storage whose data is pointed to by
4836 PTR. Store 0 in *PTR to show there's no block allocated. */
4846 mmap_free_1 (MMAP_REGION (*var
));
4852 /* Perform necessary intializations for the use of mmap. */
4858 /* The value of mmap_fd is initially 0 in temacs, and -1
4859 in a dumped Emacs. */
4862 /* No anonymous mmap -- we need the file descriptor. */
4863 mmap_fd
= open ("/dev/zero", O_RDONLY
);
4865 fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno
));
4867 #endif /* MAP_ANON == 0 */
4869 if (mmap_initialized_p
)
4871 mmap_initialized_p
= 1;
4877 mmap_page_size
= getpagesize ();
4880 #endif /* USE_MMAP_FOR_BUFFERS */
4884 /***********************************************************************
4885 Buffer-text Allocation
4886 ***********************************************************************/
4889 extern POINTER_TYPE
*r_alloc
P_ ((POINTER_TYPE
**, size_t));
4890 extern POINTER_TYPE
*r_re_alloc
P_ ((POINTER_TYPE
**, size_t));
4891 extern void r_alloc_free
P_ ((POINTER_TYPE
**ptr
));
4892 #endif /* REL_ALLOC */
4895 /* Allocate NBYTES bytes for buffer B's text buffer. */
4898 alloc_buffer_text (b
, nbytes
)
4905 #if defined USE_MMAP_FOR_BUFFERS
4906 p
= mmap_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4907 #elif defined REL_ALLOC
4908 p
= r_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4910 p
= xmalloc (nbytes
);
4919 b
->text
->beg
= (unsigned char *) p
;
4923 /* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means
4927 enlarge_buffer_text (b
, delta
)
4932 size_t nbytes
= (BUF_Z_BYTE (b
) - BUF_BEG_BYTE (b
) + BUF_GAP_SIZE (b
) + 1
4935 #if defined USE_MMAP_FOR_BUFFERS
4936 p
= mmap_realloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4937 #elif defined REL_ALLOC
4938 p
= r_re_alloc ((POINTER_TYPE
**) &b
->text
->beg
, nbytes
);
4940 p
= xrealloc (b
->text
->beg
, nbytes
);
4949 BUF_BEG_ADDR (b
) = (unsigned char *) p
;
4954 /* Free buffer B's text buffer. */
4957 free_buffer_text (b
)
4962 #if defined USE_MMAP_FOR_BUFFERS
4963 mmap_free ((POINTER_TYPE
**) &b
->text
->beg
);
4964 #elif defined REL_ALLOC
4965 r_alloc_free ((POINTER_TYPE
**) &b
->text
->beg
);
4967 xfree (b
->text
->beg
);
4970 BUF_BEG_ADDR (b
) = NULL
;
4976 /***********************************************************************
4978 ***********************************************************************/
4985 bzero (buffer_permanent_local_flags
, sizeof buffer_permanent_local_flags
);
4987 /* Make sure all markable slots in buffer_defaults
4988 are initialized reasonably, so mark_buffer won't choke. */
4989 reset_buffer (&buffer_defaults
);
4990 reset_buffer_local_variables (&buffer_defaults
, 1);
4991 reset_buffer (&buffer_local_symbols
);
4992 reset_buffer_local_variables (&buffer_local_symbols
, 1);
4993 /* Prevent GC from getting confused. */
4994 buffer_defaults
.text
= &buffer_defaults
.own_text
;
4995 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
4996 BUF_INTERVALS (&buffer_defaults
) = 0;
4997 BUF_INTERVALS (&buffer_local_symbols
) = 0;
4998 XSETPVECTYPE (&buffer_defaults
, PVEC_BUFFER
);
4999 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
5000 XSETPVECTYPE (&buffer_local_symbols
, PVEC_BUFFER
);
5001 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
5003 /* Set up the default values of various buffer slots. */
5004 /* Must do these before making the first buffer! */
5006 /* real setup is done in bindings.el */
5007 buffer_defaults
.mode_line_format
= build_string ("%-");
5008 buffer_defaults
.header_line_format
= Qnil
;
5009 buffer_defaults
.abbrev_mode
= Qnil
;
5010 buffer_defaults
.overwrite_mode
= Qnil
;
5011 buffer_defaults
.case_fold_search
= Qt
;
5012 buffer_defaults
.auto_fill_function
= Qnil
;
5013 buffer_defaults
.selective_display
= Qnil
;
5015 buffer_defaults
.selective_display_ellipses
= Qt
;
5017 buffer_defaults
.abbrev_table
= Qnil
;
5018 buffer_defaults
.display_table
= Qnil
;
5019 buffer_defaults
.undo_list
= Qnil
;
5020 buffer_defaults
.mark_active
= Qnil
;
5021 buffer_defaults
.file_format
= Qnil
;
5022 buffer_defaults
.auto_save_file_format
= Qt
;
5023 buffer_defaults
.overlays_before
= NULL
;
5024 buffer_defaults
.overlays_after
= NULL
;
5025 buffer_defaults
.overlay_center
= BEG
;
5027 XSETFASTINT (buffer_defaults
.tab_width
, 8);
5028 buffer_defaults
.truncate_lines
= Qnil
;
5029 buffer_defaults
.ctl_arrow
= Qt
;
5030 buffer_defaults
.direction_reversed
= Qnil
;
5031 buffer_defaults
.cursor_type
= Qt
;
5032 buffer_defaults
.extra_line_spacing
= Qnil
;
5033 buffer_defaults
.cursor_in_non_selected_windows
= Qt
;
5036 buffer_defaults
.buffer_file_type
= Qnil
; /* TEXT */
5038 buffer_defaults
.enable_multibyte_characters
= Qt
;
5039 buffer_defaults
.buffer_file_coding_system
= Qnil
;
5040 XSETFASTINT (buffer_defaults
.fill_column
, 70);
5041 XSETFASTINT (buffer_defaults
.left_margin
, 0);
5042 buffer_defaults
.cache_long_line_scans
= Qnil
;
5043 buffer_defaults
.file_truename
= Qnil
;
5044 XSETFASTINT (buffer_defaults
.display_count
, 0);
5045 XSETFASTINT (buffer_defaults
.left_margin_cols
, 0);
5046 XSETFASTINT (buffer_defaults
.right_margin_cols
, 0);
5047 buffer_defaults
.left_fringe_width
= Qnil
;
5048 buffer_defaults
.right_fringe_width
= Qnil
;
5049 buffer_defaults
.fringes_outside_margins
= Qnil
;
5050 buffer_defaults
.scroll_bar_width
= Qnil
;
5051 buffer_defaults
.vertical_scroll_bar_type
= Qt
;
5052 buffer_defaults
.indicate_empty_lines
= Qnil
;
5053 buffer_defaults
.indicate_buffer_boundaries
= Qnil
;
5054 buffer_defaults
.fringe_indicator_alist
= Qnil
;
5055 buffer_defaults
.fringe_cursor_alist
= Qnil
;
5056 buffer_defaults
.scroll_up_aggressively
= Qnil
;
5057 buffer_defaults
.scroll_down_aggressively
= Qnil
;
5058 buffer_defaults
.display_time
= Qnil
;
5060 /* Assign the local-flags to the slots that have default values.
5061 The local flag is a bit that is used in the buffer
5062 to say that it has its own local value for the slot.
5063 The local flag bits are in the local_var_flags slot of the buffer. */
5065 /* Nothing can work if this isn't true */
5066 if (sizeof (EMACS_INT
) != sizeof (Lisp_Object
)) abort ();
5068 /* 0 means not a lisp var, -1 means always local, else mask */
5069 bzero (&buffer_local_flags
, sizeof buffer_local_flags
);
5070 XSETINT (buffer_local_flags
.filename
, -1);
5071 XSETINT (buffer_local_flags
.directory
, -1);
5072 XSETINT (buffer_local_flags
.backed_up
, -1);
5073 XSETINT (buffer_local_flags
.save_length
, -1);
5074 XSETINT (buffer_local_flags
.auto_save_file_name
, -1);
5075 XSETINT (buffer_local_flags
.read_only
, -1);
5076 XSETINT (buffer_local_flags
.major_mode
, -1);
5077 XSETINT (buffer_local_flags
.mode_name
, -1);
5078 XSETINT (buffer_local_flags
.undo_list
, -1);
5079 XSETINT (buffer_local_flags
.mark_active
, -1);
5080 XSETINT (buffer_local_flags
.point_before_scroll
, -1);
5081 XSETINT (buffer_local_flags
.file_truename
, -1);
5082 XSETINT (buffer_local_flags
.invisibility_spec
, -1);
5083 XSETINT (buffer_local_flags
.file_format
, -1);
5084 XSETINT (buffer_local_flags
.auto_save_file_format
, -1);
5085 XSETINT (buffer_local_flags
.display_count
, -1);
5086 XSETINT (buffer_local_flags
.display_time
, -1);
5087 XSETINT (buffer_local_flags
.enable_multibyte_characters
, -1);
5090 XSETFASTINT (buffer_local_flags
.mode_line_format
, idx
); ++idx
;
5091 XSETFASTINT (buffer_local_flags
.abbrev_mode
, idx
); ++idx
;
5092 XSETFASTINT (buffer_local_flags
.overwrite_mode
, idx
); ++idx
;
5093 XSETFASTINT (buffer_local_flags
.case_fold_search
, idx
); ++idx
;
5094 XSETFASTINT (buffer_local_flags
.auto_fill_function
, idx
); ++idx
;
5095 XSETFASTINT (buffer_local_flags
.selective_display
, idx
); ++idx
;
5097 XSETFASTINT (buffer_local_flags
.selective_display_ellipses
, idx
); ++idx
;
5099 XSETFASTINT (buffer_local_flags
.tab_width
, idx
); ++idx
;
5100 XSETFASTINT (buffer_local_flags
.truncate_lines
, idx
); ++idx
;
5101 XSETFASTINT (buffer_local_flags
.ctl_arrow
, idx
); ++idx
;
5102 XSETFASTINT (buffer_local_flags
.fill_column
, idx
); ++idx
;
5103 XSETFASTINT (buffer_local_flags
.left_margin
, idx
); ++idx
;
5104 XSETFASTINT (buffer_local_flags
.abbrev_table
, idx
); ++idx
;
5105 XSETFASTINT (buffer_local_flags
.display_table
, idx
); ++idx
;
5107 XSETFASTINT (buffer_local_flags
.buffer_file_type
, idx
);
5108 /* Make this one a permanent local. */
5109 buffer_permanent_local_flags
[idx
++] = 1;
5111 XSETFASTINT (buffer_local_flags
.syntax_table
, idx
); ++idx
;
5112 XSETFASTINT (buffer_local_flags
.cache_long_line_scans
, idx
); ++idx
;
5113 XSETFASTINT (buffer_local_flags
.category_table
, idx
); ++idx
;
5114 XSETFASTINT (buffer_local_flags
.direction_reversed
, idx
); ++idx
;
5115 XSETFASTINT (buffer_local_flags
.buffer_file_coding_system
, idx
);
5116 /* Make this one a permanent local. */
5117 buffer_permanent_local_flags
[idx
++] = 1;
5118 XSETFASTINT (buffer_local_flags
.left_margin_cols
, idx
); ++idx
;
5119 XSETFASTINT (buffer_local_flags
.right_margin_cols
, idx
); ++idx
;
5120 XSETFASTINT (buffer_local_flags
.left_fringe_width
, idx
); ++idx
;
5121 XSETFASTINT (buffer_local_flags
.right_fringe_width
, idx
); ++idx
;
5122 XSETFASTINT (buffer_local_flags
.fringes_outside_margins
, idx
); ++idx
;
5123 XSETFASTINT (buffer_local_flags
.scroll_bar_width
, idx
); ++idx
;
5124 XSETFASTINT (buffer_local_flags
.vertical_scroll_bar_type
, idx
); ++idx
;
5125 XSETFASTINT (buffer_local_flags
.indicate_empty_lines
, idx
); ++idx
;
5126 XSETFASTINT (buffer_local_flags
.indicate_buffer_boundaries
, idx
); ++idx
;
5127 XSETFASTINT (buffer_local_flags
.fringe_indicator_alist
, idx
); ++idx
;
5128 XSETFASTINT (buffer_local_flags
.fringe_cursor_alist
, idx
); ++idx
;
5129 XSETFASTINT (buffer_local_flags
.scroll_up_aggressively
, idx
); ++idx
;
5130 XSETFASTINT (buffer_local_flags
.scroll_down_aggressively
, idx
); ++idx
;
5131 XSETFASTINT (buffer_local_flags
.header_line_format
, idx
); ++idx
;
5132 XSETFASTINT (buffer_local_flags
.cursor_type
, idx
); ++idx
;
5133 XSETFASTINT (buffer_local_flags
.extra_line_spacing
, idx
); ++idx
;
5134 XSETFASTINT (buffer_local_flags
.cursor_in_non_selected_windows
, idx
); ++idx
;
5136 /* Need more room? */
5137 if (idx
>= MAX_PER_BUFFER_VARS
)
5139 last_per_buffer_idx
= idx
;
5141 Vbuffer_alist
= Qnil
;
5145 QSFundamental
= build_string ("Fundamental");
5147 Qfundamental_mode
= intern ("fundamental-mode");
5148 buffer_defaults
.major_mode
= Qfundamental_mode
;
5150 Qmode_class
= intern ("mode-class");
5152 Qprotected_field
= intern ("protected-field");
5154 Qpermanent_local
= intern ("permanent-local");
5156 Qkill_buffer_hook
= intern ("kill-buffer-hook");
5157 Fput (Qkill_buffer_hook
, Qpermanent_local
, Qt
);
5159 Qucs_set_table_for_input
= intern ("ucs-set-table-for-input");
5161 Vprin1_to_string_buffer
= Fget_buffer_create (build_string (" prin1"));
5163 /* super-magic invisible buffer */
5164 Vbuffer_alist
= Qnil
;
5166 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
5168 inhibit_modification_hooks
= 0;
5178 #ifdef USE_MMAP_FOR_BUFFERS
5180 /* When using the ralloc implementation based on mmap(2), buffer
5181 text pointers will have been set to null in the dumped Emacs.
5185 for (b
= all_buffers
; b
; b
= b
->next
)
5186 if (b
->text
->beg
== NULL
)
5187 enlarge_buffer_text (b
, 0);
5189 #endif /* USE_MMAP_FOR_BUFFERS */
5191 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
5192 if (NILP (buffer_defaults
.enable_multibyte_characters
))
5193 Fset_buffer_multibyte (Qnil
);
5195 pwd
= get_current_dir_name ();
5198 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno
));
5201 /* Maybe this should really use some standard subroutine
5202 whose definition is filename syntax dependent. */
5204 if (!(IS_DIRECTORY_SEP (pwd
[len
- 1])))
5206 /* Grow buffer to add directory separator and '\0'. */
5207 pwd
= (char *) xrealloc (pwd
, len
+ 2);
5208 pwd
[len
] = DIRECTORY_SEP
;
5209 pwd
[len
+ 1] = '\0';
5211 #endif /* not VMS */
5213 current_buffer
->directory
= make_unibyte_string (pwd
, strlen (pwd
));
5214 if (! NILP (buffer_defaults
.enable_multibyte_characters
))
5215 /* At this moment, we still don't know how to decode the
5216 directory name. So, we keep the bytes in multibyte form so
5217 that ENCODE_FILE correctly gets the original bytes. */
5218 current_buffer
->directory
5219 = string_to_multibyte (current_buffer
->directory
);
5221 /* Add /: to the front of the name
5222 if it would otherwise be treated as magic. */
5223 temp
= Ffind_file_name_handler (current_buffer
->directory
, Qt
);
5225 /* If the default dir is just /, TEMP is non-nil
5226 because of the ange-ftp completion handler.
5227 However, it is not necessary to turn / into /:/.
5228 So avoid doing that. */
5229 && strcmp ("/", SDATA (current_buffer
->directory
)))
5230 current_buffer
->directory
5231 = concat2 (build_string ("/:"), current_buffer
->directory
);
5233 temp
= get_minibuffer (0);
5234 XBUFFER (temp
)->directory
= current_buffer
->directory
;
5239 /* Similar to defvar_lisp but define a variable whose value is the Lisp
5240 Object stored in the current buffer. address is the address of the slot
5241 in the buffer that is current now. */
5243 /* TYPE is nil for a general Lisp variable.
5244 An integer specifies a type; then only LIsp values
5245 with that type code are allowed (except that nil is allowed too).
5246 LNAME is the LIsp-level variable name.
5247 VNAME is the name of the buffer slot.
5248 DOC is a dummy where you write the doc string as a comment. */
5249 #define DEFVAR_PER_BUFFER(lname, vname, type, doc) \
5250 defvar_per_buffer (lname, vname, type, 0)
5253 defvar_per_buffer (namestring
, address
, type
, doc
)
5255 Lisp_Object
*address
;
5259 Lisp_Object sym
, val
;
5262 sym
= intern (namestring
);
5263 val
= allocate_misc ();
5264 offset
= (char *)address
- (char *)current_buffer
;
5266 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
5267 XBUFFER_OBJFWD (val
)->offset
= offset
;
5268 XBUFFER_OBJFWD (val
)->slottype
= type
;
5269 SET_SYMBOL_VALUE (sym
, val
);
5270 PER_BUFFER_SYMBOL (offset
) = sym
;
5272 if (PER_BUFFER_IDX (offset
) == 0)
5273 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
5274 slot of buffer_local_flags */
5279 /* initialize the buffer routines */
5283 staticpro (&last_overlay_modification_hooks
);
5284 last_overlay_modification_hooks
5285 = Fmake_vector (make_number (10), Qnil
);
5287 staticpro (&Vbuffer_defaults
);
5288 staticpro (&Vbuffer_local_symbols
);
5289 staticpro (&Qfundamental_mode
);
5290 staticpro (&Qmode_class
);
5291 staticpro (&QSFundamental
);
5292 staticpro (&Vbuffer_alist
);
5293 staticpro (&Qprotected_field
);
5294 staticpro (&Qpermanent_local
);
5295 staticpro (&Qkill_buffer_hook
);
5296 Qoverlayp
= intern ("overlayp");
5297 staticpro (&Qoverlayp
);
5298 Qevaporate
= intern ("evaporate");
5299 staticpro (&Qevaporate
);
5300 Qmodification_hooks
= intern ("modification-hooks");
5301 staticpro (&Qmodification_hooks
);
5302 Qinsert_in_front_hooks
= intern ("insert-in-front-hooks");
5303 staticpro (&Qinsert_in_front_hooks
);
5304 Qinsert_behind_hooks
= intern ("insert-behind-hooks");
5305 staticpro (&Qinsert_behind_hooks
);
5306 Qget_file_buffer
= intern ("get-file-buffer");
5307 staticpro (&Qget_file_buffer
);
5308 Qpriority
= intern ("priority");
5309 staticpro (&Qpriority
);
5310 Qwindow
= intern ("window");
5311 staticpro (&Qwindow
);
5312 Qbefore_string
= intern ("before-string");
5313 staticpro (&Qbefore_string
);
5314 Qafter_string
= intern ("after-string");
5315 staticpro (&Qafter_string
);
5316 Qfirst_change_hook
= intern ("first-change-hook");
5317 staticpro (&Qfirst_change_hook
);
5318 Qbefore_change_functions
= intern ("before-change-functions");
5319 staticpro (&Qbefore_change_functions
);
5320 Qafter_change_functions
= intern ("after-change-functions");
5321 staticpro (&Qafter_change_functions
);
5322 staticpro (&Qucs_set_table_for_input
);
5324 Qkill_buffer_query_functions
= intern ("kill-buffer-query-functions");
5325 staticpro (&Qkill_buffer_query_functions
);
5327 Fput (Qprotected_field
, Qerror_conditions
,
5328 Fcons (Qprotected_field
, Fcons (Qerror
, Qnil
)));
5329 Fput (Qprotected_field
, Qerror_message
,
5330 build_string ("Attempt to modify a protected field"));
5332 /* All these use DEFVAR_LISP_NOPRO because the slots in
5333 buffer_defaults will all be marked via Vbuffer_defaults. */
5335 DEFVAR_LISP_NOPRO ("default-mode-line-format",
5336 &buffer_defaults
.mode_line_format
,
5337 doc
: /* Default value of `mode-line-format' for buffers that don't override it.
5338 This is the same as (default-value 'mode-line-format). */);
5340 DEFVAR_LISP_NOPRO ("default-header-line-format",
5341 &buffer_defaults
.header_line_format
,
5342 doc
: /* Default value of `header-line-format' for buffers that don't override it.
5343 This is the same as (default-value 'header-line-format). */);
5345 DEFVAR_LISP_NOPRO ("default-cursor-type", &buffer_defaults
.cursor_type
,
5346 doc
: /* Default value of `cursor-type' for buffers that don't override it.
5347 This is the same as (default-value 'cursor-type). */);
5349 DEFVAR_LISP_NOPRO ("default-line-spacing",
5350 &buffer_defaults
.extra_line_spacing
,
5351 doc
: /* Default value of `line-spacing' for buffers that don't override it.
5352 This is the same as (default-value 'line-spacing). */);
5354 DEFVAR_LISP_NOPRO ("default-cursor-in-non-selected-windows",
5355 &buffer_defaults
.cursor_in_non_selected_windows
,
5356 doc
: /* Default value of `cursor-in-non-selected-windows'.
5357 This is the same as (default-value 'cursor-in-non-selected-windows). */);
5359 DEFVAR_LISP_NOPRO ("default-abbrev-mode",
5360 &buffer_defaults
.abbrev_mode
,
5361 doc
: /* Default value of `abbrev-mode' for buffers that do not override it.
5362 This is the same as (default-value 'abbrev-mode). */);
5364 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
5365 &buffer_defaults
.ctl_arrow
,
5366 doc
: /* Default value of `ctl-arrow' for buffers that do not override it.
5367 This is the same as (default-value 'ctl-arrow). */);
5369 DEFVAR_LISP_NOPRO ("default-direction-reversed",
5370 &buffer_defaults
.direction_reversed
,
5371 doc
: /* Default value of `direction-reversed' for buffers that do not override it.
5372 This is the same as (default-value 'direction-reversed). */);
5374 DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
5375 &buffer_defaults
.enable_multibyte_characters
,
5376 doc
: /* *Default value of `enable-multibyte-characters' for buffers not overriding it.
5377 This is the same as (default-value 'enable-multibyte-characters). */);
5379 DEFVAR_LISP_NOPRO ("default-buffer-file-coding-system",
5380 &buffer_defaults
.buffer_file_coding_system
,
5381 doc
: /* Default value of `buffer-file-coding-system' for buffers not overriding it.
5382 This is the same as (default-value 'buffer-file-coding-system). */);
5384 DEFVAR_LISP_NOPRO ("default-truncate-lines",
5385 &buffer_defaults
.truncate_lines
,
5386 doc
: /* Default value of `truncate-lines' for buffers that do not override it.
5387 This is the same as (default-value 'truncate-lines). */);
5389 DEFVAR_LISP_NOPRO ("default-fill-column",
5390 &buffer_defaults
.fill_column
,
5391 doc
: /* Default value of `fill-column' for buffers that do not override it.
5392 This is the same as (default-value 'fill-column). */);
5394 DEFVAR_LISP_NOPRO ("default-left-margin",
5395 &buffer_defaults
.left_margin
,
5396 doc
: /* Default value of `left-margin' for buffers that do not override it.
5397 This is the same as (default-value 'left-margin). */);
5399 DEFVAR_LISP_NOPRO ("default-tab-width",
5400 &buffer_defaults
.tab_width
,
5401 doc
: /* Default value of `tab-width' for buffers that do not override it.
5402 This is the same as (default-value 'tab-width). */);
5404 DEFVAR_LISP_NOPRO ("default-case-fold-search",
5405 &buffer_defaults
.case_fold_search
,
5406 doc
: /* Default value of `case-fold-search' for buffers that don't override it.
5407 This is the same as (default-value 'case-fold-search). */);
5410 DEFVAR_LISP_NOPRO ("default-buffer-file-type",
5411 &buffer_defaults
.buffer_file_type
,
5412 doc
: /* Default file type for buffers that do not override it.
5413 This is the same as (default-value 'buffer-file-type).
5414 The file type is nil for text, t for binary. */);
5417 DEFVAR_LISP_NOPRO ("default-left-margin-width",
5418 &buffer_defaults
.left_margin_cols
,
5419 doc
: /* Default value of `left-margin-width' for buffers that don't override it.
5420 This is the same as (default-value 'left-margin-width). */);
5422 DEFVAR_LISP_NOPRO ("default-right-margin-width",
5423 &buffer_defaults
.right_margin_cols
,
5424 doc
: /* Default value of `right-margin-width' for buffers that don't override it.
5425 This is the same as (default-value 'right-margin-width). */);
5427 DEFVAR_LISP_NOPRO ("default-left-fringe-width",
5428 &buffer_defaults
.left_fringe_width
,
5429 doc
: /* Default value of `left-fringe-width' for buffers that don't override it.
5430 This is the same as (default-value 'left-fringe-width). */);
5432 DEFVAR_LISP_NOPRO ("default-right-fringe-width",
5433 &buffer_defaults
.right_fringe_width
,
5434 doc
: /* Default value of `right-fringe-width' for buffers that don't override it.
5435 This is the same as (default-value 'right-fringe-width). */);
5437 DEFVAR_LISP_NOPRO ("default-fringes-outside-margins",
5438 &buffer_defaults
.fringes_outside_margins
,
5439 doc
: /* Default value of `fringes-outside-margins' for buffers that don't override it.
5440 This is the same as (default-value 'fringes-outside-margins). */);
5442 DEFVAR_LISP_NOPRO ("default-scroll-bar-width",
5443 &buffer_defaults
.scroll_bar_width
,
5444 doc
: /* Default value of `scroll-bar-width' for buffers that don't override it.
5445 This is the same as (default-value 'scroll-bar-width). */);
5447 DEFVAR_LISP_NOPRO ("default-vertical-scroll-bar",
5448 &buffer_defaults
.vertical_scroll_bar_type
,
5449 doc
: /* Default value of `vertical-scroll-bar' for buffers that don't override it.
5450 This is the same as (default-value 'vertical-scroll-bar). */);
5452 DEFVAR_LISP_NOPRO ("default-indicate-empty-lines",
5453 &buffer_defaults
.indicate_empty_lines
,
5454 doc
: /* Default value of `indicate-empty-lines' for buffers that don't override it.
5455 This is the same as (default-value 'indicate-empty-lines). */);
5457 DEFVAR_LISP_NOPRO ("default-indicate-buffer-boundaries",
5458 &buffer_defaults
.indicate_buffer_boundaries
,
5459 doc
: /* Default value of `indicate-buffer-boundaries' for buffers that don't override it.
5460 This is the same as (default-value 'indicate-buffer-boundaries). */);
5462 DEFVAR_LISP_NOPRO ("default-fringe-indicator-alist",
5463 &buffer_defaults
.fringe_indicator_alist
,
5464 doc
: /* Default value of `fringe-indicator-alist' for buffers that don't override it.
5465 This is the same as (default-value 'fringe-indicator-alist'). */);
5467 DEFVAR_LISP_NOPRO ("default-fringe-cursor-alist",
5468 &buffer_defaults
.fringe_cursor_alist
,
5469 doc
: /* Default value of `fringe-cursor-alist' for buffers that don't override it.
5470 This is the same as (default-value 'fringe-cursor-alist'). */);
5472 DEFVAR_LISP_NOPRO ("default-scroll-up-aggressively",
5473 &buffer_defaults
.scroll_up_aggressively
,
5474 doc
: /* Default value of `scroll-up-aggressively'.
5475 This value applies in buffers that don't have their own local values.
5476 This is the same as (default-value 'scroll-up-aggressively). */);
5478 DEFVAR_LISP_NOPRO ("default-scroll-down-aggressively",
5479 &buffer_defaults
.scroll_down_aggressively
,
5480 doc
: /* Default value of `scroll-down-aggressively'.
5481 This value applies in buffers that don't have their own local values.
5482 This is the same as (default-value 'scroll-down-aggressively). */);
5484 DEFVAR_PER_BUFFER ("header-line-format",
5485 ¤t_buffer
->header_line_format
,
5487 doc
: /* Analogous to `mode-line-format', but controls the header line.
5488 The header line appears, optionally, at the top of a window;
5489 the mode line appears at the bottom. */);
5491 DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer
->mode_line_format
,
5493 doc
: /* Template for displaying mode line for current buffer.
5494 Each buffer has its own value of this variable.
5495 Value may be nil, a string, a symbol or a list or cons cell.
5496 A value of nil means don't display a mode line.
5497 For a symbol, its value is used (but it is ignored if t or nil).
5498 A string appearing directly as the value of a symbol is processed verbatim
5499 in that the %-constructs below are not recognized.
5500 Note that unless the symbol is marked as a `risky-local-variable', all
5501 properties in any strings, as well as all :eval and :propertize forms
5502 in the value of that symbol will be ignored.
5503 For a list of the form `(:eval FORM)', FORM is evaluated and the result
5504 is used as a mode line element. Be careful--FORM should not load any files,
5505 because that can cause an infinite recursion.
5506 For a list of the form `(:propertize ELT PROPS...)', ELT is displayed
5507 with the specified properties PROPS applied.
5508 For a list whose car is a symbol, the symbol's value is taken,
5509 and if that is non-nil, the cadr of the list is processed recursively.
5510 Otherwise, the caddr of the list (if there is one) is processed.
5511 For a list whose car is a string or list, each element is processed
5512 recursively and the results are effectively concatenated.
5513 For a list whose car is an integer, the cdr of the list is processed
5514 and padded (if the number is positive) or truncated (if negative)
5515 to the width specified by that number.
5516 A string is printed verbatim in the mode line except for %-constructs:
5517 (%-constructs are allowed when the string is the entire mode-line-format
5518 or when it is found in a cons-cell or a list)
5519 %b -- print buffer name. %f -- print visited file name.
5520 %F -- print frame name.
5521 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.
5522 %& is like %*, but ignore read-only-ness.
5523 % means buffer is read-only and * means it is modified.
5524 For a modified read-only buffer, %* gives % and %+ gives *.
5525 %s -- print process status. %l -- print the current line number.
5526 %c -- print the current column number (this makes editing slower).
5527 To make the column number update correctly in all cases,
5528 `column-number-mode' must be non-nil.
5529 %i -- print the size of the buffer.
5530 %I -- like %i, but use k, M, G, etc., to abbreviate.
5531 %p -- print percent of buffer above top of window, or Top, Bot or All.
5532 %P -- print percent of buffer above bottom of window, perhaps plus Top,
5533 or print Bottom or All.
5534 %n -- print Narrow if appropriate.
5535 %t -- visited file is text or binary (if OS supports this distinction).
5536 %z -- print mnemonics of keyboard, terminal, and buffer coding systems.
5537 %Z -- like %z, but including the end-of-line format.
5538 %e -- print error message about full memory.
5539 %@ -- print @ or hyphen. @ means that default-directory is on a
5541 %[ -- print one [ for each recursive editing level. %] similar.
5542 %% -- print %. %- -- print infinitely many dashes.
5543 Decimal digits after the % specify field width to which to pad. */);
5545 DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults
.major_mode
,
5546 doc
: /* *Major mode for new buffers. Defaults to `fundamental-mode'.
5547 A value of nil means use current buffer's major mode,
5548 provided it is not marked as "special".
5550 When a mode is used by default, `find-file' switches to it
5551 before it reads the contents into the buffer and before
5552 it finishes setting up the buffer. Thus, the mode and
5553 its hooks should not expect certain variables such as
5554 `buffer-read-only' and `buffer-file-coding-system' to be set up. */);
5556 DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer
->major_mode
,
5557 make_number (Lisp_Symbol
),
5558 doc
: /* Symbol for current buffer's major mode. */);
5560 DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer
->mode_name
,
5562 doc
: /* Pretty name of current buffer's major mode (a string). */);
5564 DEFVAR_PER_BUFFER ("local-abbrev-table", ¤t_buffer
->abbrev_table
, Qnil
,
5565 doc
: /* Local (mode-specific) abbrev table of current buffer. */);
5567 DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer
->abbrev_mode
, Qnil
,
5568 doc
: /* Non-nil turns on automatic expansion of abbrevs as they are inserted. */);
5570 DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer
->case_fold_search
,
5572 doc
: /* *Non-nil if searches and matches should ignore case. */);
5574 DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer
->fill_column
,
5575 make_number (Lisp_Int
),
5576 doc
: /* *Column beyond which automatic line-wrapping should happen.
5577 Interactively, you can set the buffer local value using \\[set-fill-column]. */);
5579 DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer
->left_margin
,
5580 make_number (Lisp_Int
),
5581 doc
: /* *Column for the default `indent-line-function' to indent to.
5582 Linefeed indents to this column in Fundamental mode. */);
5584 DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer
->tab_width
,
5585 make_number (Lisp_Int
),
5586 doc
: /* *Distance between tab stops (for display of tab characters), in columns. */);
5588 DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer
->ctl_arrow
, Qnil
,
5589 doc
: /* *Non-nil means display control chars with uparrow.
5590 A value of nil means use backslash and octal digits.
5591 This variable does not apply to characters whose display is specified
5592 in the current display table (if there is one). */);
5594 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
5595 ¤t_buffer
->enable_multibyte_characters
,
5597 doc
: /* Non-nil means the buffer contents are regarded as multi-byte characters.
5598 Otherwise they are regarded as unibyte. This affects the display,
5599 file I/O and the behavior of various editing commands.
5601 This variable is buffer-local but you cannot set it directly;
5602 use the function `set-buffer-multibyte' to change a buffer's representation.
5603 Changing its default value with `setq-default' is supported.
5604 See also variable `default-enable-multibyte-characters' and Info node
5605 `(elisp)Text Representations'. */);
5606 XSYMBOL (intern ("enable-multibyte-characters"))->constant
= 1;
5608 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
5609 ¤t_buffer
->buffer_file_coding_system
, Qnil
,
5610 doc
: /* Coding system to be used for encoding the buffer contents on saving.
5611 This variable applies to saving the buffer, and also to `write-region'
5612 and other functions that use `write-region'.
5613 It does not apply to sending output to subprocesses, however.
5615 If this is nil, the buffer is saved without any code conversion
5616 unless some coding system is specified in `file-coding-system-alist'
5617 for the buffer file.
5619 If the text to be saved cannot be encoded as specified by this variable,
5620 an alternative encoding is selected by `select-safe-coding-system', which see.
5622 The variable `coding-system-for-write', if non-nil, overrides this variable.
5624 This variable is never applied to a way of decoding a file while reading it. */);
5626 DEFVAR_PER_BUFFER ("direction-reversed", ¤t_buffer
->direction_reversed
,
5628 doc
: /* *Non-nil means lines in the buffer are displayed right to left. */);
5630 DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer
->truncate_lines
, Qnil
,
5631 doc
: /* *Non-nil means do not display continuation lines.
5632 Instead, give each line of text just one screen line.
5634 Note that this is overridden by the variable
5635 `truncate-partial-width-windows' if that variable is non-nil
5636 and this buffer is not full-frame width. */);
5639 DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer
->buffer_file_type
,
5641 doc
: /* Non-nil if the visited file is a binary file.
5642 This variable is meaningful on MS-DOG and Windows NT.
5643 On those systems, it is automatically local in every buffer.
5644 On other systems, this variable is normally always nil. */);
5647 DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer
->directory
,
5648 make_number (Lisp_String
),
5649 doc
: /* Name of default directory of current buffer. Should end with slash.
5650 To interactively change the default directory, use command `cd'. */);
5652 DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer
->auto_fill_function
,
5654 doc
: /* Function called (if non-nil) to perform auto-fill.
5655 It is called after self-inserting any character specified in
5656 the `auto-fill-chars' table.
5657 NOTE: This variable is not a hook;
5658 its value may not be a list of functions. */);
5660 DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer
->filename
,
5661 make_number (Lisp_String
),
5662 doc
: /* Name of file visited in current buffer, or nil if not visiting a file. */);
5664 DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer
->file_truename
,
5665 make_number (Lisp_String
),
5666 doc
: /* Abbreviated truename of file visited in current buffer, or nil if none.
5667 The truename of a file is calculated by `file-truename'
5668 and then abbreviated with `abbreviate-file-name'. */);
5670 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
5671 ¤t_buffer
->auto_save_file_name
,
5672 make_number (Lisp_String
),
5673 doc
: /* Name of file for auto-saving current buffer.
5674 If it is nil, that means don't auto-save this buffer. */);
5676 DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer
->read_only
, Qnil
,
5677 doc
: /* Non-nil if this buffer is read-only. */);
5679 DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer
->backed_up
, Qnil
,
5680 doc
: /* Non-nil if this buffer's file has been backed up.
5681 Backing up is done before the first time the file is saved. */);
5683 DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer
->save_length
,
5684 make_number (Lisp_Int
),
5685 doc
: /* Length of current buffer when last read in, saved or auto-saved.
5688 DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer
->selective_display
,
5690 doc
: /* Non-nil enables selective display.
5691 An integer N as value means display only lines
5692 that start with less than N columns of space.
5693 A value of t means that the character ^M makes itself and
5694 all the rest of the line invisible; also, when saving the buffer
5695 in a file, save the ^M as a newline. */);
5698 DEFVAR_PER_BUFFER ("selective-display-ellipses",
5699 ¤t_buffer
->selective_display_ellipses
,
5701 doc
: /* Non-nil means display ... on previous line when a line is invisible. */);
5704 DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer
->overwrite_mode
, Qnil
,
5705 doc
: /* Non-nil if self-insertion should replace existing text.
5706 The value should be one of `overwrite-mode-textual',
5707 `overwrite-mode-binary', or nil.
5708 If it is `overwrite-mode-textual', self-insertion still
5709 inserts at the end of a line, and inserts when point is before a tab,
5710 until the tab is filled in.
5711 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too. */);
5713 DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer
->display_table
,
5715 doc
: /* Display table that controls display of the contents of current buffer.
5717 If this variable is nil, the value of `standard-display-table' is used.
5718 Each window can have its own, overriding display table, see
5719 `set-window-display-table' and `window-display-table'.
5721 The display table is a char-table created with `make-display-table'.
5722 A char-table is an array indexed by character codes. Normal array
5723 primitives `aref' and `aset' can be used to access elements of a char-table.
5725 Each of the char-table elements control how to display the corresponding
5726 text character: the element at index C in the table says how to display
5727 the character whose code is C. Each element should be a vector of
5728 characters or nil. The value nil means display the character in the
5729 default fashion; otherwise, the characters from the vector are delivered
5730 to the screen instead of the original character.
5732 For example, (aset buffer-display-table ?X [?Y]) tells Emacs
5733 to display a capital Y instead of each X character.
5735 In addition, a char-table has six extra slots to control the display of:
5737 the end of a truncated screen line (extra-slot 0, a single character);
5738 the end of a continued line (extra-slot 1, a single character);
5739 the escape character used to display character codes in octal
5740 (extra-slot 2, a single character);
5741 the character used as an arrow for control characters (extra-slot 3,
5742 a single character);
5743 the decoration indicating the presence of invisible lines (extra-slot 4,
5744 a vector of characters);
5745 the character used to draw the border between side-by-side windows
5746 (extra-slot 5, a single character).
5748 See also the functions `display-table-slot' and `set-display-table-slot'. */);
5750 DEFVAR_PER_BUFFER ("left-margin-width", ¤t_buffer
->left_margin_cols
,
5752 doc
: /* *Width of left marginal area for display of a buffer.
5753 A value of nil means no marginal area. */);
5755 DEFVAR_PER_BUFFER ("right-margin-width", ¤t_buffer
->right_margin_cols
,
5757 doc
: /* *Width of right marginal area for display of a buffer.
5758 A value of nil means no marginal area. */);
5760 DEFVAR_PER_BUFFER ("left-fringe-width", ¤t_buffer
->left_fringe_width
,
5762 doc
: /* *Width of this buffer's left fringe (in pixels).
5763 A value of 0 means no left fringe is shown in this buffer's window.
5764 A value of nil means to use the left fringe width from the window's frame. */);
5766 DEFVAR_PER_BUFFER ("right-fringe-width", ¤t_buffer
->right_fringe_width
,
5768 doc
: /* *Width of this buffer's right fringe (in pixels).
5769 A value of 0 means no right fringe is shown in this buffer's window.
5770 A value of nil means to use the right fringe width from the window's frame. */);
5772 DEFVAR_PER_BUFFER ("fringes-outside-margins", ¤t_buffer
->fringes_outside_margins
,
5774 doc
: /* *Non-nil means to display fringes outside display margins.
5775 A value of nil means to display fringes between margins and buffer text. */);
5777 DEFVAR_PER_BUFFER ("scroll-bar-width", ¤t_buffer
->scroll_bar_width
,
5779 doc
: /* *Width of this buffer's scroll bars in pixels.
5780 A value of nil means to use the scroll bar width from the window's frame. */);
5782 DEFVAR_PER_BUFFER ("vertical-scroll-bar", ¤t_buffer
->vertical_scroll_bar_type
,
5784 doc
: /* *Position of this buffer's vertical scroll bar.
5785 The value takes effect whenever you tell a window to display this buffer;
5786 for instance, with `set-window-buffer' or when `display-buffer' displays it.
5788 A value of `left' or `right' means put the vertical scroll bar at that side
5789 of the window; a value of nil means don't show any vertical scroll bars.
5790 A value of t (the default) means do whatever the window's frame specifies. */);
5792 DEFVAR_PER_BUFFER ("indicate-empty-lines",
5793 ¤t_buffer
->indicate_empty_lines
, Qnil
,
5794 doc
: /* *Visually indicate empty lines after the buffer end.
5795 If non-nil, a bitmap is displayed in the left fringe of a window on
5796 window-systems. */);
5798 DEFVAR_PER_BUFFER ("indicate-buffer-boundaries",
5799 ¤t_buffer
->indicate_buffer_boundaries
, Qnil
,
5800 doc
: /* *Visually indicate buffer boundaries and scrolling.
5801 If non-nil, the first and last line of the buffer are marked in the fringe
5802 of a window on window-systems with angle bitmaps, or if the window can be
5803 scrolled, the top and bottom line of the window are marked with up and down
5806 If value is a symbol `left' or `right', both angle and arrow bitmaps
5807 are displayed in the left or right fringe, resp. Any other value
5808 that doesn't look like an alist means display the angle bitmaps in
5809 the left fringe but no arrows.
5811 You can exercise more precise control by using an alist as the
5812 value. Each alist element (INDICATOR . POSITION) specifies
5813 where to show one of the indicators. INDICATOR is one of `top',
5814 `bottom', `up', `down', or t, which specifies the default position,
5815 and POSITION is one of `left', `right', or nil, meaning do not show
5818 For example, ((top . left) (t . right)) places the top angle bitmap in
5819 left fringe, the bottom angle bitmap in right fringe, and both arrow
5820 bitmaps in right fringe. To show just the angle bitmaps in the left
5821 fringe, but no arrow bitmaps, use ((top . left) (bottom . left)). */);
5823 DEFVAR_PER_BUFFER ("fringe-indicator-alist",
5824 ¤t_buffer
->fringe_indicator_alist
, Qnil
,
5825 doc
: /* *Mapping from logical to physical fringe indicator bitmaps.
5826 The value is an alist where each element (INDICATOR . BITMAPS)
5827 specifies the fringe bitmaps used to display a specific logical
5830 INDICATOR specifies the logical indicator type which is one of the
5831 following symbols: `truncation' , `continuation', `overlay-arrow',
5832 `top', `bottom', `up', `down', `one-line', `empty-line', or `unknown'.
5834 BITMAPS is list of symbols (LEFT RIGHT [LEFT1 RIGHT1]) which specifies
5835 the actual bitmap shown in the left or right fringe for the logical
5836 indicator. LEFT and RIGHT are the bitmaps shown in the left and/or
5837 right fringe for the specific indicator. The LEFT1 or RIGHT1 bitmaps
5838 are used only for the `bottom' and `one-line' indicators when the last
5839 \(only) line in has no final newline. BITMAPS may also be a single
5840 symbol which is used in both left and right fringes. */);
5842 DEFVAR_PER_BUFFER ("fringe-cursor-alist",
5843 ¤t_buffer
->fringe_cursor_alist
, Qnil
,
5844 doc
: /* *Mapping from logical to physical fringe cursor bitmaps.
5845 The value is an alist where each element (CURSOR . BITMAP)
5846 specifies the fringe bitmaps used to display a specific logical
5847 cursor type in the fringe.
5849 CURSOR specifies the logical cursor type which is one of the following
5850 symbols: `box' , `hollow', `bar', `hbar', or `hollow-small'. The last
5851 one is used to show a hollow cursor on narrow lines display lines
5852 where the normal hollow cursor will not fit.
5854 BITMAP is the corresponding fringe bitmap shown for the logical
5857 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
5858 ¤t_buffer
->scroll_up_aggressively
, Qnil
,
5859 doc
: /* How far to scroll windows upward.
5860 If you move point off the bottom, the window scrolls automatically.
5861 This variable controls how far it scrolls. The value nil, the default,
5862 means scroll to center point. A fraction means scroll to put point
5863 that fraction of the window's height from the bottom of the window.
5864 When the value is 0.0, point goes at the bottom line, which in the simple
5865 case that you moved off with C-f means scrolling just one line. 1.0 means
5866 point goes at the top, so that in that simple case, the window
5867 scrolls by a full window height. Meaningful values are
5868 between 0.0 and 1.0, inclusive. */);
5870 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
5871 ¤t_buffer
->scroll_down_aggressively
, Qnil
,
5872 doc
: /* How far to scroll windows downward.
5873 If you move point off the top, the window scrolls automatically.
5874 This variable controls how far it scrolls. The value nil, the default,
5875 means scroll to center point. A fraction means scroll to put point
5876 that fraction of the window's height from the top of the window.
5877 When the value is 0.0, point goes at the top line, which in the simple
5878 case that you moved off with C-b means scrolling just one line. 1.0 means
5879 point goes at the bottom, so that in that simple case, the window
5880 scrolls by a full window height. Meaningful values are
5881 between 0.0 and 1.0, inclusive. */);
5883 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
5887 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions
,
5888 doc
: /* List of functions to call before each text change.
5889 Two arguments are passed to each function: the positions of
5890 the beginning and end of the range of old text to be changed.
5891 \(For an insertion, the beginning and end are at the same place.)
5892 No information is given about the length of the text after the change.
5894 Buffer changes made while executing the `before-change-functions'
5895 don't call any before-change or after-change functions.
5896 That's because these variables are temporarily set to nil.
5897 As a result, a hook function cannot straightforwardly alter the value of
5898 these variables. See the Emacs Lisp manual for a way of
5899 accomplishing an equivalent result by using other variables.
5901 If an unhandled error happens in running these functions,
5902 the variable's value remains nil. That prevents the error
5903 from happening repeatedly and making Emacs nonfunctional. */);
5904 Vbefore_change_functions
= Qnil
;
5906 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions
,
5907 doc
: /* List of functions to call after each text change.
5908 Three arguments are passed to each function: the positions of
5909 the beginning and end of the range of changed text,
5910 and the length in bytes of the pre-change text replaced by that range.
5911 \(For an insertion, the pre-change length is zero;
5912 for a deletion, that length is the number of bytes deleted,
5913 and the post-change beginning and end are at the same place.)
5915 Buffer changes made while executing the `after-change-functions'
5916 don't call any before-change or after-change functions.
5917 That's because these variables are temporarily set to nil.
5918 As a result, a hook function cannot straightforwardly alter the value of
5919 these variables. See the Emacs Lisp manual for a way of
5920 accomplishing an equivalent result by using other variables.
5922 If an unhandled error happens in running these functions,
5923 the variable's value remains nil. That prevents the error
5924 from happening repeatedly and making Emacs nonfunctional. */);
5925 Vafter_change_functions
= Qnil
;
5927 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook
,
5928 doc
: /* A list of functions to call before changing a buffer which is unmodified.
5929 The functions are run using the `run-hooks' function. */);
5930 Vfirst_change_hook
= Qnil
;
5932 DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer
->undo_list
, Qnil
,
5933 doc
: /* List of undo entries in current buffer.
5934 Recent changes come first; older changes follow newer.
5936 An entry (BEG . END) represents an insertion which begins at
5937 position BEG and ends at position END.
5939 An entry (TEXT . POSITION) represents the deletion of the string TEXT
5940 from (abs POSITION). If POSITION is positive, point was at the front
5941 of the text being deleted; if negative, point was at the end.
5943 An entry (t HIGH . LOW) indicates that the buffer previously had
5944 \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions
5945 of the visited file's modification time, as of that time. If the
5946 modification time of the most recent save is different, this entry is
5949 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property
5950 was modified between BEG and END. PROPERTY is the property name,
5951 and VALUE is the old value.
5953 An entry (apply FUN-NAME . ARGS) means undo the change with
5954 \(apply FUN-NAME ARGS).
5956 An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo
5957 in the active region. BEG and END is the range affected by this entry
5958 and DELTA is the number of bytes added or deleted in that range by
5961 An entry (MARKER . DISTANCE) indicates that the marker MARKER
5962 was adjusted in position by the offset DISTANCE (an integer).
5964 An entry of the form POSITION indicates that point was at the buffer
5965 location given by the integer. Undoing an entry of this form places
5968 Entries with value `nil' mark undo boundaries. The undo command treats
5969 the changes between two undo boundaries as a single step to be undone.
5971 If the value of the variable is t, undo information is not recorded. */);
5973 DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer
->mark_active
, Qnil
,
5974 doc
: /* Non-nil means the mark and region are currently active in this buffer. */);
5976 DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer
->cache_long_line_scans
, Qnil
,
5977 doc
: /* Non-nil means that Emacs should use caches to handle long lines more quickly.
5979 Normally, the line-motion functions work by scanning the buffer for
5980 newlines. Columnar operations (like `move-to-column' and
5981 `compute-motion') also work by scanning the buffer, summing character
5982 widths as they go. This works well for ordinary text, but if the
5983 buffer's lines are very long (say, more than 500 characters), these
5984 motion functions will take longer to execute. Emacs may also take
5985 longer to update the display.
5987 If `cache-long-line-scans' is non-nil, these motion functions cache the
5988 results of their scans, and consult the cache to avoid rescanning
5989 regions of the buffer until the text is modified. The caches are most
5990 beneficial when they prevent the most searching---that is, when the
5991 buffer contains long lines and large regions of characters with the
5992 same, fixed screen width.
5994 When `cache-long-line-scans' is non-nil, processing short lines will
5995 become slightly slower (because of the overhead of consulting the
5996 cache), and the caches will use memory roughly proportional to the
5997 number of newlines and characters whose screen width varies.
5999 The caches require no explicit maintenance; their accuracy is
6000 maintained internally by the Emacs primitives. Enabling or disabling
6001 the cache should not affect the behavior of any of the motion
6002 functions; it should only affect their performance. */);
6004 DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer
->point_before_scroll
, Qnil
,
6005 doc
: /* Value of point before the last series of scroll operations, or nil. */);
6007 DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer
->file_format
, Qnil
,
6008 doc
: /* List of formats to use when saving this buffer.
6009 Formats are defined by `format-alist'. This variable is
6010 set when a file is visited. */);
6012 DEFVAR_PER_BUFFER ("buffer-auto-save-file-format",
6013 ¤t_buffer
->auto_save_file_format
, Qnil
,
6014 doc
: /* *Format in which to write auto-save files.
6015 Should be a list of symbols naming formats that are defined in `format-alist'.
6016 If it is t, which is the default, auto-save files are written in the
6017 same format as a regular save would use. */);
6019 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
6020 ¤t_buffer
->invisibility_spec
, Qnil
,
6021 doc
: /* Invisibility spec of this buffer.
6022 The default is t, which means that text is invisible
6023 if it has a non-nil `invisible' property.
6024 If the value is a list, a text character is invisible if its `invisible'
6025 property is an element in that list (or is a list with members in common).
6026 If an element is a cons cell of the form (PROP . ELLIPSIS),
6027 then characters with property value PROP are invisible,
6028 and they have an ellipsis as well if ELLIPSIS is non-nil. */);
6030 DEFVAR_PER_BUFFER ("buffer-display-count",
6031 ¤t_buffer
->display_count
, Qnil
,
6032 doc
: /* A number incremented each time this buffer is displayed in a window.
6033 The function `set-window-buffer' increments it. */);
6035 DEFVAR_PER_BUFFER ("buffer-display-time",
6036 ¤t_buffer
->display_time
, Qnil
,
6037 doc
: /* Time stamp updated each time this buffer is displayed in a window.
6038 The function `set-window-buffer' updates this variable
6039 to the value obtained by calling `current-time'.
6040 If the buffer has never been shown in a window, the value is nil. */);
6042 DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode
,
6043 doc
: /* *Non-nil means deactivate the mark when the buffer contents change.
6044 Non-nil also enables highlighting of the region whenever the mark is active.
6045 The variable `highlight-nonselected-windows' controls whether to highlight
6046 all windows or just the selected window.
6048 If the value is `lambda', that enables Transient Mark mode temporarily
6049 until the next buffer modification. If a command sets the value to `only',
6050 that enables Transient Mark mode for the following command only.
6051 During that following command, the value of `transient-mark-mode'
6052 is `identity'. If it is still `identity' at the end of that command,
6053 it changes to nil. */);
6054 Vtransient_mark_mode
= Qnil
;
6056 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only
,
6057 doc
: /* *Non-nil means disregard read-only status of buffers or characters.
6058 If the value is t, disregard `buffer-read-only' and all `read-only'
6059 text properties. If the value is a list, disregard `buffer-read-only'
6060 and disregard a `read-only' text property if the property value
6061 is a member of the list. */);
6062 Vinhibit_read_only
= Qnil
;
6064 DEFVAR_PER_BUFFER ("cursor-type", ¤t_buffer
->cursor_type
, Qnil
,
6065 doc
: /* Cursor to use when this buffer is in the selected window.
6066 Values are interpreted as follows:
6068 t use the cursor specified for the frame
6069 nil don't display a cursor
6070 box display a filled box cursor
6071 hollow display a hollow box cursor
6072 bar display a vertical bar cursor with default width
6073 (bar . WIDTH) display a vertical bar cursor with width WIDTH
6074 hbar display a horizontal bar cursor with default height
6075 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
6076 ANYTHING ELSE display a hollow box cursor
6078 When the buffer is displayed in a nonselected window,
6079 this variable has no effect; the cursor appears as a hollow box. */);
6081 DEFVAR_PER_BUFFER ("line-spacing",
6082 ¤t_buffer
->extra_line_spacing
, Qnil
,
6083 doc
: /* Additional space to put between lines when displaying a buffer.
6084 The space is measured in pixels, and put below lines on window systems.
6085 If value is a floating point number, it specifies the spacing relative
6086 to the default frame line height. A value of nil means add no extra space. */);
6088 DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
6089 ¤t_buffer
->cursor_in_non_selected_windows
, Qnil
,
6090 doc
: /* *Cursor type to display in non-selected windows.
6091 The value t means to use hollow box cursor. See `cursor-type' for other values. */);
6093 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions
,
6094 doc
: /* List of functions called with no args to query before killing a buffer.
6095 The buffer being killed will be current while the functions are running.
6096 If any of them returns nil, the buffer is not killed. */);
6097 Vkill_buffer_query_functions
= Qnil
;
6099 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook
,
6100 doc
: /* Normal hook run before changing the major mode of a buffer.
6101 The function `kill-all-local-variables' runs this before doing anything else. */);
6102 Vchange_major_mode_hook
= Qnil
;
6103 Qchange_major_mode_hook
= intern ("change-major-mode-hook");
6104 staticpro (&Qchange_major_mode_hook
);
6106 defsubr (&Sbuffer_live_p
);
6107 defsubr (&Sbuffer_list
);
6108 defsubr (&Sget_buffer
);
6109 defsubr (&Sget_file_buffer
);
6110 defsubr (&Sget_buffer_create
);
6111 defsubr (&Smake_indirect_buffer
);
6112 defsubr (&Sgenerate_new_buffer_name
);
6113 defsubr (&Sbuffer_name
);
6114 /*defsubr (&Sbuffer_number);*/
6115 defsubr (&Sbuffer_file_name
);
6116 defsubr (&Sbuffer_base_buffer
);
6117 defsubr (&Sbuffer_local_value
);
6118 defsubr (&Sbuffer_local_variables
);
6119 defsubr (&Sbuffer_modified_p
);
6120 defsubr (&Sset_buffer_modified_p
);
6121 defsubr (&Sbuffer_modified_tick
);
6122 defsubr (&Sbuffer_chars_modified_tick
);
6123 defsubr (&Srename_buffer
);
6124 defsubr (&Sother_buffer
);
6125 defsubr (&Sbuffer_enable_undo
);
6126 defsubr (&Skill_buffer
);
6127 defsubr (&Sset_buffer_major_mode
);
6128 defsubr (&Sswitch_to_buffer
);
6129 defsubr (&Spop_to_buffer
);
6130 defsubr (&Scurrent_buffer
);
6131 defsubr (&Sset_buffer
);
6132 defsubr (&Sbarf_if_buffer_read_only
);
6133 defsubr (&Sbury_buffer
);
6134 defsubr (&Serase_buffer
);
6135 defsubr (&Sset_buffer_multibyte
);
6136 defsubr (&Skill_all_local_variables
);
6138 defsubr (&Soverlayp
);
6139 defsubr (&Smake_overlay
);
6140 defsubr (&Sdelete_overlay
);
6141 defsubr (&Smove_overlay
);
6142 defsubr (&Soverlay_start
);
6143 defsubr (&Soverlay_end
);
6144 defsubr (&Soverlay_buffer
);
6145 defsubr (&Soverlay_properties
);
6146 defsubr (&Soverlays_at
);
6147 defsubr (&Soverlays_in
);
6148 defsubr (&Snext_overlay_change
);
6149 defsubr (&Sprevious_overlay_change
);
6150 defsubr (&Soverlay_recenter
);
6151 defsubr (&Soverlay_lists
);
6152 defsubr (&Soverlay_get
);
6153 defsubr (&Soverlay_put
);
6154 defsubr (&Srestore_buffer_modified_p
);
6160 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
6161 initial_define_key (control_x_map
, 'k', "kill-buffer");
6163 /* This must not be in syms_of_buffer, because Qdisabled is not
6164 initialized when that function gets called. */
6165 Fput (intern ("erase-buffer"), Qdisabled
, Qt
);
6168 /* arch-tag: e48569bf-69a9-4b65-a23b-8e68769436e1
6169 (do not change this comment) */