1 /* Buffer manipulation primitives for GNU Emacs.
3 Copyright (C) 1985-1989, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 #define BUFFER_INLINE EXTERN_INLINE
24 #include <sys/types.h>
26 #include <sys/param.h>
35 #include "intervals.h"
38 #include "character.h"
40 #include "region-cache.h"
42 #include "blockinput.h"
47 struct buffer
*current_buffer
; /* the current buffer */
49 /* First buffer in chain of all buffers (in reverse order of creation).
50 Threaded through ->header.next.buffer. */
52 struct buffer
*all_buffers
;
54 /* This structure holds the default values of the buffer-local variables
55 defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
56 The default value occupies the same slot in this structure
57 as an individual buffer's value occupies in that buffer.
58 Setting the default value also goes through the alist of buffers
59 and stores into each buffer that does not say it has a local value. */
61 struct buffer
alignas (GCALIGNMENT
) buffer_defaults
;
63 /* A Lisp_Object pointer to the above, used for staticpro */
65 static Lisp_Object Vbuffer_defaults
;
67 /* This structure marks which slots in a buffer have corresponding
68 default values in buffer_defaults.
69 Each such slot has a nonzero value in this structure.
70 The value has only one nonzero bit.
72 When a buffer has its own local value for a slot,
73 the entry for that slot (found in the same slot in this structure)
74 is turned on in the buffer's local_flags array.
76 If a slot in this structure is -1, then even though there may
77 be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
78 and the corresponding slot in buffer_defaults is not used.
80 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
81 zero, that is a bug */
83 struct buffer buffer_local_flags
;
85 /* This structure holds the names of symbols whose values may be
86 buffer-local. It is indexed and accessed in the same way as the above. */
88 struct buffer
alignas (GCALIGNMENT
) buffer_local_symbols
;
90 /* A Lisp_Object pointer to the above, used for staticpro */
91 static Lisp_Object Vbuffer_local_symbols
;
93 /* Return the symbol of the per-buffer variable at offset OFFSET in
94 the buffer structure. */
96 #define PER_BUFFER_SYMBOL(OFFSET) \
97 (*(Lisp_Object *)((OFFSET) + (char *) &buffer_local_symbols))
99 /* Maximum length of an overlay vector. */
100 #define OVERLAY_COUNT_MAX \
101 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, \
102 min (PTRDIFF_MAX, SIZE_MAX) / word_size))
104 /* Flags indicating which built-in buffer-local variables
105 are permanent locals. */
106 static char buffer_permanent_local_flags
[MAX_PER_BUFFER_VARS
];
108 /* Number of per-buffer variables used. */
110 int last_per_buffer_idx
;
112 static void call_overlay_mod_hooks (Lisp_Object list
, Lisp_Object overlay
,
113 int after
, Lisp_Object arg1
,
114 Lisp_Object arg2
, Lisp_Object arg3
);
115 static void swap_out_buffer_local_variables (struct buffer
*b
);
116 static void reset_buffer_local_variables (struct buffer
*b
, int permanent_too
);
118 /* Alist of all buffer names vs the buffers. */
119 /* This used to be a variable, but is no longer,
120 to prevent lossage due to user rplac'ing this alist or its elements. */
121 Lisp_Object Vbuffer_alist
;
123 static Lisp_Object Qkill_buffer_query_functions
;
125 /* Hook run before changing a major mode. */
126 static Lisp_Object Qchange_major_mode_hook
;
128 Lisp_Object Qfirst_change_hook
;
129 Lisp_Object Qbefore_change_functions
;
130 Lisp_Object Qafter_change_functions
;
132 static Lisp_Object Qfundamental_mode
, Qmode_class
, Qpermanent_local
;
133 static Lisp_Object Qpermanent_local_hook
;
135 static Lisp_Object Qprotected_field
;
137 static Lisp_Object QSFundamental
; /* A string "Fundamental" */
139 static Lisp_Object Qkill_buffer_hook
;
140 static Lisp_Object Qbuffer_list_update_hook
;
142 static Lisp_Object Qget_file_buffer
;
144 static Lisp_Object Qoverlayp
;
146 Lisp_Object Qpriority
, Qbefore_string
, Qafter_string
;
148 static Lisp_Object Qevaporate
;
150 Lisp_Object Qmodification_hooks
;
151 Lisp_Object Qinsert_in_front_hooks
;
152 Lisp_Object Qinsert_behind_hooks
;
154 static void alloc_buffer_text (struct buffer
*, ptrdiff_t);
155 static void free_buffer_text (struct buffer
*b
);
156 static struct Lisp_Overlay
* copy_overlays (struct buffer
*, struct Lisp_Overlay
*);
157 static void modify_overlay (struct buffer
*, ptrdiff_t, ptrdiff_t);
158 static Lisp_Object
buffer_lisp_local_variables (struct buffer
*, int);
160 /* For debugging; temporary. See set_buffer_internal. */
161 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
164 nsberror (Lisp_Object spec
)
167 error ("No buffer named %s", SDATA (spec
));
168 error ("Invalid buffer argument");
171 DEFUN ("buffer-live-p", Fbuffer_live_p
, Sbuffer_live_p
, 1, 1, 0,
172 doc
: /* Return non-nil if OBJECT is a buffer which has not been killed.
173 Value is nil if OBJECT is not a buffer or if it has been killed. */)
176 return ((BUFFERP (object
) && ! NILP (BVAR (XBUFFER (object
), name
)))
180 DEFUN ("buffer-list", Fbuffer_list
, Sbuffer_list
, 0, 1, 0,
181 doc
: /* Return a list of all existing live buffers.
182 If the optional arg FRAME is a frame, we return the buffer list in the
183 proper order for that frame: the buffers show in FRAME come first,
184 followed by the rest of the buffers. */)
188 general
= Fmapcar (Qcdr
, Vbuffer_alist
);
192 Lisp_Object framelist
, prevlist
, tail
;
196 framelist
= Fcopy_sequence (XFRAME (frame
)->buffer_list
);
197 prevlist
= Fnreverse (Fcopy_sequence
198 (XFRAME (frame
)->buried_buffer_list
));
200 /* Remove from GENERAL any buffer that duplicates one in
201 FRAMELIST or PREVLIST. */
205 general
= Fdelq (XCAR (tail
), general
);
211 general
= Fdelq (XCAR (tail
), general
);
218 return Fnconc (3, args
);
224 /* Like Fassoc, but use Fstring_equal to compare
225 (which ignores text properties),
226 and don't ever QUIT. */
229 assoc_ignore_text_properties (register Lisp_Object key
, Lisp_Object list
)
231 register Lisp_Object tail
;
232 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
234 register Lisp_Object elt
, tem
;
236 tem
= Fstring_equal (Fcar (elt
), key
);
243 DEFUN ("get-buffer", Fget_buffer
, Sget_buffer
, 1, 1, 0,
244 doc
: /* Return the buffer named BUFFER-OR-NAME.
245 BUFFER-OR-NAME must be either a string or a buffer. If BUFFER-OR-NAME
246 is a string and there is no buffer with that name, return nil. If
247 BUFFER-OR-NAME is a buffer, return it as given. */)
248 (register Lisp_Object buffer_or_name
)
250 if (BUFFERP (buffer_or_name
))
251 return buffer_or_name
;
252 CHECK_STRING (buffer_or_name
);
254 return Fcdr (assoc_ignore_text_properties (buffer_or_name
, Vbuffer_alist
));
257 DEFUN ("get-file-buffer", Fget_file_buffer
, Sget_file_buffer
, 1, 1, 0,
258 doc
: /* Return the buffer visiting file FILENAME (a string).
259 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.
260 If there is no such live buffer, return nil.
261 See also `find-buffer-visiting'. */)
262 (register Lisp_Object filename
)
264 register Lisp_Object tail
, buf
, tem
;
267 CHECK_STRING (filename
);
268 filename
= Fexpand_file_name (filename
, Qnil
);
270 /* If the file name has special constructs in it,
271 call the corresponding file handler. */
272 handler
= Ffind_file_name_handler (filename
, Qget_file_buffer
);
275 Lisp_Object handled_buf
= call2 (handler
, Qget_file_buffer
,
277 return BUFFERP (handled_buf
) ? handled_buf
: Qnil
;
280 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
282 buf
= Fcdr (XCAR (tail
));
283 if (!BUFFERP (buf
)) continue;
284 if (!STRINGP (BVAR (XBUFFER (buf
), filename
))) continue;
285 tem
= Fstring_equal (BVAR (XBUFFER (buf
), filename
), filename
);
293 get_truename_buffer (register Lisp_Object filename
)
295 register Lisp_Object tail
, buf
, tem
;
297 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
299 buf
= Fcdr (XCAR (tail
));
300 if (!BUFFERP (buf
)) continue;
301 if (!STRINGP (BVAR (XBUFFER (buf
), file_truename
))) continue;
302 tem
= Fstring_equal (BVAR (XBUFFER (buf
), file_truename
), filename
);
309 DEFUN ("get-buffer-create", Fget_buffer_create
, Sget_buffer_create
, 1, 1, 0,
310 doc
: /* Return the buffer specified by BUFFER-OR-NAME, creating a new one if needed.
311 If BUFFER-OR-NAME is a string and a live buffer with that name exists,
312 return that buffer. If no such buffer exists, create a new buffer with
313 that name and return it. If BUFFER-OR-NAME starts with a space, the new
314 buffer does not keep undo information.
316 If BUFFER-OR-NAME is a buffer instead of a string, return it as given,
317 even if it is dead. The return value is never nil. */)
318 (register Lisp_Object buffer_or_name
)
320 register Lisp_Object buffer
, name
;
321 register struct buffer
*b
;
323 buffer
= Fget_buffer (buffer_or_name
);
327 if (SCHARS (buffer_or_name
) == 0)
328 error ("Empty string for buffer name is not allowed");
330 b
= allocate_buffer ();
332 /* An ordinary buffer uses its own struct buffer_text. */
333 b
->text
= &b
->own_text
;
334 b
->base_buffer
= NULL
;
335 /* No one shares the text with us now. */
338 BUF_GAP_SIZE (b
) = 20;
340 /* We allocate extra 1-byte at the tail and keep it always '\0' for
341 anchoring a search. */
342 alloc_buffer_text (b
, BUF_GAP_SIZE (b
) + 1);
344 if (! BUF_BEG_ADDR (b
))
345 buffer_memory_full (BUF_GAP_SIZE (b
) + 1);
350 b
->pt_byte
= BEG_BYTE
;
351 b
->begv_byte
= BEG_BYTE
;
352 b
->zv_byte
= BEG_BYTE
;
355 BUF_GPT_BYTE (b
) = BEG_BYTE
;
358 BUF_Z_BYTE (b
) = BEG_BYTE
;
360 BUF_CHARS_MODIFF (b
) = 1;
361 BUF_OVERLAY_MODIFF (b
) = 1;
362 BUF_SAVE_MODIFF (b
) = 1;
363 buffer_set_intervals (b
, NULL
);
364 BUF_UNCHANGED_MODIFIED (b
) = 1;
365 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = 1;
366 BUF_END_UNCHANGED (b
) = 0;
367 BUF_BEG_UNCHANGED (b
) = 0;
368 *(BUF_GPT_ADDR (b
)) = *(BUF_Z_ADDR (b
)) = 0; /* Put an anchor '\0'. */
369 b
->text
->inhibit_shrinking
= 0;
371 b
->newline_cache
= 0;
372 b
->width_run_cache
= 0;
373 BSET (b
, width_table
, Qnil
);
374 b
->prevent_redisplay_optimizations_p
= 1;
376 /* Put this on the chain of all buffers including killed ones. */
377 b
->header
.next
.buffer
= all_buffers
;
380 /* An ordinary buffer normally doesn't need markers
381 to handle BEGV and ZV. */
382 BSET (b
, pt_marker
, Qnil
);
383 BSET (b
, begv_marker
, Qnil
);
384 BSET (b
, zv_marker
, Qnil
);
386 name
= Fcopy_sequence (buffer_or_name
);
387 string_set_intervals (name
, NULL
);
388 BSET (b
, name
, name
);
390 BSET (b
, undo_list
, (SREF (name
, 0) != ' ') ? Qnil
: Qt
);
393 reset_buffer_local_variables (b
, 1);
395 BSET (b
, mark
, Fmake_marker ());
396 BUF_MARKERS (b
) = NULL
;
398 /* Put this in the alist of all live buffers. */
399 XSETBUFFER (buffer
, b
);
400 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buffer
), Qnil
));
401 /* And run buffer-list-update-hook. */
402 if (!NILP (Vrun_hooks
))
403 call1 (Vrun_hooks
, Qbuffer_list_update_hook
);
409 /* Return a list of overlays which is a copy of the overlay list
410 LIST, but for buffer B. */
412 static struct Lisp_Overlay
*
413 copy_overlays (struct buffer
*b
, struct Lisp_Overlay
*list
)
415 struct Lisp_Overlay
*result
= NULL
, *tail
= NULL
;
417 for (; list
; list
= list
->next
)
419 Lisp_Object overlay
, start
, end
;
420 struct Lisp_Marker
*m
;
422 eassert (MARKERP (list
->start
));
423 m
= XMARKER (list
->start
);
424 start
= build_marker (b
, m
->charpos
, m
->bytepos
);
425 XMARKER (start
)->insertion_type
= m
->insertion_type
;
427 eassert (MARKERP (list
->end
));
428 m
= XMARKER (list
->end
);
429 end
= build_marker (b
, m
->charpos
, m
->bytepos
);
430 XMARKER (end
)->insertion_type
= m
->insertion_type
;
432 overlay
= build_overlay (start
, end
, Fcopy_sequence (list
->plist
));
434 tail
= tail
->next
= XOVERLAY (overlay
);
436 result
= tail
= XOVERLAY (overlay
);
443 /* Clone per-buffer values of buffer FROM.
445 Buffer TO gets the same per-buffer values as FROM, with the
446 following exceptions: (1) TO's name is left untouched, (2) markers
447 are copied and made to refer to TO, and (3) overlay lists are
451 clone_per_buffer_values (struct buffer
*from
, struct buffer
*to
)
455 FOR_EACH_PER_BUFFER_OBJECT_AT (offset
)
459 /* Don't touch the `name' which should be unique for every buffer. */
460 if (offset
== PER_BUFFER_VAR_OFFSET (name
))
463 obj
= PER_BUFFER_VALUE (from
, offset
);
464 if (MARKERP (obj
) && XMARKER (obj
)->buffer
== from
)
466 struct Lisp_Marker
*m
= XMARKER (obj
);
468 obj
= build_marker (to
, m
->charpos
, m
->bytepos
);
469 XMARKER (obj
)->insertion_type
= m
->insertion_type
;
472 PER_BUFFER_VALUE (to
, offset
) = obj
;
475 memcpy (to
->local_flags
, from
->local_flags
, sizeof to
->local_flags
);
478 (to
, copy_overlays (to
, buffer_get_overlays (from
, OV_BEFORE
)), OV_BEFORE
);
480 (to
, copy_overlays (to
, buffer_get_overlays (from
, OV_AFTER
)), OV_AFTER
);
482 /* Get (a copy of) the alist of Lisp-level local variables of FROM
483 and install that in TO. */
484 BSET (to
, local_var_alist
, buffer_lisp_local_variables (from
, 1));
488 /* If buffer B has markers to record PT, BEGV and ZV when it is not
489 current, update these markers. */
492 record_buffer_markers (struct buffer
*b
)
494 if (! NILP (BVAR (b
, pt_marker
)))
498 eassert (!NILP (BVAR (b
, begv_marker
)));
499 eassert (!NILP (BVAR (b
, zv_marker
)));
501 XSETBUFFER (buffer
, b
);
502 set_marker_both (BVAR (b
, pt_marker
), buffer
, b
->pt
, b
->pt_byte
);
503 set_marker_both (BVAR (b
, begv_marker
), buffer
, b
->begv
, b
->begv_byte
);
504 set_marker_both (BVAR (b
, zv_marker
), buffer
, b
->zv
, b
->zv_byte
);
509 /* If buffer B has markers to record PT, BEGV and ZV when it is not
510 current, fetch these values into B->begv etc. */
513 fetch_buffer_markers (struct buffer
*b
)
515 if (! NILP (BVAR (b
, pt_marker
)))
519 eassert (!NILP (BVAR (b
, begv_marker
)));
520 eassert (!NILP (BVAR (b
, zv_marker
)));
522 m
= BVAR (b
, pt_marker
);
523 SET_BUF_PT_BOTH (b
, marker_position (m
), marker_byte_position (m
));
525 m
= BVAR (b
, begv_marker
);
526 SET_BUF_BEGV_BOTH (b
, marker_position (m
), marker_byte_position (m
));
528 m
= BVAR (b
, zv_marker
);
529 SET_BUF_ZV_BOTH (b
, marker_position (m
), marker_byte_position (m
));
534 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer
, Smake_indirect_buffer
,
536 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ",
537 doc
: /* Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.
538 BASE-BUFFER should be a live buffer, or the name of an existing buffer.
539 NAME should be a string which is not the name of an existing buffer.
540 Optional argument CLONE non-nil means preserve BASE-BUFFER's state,
541 such as major and minor modes, in the indirect buffer.
542 CLONE nil means the indirect buffer's state is reset to default values. */)
543 (Lisp_Object base_buffer
, Lisp_Object name
, Lisp_Object clone
)
545 Lisp_Object buf
, tem
;
549 buf
= Fget_buffer (name
);
551 error ("Buffer name `%s' is in use", SDATA (name
));
554 base_buffer
= Fget_buffer (base_buffer
);
555 if (NILP (base_buffer
))
556 error ("No such buffer: `%s'", SDATA (tem
));
557 if (NILP (BVAR (XBUFFER (base_buffer
), name
)))
558 error ("Base buffer has been killed");
560 if (SCHARS (name
) == 0)
561 error ("Empty string for buffer name is not allowed");
563 b
= allocate_buffer ();
565 /* No double indirection - if base buffer is indirect,
566 new buffer becomes an indirect to base's base. */
567 b
->base_buffer
= (XBUFFER (base_buffer
)->base_buffer
568 ? XBUFFER (base_buffer
)->base_buffer
569 : XBUFFER (base_buffer
));
571 /* Use the base buffer's text object. */
572 b
->text
= b
->base_buffer
->text
;
573 /* We have no own text. */
574 b
->indirections
= -1;
575 /* Notify base buffer that we share the text now. */
576 b
->base_buffer
->indirections
++;
578 b
->pt
= b
->base_buffer
->pt
;
579 b
->begv
= b
->base_buffer
->begv
;
580 b
->zv
= b
->base_buffer
->zv
;
581 b
->pt_byte
= b
->base_buffer
->pt_byte
;
582 b
->begv_byte
= b
->base_buffer
->begv_byte
;
583 b
->zv_byte
= b
->base_buffer
->zv_byte
;
585 b
->newline_cache
= 0;
586 b
->width_run_cache
= 0;
587 BSET (b
, width_table
, Qnil
);
589 /* Put this on the chain of all buffers including killed ones. */
590 b
->header
.next
.buffer
= all_buffers
;
593 name
= Fcopy_sequence (name
);
594 string_set_intervals (name
, NULL
);
595 BSET (b
, name
, name
);
598 reset_buffer_local_variables (b
, 1);
600 /* Put this in the alist of all live buffers. */
602 Vbuffer_alist
= nconc2 (Vbuffer_alist
, Fcons (Fcons (name
, buf
), Qnil
));
604 BSET (b
, mark
, Fmake_marker ());
606 /* The multibyte status belongs to the base buffer. */
607 BSET (b
, enable_multibyte_characters
, BVAR (b
->base_buffer
, enable_multibyte_characters
));
609 /* Make sure the base buffer has markers for its narrowing. */
610 if (NILP (BVAR (b
->base_buffer
, pt_marker
)))
612 eassert (NILP (BVAR (b
->base_buffer
, begv_marker
)));
613 eassert (NILP (BVAR (b
->base_buffer
, zv_marker
)));
615 BSET (b
->base_buffer
, pt_marker
,
616 build_marker (b
->base_buffer
, b
->base_buffer
->pt
, b
->base_buffer
->pt_byte
));
618 BSET (b
->base_buffer
, begv_marker
,
619 build_marker (b
->base_buffer
, b
->base_buffer
->begv
, b
->base_buffer
->begv_byte
));
621 BSET (b
->base_buffer
, zv_marker
,
622 build_marker (b
->base_buffer
, b
->base_buffer
->zv
, b
->base_buffer
->zv_byte
));
624 XMARKER (BVAR (b
->base_buffer
, zv_marker
))->insertion_type
= 1;
629 /* Give the indirect buffer markers for its narrowing. */
630 BSET (b
, pt_marker
, build_marker (b
, b
->pt
, b
->pt_byte
));
631 BSET (b
, begv_marker
, build_marker (b
, b
->begv
, b
->begv_byte
));
632 BSET (b
, zv_marker
, build_marker (b
, b
->zv
, b
->zv_byte
));
633 XMARKER (BVAR (b
, zv_marker
))->insertion_type
= 1;
637 struct buffer
*old_b
= current_buffer
;
639 clone_per_buffer_values (b
->base_buffer
, b
);
640 BSET (b
, filename
, Qnil
);
641 BSET (b
, file_truename
, Qnil
);
642 BSET (b
, display_count
, make_number (0));
643 BSET (b
, backed_up
, Qnil
);
644 BSET (b
, auto_save_file_name
, Qnil
);
645 set_buffer_internal_1 (b
);
646 Fset (intern ("buffer-save-without-query"), Qnil
);
647 Fset (intern ("buffer-file-number"), Qnil
);
648 Fset (intern ("buffer-stale-function"), Qnil
);
649 set_buffer_internal_1 (old_b
);
652 /* Run buffer-list-update-hook. */
653 if (!NILP (Vrun_hooks
))
654 call1 (Vrun_hooks
, Qbuffer_list_update_hook
);
659 /* Mark OV as no longer associated with B. */
662 drop_overlay (struct buffer
*b
, struct Lisp_Overlay
*ov
)
664 eassert (b
== XBUFFER (Fmarker_buffer (ov
->start
)));
665 modify_overlay (b
, marker_position (ov
->start
),
666 marker_position (ov
->end
));
667 Fset_marker (ov
->start
, Qnil
, Qnil
);
668 Fset_marker (ov
->end
, Qnil
, Qnil
);
672 /* Delete all overlays of B and reset it's overlay lists. */
675 delete_all_overlays (struct buffer
*b
)
677 struct Lisp_Overlay
*ov
, *next
;
679 for (ov
= buffer_get_overlays (b
, OV_BEFORE
); ov
; ov
= next
)
681 drop_overlay (b
, ov
);
686 for (ov
= buffer_get_overlays (b
, OV_AFTER
); ov
; ov
= next
)
688 drop_overlay (b
, ov
);
693 buffer_set_overlays (b
, NULL
, OV_BEFORE
);
694 buffer_set_overlays (b
, NULL
, OV_AFTER
);
697 /* Reinitialize everything about a buffer except its name and contents
699 If called on an already-initialized buffer, the list of overlays
700 should be deleted before calling this function, otherwise we end up
701 with overlays that claim to belong to the buffer but the buffer
702 claims it doesn't belong to it. */
705 reset_buffer (register struct buffer
*b
)
707 BSET (b
, filename
, Qnil
);
708 BSET (b
, file_truename
, Qnil
);
710 (current_buffer
) ? BVAR (current_buffer
, directory
) : Qnil
);
711 b
->modtime
= make_emacs_time (0, UNKNOWN_MODTIME_NSECS
);
712 b
->modtime_size
= -1;
713 XSETFASTINT (BVAR (b
, save_length
), 0);
714 b
->last_window_start
= 1;
715 /* It is more conservative to start out "changed" than "unchanged". */
717 b
->prevent_redisplay_optimizations_p
= 1;
718 BSET (b
, backed_up
, Qnil
);
719 BUF_AUTOSAVE_MODIFF (b
) = 0;
720 b
->auto_save_failure_time
= 0;
721 BSET (b
, auto_save_file_name
, Qnil
);
722 BSET (b
, read_only
, Qnil
);
723 buffer_set_overlays (b
, NULL
, OV_BEFORE
);
724 buffer_set_overlays (b
, NULL
, OV_AFTER
);
725 b
->overlay_center
= BEG
;
726 BSET (b
, mark_active
, Qnil
);
727 BSET (b
, point_before_scroll
, Qnil
);
728 BSET (b
, file_format
, Qnil
);
729 BSET (b
, auto_save_file_format
, Qt
);
730 BSET (b
, last_selected_window
, Qnil
);
731 BSET (b
, display_count
, make_number (0));
732 BSET (b
, display_time
, Qnil
);
733 BSET (b
, enable_multibyte_characters
,
734 BVAR (&buffer_defaults
, enable_multibyte_characters
));
735 BSET (b
, cursor_type
, BVAR (&buffer_defaults
, cursor_type
));
736 BSET (b
, extra_line_spacing
, BVAR (&buffer_defaults
, extra_line_spacing
));
738 b
->display_error_modiff
= 0;
741 /* Reset buffer B's local variables info.
742 Don't use this on a buffer that has already been in use;
743 it does not treat permanent locals consistently.
744 Instead, use Fkill_all_local_variables.
746 If PERMANENT_TOO is 1, then we reset permanent
747 buffer-local variables. If PERMANENT_TOO is 0,
748 we preserve those. */
751 reset_buffer_local_variables (register struct buffer
*b
, int permanent_too
)
756 /* Reset the major mode to Fundamental, together with all the
757 things that depend on the major mode.
758 default-major-mode is handled at a higher level.
759 We ignore it here. */
760 BSET (b
, major_mode
, Qfundamental_mode
);
761 BSET (b
, keymap
, Qnil
);
762 BSET (b
, mode_name
, QSFundamental
);
763 BSET (b
, minor_modes
, Qnil
);
765 /* If the standard case table has been altered and invalidated,
766 fix up its insides first. */
767 if (! (CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[0])
768 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[1])
769 && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table
)->extras
[2])))
770 Fset_standard_case_table (Vascii_downcase_table
);
772 BSET (b
, downcase_table
, Vascii_downcase_table
);
773 BSET (b
, upcase_table
, XCHAR_TABLE (Vascii_downcase_table
)->extras
[0]);
774 BSET (b
, case_canon_table
, XCHAR_TABLE (Vascii_downcase_table
)->extras
[1]);
775 BSET (b
, case_eqv_table
, XCHAR_TABLE (Vascii_downcase_table
)->extras
[2]);
776 BSET (b
, invisibility_spec
, Qt
);
778 /* Reset all (or most) per-buffer variables to their defaults. */
780 BSET (b
, local_var_alist
, Qnil
);
783 Lisp_Object tmp
, prop
, last
= Qnil
;
784 for (tmp
= BVAR (b
, local_var_alist
); CONSP (tmp
); tmp
= XCDR (tmp
))
785 if (!NILP (prop
= Fget (XCAR (XCAR (tmp
)), Qpermanent_local
)))
787 /* If permanent-local, keep it. */
789 if (EQ (prop
, Qpermanent_local_hook
))
791 /* This is a partially permanent hook variable.
792 Preserve only the elements that want to be preserved. */
793 Lisp_Object list
, newlist
;
794 list
= XCDR (XCAR (tmp
));
798 for (newlist
= Qnil
; CONSP (list
); list
= XCDR (list
))
800 Lisp_Object elt
= XCAR (list
);
801 /* Preserve element ELT if it's t,
802 if it is a function with a `permanent-local-hook' property,
803 or if it's not a symbol. */
806 || !NILP (Fget (elt
, Qpermanent_local_hook
)))
807 newlist
= Fcons (elt
, newlist
);
809 XSETCDR (XCAR (tmp
), Fnreverse (newlist
));
812 /* Delete this local variable. */
813 else if (NILP (last
))
814 BSET (b
, local_var_alist
, XCDR (tmp
));
816 XSETCDR (last
, XCDR (tmp
));
819 for (i
= 0; i
< last_per_buffer_idx
; ++i
)
820 if (permanent_too
|| buffer_permanent_local_flags
[i
] == 0)
821 SET_PER_BUFFER_VALUE_P (b
, i
, 0);
823 /* For each slot that has a default value, copy that into the slot. */
824 FOR_EACH_PER_BUFFER_OBJECT_AT (offset
)
826 int idx
= PER_BUFFER_IDX (offset
);
829 || buffer_permanent_local_flags
[idx
] == 0)))
830 PER_BUFFER_VALUE (b
, offset
) = PER_BUFFER_DEFAULT (offset
);
834 /* We split this away from generate-new-buffer, because rename-buffer
835 and set-visited-file-name ought to be able to use this to really
836 rename the buffer properly. */
838 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name
,
839 Sgenerate_new_buffer_name
, 1, 2, 0,
840 doc
: /* Return a string that is the name of no existing buffer based on NAME.
841 If there is no live buffer named NAME, then return NAME.
842 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
843 \(starting at 2) until an unused name is found, and then return that name.
844 Optional second argument IGNORE specifies a name that is okay to use (if
845 it is in the sequence to be tried) even if a buffer with that name exists.
847 If NAME begins with a space (i.e., a buffer that is not normally
848 visible to users), then if buffer NAME already exists a random number
849 is first appended to NAME, to speed up finding a non-existent buffer. */)
850 (register Lisp_Object name
, Lisp_Object ignore
)
852 register Lisp_Object gentemp
, tem
, tem2
;
854 char number
[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
858 tem
= Fstring_equal (name
, ignore
);
861 tem
= Fget_buffer (name
);
865 if (!strncmp (SSDATA (name
), " ", 1)) /* see bug#1229 */
867 /* Note fileio.c:make_temp_name does random differently. */
868 tem2
= concat2 (name
, make_formatted_string
870 XFASTINT (Frandom (make_number (999999)))));
871 tem
= Fget_buffer (tem2
);
881 gentemp
= concat2 (tem2
, make_formatted_string
882 (number
, "<%"pD
"d>", ++count
));
883 tem
= Fstring_equal (gentemp
, ignore
);
886 tem
= Fget_buffer (gentemp
);
893 DEFUN ("buffer-name", Fbuffer_name
, Sbuffer_name
, 0, 1, 0,
894 doc
: /* Return the name of BUFFER, as a string.
895 BUFFER defaults to the current buffer.
896 Return nil if BUFFER has been killed. */)
897 (register Lisp_Object buffer
)
900 return BVAR (current_buffer
, name
);
901 CHECK_BUFFER (buffer
);
902 return BVAR (XBUFFER (buffer
), name
);
905 DEFUN ("buffer-file-name", Fbuffer_file_name
, Sbuffer_file_name
, 0, 1, 0,
906 doc
: /* Return name of file BUFFER is visiting, or nil if none.
907 No argument or nil as argument means use the current buffer. */)
908 (register Lisp_Object buffer
)
911 return BVAR (current_buffer
, filename
);
912 CHECK_BUFFER (buffer
);
913 return BVAR (XBUFFER (buffer
), filename
);
916 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer
, Sbuffer_base_buffer
,
918 doc
: /* Return the base buffer of indirect buffer BUFFER.
919 If BUFFER is not indirect, return nil.
920 BUFFER defaults to the current buffer. */)
921 (register Lisp_Object buffer
)
924 Lisp_Object base_buffer
;
927 base
= current_buffer
->base_buffer
;
930 CHECK_BUFFER (buffer
);
931 base
= XBUFFER (buffer
)->base_buffer
;
936 XSETBUFFER (base_buffer
, base
);
940 DEFUN ("buffer-local-value", Fbuffer_local_value
,
941 Sbuffer_local_value
, 2, 2, 0,
942 doc
: /* Return the value of VARIABLE in BUFFER.
943 If VARIABLE does not have a buffer-local binding in BUFFER, the value
944 is the default binding of the variable. */)
945 (register Lisp_Object variable
, register Lisp_Object buffer
)
947 register Lisp_Object result
= buffer_local_value_1 (variable
, buffer
);
949 if (EQ (result
, Qunbound
))
950 xsignal1 (Qvoid_variable
, variable
);
956 /* Like Fbuffer_local_value, but return Qunbound if the variable is
960 buffer_local_value_1 (Lisp_Object variable
, Lisp_Object buffer
)
962 register struct buffer
*buf
;
963 register Lisp_Object result
;
964 struct Lisp_Symbol
*sym
;
966 CHECK_SYMBOL (variable
);
967 CHECK_BUFFER (buffer
);
968 buf
= XBUFFER (buffer
);
969 sym
= XSYMBOL (variable
);
972 switch (sym
->redirect
)
974 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
975 case SYMBOL_PLAINVAL
: result
= SYMBOL_VAL (sym
); break;
976 case SYMBOL_LOCALIZED
:
977 { /* Look in local_var_alist. */
978 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
979 XSETSYMBOL (variable
, sym
); /* Update In case of aliasing. */
980 result
= Fassoc (variable
, BVAR (buf
, local_var_alist
));
984 { /* What binding is loaded right now? */
985 Lisp_Object current_alist_element
= blv
->valcell
;
987 /* The value of the currently loaded binding is not
988 stored in it, but rather in the realvalue slot.
989 Store that value into the binding it belongs to
990 in case that is the one we are about to use. */
992 XSETCDR (current_alist_element
,
993 do_symval_forwarding (blv
->fwd
));
995 /* Now get the (perhaps updated) value out of the binding. */
996 result
= XCDR (result
);
999 result
= Fdefault_value (variable
);
1002 case SYMBOL_FORWARDED
:
1004 union Lisp_Fwd
*fwd
= SYMBOL_FWD (sym
);
1005 if (BUFFER_OBJFWDP (fwd
))
1006 result
= PER_BUFFER_VALUE (buf
, XBUFFER_OBJFWD (fwd
)->offset
);
1008 result
= Fdefault_value (variable
);
1017 /* Return an alist of the Lisp-level buffer-local bindings of
1018 buffer BUF. That is, don't include the variables maintained
1019 in special slots in the buffer object.
1020 If CLONE is zero elements of the form (VAR . unbound) are replaced
1024 buffer_lisp_local_variables (struct buffer
*buf
, int clone
)
1026 Lisp_Object result
= Qnil
;
1027 register Lisp_Object tail
;
1028 for (tail
= BVAR (buf
, local_var_alist
); CONSP (tail
); tail
= XCDR (tail
))
1030 Lisp_Object val
, elt
;
1034 /* Reference each variable in the alist in buf.
1035 If inquiring about the current buffer, this gets the current values,
1036 so store them into the alist so the alist is up to date.
1037 If inquiring about some other buffer, this swaps out any values
1038 for that buffer, making the alist up to date automatically. */
1039 val
= find_symbol_value (XCAR (elt
));
1040 /* Use the current buffer value only if buf is the current buffer. */
1041 if (buf
!= current_buffer
)
1044 result
= Fcons (!clone
&& EQ (val
, Qunbound
)
1046 : Fcons (XCAR (elt
), val
),
1053 DEFUN ("buffer-local-variables", Fbuffer_local_variables
,
1054 Sbuffer_local_variables
, 0, 1, 0,
1055 doc
: /* Return an alist of variables that are buffer-local in BUFFER.
1056 Most elements look like (SYMBOL . VALUE), describing one variable.
1057 For a symbol that is locally unbound, just the symbol appears in the value.
1058 Note that storing new VALUEs in these elements doesn't change the variables.
1059 No argument or nil as argument means use current buffer as BUFFER. */)
1060 (register Lisp_Object buffer
)
1062 register struct buffer
*buf
;
1063 register Lisp_Object result
;
1066 buf
= current_buffer
;
1069 CHECK_BUFFER (buffer
);
1070 buf
= XBUFFER (buffer
);
1073 result
= buffer_lisp_local_variables (buf
, 0);
1075 /* Add on all the variables stored in special slots. */
1079 FOR_EACH_PER_BUFFER_OBJECT_AT (offset
)
1081 idx
= PER_BUFFER_IDX (offset
);
1082 if ((idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
1083 && SYMBOLP (PER_BUFFER_SYMBOL (offset
)))
1085 Lisp_Object sym
= PER_BUFFER_SYMBOL (offset
);
1086 Lisp_Object val
= PER_BUFFER_VALUE (buf
, offset
);
1087 result
= Fcons (EQ (val
, Qunbound
) ? sym
: Fcons (sym
, val
),
1096 DEFUN ("buffer-modified-p", Fbuffer_modified_p
, Sbuffer_modified_p
,
1098 doc
: /* Return t if BUFFER was modified since its file was last read or saved.
1099 No argument or nil as argument means use current buffer as BUFFER. */)
1100 (register Lisp_Object buffer
)
1102 register struct buffer
*buf
;
1104 buf
= current_buffer
;
1107 CHECK_BUFFER (buffer
);
1108 buf
= XBUFFER (buffer
);
1111 return BUF_SAVE_MODIFF (buf
) < BUF_MODIFF (buf
) ? Qt
: Qnil
;
1114 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p
, Sset_buffer_modified_p
,
1116 doc
: /* Mark current buffer as modified or unmodified according to FLAG.
1117 A non-nil FLAG means mark the buffer modified. */)
1118 (register Lisp_Object flag
)
1120 register int already
;
1121 register Lisp_Object fn
;
1122 Lisp_Object buffer
, window
;
1124 #ifdef CLASH_DETECTION
1125 /* If buffer becoming modified, lock the file.
1126 If buffer becoming unmodified, unlock the file. */
1128 fn
= BVAR (current_buffer
, file_truename
);
1129 /* Test buffer-file-name so that binding it to nil is effective. */
1130 if (!NILP (fn
) && ! NILP (BVAR (current_buffer
, filename
)))
1132 already
= SAVE_MODIFF
< MODIFF
;
1133 if (!already
&& !NILP (flag
))
1135 else if (already
&& NILP (flag
))
1138 #endif /* CLASH_DETECTION */
1140 /* Here we have a problem. SAVE_MODIFF is used here to encode
1141 buffer-modified-p (as SAVE_MODIFF<MODIFF) as well as
1142 recent-auto-save-p (as SAVE_MODIFF<auto_save_modified). So if we
1143 modify SAVE_MODIFF to affect one, we may affect the other
1145 E.g. if FLAG is nil we need to set SAVE_MODIFF to MODIFF, but
1146 if SAVE_MODIFF<auto_save_modified that means we risk changing
1147 recent-auto-save-p from t to nil.
1148 Vice versa, if FLAG is non-nil and SAVE_MODIFF>=auto_save_modified
1149 we risk changing recent-auto-save-p from nil to t. */
1150 SAVE_MODIFF
= (NILP (flag
)
1151 /* FIXME: This unavoidably sets recent-auto-save-p to nil. */
1153 /* Let's try to preserve recent-auto-save-p. */
1154 : SAVE_MODIFF
< MODIFF
? SAVE_MODIFF
1155 /* If SAVE_MODIFF == auto_save_modified == MODIFF,
1156 we can either decrease SAVE_MODIFF and auto_save_modified
1157 or increase MODIFF. */
1160 /* Set update_mode_lines only if buffer is displayed in some window.
1161 Packages like jit-lock or lazy-lock preserve a buffer's modified
1162 state by recording/restoring the state around blocks of code.
1163 Setting update_mode_lines makes redisplay consider all windows
1164 (on all frames). Stealth fontification of buffers not displayed
1165 would incur additional redisplay costs if we'd set
1166 update_modes_lines unconditionally.
1168 Ideally, I think there should be another mechanism for fontifying
1169 buffers without "modifying" buffers, or redisplay should be
1170 smarter about updating the `*' in mode lines. --gerd */
1171 XSETBUFFER (buffer
, current_buffer
);
1172 window
= Fget_buffer_window (buffer
, Qt
);
1173 if (WINDOWP (window
))
1175 ++update_mode_lines
;
1176 current_buffer
->prevent_redisplay_optimizations_p
= 1;
1182 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p
,
1183 Srestore_buffer_modified_p
, 1, 1, 0,
1184 doc
: /* Like `set-buffer-modified-p', with a difference concerning redisplay.
1185 It is not ensured that mode lines will be updated to show the modified
1186 state of the current buffer. Use with care. */)
1189 #ifdef CLASH_DETECTION
1192 /* If buffer becoming modified, lock the file.
1193 If buffer becoming unmodified, unlock the file. */
1195 fn
= BVAR (current_buffer
, file_truename
);
1196 /* Test buffer-file-name so that binding it to nil is effective. */
1197 if (!NILP (fn
) && ! NILP (BVAR (current_buffer
, filename
)))
1199 int already
= SAVE_MODIFF
< MODIFF
;
1200 if (!already
&& !NILP (flag
))
1202 else if (already
&& NILP (flag
))
1205 #endif /* CLASH_DETECTION */
1207 SAVE_MODIFF
= NILP (flag
) ? MODIFF
: 0;
1211 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick
, Sbuffer_modified_tick
,
1213 doc
: /* Return BUFFER's tick counter, incremented for each change in text.
1214 Each buffer has a tick counter which is incremented each time the
1215 text in that buffer is changed. It wraps around occasionally.
1216 No argument or nil as argument means use current buffer as BUFFER. */)
1217 (register Lisp_Object buffer
)
1219 register struct buffer
*buf
;
1221 buf
= current_buffer
;
1224 CHECK_BUFFER (buffer
);
1225 buf
= XBUFFER (buffer
);
1228 return make_number (BUF_MODIFF (buf
));
1231 DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick
,
1232 Sbuffer_chars_modified_tick
, 0, 1, 0,
1233 doc
: /* Return BUFFER's character-change tick counter.
1234 Each buffer has a character-change tick counter, which is set to the
1235 value of the buffer's tick counter \(see `buffer-modified-tick'), each
1236 time text in that buffer is inserted or deleted. By comparing the
1237 values returned by two individual calls of `buffer-chars-modified-tick',
1238 you can tell whether a character change occurred in that buffer in
1239 between these calls. No argument or nil as argument means use current
1240 buffer as BUFFER. */)
1241 (register Lisp_Object buffer
)
1243 register struct buffer
*buf
;
1245 buf
= current_buffer
;
1248 CHECK_BUFFER (buffer
);
1249 buf
= XBUFFER (buffer
);
1252 return make_number (BUF_CHARS_MODIFF (buf
));
1255 DEFUN ("rename-buffer", Frename_buffer
, Srename_buffer
, 1, 2,
1256 "(list (read-string \"Rename buffer (to new name): \" \
1257 nil 'buffer-name-history (buffer-name (current-buffer))) \
1258 current-prefix-arg)",
1259 doc
: /* Change current buffer's name to NEWNAME (a string).
1260 If second arg UNIQUE is nil or omitted, it is an error if a
1261 buffer named NEWNAME already exists.
1262 If UNIQUE is non-nil, come up with a new name using
1263 `generate-new-buffer-name'.
1264 Interactively, you can set UNIQUE with a prefix argument.
1265 We return the name we actually gave the buffer.
1266 This does not change the name of the visited file (if any). */)
1267 (register Lisp_Object newname
, Lisp_Object unique
)
1269 register Lisp_Object tem
, buf
;
1271 CHECK_STRING (newname
);
1273 if (SCHARS (newname
) == 0)
1274 error ("Empty string is invalid as a buffer name");
1276 tem
= Fget_buffer (newname
);
1279 /* Don't short-circuit if UNIQUE is t. That is a useful way to
1280 rename the buffer automatically so you can create another
1281 with the original name. It makes UNIQUE equivalent to
1282 (rename-buffer (generate-new-buffer-name NEWNAME)). */
1283 if (NILP (unique
) && XBUFFER (tem
) == current_buffer
)
1284 return BVAR (current_buffer
, name
);
1286 newname
= Fgenerate_new_buffer_name (newname
, BVAR (current_buffer
, name
));
1288 error ("Buffer name `%s' is in use", SDATA (newname
));
1291 BSET (current_buffer
, name
, newname
);
1293 /* Catch redisplay's attention. Unless we do this, the mode lines for
1294 any windows displaying current_buffer will stay unchanged. */
1295 update_mode_lines
++;
1297 XSETBUFFER (buf
, current_buffer
);
1298 Fsetcar (Frassq (buf
, Vbuffer_alist
), newname
);
1299 if (NILP (BVAR (current_buffer
, filename
))
1300 && !NILP (BVAR (current_buffer
, auto_save_file_name
)))
1301 call0 (intern ("rename-auto-save-file"));
1303 /* Run buffer-list-update-hook. */
1304 if (!NILP (Vrun_hooks
))
1305 call1 (Vrun_hooks
, Qbuffer_list_update_hook
);
1307 /* Refetch since that last call may have done GC. */
1308 return BVAR (current_buffer
, name
);
1311 DEFUN ("other-buffer", Fother_buffer
, Sother_buffer
, 0, 3, 0,
1312 doc
: /* Return most recently selected buffer other than BUFFER.
1313 Buffers not visible in windows are preferred to visible buffers, unless
1314 optional second argument VISIBLE-OK is non-nil. Ignore the argument
1315 BUFFER unless it denotes a live buffer. If the optional third argument
1316 FRAME is non-nil, use that frame's buffer list instead of the selected
1317 frame's buffer list.
1319 The buffer is found by scanning the selected or specified frame's buffer
1320 list first, followed by the list of all buffers. If no other buffer
1321 exists, return the buffer `*scratch*' (creating it if necessary). */)
1322 (register Lisp_Object buffer
, Lisp_Object visible_ok
, Lisp_Object frame
)
1324 Lisp_Object
Fset_buffer_major_mode (Lisp_Object buffer
);
1325 Lisp_Object tail
, buf
, pred
;
1326 Lisp_Object notsogood
= Qnil
;
1329 frame
= selected_frame
;
1331 CHECK_FRAME (frame
);
1333 pred
= frame_buffer_predicate (frame
);
1334 /* Consider buffers that have been seen in the frame first. */
1335 tail
= XFRAME (frame
)->buffer_list
;
1336 for (; CONSP (tail
); tail
= XCDR (tail
))
1339 if (BUFFERP (buf
) && !EQ (buf
, buffer
)
1340 && !NILP (BVAR (XBUFFER (buf
), name
))
1341 && (SREF (BVAR (XBUFFER (buf
), name
), 0) != ' ')
1342 /* If the frame has a buffer_predicate, disregard buffers that
1343 don't fit the predicate. */
1344 && (NILP (pred
) || !NILP (call1 (pred
, buf
))))
1346 if (!NILP (visible_ok
)
1347 || NILP (Fget_buffer_window (buf
, Qvisible
)))
1349 else if (NILP (notsogood
))
1354 /* Consider alist of all buffers next. */
1355 tail
= Vbuffer_alist
;
1356 for (; CONSP (tail
); tail
= XCDR (tail
))
1358 buf
= Fcdr (XCAR (tail
));
1359 if (BUFFERP (buf
) && !EQ (buf
, buffer
)
1360 && !NILP (BVAR (XBUFFER (buf
), name
))
1361 && (SREF (BVAR (XBUFFER (buf
), name
), 0) != ' ')
1362 /* If the frame has a buffer_predicate, disregard buffers that
1363 don't fit the predicate. */
1364 && (NILP (pred
) || !NILP (call1 (pred
, buf
))))
1366 if (!NILP (visible_ok
)
1367 || NILP (Fget_buffer_window (buf
, Qvisible
)))
1369 else if (NILP (notsogood
))
1374 if (!NILP (notsogood
))
1378 buf
= Fget_buffer (build_string ("*scratch*"));
1381 buf
= Fget_buffer_create (build_string ("*scratch*"));
1382 Fset_buffer_major_mode (buf
);
1388 /* The following function is a safe variant of Fother_buffer: It doesn't
1389 pay attention to any frame-local buffer lists, doesn't care about
1390 visibility of buffers, and doesn't evaluate any frame predicates. */
1393 other_buffer_safely (Lisp_Object buffer
)
1395 Lisp_Object
Fset_buffer_major_mode (Lisp_Object buffer
);
1396 Lisp_Object tail
, buf
;
1398 tail
= Vbuffer_alist
;
1399 for (; CONSP (tail
); tail
= XCDR (tail
))
1401 buf
= Fcdr (XCAR (tail
));
1402 if (BUFFERP (buf
) && !EQ (buf
, buffer
)
1403 && !NILP (BVAR (XBUFFER (buf
), name
))
1404 && (SREF (BVAR (XBUFFER (buf
), name
), 0) != ' '))
1408 buf
= Fget_buffer (build_string ("*scratch*"));
1411 buf
= Fget_buffer_create (build_string ("*scratch*"));
1412 Fset_buffer_major_mode (buf
);
1418 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo
, Sbuffer_enable_undo
,
1420 doc
: /* Start keeping undo information for buffer BUFFER.
1421 No argument or nil as argument means do this for the current buffer. */)
1422 (register Lisp_Object buffer
)
1424 Lisp_Object real_buffer
;
1427 XSETBUFFER (real_buffer
, current_buffer
);
1430 real_buffer
= Fget_buffer (buffer
);
1431 if (NILP (real_buffer
))
1435 if (EQ (BVAR (XBUFFER (real_buffer
), undo_list
), Qt
))
1436 BSET (XBUFFER (real_buffer
), undo_list
, Qnil
);
1441 /* Truncate undo list and shrink the gap of BUFFER. */
1444 compact_buffer (struct buffer
*buffer
)
1446 /* Verify indirection counters. */
1447 if (buffer
->base_buffer
)
1449 eassert (buffer
->indirections
== -1);
1450 eassert (buffer
->base_buffer
->indirections
> 0);
1453 eassert (buffer
->indirections
>= 0);
1455 /* Skip dead buffers, indirect buffers and buffers
1456 which aren't changed since last compaction. */
1457 if (!NILP (buffer
->INTERNAL_FIELD (name
))
1458 && (buffer
->base_buffer
== NULL
)
1459 && (buffer
->text
->compact
!= buffer
->text
->modiff
))
1461 /* If a buffer's undo list is Qt, that means that undo is
1462 turned off in that buffer. Calling truncate_undo_list on
1463 Qt tends to return NULL, which effectively turns undo back on.
1464 So don't call truncate_undo_list if undo_list is Qt. */
1465 if (!EQ (buffer
->INTERNAL_FIELD (undo_list
), Qt
))
1466 truncate_undo_list (buffer
);
1468 /* Shrink buffer gaps. */
1469 if (!buffer
->text
->inhibit_shrinking
)
1471 /* If a buffer's gap size is more than 10% of the buffer
1472 size, or larger than 2000 bytes, then shrink it
1473 accordingly. Keep a minimum size of 20 bytes. */
1474 int size
= min (2000, max (20, (buffer
->text
->z_byte
/ 10)));
1476 if (buffer
->text
->gap_size
> size
)
1478 struct buffer
*save_current
= current_buffer
;
1479 current_buffer
= buffer
;
1480 make_gap (-(buffer
->text
->gap_size
- size
));
1481 current_buffer
= save_current
;
1484 buffer
->text
->compact
= buffer
->text
->modiff
;
1490 DEFUN ("kill-buffer", Fkill_buffer
, Skill_buffer
, 0, 1, "bKill buffer: ",
1491 doc
: /* Kill the buffer specified by BUFFER-OR-NAME.
1492 The argument may be a buffer or the name of an existing buffer.
1493 Argument nil or omitted means kill the current buffer. Return t if the
1494 buffer is actually killed, nil otherwise.
1496 The functions in `kill-buffer-query-functions' are called with the
1497 buffer to be killed as the current buffer. If any of them returns nil,
1498 the buffer is not killed. The hook `kill-buffer-hook' is run before the
1499 buffer is actually killed. The buffer being killed will be current
1500 while the hook is running. Functions called by any of these hooks are
1501 supposed to not change the current buffer.
1503 Any processes that have this buffer as the `process-buffer' are killed
1504 with SIGHUP. This function calls `replace-buffer-in-windows' for
1505 cleaning up all windows currently displaying the buffer to be killed. */)
1506 (Lisp_Object buffer_or_name
)
1509 register struct buffer
*b
;
1510 register Lisp_Object tem
;
1511 register struct Lisp_Marker
*m
;
1512 struct gcpro gcpro1
;
1514 if (NILP (buffer_or_name
))
1515 buffer
= Fcurrent_buffer ();
1517 buffer
= Fget_buffer (buffer_or_name
);
1519 nsberror (buffer_or_name
);
1521 b
= XBUFFER (buffer
);
1523 /* Avoid trouble for buffer already dead. */
1524 if (NILP (BVAR (b
, name
)))
1527 /* Query if the buffer is still modified. */
1528 if (INTERACTIVE
&& !NILP (BVAR (b
, filename
))
1529 && BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
1532 tem
= do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
1533 BVAR (b
, name
), make_number (0)));
1539 /* Run hooks with the buffer to be killed the current buffer. */
1541 ptrdiff_t count
= SPECPDL_INDEX ();
1542 Lisp_Object arglist
[1];
1544 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1545 set_buffer_internal (b
);
1547 /* First run the query functions; if any query is answered no,
1548 don't kill the buffer. */
1549 arglist
[0] = Qkill_buffer_query_functions
;
1550 tem
= Frun_hook_with_args_until_failure (1, arglist
);
1552 return unbind_to (count
, Qnil
);
1554 /* Then run the hooks. */
1555 Frun_hooks (1, &Qkill_buffer_hook
);
1556 unbind_to (count
, Qnil
);
1559 /* If the hooks have killed the buffer, exit now. */
1560 if (NILP (BVAR (b
, name
)))
1563 /* We have no more questions to ask. Verify that it is valid
1564 to kill the buffer. This must be done after the questions
1565 since anything can happen within do_yes_or_no_p. */
1567 /* Don't kill the minibuffer now current. */
1568 if (EQ (buffer
, XWINDOW (minibuf_window
)->buffer
))
1571 /* When we kill an ordinary buffer which shares it's buffer text
1572 with indirect buffer(s), we must kill indirect buffer(s) too.
1573 We do it at this stage so nothing terrible happens if they
1574 ask questions or their hooks get errors. */
1575 if (!b
->base_buffer
&& b
->indirections
> 0)
1577 struct buffer
*other
;
1581 FOR_EACH_BUFFER (other
)
1582 if (other
->base_buffer
== b
)
1585 XSETBUFFER (buf
, other
);
1591 /* Exit if we now have killed the base buffer (Bug#11665). */
1592 if (NILP (BVAR (b
, name
)))
1596 /* Run replace_buffer_in_windows before making another buffer current
1597 since set-window-buffer-start-and-point will refuse to make another
1598 buffer current if the selected window does not show the current
1599 buffer. (Bug#10114) */
1600 replace_buffer_in_windows (buffer
);
1602 /* Exit if replacing the buffer in windows has killed our buffer. */
1603 if (NILP (BVAR (b
, name
)))
1606 /* Make this buffer not be current. Exit if it is the sole visible
1608 if (b
== current_buffer
)
1610 tem
= Fother_buffer (buffer
, Qnil
, Qnil
);
1612 if (b
== current_buffer
)
1616 /* If the buffer now current is shown in the minibuffer and our buffer
1617 is the sole other buffer give up. */
1618 XSETBUFFER (tem
, current_buffer
);
1619 if (EQ (tem
, XWINDOW (minibuf_window
)->buffer
)
1620 && EQ (buffer
, Fother_buffer (buffer
, Qnil
, Qnil
)))
1623 /* Now there is no question: we can kill the buffer. */
1625 #ifdef CLASH_DETECTION
1626 /* Unlock this buffer's file, if it is locked. */
1628 #endif /* CLASH_DETECTION */
1631 kill_buffer_processes (buffer
);
1634 /* Killing buffer processes may run sentinels which may have killed
1636 if (NILP (BVAR (b
, name
)))
1639 /* These may run Lisp code and into infinite loops (if someone
1640 insisted on circular lists) so allow quitting here. */
1641 frames_discard_buffer (buffer
);
1643 clear_charpos_cache (b
);
1645 tem
= Vinhibit_quit
;
1647 /* Remove the buffer from the list of all buffers. */
1648 Vbuffer_alist
= Fdelq (Frassq (buffer
, Vbuffer_alist
), Vbuffer_alist
);
1649 /* If replace_buffer_in_windows didn't do its job fix that now. */
1650 replace_buffer_in_windows_safely (buffer
);
1651 Vinhibit_quit
= tem
;
1653 /* Delete any auto-save file, if we saved it in this session.
1654 But not if the buffer is modified. */
1655 if (STRINGP (BVAR (b
, auto_save_file_name
))
1656 && BUF_AUTOSAVE_MODIFF (b
) != 0
1657 && BUF_SAVE_MODIFF (b
) < BUF_AUTOSAVE_MODIFF (b
)
1658 && BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)
1659 && NILP (Fsymbol_value (intern ("auto-save-visited-file-name"))))
1662 delete = Fsymbol_value (intern ("delete-auto-save-files"));
1663 if (! NILP (delete))
1664 internal_delete_file (BVAR (b
, auto_save_file_name
));
1667 /* Deleting an auto-save file could have killed our buffer. */
1668 if (NILP (BVAR (b
, name
)))
1673 /* Unchain all markers that belong to this indirect buffer.
1674 Don't unchain the markers that belong to the base buffer
1675 or its other indirect buffers. */
1676 for (m
= BUF_MARKERS (b
); m
; )
1678 struct Lisp_Marker
*next
= m
->next
;
1686 /* Unchain all markers of this buffer and its indirect buffers.
1687 and leave them pointing nowhere. */
1688 for (m
= BUF_MARKERS (b
); m
; )
1690 struct Lisp_Marker
*next
= m
->next
;
1695 BUF_MARKERS (b
) = NULL
;
1696 buffer_set_intervals (b
, NULL
);
1698 /* Perhaps we should explicitly free the interval tree here... */
1701 /* Reset the local variables, so that this buffer's local values
1702 won't be protected from GC. They would be protected
1703 if they happened to remain cached in their symbols.
1704 This gets rid of them for certain. */
1705 swap_out_buffer_local_variables (b
);
1706 reset_buffer_local_variables (b
, 1);
1708 BSET (b
, name
, Qnil
);
1713 /* Notify our base buffer that we don't share the text anymore. */
1714 eassert (b
->indirections
== -1);
1715 b
->base_buffer
->indirections
--;
1716 eassert (b
->base_buffer
->indirections
>= 0);
1719 /* No one shares our buffer text, can free it. */
1720 free_buffer_text (b
);
1722 if (b
->newline_cache
)
1724 free_region_cache (b
->newline_cache
);
1725 b
->newline_cache
= 0;
1727 if (b
->width_run_cache
)
1729 free_region_cache (b
->width_run_cache
);
1730 b
->width_run_cache
= 0;
1732 BSET (b
, width_table
, Qnil
);
1734 BSET (b
, undo_list
, Qnil
);
1736 /* Run buffer-list-update-hook. */
1737 if (!NILP (Vrun_hooks
))
1738 call1 (Vrun_hooks
, Qbuffer_list_update_hook
);
1743 /* Move association for BUFFER to the front of buffer (a)lists. Since
1744 we do this each time BUFFER is selected visibly, the more recently
1745 selected buffers are always closer to the front of those lists. This
1746 means that other_buffer is more likely to choose a relevant buffer.
1748 Note that this moves BUFFER to the front of the buffer lists of the
1749 selected frame even if BUFFER is not shown there. If BUFFER is not
1750 shown in the selected frame, consider the present behavior a feature.
1751 `select-window' gets this right since it shows BUFFER in the selected
1752 window when calling us. */
1755 record_buffer (Lisp_Object buffer
)
1757 Lisp_Object aelt
, aelt_cons
, tem
;
1758 register struct frame
*f
= XFRAME (selected_frame
);
1760 CHECK_BUFFER (buffer
);
1762 /* Update Vbuffer_alist (we know that it has an entry for BUFFER).
1763 Don't allow quitting since this might leave the buffer list in an
1764 inconsistent state. */
1765 tem
= Vinhibit_quit
;
1767 aelt
= Frassq (buffer
, Vbuffer_alist
);
1768 aelt_cons
= Fmemq (aelt
, Vbuffer_alist
);
1769 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1770 XSETCDR (aelt_cons
, Vbuffer_alist
);
1771 Vbuffer_alist
= aelt_cons
;
1772 Vinhibit_quit
= tem
;
1774 /* Update buffer list of selected frame. */
1775 FSET (f
, buffer_list
, Fcons (buffer
, Fdelq (buffer
, f
->buffer_list
)));
1776 FSET (f
, buried_buffer_list
, Fdelq (buffer
, f
->buried_buffer_list
));
1778 /* Run buffer-list-update-hook. */
1779 if (!NILP (Vrun_hooks
))
1780 call1 (Vrun_hooks
, Qbuffer_list_update_hook
);
1784 /* Move BUFFER to the end of the buffer (a)lists. Do nothing if the
1785 buffer is killed. For the selected frame's buffer list this moves
1786 BUFFER to its end even if it was never shown in that frame. If
1787 this happens we have a feature, hence `bury-buffer-internal' should be
1788 called only when BUFFER was shown in the selected frame. */
1790 DEFUN ("bury-buffer-internal", Fbury_buffer_internal
, Sbury_buffer_internal
,
1792 doc
: /* Move BUFFER to the end of the buffer list. */)
1793 (Lisp_Object buffer
)
1795 Lisp_Object aelt
, aelt_cons
, tem
;
1796 register struct frame
*f
= XFRAME (selected_frame
);
1798 CHECK_BUFFER (buffer
);
1800 /* Update Vbuffer_alist (we know that it has an entry for BUFFER).
1801 Don't allow quitting since this might leave the buffer list in an
1802 inconsistent state. */
1803 tem
= Vinhibit_quit
;
1805 aelt
= Frassq (buffer
, Vbuffer_alist
);
1806 aelt_cons
= Fmemq (aelt
, Vbuffer_alist
);
1807 Vbuffer_alist
= Fdelq (aelt
, Vbuffer_alist
);
1808 XSETCDR (aelt_cons
, Qnil
);
1809 Vbuffer_alist
= nconc2 (Vbuffer_alist
, aelt_cons
);
1810 Vinhibit_quit
= tem
;
1812 /* Update buffer lists of selected frame. */
1813 FSET (f
, buffer_list
, Fdelq (buffer
, f
->buffer_list
));
1814 FSET (f
, buried_buffer_list
,
1815 Fcons (buffer
, Fdelq (buffer
, f
->buried_buffer_list
)));
1817 /* Run buffer-list-update-hook. */
1818 if (!NILP (Vrun_hooks
))
1819 call1 (Vrun_hooks
, Qbuffer_list_update_hook
);
1824 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode
, Sset_buffer_major_mode
, 1, 1, 0,
1825 doc
: /* Set an appropriate major mode for BUFFER.
1826 For the *scratch* buffer, use `initial-major-mode', otherwise choose a mode
1827 according to `default-major-mode'.
1828 Use this function before selecting the buffer, since it may need to inspect
1829 the current buffer's major mode. */)
1830 (Lisp_Object buffer
)
1833 Lisp_Object function
;
1835 CHECK_BUFFER (buffer
);
1837 if (STRINGP (BVAR (XBUFFER (buffer
), name
))
1838 && strcmp (SSDATA (BVAR (XBUFFER (buffer
), name
)), "*scratch*") == 0)
1839 function
= find_symbol_value (intern ("initial-major-mode"));
1842 function
= BVAR (&buffer_defaults
, major_mode
);
1844 && NILP (Fget (BVAR (current_buffer
, major_mode
), Qmode_class
)))
1845 function
= BVAR (current_buffer
, major_mode
);
1848 if (NILP (function
) || EQ (function
, Qfundamental_mode
))
1851 count
= SPECPDL_INDEX ();
1853 /* To select a nonfundamental mode,
1854 select the buffer temporarily and then call the mode function. */
1856 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1858 Fset_buffer (buffer
);
1861 return unbind_to (count
, Qnil
);
1864 DEFUN ("current-buffer", Fcurrent_buffer
, Scurrent_buffer
, 0, 0, 0,
1865 doc
: /* Return the current buffer as a Lisp object. */)
1868 register Lisp_Object buf
;
1869 XSETBUFFER (buf
, current_buffer
);
1873 /* Set the current buffer to B.
1875 We previously set windows_or_buffers_changed here to invalidate
1876 global unchanged information in beg_unchanged and end_unchanged.
1877 This is no longer necessary because we now compute unchanged
1878 information on a buffer-basis. Every action affecting other
1879 windows than the selected one requires a select_window at some
1880 time, and that increments windows_or_buffers_changed. */
1883 set_buffer_internal (register struct buffer
*b
)
1885 if (current_buffer
!= b
)
1886 set_buffer_internal_1 (b
);
1889 /* Set the current buffer to B, and do not set windows_or_buffers_changed.
1890 This is used by redisplay. */
1893 set_buffer_internal_1 (register struct buffer
*b
)
1895 register struct buffer
*old_buf
;
1896 register Lisp_Object tail
;
1898 #ifdef USE_MMAP_FOR_BUFFERS
1899 if (b
->text
->beg
== NULL
)
1900 enlarge_buffer_text (b
, 0);
1901 #endif /* USE_MMAP_FOR_BUFFERS */
1903 if (current_buffer
== b
)
1906 old_buf
= current_buffer
;
1908 last_known_column_point
= -1; /* invalidate indentation cache */
1912 /* Put the undo list back in the base buffer, so that it appears
1913 that an indirect buffer shares the undo list of its base. */
1914 if (old_buf
->base_buffer
)
1915 BSET (old_buf
->base_buffer
, undo_list
, BVAR (old_buf
, undo_list
));
1917 /* If the old current buffer has markers to record PT, BEGV and ZV
1918 when it is not current, update them now. */
1919 record_buffer_markers (old_buf
);
1922 /* Get the undo list from the base buffer, so that it appears
1923 that an indirect buffer shares the undo list of its base. */
1925 BSET (b
, undo_list
, BVAR (b
->base_buffer
, undo_list
));
1927 /* If the new current buffer has markers to record PT, BEGV and ZV
1928 when it is not current, fetch them now. */
1929 fetch_buffer_markers (b
);
1931 /* Look down buffer's list of local Lisp variables
1932 to find and update any that forward into C variables. */
1936 for (tail
= BVAR (b
, local_var_alist
); CONSP (tail
); tail
= XCDR (tail
))
1938 Lisp_Object var
= XCAR (XCAR (tail
));
1939 struct Lisp_Symbol
*sym
= XSYMBOL (var
);
1940 if (sym
->redirect
== SYMBOL_LOCALIZED
/* Just to be sure. */
1941 && SYMBOL_BLV (sym
)->fwd
)
1942 /* Just reference the variable
1943 to cause it to become set for this buffer. */
1944 Fsymbol_value (var
);
1947 /* Do the same with any others that were local to the previous buffer */
1948 while (b
!= old_buf
&& (b
= old_buf
, b
));
1951 /* Switch to buffer B temporarily for redisplay purposes.
1952 This avoids certain things that don't need to be done within redisplay. */
1955 set_buffer_temp (struct buffer
*b
)
1957 register struct buffer
*old_buf
;
1959 if (current_buffer
== b
)
1962 old_buf
= current_buffer
;
1965 /* If the old current buffer has markers to record PT, BEGV and ZV
1966 when it is not current, update them now. */
1967 record_buffer_markers (old_buf
);
1969 /* If the new current buffer has markers to record PT, BEGV and ZV
1970 when it is not current, fetch them now. */
1971 fetch_buffer_markers (b
);
1974 DEFUN ("set-buffer", Fset_buffer
, Sset_buffer
, 1, 1, 0,
1975 doc
: /* Make buffer BUFFER-OR-NAME current for editing operations.
1976 BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See
1977 also `save-excursion' when you want to make a buffer current
1978 temporarily. This function does not display the buffer, so its effect
1979 ends when the current command terminates. Use `switch-to-buffer' or
1980 `pop-to-buffer' to switch buffers permanently. */)
1981 (register Lisp_Object buffer_or_name
)
1983 register Lisp_Object buffer
;
1984 buffer
= Fget_buffer (buffer_or_name
);
1986 nsberror (buffer_or_name
);
1987 if (NILP (BVAR (XBUFFER (buffer
), name
)))
1988 error ("Selecting deleted buffer");
1989 set_buffer_internal (XBUFFER (buffer
));
1993 /* Set the current buffer to BUFFER provided it is alive. */
1996 set_buffer_if_live (Lisp_Object buffer
)
1998 if (! NILP (BVAR (XBUFFER (buffer
), name
)))
1999 Fset_buffer (buffer
);
2003 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only
,
2004 Sbarf_if_buffer_read_only
, 0, 0, 0,
2005 doc
: /* Signal a `buffer-read-only' error if the current buffer is read-only. */)
2008 if (!NILP (BVAR (current_buffer
, read_only
))
2009 && NILP (Vinhibit_read_only
))
2010 xsignal1 (Qbuffer_read_only
, Fcurrent_buffer ());
2014 DEFUN ("erase-buffer", Ferase_buffer
, Serase_buffer
, 0, 0, "*",
2015 doc
: /* Delete the entire contents of the current buffer.
2016 Any narrowing restriction in effect (see `narrow-to-region') is removed,
2017 so the buffer is truly empty after this. */)
2024 current_buffer
->last_window_start
= 1;
2025 /* Prevent warnings, or suspension of auto saving, that would happen
2026 if future size is less than past size. Use of erase-buffer
2027 implies that the future text is not really related to the past text. */
2028 XSETFASTINT (BVAR (current_buffer
, save_length
), 0);
2033 validate_region (register Lisp_Object
*b
, register Lisp_Object
*e
)
2035 CHECK_NUMBER_COERCE_MARKER (*b
);
2036 CHECK_NUMBER_COERCE_MARKER (*e
);
2038 if (XINT (*b
) > XINT (*e
))
2041 tem
= *b
; *b
= *e
; *e
= tem
;
2044 if (! (BEGV
<= XINT (*b
) && XINT (*e
) <= ZV
))
2045 args_out_of_range (*b
, *e
);
2048 /* Advance BYTE_POS up to a character boundary
2049 and return the adjusted position. */
2052 advance_to_char_boundary (ptrdiff_t byte_pos
)
2056 if (byte_pos
== BEG
)
2057 /* Beginning of buffer is always a character boundary. */
2060 c
= FETCH_BYTE (byte_pos
);
2061 if (! CHAR_HEAD_P (c
))
2063 /* We should advance BYTE_POS only when C is a constituent of a
2064 multibyte sequence. */
2065 ptrdiff_t orig_byte_pos
= byte_pos
;
2070 c
= FETCH_BYTE (byte_pos
);
2072 while (! CHAR_HEAD_P (c
) && byte_pos
> BEG
);
2074 if (byte_pos
< orig_byte_pos
)
2075 byte_pos
= orig_byte_pos
;
2076 /* If C is a constituent of a multibyte sequence, BYTE_POS was
2077 surely advance to the correct character boundary. If C is
2078 not, BYTE_POS was unchanged. */
2084 DEFUN ("buffer-swap-text", Fbuffer_swap_text
, Sbuffer_swap_text
,
2086 doc
: /* Swap the text between current buffer and BUFFER. */)
2087 (Lisp_Object buffer
)
2089 struct buffer
*other_buffer
;
2090 CHECK_BUFFER (buffer
);
2091 other_buffer
= XBUFFER (buffer
);
2093 if (NILP (BVAR (other_buffer
, name
)))
2094 error ("Cannot swap a dead buffer's text");
2096 /* Actually, it probably works just fine.
2097 * if (other_buffer == current_buffer)
2098 * error ("Cannot swap a buffer's text with itself"); */
2100 /* Actually, this may be workable as well, tho probably only if they're
2102 if (other_buffer
->base_buffer
2103 || current_buffer
->base_buffer
)
2104 error ("Cannot swap indirect buffers's text");
2106 { /* This is probably harder to make work. */
2107 struct buffer
*other
;
2108 FOR_EACH_BUFFER (other
)
2109 if (other
->base_buffer
== other_buffer
2110 || other
->base_buffer
== current_buffer
)
2111 error ("One of the buffers to swap has indirect buffers");
2114 #define swapfield(field, type) \
2116 type tmp##field = other_buffer->field; \
2117 other_buffer->field = current_buffer->field; \
2118 current_buffer->field = tmp##field; \
2120 #define swapfield_(field, type) \
2122 type tmp##field = BVAR (other_buffer, field); \
2123 BSET (other_buffer, field, BVAR (current_buffer, field)); \
2124 BSET (current_buffer, field, tmp##field); \
2127 swapfield (own_text
, struct buffer_text
);
2128 eassert (current_buffer
->text
== ¤t_buffer
->own_text
);
2129 eassert (other_buffer
->text
== &other_buffer
->own_text
);
2131 r_alloc_reset_variable ((void **) ¤t_buffer
->own_text
.beg
,
2132 (void **) &other_buffer
->own_text
.beg
);
2133 r_alloc_reset_variable ((void **) &other_buffer
->own_text
.beg
,
2134 (void **) ¤t_buffer
->own_text
.beg
);
2135 #endif /* REL_ALLOC */
2137 swapfield (pt
, ptrdiff_t);
2138 swapfield (pt_byte
, ptrdiff_t);
2139 swapfield (begv
, ptrdiff_t);
2140 swapfield (begv_byte
, ptrdiff_t);
2141 swapfield (zv
, ptrdiff_t);
2142 swapfield (zv_byte
, ptrdiff_t);
2143 eassert (!current_buffer
->base_buffer
);
2144 eassert (!other_buffer
->base_buffer
);
2145 swapfield (indirections
, ptrdiff_t);
2146 current_buffer
->clip_changed
= 1; other_buffer
->clip_changed
= 1;
2147 swapfield (newline_cache
, struct region_cache
*);
2148 swapfield (width_run_cache
, struct region_cache
*);
2149 current_buffer
->prevent_redisplay_optimizations_p
= 1;
2150 other_buffer
->prevent_redisplay_optimizations_p
= 1;
2151 swapfield (overlays_before
, struct Lisp_Overlay
*);
2152 swapfield (overlays_after
, struct Lisp_Overlay
*);
2153 swapfield (overlay_center
, ptrdiff_t);
2154 swapfield_ (undo_list
, Lisp_Object
);
2155 swapfield_ (mark
, Lisp_Object
);
2156 swapfield_ (enable_multibyte_characters
, Lisp_Object
);
2157 swapfield_ (bidi_display_reordering
, Lisp_Object
);
2158 swapfield_ (bidi_paragraph_direction
, Lisp_Object
);
2159 /* FIXME: Not sure what we should do with these *_marker fields.
2160 Hopefully they're just nil anyway. */
2161 swapfield_ (pt_marker
, Lisp_Object
);
2162 swapfield_ (begv_marker
, Lisp_Object
);
2163 swapfield_ (zv_marker
, Lisp_Object
);
2164 BSET (current_buffer
, point_before_scroll
, Qnil
);
2165 BSET (other_buffer
, point_before_scroll
, Qnil
);
2167 current_buffer
->text
->modiff
++; other_buffer
->text
->modiff
++;
2168 current_buffer
->text
->chars_modiff
++; other_buffer
->text
->chars_modiff
++;
2169 current_buffer
->text
->overlay_modiff
++; other_buffer
->text
->overlay_modiff
++;
2170 current_buffer
->text
->beg_unchanged
= current_buffer
->text
->gpt
;
2171 current_buffer
->text
->end_unchanged
= current_buffer
->text
->gpt
;
2172 other_buffer
->text
->beg_unchanged
= other_buffer
->text
->gpt
;
2173 other_buffer
->text
->end_unchanged
= other_buffer
->text
->gpt
;
2175 struct Lisp_Marker
*m
;
2176 for (m
= BUF_MARKERS (current_buffer
); m
; m
= m
->next
)
2177 if (m
->buffer
== other_buffer
)
2178 m
->buffer
= current_buffer
;
2180 /* Since there's no indirect buffer in sight, markers on
2181 BUF_MARKERS(buf) should either be for `buf' or dead. */
2182 eassert (!m
->buffer
);
2183 for (m
= BUF_MARKERS (other_buffer
); m
; m
= m
->next
)
2184 if (m
->buffer
== current_buffer
)
2185 m
->buffer
= other_buffer
;
2187 /* Since there's no indirect buffer in sight, markers on
2188 BUF_MARKERS(buf) should either be for `buf' or dead. */
2189 eassert (!m
->buffer
);
2191 { /* Some of the C code expects that w->buffer == w->pointm->buffer.
2192 So since we just swapped the markers between the two buffers, we need
2193 to undo the effect of this swap for window markers. */
2194 Lisp_Object w
= Fselected_window (), ws
= Qnil
;
2195 Lisp_Object buf1
, buf2
;
2196 XSETBUFFER (buf1
, current_buffer
); XSETBUFFER (buf2
, other_buffer
);
2198 while (NILP (Fmemq (w
, ws
)))
2201 if (MARKERP (XWINDOW (w
)->pointm
)
2202 && (EQ (XWINDOW (w
)->buffer
, buf1
)
2203 || EQ (XWINDOW (w
)->buffer
, buf2
)))
2204 Fset_marker (XWINDOW (w
)->pointm
,
2206 (BUF_BEGV (XBUFFER (XWINDOW (w
)->buffer
))),
2207 XWINDOW (w
)->buffer
);
2208 w
= Fnext_window (w
, Qt
, Qt
);
2212 if (current_buffer
->text
->intervals
)
2213 (eassert (EQ (current_buffer
->text
->intervals
->up
.obj
, buffer
)),
2214 XSETBUFFER (current_buffer
->text
->intervals
->up
.obj
, current_buffer
));
2215 if (other_buffer
->text
->intervals
)
2216 (eassert (EQ (other_buffer
->text
->intervals
->up
.obj
, Fcurrent_buffer ())),
2217 XSETBUFFER (other_buffer
->text
->intervals
->up
.obj
, other_buffer
));
2222 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte
, Sset_buffer_multibyte
,
2224 doc
: /* Set the multibyte flag of the current buffer to FLAG.
2225 If FLAG is t, this makes the buffer a multibyte buffer.
2226 If FLAG is nil, this makes the buffer a single-byte buffer.
2227 In these cases, the buffer contents remain unchanged as a sequence of
2228 bytes but the contents viewed as characters do change.
2229 If FLAG is `to', this makes the buffer a multibyte buffer by changing
2230 all eight-bit bytes to eight-bit characters.
2231 If the multibyte flag was really changed, undo information of the
2232 current buffer is cleared. */)
2235 struct Lisp_Marker
*tail
, *markers
;
2236 struct buffer
*other
;
2238 int narrowed
= (BEG
!= BEGV
|| Z
!= ZV
);
2239 int modified_p
= !NILP (Fbuffer_modified_p (Qnil
));
2240 Lisp_Object old_undo
= BVAR (current_buffer
, undo_list
);
2241 struct gcpro gcpro1
;
2243 if (current_buffer
->base_buffer
)
2244 error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
2246 /* Do nothing if nothing actually changes. */
2247 if (NILP (flag
) == NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
2252 /* Don't record these buffer changes. We will put a special undo entry
2254 BSET (current_buffer
, undo_list
, Qt
);
2256 /* If the cached position is for this buffer, clear it out. */
2257 clear_charpos_cache (current_buffer
);
2260 begv
= BEGV_BYTE
, zv
= ZV_BYTE
;
2262 begv
= BEGV
, zv
= ZV
;
2269 ptrdiff_t pos
, stop
;
2272 /* Do this first, so it can use CHAR_TO_BYTE
2273 to calculate the old correspondences. */
2274 set_intervals_multibyte (0);
2276 BSET (current_buffer
, enable_multibyte_characters
, Qnil
);
2282 TEMP_SET_PT_BOTH (PT_BYTE
, PT_BYTE
);
2285 for (tail
= BUF_MARKERS (current_buffer
); tail
; tail
= tail
->next
)
2286 tail
->charpos
= tail
->bytepos
;
2288 /* Convert multibyte form of 8-bit characters to unibyte. */
2303 if (ASCII_BYTE_P (*p
))
2305 else if (CHAR_BYTE8_HEAD_P (*p
))
2307 c
= STRING_CHAR_AND_LENGTH (p
, bytes
);
2308 /* Delete all bytes for this 8-bit character but the
2309 last one, and change the last one to the character
2312 del_range_2 (pos
, pos
, pos
+ bytes
, pos
+ bytes
, 0);
2324 bytes
= BYTES_BY_CHAR_HEAD (*p
);
2325 p
+= bytes
, pos
+= bytes
;
2329 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2334 ptrdiff_t pos
, stop
;
2335 unsigned char *p
, *pend
;
2337 /* Be sure not to have a multibyte sequence striding over the GAP.
2338 Ex: We change this: "...abc\302 _GAP_ \241def..."
2339 to: "...abc _GAP_ \302\241def..." */
2342 && GPT_BYTE
> 1 && GPT_BYTE
< Z_BYTE
2343 && ! CHAR_HEAD_P (*(GAP_END_ADDR
)))
2345 unsigned char *q
= GPT_ADDR
- 1;
2347 while (! CHAR_HEAD_P (*q
) && q
> BEG_ADDR
) q
--;
2348 if (LEADING_CODE_P (*q
))
2350 ptrdiff_t new_gpt
= GPT_BYTE
- (GPT_ADDR
- q
);
2352 move_gap_both (new_gpt
, new_gpt
);
2356 /* Make the buffer contents valid as multibyte by converting
2357 8-bit characters to multibyte form. */
2375 if (ASCII_BYTE_P (*p
))
2377 else if (EQ (flag
, Qt
)
2378 && ! CHAR_BYTE8_HEAD_P (*p
)
2379 && (bytes
= MULTIBYTE_LENGTH (p
, pend
)) > 0)
2380 p
+= bytes
, pos
+= bytes
;
2383 unsigned char tmp
[MAX_MULTIBYTE_LENGTH
];
2386 c
= BYTE8_TO_CHAR (*p
);
2387 bytes
= CHAR_STRING (c
, tmp
);
2389 TEMP_SET_PT_BOTH (pos
+ 1, pos
+ 1);
2391 insert_1_both ((char *) tmp
+ 1, bytes
, bytes
, 1, 0, 0);
2392 /* Now the gap is after the just inserted data. */
2410 Fnarrow_to_region (make_number (begv
), make_number (zv
));
2412 /* Do this first, so that chars_in_text asks the right question.
2413 set_intervals_multibyte needs it too. */
2414 BSET (current_buffer
, enable_multibyte_characters
, Qt
);
2416 GPT_BYTE
= advance_to_char_boundary (GPT_BYTE
);
2417 GPT
= chars_in_text (BEG_ADDR
, GPT_BYTE
- BEG_BYTE
) + BEG
;
2419 Z
= chars_in_text (GAP_END_ADDR
, Z_BYTE
- GPT_BYTE
) + GPT
;
2421 BEGV_BYTE
= advance_to_char_boundary (BEGV_BYTE
);
2422 if (BEGV_BYTE
> GPT_BYTE
)
2423 BEGV
= chars_in_text (GAP_END_ADDR
, BEGV_BYTE
- GPT_BYTE
) + GPT
;
2425 BEGV
= chars_in_text (BEG_ADDR
, BEGV_BYTE
- BEG_BYTE
) + BEG
;
2427 ZV_BYTE
= advance_to_char_boundary (ZV_BYTE
);
2428 if (ZV_BYTE
> GPT_BYTE
)
2429 ZV
= chars_in_text (GAP_END_ADDR
, ZV_BYTE
- GPT_BYTE
) + GPT
;
2431 ZV
= chars_in_text (BEG_ADDR
, ZV_BYTE
- BEG_BYTE
) + BEG
;
2434 ptrdiff_t byte
= advance_to_char_boundary (PT_BYTE
);
2437 if (byte
> GPT_BYTE
)
2438 position
= chars_in_text (GAP_END_ADDR
, byte
- GPT_BYTE
) + GPT
;
2440 position
= chars_in_text (BEG_ADDR
, byte
- BEG_BYTE
) + BEG
;
2441 TEMP_SET_PT_BOTH (position
, byte
);
2444 tail
= markers
= BUF_MARKERS (current_buffer
);
2446 /* This prevents BYTE_TO_CHAR (that is, buf_bytepos_to_charpos) from
2447 getting confused by the markers that have not yet been updated.
2448 It is also a signal that it should never create a marker. */
2449 BUF_MARKERS (current_buffer
) = NULL
;
2451 for (; tail
; tail
= tail
->next
)
2453 tail
->bytepos
= advance_to_char_boundary (tail
->bytepos
);
2454 tail
->charpos
= BYTE_TO_CHAR (tail
->bytepos
);
2457 /* Make sure no markers were put on the chain
2458 while the chain value was incorrect. */
2459 if (BUF_MARKERS (current_buffer
))
2462 BUF_MARKERS (current_buffer
) = markers
;
2464 /* Do this last, so it can calculate the new correspondences
2465 between chars and bytes. */
2466 set_intervals_multibyte (1);
2469 if (!EQ (old_undo
, Qt
))
2471 /* Represent all the above changes by a special undo entry. */
2472 BSET (current_buffer
, undo_list
,
2473 Fcons (list3 (Qapply
,
2474 intern ("set-buffer-multibyte"),
2475 NILP (flag
) ? Qt
: Qnil
),
2481 /* Changing the multibyteness of a buffer means that all windows
2482 showing that buffer must be updated thoroughly. */
2483 current_buffer
->prevent_redisplay_optimizations_p
= 1;
2484 ++windows_or_buffers_changed
;
2486 /* Copy this buffer's new multibyte status
2487 into all of its indirect buffers. */
2488 FOR_EACH_BUFFER (other
)
2489 if (other
->base_buffer
== current_buffer
&& !NILP (BVAR (other
, name
)))
2491 BVAR (other
, enable_multibyte_characters
)
2492 = BVAR (current_buffer
, enable_multibyte_characters
);
2493 other
->prevent_redisplay_optimizations_p
= 1;
2496 /* Restore the modifiedness of the buffer. */
2497 if (!modified_p
&& !NILP (Fbuffer_modified_p (Qnil
)))
2498 Fset_buffer_modified_p (Qnil
);
2500 /* Update coding systems of this buffer's process (if any). */
2502 Lisp_Object process
;
2504 process
= Fget_buffer_process (Fcurrent_buffer ());
2505 if (PROCESSP (process
))
2506 setup_process_coding_systems (process
);
2512 DEFUN ("kill-all-local-variables", Fkill_all_local_variables
,
2513 Skill_all_local_variables
, 0, 0, 0,
2514 doc
: /* Switch to Fundamental mode by killing current buffer's local variables.
2515 Most local variable bindings are eliminated so that the default values
2516 become effective once more. Also, the syntax table is set from
2517 `standard-syntax-table', the local keymap is set to nil,
2518 and the abbrev table from `fundamental-mode-abbrev-table'.
2519 This function also forces redisplay of the mode line.
2521 Every function to select a new major mode starts by
2522 calling this function.
2524 As a special exception, local variables whose names have
2525 a non-nil `permanent-local' property are not eliminated by this function.
2527 The first thing this function does is run
2528 the normal hook `change-major-mode-hook'. */)
2531 Frun_hooks (1, &Qchange_major_mode_hook
);
2533 /* Make sure none of the bindings in local_var_alist
2534 remain swapped in, in their symbols. */
2536 swap_out_buffer_local_variables (current_buffer
);
2538 /* Actually eliminate all local bindings of this buffer. */
2540 reset_buffer_local_variables (current_buffer
, 0);
2542 /* Force mode-line redisplay. Useful here because all major mode
2543 commands call this function. */
2544 update_mode_lines
++;
2549 /* Make sure no local variables remain set up with buffer B
2550 for their current values. */
2553 swap_out_buffer_local_variables (struct buffer
*b
)
2555 Lisp_Object oalist
, alist
, buffer
;
2557 XSETBUFFER (buffer
, b
);
2558 oalist
= BVAR (b
, local_var_alist
);
2560 for (alist
= oalist
; CONSP (alist
); alist
= XCDR (alist
))
2562 Lisp_Object sym
= XCAR (XCAR (alist
));
2563 eassert (XSYMBOL (sym
)->redirect
== SYMBOL_LOCALIZED
);
2564 /* Need not do anything if some other buffer's binding is
2566 if (EQ (SYMBOL_BLV (XSYMBOL (sym
))->where
, buffer
))
2568 /* Symbol is set up for this buffer's old local value:
2570 swap_in_global_binding (XSYMBOL (sym
));
2575 /* Find all the overlays in the current buffer that contain position POS.
2576 Return the number found, and store them in a vector in *VEC_PTR.
2577 Store in *LEN_PTR the size allocated for the vector.
2578 Store in *NEXT_PTR the next position after POS where an overlay starts,
2579 or ZV if there are no more overlays between POS and ZV.
2580 Store in *PREV_PTR the previous position before POS where an overlay ends,
2581 or where an overlay starts which ends at or after POS;
2582 or BEGV if there are no such overlays from BEGV to POS.
2583 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2585 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2586 when this function is called.
2588 If EXTEND is non-zero, we make the vector bigger if necessary.
2589 If EXTEND is zero, we never extend the vector,
2590 and we store only as many overlays as will fit.
2591 But we still return the total number of overlays.
2593 If CHANGE_REQ is true, then any position written into *PREV_PTR or
2594 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2595 default (BEGV or ZV). */
2598 overlays_at (EMACS_INT pos
, int extend
, Lisp_Object
**vec_ptr
,
2600 ptrdiff_t *next_ptr
, ptrdiff_t *prev_ptr
, int change_req
)
2602 Lisp_Object overlay
, start
, end
;
2603 struct Lisp_Overlay
*tail
;
2605 ptrdiff_t len
= *len_ptr
;
2606 Lisp_Object
*vec
= *vec_ptr
;
2607 ptrdiff_t next
= ZV
;
2608 ptrdiff_t prev
= BEGV
;
2609 int inhibit_storing
= 0;
2611 for (tail
= buffer_get_overlays (NULL
, OV_BEFORE
); tail
; tail
= tail
->next
)
2613 ptrdiff_t startpos
, endpos
;
2615 XSETMISC (overlay
, tail
);
2617 start
= OVERLAY_START (overlay
);
2618 end
= OVERLAY_END (overlay
);
2619 endpos
= OVERLAY_POSITION (end
);
2626 startpos
= OVERLAY_POSITION (start
);
2627 /* This one ends at or after POS
2628 so its start counts for PREV_PTR if it's before POS. */
2629 if (prev
< startpos
&& startpos
< pos
)
2633 if (startpos
<= pos
)
2637 /* The supplied vector is full.
2638 Either make it bigger, or don't store any more in it. */
2641 vec
= xpalloc (vec
, len_ptr
, 1, OVERLAY_COUNT_MAX
,
2647 inhibit_storing
= 1;
2650 if (!inhibit_storing
)
2652 /* Keep counting overlays even if we can't return them all. */
2655 else if (startpos
< next
)
2659 for (tail
= buffer_get_overlays (NULL
, OV_AFTER
); tail
; tail
= tail
->next
)
2661 ptrdiff_t startpos
, endpos
;
2663 XSETMISC (overlay
, tail
);
2665 start
= OVERLAY_START (overlay
);
2666 end
= OVERLAY_END (overlay
);
2667 startpos
= OVERLAY_POSITION (start
);
2670 if (startpos
< next
)
2674 endpos
= OVERLAY_POSITION (end
);
2681 vec
= xpalloc (vec
, len_ptr
, 1, OVERLAY_COUNT_MAX
,
2687 inhibit_storing
= 1;
2690 if (!inhibit_storing
)
2694 if (startpos
< pos
&& startpos
> prev
)
2697 else if (endpos
< pos
&& endpos
> prev
)
2699 else if (endpos
== pos
&& startpos
> prev
2700 && (!change_req
|| startpos
< pos
))
2711 /* Find all the overlays in the current buffer that overlap the range
2712 BEG-END, or are empty at BEG, or are empty at END provided END
2713 denotes the position at the end of the current buffer.
2715 Return the number found, and store them in a vector in *VEC_PTR.
2716 Store in *LEN_PTR the size allocated for the vector.
2717 Store in *NEXT_PTR the next position after POS where an overlay starts,
2718 or ZV if there are no more overlays.
2719 Store in *PREV_PTR the previous position before POS where an overlay ends,
2720 or BEGV if there are no previous overlays.
2721 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
2723 *VEC_PTR and *LEN_PTR should contain a valid vector and size
2724 when this function is called.
2726 If EXTEND is non-zero, we make the vector bigger if necessary.
2727 If EXTEND is zero, we never extend the vector,
2728 and we store only as many overlays as will fit.
2729 But we still return the total number of overlays. */
2732 overlays_in (EMACS_INT beg
, EMACS_INT end
, int extend
,
2733 Lisp_Object
**vec_ptr
, ptrdiff_t *len_ptr
,
2734 ptrdiff_t *next_ptr
, ptrdiff_t *prev_ptr
)
2736 Lisp_Object overlay
, ostart
, oend
;
2737 struct Lisp_Overlay
*tail
;
2739 ptrdiff_t len
= *len_ptr
;
2740 Lisp_Object
*vec
= *vec_ptr
;
2741 ptrdiff_t next
= ZV
;
2742 ptrdiff_t prev
= BEGV
;
2743 int inhibit_storing
= 0;
2744 int end_is_Z
= end
== Z
;
2746 for (tail
= buffer_get_overlays (NULL
, OV_BEFORE
); tail
; tail
= tail
->next
)
2748 ptrdiff_t startpos
, endpos
;
2750 XSETMISC (overlay
, tail
);
2752 ostart
= OVERLAY_START (overlay
);
2753 oend
= OVERLAY_END (overlay
);
2754 endpos
= OVERLAY_POSITION (oend
);
2761 startpos
= OVERLAY_POSITION (ostart
);
2762 /* Count an interval if it overlaps the range, is empty at the
2763 start of the range, or is empty at END provided END denotes the
2764 end of the buffer. */
2765 if ((beg
< endpos
&& startpos
< end
)
2766 || (startpos
== endpos
2767 && (beg
== endpos
|| (end_is_Z
&& endpos
== end
))))
2771 /* The supplied vector is full.
2772 Either make it bigger, or don't store any more in it. */
2775 vec
= xpalloc (vec
, len_ptr
, 1, OVERLAY_COUNT_MAX
,
2781 inhibit_storing
= 1;
2784 if (!inhibit_storing
)
2786 /* Keep counting overlays even if we can't return them all. */
2789 else if (startpos
< next
)
2793 for (tail
= buffer_get_overlays (NULL
, OV_AFTER
); tail
; tail
= tail
->next
)
2795 ptrdiff_t startpos
, endpos
;
2797 XSETMISC (overlay
, tail
);
2799 ostart
= OVERLAY_START (overlay
);
2800 oend
= OVERLAY_END (overlay
);
2801 startpos
= OVERLAY_POSITION (ostart
);
2804 if (startpos
< next
)
2808 endpos
= OVERLAY_POSITION (oend
);
2809 /* Count an interval if it overlaps the range, is empty at the
2810 start of the range, or is empty at END provided END denotes the
2811 end of the buffer. */
2812 if ((beg
< endpos
&& startpos
< end
)
2813 || (startpos
== endpos
2814 && (beg
== endpos
|| (end_is_Z
&& endpos
== end
))))
2820 vec
= xpalloc (vec
, len_ptr
, 1, OVERLAY_COUNT_MAX
,
2826 inhibit_storing
= 1;
2829 if (!inhibit_storing
)
2833 else if (endpos
< beg
&& endpos
> prev
)
2845 /* Return non-zero if there exists an overlay with a non-nil
2846 `mouse-face' property overlapping OVERLAY. */
2849 mouse_face_overlay_overlaps (Lisp_Object overlay
)
2851 ptrdiff_t start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2852 ptrdiff_t end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2853 ptrdiff_t n
, i
, size
;
2854 Lisp_Object
*v
, tem
;
2857 v
= alloca (size
* sizeof *v
);
2858 n
= overlays_in (start
, end
, 0, &v
, &size
, NULL
, NULL
);
2861 v
= alloca (n
* sizeof *v
);
2862 overlays_in (start
, end
, 0, &v
, &n
, NULL
, NULL
);
2865 for (i
= 0; i
< n
; ++i
)
2866 if (!EQ (v
[i
], overlay
)
2867 && (tem
= Foverlay_get (overlay
, Qmouse_face
),
2876 /* Fast function to just test if we're at an overlay boundary. */
2878 overlay_touches_p (ptrdiff_t pos
)
2880 Lisp_Object overlay
;
2881 struct Lisp_Overlay
*tail
;
2883 for (tail
= buffer_get_overlays (NULL
, OV_BEFORE
); tail
; tail
= tail
->next
)
2887 XSETMISC (overlay
,tail
);
2888 eassert (OVERLAYP (overlay
));
2890 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2893 if (endpos
== pos
|| OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
)
2897 for (tail
= buffer_get_overlays (NULL
, OV_AFTER
); tail
; tail
= tail
->next
)
2901 XSETMISC (overlay
, tail
);
2902 eassert (OVERLAYP (overlay
));
2904 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2907 if (startpos
== pos
|| OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
)
2915 Lisp_Object overlay
;
2921 compare_overlays (const void *v1
, const void *v2
)
2923 const struct sortvec
*s1
= (const struct sortvec
*) v1
;
2924 const struct sortvec
*s2
= (const struct sortvec
*) v2
;
2925 if (s1
->priority
!= s2
->priority
)
2926 return s1
->priority
< s2
->priority
? -1 : 1;
2927 if (s1
->beg
!= s2
->beg
)
2928 return s1
->beg
< s2
->beg
? -1 : 1;
2929 if (s1
->end
!= s2
->end
)
2930 return s2
->end
< s1
->end
? -1 : 1;
2931 /* Avoid the non-determinism of qsort by choosing an arbitrary ordering
2932 between "equal" overlays. The result can still change between
2933 invocations of Emacs, but it won't change in the middle of
2934 `find_field' (bug#6830). */
2935 if (XHASH (s1
->overlay
) != XHASH (s2
->overlay
))
2936 return XHASH (s1
->overlay
) < XHASH (s2
->overlay
) ? -1 : 1;
2940 /* Sort an array of overlays by priority. The array is modified in place.
2941 The return value is the new size; this may be smaller than the original
2942 size if some of the overlays were invalid or were window-specific. */
2944 sort_overlays (Lisp_Object
*overlay_vec
, ptrdiff_t noverlays
, struct window
*w
)
2947 struct sortvec
*sortvec
= alloca (noverlays
* sizeof *sortvec
);
2949 /* Put the valid and relevant overlays into sortvec. */
2951 for (i
= 0, j
= 0; i
< noverlays
; i
++)
2954 Lisp_Object overlay
;
2956 overlay
= overlay_vec
[i
];
2957 if (OVERLAYP (overlay
)
2958 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
2959 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
2961 /* If we're interested in a specific window, then ignore
2962 overlays that are limited to some other window. */
2967 window
= Foverlay_get (overlay
, Qwindow
);
2968 if (WINDOWP (window
) && XWINDOW (window
) != w
)
2972 /* This overlay is good and counts: put it into sortvec. */
2973 sortvec
[j
].overlay
= overlay
;
2974 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2975 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2976 tem
= Foverlay_get (overlay
, Qpriority
);
2978 sortvec
[j
].priority
= XINT (tem
);
2980 sortvec
[j
].priority
= 0;
2986 /* Sort the overlays into the proper order: increasing priority. */
2989 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), compare_overlays
);
2991 for (i
= 0; i
< noverlays
; i
++)
2992 overlay_vec
[i
] = sortvec
[i
].overlay
;
2998 Lisp_Object string
, string2
;
3005 struct sortstr
*buf
; /* An array that expands as needed; never freed. */
3006 ptrdiff_t size
; /* Allocated length of that array. */
3007 ptrdiff_t used
; /* How much of the array is currently in use. */
3008 ptrdiff_t bytes
; /* Total length of the strings in buf. */
3011 /* Buffers for storing information about the overlays touching a given
3012 position. These could be automatic variables in overlay_strings, but
3013 it's more efficient to hold onto the memory instead of repeatedly
3014 allocating and freeing it. */
3015 static struct sortstrlist overlay_heads
, overlay_tails
;
3016 static unsigned char *overlay_str_buf
;
3018 /* Allocated length of overlay_str_buf. */
3019 static ptrdiff_t overlay_str_len
;
3021 /* A comparison function suitable for passing to qsort. */
3023 cmp_for_strings (const void *as1
, const void *as2
)
3025 struct sortstr
*s1
= (struct sortstr
*)as1
;
3026 struct sortstr
*s2
= (struct sortstr
*)as2
;
3027 if (s1
->size
!= s2
->size
)
3028 return s2
->size
< s1
->size
? -1 : 1;
3029 if (s1
->priority
!= s2
->priority
)
3030 return s1
->priority
< s2
->priority
? -1 : 1;
3035 record_overlay_string (struct sortstrlist
*ssl
, Lisp_Object str
,
3036 Lisp_Object str2
, Lisp_Object pri
, ptrdiff_t size
)
3040 if (ssl
->used
== ssl
->size
)
3041 ssl
->buf
= xpalloc (ssl
->buf
, &ssl
->size
, 5, -1, sizeof *ssl
->buf
);
3042 ssl
->buf
[ssl
->used
].string
= str
;
3043 ssl
->buf
[ssl
->used
].string2
= str2
;
3044 ssl
->buf
[ssl
->used
].size
= size
;
3045 ssl
->buf
[ssl
->used
].priority
= (INTEGERP (pri
) ? XINT (pri
) : 0);
3048 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
3049 nbytes
= SCHARS (str
);
3050 else if (! STRING_MULTIBYTE (str
))
3051 nbytes
= count_size_as_multibyte (SDATA (str
),
3054 nbytes
= SBYTES (str
);
3056 if (INT_ADD_OVERFLOW (ssl
->bytes
, nbytes
))
3057 memory_full (SIZE_MAX
);
3058 ssl
->bytes
+= nbytes
;
3062 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
3063 nbytes
= SCHARS (str2
);
3064 else if (! STRING_MULTIBYTE (str2
))
3065 nbytes
= count_size_as_multibyte (SDATA (str2
),
3068 nbytes
= SBYTES (str2
);
3070 if (INT_ADD_OVERFLOW (ssl
->bytes
, nbytes
))
3071 memory_full (SIZE_MAX
);
3072 ssl
->bytes
+= nbytes
;
3076 /* Return the concatenation of the strings associated with overlays that
3077 begin or end at POS, ignoring overlays that are specific to a window
3078 other than W. The strings are concatenated in the appropriate order:
3079 shorter overlays nest inside longer ones, and higher priority inside
3080 lower. Normally all of the after-strings come first, but zero-sized
3081 overlays have their after-strings ride along with the before-strings
3082 because it would look strange to print them inside-out.
3084 Returns the string length, and stores the contents indirectly through
3085 PSTR, if that variable is non-null. The string may be overwritten by
3086 subsequent calls. */
3089 overlay_strings (ptrdiff_t pos
, struct window
*w
, unsigned char **pstr
)
3091 Lisp_Object overlay
, window
, str
;
3092 struct Lisp_Overlay
*ov
;
3093 ptrdiff_t startpos
, endpos
;
3094 int multibyte
= ! NILP (BVAR (current_buffer
, enable_multibyte_characters
));
3096 overlay_heads
.used
= overlay_heads
.bytes
= 0;
3097 overlay_tails
.used
= overlay_tails
.bytes
= 0;
3098 for (ov
= buffer_get_overlays (NULL
, OV_BEFORE
); ov
; ov
= ov
->next
)
3100 XSETMISC (overlay
, ov
);
3101 eassert (OVERLAYP (overlay
));
3103 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3104 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3107 if (endpos
!= pos
&& startpos
!= pos
)
3109 window
= Foverlay_get (overlay
, Qwindow
);
3110 if (WINDOWP (window
) && XWINDOW (window
) != w
)
3113 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
3114 record_overlay_string (&overlay_heads
, str
,
3116 ? Foverlay_get (overlay
, Qafter_string
)
3118 Foverlay_get (overlay
, Qpriority
),
3120 else if (endpos
== pos
3121 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
3122 record_overlay_string (&overlay_tails
, str
, Qnil
,
3123 Foverlay_get (overlay
, Qpriority
),
3126 for (ov
= buffer_get_overlays (NULL
, OV_AFTER
); ov
; ov
= ov
->next
)
3128 XSETMISC (overlay
, ov
);
3129 eassert (OVERLAYP (overlay
));
3131 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3132 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3135 if (endpos
!= pos
&& startpos
!= pos
)
3137 window
= Foverlay_get (overlay
, Qwindow
);
3138 if (WINDOWP (window
) && XWINDOW (window
) != w
)
3141 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
)))
3142 record_overlay_string (&overlay_heads
, str
,
3144 ? Foverlay_get (overlay
, Qafter_string
)
3146 Foverlay_get (overlay
, Qpriority
),
3148 else if (endpos
== pos
3149 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
)))
3150 record_overlay_string (&overlay_tails
, str
, Qnil
,
3151 Foverlay_get (overlay
, Qpriority
),
3154 if (overlay_tails
.used
> 1)
3155 qsort (overlay_tails
.buf
, overlay_tails
.used
, sizeof (struct sortstr
),
3157 if (overlay_heads
.used
> 1)
3158 qsort (overlay_heads
.buf
, overlay_heads
.used
, sizeof (struct sortstr
),
3160 if (overlay_heads
.bytes
|| overlay_tails
.bytes
)
3167 if (INT_ADD_OVERFLOW (overlay_heads
.bytes
, overlay_tails
.bytes
))
3168 memory_full (SIZE_MAX
);
3169 total
= overlay_heads
.bytes
+ overlay_tails
.bytes
;
3170 if (total
> overlay_str_len
)
3171 overlay_str_buf
= xpalloc (overlay_str_buf
, &overlay_str_len
,
3172 total
- overlay_str_len
, -1, 1);
3174 p
= overlay_str_buf
;
3175 for (i
= overlay_tails
.used
; --i
>= 0;)
3178 tem
= overlay_tails
.buf
[i
].string
;
3179 nbytes
= copy_text (SDATA (tem
), p
,
3181 STRING_MULTIBYTE (tem
), multibyte
);
3184 for (i
= 0; i
< overlay_heads
.used
; ++i
)
3187 tem
= overlay_heads
.buf
[i
].string
;
3188 nbytes
= copy_text (SDATA (tem
), p
,
3190 STRING_MULTIBYTE (tem
), multibyte
);
3192 tem
= overlay_heads
.buf
[i
].string2
;
3195 nbytes
= copy_text (SDATA (tem
), p
,
3197 STRING_MULTIBYTE (tem
), multibyte
);
3201 if (p
!= overlay_str_buf
+ total
)
3204 *pstr
= overlay_str_buf
;
3210 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3213 recenter_overlay_lists (struct buffer
*buf
, ptrdiff_t pos
)
3215 Lisp_Object overlay
, beg
, end
;
3216 struct Lisp_Overlay
*prev
, *tail
, *next
;
3218 /* See if anything in overlays_before should move to overlays_after. */
3220 /* We don't strictly need prev in this loop; it should always be nil.
3221 But we use it for symmetry and in case that should cease to be true
3222 with some future change. */
3224 for (tail
= buffer_get_overlays (buf
, OV_BEFORE
); tail
; prev
= tail
, tail
= next
)
3227 XSETMISC (overlay
, tail
);
3228 eassert (OVERLAYP (overlay
));
3230 beg
= OVERLAY_START (overlay
);
3231 end
= OVERLAY_END (overlay
);
3233 if (OVERLAY_POSITION (end
) > pos
)
3235 /* OVERLAY needs to be moved. */
3236 ptrdiff_t where
= OVERLAY_POSITION (beg
);
3237 struct Lisp_Overlay
*other
, *other_prev
;
3239 /* Splice the cons cell TAIL out of overlays_before. */
3243 buffer_set_overlays (buf
, next
, OV_BEFORE
);
3245 /* Search thru overlays_after for where to put it. */
3247 for (other
= buffer_get_overlays (buf
, OV_AFTER
); other
;
3248 other_prev
= other
, other
= other
->next
)
3250 Lisp_Object otherbeg
, otheroverlay
;
3252 XSETMISC (otheroverlay
, other
);
3253 eassert (OVERLAYP (otheroverlay
));
3255 otherbeg
= OVERLAY_START (otheroverlay
);
3256 if (OVERLAY_POSITION (otherbeg
) >= where
)
3260 /* Add TAIL to overlays_after before OTHER. */
3263 other_prev
->next
= tail
;
3265 buffer_set_overlays (buf
, tail
, OV_AFTER
);
3269 /* We've reached the things that should stay in overlays_before.
3270 All the rest of overlays_before must end even earlier,
3275 /* See if anything in overlays_after should be in overlays_before. */
3277 for (tail
= buffer_get_overlays (buf
, OV_AFTER
); tail
; prev
= tail
, tail
= next
)
3280 XSETMISC (overlay
, tail
);
3281 eassert (OVERLAYP (overlay
));
3283 beg
= OVERLAY_START (overlay
);
3284 end
= OVERLAY_END (overlay
);
3286 /* Stop looking, when we know that nothing further
3287 can possibly end before POS. */
3288 if (OVERLAY_POSITION (beg
) > pos
)
3291 if (OVERLAY_POSITION (end
) <= pos
)
3293 /* OVERLAY needs to be moved. */
3294 ptrdiff_t where
= OVERLAY_POSITION (end
);
3295 struct Lisp_Overlay
*other
, *other_prev
;
3297 /* Splice the cons cell TAIL out of overlays_after. */
3301 buffer_set_overlays (buf
, next
, OV_AFTER
);
3303 /* Search thru overlays_before for where to put it. */
3305 for (other
= buffer_get_overlays (buf
, OV_BEFORE
); other
;
3306 other_prev
= other
, other
= other
->next
)
3308 Lisp_Object otherend
, otheroverlay
;
3310 XSETMISC (otheroverlay
, other
);
3311 eassert (OVERLAYP (otheroverlay
));
3313 otherend
= OVERLAY_END (otheroverlay
);
3314 if (OVERLAY_POSITION (otherend
) <= where
)
3318 /* Add TAIL to overlays_before before OTHER. */
3321 other_prev
->next
= tail
;
3323 buffer_set_overlays (buf
, tail
, OV_BEFORE
);
3328 buf
->overlay_center
= pos
;
3332 adjust_overlays_for_insert (ptrdiff_t pos
, ptrdiff_t length
)
3334 /* After an insertion, the lists are still sorted properly,
3335 but we may need to update the value of the overlay center. */
3336 if (current_buffer
->overlay_center
>= pos
)
3337 current_buffer
->overlay_center
+= length
;
3341 adjust_overlays_for_delete (ptrdiff_t pos
, ptrdiff_t length
)
3343 if (current_buffer
->overlay_center
< pos
)
3344 /* The deletion was to our right. No change needed; the before- and
3345 after-lists are still consistent. */
3347 else if (current_buffer
->overlay_center
- pos
> length
)
3348 /* The deletion was to our left. We need to adjust the center value
3349 to account for the change in position, but the lists are consistent
3350 given the new value. */
3351 current_buffer
->overlay_center
-= length
;
3353 /* We're right in the middle. There might be things on the after-list
3354 that now belong on the before-list. Recentering will move them,
3355 and also update the center point. */
3356 recenter_overlay_lists (current_buffer
, pos
);
3359 /* Fix up overlays that were garbled as a result of permuting markers
3360 in the range START through END. Any overlay with at least one
3361 endpoint in this range will need to be unlinked from the overlay
3362 list and reinserted in its proper place.
3363 Such an overlay might even have negative size at this point.
3364 If so, we'll make the overlay empty. */
3366 fix_start_end_in_overlays (register ptrdiff_t start
, register ptrdiff_t end
)
3368 Lisp_Object overlay
;
3369 struct Lisp_Overlay
*before_list
IF_LINT (= NULL
);
3370 struct Lisp_Overlay
*after_list
IF_LINT (= NULL
);
3371 /* These are either nil, indicating that before_list or after_list
3372 should be assigned, or the cons cell the cdr of which should be
3374 struct Lisp_Overlay
*beforep
= NULL
, *afterp
= NULL
;
3375 /* 'Parent', likewise, indicates a cons cell or
3376 before or after overlays list, depending
3377 which loop we're in. */
3378 struct Lisp_Overlay
*tail
, *parent
;
3379 ptrdiff_t startpos
, endpos
;
3381 /* This algorithm shifts links around instead of consing and GCing.
3382 The loop invariant is that before_list (resp. after_list) is a
3383 well-formed list except that its last element, the CDR of beforep
3384 (resp. afterp) if beforep (afterp) isn't nil or before_list
3385 (after_list) if it is, is still uninitialized. So it's not a bug
3386 that before_list isn't initialized, although it may look
3388 for (parent
= NULL
, tail
= buffer_get_overlays (NULL
, OV_BEFORE
); tail
;)
3390 XSETMISC (overlay
, tail
);
3392 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3393 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3395 /* If the overlay is backwards, make it empty. */
3396 if (endpos
< startpos
)
3399 Fset_marker (OVERLAY_START (overlay
), make_number (startpos
),
3407 || (startpos
>= start
&& startpos
< end
))
3409 /* Add it to the end of the wrong list. Later on,
3410 recenter_overlay_lists will move it to the right place. */
3411 if (endpos
< current_buffer
->overlay_center
)
3416 afterp
->next
= tail
;
3424 beforep
->next
= tail
;
3428 buffer_set_overlays (NULL
, tail
->next
, OV_BEFORE
);
3430 parent
->next
= tail
->next
;
3434 parent
= tail
, tail
= parent
->next
;
3436 for (parent
= NULL
, tail
= buffer_get_overlays (NULL
, OV_AFTER
); tail
;)
3438 XSETMISC (overlay
, tail
);
3440 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3441 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3443 /* If the overlay is backwards, make it empty. */
3444 if (endpos
< startpos
)
3447 Fset_marker (OVERLAY_START (overlay
), make_number (startpos
),
3451 if (startpos
>= end
)
3454 if (startpos
>= start
3455 || (endpos
>= start
&& endpos
< end
))
3457 if (endpos
< current_buffer
->overlay_center
)
3462 afterp
->next
= tail
;
3470 beforep
->next
= tail
;
3474 buffer_set_overlays (NULL
, tail
->next
, OV_AFTER
);
3476 parent
->next
= tail
->next
;
3480 parent
= tail
, tail
= parent
->next
;
3483 /* Splice the constructed (wrong) lists into the buffer's lists,
3484 and let the recenter function make it sane again. */
3487 beforep
->next
= buffer_get_overlays (NULL
, OV_BEFORE
);
3488 buffer_set_overlays (NULL
, before_list
, OV_BEFORE
);
3490 recenter_overlay_lists (current_buffer
, current_buffer
->overlay_center
);
3494 afterp
->next
= buffer_get_overlays (NULL
, OV_AFTER
);
3495 buffer_set_overlays (NULL
, after_list
, OV_AFTER
);
3497 recenter_overlay_lists (current_buffer
, current_buffer
->overlay_center
);
3500 /* We have two types of overlay: the one whose ending marker is
3501 after-insertion-marker (this is the usual case) and the one whose
3502 ending marker is before-insertion-marker. When `overlays_before'
3503 contains overlays of the latter type and the former type in this
3504 order and both overlays end at inserting position, inserting a text
3505 increases only the ending marker of the latter type, which results
3506 in incorrect ordering of `overlays_before'.
3508 This function fixes ordering of overlays in the slot
3509 `overlays_before' of the buffer *BP. Before the insertion, `point'
3510 was at PREV, and now is at POS. */
3513 fix_overlays_before (struct buffer
*bp
, ptrdiff_t prev
, ptrdiff_t pos
)
3515 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3516 struct Lisp_Overlay
*tail
= buffer_get_overlays (bp
, OV_BEFORE
);
3517 struct Lisp_Overlay
*parent
= NULL
, *right_pair
;
3519 ptrdiff_t end
IF_LINT (= 0);
3521 /* After the insertion, the several overlays may be in incorrect
3522 order. The possibility is that, in the list `overlays_before',
3523 an overlay which ends at POS appears after an overlay which ends
3524 at PREV. Since POS is greater than PREV, we must fix the
3525 ordering of these overlays, by moving overlays ends at POS before
3526 the overlays ends at PREV. */
3528 /* At first, find a place where disordered overlays should be linked
3529 in. It is where an overlay which end before POS exists. (i.e. an
3530 overlay whose ending marker is after-insertion-marker if disorder
3533 && (XSETMISC (tem
, tail
),
3534 (end
= OVERLAY_POSITION (OVERLAY_END (tem
))) >= pos
))
3540 /* If we don't find such an overlay,
3541 or the found one ends before PREV,
3542 or the found one is the last one in the list,
3543 we don't have to fix anything. */
3544 if (!tail
|| end
< prev
|| !tail
->next
)
3547 right_pair
= parent
;
3551 /* Now, end position of overlays in the list TAIL should be before
3552 or equal to PREV. In the loop, an overlay which ends at POS is
3553 moved ahead to the place indicated by the CDR of RIGHT_PAIR. If
3554 we found an overlay which ends before PREV, the remaining
3555 overlays are in correct order. */
3558 XSETMISC (tem
, tail
);
3559 end
= OVERLAY_POSITION (OVERLAY_END (tem
));
3562 { /* This overlay is disordered. */
3563 struct Lisp_Overlay
*found
= tail
;
3565 /* Unlink the found overlay. */
3567 parent
->next
= tail
;
3568 /* Move an overlay at RIGHT_PLACE to the next of the found one,
3569 and link it into the right place. */
3572 found
->next
= buffer_get_overlays (bp
, OV_BEFORE
);
3573 buffer_set_overlays (bp
, found
, OV_BEFORE
);
3577 found
->next
= right_pair
->next
;
3578 right_pair
->next
= found
;
3581 else if (end
== prev
)
3586 else /* No more disordered overlay. */
3591 DEFUN ("overlayp", Foverlayp
, Soverlayp
, 1, 1, 0,
3592 doc
: /* Return t if OBJECT is an overlay. */)
3593 (Lisp_Object object
)
3595 return (OVERLAYP (object
) ? Qt
: Qnil
);
3598 DEFUN ("make-overlay", Fmake_overlay
, Smake_overlay
, 2, 5, 0,
3599 doc
: /* Create a new overlay with range BEG to END in BUFFER.
3600 If omitted, BUFFER defaults to the current buffer.
3601 BEG and END may be integers or markers.
3602 The fourth arg FRONT-ADVANCE, if non-nil, makes the marker
3603 for the front of the overlay advance when text is inserted there
3604 \(which means the text *is not* included in the overlay).
3605 The fifth arg REAR-ADVANCE, if non-nil, makes the marker
3606 for the rear of the overlay advance when text is inserted there
3607 \(which means the text *is* included in the overlay). */)
3608 (Lisp_Object beg
, Lisp_Object end
, Lisp_Object buffer
, Lisp_Object front_advance
, Lisp_Object rear_advance
)
3610 Lisp_Object overlay
;
3614 XSETBUFFER (buffer
, current_buffer
);
3616 CHECK_BUFFER (buffer
);
3618 && ! EQ (Fmarker_buffer (beg
), buffer
))
3619 error ("Marker points into wrong buffer");
3621 && ! EQ (Fmarker_buffer (end
), buffer
))
3622 error ("Marker points into wrong buffer");
3624 CHECK_NUMBER_COERCE_MARKER (beg
);
3625 CHECK_NUMBER_COERCE_MARKER (end
);
3627 if (XINT (beg
) > XINT (end
))
3630 temp
= beg
; beg
= end
; end
= temp
;
3633 b
= XBUFFER (buffer
);
3635 beg
= Fset_marker (Fmake_marker (), beg
, buffer
);
3636 end
= Fset_marker (Fmake_marker (), end
, buffer
);
3638 if (!NILP (front_advance
))
3639 XMARKER (beg
)->insertion_type
= 1;
3640 if (!NILP (rear_advance
))
3641 XMARKER (end
)->insertion_type
= 1;
3643 overlay
= build_overlay (beg
, end
, Qnil
);
3645 /* Put the new overlay on the wrong list. */
3646 end
= OVERLAY_END (overlay
);
3647 if (OVERLAY_POSITION (end
) < b
->overlay_center
)
3649 if (buffer_get_overlays (b
, OV_AFTER
))
3650 XOVERLAY (overlay
)->next
= buffer_get_overlays (b
, OV_AFTER
);
3651 buffer_set_overlays (b
, XOVERLAY (overlay
), OV_AFTER
);
3655 if (buffer_get_overlays (b
, OV_BEFORE
))
3656 XOVERLAY (overlay
)->next
= buffer_get_overlays (b
, OV_BEFORE
);
3657 buffer_set_overlays (b
, XOVERLAY (overlay
), OV_BEFORE
);
3660 /* This puts it in the right list, and in the right order. */
3661 recenter_overlay_lists (b
, b
->overlay_center
);
3663 /* We don't need to redisplay the region covered by the overlay, because
3664 the overlay has no properties at the moment. */
3669 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3672 modify_overlay (struct buffer
*buf
, ptrdiff_t start
, ptrdiff_t end
)
3676 ptrdiff_t temp
= start
;
3681 BUF_COMPUTE_UNCHANGED (buf
, start
, end
);
3683 /* If this is a buffer not in the selected window,
3684 we must do other windows. */
3685 if (buf
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
3686 windows_or_buffers_changed
= 1;
3687 /* If multiple windows show this buffer, we must do other windows. */
3688 else if (buffer_shared
> 1)
3689 windows_or_buffers_changed
= 1;
3690 /* If we modify an overlay at the end of the buffer, we cannot
3691 be sure that window end is still valid. */
3692 else if (end
>= ZV
&& start
<= ZV
)
3693 windows_or_buffers_changed
= 1;
3695 ++BUF_OVERLAY_MODIFF (buf
);
3698 /* Remove OVERLAY from LIST. */
3700 static struct Lisp_Overlay
*
3701 unchain_overlay (struct Lisp_Overlay
*list
, struct Lisp_Overlay
*overlay
)
3703 register struct Lisp_Overlay
*tail
, **prev
= &list
;
3705 for (tail
= list
; tail
; prev
= &tail
->next
, tail
= *prev
)
3706 if (tail
== overlay
)
3708 *prev
= overlay
->next
;
3709 overlay
->next
= NULL
;
3715 /* Remove OVERLAY from both overlay lists of B. */
3718 unchain_both (struct buffer
*b
, Lisp_Object overlay
)
3720 struct Lisp_Overlay
*ov
= XOVERLAY (overlay
);
3723 (b
, unchain_overlay (buffer_get_overlays (b
, OV_BEFORE
), ov
), OV_BEFORE
);
3725 (b
, unchain_overlay (buffer_get_overlays (b
, OV_AFTER
), ov
), OV_AFTER
);
3728 DEFUN ("move-overlay", Fmove_overlay
, Smove_overlay
, 3, 4, 0,
3729 doc
: /* Set the endpoints of OVERLAY to BEG and END in BUFFER.
3730 If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
3731 If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
3733 (Lisp_Object overlay
, Lisp_Object beg
, Lisp_Object end
, Lisp_Object buffer
)
3735 struct buffer
*b
, *ob
= 0;
3736 Lisp_Object obuffer
;
3737 ptrdiff_t count
= SPECPDL_INDEX ();
3738 ptrdiff_t n_beg
, n_end
, o_beg
IF_LINT (= 0), o_end
IF_LINT (= 0);
3740 CHECK_OVERLAY (overlay
);
3742 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3744 XSETBUFFER (buffer
, current_buffer
);
3745 CHECK_BUFFER (buffer
);
3747 if (NILP (Fbuffer_live_p (buffer
)))
3748 error ("Attempt to move overlay to a dead buffer");
3751 && ! EQ (Fmarker_buffer (beg
), buffer
))
3752 error ("Marker points into wrong buffer");
3754 && ! EQ (Fmarker_buffer (end
), buffer
))
3755 error ("Marker points into wrong buffer");
3757 CHECK_NUMBER_COERCE_MARKER (beg
);
3758 CHECK_NUMBER_COERCE_MARKER (end
);
3760 if (XINT (beg
) > XINT (end
))
3763 temp
= beg
; beg
= end
; end
= temp
;
3766 specbind (Qinhibit_quit
, Qt
);
3768 obuffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3769 b
= XBUFFER (buffer
);
3771 if (!NILP (obuffer
))
3773 ob
= XBUFFER (obuffer
);
3775 o_beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3776 o_end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3778 unchain_both (ob
, overlay
);
3779 eassert (XOVERLAY (overlay
)->next
== NULL
);
3782 /* Set the overlay boundaries, which may clip them. */
3783 Fset_marker (OVERLAY_START (overlay
), beg
, buffer
);
3784 Fset_marker (OVERLAY_END (overlay
), end
, buffer
);
3786 n_beg
= marker_position (OVERLAY_START (overlay
));
3787 n_end
= marker_position (OVERLAY_END (overlay
));
3789 /* If the overlay has changed buffers, do a thorough redisplay. */
3790 if (!EQ (buffer
, obuffer
))
3792 /* Redisplay where the overlay was. */
3794 modify_overlay (ob
, o_beg
, o_end
);
3796 /* Redisplay where the overlay is going to be. */
3797 modify_overlay (b
, n_beg
, n_end
);
3800 /* Redisplay the area the overlay has just left, or just enclosed. */
3803 modify_overlay (b
, o_end
, n_end
);
3804 else if (o_end
== n_end
)
3805 modify_overlay (b
, o_beg
, n_beg
);
3807 modify_overlay (b
, min (o_beg
, n_beg
), max (o_end
, n_end
));
3810 /* Delete the overlay if it is empty after clipping and has the
3811 evaporate property. */
3812 if (n_beg
== n_end
&& !NILP (Foverlay_get (overlay
, Qevaporate
)))
3813 return unbind_to (count
, Fdelete_overlay (overlay
));
3815 /* Put the overlay into the new buffer's overlay lists, first on the
3817 if (n_end
< b
->overlay_center
)
3819 XOVERLAY (overlay
)->next
= buffer_get_overlays (b
, OV_AFTER
);
3820 buffer_set_overlays (b
, XOVERLAY (overlay
), OV_AFTER
);
3824 XOVERLAY (overlay
)->next
= buffer_get_overlays (b
, OV_BEFORE
);
3825 buffer_set_overlays (b
, XOVERLAY (overlay
), OV_BEFORE
);
3828 /* This puts it in the right list, and in the right order. */
3829 recenter_overlay_lists (b
, b
->overlay_center
);
3831 return unbind_to (count
, overlay
);
3834 DEFUN ("delete-overlay", Fdelete_overlay
, Sdelete_overlay
, 1, 1, 0,
3835 doc
: /* Delete the overlay OVERLAY from its buffer. */)
3836 (Lisp_Object overlay
)
3840 ptrdiff_t count
= SPECPDL_INDEX ();
3842 CHECK_OVERLAY (overlay
);
3844 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
3848 b
= XBUFFER (buffer
);
3849 specbind (Qinhibit_quit
, Qt
);
3851 unchain_both (b
, overlay
);
3852 eassert (XOVERLAY (overlay
)->next
== NULL
);
3854 drop_overlay (b
, XOVERLAY (overlay
));
3856 /* When deleting an overlay with before or after strings, turn off
3857 display optimizations for the affected buffer, on the basis that
3858 these strings may contain newlines. This is easier to do than to
3859 check for that situation during redisplay. */
3860 if (!windows_or_buffers_changed
3861 && (!NILP (Foverlay_get (overlay
, Qbefore_string
))
3862 || !NILP (Foverlay_get (overlay
, Qafter_string
))))
3863 b
->prevent_redisplay_optimizations_p
= 1;
3865 return unbind_to (count
, Qnil
);
3868 /* Overlay dissection functions. */
3870 DEFUN ("overlay-start", Foverlay_start
, Soverlay_start
, 1, 1, 0,
3871 doc
: /* Return the position at which OVERLAY starts. */)
3872 (Lisp_Object overlay
)
3874 CHECK_OVERLAY (overlay
);
3876 return (Fmarker_position (OVERLAY_START (overlay
)));
3879 DEFUN ("overlay-end", Foverlay_end
, Soverlay_end
, 1, 1, 0,
3880 doc
: /* Return the position at which OVERLAY ends. */)
3881 (Lisp_Object overlay
)
3883 CHECK_OVERLAY (overlay
);
3885 return (Fmarker_position (OVERLAY_END (overlay
)));
3888 DEFUN ("overlay-buffer", Foverlay_buffer
, Soverlay_buffer
, 1, 1, 0,
3889 doc
: /* Return the buffer OVERLAY belongs to.
3890 Return nil if OVERLAY has been deleted. */)
3891 (Lisp_Object overlay
)
3893 CHECK_OVERLAY (overlay
);
3895 return Fmarker_buffer (OVERLAY_START (overlay
));
3898 DEFUN ("overlay-properties", Foverlay_properties
, Soverlay_properties
, 1, 1, 0,
3899 doc
: /* Return a list of the properties on OVERLAY.
3900 This is a copy of OVERLAY's plist; modifying its conses has no effect on
3902 (Lisp_Object overlay
)
3904 CHECK_OVERLAY (overlay
);
3906 return Fcopy_sequence (XOVERLAY (overlay
)->plist
);
3910 DEFUN ("overlays-at", Foverlays_at
, Soverlays_at
, 1, 1, 0,
3911 doc
: /* Return a list of the overlays that contain the character at POS. */)
3914 ptrdiff_t len
, noverlays
;
3915 Lisp_Object
*overlay_vec
;
3918 CHECK_NUMBER_COERCE_MARKER (pos
);
3921 /* We can't use alloca here because overlays_at can call xrealloc. */
3922 overlay_vec
= xmalloc (len
* sizeof *overlay_vec
);
3924 /* Put all the overlays we want in a vector in overlay_vec.
3925 Store the length in len. */
3926 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3929 /* Make a list of them all. */
3930 result
= Flist (noverlays
, overlay_vec
);
3932 xfree (overlay_vec
);
3936 DEFUN ("overlays-in", Foverlays_in
, Soverlays_in
, 2, 2, 0,
3937 doc
: /* Return a list of the overlays that overlap the region BEG ... END.
3938 Overlap means that at least one character is contained within the overlay
3939 and also contained within the specified region.
3940 Empty overlays are included in the result if they are located at BEG,
3941 between BEG and END, or at END provided END denotes the position at the
3942 end of the buffer. */)
3943 (Lisp_Object beg
, Lisp_Object end
)
3945 ptrdiff_t len
, noverlays
;
3946 Lisp_Object
*overlay_vec
;
3949 CHECK_NUMBER_COERCE_MARKER (beg
);
3950 CHECK_NUMBER_COERCE_MARKER (end
);
3953 overlay_vec
= xmalloc (len
* sizeof *overlay_vec
);
3955 /* Put all the overlays we want in a vector in overlay_vec.
3956 Store the length in len. */
3957 noverlays
= overlays_in (XINT (beg
), XINT (end
), 1, &overlay_vec
, &len
,
3960 /* Make a list of them all. */
3961 result
= Flist (noverlays
, overlay_vec
);
3963 xfree (overlay_vec
);
3967 DEFUN ("next-overlay-change", Fnext_overlay_change
, Snext_overlay_change
,
3969 doc
: /* Return the next position after POS where an overlay starts or ends.
3970 If there are no overlay boundaries from POS to (point-max),
3971 the value is (point-max). */)
3974 ptrdiff_t i
, len
, noverlays
;
3976 Lisp_Object
*overlay_vec
;
3978 CHECK_NUMBER_COERCE_MARKER (pos
);
3981 overlay_vec
= xmalloc (len
* sizeof *overlay_vec
);
3983 /* Put all the overlays we want in a vector in overlay_vec.
3984 Store the length in len.
3985 endpos gets the position where the next overlay starts. */
3986 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
3989 /* If any of these overlays ends before endpos,
3990 use its ending point instead. */
3991 for (i
= 0; i
< noverlays
; i
++)
3996 oend
= OVERLAY_END (overlay_vec
[i
]);
3997 oendpos
= OVERLAY_POSITION (oend
);
3998 if (oendpos
< endpos
)
4002 xfree (overlay_vec
);
4003 return make_number (endpos
);
4006 DEFUN ("previous-overlay-change", Fprevious_overlay_change
,
4007 Sprevious_overlay_change
, 1, 1, 0,
4008 doc
: /* Return the previous position before POS where an overlay starts or ends.
4009 If there are no overlay boundaries from (point-min) to POS,
4010 the value is (point-min). */)
4014 Lisp_Object
*overlay_vec
;
4017 CHECK_NUMBER_COERCE_MARKER (pos
);
4019 /* At beginning of buffer, we know the answer;
4020 avoid bug subtracting 1 below. */
4021 if (XINT (pos
) == BEGV
)
4025 overlay_vec
= xmalloc (len
* sizeof *overlay_vec
);
4027 /* Put all the overlays we want in a vector in overlay_vec.
4028 Store the length in len.
4029 prevpos gets the position of the previous change. */
4030 overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
4033 xfree (overlay_vec
);
4034 return make_number (prevpos
);
4037 /* These functions are for debugging overlays. */
4039 DEFUN ("overlay-lists", Foverlay_lists
, Soverlay_lists
, 0, 0, 0,
4040 doc
: /* Return a pair of lists giving all the overlays of the current buffer.
4041 The car has all the overlays before the overlay center;
4042 the cdr has all the overlays after the overlay center.
4043 Recentering overlays moves overlays between these lists.
4044 The lists you get are copies, so that changing them has no effect.
4045 However, the overlays you get are the real objects that the buffer uses. */)
4048 struct Lisp_Overlay
*ol
;
4049 Lisp_Object before
= Qnil
, after
= Qnil
, tmp
;
4051 for (ol
= buffer_get_overlays (NULL
, OV_BEFORE
); ol
; ol
= ol
->next
)
4054 before
= Fcons (tmp
, before
);
4057 for (ol
= buffer_get_overlays (NULL
, OV_AFTER
); ol
; ol
= ol
->next
)
4060 after
= Fcons (tmp
, after
);
4063 return Fcons (Fnreverse (before
), Fnreverse (after
));
4066 DEFUN ("overlay-recenter", Foverlay_recenter
, Soverlay_recenter
, 1, 1, 0,
4067 doc
: /* Recenter the overlays of the current buffer around position POS.
4068 That makes overlay lookup faster for positions near POS (but perhaps slower
4069 for positions far away from POS). */)
4073 CHECK_NUMBER_COERCE_MARKER (pos
);
4075 p
= clip_to_bounds (PTRDIFF_MIN
, XINT (pos
), PTRDIFF_MAX
);
4076 recenter_overlay_lists (current_buffer
, p
);
4080 DEFUN ("overlay-get", Foverlay_get
, Soverlay_get
, 2, 2, 0,
4081 doc
: /* Get the property of overlay OVERLAY with property name PROP. */)
4082 (Lisp_Object overlay
, Lisp_Object prop
)
4084 CHECK_OVERLAY (overlay
);
4085 return lookup_char_property (XOVERLAY (overlay
)->plist
, prop
, 0);
4088 DEFUN ("overlay-put", Foverlay_put
, Soverlay_put
, 3, 3, 0,
4089 doc
: /* Set one property of overlay OVERLAY: give property PROP value VALUE.
4090 VALUE will be returned.*/)
4091 (Lisp_Object overlay
, Lisp_Object prop
, Lisp_Object value
)
4093 Lisp_Object tail
, buffer
;
4096 CHECK_OVERLAY (overlay
);
4098 buffer
= Fmarker_buffer (OVERLAY_START (overlay
));
4100 for (tail
= XOVERLAY (overlay
)->plist
;
4101 CONSP (tail
) && CONSP (XCDR (tail
));
4102 tail
= XCDR (XCDR (tail
)))
4103 if (EQ (XCAR (tail
), prop
))
4105 changed
= !EQ (XCAR (XCDR (tail
)), value
);
4106 XSETCAR (XCDR (tail
), value
);
4109 /* It wasn't in the list, so add it to the front. */
4110 changed
= !NILP (value
);
4112 (overlay
, Fcons (prop
, Fcons (value
, XOVERLAY (overlay
)->plist
)));
4114 if (! NILP (buffer
))
4117 modify_overlay (XBUFFER (buffer
),
4118 marker_position (OVERLAY_START (overlay
)),
4119 marker_position (OVERLAY_END (overlay
)));
4120 if (EQ (prop
, Qevaporate
) && ! NILP (value
)
4121 && (OVERLAY_POSITION (OVERLAY_START (overlay
))
4122 == OVERLAY_POSITION (OVERLAY_END (overlay
))))
4123 Fdelete_overlay (overlay
);
4129 /* Subroutine of report_overlay_modification. */
4131 /* Lisp vector holding overlay hook functions to call.
4132 Vector elements come in pairs.
4133 Each even-index element is a list of hook functions.
4134 The following odd-index element is the overlay they came from.
4136 Before the buffer change, we fill in this vector
4137 as we call overlay hook functions.
4138 After the buffer change, we get the functions to call from this vector.
4139 This way we always call the same functions before and after the change. */
4140 static Lisp_Object last_overlay_modification_hooks
;
4142 /* Number of elements actually used in last_overlay_modification_hooks. */
4143 static ptrdiff_t last_overlay_modification_hooks_used
;
4145 /* Add one functionlist/overlay pair
4146 to the end of last_overlay_modification_hooks. */
4149 add_overlay_mod_hooklist (Lisp_Object functionlist
, Lisp_Object overlay
)
4151 ptrdiff_t oldsize
= ASIZE (last_overlay_modification_hooks
);
4153 if (oldsize
- 1 <= last_overlay_modification_hooks_used
)
4154 last_overlay_modification_hooks
=
4155 larger_vector (last_overlay_modification_hooks
, 2, -1);
4156 ASET (last_overlay_modification_hooks
, last_overlay_modification_hooks_used
,
4157 functionlist
); last_overlay_modification_hooks_used
++;
4158 ASET (last_overlay_modification_hooks
, last_overlay_modification_hooks_used
,
4159 overlay
); last_overlay_modification_hooks_used
++;
4162 /* Run the modification-hooks of overlays that include
4163 any part of the text in START to END.
4164 If this change is an insertion, also
4165 run the insert-before-hooks of overlay starting at END,
4166 and the insert-after-hooks of overlay ending at START.
4168 This is called both before and after the modification.
4169 AFTER is nonzero when we call after the modification.
4171 ARG1, ARG2, ARG3 are arguments to pass to the hook functions.
4172 When AFTER is nonzero, they are the start position,
4173 the position after the inserted new text,
4174 and the length of deleted or replaced old text. */
4177 report_overlay_modification (Lisp_Object start
, Lisp_Object end
, int after
,
4178 Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
4180 Lisp_Object prop
, overlay
;
4181 struct Lisp_Overlay
*tail
;
4182 /* 1 if this change is an insertion. */
4183 int insertion
= (after
? XFASTINT (arg3
) == 0 : EQ (start
, end
));
4184 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4189 /* We used to run the functions as soon as we found them and only register
4190 them in last_overlay_modification_hooks for the purpose of the `after'
4191 case. But running elisp code as we traverse the list of overlays is
4192 painful because the list can be modified by the elisp code so we had to
4193 copy at several places. We now simply do a read-only traversal that
4194 only collects the functions to run and we run them afterwards. It's
4195 simpler, especially since all the code was already there. -stef */
4199 /* We are being called before a change.
4200 Scan the overlays to find the functions to call. */
4201 last_overlay_modification_hooks_used
= 0;
4202 for (tail
= buffer_get_overlays (NULL
, OV_BEFORE
); tail
; tail
= tail
->next
)
4204 ptrdiff_t startpos
, endpos
;
4205 Lisp_Object ostart
, oend
;
4207 XSETMISC (overlay
, tail
);
4209 ostart
= OVERLAY_START (overlay
);
4210 oend
= OVERLAY_END (overlay
);
4211 endpos
= OVERLAY_POSITION (oend
);
4212 if (XFASTINT (start
) > endpos
)
4214 startpos
= OVERLAY_POSITION (ostart
);
4215 if (insertion
&& (XFASTINT (start
) == startpos
4216 || XFASTINT (end
) == startpos
))
4218 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
4220 add_overlay_mod_hooklist (prop
, overlay
);
4222 if (insertion
&& (XFASTINT (start
) == endpos
4223 || XFASTINT (end
) == endpos
))
4225 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
4227 add_overlay_mod_hooklist (prop
, overlay
);
4229 /* Test for intersecting intervals. This does the right thing
4230 for both insertion and deletion. */
4231 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
4233 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
4235 add_overlay_mod_hooklist (prop
, overlay
);
4239 for (tail
= buffer_get_overlays (NULL
, OV_AFTER
); tail
; tail
= tail
->next
)
4241 ptrdiff_t startpos
, endpos
;
4242 Lisp_Object ostart
, oend
;
4244 XSETMISC (overlay
, tail
);
4246 ostart
= OVERLAY_START (overlay
);
4247 oend
= OVERLAY_END (overlay
);
4248 startpos
= OVERLAY_POSITION (ostart
);
4249 endpos
= OVERLAY_POSITION (oend
);
4250 if (XFASTINT (end
) < startpos
)
4252 if (insertion
&& (XFASTINT (start
) == startpos
4253 || XFASTINT (end
) == startpos
))
4255 prop
= Foverlay_get (overlay
, Qinsert_in_front_hooks
);
4257 add_overlay_mod_hooklist (prop
, overlay
);
4259 if (insertion
&& (XFASTINT (start
) == endpos
4260 || XFASTINT (end
) == endpos
))
4262 prop
= Foverlay_get (overlay
, Qinsert_behind_hooks
);
4264 add_overlay_mod_hooklist (prop
, overlay
);
4266 /* Test for intersecting intervals. This does the right thing
4267 for both insertion and deletion. */
4268 if (XFASTINT (end
) > startpos
&& XFASTINT (start
) < endpos
)
4270 prop
= Foverlay_get (overlay
, Qmodification_hooks
);
4272 add_overlay_mod_hooklist (prop
, overlay
);
4277 GCPRO4 (overlay
, arg1
, arg2
, arg3
);
4279 /* Call the functions recorded in last_overlay_modification_hooks.
4280 First copy the vector contents, in case some of these hooks
4281 do subsequent modification of the buffer. */
4282 ptrdiff_t size
= last_overlay_modification_hooks_used
;
4283 Lisp_Object
*copy
= alloca (size
* sizeof *copy
);
4286 memcpy (copy
, XVECTOR (last_overlay_modification_hooks
)->contents
,
4289 gcpro1
.nvars
= size
;
4291 for (i
= 0; i
< size
;)
4293 Lisp_Object prop_i
, overlay_i
;
4295 overlay_i
= copy
[i
++];
4296 call_overlay_mod_hooks (prop_i
, overlay_i
, after
, arg1
, arg2
, arg3
);
4303 call_overlay_mod_hooks (Lisp_Object list
, Lisp_Object overlay
, int after
,
4304 Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
4306 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4308 GCPRO4 (list
, arg1
, arg2
, arg3
);
4310 while (CONSP (list
))
4313 call4 (XCAR (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
);
4315 call5 (XCAR (list
), overlay
, after
? Qt
: Qnil
, arg1
, arg2
, arg3
);
4321 /* Delete any zero-sized overlays at position POS, if the `evaporate'
4324 evaporate_overlays (ptrdiff_t pos
)
4326 Lisp_Object overlay
, hit_list
;
4327 struct Lisp_Overlay
*tail
;
4330 if (pos
<= current_buffer
->overlay_center
)
4331 for (tail
= buffer_get_overlays (NULL
, OV_BEFORE
); tail
; tail
= tail
->next
)
4334 XSETMISC (overlay
, tail
);
4335 endpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4338 if (endpos
== pos
&& OVERLAY_POSITION (OVERLAY_START (overlay
)) == pos
4339 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4340 hit_list
= Fcons (overlay
, hit_list
);
4343 for (tail
= buffer_get_overlays (NULL
, OV_AFTER
); tail
; tail
= tail
->next
)
4346 XSETMISC (overlay
, tail
);
4347 startpos
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4350 if (startpos
== pos
&& OVERLAY_POSITION (OVERLAY_END (overlay
)) == pos
4351 && ! NILP (Foverlay_get (overlay
, Qevaporate
)))
4352 hit_list
= Fcons (overlay
, hit_list
);
4354 for (; CONSP (hit_list
); hit_list
= XCDR (hit_list
))
4355 Fdelete_overlay (XCAR (hit_list
));
4358 /* Somebody has tried to store a value with an unacceptable type
4359 in the slot with offset OFFSET. */
4362 buffer_slot_type_mismatch (Lisp_Object newval
, int type
)
4364 Lisp_Object predicate
;
4368 case_Lisp_Int
: predicate
= Qintegerp
; break;
4369 case Lisp_String
: predicate
= Qstringp
; break;
4370 case Lisp_Symbol
: predicate
= Qsymbolp
; break;
4374 wrong_type_argument (predicate
, newval
);
4378 /***********************************************************************
4379 Allocation with mmap
4380 ***********************************************************************/
4382 #ifdef USE_MMAP_FOR_BUFFERS
4384 #include <sys/types.h>
4385 #include <sys/mman.h>
4388 #ifdef MAP_ANONYMOUS
4389 #define MAP_ANON MAP_ANONYMOUS
4396 #define MAP_FAILED ((void *) -1)
4408 /* Memory is allocated in regions which are mapped using mmap(2).
4409 The current implementation lets the system select mapped
4410 addresses; we're not using MAP_FIXED in general, except when
4411 trying to enlarge regions.
4413 Each mapped region starts with a mmap_region structure, the user
4414 area starts after that structure, aligned to MEM_ALIGN.
4416 +-----------------------+
4417 | struct mmap_info + |
4419 +-----------------------+
4423 +-----------------------+ */
4427 /* User-specified size. */
4428 size_t nbytes_specified
;
4430 /* Number of bytes mapped */
4431 size_t nbytes_mapped
;
4433 /* Pointer to the location holding the address of the memory
4434 allocated with the mmap'd block. The variable actually points
4435 after this structure. */
4438 /* Next and previous in list of all mmap'd regions. */
4439 struct mmap_region
*next
, *prev
;
4442 /* Doubly-linked list of mmap'd regions. */
4444 static struct mmap_region
*mmap_regions
;
4446 /* File descriptor for mmap. If we don't have anonymous mapping,
4447 /dev/zero will be opened on it. */
4451 /* Temporary storage for mmap_set_vars, see there. */
4453 static struct mmap_region
*mmap_regions_1
;
4454 static int mmap_fd_1
;
4456 /* Page size on this system. */
4458 static int mmap_page_size
;
4460 /* 1 means mmap has been initialized. */
4462 static int mmap_initialized_p
;
4464 /* Value is X rounded up to the next multiple of N. */
4466 #define ROUND(X, N) (((X) + (N) - 1) / (N) * (N))
4468 /* Size of mmap_region structure plus padding. */
4470 #define MMAP_REGION_STRUCT_SIZE \
4471 ROUND (sizeof (struct mmap_region), MEM_ALIGN)
4473 /* Given a pointer P to the start of the user-visible part of a mapped
4474 region, return a pointer to the start of the region. */
4476 #define MMAP_REGION(P) \
4477 ((struct mmap_region *) ((char *) (P) - MMAP_REGION_STRUCT_SIZE))
4479 /* Given a pointer P to the start of a mapped region, return a pointer
4480 to the start of the user-visible part of the region. */
4482 #define MMAP_USER_AREA(P) \
4483 ((void *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE))
4485 #define MEM_ALIGN sizeof (double)
4487 /* Predicate returning true if part of the address range [START .. END]
4488 is currently mapped. Used to prevent overwriting an existing
4491 Default is to conservatively assume the address range is occupied by
4492 something else. This can be overridden by system configuration
4493 files if system-specific means to determine this exists. */
4495 #ifndef MMAP_ALLOCATED_P
4496 #define MMAP_ALLOCATED_P(start, end) 1
4499 /* Perform necessary initializations for the use of mmap. */
4505 /* The value of mmap_fd is initially 0 in temacs, and -1
4506 in a dumped Emacs. */
4509 /* No anonymous mmap -- we need the file descriptor. */
4510 mmap_fd
= open ("/dev/zero", O_RDONLY
);
4512 fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno
));
4514 #endif /* MAP_ANON == 0 */
4516 if (mmap_initialized_p
)
4518 mmap_initialized_p
= 1;
4524 mmap_page_size
= getpagesize ();
4527 /* Return a region overlapping address range START...END, or null if
4528 none. END is not including, i.e. the last byte in the range
4531 static struct mmap_region
*
4532 mmap_find (void *start
, void *end
)
4534 struct mmap_region
*r
;
4535 char *s
= (char *) start
, *e
= (char *) end
;
4537 for (r
= mmap_regions
; r
; r
= r
->next
)
4539 char *rstart
= (char *) r
;
4540 char *rend
= rstart
+ r
->nbytes_mapped
;
4542 if (/* First byte of range, i.e. START, in this region? */
4543 (s
>= rstart
&& s
< rend
)
4544 /* Last byte of range, i.e. END - 1, in this region? */
4545 || (e
> rstart
&& e
<= rend
)
4546 /* First byte of this region in the range? */
4547 || (rstart
>= s
&& rstart
< e
)
4548 /* Last byte of this region in the range? */
4549 || (rend
> s
&& rend
<= e
))
4557 /* Unmap a region. P is a pointer to the start of the user-araa of
4558 the region. Value is non-zero if successful. */
4561 mmap_free_1 (struct mmap_region
*r
)
4564 r
->next
->prev
= r
->prev
;
4566 r
->prev
->next
= r
->next
;
4568 mmap_regions
= r
->next
;
4570 if (munmap (r
, r
->nbytes_mapped
) == -1)
4572 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4580 /* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R.
4581 Value is non-zero if successful. */
4584 mmap_enlarge (struct mmap_region
*r
, int npages
)
4586 char *region_end
= (char *) r
+ r
->nbytes_mapped
;
4592 /* Unmap pages at the end of the region. */
4593 nbytes
= - npages
* mmap_page_size
;
4594 if (munmap (region_end
- nbytes
, nbytes
) == -1)
4595 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4598 r
->nbytes_mapped
-= nbytes
;
4602 else if (npages
> 0)
4604 nbytes
= npages
* mmap_page_size
;
4606 /* Try to map additional pages at the end of the region. We
4607 cannot do this if the address range is already occupied by
4608 something else because mmap deletes any previous mapping.
4609 I'm not sure this is worth doing, let's see. */
4610 if (!MMAP_ALLOCATED_P (region_end
, region_end
+ nbytes
))
4614 p
= mmap (region_end
, nbytes
, PROT_READ
| PROT_WRITE
,
4615 MAP_ANON
| MAP_PRIVATE
| MAP_FIXED
, mmap_fd
, 0);
4616 if (p
== MAP_FAILED
)
4617 ; /* fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); */
4618 else if (p
!= region_end
)
4620 /* Kernels are free to choose a different address. In
4621 that case, unmap what we've mapped above; we have
4623 if (munmap (p
, nbytes
) == -1)
4624 fprintf (stderr
, "munmap: %s\n", emacs_strerror (errno
));
4628 r
->nbytes_mapped
+= nbytes
;
4638 /* Set or reset variables holding references to mapped regions. If
4639 RESTORE_P is zero, set all variables to null. If RESTORE_P is
4640 non-zero, set all variables to the start of the user-areas
4643 This function is called from Fdump_emacs to ensure that the dumped
4644 Emacs doesn't contain references to memory that won't be mapped
4645 when Emacs starts. */
4648 mmap_set_vars (int restore_p
)
4650 struct mmap_region
*r
;
4654 mmap_regions
= mmap_regions_1
;
4655 mmap_fd
= mmap_fd_1
;
4656 for (r
= mmap_regions
; r
; r
= r
->next
)
4657 *r
->var
= MMAP_USER_AREA (r
);
4661 for (r
= mmap_regions
; r
; r
= r
->next
)
4663 mmap_regions_1
= mmap_regions
;
4664 mmap_regions
= NULL
;
4665 mmap_fd_1
= mmap_fd
;
4671 /* Allocate a block of storage large enough to hold NBYTES bytes of
4672 data. A pointer to the data is returned in *VAR. VAR is thus the
4673 address of some variable which will use the data area.
4675 The allocation of 0 bytes is valid.
4677 If we can't allocate the necessary memory, set *VAR to null, and
4681 mmap_alloc (void **var
, size_t nbytes
)
4688 map
= ROUND (nbytes
+ MMAP_REGION_STRUCT_SIZE
, mmap_page_size
);
4689 p
= mmap (NULL
, map
, PROT_READ
| PROT_WRITE
, MAP_ANON
| MAP_PRIVATE
,
4692 if (p
== MAP_FAILED
)
4694 if (errno
!= ENOMEM
)
4695 fprintf (stderr
, "mmap: %s\n", emacs_strerror (errno
));
4700 struct mmap_region
*r
= (struct mmap_region
*) p
;
4702 r
->nbytes_specified
= nbytes
;
4703 r
->nbytes_mapped
= map
;
4706 r
->next
= mmap_regions
;
4711 p
= MMAP_USER_AREA (p
);
4718 /* Free a block of relocatable storage whose data is pointed to by
4719 PTR. Store 0 in *PTR to show there's no block allocated. */
4722 mmap_free (void **var
)
4728 mmap_free_1 (MMAP_REGION (*var
));
4734 /* Given a pointer at address VAR to data allocated with mmap_alloc,
4735 resize it to size NBYTES. Change *VAR to reflect the new block,
4736 and return this value. If more memory cannot be allocated, then
4737 leave *VAR unchanged, and return null. */
4740 mmap_realloc (void **var
, size_t nbytes
)
4747 result
= mmap_alloc (var
, nbytes
);
4748 else if (nbytes
== 0)
4751 result
= mmap_alloc (var
, nbytes
);
4755 struct mmap_region
*r
= MMAP_REGION (*var
);
4756 size_t room
= r
->nbytes_mapped
- MMAP_REGION_STRUCT_SIZE
;
4761 void *old_ptr
= *var
;
4763 /* Try to map additional pages at the end of the region.
4764 If that fails, allocate a new region, copy data
4765 from the old region, then free it. */
4766 if (mmap_enlarge (r
, (ROUND (nbytes
- room
, mmap_page_size
)
4769 r
->nbytes_specified
= nbytes
;
4770 *var
= result
= old_ptr
;
4772 else if (mmap_alloc (var
, nbytes
))
4774 memcpy (*var
, old_ptr
, r
->nbytes_specified
);
4775 mmap_free_1 (MMAP_REGION (old_ptr
));
4777 r
= MMAP_REGION (result
);
4778 r
->nbytes_specified
= nbytes
;
4786 else if (room
- nbytes
>= mmap_page_size
)
4788 /* Shrinking by at least a page. Let's give some
4789 memory back to the system.
4791 The extra parens are to make the division happens first,
4792 on positive values, so we know it will round towards
4794 mmap_enlarge (r
, - ((room
- nbytes
) / mmap_page_size
));
4796 r
->nbytes_specified
= nbytes
;
4800 /* Leave it alone. */
4802 r
->nbytes_specified
= nbytes
;
4810 #endif /* USE_MMAP_FOR_BUFFERS */
4814 /***********************************************************************
4815 Buffer-text Allocation
4816 ***********************************************************************/
4818 /* Allocate NBYTES bytes for buffer B's text buffer. */
4821 alloc_buffer_text (struct buffer
*b
, ptrdiff_t nbytes
)
4826 #if defined USE_MMAP_FOR_BUFFERS
4827 p
= mmap_alloc ((void **) &b
->text
->beg
, nbytes
);
4828 #elif defined REL_ALLOC
4829 p
= r_alloc ((void **) &b
->text
->beg
, nbytes
);
4831 p
= xmalloc (nbytes
);
4837 memory_full (nbytes
);
4840 b
->text
->beg
= (unsigned char *) p
;
4844 /* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means
4848 enlarge_buffer_text (struct buffer
*b
, ptrdiff_t delta
)
4851 ptrdiff_t nbytes
= (BUF_Z_BYTE (b
) - BUF_BEG_BYTE (b
) + BUF_GAP_SIZE (b
) + 1
4854 #if defined USE_MMAP_FOR_BUFFERS
4855 p
= mmap_realloc ((void **) &b
->text
->beg
, nbytes
);
4856 #elif defined REL_ALLOC
4857 p
= r_re_alloc ((void **) &b
->text
->beg
, nbytes
);
4859 p
= xrealloc (b
->text
->beg
, nbytes
);
4865 memory_full (nbytes
);
4868 BUF_BEG_ADDR (b
) = (unsigned char *) p
;
4873 /* Free buffer B's text buffer. */
4876 free_buffer_text (struct buffer
*b
)
4880 #if defined USE_MMAP_FOR_BUFFERS
4881 mmap_free ((void **) &b
->text
->beg
);
4882 #elif defined REL_ALLOC
4883 r_alloc_free ((void **) &b
->text
->beg
);
4885 xfree (b
->text
->beg
);
4888 BUF_BEG_ADDR (b
) = NULL
;
4894 /***********************************************************************
4896 ***********************************************************************/
4899 init_buffer_once (void)
4902 /* If you add, remove, or reorder Lisp_Objects in a struct buffer, make
4903 sure that this is still correct. Otherwise, mark_vectorlike may not
4904 trace all Lisp_Objects in buffer_defaults and buffer_local_symbols. */
4906 = (offsetof (struct buffer
, own_text
) - header_size
) / word_size
;
4908 memset (buffer_permanent_local_flags
, 0, sizeof buffer_permanent_local_flags
);
4910 /* Make sure all markable slots in buffer_defaults
4911 are initialized reasonably, so mark_buffer won't choke. */
4912 reset_buffer (&buffer_defaults
);
4913 eassert (EQ (BVAR (&buffer_defaults
, name
), make_number (0)));
4914 reset_buffer_local_variables (&buffer_defaults
, 1);
4915 eassert (EQ (BVAR (&buffer_local_symbols
, name
), make_number (0)));
4916 reset_buffer (&buffer_local_symbols
);
4917 reset_buffer_local_variables (&buffer_local_symbols
, 1);
4918 /* Prevent GC from getting confused. */
4919 buffer_defaults
.text
= &buffer_defaults
.own_text
;
4920 buffer_local_symbols
.text
= &buffer_local_symbols
.own_text
;
4921 /* No one will share the text with these buffers, but let's play it safe. */
4922 buffer_defaults
.indirections
= 0;
4923 buffer_local_symbols
.indirections
= 0;
4924 buffer_set_intervals (&buffer_defaults
, NULL
);
4925 buffer_set_intervals (&buffer_local_symbols
, NULL
);
4926 XSETPVECTYPESIZE (&buffer_defaults
, PVEC_BUFFER
, pvecsize
);
4927 XSETBUFFER (Vbuffer_defaults
, &buffer_defaults
);
4928 XSETPVECTYPESIZE (&buffer_local_symbols
, PVEC_BUFFER
, pvecsize
);
4929 XSETBUFFER (Vbuffer_local_symbols
, &buffer_local_symbols
);
4931 /* Set up the default values of various buffer slots. */
4932 /* Must do these before making the first buffer! */
4934 /* real setup is done in bindings.el */
4935 BSET (&buffer_defaults
, mode_line_format
, build_pure_c_string ("%-"));
4936 BSET (&buffer_defaults
, header_line_format
, Qnil
);
4937 BSET (&buffer_defaults
, abbrev_mode
, Qnil
);
4938 BSET (&buffer_defaults
, overwrite_mode
, Qnil
);
4939 BSET (&buffer_defaults
, case_fold_search
, Qt
);
4940 BSET (&buffer_defaults
, auto_fill_function
, Qnil
);
4941 BSET (&buffer_defaults
, selective_display
, Qnil
);
4942 BSET (&buffer_defaults
, selective_display_ellipses
, Qt
);
4943 BSET (&buffer_defaults
, abbrev_table
, Qnil
);
4944 BSET (&buffer_defaults
, display_table
, Qnil
);
4945 BSET (&buffer_defaults
, undo_list
, Qnil
);
4946 BSET (&buffer_defaults
, mark_active
, Qnil
);
4947 BSET (&buffer_defaults
, file_format
, Qnil
);
4948 BSET (&buffer_defaults
, auto_save_file_format
, Qt
);
4949 buffer_defaults
.overlays_before
= NULL
;
4950 buffer_defaults
.overlays_after
= NULL
;
4951 buffer_defaults
.overlay_center
= BEG
;
4953 XSETFASTINT (BVAR (&buffer_defaults
, tab_width
), 8);
4954 BSET (&buffer_defaults
, truncate_lines
, Qnil
);
4955 BSET (&buffer_defaults
, word_wrap
, Qnil
);
4956 BSET (&buffer_defaults
, ctl_arrow
, Qt
);
4957 BSET (&buffer_defaults
, bidi_display_reordering
, Qt
);
4958 BSET (&buffer_defaults
, bidi_paragraph_direction
, Qnil
);
4959 BSET (&buffer_defaults
, cursor_type
, Qt
);
4960 BSET (&buffer_defaults
, extra_line_spacing
, Qnil
);
4961 BSET (&buffer_defaults
, cursor_in_non_selected_windows
, Qt
);
4963 BSET (&buffer_defaults
, enable_multibyte_characters
, Qt
);
4964 BSET (&buffer_defaults
, buffer_file_coding_system
, Qnil
);
4965 XSETFASTINT (BVAR (&buffer_defaults
, fill_column
), 70);
4966 XSETFASTINT (BVAR (&buffer_defaults
, left_margin
), 0);
4967 BSET (&buffer_defaults
, cache_long_line_scans
, Qnil
);
4968 BSET (&buffer_defaults
, file_truename
, Qnil
);
4969 XSETFASTINT (BVAR (&buffer_defaults
, display_count
), 0);
4970 XSETFASTINT (BVAR (&buffer_defaults
, left_margin_cols
), 0);
4971 XSETFASTINT (BVAR (&buffer_defaults
, right_margin_cols
), 0);
4972 BSET (&buffer_defaults
, left_fringe_width
, Qnil
);
4973 BSET (&buffer_defaults
, right_fringe_width
, Qnil
);
4974 BSET (&buffer_defaults
, fringes_outside_margins
, Qnil
);
4975 BSET (&buffer_defaults
, scroll_bar_width
, Qnil
);
4976 BSET (&buffer_defaults
, vertical_scroll_bar_type
, Qt
);
4977 BSET (&buffer_defaults
, indicate_empty_lines
, Qnil
);
4978 BSET (&buffer_defaults
, indicate_buffer_boundaries
, Qnil
);
4979 BSET (&buffer_defaults
, fringe_indicator_alist
, Qnil
);
4980 BSET (&buffer_defaults
, fringe_cursor_alist
, Qnil
);
4981 BSET (&buffer_defaults
, scroll_up_aggressively
, Qnil
);
4982 BSET (&buffer_defaults
, scroll_down_aggressively
, Qnil
);
4983 BSET (&buffer_defaults
, display_time
, Qnil
);
4985 /* Assign the local-flags to the slots that have default values.
4986 The local flag is a bit that is used in the buffer
4987 to say that it has its own local value for the slot.
4988 The local flag bits are in the local_var_flags slot of the buffer. */
4990 /* Nothing can work if this isn't true */
4991 { verify (sizeof (EMACS_INT
) == word_size
); }
4993 /* 0 means not a lisp var, -1 means always local, else mask */
4994 memset (&buffer_local_flags
, 0, sizeof buffer_local_flags
);
4995 BSET (&buffer_local_flags
, filename
, make_number (-1));
4996 BSET (&buffer_local_flags
, directory
, make_number (-1));
4997 BSET (&buffer_local_flags
, backed_up
, make_number (-1));
4998 BSET (&buffer_local_flags
, save_length
, make_number (-1));
4999 BSET (&buffer_local_flags
, auto_save_file_name
, make_number (-1));
5000 BSET (&buffer_local_flags
, read_only
, make_number (-1));
5001 BSET (&buffer_local_flags
, major_mode
, make_number (-1));
5002 BSET (&buffer_local_flags
, mode_name
, make_number (-1));
5003 BSET (&buffer_local_flags
, undo_list
, make_number (-1));
5004 BSET (&buffer_local_flags
, mark_active
, make_number (-1));
5005 BSET (&buffer_local_flags
, point_before_scroll
, make_number (-1));
5006 BSET (&buffer_local_flags
, file_truename
, make_number (-1));
5007 BSET (&buffer_local_flags
, invisibility_spec
, make_number (-1));
5008 BSET (&buffer_local_flags
, file_format
, make_number (-1));
5009 BSET (&buffer_local_flags
, auto_save_file_format
, make_number (-1));
5010 BSET (&buffer_local_flags
, display_count
, make_number (-1));
5011 BSET (&buffer_local_flags
, display_time
, make_number (-1));
5012 BSET (&buffer_local_flags
, enable_multibyte_characters
, make_number (-1));
5015 XSETFASTINT (BVAR (&buffer_local_flags
, mode_line_format
), idx
); ++idx
;
5016 XSETFASTINT (BVAR (&buffer_local_flags
, abbrev_mode
), idx
); ++idx
;
5017 XSETFASTINT (BVAR (&buffer_local_flags
, overwrite_mode
), idx
); ++idx
;
5018 XSETFASTINT (BVAR (&buffer_local_flags
, case_fold_search
), idx
); ++idx
;
5019 XSETFASTINT (BVAR (&buffer_local_flags
, auto_fill_function
), idx
); ++idx
;
5020 XSETFASTINT (BVAR (&buffer_local_flags
, selective_display
), idx
); ++idx
;
5021 XSETFASTINT (BVAR (&buffer_local_flags
, selective_display_ellipses
), idx
); ++idx
;
5022 XSETFASTINT (BVAR (&buffer_local_flags
, tab_width
), idx
); ++idx
;
5023 XSETFASTINT (BVAR (&buffer_local_flags
, truncate_lines
), idx
); ++idx
;
5024 XSETFASTINT (BVAR (&buffer_local_flags
, word_wrap
), idx
); ++idx
;
5025 XSETFASTINT (BVAR (&buffer_local_flags
, ctl_arrow
), idx
); ++idx
;
5026 XSETFASTINT (BVAR (&buffer_local_flags
, fill_column
), idx
); ++idx
;
5027 XSETFASTINT (BVAR (&buffer_local_flags
, left_margin
), idx
); ++idx
;
5028 XSETFASTINT (BVAR (&buffer_local_flags
, abbrev_table
), idx
); ++idx
;
5029 XSETFASTINT (BVAR (&buffer_local_flags
, display_table
), idx
); ++idx
;
5030 XSETFASTINT (BVAR (&buffer_local_flags
, syntax_table
), idx
); ++idx
;
5031 XSETFASTINT (BVAR (&buffer_local_flags
, cache_long_line_scans
), idx
); ++idx
;
5032 XSETFASTINT (BVAR (&buffer_local_flags
, category_table
), idx
); ++idx
;
5033 XSETFASTINT (BVAR (&buffer_local_flags
, bidi_display_reordering
), idx
); ++idx
;
5034 XSETFASTINT (BVAR (&buffer_local_flags
, bidi_paragraph_direction
), idx
); ++idx
;
5035 XSETFASTINT (BVAR (&buffer_local_flags
, buffer_file_coding_system
), idx
);
5036 /* Make this one a permanent local. */
5037 buffer_permanent_local_flags
[idx
++] = 1;
5038 XSETFASTINT (BVAR (&buffer_local_flags
, left_margin_cols
), idx
); ++idx
;
5039 XSETFASTINT (BVAR (&buffer_local_flags
, right_margin_cols
), idx
); ++idx
;
5040 XSETFASTINT (BVAR (&buffer_local_flags
, left_fringe_width
), idx
); ++idx
;
5041 XSETFASTINT (BVAR (&buffer_local_flags
, right_fringe_width
), idx
); ++idx
;
5042 XSETFASTINT (BVAR (&buffer_local_flags
, fringes_outside_margins
), idx
); ++idx
;
5043 XSETFASTINT (BVAR (&buffer_local_flags
, scroll_bar_width
), idx
); ++idx
;
5044 XSETFASTINT (BVAR (&buffer_local_flags
, vertical_scroll_bar_type
), idx
); ++idx
;
5045 XSETFASTINT (BVAR (&buffer_local_flags
, indicate_empty_lines
), idx
); ++idx
;
5046 XSETFASTINT (BVAR (&buffer_local_flags
, indicate_buffer_boundaries
), idx
); ++idx
;
5047 XSETFASTINT (BVAR (&buffer_local_flags
, fringe_indicator_alist
), idx
); ++idx
;
5048 XSETFASTINT (BVAR (&buffer_local_flags
, fringe_cursor_alist
), idx
); ++idx
;
5049 XSETFASTINT (BVAR (&buffer_local_flags
, scroll_up_aggressively
), idx
); ++idx
;
5050 XSETFASTINT (BVAR (&buffer_local_flags
, scroll_down_aggressively
), idx
); ++idx
;
5051 XSETFASTINT (BVAR (&buffer_local_flags
, header_line_format
), idx
); ++idx
;
5052 XSETFASTINT (BVAR (&buffer_local_flags
, cursor_type
), idx
); ++idx
;
5053 XSETFASTINT (BVAR (&buffer_local_flags
, extra_line_spacing
), idx
); ++idx
;
5054 XSETFASTINT (BVAR (&buffer_local_flags
, cursor_in_non_selected_windows
), idx
); ++idx
;
5056 /* Need more room? */
5057 if (idx
>= MAX_PER_BUFFER_VARS
)
5059 last_per_buffer_idx
= idx
;
5061 Vbuffer_alist
= Qnil
;
5065 QSFundamental
= build_pure_c_string ("Fundamental");
5067 Qfundamental_mode
= intern_c_string ("fundamental-mode");
5068 BSET (&buffer_defaults
, major_mode
, Qfundamental_mode
);
5070 Qmode_class
= intern_c_string ("mode-class");
5072 Qprotected_field
= intern_c_string ("protected-field");
5074 Qpermanent_local
= intern_c_string ("permanent-local");
5076 Qkill_buffer_hook
= intern_c_string ("kill-buffer-hook");
5077 Fput (Qkill_buffer_hook
, Qpermanent_local
, Qt
);
5079 /* super-magic invisible buffer */
5080 Vprin1_to_string_buffer
= Fget_buffer_create (build_pure_c_string (" prin1"));
5081 Vbuffer_alist
= Qnil
;
5083 Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*")));
5085 inhibit_modification_hooks
= 0;
5095 #ifdef USE_MMAP_FOR_BUFFERS
5097 /* When using the ralloc implementation based on mmap(2), buffer
5098 text pointers will have been set to null in the dumped Emacs.
5103 if (b
->text
->beg
== NULL
)
5104 enlarge_buffer_text (b
, 0);
5106 #endif /* USE_MMAP_FOR_BUFFERS */
5108 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
5109 if (NILP (BVAR (&buffer_defaults
, enable_multibyte_characters
)))
5110 Fset_buffer_multibyte (Qnil
);
5112 pwd
= get_current_dir_name ();
5115 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno
));
5117 /* Maybe this should really use some standard subroutine
5118 whose definition is filename syntax dependent. */
5120 if (!(IS_DIRECTORY_SEP (pwd
[len
- 1])))
5122 /* Grow buffer to add directory separator and '\0'. */
5123 pwd
= realloc (pwd
, len
+ 2);
5125 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno
));
5126 pwd
[len
] = DIRECTORY_SEP
;
5127 pwd
[len
+ 1] = '\0';
5131 BSET (current_buffer
, directory
, make_unibyte_string (pwd
, len
));
5132 if (! NILP (BVAR (&buffer_defaults
, enable_multibyte_characters
)))
5133 /* At this moment, we still don't know how to decode the
5134 directory name. So, we keep the bytes in multibyte form so
5135 that ENCODE_FILE correctly gets the original bytes. */
5136 BSET (current_buffer
, directory
,
5137 string_to_multibyte (BVAR (current_buffer
, directory
)));
5139 /* Add /: to the front of the name
5140 if it would otherwise be treated as magic. */
5141 temp
= Ffind_file_name_handler (BVAR (current_buffer
, directory
), Qt
);
5143 /* If the default dir is just /, TEMP is non-nil
5144 because of the ange-ftp completion handler.
5145 However, it is not necessary to turn / into /:/.
5146 So avoid doing that. */
5147 && strcmp ("/", SSDATA (BVAR (current_buffer
, directory
))))
5148 BSET (current_buffer
, directory
,
5149 concat2 (build_string ("/:"), BVAR (current_buffer
, directory
)));
5151 temp
= get_minibuffer (0);
5152 BSET (XBUFFER (temp
), directory
, BVAR (current_buffer
, directory
));
5157 /* Similar to defvar_lisp but define a variable whose value is the Lisp
5158 Object stored in the current buffer. address is the address of the slot
5159 in the buffer that is current now. */
5161 /* TYPE is nil for a general Lisp variable.
5162 An integer specifies a type; then only Lisp values
5163 with that type code are allowed (except that nil is allowed too).
5164 LNAME is the Lisp-level variable name.
5165 VNAME is the name of the buffer slot.
5166 DOC is a dummy where you write the doc string as a comment. */
5167 #define DEFVAR_PER_BUFFER(lname, vname, type, doc) \
5169 static struct Lisp_Buffer_Objfwd bo_fwd; \
5170 defvar_per_buffer (&bo_fwd, lname, vname, type); \
5174 defvar_per_buffer (struct Lisp_Buffer_Objfwd
*bo_fwd
, const char *namestring
,
5175 Lisp_Object
*address
, Lisp_Object type
)
5177 struct Lisp_Symbol
*sym
;
5180 sym
= XSYMBOL (intern (namestring
));
5181 offset
= (char *)address
- (char *)current_buffer
;
5183 bo_fwd
->type
= Lisp_Fwd_Buffer_Obj
;
5184 bo_fwd
->offset
= offset
;
5185 bo_fwd
->slottype
= type
;
5186 sym
->declared_special
= 1;
5187 sym
->redirect
= SYMBOL_FORWARDED
;
5189 /* I tried to do the job without a cast, but it seems impossible.
5190 union Lisp_Fwd *fwd; &(fwd->u_buffer_objfwd) = bo_fwd; */
5191 SET_SYMBOL_FWD (sym
, (union Lisp_Fwd
*)bo_fwd
);
5193 XSETSYMBOL (PER_BUFFER_SYMBOL (offset
), sym
);
5195 if (PER_BUFFER_IDX (offset
) == 0)
5196 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
5197 slot of buffer_local_flags */
5202 /* initialize the buffer routines */
5204 syms_of_buffer (void)
5206 staticpro (&last_overlay_modification_hooks
);
5207 last_overlay_modification_hooks
5208 = Fmake_vector (make_number (10), Qnil
);
5210 staticpro (&Vbuffer_defaults
);
5211 staticpro (&Vbuffer_local_symbols
);
5212 staticpro (&Qfundamental_mode
);
5213 staticpro (&Qmode_class
);
5214 staticpro (&QSFundamental
);
5215 staticpro (&Vbuffer_alist
);
5216 staticpro (&Qprotected_field
);
5217 staticpro (&Qpermanent_local
);
5218 staticpro (&Qkill_buffer_hook
);
5220 DEFSYM (Qpermanent_local_hook
, "permanent-local-hook");
5221 DEFSYM (Qoverlayp
, "overlayp");
5222 DEFSYM (Qevaporate
, "evaporate");
5223 DEFSYM (Qmodification_hooks
, "modification-hooks");
5224 DEFSYM (Qinsert_in_front_hooks
, "insert-in-front-hooks");
5225 DEFSYM (Qinsert_behind_hooks
, "insert-behind-hooks");
5226 DEFSYM (Qget_file_buffer
, "get-file-buffer");
5227 DEFSYM (Qpriority
, "priority");
5228 DEFSYM (Qbefore_string
, "before-string");
5229 DEFSYM (Qafter_string
, "after-string");
5230 DEFSYM (Qfirst_change_hook
, "first-change-hook");
5231 DEFSYM (Qbefore_change_functions
, "before-change-functions");
5232 DEFSYM (Qafter_change_functions
, "after-change-functions");
5233 DEFSYM (Qkill_buffer_query_functions
, "kill-buffer-query-functions");
5235 Fput (Qprotected_field
, Qerror_conditions
,
5236 listn (CONSTYPE_PURE
, 2, Qprotected_field
, Qerror
));
5237 Fput (Qprotected_field
, Qerror_message
,
5238 build_pure_c_string ("Attempt to modify a protected field"));
5240 DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format",
5242 doc
: /* Default value of `mode-line-format' for buffers that don't override it.
5243 This is the same as (default-value 'mode-line-format). */);
5245 DEFVAR_BUFFER_DEFAULTS ("default-header-line-format",
5247 doc
: /* Default value of `header-line-format' for buffers that don't override it.
5248 This is the same as (default-value 'header-line-format). */);
5250 DEFVAR_BUFFER_DEFAULTS ("default-cursor-type", cursor_type
,
5251 doc
: /* Default value of `cursor-type' for buffers that don't override it.
5252 This is the same as (default-value 'cursor-type). */);
5254 DEFVAR_BUFFER_DEFAULTS ("default-line-spacing",
5256 doc
: /* Default value of `line-spacing' for buffers that don't override it.
5257 This is the same as (default-value 'line-spacing). */);
5259 DEFVAR_BUFFER_DEFAULTS ("default-cursor-in-non-selected-windows",
5260 cursor_in_non_selected_windows
,
5261 doc
: /* Default value of `cursor-in-non-selected-windows'.
5262 This is the same as (default-value 'cursor-in-non-selected-windows). */);
5264 DEFVAR_BUFFER_DEFAULTS ("default-abbrev-mode",
5266 doc
: /* Default value of `abbrev-mode' for buffers that do not override it.
5267 This is the same as (default-value 'abbrev-mode). */);
5269 DEFVAR_BUFFER_DEFAULTS ("default-ctl-arrow",
5271 doc
: /* Default value of `ctl-arrow' for buffers that do not override it.
5272 This is the same as (default-value 'ctl-arrow). */);
5274 DEFVAR_BUFFER_DEFAULTS ("default-enable-multibyte-characters",
5275 enable_multibyte_characters
,
5276 doc
: /* Default value of `enable-multibyte-characters' for buffers not overriding it.
5277 This is the same as (default-value 'enable-multibyte-characters). */);
5279 DEFVAR_BUFFER_DEFAULTS ("default-buffer-file-coding-system",
5280 buffer_file_coding_system
,
5281 doc
: /* Default value of `buffer-file-coding-system' for buffers not overriding it.
5282 This is the same as (default-value 'buffer-file-coding-system). */);
5284 DEFVAR_BUFFER_DEFAULTS ("default-truncate-lines",
5286 doc
: /* Default value of `truncate-lines' for buffers that do not override it.
5287 This is the same as (default-value 'truncate-lines). */);
5289 DEFVAR_BUFFER_DEFAULTS ("default-fill-column",
5291 doc
: /* Default value of `fill-column' for buffers that do not override it.
5292 This is the same as (default-value 'fill-column). */);
5294 DEFVAR_BUFFER_DEFAULTS ("default-left-margin",
5296 doc
: /* Default value of `left-margin' for buffers that do not override it.
5297 This is the same as (default-value 'left-margin). */);
5299 DEFVAR_BUFFER_DEFAULTS ("default-tab-width",
5301 doc
: /* Default value of `tab-width' for buffers that do not override it.
5302 This is the same as (default-value 'tab-width). */);
5304 DEFVAR_BUFFER_DEFAULTS ("default-case-fold-search",
5306 doc
: /* Default value of `case-fold-search' for buffers that don't override it.
5307 This is the same as (default-value 'case-fold-search). */);
5309 DEFVAR_BUFFER_DEFAULTS ("default-left-margin-width",
5311 doc
: /* Default value of `left-margin-width' for buffers that don't override it.
5312 This is the same as (default-value 'left-margin-width). */);
5314 DEFVAR_BUFFER_DEFAULTS ("default-right-margin-width",
5316 doc
: /* Default value of `right-margin-width' for buffers that don't override it.
5317 This is the same as (default-value 'right-margin-width). */);
5319 DEFVAR_BUFFER_DEFAULTS ("default-left-fringe-width",
5321 doc
: /* Default value of `left-fringe-width' for buffers that don't override it.
5322 This is the same as (default-value 'left-fringe-width). */);
5324 DEFVAR_BUFFER_DEFAULTS ("default-right-fringe-width",
5326 doc
: /* Default value of `right-fringe-width' for buffers that don't override it.
5327 This is the same as (default-value 'right-fringe-width). */);
5329 DEFVAR_BUFFER_DEFAULTS ("default-fringes-outside-margins",
5330 fringes_outside_margins
,
5331 doc
: /* Default value of `fringes-outside-margins' for buffers that don't override it.
5332 This is the same as (default-value 'fringes-outside-margins). */);
5334 DEFVAR_BUFFER_DEFAULTS ("default-scroll-bar-width",
5336 doc
: /* Default value of `scroll-bar-width' for buffers that don't override it.
5337 This is the same as (default-value 'scroll-bar-width). */);
5339 DEFVAR_BUFFER_DEFAULTS ("default-vertical-scroll-bar",
5340 vertical_scroll_bar_type
,
5341 doc
: /* Default value of `vertical-scroll-bar' for buffers that don't override it.
5342 This is the same as (default-value 'vertical-scroll-bar). */);
5344 DEFVAR_BUFFER_DEFAULTS ("default-indicate-empty-lines",
5345 indicate_empty_lines
,
5346 doc
: /* Default value of `indicate-empty-lines' for buffers that don't override it.
5347 This is the same as (default-value 'indicate-empty-lines). */);
5349 DEFVAR_BUFFER_DEFAULTS ("default-indicate-buffer-boundaries",
5350 indicate_buffer_boundaries
,
5351 doc
: /* Default value of `indicate-buffer-boundaries' for buffers that don't override it.
5352 This is the same as (default-value 'indicate-buffer-boundaries). */);
5354 DEFVAR_BUFFER_DEFAULTS ("default-fringe-indicator-alist",
5355 fringe_indicator_alist
,
5356 doc
: /* Default value of `fringe-indicator-alist' for buffers that don't override it.
5357 This is the same as (default-value 'fringe-indicator-alist'). */);
5359 DEFVAR_BUFFER_DEFAULTS ("default-fringe-cursor-alist",
5360 fringe_cursor_alist
,
5361 doc
: /* Default value of `fringe-cursor-alist' for buffers that don't override it.
5362 This is the same as (default-value 'fringe-cursor-alist'). */);
5364 DEFVAR_BUFFER_DEFAULTS ("default-scroll-up-aggressively",
5365 scroll_up_aggressively
,
5366 doc
: /* Default value of `scroll-up-aggressively'.
5367 This value applies in buffers that don't have their own local values.
5368 This is the same as (default-value 'scroll-up-aggressively). */);
5370 DEFVAR_BUFFER_DEFAULTS ("default-scroll-down-aggressively",
5371 scroll_down_aggressively
,
5372 doc
: /* Default value of `scroll-down-aggressively'.
5373 This value applies in buffers that don't have their own local values.
5374 This is the same as (default-value 'scroll-down-aggressively). */);
5376 DEFVAR_PER_BUFFER ("header-line-format",
5377 &BVAR (current_buffer
, header_line_format
),
5379 doc
: /* Analogous to `mode-line-format', but controls the header line.
5380 The header line appears, optionally, at the top of a window;
5381 the mode line appears at the bottom. */);
5383 DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer
, mode_line_format
),
5385 doc
: /* Template for displaying mode line for current buffer.
5387 The value may be nil, a string, a symbol or a list.
5389 A value of nil means don't display a mode line.
5391 For any symbol other than t or nil, the symbol's value is processed as
5392 a mode line construct. As a special exception, if that value is a
5393 string, the string is processed verbatim, without handling any
5394 %-constructs (see below). Also, unless the symbol has a non-nil
5395 `risky-local-variable' property, all properties in any strings, as
5396 well as all :eval and :propertize forms in the value, are ignored.
5398 A list whose car is a string or list is processed by processing each
5399 of the list elements recursively, as separate mode line constructs,
5400 and concatenating the results.
5402 A list of the form `(:eval FORM)' is processed by evaluating FORM and
5403 using the result as a mode line construct. Be careful--FORM should
5404 not load any files, because that can cause an infinite recursion.
5406 A list of the form `(:propertize ELT PROPS...)' is processed by
5407 processing ELT as the mode line construct, and adding the text
5408 properties PROPS to the result.
5410 A list whose car is a symbol is processed by examining the symbol's
5411 value, and, if that value is non-nil, processing the cadr of the list
5412 recursively; and if that value is nil, processing the caddr of the
5415 A list whose car is an integer is processed by processing the cadr of
5416 the list, and padding (if the number is positive) or truncating (if
5417 negative) to the width specified by that number.
5419 A string is printed verbatim in the mode line except for %-constructs:
5420 %b -- print buffer name. %f -- print visited file name.
5421 %F -- print frame name.
5422 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.
5423 %& is like %*, but ignore read-only-ness.
5424 % means buffer is read-only and * means it is modified.
5425 For a modified read-only buffer, %* gives % and %+ gives *.
5426 %s -- print process status. %l -- print the current line number.
5427 %c -- print the current column number (this makes editing slower).
5428 To make the column number update correctly in all cases,
5429 `column-number-mode' must be non-nil.
5430 %i -- print the size of the buffer.
5431 %I -- like %i, but use k, M, G, etc., to abbreviate.
5432 %p -- print percent of buffer above top of window, or Top, Bot or All.
5433 %P -- print percent of buffer above bottom of window, perhaps plus Top,
5434 or print Bottom or All.
5435 %n -- print Narrow if appropriate.
5436 %t -- visited file is text or binary (if OS supports this distinction).
5437 %z -- print mnemonics of keyboard, terminal, and buffer coding systems.
5438 %Z -- like %z, but including the end-of-line format.
5439 %e -- print error message about full memory.
5440 %@ -- print @ or hyphen. @ means that default-directory is on a
5442 %[ -- print one [ for each recursive editing level. %] similar.
5443 %% -- print %. %- -- print infinitely many dashes.
5444 Decimal digits after the % specify field width to which to pad. */);
5446 DEFVAR_BUFFER_DEFAULTS ("default-major-mode", major_mode
,
5447 doc
: /* Value of `major-mode' for new buffers. */);
5449 DEFVAR_PER_BUFFER ("major-mode", &BVAR (current_buffer
, major_mode
),
5450 make_number (Lisp_Symbol
),
5451 doc
: /* Symbol for current buffer's major mode.
5452 The default value (normally `fundamental-mode') affects new buffers.
5453 A value of nil means to use the current buffer's major mode, provided
5454 it is not marked as "special".
5456 When a mode is used by default, `find-file' switches to it before it
5457 reads the contents into the buffer and before it finishes setting up
5458 the buffer. Thus, the mode and its hooks should not expect certain
5459 variables such as `buffer-read-only' and `buffer-file-coding-system'
5462 DEFVAR_PER_BUFFER ("mode-name", &BVAR (current_buffer
, mode_name
),
5464 doc
: /* Pretty name of current buffer's major mode.
5465 Usually a string, but can use any of the constructs for `mode-line-format',
5467 Format with `format-mode-line' to produce a string value. */);
5469 DEFVAR_PER_BUFFER ("local-abbrev-table", &BVAR (current_buffer
, abbrev_table
), Qnil
,
5470 doc
: /* Local (mode-specific) abbrev table of current buffer. */);
5472 DEFVAR_PER_BUFFER ("abbrev-mode", &BVAR (current_buffer
, abbrev_mode
), Qnil
,
5473 doc
: /* Non-nil if Abbrev mode is enabled.
5474 Use the command `abbrev-mode' to change this variable. */);
5476 DEFVAR_PER_BUFFER ("case-fold-search", &BVAR (current_buffer
, case_fold_search
),
5478 doc
: /* Non-nil if searches and matches should ignore case. */);
5480 DEFVAR_PER_BUFFER ("fill-column", &BVAR (current_buffer
, fill_column
),
5481 make_number (Lisp_Int0
),
5482 doc
: /* Column beyond which automatic line-wrapping should happen.
5483 Interactively, you can set the buffer local value using \\[set-fill-column]. */);
5485 DEFVAR_PER_BUFFER ("left-margin", &BVAR (current_buffer
, left_margin
),
5486 make_number (Lisp_Int0
),
5487 doc
: /* Column for the default `indent-line-function' to indent to.
5488 Linefeed indents to this column in Fundamental mode. */);
5490 DEFVAR_PER_BUFFER ("tab-width", &BVAR (current_buffer
, tab_width
),
5491 make_number (Lisp_Int0
),
5492 doc
: /* Distance between tab stops (for display of tab characters), in columns.
5493 This should be an integer greater than zero. */);
5495 DEFVAR_PER_BUFFER ("ctl-arrow", &BVAR (current_buffer
, ctl_arrow
), Qnil
,
5496 doc
: /* Non-nil means display control chars with uparrow.
5497 A value of nil means use backslash and octal digits.
5498 This variable does not apply to characters whose display is specified
5499 in the current display table (if there is one). */);
5501 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
5502 &BVAR (current_buffer
, enable_multibyte_characters
),
5504 doc
: /* Non-nil means the buffer contents are regarded as multi-byte characters.
5505 Otherwise they are regarded as unibyte. This affects the display,
5506 file I/O and the behavior of various editing commands.
5508 This variable is buffer-local but you cannot set it directly;
5509 use the function `set-buffer-multibyte' to change a buffer's representation.
5510 See also Info node `(elisp)Text Representations'. */);
5511 XSYMBOL (intern_c_string ("enable-multibyte-characters"))->constant
= 1;
5513 DEFVAR_PER_BUFFER ("buffer-file-coding-system",
5514 &BVAR (current_buffer
, buffer_file_coding_system
), Qnil
,
5515 doc
: /* Coding system to be used for encoding the buffer contents on saving.
5516 This variable applies to saving the buffer, and also to `write-region'
5517 and other functions that use `write-region'.
5518 It does not apply to sending output to subprocesses, however.
5520 If this is nil, the buffer is saved without any code conversion
5521 unless some coding system is specified in `file-coding-system-alist'
5522 for the buffer file.
5524 If the text to be saved cannot be encoded as specified by this variable,
5525 an alternative encoding is selected by `select-safe-coding-system', which see.
5527 The variable `coding-system-for-write', if non-nil, overrides this variable.
5529 This variable is never applied to a way of decoding a file while reading it. */);
5531 DEFVAR_PER_BUFFER ("bidi-display-reordering",
5532 &BVAR (current_buffer
, bidi_display_reordering
), Qnil
,
5533 doc
: /* Non-nil means reorder bidirectional text for display in the visual order. */);
5535 DEFVAR_PER_BUFFER ("bidi-paragraph-direction",
5536 &BVAR (current_buffer
, bidi_paragraph_direction
), Qnil
,
5537 doc
: /* If non-nil, forces directionality of text paragraphs in the buffer.
5539 If this is nil (the default), the direction of each paragraph is
5540 determined by the first strong directional character of its text.
5541 The values of `right-to-left' and `left-to-right' override that.
5542 Any other value is treated as nil.
5544 This variable has no effect unless the buffer's value of
5545 \`bidi-display-reordering' is non-nil. */);
5547 DEFVAR_PER_BUFFER ("truncate-lines", &BVAR (current_buffer
, truncate_lines
), Qnil
,
5548 doc
: /* Non-nil means do not display continuation lines.
5549 Instead, give each line of text just one screen line.
5551 Note that this is overridden by the variable
5552 `truncate-partial-width-windows' if that variable is non-nil
5553 and this buffer is not full-frame width.
5555 Minibuffers set this variable to nil. */);
5557 DEFVAR_PER_BUFFER ("word-wrap", &BVAR (current_buffer
, word_wrap
), Qnil
,
5558 doc
: /* Non-nil means to use word-wrapping for continuation lines.
5559 When word-wrapping is on, continuation lines are wrapped at the space
5560 or tab character nearest to the right window edge.
5561 If nil, continuation lines are wrapped at the right screen edge.
5563 This variable has no effect if long lines are truncated (see
5564 `truncate-lines' and `truncate-partial-width-windows'). If you use
5565 word-wrapping, you might want to reduce the value of
5566 `truncate-partial-width-windows', since wrapping can make text readable
5567 in narrower windows.
5569 Instead of setting this variable directly, most users should use
5570 Visual Line mode . Visual Line mode, when enabled, sets `word-wrap'
5571 to t, and additionally redefines simple editing commands to act on
5572 visual lines rather than logical lines. See the documentation of
5573 `visual-line-mode'. */);
5575 DEFVAR_PER_BUFFER ("default-directory", &BVAR (current_buffer
, directory
),
5576 make_number (Lisp_String
),
5577 doc
: /* Name of default directory of current buffer. Should end with slash.
5578 To interactively change the default directory, use command `cd'. */);
5580 DEFVAR_PER_BUFFER ("auto-fill-function", &BVAR (current_buffer
, auto_fill_function
),
5582 doc
: /* Function called (if non-nil) to perform auto-fill.
5583 It is called after self-inserting any character specified in
5584 the `auto-fill-chars' table.
5585 NOTE: This variable is not a hook;
5586 its value may not be a list of functions. */);
5588 DEFVAR_PER_BUFFER ("buffer-file-name", &BVAR (current_buffer
, filename
),
5589 make_number (Lisp_String
),
5590 doc
: /* Name of file visited in current buffer, or nil if not visiting a file. */);
5592 DEFVAR_PER_BUFFER ("buffer-file-truename", &BVAR (current_buffer
, file_truename
),
5593 make_number (Lisp_String
),
5594 doc
: /* Abbreviated truename of file visited in current buffer, or nil if none.
5595 The truename of a file is calculated by `file-truename'
5596 and then abbreviated with `abbreviate-file-name'. */);
5598 DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
5599 &BVAR (current_buffer
, auto_save_file_name
),
5600 make_number (Lisp_String
),
5601 doc
: /* Name of file for auto-saving current buffer.
5602 If it is nil, that means don't auto-save this buffer. */);
5604 DEFVAR_PER_BUFFER ("buffer-read-only", &BVAR (current_buffer
, read_only
), Qnil
,
5605 doc
: /* Non-nil if this buffer is read-only. */);
5607 DEFVAR_PER_BUFFER ("buffer-backed-up", &BVAR (current_buffer
, backed_up
), Qnil
,
5608 doc
: /* Non-nil if this buffer's file has been backed up.
5609 Backing up is done before the first time the file is saved. */);
5611 DEFVAR_PER_BUFFER ("buffer-saved-size", &BVAR (current_buffer
, save_length
),
5612 make_number (Lisp_Int0
),
5613 doc
: /* Length of current buffer when last read in, saved or auto-saved.
5615 -1 means auto-saving turned off until next real save.
5617 If you set this to -2, that means don't turn off auto-saving in this buffer
5618 if its text size shrinks. If you use `buffer-swap-text' on a buffer,
5619 you probably should set this to -2 in that buffer. */);
5621 DEFVAR_PER_BUFFER ("selective-display", &BVAR (current_buffer
, selective_display
),
5623 doc
: /* Non-nil enables selective display.
5624 An integer N as value means display only lines
5625 that start with less than N columns of space.
5626 A value of t means that the character ^M makes itself and
5627 all the rest of the line invisible; also, when saving the buffer
5628 in a file, save the ^M as a newline. */);
5630 DEFVAR_PER_BUFFER ("selective-display-ellipses",
5631 &BVAR (current_buffer
, selective_display_ellipses
),
5633 doc
: /* Non-nil means display ... on previous line when a line is invisible. */);
5635 DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer
, overwrite_mode
), Qnil
,
5636 doc
: /* Non-nil if self-insertion should replace existing text.
5637 The value should be one of `overwrite-mode-textual',
5638 `overwrite-mode-binary', or nil.
5639 If it is `overwrite-mode-textual', self-insertion still
5640 inserts at the end of a line, and inserts when point is before a tab,
5641 until the tab is filled in.
5642 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too. */);
5644 DEFVAR_PER_BUFFER ("buffer-display-table", &BVAR (current_buffer
, display_table
),
5646 doc
: /* Display table that controls display of the contents of current buffer.
5648 If this variable is nil, the value of `standard-display-table' is used.
5649 Each window can have its own, overriding display table, see
5650 `set-window-display-table' and `window-display-table'.
5652 The display table is a char-table created with `make-display-table'.
5653 A char-table is an array indexed by character codes. Normal array
5654 primitives `aref' and `aset' can be used to access elements of a char-table.
5656 Each of the char-table elements control how to display the corresponding
5657 text character: the element at index C in the table says how to display
5658 the character whose code is C. Each element should be a vector of
5659 characters or nil. The value nil means display the character in the
5660 default fashion; otherwise, the characters from the vector are delivered
5661 to the screen instead of the original character.
5663 For example, (aset buffer-display-table ?X [?Y]) tells Emacs
5664 to display a capital Y instead of each X character.
5666 In addition, a char-table has six extra slots to control the display of:
5668 the end of a truncated screen line (extra-slot 0, a single character);
5669 the end of a continued line (extra-slot 1, a single character);
5670 the escape character used to display character codes in octal
5671 (extra-slot 2, a single character);
5672 the character used as an arrow for control characters (extra-slot 3,
5673 a single character);
5674 the decoration indicating the presence of invisible lines (extra-slot 4,
5675 a vector of characters);
5676 the character used to draw the border between side-by-side windows
5677 (extra-slot 5, a single character).
5679 See also the functions `display-table-slot' and `set-display-table-slot'. */);
5681 DEFVAR_PER_BUFFER ("left-margin-width", &BVAR (current_buffer
, left_margin_cols
),
5683 doc
: /* Width of left marginal area for display of a buffer.
5684 A value of nil means no marginal area. */);
5686 DEFVAR_PER_BUFFER ("right-margin-width", &BVAR (current_buffer
, right_margin_cols
),
5688 doc
: /* Width of right marginal area for display of a buffer.
5689 A value of nil means no marginal area. */);
5691 DEFVAR_PER_BUFFER ("left-fringe-width", &BVAR (current_buffer
, left_fringe_width
),
5693 doc
: /* Width of this buffer's left fringe (in pixels).
5694 A value of 0 means no left fringe is shown in this buffer's window.
5695 A value of nil means to use the left fringe width from the window's frame. */);
5697 DEFVAR_PER_BUFFER ("right-fringe-width", &BVAR (current_buffer
, right_fringe_width
),
5699 doc
: /* Width of this buffer's right fringe (in pixels).
5700 A value of 0 means no right fringe is shown in this buffer's window.
5701 A value of nil means to use the right fringe width from the window's frame. */);
5703 DEFVAR_PER_BUFFER ("fringes-outside-margins", &BVAR (current_buffer
, fringes_outside_margins
),
5705 doc
: /* Non-nil means to display fringes outside display margins.
5706 A value of nil means to display fringes between margins and buffer text. */);
5708 DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer
, scroll_bar_width
),
5710 doc
: /* Width of this buffer's scroll bars in pixels.
5711 A value of nil means to use the scroll bar width from the window's frame. */);
5713 DEFVAR_PER_BUFFER ("vertical-scroll-bar", &BVAR (current_buffer
, vertical_scroll_bar_type
),
5715 doc
: /* Position of this buffer's vertical scroll bar.
5716 The value takes effect whenever you tell a window to display this buffer;
5717 for instance, with `set-window-buffer' or when `display-buffer' displays it.
5719 A value of `left' or `right' means put the vertical scroll bar at that side
5720 of the window; a value of nil means don't show any vertical scroll bars.
5721 A value of t (the default) means do whatever the window's frame specifies. */);
5723 DEFVAR_PER_BUFFER ("indicate-empty-lines",
5724 &BVAR (current_buffer
, indicate_empty_lines
), Qnil
,
5725 doc
: /* Visually indicate empty lines after the buffer end.
5726 If non-nil, a bitmap is displayed in the left fringe of a window on
5727 window-systems. */);
5729 DEFVAR_PER_BUFFER ("indicate-buffer-boundaries",
5730 &BVAR (current_buffer
, indicate_buffer_boundaries
), Qnil
,
5731 doc
: /* Visually indicate buffer boundaries and scrolling.
5732 If non-nil, the first and last line of the buffer are marked in the fringe
5733 of a window on window-systems with angle bitmaps, or if the window can be
5734 scrolled, the top and bottom line of the window are marked with up and down
5737 If value is a symbol `left' or `right', both angle and arrow bitmaps
5738 are displayed in the left or right fringe, resp. Any other value
5739 that doesn't look like an alist means display the angle bitmaps in
5740 the left fringe but no arrows.
5742 You can exercise more precise control by using an alist as the
5743 value. Each alist element (INDICATOR . POSITION) specifies
5744 where to show one of the indicators. INDICATOR is one of `top',
5745 `bottom', `up', `down', or t, which specifies the default position,
5746 and POSITION is one of `left', `right', or nil, meaning do not show
5749 For example, ((top . left) (t . right)) places the top angle bitmap in
5750 left fringe, the bottom angle bitmap in right fringe, and both arrow
5751 bitmaps in right fringe. To show just the angle bitmaps in the left
5752 fringe, but no arrow bitmaps, use ((top . left) (bottom . left)). */);
5754 DEFVAR_PER_BUFFER ("fringe-indicator-alist",
5755 &BVAR (current_buffer
, fringe_indicator_alist
), Qnil
,
5756 doc
: /* Mapping from logical to physical fringe indicator bitmaps.
5757 The value is an alist where each element (INDICATOR . BITMAPS)
5758 specifies the fringe bitmaps used to display a specific logical
5761 INDICATOR specifies the logical indicator type which is one of the
5762 following symbols: `truncation' , `continuation', `overlay-arrow',
5763 `top', `bottom', `top-bottom', `up', `down', empty-line', or `unknown'.
5765 BITMAPS is a list of symbols (LEFT RIGHT [LEFT1 RIGHT1]) which specifies
5766 the actual bitmap shown in the left or right fringe for the logical
5767 indicator. LEFT and RIGHT are the bitmaps shown in the left and/or
5768 right fringe for the specific indicator. The LEFT1 or RIGHT1 bitmaps
5769 are used only for the `bottom' and `top-bottom' indicators when the
5770 last (only) line has no final newline. BITMAPS may also be a single
5771 symbol which is used in both left and right fringes. */);
5773 DEFVAR_PER_BUFFER ("fringe-cursor-alist",
5774 &BVAR (current_buffer
, fringe_cursor_alist
), Qnil
,
5775 doc
: /* Mapping from logical to physical fringe cursor bitmaps.
5776 The value is an alist where each element (CURSOR . BITMAP)
5777 specifies the fringe bitmaps used to display a specific logical
5778 cursor type in the fringe.
5780 CURSOR specifies the logical cursor type which is one of the following
5781 symbols: `box' , `hollow', `bar', `hbar', or `hollow-small'. The last
5782 one is used to show a hollow cursor on narrow lines display lines
5783 where the normal hollow cursor will not fit.
5785 BITMAP is the corresponding fringe bitmap shown for the logical
5788 DEFVAR_PER_BUFFER ("scroll-up-aggressively",
5789 &BVAR (current_buffer
, scroll_up_aggressively
), Qnil
,
5790 doc
: /* How far to scroll windows upward.
5791 If you move point off the bottom, the window scrolls automatically.
5792 This variable controls how far it scrolls. The value nil, the default,
5793 means scroll to center point. A fraction means scroll to put point
5794 that fraction of the window's height from the bottom of the window.
5795 When the value is 0.0, point goes at the bottom line, which in the
5796 simple case that you moved off with C-f means scrolling just one line.
5797 1.0 means point goes at the top, so that in that simple case, the
5798 window scrolls by a full window height. Meaningful values are
5799 between 0.0 and 1.0, inclusive. */);
5801 DEFVAR_PER_BUFFER ("scroll-down-aggressively",
5802 &BVAR (current_buffer
, scroll_down_aggressively
), Qnil
,
5803 doc
: /* How far to scroll windows downward.
5804 If you move point off the top, the window scrolls automatically.
5805 This variable controls how far it scrolls. The value nil, the default,
5806 means scroll to center point. A fraction means scroll to put point
5807 that fraction of the window's height from the top of the window.
5808 When the value is 0.0, point goes at the top line, which in the
5809 simple case that you moved off with C-b means scrolling just one line.
5810 1.0 means point goes at the bottom, so that in that simple case, the
5811 window scrolls by a full window height. Meaningful values are
5812 between 0.0 and 1.0, inclusive. */);
5814 /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
5818 DEFVAR_LISP ("before-change-functions", Vbefore_change_functions
,
5819 doc
: /* List of functions to call before each text change.
5820 Two arguments are passed to each function: the positions of
5821 the beginning and end of the range of old text to be changed.
5822 \(For an insertion, the beginning and end are at the same place.)
5823 No information is given about the length of the text after the change.
5825 Buffer changes made while executing the `before-change-functions'
5826 don't call any before-change or after-change functions.
5827 That's because `inhibit-modification-hooks' is temporarily set non-nil.
5829 If an unhandled error happens in running these functions,
5830 the variable's value remains nil. That prevents the error
5831 from happening repeatedly and making Emacs nonfunctional. */);
5832 Vbefore_change_functions
= Qnil
;
5834 DEFVAR_LISP ("after-change-functions", Vafter_change_functions
,
5835 doc
: /* List of functions to call after each text change.
5836 Three arguments are passed to each function: the positions of
5837 the beginning and end of the range of changed text,
5838 and the length in bytes of the pre-change text replaced by that range.
5839 \(For an insertion, the pre-change length is zero;
5840 for a deletion, that length is the number of bytes deleted,
5841 and the post-change beginning and end are at the same place.)
5843 Buffer changes made while executing the `after-change-functions'
5844 don't call any before-change or after-change functions.
5845 That's because `inhibit-modification-hooks' is temporarily set non-nil.
5847 If an unhandled error happens in running these functions,
5848 the variable's value remains nil. That prevents the error
5849 from happening repeatedly and making Emacs nonfunctional. */);
5850 Vafter_change_functions
= Qnil
;
5852 DEFVAR_LISP ("first-change-hook", Vfirst_change_hook
,
5853 doc
: /* A list of functions to call before changing a buffer which is unmodified.
5854 The functions are run using the `run-hooks' function. */);
5855 Vfirst_change_hook
= Qnil
;
5857 DEFVAR_PER_BUFFER ("buffer-undo-list", &BVAR (current_buffer
, undo_list
), Qnil
,
5858 doc
: /* List of undo entries in current buffer.
5859 Recent changes come first; older changes follow newer.
5861 An entry (BEG . END) represents an insertion which begins at
5862 position BEG and ends at position END.
5864 An entry (TEXT . POSITION) represents the deletion of the string TEXT
5865 from (abs POSITION). If POSITION is positive, point was at the front
5866 of the text being deleted; if negative, point was at the end.
5868 An entry (t HIGH LOW USEC PSEC) indicates that the buffer was previously
5869 unmodified; (HIGH LOW USEC PSEC) is in the same style as (current-time)
5870 and is the visited file's modification time, as of that time. If the
5871 modification time of the most recent save is different, this entry is
5874 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property
5875 was modified between BEG and END. PROPERTY is the property name,
5876 and VALUE is the old value.
5878 An entry (apply FUN-NAME . ARGS) means undo the change with
5879 \(apply FUN-NAME ARGS).
5881 An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo
5882 in the active region. BEG and END is the range affected by this entry
5883 and DELTA is the number of bytes added or deleted in that range by
5886 An entry (MARKER . DISTANCE) indicates that the marker MARKER
5887 was adjusted in position by the offset DISTANCE (an integer).
5889 An entry of the form POSITION indicates that point was at the buffer
5890 location given by the integer. Undoing an entry of this form places
5893 Entries with value `nil' mark undo boundaries. The undo command treats
5894 the changes between two undo boundaries as a single step to be undone.
5896 If the value of the variable is t, undo information is not recorded. */);
5898 DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer
, mark_active
), Qnil
,
5899 doc
: /* Non-nil means the mark and region are currently active in this buffer. */);
5901 DEFVAR_PER_BUFFER ("cache-long-line-scans", &BVAR (current_buffer
, cache_long_line_scans
), Qnil
,
5902 doc
: /* Non-nil means that Emacs should use caches to handle long lines more quickly.
5904 Normally, the line-motion functions work by scanning the buffer for
5905 newlines. Columnar operations (like `move-to-column' and
5906 `compute-motion') also work by scanning the buffer, summing character
5907 widths as they go. This works well for ordinary text, but if the
5908 buffer's lines are very long (say, more than 500 characters), these
5909 motion functions will take longer to execute. Emacs may also take
5910 longer to update the display.
5912 If `cache-long-line-scans' is non-nil, these motion functions cache the
5913 results of their scans, and consult the cache to avoid rescanning
5914 regions of the buffer until the text is modified. The caches are most
5915 beneficial when they prevent the most searching---that is, when the
5916 buffer contains long lines and large regions of characters with the
5917 same, fixed screen width.
5919 When `cache-long-line-scans' is non-nil, processing short lines will
5920 become slightly slower (because of the overhead of consulting the
5921 cache), and the caches will use memory roughly proportional to the
5922 number of newlines and characters whose screen width varies.
5924 The caches require no explicit maintenance; their accuracy is
5925 maintained internally by the Emacs primitives. Enabling or disabling
5926 the cache should not affect the behavior of any of the motion
5927 functions; it should only affect their performance. */);
5929 DEFVAR_PER_BUFFER ("point-before-scroll", &BVAR (current_buffer
, point_before_scroll
), Qnil
,
5930 doc
: /* Value of point before the last series of scroll operations, or nil. */);
5932 DEFVAR_PER_BUFFER ("buffer-file-format", &BVAR (current_buffer
, file_format
), Qnil
,
5933 doc
: /* List of formats to use when saving this buffer.
5934 Formats are defined by `format-alist'. This variable is
5935 set when a file is visited. */);
5937 DEFVAR_PER_BUFFER ("buffer-auto-save-file-format",
5938 &BVAR (current_buffer
, auto_save_file_format
), Qnil
,
5939 doc
: /* Format in which to write auto-save files.
5940 Should be a list of symbols naming formats that are defined in `format-alist'.
5941 If it is t, which is the default, auto-save files are written in the
5942 same format as a regular save would use. */);
5944 DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
5945 &BVAR (current_buffer
, invisibility_spec
), Qnil
,
5946 doc
: /* Invisibility spec of this buffer.
5947 The default is t, which means that text is invisible
5948 if it has a non-nil `invisible' property.
5949 If the value is a list, a text character is invisible if its `invisible'
5950 property is an element in that list (or is a list with members in common).
5951 If an element is a cons cell of the form (PROP . ELLIPSIS),
5952 then characters with property value PROP are invisible,
5953 and they have an ellipsis as well if ELLIPSIS is non-nil. */);
5955 DEFVAR_PER_BUFFER ("buffer-display-count",
5956 &BVAR (current_buffer
, display_count
), Qnil
,
5957 doc
: /* A number incremented each time this buffer is displayed in a window.
5958 The function `set-window-buffer' increments it. */);
5960 DEFVAR_PER_BUFFER ("buffer-display-time",
5961 &BVAR (current_buffer
, display_time
), Qnil
,
5962 doc
: /* Time stamp updated each time this buffer is displayed in a window.
5963 The function `set-window-buffer' updates this variable
5964 to the value obtained by calling `current-time'.
5965 If the buffer has never been shown in a window, the value is nil. */);
5967 DEFVAR_LISP ("transient-mark-mode", Vtransient_mark_mode
,
5968 doc
: /* Non-nil if Transient Mark mode is enabled.
5969 See the command `transient-mark-mode' for a description of this minor mode.
5971 Non-nil also enables highlighting of the region whenever the mark is active.
5972 The variable `highlight-nonselected-windows' controls whether to highlight
5973 all windows or just the selected window.
5975 Lisp programs may give this variable certain special values:
5977 - A value of `lambda' enables Transient Mark mode temporarily.
5978 It is disabled again after any subsequent action that would
5979 normally deactivate the mark (e.g. buffer modification).
5981 - A value of (only . OLDVAL) enables Transient Mark mode
5982 temporarily. After any subsequent point motion command that is
5983 not shift-translated, or any other action that would normally
5984 deactivate the mark (e.g. buffer modification), the value of
5985 `transient-mark-mode' is set to OLDVAL. */);
5986 Vtransient_mark_mode
= Qnil
;
5988 DEFVAR_LISP ("inhibit-read-only", Vinhibit_read_only
,
5989 doc
: /* Non-nil means disregard read-only status of buffers or characters.
5990 If the value is t, disregard `buffer-read-only' and all `read-only'
5991 text properties. If the value is a list, disregard `buffer-read-only'
5992 and disregard a `read-only' text property if the property value
5993 is a member of the list. */);
5994 Vinhibit_read_only
= Qnil
;
5996 DEFVAR_PER_BUFFER ("cursor-type", &BVAR (current_buffer
, cursor_type
), Qnil
,
5997 doc
: /* Cursor to use when this buffer is in the selected window.
5998 Values are interpreted as follows:
6000 t use the cursor specified for the frame
6001 nil don't display a cursor
6002 box display a filled box cursor
6003 hollow display a hollow box cursor
6004 bar display a vertical bar cursor with default width
6005 (bar . WIDTH) display a vertical bar cursor with width WIDTH
6006 hbar display a horizontal bar cursor with default height
6007 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
6008 ANYTHING ELSE display a hollow box cursor
6010 When the buffer is displayed in a non-selected window, the
6011 cursor's appearance is instead controlled by the variable
6012 `cursor-in-non-selected-windows'. */);
6014 DEFVAR_PER_BUFFER ("line-spacing",
6015 &BVAR (current_buffer
, extra_line_spacing
), Qnil
,
6016 doc
: /* Additional space to put between lines when displaying a buffer.
6017 The space is measured in pixels, and put below lines on graphic displays,
6018 see `display-graphic-p'.
6019 If value is a floating point number, it specifies the spacing relative
6020 to the default frame line height. A value of nil means add no extra space. */);
6022 DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
6023 &BVAR (current_buffer
, cursor_in_non_selected_windows
), Qnil
,
6024 doc
: /* Non-nil means show a cursor in non-selected windows.
6025 If nil, only shows a cursor in the selected window.
6026 If t, displays a cursor related to the usual cursor type
6027 \(a solid box becomes hollow, a bar becomes a narrower bar).
6028 You can also specify the cursor type as in the `cursor-type' variable.
6029 Use Custom to set this variable and update the display." */);
6031 DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions
,
6032 doc
: /* List of functions called with no args to query before killing a buffer.
6033 The buffer being killed will be current while the functions are running.
6035 If any of them returns nil, the buffer is not killed. Functions run by
6036 this hook are supposed to not change the current buffer. */);
6037 Vkill_buffer_query_functions
= Qnil
;
6039 DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook
,
6040 doc
: /* Normal hook run before changing the major mode of a buffer.
6041 The function `kill-all-local-variables' runs this before doing anything else. */);
6042 Vchange_major_mode_hook
= Qnil
;
6043 DEFSYM (Qchange_major_mode_hook
, "change-major-mode-hook");
6045 DEFVAR_LISP ("buffer-list-update-hook", Vbuffer_list_update_hook
,
6046 doc
: /* Hook run when the buffer list changes.
6047 Functions running this hook are `get-buffer-create',
6048 `make-indirect-buffer', `rename-buffer', `kill-buffer',
6049 and `bury-buffer-internal'. */);
6050 Vbuffer_list_update_hook
= Qnil
;
6051 DEFSYM (Qbuffer_list_update_hook
, "buffer-list-update-hook");
6053 defsubr (&Sbuffer_live_p
);
6054 defsubr (&Sbuffer_list
);
6055 defsubr (&Sget_buffer
);
6056 defsubr (&Sget_file_buffer
);
6057 defsubr (&Sget_buffer_create
);
6058 defsubr (&Smake_indirect_buffer
);
6059 defsubr (&Sgenerate_new_buffer_name
);
6060 defsubr (&Sbuffer_name
);
6061 defsubr (&Sbuffer_file_name
);
6062 defsubr (&Sbuffer_base_buffer
);
6063 defsubr (&Sbuffer_local_value
);
6064 defsubr (&Sbuffer_local_variables
);
6065 defsubr (&Sbuffer_modified_p
);
6066 defsubr (&Sset_buffer_modified_p
);
6067 defsubr (&Sbuffer_modified_tick
);
6068 defsubr (&Sbuffer_chars_modified_tick
);
6069 defsubr (&Srename_buffer
);
6070 defsubr (&Sother_buffer
);
6071 defsubr (&Sbuffer_enable_undo
);
6072 defsubr (&Skill_buffer
);
6073 defsubr (&Sbury_buffer_internal
);
6074 defsubr (&Sset_buffer_major_mode
);
6075 defsubr (&Scurrent_buffer
);
6076 defsubr (&Sset_buffer
);
6077 defsubr (&Sbarf_if_buffer_read_only
);
6078 defsubr (&Serase_buffer
);
6079 defsubr (&Sbuffer_swap_text
);
6080 defsubr (&Sset_buffer_multibyte
);
6081 defsubr (&Skill_all_local_variables
);
6083 defsubr (&Soverlayp
);
6084 defsubr (&Smake_overlay
);
6085 defsubr (&Sdelete_overlay
);
6086 defsubr (&Smove_overlay
);
6087 defsubr (&Soverlay_start
);
6088 defsubr (&Soverlay_end
);
6089 defsubr (&Soverlay_buffer
);
6090 defsubr (&Soverlay_properties
);
6091 defsubr (&Soverlays_at
);
6092 defsubr (&Soverlays_in
);
6093 defsubr (&Snext_overlay_change
);
6094 defsubr (&Sprevious_overlay_change
);
6095 defsubr (&Soverlay_recenter
);
6096 defsubr (&Soverlay_lists
);
6097 defsubr (&Soverlay_get
);
6098 defsubr (&Soverlay_put
);
6099 defsubr (&Srestore_buffer_modified_p
);
6103 keys_of_buffer (void)
6105 initial_define_key (control_x_map
, 'b', "switch-to-buffer");
6106 initial_define_key (control_x_map
, 'k', "kill-buffer");
6108 /* This must not be in syms_of_buffer, because Qdisabled is not
6109 initialized when that function gets called. */
6110 Fput (intern_c_string ("erase-buffer"), Qdisabled
, Qt
);