Commit | Line | Data |
---|---|---|
1ab256cb | 1 | /* Buffer manipulation primitives for GNU Emacs. |
3cb719bd | 2 | Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995 |
c922bc55 | 3 | Free Software Foundation, Inc. |
1ab256cb RM |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
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 | |
c922bc55 | 9 | the Free Software Foundation; either version 2, or (at your option) |
1ab256cb RM |
10 | any later version. |
11 | ||
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | ||
2381d133 JB |
22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | |
1ab256cb RM |
24 | #include <sys/param.h> |
25 | ||
26 | #ifndef MAXPATHLEN | |
27 | /* in 4.1, param.h fails to define this. */ | |
28 | #define MAXPATHLEN 1024 | |
29 | #endif /* not MAXPATHLEN */ | |
30 | ||
18160b98 | 31 | #include <config.h> |
1ab256cb | 32 | #include "lisp.h" |
21cf4cf8 | 33 | #include "intervals.h" |
1ab256cb RM |
34 | #include "window.h" |
35 | #include "commands.h" | |
36 | #include "buffer.h" | |
28e969dd | 37 | #include "region-cache.h" |
1ab256cb | 38 | #include "indent.h" |
d014bf88 | 39 | #include "blockinput.h" |
1ab256cb RM |
40 | |
41 | struct buffer *current_buffer; /* the current buffer */ | |
42 | ||
43 | /* First buffer in chain of all buffers (in reverse order of creation). | |
44 | Threaded through ->next. */ | |
45 | ||
46 | struct buffer *all_buffers; | |
47 | ||
48 | /* This structure holds the default values of the buffer-local variables | |
49 | defined with DEFVAR_PER_BUFFER, that have special slots in each buffer. | |
50 | The default value occupies the same slot in this structure | |
51 | as an individual buffer's value occupies in that buffer. | |
52 | Setting the default value also goes through the alist of buffers | |
53 | and stores into each buffer that does not say it has a local value. */ | |
54 | ||
55 | struct buffer buffer_defaults; | |
56 | ||
57 | /* A Lisp_Object pointer to the above, used for staticpro */ | |
58 | ||
59 | static Lisp_Object Vbuffer_defaults; | |
60 | ||
61 | /* This structure marks which slots in a buffer have corresponding | |
62 | default values in buffer_defaults. | |
63 | Each such slot has a nonzero value in this structure. | |
64 | The value has only one nonzero bit. | |
65 | ||
66 | When a buffer has its own local value for a slot, | |
67 | the bit for that slot (found in the same slot in this structure) | |
68 | is turned on in the buffer's local_var_flags slot. | |
69 | ||
70 | If a slot in this structure is -1, then even though there may | |
71 | be a DEFVAR_PER_BUFFER for the slot, there is no default value for it; | |
72 | and the corresponding slot in buffer_defaults is not used. | |
73 | ||
74 | If a slot is -2, then there is no DEFVAR_PER_BUFFER for it, | |
75 | but there is a default value which is copied into each buffer. | |
76 | ||
77 | If a slot in this structure is negative, then even though there may | |
78 | be a DEFVAR_PER_BUFFER for the slot, there is no default value for it; | |
79 | and the corresponding slot in buffer_defaults is not used. | |
80 | ||
81 | If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is | |
82 | zero, that is a bug */ | |
83 | ||
84 | struct buffer buffer_local_flags; | |
85 | ||
86 | /* This structure holds the names of symbols whose values may be | |
87 | buffer-local. It is indexed and accessed in the same way as the above. */ | |
88 | ||
89 | struct buffer buffer_local_symbols; | |
90 | /* A Lisp_Object pointer to the above, used for staticpro */ | |
91 | static Lisp_Object Vbuffer_local_symbols; | |
92 | ||
0fa3ba92 JB |
93 | /* This structure holds the required types for the values in the |
94 | buffer-local slots. If a slot contains Qnil, then the | |
95 | corresponding buffer slot may contain a value of any type. If a | |
96 | slot contains an integer, then prospective values' tags must be | |
97 | equal to that integer. When a tag does not match, the function | |
98 | buffer_slot_type_mismatch will signal an error. */ | |
99 | struct buffer buffer_local_types; | |
100 | ||
1ab256cb | 101 | Lisp_Object Fset_buffer (); |
01050cb5 | 102 | void set_buffer_internal (); |
173f2a64 | 103 | static void call_overlay_mod_hooks (); |
2f3f993b | 104 | static void swap_out_buffer_local_variables (); |
1ab256cb RM |
105 | |
106 | /* Alist of all buffer names vs the buffers. */ | |
107 | /* This used to be a variable, but is no longer, | |
108 | to prevent lossage due to user rplac'ing this alist or its elements. */ | |
109 | Lisp_Object Vbuffer_alist; | |
110 | ||
111 | /* Functions to call before and after each text change. */ | |
112 | Lisp_Object Vbefore_change_function; | |
113 | Lisp_Object Vafter_change_function; | |
5f079267 RS |
114 | Lisp_Object Vbefore_change_functions; |
115 | Lisp_Object Vafter_change_functions; | |
1ab256cb | 116 | |
c48f61ef RS |
117 | Lisp_Object Vtransient_mark_mode; |
118 | ||
a96b68f1 RS |
119 | /* t means ignore all read-only text properties. |
120 | A list means ignore such a property if its value is a member of the list. | |
121 | Any non-nil value means ignore buffer-read-only. */ | |
122 | Lisp_Object Vinhibit_read_only; | |
123 | ||
dcdffbf6 RS |
124 | /* List of functions to call that can query about killing a buffer. |
125 | If any of these functions returns nil, we don't kill it. */ | |
126 | Lisp_Object Vkill_buffer_query_functions; | |
127 | ||
dbc4e1c1 JB |
128 | /* List of functions to call before changing an unmodified buffer. */ |
129 | Lisp_Object Vfirst_change_hook; | |
130 | Lisp_Object Qfirst_change_hook; | |
1ab256cb RM |
131 | |
132 | Lisp_Object Qfundamental_mode, Qmode_class, Qpermanent_local; | |
133 | ||
134 | Lisp_Object Qprotected_field; | |
135 | ||
136 | Lisp_Object QSFundamental; /* A string "Fundamental" */ | |
137 | ||
138 | Lisp_Object Qkill_buffer_hook; | |
139 | ||
5fe0b67e RS |
140 | Lisp_Object Qget_file_buffer; |
141 | ||
52f8ec73 JB |
142 | Lisp_Object Qoverlayp; |
143 | ||
9d7608b7 | 144 | Lisp_Object Qpriority, Qwindow, Qevaporate; |
5985d248 | 145 | |
294d215f RS |
146 | Lisp_Object Qmodification_hooks; |
147 | Lisp_Object Qinsert_in_front_hooks; | |
148 | Lisp_Object Qinsert_behind_hooks; | |
149 | ||
1ab256cb RM |
150 | /* For debugging; temporary. See set_buffer_internal. */ |
151 | /* Lisp_Object Qlisp_mode, Vcheck_symbol; */ | |
152 | ||
153 | nsberror (spec) | |
154 | Lisp_Object spec; | |
155 | { | |
a7a60ce9 | 156 | if (STRINGP (spec)) |
1ab256cb RM |
157 | error ("No buffer named %s", XSTRING (spec)->data); |
158 | error ("Invalid buffer argument"); | |
159 | } | |
160 | \f | |
161 | DEFUN ("buffer-list", Fbuffer_list, Sbuffer_list, 0, 0, 0, | |
162 | "Return a list of all existing live buffers.") | |
163 | () | |
164 | { | |
165 | return Fmapcar (Qcdr, Vbuffer_alist); | |
166 | } | |
167 | ||
04ae1b48 RS |
168 | /* Like Fassoc, but use Fstring_equal to compare |
169 | (which ignores text properties), | |
170 | and don't ever QUIT. */ | |
171 | ||
172 | static Lisp_Object | |
173 | assoc_ignore_text_properties (key, list) | |
174 | register Lisp_Object key; | |
175 | Lisp_Object list; | |
176 | { | |
177 | register Lisp_Object tail; | |
178 | for (tail = list; !NILP (tail); tail = Fcdr (tail)) | |
179 | { | |
180 | register Lisp_Object elt, tem; | |
181 | elt = Fcar (tail); | |
182 | tem = Fstring_equal (Fcar (elt), key); | |
183 | if (!NILP (tem)) | |
184 | return elt; | |
185 | } | |
186 | return Qnil; | |
187 | } | |
188 | ||
1ab256cb RM |
189 | DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0, |
190 | "Return the buffer named NAME (a string).\n\ | |
191 | If there is no live buffer named NAME, return nil.\n\ | |
192 | NAME may also be a buffer; if so, the value is that buffer.") | |
193 | (name) | |
194 | register Lisp_Object name; | |
195 | { | |
a7a60ce9 | 196 | if (BUFFERP (name)) |
1ab256cb RM |
197 | return name; |
198 | CHECK_STRING (name, 0); | |
199 | ||
04ae1b48 | 200 | return Fcdr (assoc_ignore_text_properties (name, Vbuffer_alist)); |
1ab256cb RM |
201 | } |
202 | ||
203 | DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0, | |
204 | "Return the buffer visiting file FILENAME (a string).\n\ | |
92194d02 | 205 | The buffer's `buffer-file-name' must match exactly the expansion of FILENAME.\n\ |
11da5363 RS |
206 | If there is no such live buffer, return nil.\n\ |
207 | See also `find-buffer-visiting'.") | |
1ab256cb RM |
208 | (filename) |
209 | register Lisp_Object filename; | |
210 | { | |
211 | register Lisp_Object tail, buf, tem; | |
5fe0b67e RS |
212 | Lisp_Object handler; |
213 | ||
1ab256cb RM |
214 | CHECK_STRING (filename, 0); |
215 | filename = Fexpand_file_name (filename, Qnil); | |
216 | ||
5fe0b67e RS |
217 | /* If the file name has special constructs in it, |
218 | call the corresponding file handler. */ | |
a617e913 | 219 | handler = Ffind_file_name_handler (filename, Qget_file_buffer); |
5fe0b67e RS |
220 | if (!NILP (handler)) |
221 | return call2 (handler, Qget_file_buffer, filename); | |
222 | ||
1ab256cb RM |
223 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCONS (tail)->cdr) |
224 | { | |
225 | buf = Fcdr (XCONS (tail)->car); | |
a7a60ce9 KH |
226 | if (!BUFFERP (buf)) continue; |
227 | if (!STRINGP (XBUFFER (buf)->filename)) continue; | |
1ab256cb | 228 | tem = Fstring_equal (XBUFFER (buf)->filename, filename); |
265a9e55 | 229 | if (!NILP (tem)) |
1ab256cb RM |
230 | return buf; |
231 | } | |
232 | return Qnil; | |
233 | } | |
234 | ||
235 | /* Incremented for each buffer created, to assign the buffer number. */ | |
236 | int buffer_count; | |
237 | ||
238 | DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0, | |
239 | "Return the buffer named NAME, or create such a buffer and return it.\n\ | |
240 | A new buffer is created if there is no live buffer named NAME.\n\ | |
b44895bc | 241 | If NAME starts with a space, the new buffer does not keep undo information.\n\ |
1ab256cb RM |
242 | If NAME is a buffer instead of a string, then it is the value returned.\n\ |
243 | The value is never nil.") | |
244 | (name) | |
245 | register Lisp_Object name; | |
246 | { | |
a9ee7a59 | 247 | register Lisp_Object buf; |
1ab256cb RM |
248 | register struct buffer *b; |
249 | ||
250 | buf = Fget_buffer (name); | |
265a9e55 | 251 | if (!NILP (buf)) |
1ab256cb RM |
252 | return buf; |
253 | ||
31cd83e9 KH |
254 | if (XSTRING (name)->size == 0) |
255 | error ("Empty string for buffer name is not allowed"); | |
256 | ||
9ac0d9e0 | 257 | b = (struct buffer *) xmalloc (sizeof (struct buffer)); |
1ab256cb | 258 | |
336cd056 RS |
259 | b->size = sizeof (struct buffer) / sizeof (EMACS_INT); |
260 | ||
261 | /* An ordinary buffer uses its own struct buffer_text. */ | |
262 | b->text = &b->own_text; | |
263 | b->base_buffer = 0; | |
264 | ||
1ab256cb | 265 | BUF_GAP_SIZE (b) = 20; |
9ac0d9e0 | 266 | BLOCK_INPUT; |
1ab256cb | 267 | BUFFER_ALLOC (BUF_BEG_ADDR (b), BUF_GAP_SIZE (b)); |
9ac0d9e0 | 268 | UNBLOCK_INPUT; |
1ab256cb | 269 | if (! BUF_BEG_ADDR (b)) |
81841847 | 270 | buffer_memory_full (); |
1ab256cb RM |
271 | |
272 | BUF_PT (b) = 1; | |
273 | BUF_GPT (b) = 1; | |
274 | BUF_BEGV (b) = 1; | |
275 | BUF_ZV (b) = 1; | |
276 | BUF_Z (b) = 1; | |
277 | BUF_MODIFF (b) = 1; | |
336cd056 RS |
278 | BUF_SAVE_MODIFF (b) = 1; |
279 | BUF_INTERVALS (b) = 0; | |
1ab256cb | 280 | |
28e969dd JB |
281 | b->newline_cache = 0; |
282 | b->width_run_cache = 0; | |
283 | b->width_table = Qnil; | |
284 | ||
1ab256cb RM |
285 | /* Put this on the chain of all buffers including killed ones. */ |
286 | b->next = all_buffers; | |
287 | all_buffers = b; | |
288 | ||
336cd056 RS |
289 | /* An ordinary buffer normally doesn't need markers |
290 | to handle BEGV and ZV. */ | |
291 | b->pt_marker = Qnil; | |
292 | b->begv_marker = Qnil; | |
293 | b->zv_marker = Qnil; | |
04ae1b48 RS |
294 | |
295 | name = Fcopy_sequence (name); | |
296 | INITIALIZE_INTERVAL (XSTRING (name), NULL_INTERVAL); | |
1ab256cb | 297 | b->name = name; |
04ae1b48 | 298 | |
1ab256cb RM |
299 | if (XSTRING (name)->data[0] != ' ') |
300 | b->undo_list = Qnil; | |
301 | else | |
302 | b->undo_list = Qt; | |
303 | ||
304 | reset_buffer (b); | |
bcd40520 | 305 | reset_buffer_local_variables (b); |
1ab256cb RM |
306 | |
307 | /* Put this in the alist of all live buffers. */ | |
67180c6a | 308 | XSETBUFFER (buf, b); |
1ab256cb RM |
309 | Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil)); |
310 | ||
311 | b->mark = Fmake_marker (); | |
336cd056 RS |
312 | BUF_MARKERS (b) = Qnil; |
313 | b->name = name; | |
314 | return buf; | |
315 | } | |
316 | ||
317 | DEFUN ("make-indirect-buffer", | |
318 | Fmake_indirect_buffer, Smake_indirect_buffer, 2, 2, | |
9e552710 RS |
319 | "BMake indirect buffer (to buffer): \nbName of indirect buffer: ", |
320 | "Create and return an indirect buffer for buffer BASE, named NAME.\n\ | |
321 | BASE should be an existing buffer (or buffer name).\n\ | |
322 | NAME should be a string which is not the name of an existing buffer.") | |
323 | (base_buffer, name) | |
324 | register Lisp_Object base_buffer, name; | |
336cd056 RS |
325 | { |
326 | register Lisp_Object buf; | |
327 | register struct buffer *b; | |
328 | ||
329 | buf = Fget_buffer (name); | |
330 | if (!NILP (buf)) | |
331 | error ("Buffer name `%s' is in use", XSTRING (name)->data); | |
332 | ||
333 | base_buffer = Fget_buffer (base_buffer); | |
334 | if (NILP (base_buffer)) | |
335 | error ("No such buffer: `%s'", | |
336 | XSTRING (XBUFFER (base_buffer)->name)->data); | |
337 | ||
338 | if (XSTRING (name)->size == 0) | |
339 | error ("Empty string for buffer name is not allowed"); | |
340 | ||
341 | b = (struct buffer *) xmalloc (sizeof (struct buffer)); | |
342 | ||
343 | b->size = sizeof (struct buffer) / sizeof (EMACS_INT); | |
344 | ||
345 | if (XBUFFER (base_buffer)->base_buffer) | |
346 | b->base_buffer = XBUFFER (base_buffer)->base_buffer; | |
347 | else | |
348 | b->base_buffer = XBUFFER (base_buffer); | |
349 | ||
350 | /* Use the base buffer's text object. */ | |
351 | b->text = b->base_buffer->text; | |
352 | ||
353 | BUF_BEGV (b) = BUF_BEGV (b->base_buffer); | |
354 | BUF_ZV (b) = BUF_ZV (b->base_buffer); | |
355 | BUF_PT (b) = BUF_PT (b->base_buffer); | |
356 | ||
357 | b->newline_cache = 0; | |
358 | b->width_run_cache = 0; | |
359 | b->width_table = Qnil; | |
360 | ||
361 | /* Put this on the chain of all buffers including killed ones. */ | |
362 | b->next = all_buffers; | |
363 | all_buffers = b; | |
364 | ||
365 | name = Fcopy_sequence (name); | |
366 | INITIALIZE_INTERVAL (XSTRING (name), NULL_INTERVAL); | |
367 | b->name = name; | |
368 | ||
369 | reset_buffer (b); | |
370 | reset_buffer_local_variables (b); | |
371 | ||
372 | /* Put this in the alist of all live buffers. */ | |
373 | XSETBUFFER (buf, b); | |
374 | Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil)); | |
375 | ||
376 | b->mark = Fmake_marker (); | |
1ab256cb | 377 | b->name = name; |
336cd056 RS |
378 | |
379 | /* Make sure the base buffer has markers for its narrowing. */ | |
380 | if (NILP (b->base_buffer->pt_marker)) | |
381 | { | |
382 | b->base_buffer->pt_marker = Fmake_marker (); | |
383 | Fset_marker (b->base_buffer->pt_marker, | |
384 | make_number (BUF_PT (b->base_buffer)), base_buffer); | |
385 | } | |
386 | if (NILP (b->base_buffer->begv_marker)) | |
387 | { | |
388 | b->base_buffer->begv_marker = Fmake_marker (); | |
389 | Fset_marker (b->base_buffer->begv_marker, | |
390 | make_number (BUF_BEGV (b->base_buffer)), base_buffer); | |
391 | } | |
392 | if (NILP (b->base_buffer->zv_marker)) | |
393 | { | |
394 | b->base_buffer->zv_marker = Fmake_marker (); | |
395 | Fset_marker (b->base_buffer->zv_marker, | |
396 | make_number (BUF_ZV (b->base_buffer)), base_buffer); | |
397 | } | |
398 | ||
399 | /* Give the indirect buffer markers for its narrowing. */ | |
400 | b->pt_marker = Fpoint_marker (); | |
401 | b->begv_marker = Fpoint_min_marker (); | |
402 | b->zv_marker = Fpoint_max_marker (); | |
403 | ||
a9ee7a59 | 404 | return buf; |
1ab256cb RM |
405 | } |
406 | ||
bcd40520 RS |
407 | /* Reinitialize everything about a buffer except its name and contents |
408 | and local variables. */ | |
1ab256cb RM |
409 | |
410 | void | |
411 | reset_buffer (b) | |
412 | register struct buffer *b; | |
413 | { | |
414 | b->filename = Qnil; | |
f6ed2e84 | 415 | b->file_truename = Qnil; |
1ab256cb RM |
416 | b->directory = (current_buffer) ? current_buffer->directory : Qnil; |
417 | b->modtime = 0; | |
8d7a4592 | 418 | XSETFASTINT (b->save_length, 0); |
1ab256cb RM |
419 | b->last_window_start = 1; |
420 | b->backed_up = Qnil; | |
421 | b->auto_save_modified = 0; | |
84f6bcba | 422 | b->auto_save_failure_time = -1; |
1ab256cb RM |
423 | b->auto_save_file_name = Qnil; |
424 | b->read_only = Qnil; | |
2eec3b4e RS |
425 | b->overlays_before = Qnil; |
426 | b->overlays_after = Qnil; | |
8d7a4592 | 427 | XSETFASTINT (b->overlay_center, 1); |
dfda7a7f | 428 | b->mark_active = Qnil; |
943e065b | 429 | b->point_before_scroll = Qnil; |
be9aafdd | 430 | b->file_format = Qnil; |
1ab256cb RM |
431 | } |
432 | ||
bcd40520 RS |
433 | /* Reset buffer B's local variables info. |
434 | Don't use this on a buffer that has already been in use; | |
435 | it does not treat permanent locals consistently. | |
436 | Instead, use Fkill_all_local_variables. */ | |
437 | ||
c48f61ef | 438 | reset_buffer_local_variables (b) |
1ab256cb RM |
439 | register struct buffer *b; |
440 | { | |
441 | register int offset; | |
442 | ||
443 | /* Reset the major mode to Fundamental, together with all the | |
444 | things that depend on the major mode. | |
445 | default-major-mode is handled at a higher level. | |
446 | We ignore it here. */ | |
447 | b->major_mode = Qfundamental_mode; | |
448 | b->keymap = Qnil; | |
449 | b->abbrev_table = Vfundamental_mode_abbrev_table; | |
450 | b->mode_name = QSFundamental; | |
451 | b->minor_modes = Qnil; | |
452 | b->downcase_table = Vascii_downcase_table; | |
453 | b->upcase_table = Vascii_upcase_table; | |
e9edf33c RS |
454 | b->case_canon_table = Vascii_canon_table; |
455 | b->case_eqv_table = Vascii_eqv_table; | |
336cd056 | 456 | b->buffer_file_type = Qnil; |
3cb719bd RS |
457 | b->invisibility_spec = Qt; |
458 | ||
1ab256cb RM |
459 | #if 0 |
460 | b->sort_table = XSTRING (Vascii_sort_table); | |
461 | b->folding_sort_table = XSTRING (Vascii_folding_sort_table); | |
462 | #endif /* 0 */ | |
463 | ||
464 | /* Reset all per-buffer variables to their defaults. */ | |
465 | b->local_var_alist = Qnil; | |
466 | b->local_var_flags = 0; | |
467 | ||
468 | /* For each slot that has a default value, | |
469 | copy that into the slot. */ | |
470 | ||
471 | for (offset = (char *)&buffer_local_flags.name - (char *)&buffer_local_flags; | |
472 | offset < sizeof (struct buffer); | |
4d2f1389 | 473 | offset += sizeof (Lisp_Object)) /* sizeof EMACS_INT == sizeof Lisp_Object */ |
aab80822 KH |
474 | { |
475 | int flag = XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags)); | |
476 | if (flag > 0 || flag == -2) | |
477 | *(Lisp_Object *)(offset + (char *)b) = | |
478 | *(Lisp_Object *)(offset + (char *)&buffer_defaults); | |
479 | } | |
1ab256cb RM |
480 | } |
481 | ||
01050cb5 RM |
482 | /* We split this away from generate-new-buffer, because rename-buffer |
483 | and set-visited-file-name ought to be able to use this to really | |
484 | rename the buffer properly. */ | |
485 | ||
486 | DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, Sgenerate_new_buffer_name, | |
c273e647 | 487 | 1, 2, 0, |
01050cb5 RM |
488 | "Return a string that is the name of no existing buffer based on NAME.\n\ |
489 | If there is no live buffer named NAME, then return NAME.\n\ | |
1ab256cb | 490 | Otherwise modify name by appending `<NUMBER>', incrementing NUMBER\n\ |
c273e647 | 491 | until an unused name is found, and then return that name.\n\ |
03bdd54c | 492 | Optional second argument IGNORE specifies a name that is okay to use\n\ |
c273e647 | 493 | \(if it is in the sequence to be tried)\n\ |
e8b3a22d | 494 | even if a buffer with that name exists.") |
c273e647 RS |
495 | (name, ignore) |
496 | register Lisp_Object name, ignore; | |
1ab256cb RM |
497 | { |
498 | register Lisp_Object gentemp, tem; | |
499 | int count; | |
500 | char number[10]; | |
501 | ||
502 | CHECK_STRING (name, 0); | |
503 | ||
504 | tem = Fget_buffer (name); | |
265a9e55 | 505 | if (NILP (tem)) |
01050cb5 | 506 | return name; |
1ab256cb RM |
507 | |
508 | count = 1; | |
509 | while (1) | |
510 | { | |
511 | sprintf (number, "<%d>", ++count); | |
512 | gentemp = concat2 (name, build_string (number)); | |
638e4fc3 | 513 | tem = Fstring_equal (gentemp, ignore); |
c273e647 RS |
514 | if (!NILP (tem)) |
515 | return gentemp; | |
1ab256cb | 516 | tem = Fget_buffer (gentemp); |
265a9e55 | 517 | if (NILP (tem)) |
01050cb5 | 518 | return gentemp; |
1ab256cb RM |
519 | } |
520 | } | |
521 | ||
522 | \f | |
523 | DEFUN ("buffer-name", Fbuffer_name, Sbuffer_name, 0, 1, 0, | |
524 | "Return the name of BUFFER, as a string.\n\ | |
01050cb5 | 525 | With no argument or nil as argument, return the name of the current buffer.") |
1ab256cb RM |
526 | (buffer) |
527 | register Lisp_Object buffer; | |
528 | { | |
265a9e55 | 529 | if (NILP (buffer)) |
1ab256cb RM |
530 | return current_buffer->name; |
531 | CHECK_BUFFER (buffer, 0); | |
532 | return XBUFFER (buffer)->name; | |
533 | } | |
534 | ||
535 | DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0, | |
536 | "Return name of file BUFFER is visiting, or nil if none.\n\ | |
537 | No argument or nil as argument means use the current buffer.") | |
538 | (buffer) | |
539 | register Lisp_Object buffer; | |
540 | { | |
265a9e55 | 541 | if (NILP (buffer)) |
1ab256cb RM |
542 | return current_buffer->filename; |
543 | CHECK_BUFFER (buffer, 0); | |
544 | return XBUFFER (buffer)->filename; | |
545 | } | |
546 | ||
336cd056 RS |
547 | DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, Sbuffer_base_buffer, |
548 | 0, 1, 0, | |
549 | "Return the base buffer of indirect buffer BUFFER.\n\ | |
550 | If BUFFER is not indirect, return nil.") | |
551 | (buffer) | |
552 | register Lisp_Object buffer; | |
553 | { | |
554 | struct buffer *base; | |
555 | Lisp_Object base_buffer; | |
556 | ||
557 | if (NILP (buffer)) | |
558 | base = current_buffer->base_buffer; | |
559 | else | |
560 | { | |
561 | CHECK_BUFFER (buffer, 0); | |
562 | base = XBUFFER (buffer)->base_buffer; | |
563 | } | |
564 | ||
565 | if (! base) | |
566 | return Qnil; | |
567 | XSETBUFFER (base_buffer, base); | |
568 | return base_buffer; | |
569 | } | |
570 | ||
1ab256cb RM |
571 | DEFUN ("buffer-local-variables", Fbuffer_local_variables, |
572 | Sbuffer_local_variables, 0, 1, 0, | |
573 | "Return an alist of variables that are buffer-local in BUFFER.\n\ | |
553defa4 RS |
574 | Most elements look like (SYMBOL . VALUE), describing one variable.\n\ |
575 | For a symbol that is locally unbound, just the symbol appears in the value.\n\ | |
1ab256cb RM |
576 | Note that storing new VALUEs in these elements doesn't change the variables.\n\ |
577 | No argument or nil as argument means use current buffer as BUFFER.") | |
578 | (buffer) | |
579 | register Lisp_Object buffer; | |
580 | { | |
581 | register struct buffer *buf; | |
553defa4 | 582 | register Lisp_Object result; |
1ab256cb | 583 | |
265a9e55 | 584 | if (NILP (buffer)) |
1ab256cb RM |
585 | buf = current_buffer; |
586 | else | |
587 | { | |
588 | CHECK_BUFFER (buffer, 0); | |
589 | buf = XBUFFER (buffer); | |
590 | } | |
591 | ||
553defa4 RS |
592 | result = Qnil; |
593 | ||
1ab256cb | 594 | { |
553defa4 RS |
595 | register Lisp_Object tail; |
596 | for (tail = buf->local_var_alist; CONSP (tail); tail = XCONS (tail)->cdr) | |
1ab256cb | 597 | { |
553defa4 RS |
598 | Lisp_Object val, elt; |
599 | ||
600 | elt = XCONS (tail)->car; | |
601 | ||
e0585c64 RS |
602 | /* Reference each variable in the alist in buf. |
603 | If inquiring about the current buffer, this gets the current values, | |
604 | so store them into the alist so the alist is up to date. | |
605 | If inquiring about some other buffer, this swaps out any values | |
606 | for that buffer, making the alist up to date automatically. */ | |
607 | val = find_symbol_value (XCONS (elt)->car); | |
608 | /* Use the current buffer value only if buf is the current buffer. */ | |
609 | if (buf != current_buffer) | |
553defa4 RS |
610 | val = XCONS (elt)->cdr; |
611 | ||
612 | /* If symbol is unbound, put just the symbol in the list. */ | |
613 | if (EQ (val, Qunbound)) | |
614 | result = Fcons (XCONS (elt)->car, result); | |
615 | /* Otherwise, put (symbol . value) in the list. */ | |
616 | else | |
617 | result = Fcons (Fcons (XCONS (elt)->car, val), result); | |
1ab256cb RM |
618 | } |
619 | } | |
620 | ||
1ab256cb RM |
621 | /* Add on all the variables stored in special slots. */ |
622 | { | |
623 | register int offset, mask; | |
624 | ||
625 | for (offset = (char *)&buffer_local_symbols.name - (char *)&buffer_local_symbols; | |
626 | offset < sizeof (struct buffer); | |
4d2f1389 | 627 | offset += (sizeof (EMACS_INT))) /* sizeof EMACS_INT == sizeof Lisp_Object */ |
1ab256cb | 628 | { |
aab80822 | 629 | mask = XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags)); |
1ab256cb | 630 | if (mask == -1 || (buf->local_var_flags & mask)) |
aab80822 KH |
631 | if (SYMBOLP (*(Lisp_Object *)(offset |
632 | + (char *)&buffer_local_symbols))) | |
633 | result = Fcons (Fcons (*((Lisp_Object *) | |
634 | (offset + (char *)&buffer_local_symbols)), | |
553defa4 RS |
635 | *(Lisp_Object *)(offset + (char *)buf)), |
636 | result); | |
1ab256cb RM |
637 | } |
638 | } | |
553defa4 RS |
639 | |
640 | return result; | |
1ab256cb RM |
641 | } |
642 | ||
643 | \f | |
644 | DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, | |
645 | 0, 1, 0, | |
646 | "Return t if BUFFER was modified since its file was last read or saved.\n\ | |
647 | No argument or nil as argument means use current buffer as BUFFER.") | |
648 | (buffer) | |
649 | register Lisp_Object buffer; | |
650 | { | |
651 | register struct buffer *buf; | |
265a9e55 | 652 | if (NILP (buffer)) |
1ab256cb RM |
653 | buf = current_buffer; |
654 | else | |
655 | { | |
656 | CHECK_BUFFER (buffer, 0); | |
657 | buf = XBUFFER (buffer); | |
658 | } | |
659 | ||
336cd056 | 660 | return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; |
1ab256cb RM |
661 | } |
662 | ||
663 | DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p, | |
664 | 1, 1, 0, | |
665 | "Mark current buffer as modified or unmodified according to FLAG.\n\ | |
666 | A non-nil FLAG means mark the buffer modified.") | |
667 | (flag) | |
668 | register Lisp_Object flag; | |
669 | { | |
670 | register int already; | |
671 | register Lisp_Object fn; | |
672 | ||
673 | #ifdef CLASH_DETECTION | |
674 | /* If buffer becoming modified, lock the file. | |
675 | If buffer becoming unmodified, unlock the file. */ | |
676 | ||
677 | fn = current_buffer->filename; | |
265a9e55 | 678 | if (!NILP (fn)) |
1ab256cb | 679 | { |
336cd056 | 680 | already = SAVE_MODIFF < MODIFF; |
265a9e55 | 681 | if (!already && !NILP (flag)) |
1ab256cb | 682 | lock_file (fn); |
265a9e55 | 683 | else if (already && NILP (flag)) |
1ab256cb RM |
684 | unlock_file (fn); |
685 | } | |
686 | #endif /* CLASH_DETECTION */ | |
687 | ||
336cd056 | 688 | SAVE_MODIFF = NILP (flag) ? MODIFF : 0; |
1ab256cb RM |
689 | update_mode_lines++; |
690 | return flag; | |
691 | } | |
692 | ||
693 | DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, Sbuffer_modified_tick, | |
694 | 0, 1, 0, | |
695 | "Return BUFFER's tick counter, incremented for each change in text.\n\ | |
696 | Each buffer has a tick counter which is incremented each time the text in\n\ | |
697 | that buffer is changed. It wraps around occasionally.\n\ | |
698 | No argument or nil as argument means use current buffer as BUFFER.") | |
699 | (buffer) | |
700 | register Lisp_Object buffer; | |
701 | { | |
702 | register struct buffer *buf; | |
265a9e55 | 703 | if (NILP (buffer)) |
1ab256cb RM |
704 | buf = current_buffer; |
705 | else | |
706 | { | |
707 | CHECK_BUFFER (buffer, 0); | |
708 | buf = XBUFFER (buffer); | |
709 | } | |
710 | ||
711 | return make_number (BUF_MODIFF (buf)); | |
712 | } | |
713 | \f | |
01050cb5 | 714 | DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2, |
4c7e5f09 | 715 | "sRename buffer (to new name): \nP", |
1ab256cb | 716 | "Change current buffer's name to NEWNAME (a string).\n\ |
3bd779aa | 717 | If second arg UNIQUE is nil or omitted, it is an error if a\n\ |
01050cb5 | 718 | buffer named NEWNAME already exists.\n\ |
3bd779aa | 719 | If UNIQUE is non-nil, come up with a new name using\n\ |
01050cb5 | 720 | `generate-new-buffer-name'.\n\ |
3bd779aa RS |
721 | Interactively, you can set UNIQUE with a prefix argument.\n\ |
722 | We return the name we actually gave the buffer.\n\ | |
1ab256cb | 723 | This does not change the name of the visited file (if any).") |
489c043a RS |
724 | (newname, unique) |
725 | register Lisp_Object newname, unique; | |
1ab256cb RM |
726 | { |
727 | register Lisp_Object tem, buf; | |
728 | ||
489c043a | 729 | CHECK_STRING (newname, 0); |
d59698c4 | 730 | |
489c043a | 731 | if (XSTRING (newname)->size == 0) |
d59698c4 RS |
732 | error ("Empty string is invalid as a buffer name"); |
733 | ||
489c043a | 734 | tem = Fget_buffer (newname); |
c059b5ea RM |
735 | /* Don't short-circuit if UNIQUE is t. That is a useful way to rename |
736 | the buffer automatically so you can create another with the original name. | |
737 | It makes UNIQUE equivalent to | |
489c043a | 738 | (rename-buffer (generate-new-buffer-name NEWNAME)). */ |
c059b5ea | 739 | if (NILP (unique) && XBUFFER (tem) == current_buffer) |
fb5eba9c | 740 | return current_buffer->name; |
265a9e55 | 741 | if (!NILP (tem)) |
01050cb5 | 742 | { |
3bd779aa | 743 | if (!NILP (unique)) |
489c043a | 744 | newname = Fgenerate_new_buffer_name (newname, current_buffer->name); |
01050cb5 | 745 | else |
489c043a | 746 | error ("Buffer name `%s' is in use", XSTRING (newname)->data); |
01050cb5 | 747 | } |
1ab256cb | 748 | |
489c043a | 749 | current_buffer->name = newname; |
76f590d7 JB |
750 | |
751 | /* Catch redisplay's attention. Unless we do this, the mode lines for | |
752 | any windows displaying current_buffer will stay unchanged. */ | |
753 | update_mode_lines++; | |
754 | ||
67180c6a | 755 | XSETBUFFER (buf, current_buffer); |
489c043a | 756 | Fsetcar (Frassq (buf, Vbuffer_alist), newname); |
cf058e49 KH |
757 | if (NILP (current_buffer->filename) |
758 | && !NILP (current_buffer->auto_save_file_name)) | |
1ab256cb | 759 | call0 (intern ("rename-auto-save-file")); |
fb5eba9c RS |
760 | /* Refetch since that last call may have done GC. */ |
761 | return current_buffer->name; | |
1ab256cb RM |
762 | } |
763 | ||
a0ebb746 | 764 | DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 2, 0, |
1ab256cb | 765 | "Return most recently selected buffer other than BUFFER.\n\ |
a0ebb746 JB |
766 | Buffers not visible in windows are preferred to visible buffers,\n\ |
767 | unless optional second argument VISIBLE-OK is non-nil.\n\ | |
1ab256cb RM |
768 | If no other buffer exists, the buffer `*scratch*' is returned.\n\ |
769 | If BUFFER is omitted or nil, some interesting buffer is returned.") | |
a0ebb746 JB |
770 | (buffer, visible_ok) |
771 | register Lisp_Object buffer, visible_ok; | |
1ab256cb RM |
772 | { |
773 | register Lisp_Object tail, buf, notsogood, tem; | |
774 | notsogood = Qnil; | |
775 | ||
265a9e55 | 776 | for (tail = Vbuffer_alist; !NILP (tail); tail = Fcdr (tail)) |
1ab256cb RM |
777 | { |
778 | buf = Fcdr (Fcar (tail)); | |
779 | if (EQ (buf, buffer)) | |
780 | continue; | |
781 | if (XSTRING (XBUFFER (buf)->name)->data[0] == ' ') | |
782 | continue; | |
04ae1b48 RS |
783 | #ifdef MULTI_FRAME |
784 | /* If the selected frame has a buffer_predicate, | |
785 | disregard buffers that don't fit the predicate. */ | |
786 | tem = frame_buffer_predicate (); | |
787 | if (!NILP (tem)) | |
788 | { | |
789 | tem = call1 (tem, buf); | |
790 | if (NILP (tem)) | |
791 | continue; | |
792 | } | |
793 | #endif | |
794 | ||
a0ebb746 | 795 | if (NILP (visible_ok)) |
db732e5a | 796 | tem = Fget_buffer_window (buf, Qt); |
a0ebb746 JB |
797 | else |
798 | tem = Qnil; | |
265a9e55 | 799 | if (NILP (tem)) |
1ab256cb | 800 | return buf; |
265a9e55 | 801 | if (NILP (notsogood)) |
1ab256cb RM |
802 | notsogood = buf; |
803 | } | |
265a9e55 | 804 | if (!NILP (notsogood)) |
1ab256cb RM |
805 | return notsogood; |
806 | return Fget_buffer_create (build_string ("*scratch*")); | |
807 | } | |
808 | \f | |
5b8bcf48 | 809 | DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, Sbuffer_disable_undo, 0, 1, |
1ab256cb | 810 | 0, |
5b8bcf48 RS |
811 | "Make BUFFER stop keeping undo information.\n\ |
812 | No argument or nil as argument means do this for the current buffer.") | |
ffd56f97 JB |
813 | (buffer) |
814 | register Lisp_Object buffer; | |
1ab256cb | 815 | { |
ffd56f97 JB |
816 | Lisp_Object real_buffer; |
817 | ||
818 | if (NILP (buffer)) | |
67180c6a | 819 | XSETBUFFER (real_buffer, current_buffer); |
ffd56f97 JB |
820 | else |
821 | { | |
822 | real_buffer = Fget_buffer (buffer); | |
823 | if (NILP (real_buffer)) | |
824 | nsberror (buffer); | |
825 | } | |
826 | ||
827 | XBUFFER (real_buffer)->undo_list = Qt; | |
828 | ||
1ab256cb RM |
829 | return Qnil; |
830 | } | |
831 | ||
832 | DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo, | |
833 | 0, 1, "", | |
834 | "Start keeping undo information for buffer BUFFER.\n\ | |
835 | No argument or nil as argument means do this for the current buffer.") | |
ffd56f97 JB |
836 | (buffer) |
837 | register Lisp_Object buffer; | |
1ab256cb | 838 | { |
ffd56f97 | 839 | Lisp_Object real_buffer; |
1ab256cb | 840 | |
ffd56f97 | 841 | if (NILP (buffer)) |
67180c6a | 842 | XSETBUFFER (real_buffer, current_buffer); |
1ab256cb RM |
843 | else |
844 | { | |
ffd56f97 JB |
845 | real_buffer = Fget_buffer (buffer); |
846 | if (NILP (real_buffer)) | |
847 | nsberror (buffer); | |
1ab256cb RM |
848 | } |
849 | ||
ffd56f97 JB |
850 | if (EQ (XBUFFER (real_buffer)->undo_list, Qt)) |
851 | XBUFFER (real_buffer)->undo_list = Qnil; | |
1ab256cb RM |
852 | |
853 | return Qnil; | |
854 | } | |
855 | ||
856 | /* | |
857 | DEFVAR_LISP ("kill-buffer-hook", no_cell, "\ | |
858 | Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\ | |
859 | The buffer being killed will be current while the hook is running.\n\ | |
860 | See `kill-buffer'." | |
861 | */ | |
862 | DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ", | |
863 | "Kill the buffer BUFFER.\n\ | |
864 | The argument may be a buffer or may be the name of a buffer.\n\ | |
865 | An argument of nil means kill the current buffer.\n\n\ | |
866 | Value is t if the buffer is actually killed, nil if user says no.\n\n\ | |
867 | The value of `kill-buffer-hook' (which may be local to that buffer),\n\ | |
868 | if not void, is a list of functions to be called, with no arguments,\n\ | |
869 | before the buffer is actually killed. The buffer to be killed is current\n\ | |
870 | when the hook functions are called.\n\n\ | |
871 | Any processes that have this buffer as the `process-buffer' are killed\n\ | |
872 | with `delete-process'.") | |
873 | (bufname) | |
874 | Lisp_Object bufname; | |
875 | { | |
876 | Lisp_Object buf; | |
877 | register struct buffer *b; | |
878 | register Lisp_Object tem; | |
879 | register struct Lisp_Marker *m; | |
880 | struct gcpro gcpro1, gcpro2; | |
881 | ||
265a9e55 | 882 | if (NILP (bufname)) |
1ab256cb RM |
883 | buf = Fcurrent_buffer (); |
884 | else | |
885 | buf = Fget_buffer (bufname); | |
265a9e55 | 886 | if (NILP (buf)) |
1ab256cb RM |
887 | nsberror (bufname); |
888 | ||
889 | b = XBUFFER (buf); | |
890 | ||
891 | /* Query if the buffer is still modified. */ | |
265a9e55 | 892 | if (INTERACTIVE && !NILP (b->filename) |
336cd056 | 893 | && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) |
1ab256cb RM |
894 | { |
895 | GCPRO2 (buf, bufname); | |
896 | tem = do_yes_or_no_p (format1 ("Buffer %s modified; kill anyway? ", | |
897 | XSTRING (b->name)->data)); | |
898 | UNGCPRO; | |
265a9e55 | 899 | if (NILP (tem)) |
1ab256cb RM |
900 | return Qnil; |
901 | } | |
902 | ||
dcdffbf6 | 903 | /* Run hooks with the buffer to be killed the current buffer. */ |
1ab256cb RM |
904 | { |
905 | register Lisp_Object val; | |
906 | int count = specpdl_ptr - specpdl; | |
dcdffbf6 | 907 | Lisp_Object list; |
1ab256cb RM |
908 | |
909 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
910 | set_buffer_internal (b); | |
dcdffbf6 RS |
911 | |
912 | /* First run the query functions; if any query is answered no, | |
913 | don't kill the buffer. */ | |
914 | for (list = Vkill_buffer_query_functions; !NILP (list); list = Fcdr (list)) | |
915 | { | |
916 | tem = call0 (Fcar (list)); | |
917 | if (NILP (tem)) | |
918 | return unbind_to (count, Qnil); | |
919 | } | |
920 | ||
921 | /* Then run the hooks. */ | |
fd186f07 RS |
922 | if (!NILP (Vrun_hooks)) |
923 | call1 (Vrun_hooks, Qkill_buffer_hook); | |
1ab256cb RM |
924 | unbind_to (count, Qnil); |
925 | } | |
926 | ||
927 | /* We have no more questions to ask. Verify that it is valid | |
928 | to kill the buffer. This must be done after the questions | |
929 | since anything can happen within do_yes_or_no_p. */ | |
930 | ||
931 | /* Don't kill the minibuffer now current. */ | |
932 | if (EQ (buf, XWINDOW (minibuf_window)->buffer)) | |
933 | return Qnil; | |
934 | ||
265a9e55 | 935 | if (NILP (b->name)) |
1ab256cb RM |
936 | return Qnil; |
937 | ||
336cd056 RS |
938 | /* When we kill a base buffer, kill all its indirect buffers. |
939 | We do it at this stage so nothing terrible happens if they | |
940 | ask questions or their hooks get errors. */ | |
941 | if (! b->base_buffer) | |
942 | { | |
943 | struct buffer *other; | |
944 | ||
945 | GCPRO1 (buf); | |
946 | ||
947 | for (other = all_buffers; other; other = other->next) | |
948 | if (other->base_buffer == b) | |
949 | { | |
950 | Lisp_Object buf; | |
951 | XSETBUFFER (buf, other); | |
952 | Fkill_buffer (buf); | |
953 | } | |
954 | ||
955 | UNGCPRO; | |
956 | } | |
957 | ||
1ab256cb RM |
958 | /* Make this buffer not be current. |
959 | In the process, notice if this is the sole visible buffer | |
960 | and give up if so. */ | |
961 | if (b == current_buffer) | |
962 | { | |
172a9c1f | 963 | tem = Fother_buffer (buf, Qnil); |
1ab256cb RM |
964 | Fset_buffer (tem); |
965 | if (b == current_buffer) | |
966 | return Qnil; | |
967 | } | |
968 | ||
969 | /* Now there is no question: we can kill the buffer. */ | |
970 | ||
971 | #ifdef CLASH_DETECTION | |
972 | /* Unlock this buffer's file, if it is locked. */ | |
973 | unlock_buffer (b); | |
974 | #endif /* CLASH_DETECTION */ | |
975 | ||
1ab256cb | 976 | kill_buffer_processes (buf); |
1ab256cb RM |
977 | |
978 | tem = Vinhibit_quit; | |
979 | Vinhibit_quit = Qt; | |
980 | Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist); | |
981 | Freplace_buffer_in_windows (buf); | |
982 | Vinhibit_quit = tem; | |
983 | ||
9b59d6d0 | 984 | /* Delete any auto-save file, if we saved it in this session. */ |
a7a60ce9 | 985 | if (STRINGP (b->auto_save_file_name) |
9b59d6d0 | 986 | && b->auto_save_modified != 0) |
1ab256cb RM |
987 | { |
988 | Lisp_Object tem; | |
989 | tem = Fsymbol_value (intern ("delete-auto-save-files")); | |
265a9e55 | 990 | if (! NILP (tem)) |
cbb6a418 | 991 | internal_delete_file (b->auto_save_file_name); |
1ab256cb RM |
992 | } |
993 | ||
336cd056 | 994 | if (! b->base_buffer) |
1ab256cb | 995 | { |
336cd056 RS |
996 | /* Unchain all markers of this buffer |
997 | and leave them pointing nowhere. */ | |
998 | for (tem = BUF_MARKERS (b); !EQ (tem, Qnil); ) | |
999 | { | |
1000 | m = XMARKER (tem); | |
1001 | m->buffer = 0; | |
1002 | tem = m->chain; | |
1003 | m->chain = Qnil; | |
1004 | } | |
1005 | BUF_MARKERS (b) = Qnil; | |
1ab256cb | 1006 | |
336cd056 RS |
1007 | #ifdef USE_TEXT_PROPERTIES |
1008 | BUF_INTERVALS (b) = NULL_INTERVAL; | |
1009 | #endif | |
1010 | ||
1011 | /* Perhaps we should explicitly free the interval tree here... */ | |
1012 | } | |
33f7013e | 1013 | |
2f3f993b RS |
1014 | /* Reset the local variables, so that this buffer's local values |
1015 | won't be protected from GC. They would be protected | |
1016 | if they happened to remain encached in their symbols. | |
1017 | This gets rid of them for certain. */ | |
1018 | swap_out_buffer_local_variables (b); | |
1019 | reset_buffer_local_variables (b); | |
1020 | ||
1ab256cb | 1021 | b->name = Qnil; |
336cd056 | 1022 | |
9ac0d9e0 | 1023 | BLOCK_INPUT; |
336cd056 RS |
1024 | if (! b->base_buffer) |
1025 | BUFFER_FREE (BUF_BEG_ADDR (b)); | |
1026 | ||
28e969dd JB |
1027 | if (b->newline_cache) |
1028 | { | |
1029 | free_region_cache (b->newline_cache); | |
1030 | b->newline_cache = 0; | |
1031 | } | |
1032 | if (b->width_run_cache) | |
1033 | { | |
1034 | free_region_cache (b->width_run_cache); | |
1035 | b->width_run_cache = 0; | |
1036 | } | |
1037 | b->width_table = Qnil; | |
9ac0d9e0 | 1038 | UNBLOCK_INPUT; |
1ab256cb RM |
1039 | b->undo_list = Qnil; |
1040 | ||
1041 | return Qt; | |
1042 | } | |
1043 | \f | |
36a8c287 JB |
1044 | /* Move the assoc for buffer BUF to the front of buffer-alist. Since |
1045 | we do this each time BUF is selected visibly, the more recently | |
1046 | selected buffers are always closer to the front of the list. This | |
1047 | means that other_buffer is more likely to choose a relevant buffer. */ | |
1ab256cb RM |
1048 | |
1049 | record_buffer (buf) | |
1050 | Lisp_Object buf; | |
1051 | { | |
1052 | register Lisp_Object link, prev; | |
1053 | ||
1054 | prev = Qnil; | |
1055 | for (link = Vbuffer_alist; CONSP (link); link = XCONS (link)->cdr) | |
1056 | { | |
1057 | if (EQ (XCONS (XCONS (link)->car)->cdr, buf)) | |
1058 | break; | |
1059 | prev = link; | |
1060 | } | |
1061 | ||
36a8c287 JB |
1062 | /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist); |
1063 | we cannot use Fdelq itself here because it allows quitting. */ | |
1ab256cb | 1064 | |
265a9e55 | 1065 | if (NILP (prev)) |
1ab256cb RM |
1066 | Vbuffer_alist = XCONS (Vbuffer_alist)->cdr; |
1067 | else | |
1068 | XCONS (prev)->cdr = XCONS (XCONS (prev)->cdr)->cdr; | |
1069 | ||
1070 | XCONS(link)->cdr = Vbuffer_alist; | |
1071 | Vbuffer_alist = link; | |
1072 | } | |
1073 | ||
a9ee7a59 KH |
1074 | DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0, |
1075 | "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\ | |
1076 | Use this function before selecting the buffer, since it may need to inspect\n\ | |
1077 | the current buffer's major mode.") | |
1078 | (buf) | |
1079 | Lisp_Object buf; | |
1080 | { | |
1081 | int count; | |
1082 | Lisp_Object function; | |
1083 | ||
1084 | function = buffer_defaults.major_mode; | |
1085 | if (NILP (function) && NILP (Fget (current_buffer->major_mode, Qmode_class))) | |
1086 | function = current_buffer->major_mode; | |
1087 | ||
1088 | if (NILP (function) || EQ (function, Qfundamental_mode)) | |
1089 | return Qnil; | |
1090 | ||
1091 | count = specpdl_ptr - specpdl; | |
1092 | ||
1093 | /* To select a nonfundamental mode, | |
1094 | select the buffer temporarily and then call the mode function. */ | |
1095 | ||
1096 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
1097 | ||
1098 | Fset_buffer (buf); | |
1099 | call0 (function); | |
1100 | ||
1101 | return unbind_to (count, Qnil); | |
1102 | } | |
1103 | ||
1ab256cb RM |
1104 | DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ", |
1105 | "Select buffer BUFFER in the current window.\n\ | |
1106 | BUFFER may be a buffer or a buffer name.\n\ | |
1107 | Optional second arg NORECORD non-nil means\n\ | |
1108 | do not put this buffer at the front of the list of recently selected ones.\n\ | |
1109 | \n\ | |
1110 | WARNING: This is NOT the way to work on another buffer temporarily\n\ | |
1111 | within a Lisp program! Use `set-buffer' instead. That avoids messing with\n\ | |
1112 | the window-buffer correspondences.") | |
1113 | (bufname, norecord) | |
1114 | Lisp_Object bufname, norecord; | |
1115 | { | |
1116 | register Lisp_Object buf; | |
1117 | Lisp_Object tem; | |
1118 | ||
1119 | if (EQ (minibuf_window, selected_window)) | |
1120 | error ("Cannot switch buffers in minibuffer window"); | |
1121 | tem = Fwindow_dedicated_p (selected_window); | |
265a9e55 | 1122 | if (!NILP (tem)) |
1ab256cb RM |
1123 | error ("Cannot switch buffers in a dedicated window"); |
1124 | ||
265a9e55 | 1125 | if (NILP (bufname)) |
172a9c1f | 1126 | buf = Fother_buffer (Fcurrent_buffer (), Qnil); |
1ab256cb | 1127 | else |
a9ee7a59 KH |
1128 | { |
1129 | buf = Fget_buffer (bufname); | |
1130 | if (NILP (buf)) | |
1131 | { | |
1132 | buf = Fget_buffer_create (bufname); | |
1133 | Fset_buffer_major_mode (buf); | |
1134 | } | |
1135 | } | |
1ab256cb | 1136 | Fset_buffer (buf); |
265a9e55 | 1137 | if (NILP (norecord)) |
1ab256cb RM |
1138 | record_buffer (buf); |
1139 | ||
1140 | Fset_window_buffer (EQ (selected_window, minibuf_window) | |
5fcd022d JB |
1141 | ? Fnext_window (minibuf_window, Qnil, Qnil) |
1142 | : selected_window, | |
1ab256cb RM |
1143 | buf); |
1144 | ||
e8b3a22d | 1145 | return buf; |
1ab256cb RM |
1146 | } |
1147 | ||
1148 | DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 2, 0, | |
1149 | "Select buffer BUFFER in some window, preferably a different one.\n\ | |
1150 | If BUFFER is nil, then some other buffer is chosen.\n\ | |
1151 | If `pop-up-windows' is non-nil, windows can be split to do this.\n\ | |
1152 | If optional second arg OTHER-WINDOW is non-nil, insist on finding another\n\ | |
1153 | window even if BUFFER is already visible in the selected window.") | |
1154 | (bufname, other) | |
1155 | Lisp_Object bufname, other; | |
1156 | { | |
1157 | register Lisp_Object buf; | |
265a9e55 | 1158 | if (NILP (bufname)) |
172a9c1f | 1159 | buf = Fother_buffer (Fcurrent_buffer (), Qnil); |
1ab256cb | 1160 | else |
7c2087ee RS |
1161 | { |
1162 | buf = Fget_buffer (bufname); | |
1163 | if (NILP (buf)) | |
1164 | { | |
1165 | buf = Fget_buffer_create (bufname); | |
1166 | Fset_buffer_major_mode (buf); | |
1167 | } | |
1168 | } | |
1ab256cb RM |
1169 | Fset_buffer (buf); |
1170 | record_buffer (buf); | |
1171 | Fselect_window (Fdisplay_buffer (buf, other)); | |
e8b3a22d | 1172 | return buf; |
1ab256cb RM |
1173 | } |
1174 | ||
1175 | DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0, | |
1176 | "Return the current buffer as a Lisp object.") | |
1177 | () | |
1178 | { | |
1179 | register Lisp_Object buf; | |
67180c6a | 1180 | XSETBUFFER (buf, current_buffer); |
1ab256cb RM |
1181 | return buf; |
1182 | } | |
1183 | \f | |
1184 | /* Set the current buffer to b */ | |
1185 | ||
1186 | void | |
1187 | set_buffer_internal (b) | |
1188 | register struct buffer *b; | |
1189 | { | |
1190 | register struct buffer *old_buf; | |
1191 | register Lisp_Object tail, valcontents; | |
a7a60ce9 | 1192 | Lisp_Object tem; |
1ab256cb RM |
1193 | |
1194 | if (current_buffer == b) | |
1195 | return; | |
1196 | ||
1197 | windows_or_buffers_changed = 1; | |
1198 | old_buf = current_buffer; | |
1199 | current_buffer = b; | |
1200 | last_known_column_point = -1; /* invalidate indentation cache */ | |
1201 | ||
336cd056 RS |
1202 | if (old_buf) |
1203 | { | |
1204 | /* Put the undo list back in the base buffer, so that it appears | |
1205 | that an indirect buffer shares the undo list of its base. */ | |
1206 | if (old_buf->base_buffer) | |
1207 | old_buf->base_buffer->undo_list = old_buf->undo_list; | |
1208 | ||
1209 | /* If the old current buffer has markers to record PT, BEGV and ZV | |
1210 | when it is not current, update them now. */ | |
1211 | if (! NILP (old_buf->pt_marker)) | |
1212 | { | |
1213 | Lisp_Object obuf; | |
1214 | XSETBUFFER (obuf, old_buf); | |
1215 | Fset_marker (old_buf->pt_marker, BUF_PT (old_buf), obuf); | |
1216 | } | |
1217 | if (! NILP (old_buf->begv_marker)) | |
1218 | { | |
1219 | Lisp_Object obuf; | |
1220 | XSETBUFFER (obuf, old_buf); | |
1221 | Fset_marker (old_buf->begv_marker, BUF_BEGV (old_buf), obuf); | |
1222 | } | |
1223 | if (! NILP (old_buf->zv_marker)) | |
1224 | { | |
1225 | Lisp_Object obuf; | |
1226 | XSETBUFFER (obuf, old_buf); | |
1227 | Fset_marker (old_buf->zv_marker, BUF_ZV (old_buf), obuf); | |
1228 | } | |
1229 | } | |
1230 | ||
1231 | /* Get the undo list from the base buffer, so that it appears | |
1232 | that an indirect buffer shares the undo list of its base. */ | |
1233 | if (b->base_buffer) | |
1234 | b->undo_list = b->base_buffer->undo_list; | |
1235 | ||
1236 | /* If the new current buffer has markers to record PT, BEGV and ZV | |
1237 | when it is not current, fetch them now. */ | |
1238 | if (! NILP (b->pt_marker)) | |
1239 | BUF_PT (b) = marker_position (b->pt_marker); | |
1240 | if (! NILP (b->begv_marker)) | |
1241 | BUF_BEGV (b) = marker_position (b->begv_marker); | |
1242 | if (! NILP (b->zv_marker)) | |
1243 | BUF_ZV (b) = marker_position (b->zv_marker); | |
1244 | ||
1ab256cb RM |
1245 | /* Look down buffer's list of local Lisp variables |
1246 | to find and update any that forward into C variables. */ | |
1247 | ||
265a9e55 | 1248 | for (tail = b->local_var_alist; !NILP (tail); tail = XCONS (tail)->cdr) |
1ab256cb RM |
1249 | { |
1250 | valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value; | |
a7a60ce9 KH |
1251 | if ((BUFFER_LOCAL_VALUEP (valcontents) |
1252 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
fdc6e516 | 1253 | && (tem = XBUFFER_LOCAL_VALUE (valcontents)->car, |
a7a60ce9 | 1254 | (BOOLFWDP (tem) || INTFWDP (tem) || OBJFWDP (tem)))) |
1ab256cb RM |
1255 | /* Just reference the variable |
1256 | to cause it to become set for this buffer. */ | |
1257 | Fsymbol_value (XCONS (XCONS (tail)->car)->car); | |
1258 | } | |
1259 | ||
1260 | /* Do the same with any others that were local to the previous buffer */ | |
1261 | ||
1262 | if (old_buf) | |
265a9e55 | 1263 | for (tail = old_buf->local_var_alist; !NILP (tail); tail = XCONS (tail)->cdr) |
1ab256cb RM |
1264 | { |
1265 | valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value; | |
a7a60ce9 KH |
1266 | if ((BUFFER_LOCAL_VALUEP (valcontents) |
1267 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
fdc6e516 | 1268 | && (tem = XBUFFER_LOCAL_VALUE (valcontents)->car, |
a7a60ce9 | 1269 | (BOOLFWDP (tem) || INTFWDP (tem) || OBJFWDP (tem)))) |
1ab256cb RM |
1270 | /* Just reference the variable |
1271 | to cause it to become set for this buffer. */ | |
1272 | Fsymbol_value (XCONS (XCONS (tail)->car)->car); | |
1273 | } | |
1274 | } | |
1275 | ||
336cd056 RS |
1276 | /* Switch to buffer B temporarily for redisplay purposes. |
1277 | This avoids certain things thatdon't need to be done within redisplay. */ | |
1278 | ||
1279 | void | |
1280 | set_buffer_temp (b) | |
1281 | struct buffer *b; | |
1282 | { | |
1283 | register struct buffer *old_buf; | |
1284 | ||
1285 | if (current_buffer == b) | |
1286 | return; | |
1287 | ||
1288 | old_buf = current_buffer; | |
1289 | current_buffer = b; | |
1290 | ||
1291 | if (old_buf) | |
1292 | { | |
1293 | /* If the old current buffer has markers to record PT, BEGV and ZV | |
1294 | when it is not current, update them now. */ | |
1295 | if (! NILP (old_buf->pt_marker)) | |
1296 | { | |
1297 | Lisp_Object obuf; | |
1298 | XSETBUFFER (obuf, old_buf); | |
1299 | Fset_marker (old_buf->pt_marker, BUF_PT (old_buf), obuf); | |
1300 | } | |
1301 | if (! NILP (old_buf->begv_marker)) | |
1302 | { | |
1303 | Lisp_Object obuf; | |
1304 | XSETBUFFER (obuf, old_buf); | |
1305 | Fset_marker (old_buf->begv_marker, BUF_BEGV (old_buf), obuf); | |
1306 | } | |
1307 | if (! NILP (old_buf->zv_marker)) | |
1308 | { | |
1309 | Lisp_Object obuf; | |
1310 | XSETBUFFER (obuf, old_buf); | |
1311 | Fset_marker (old_buf->zv_marker, BUF_ZV (old_buf), obuf); | |
1312 | } | |
1313 | } | |
1314 | ||
1315 | /* If the new current buffer has markers to record PT, BEGV and ZV | |
1316 | when it is not current, fetch them now. */ | |
1317 | if (! NILP (b->pt_marker)) | |
1318 | BUF_PT (b) = marker_position (b->pt_marker); | |
1319 | if (! NILP (b->begv_marker)) | |
1320 | BUF_BEGV (b) = marker_position (b->begv_marker); | |
1321 | if (! NILP (b->zv_marker)) | |
1322 | BUF_ZV (b) = marker_position (b->zv_marker); | |
1323 | } | |
1324 | ||
1ab256cb RM |
1325 | DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0, |
1326 | "Make the buffer BUFFER current for editing operations.\n\ | |
1327 | BUFFER may be a buffer or the name of an existing buffer.\n\ | |
1328 | See also `save-excursion' when you want to make a buffer current temporarily.\n\ | |
1329 | This function does not display the buffer, so its effect ends\n\ | |
1330 | when the current command terminates.\n\ | |
1331 | Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.") | |
1332 | (bufname) | |
1333 | register Lisp_Object bufname; | |
1334 | { | |
1335 | register Lisp_Object buffer; | |
1336 | buffer = Fget_buffer (bufname); | |
265a9e55 | 1337 | if (NILP (buffer)) |
1ab256cb | 1338 | nsberror (bufname); |
265a9e55 | 1339 | if (NILP (XBUFFER (buffer)->name)) |
1ab256cb RM |
1340 | error ("Selecting deleted buffer"); |
1341 | set_buffer_internal (XBUFFER (buffer)); | |
1342 | return buffer; | |
1343 | } | |
1344 | \f | |
1345 | DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, | |
1346 | Sbarf_if_buffer_read_only, 0, 0, 0, | |
1347 | "Signal a `buffer-read-only' error if the current buffer is read-only.") | |
1348 | () | |
1349 | { | |
a96b68f1 RS |
1350 | if (!NILP (current_buffer->read_only) |
1351 | && NILP (Vinhibit_read_only)) | |
1ab256cb RM |
1352 | Fsignal (Qbuffer_read_only, (Fcons (Fcurrent_buffer (), Qnil))); |
1353 | return Qnil; | |
1354 | } | |
1355 | ||
1356 | DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "", | |
1357 | "Put BUFFER at the end of the list of all buffers.\n\ | |
1358 | There it is the least likely candidate for `other-buffer' to return;\n\ | |
528415e7 | 1359 | thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\ |
a5611885 JB |
1360 | If BUFFER is nil or omitted, bury the current buffer.\n\ |
1361 | Also, if BUFFER is nil or omitted, remove the current buffer from the\n\ | |
1362 | selected window if it is displayed there.") | |
1ab256cb RM |
1363 | (buf) |
1364 | register Lisp_Object buf; | |
1365 | { | |
b271272a | 1366 | /* Figure out what buffer we're going to bury. */ |
265a9e55 | 1367 | if (NILP (buf)) |
a5611885 | 1368 | { |
67180c6a | 1369 | XSETBUFFER (buf, current_buffer); |
a5611885 JB |
1370 | |
1371 | /* If we're burying the current buffer, unshow it. */ | |
5fcd022d | 1372 | Fswitch_to_buffer (Fother_buffer (buf, Qnil), Qnil); |
a5611885 | 1373 | } |
1ab256cb RM |
1374 | else |
1375 | { | |
1376 | Lisp_Object buf1; | |
1377 | ||
1378 | buf1 = Fget_buffer (buf); | |
265a9e55 | 1379 | if (NILP (buf1)) |
1ab256cb RM |
1380 | nsberror (buf); |
1381 | buf = buf1; | |
b271272a JB |
1382 | } |
1383 | ||
a5611885 | 1384 | /* Move buf to the end of the buffer list. */ |
b271272a JB |
1385 | { |
1386 | register Lisp_Object aelt, link; | |
1387 | ||
1388 | aelt = Frassq (buf, Vbuffer_alist); | |
1389 | link = Fmemq (aelt, Vbuffer_alist); | |
1390 | Vbuffer_alist = Fdelq (aelt, Vbuffer_alist); | |
1391 | XCONS (link)->cdr = Qnil; | |
1392 | Vbuffer_alist = nconc2 (Vbuffer_alist, link); | |
1393 | } | |
1ab256cb | 1394 | |
1ab256cb RM |
1395 | return Qnil; |
1396 | } | |
1397 | \f | |
c922bc55 | 1398 | DEFUN ("erase-buffer", Ferase_buffer, Serase_buffer, 0, 0, "*", |
1ab256cb | 1399 | "Delete the entire contents of the current buffer.\n\ |
2950a20e | 1400 | Any narrowing restriction in effect (see `narrow-to-region') is removed,\n\ |
1ab256cb RM |
1401 | so the buffer is truly empty after this.") |
1402 | () | |
1403 | { | |
1404 | Fwiden (); | |
1405 | del_range (BEG, Z); | |
1406 | current_buffer->last_window_start = 1; | |
1407 | /* Prevent warnings, or suspension of auto saving, that would happen | |
1408 | if future size is less than past size. Use of erase-buffer | |
1409 | implies that the future text is not really related to the past text. */ | |
8d7a4592 | 1410 | XSETFASTINT (current_buffer->save_length, 0); |
1ab256cb RM |
1411 | return Qnil; |
1412 | } | |
1413 | ||
1414 | validate_region (b, e) | |
1415 | register Lisp_Object *b, *e; | |
1416 | { | |
1ab256cb RM |
1417 | CHECK_NUMBER_COERCE_MARKER (*b, 0); |
1418 | CHECK_NUMBER_COERCE_MARKER (*e, 1); | |
1419 | ||
1420 | if (XINT (*b) > XINT (*e)) | |
1421 | { | |
03192067 KH |
1422 | Lisp_Object tem; |
1423 | tem = *b; *b = *e; *e = tem; | |
1ab256cb RM |
1424 | } |
1425 | ||
1426 | if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e) | |
1427 | && XINT (*e) <= ZV)) | |
1428 | args_out_of_range (*b, *e); | |
1429 | } | |
1430 | \f | |
1ab256cb RM |
1431 | DEFUN ("kill-all-local-variables", Fkill_all_local_variables, Skill_all_local_variables, |
1432 | 0, 0, 0, | |
1433 | "Switch to Fundamental mode by killing current buffer's local variables.\n\ | |
1434 | Most local variable bindings are eliminated so that the default values\n\ | |
1435 | become effective once more. Also, the syntax table is set from\n\ | |
1436 | `standard-syntax-table', the local keymap is set to nil,\n\ | |
1437 | and the abbrev table from `fundamental-mode-abbrev-table'.\n\ | |
1438 | This function also forces redisplay of the mode line.\n\ | |
1439 | \n\ | |
1440 | Every function to select a new major mode starts by\n\ | |
1441 | calling this function.\n\n\ | |
1442 | As a special exception, local variables whose names have\n\ | |
c5a15222 RS |
1443 | a non-nil `permanent-local' property are not eliminated by this function.\n\ |
1444 | \n\ | |
1445 | The first thing this function does is run\n\ | |
1446 | the normal hook `change-major-mode-hook'.") | |
1ab256cb RM |
1447 | () |
1448 | { | |
1449 | register Lisp_Object alist, sym, tem; | |
1450 | Lisp_Object oalist; | |
7410477a | 1451 | |
fd186f07 RS |
1452 | if (!NILP (Vrun_hooks)) |
1453 | call1 (Vrun_hooks, intern ("change-major-mode-hook")); | |
1ab256cb RM |
1454 | oalist = current_buffer->local_var_alist; |
1455 | ||
2f3f993b RS |
1456 | /* Make sure none of the bindings in oalist |
1457 | remain swapped in, in their symbols. */ | |
1ab256cb | 1458 | |
2f3f993b | 1459 | swap_out_buffer_local_variables (current_buffer); |
1ab256cb RM |
1460 | |
1461 | /* Actually eliminate all local bindings of this buffer. */ | |
1462 | ||
1463 | reset_buffer_local_variables (current_buffer); | |
1464 | ||
1465 | /* Redisplay mode lines; we are changing major mode. */ | |
1466 | ||
1467 | update_mode_lines++; | |
1468 | ||
1469 | /* Any which are supposed to be permanent, | |
1470 | make local again, with the same values they had. */ | |
1471 | ||
265a9e55 | 1472 | for (alist = oalist; !NILP (alist); alist = XCONS (alist)->cdr) |
1ab256cb RM |
1473 | { |
1474 | sym = XCONS (XCONS (alist)->car)->car; | |
1475 | tem = Fget (sym, Qpermanent_local); | |
265a9e55 | 1476 | if (! NILP (tem)) |
01050cb5 RM |
1477 | { |
1478 | Fmake_local_variable (sym); | |
1479 | Fset (sym, XCONS (XCONS (alist)->car)->cdr); | |
1480 | } | |
1ab256cb RM |
1481 | } |
1482 | ||
1483 | /* Force mode-line redisplay. Useful here because all major mode | |
1484 | commands call this function. */ | |
1485 | update_mode_lines++; | |
1486 | ||
1487 | return Qnil; | |
1488 | } | |
2f3f993b RS |
1489 | |
1490 | /* Make sure no local variables remain set up with buffer B | |
1491 | for their current values. */ | |
1492 | ||
1493 | static void | |
1494 | swap_out_buffer_local_variables (b) | |
1495 | struct buffer *b; | |
1496 | { | |
1497 | Lisp_Object oalist, alist, sym, tem, buffer; | |
1498 | ||
1499 | XSETBUFFER (buffer, b); | |
1500 | oalist = b->local_var_alist; | |
1501 | ||
1502 | for (alist = oalist; !NILP (alist); alist = XCONS (alist)->cdr) | |
1503 | { | |
1504 | sym = XCONS (XCONS (alist)->car)->car; | |
1505 | ||
1506 | /* Need not do anything if some other buffer's binding is now encached. */ | |
1507 | tem = XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->car; | |
1508 | if (XBUFFER (tem) == current_buffer) | |
1509 | { | |
1510 | /* Symbol is set up for this buffer's old local value. | |
1511 | Set it up for the current buffer with the default value. */ | |
1512 | ||
1513 | tem = XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->cdr; | |
1514 | /* Store the symbol's current value into the alist entry | |
1515 | it is currently set up for. This is so that, if the | |
1516 | local is marked permanent, and we make it local again | |
1517 | later in Fkill_all_local_variables, we don't lose the value. */ | |
1518 | XCONS (XCONS (tem)->car)->cdr | |
1519 | = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car); | |
1520 | /* Switch to the symbol's default-value alist entry. */ | |
1521 | XCONS (tem)->car = tem; | |
1522 | /* Mark it as current for buffer B. */ | |
1523 | XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->car | |
1524 | = buffer; | |
1525 | /* Store the current value into any forwarding in the symbol. */ | |
1526 | store_symval_forwarding (sym, XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car, | |
1527 | XCONS (tem)->cdr); | |
1528 | } | |
1529 | } | |
1530 | } | |
1ab256cb | 1531 | \f |
2eec3b4e RS |
1532 | /* Find all the overlays in the current buffer that contain position POS. |
1533 | Return the number found, and store them in a vector in *VEC_PTR. | |
1534 | Store in *LEN_PTR the size allocated for the vector. | |
52f8ec73 JB |
1535 | Store in *NEXT_PTR the next position after POS where an overlay starts, |
1536 | or ZV if there are no more overlays. | |
239c932b RS |
1537 | Store in *PREV_PTR the previous position after POS where an overlay ends, |
1538 | or BEGV if there are no previous overlays. | |
1539 | NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info. | |
2eec3b4e RS |
1540 | |
1541 | *VEC_PTR and *LEN_PTR should contain a valid vector and size | |
61d54cd5 RS |
1542 | when this function is called. |
1543 | ||
1544 | If EXTEND is non-zero, we make the vector bigger if necessary. | |
1545 | If EXTEND is zero, we never extend the vector, | |
1546 | and we store only as many overlays as will fit. | |
1547 | But we still return the total number of overlays. */ | |
2eec3b4e RS |
1548 | |
1549 | int | |
239c932b | 1550 | overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr, prev_ptr) |
2eec3b4e | 1551 | int pos; |
61d54cd5 | 1552 | int extend; |
2eec3b4e RS |
1553 | Lisp_Object **vec_ptr; |
1554 | int *len_ptr; | |
1555 | int *next_ptr; | |
239c932b | 1556 | int *prev_ptr; |
1ab256cb | 1557 | { |
2eec3b4e RS |
1558 | Lisp_Object tail, overlay, start, end, result; |
1559 | int idx = 0; | |
1560 | int len = *len_ptr; | |
1561 | Lisp_Object *vec = *vec_ptr; | |
1562 | int next = ZV; | |
239c932b | 1563 | int prev = BEGV; |
61d54cd5 RS |
1564 | int inhibit_storing = 0; |
1565 | ||
2eec3b4e | 1566 | for (tail = current_buffer->overlays_before; |
8fc0589a | 1567 | GC_CONSP (tail); |
2eec3b4e RS |
1568 | tail = XCONS (tail)->cdr) |
1569 | { | |
239c932b | 1570 | int startpos, endpos; |
52f8ec73 | 1571 | |
2eec3b4e | 1572 | overlay = XCONS (tail)->car; |
1ab256cb | 1573 | |
2eec3b4e RS |
1574 | start = OVERLAY_START (overlay); |
1575 | end = OVERLAY_END (overlay); | |
239c932b RS |
1576 | endpos = OVERLAY_POSITION (end); |
1577 | if (endpos < pos) | |
1578 | { | |
1579 | if (prev < endpos) | |
1580 | prev = endpos; | |
1581 | break; | |
1582 | } | |
1583 | if (endpos == pos) | |
1584 | continue; | |
2eec3b4e RS |
1585 | startpos = OVERLAY_POSITION (start); |
1586 | if (startpos <= pos) | |
1587 | { | |
1588 | if (idx == len) | |
1589 | { | |
61d54cd5 RS |
1590 | /* The supplied vector is full. |
1591 | Either make it bigger, or don't store any more in it. */ | |
1592 | if (extend) | |
1593 | { | |
1594 | *len_ptr = len *= 2; | |
1595 | vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); | |
1596 | *vec_ptr = vec; | |
1597 | } | |
1598 | else | |
1599 | inhibit_storing = 1; | |
2eec3b4e | 1600 | } |
61d54cd5 RS |
1601 | |
1602 | if (!inhibit_storing) | |
1603 | vec[idx] = overlay; | |
1604 | /* Keep counting overlays even if we can't return them all. */ | |
1605 | idx++; | |
2eec3b4e RS |
1606 | } |
1607 | else if (startpos < next) | |
1608 | next = startpos; | |
1609 | } | |
1610 | ||
1611 | for (tail = current_buffer->overlays_after; | |
8fc0589a | 1612 | GC_CONSP (tail); |
2eec3b4e | 1613 | tail = XCONS (tail)->cdr) |
1ab256cb | 1614 | { |
239c932b | 1615 | int startpos, endpos; |
52f8ec73 | 1616 | |
2eec3b4e | 1617 | overlay = XCONS (tail)->car; |
2eec3b4e RS |
1618 | |
1619 | start = OVERLAY_START (overlay); | |
1620 | end = OVERLAY_END (overlay); | |
1621 | startpos = OVERLAY_POSITION (start); | |
52f8ec73 | 1622 | if (pos < startpos) |
2eec3b4e RS |
1623 | { |
1624 | if (startpos < next) | |
1625 | next = startpos; | |
1626 | break; | |
1627 | } | |
239c932b RS |
1628 | endpos = OVERLAY_POSITION (end); |
1629 | if (pos < endpos) | |
2eec3b4e RS |
1630 | { |
1631 | if (idx == len) | |
1632 | { | |
61d54cd5 RS |
1633 | if (extend) |
1634 | { | |
1635 | *len_ptr = len *= 2; | |
1636 | vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); | |
1637 | *vec_ptr = vec; | |
1638 | } | |
1639 | else | |
1640 | inhibit_storing = 1; | |
2eec3b4e | 1641 | } |
61d54cd5 RS |
1642 | |
1643 | if (!inhibit_storing) | |
1644 | vec[idx] = overlay; | |
1645 | idx++; | |
2eec3b4e | 1646 | } |
239c932b RS |
1647 | else if (endpos < pos && endpos > prev) |
1648 | prev = endpos; | |
1ab256cb RM |
1649 | } |
1650 | ||
239c932b RS |
1651 | if (next_ptr) |
1652 | *next_ptr = next; | |
1653 | if (prev_ptr) | |
1654 | *prev_ptr = prev; | |
2eec3b4e RS |
1655 | return idx; |
1656 | } | |
fc04fa47 KH |
1657 | |
1658 | /* Fast function to just test if we're at an overlay boundary. */ | |
1659 | int | |
1660 | overlay_touches_p (pos) | |
1661 | int pos; | |
1662 | { | |
1663 | Lisp_Object tail, overlay; | |
1664 | ||
1665 | for (tail = current_buffer->overlays_before; GC_CONSP (tail); | |
1666 | tail = XCONS (tail)->cdr) | |
1667 | { | |
1668 | int endpos; | |
1669 | ||
1670 | overlay = XCONS (tail)->car; | |
1671 | if (!GC_OVERLAYP (overlay)) | |
1672 | abort (); | |
1673 | ||
1674 | endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); | |
1675 | if (endpos < pos) | |
1676 | break; | |
1677 | if (endpos == pos || OVERLAY_POSITION (OVERLAY_START (overlay)) == pos) | |
1678 | return 1; | |
1679 | } | |
1680 | ||
1681 | for (tail = current_buffer->overlays_after; GC_CONSP (tail); | |
1682 | tail = XCONS (tail)->cdr) | |
1683 | { | |
1684 | int startpos; | |
1685 | ||
1686 | overlay = XCONS (tail)->car; | |
1687 | if (!GC_OVERLAYP (overlay)) | |
1688 | abort (); | |
1689 | ||
1690 | startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); | |
1691 | if (pos < startpos) | |
1692 | break; | |
1693 | if (startpos == pos || OVERLAY_POSITION (OVERLAY_END (overlay)) == pos) | |
1694 | return 1; | |
1695 | } | |
1696 | return 0; | |
1697 | } | |
2eec3b4e | 1698 | \f |
5985d248 KH |
1699 | struct sortvec |
1700 | { | |
1701 | Lisp_Object overlay; | |
1702 | int beg, end; | |
1703 | int priority; | |
1704 | }; | |
1705 | ||
1706 | static int | |
1707 | compare_overlays (s1, s2) | |
1708 | struct sortvec *s1, *s2; | |
1709 | { | |
1710 | if (s1->priority != s2->priority) | |
1711 | return s1->priority - s2->priority; | |
1712 | if (s1->beg != s2->beg) | |
1713 | return s1->beg - s2->beg; | |
1714 | if (s1->end != s2->end) | |
1715 | return s2->end - s1->end; | |
1716 | return 0; | |
1717 | } | |
1718 | ||
1719 | /* Sort an array of overlays by priority. The array is modified in place. | |
1720 | The return value is the new size; this may be smaller than the original | |
1721 | size if some of the overlays were invalid or were window-specific. */ | |
1722 | int | |
1723 | sort_overlays (overlay_vec, noverlays, w) | |
1724 | Lisp_Object *overlay_vec; | |
1725 | int noverlays; | |
1726 | struct window *w; | |
1727 | { | |
1728 | int i, j; | |
1729 | struct sortvec *sortvec; | |
1730 | sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec)); | |
1731 | ||
1732 | /* Put the valid and relevant overlays into sortvec. */ | |
1733 | ||
1734 | for (i = 0, j = 0; i < noverlays; i++) | |
1735 | { | |
0fa767e7 | 1736 | Lisp_Object tem; |
c99fc30f | 1737 | Lisp_Object overlay; |
5985d248 | 1738 | |
c99fc30f | 1739 | overlay = overlay_vec[i]; |
5985d248 KH |
1740 | if (OVERLAY_VALID (overlay) |
1741 | && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0 | |
1742 | && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0) | |
1743 | { | |
0fa767e7 KH |
1744 | /* If we're interested in a specific window, then ignore |
1745 | overlays that are limited to some other window. */ | |
1746 | if (w) | |
5985d248 | 1747 | { |
0fa767e7 KH |
1748 | Lisp_Object window; |
1749 | ||
1750 | window = Foverlay_get (overlay, Qwindow); | |
a7a60ce9 | 1751 | if (WINDOWP (window) && XWINDOW (window) != w) |
0fa767e7 | 1752 | continue; |
5985d248 | 1753 | } |
0fa767e7 KH |
1754 | |
1755 | /* This overlay is good and counts: put it into sortvec. */ | |
1756 | sortvec[j].overlay = overlay; | |
1757 | sortvec[j].beg = OVERLAY_POSITION (OVERLAY_START (overlay)); | |
1758 | sortvec[j].end = OVERLAY_POSITION (OVERLAY_END (overlay)); | |
1759 | tem = Foverlay_get (overlay, Qpriority); | |
1760 | if (INTEGERP (tem)) | |
1761 | sortvec[j].priority = XINT (tem); | |
1762 | else | |
1763 | sortvec[j].priority = 0; | |
1764 | j++; | |
5985d248 KH |
1765 | } |
1766 | } | |
1767 | noverlays = j; | |
1768 | ||
1769 | /* Sort the overlays into the proper order: increasing priority. */ | |
1770 | ||
1771 | if (noverlays > 1) | |
1772 | qsort (sortvec, noverlays, sizeof (struct sortvec), compare_overlays); | |
1773 | ||
1774 | for (i = 0; i < noverlays; i++) | |
1775 | overlay_vec[i] = sortvec[i].overlay; | |
1776 | return (noverlays); | |
1777 | } | |
1778 | \f | |
5c4f68f1 | 1779 | /* Shift overlays in BUF's overlay lists, to center the lists at POS. */ |
1ab256cb | 1780 | |
2eec3b4e | 1781 | void |
5c4f68f1 JB |
1782 | recenter_overlay_lists (buf, pos) |
1783 | struct buffer *buf; | |
2eec3b4e RS |
1784 | int pos; |
1785 | { | |
1786 | Lisp_Object overlay, tail, next, prev, beg, end; | |
1787 | ||
1788 | /* See if anything in overlays_before should move to overlays_after. */ | |
1789 | ||
1790 | /* We don't strictly need prev in this loop; it should always be nil. | |
1791 | But we use it for symmetry and in case that should cease to be true | |
1792 | with some future change. */ | |
1793 | prev = Qnil; | |
5c4f68f1 | 1794 | for (tail = buf->overlays_before; |
2eec3b4e RS |
1795 | CONSP (tail); |
1796 | prev = tail, tail = next) | |
1ab256cb | 1797 | { |
2eec3b4e RS |
1798 | next = XCONS (tail)->cdr; |
1799 | overlay = XCONS (tail)->car; | |
1800 | ||
1801 | /* If the overlay is not valid, get rid of it. */ | |
1802 | if (!OVERLAY_VALID (overlay)) | |
52f8ec73 JB |
1803 | #if 1 |
1804 | abort (); | |
1805 | #else | |
2eec3b4e RS |
1806 | { |
1807 | /* Splice the cons cell TAIL out of overlays_before. */ | |
1808 | if (!NILP (prev)) | |
1809 | XCONS (prev)->cdr = next; | |
1810 | else | |
5c4f68f1 | 1811 | buf->overlays_before = next; |
2eec3b4e RS |
1812 | tail = prev; |
1813 | continue; | |
1814 | } | |
52f8ec73 | 1815 | #endif |
1ab256cb | 1816 | |
2eec3b4e RS |
1817 | beg = OVERLAY_START (overlay); |
1818 | end = OVERLAY_END (overlay); | |
1ab256cb | 1819 | |
2eec3b4e | 1820 | if (OVERLAY_POSITION (end) > pos) |
1ab256cb | 1821 | { |
2eec3b4e RS |
1822 | /* OVERLAY needs to be moved. */ |
1823 | int where = OVERLAY_POSITION (beg); | |
1824 | Lisp_Object other, other_prev; | |
1825 | ||
1826 | /* Splice the cons cell TAIL out of overlays_before. */ | |
1827 | if (!NILP (prev)) | |
1828 | XCONS (prev)->cdr = next; | |
1829 | else | |
5c4f68f1 | 1830 | buf->overlays_before = next; |
2eec3b4e RS |
1831 | |
1832 | /* Search thru overlays_after for where to put it. */ | |
1833 | other_prev = Qnil; | |
5c4f68f1 | 1834 | for (other = buf->overlays_after; |
2eec3b4e RS |
1835 | CONSP (other); |
1836 | other_prev = other, other = XCONS (other)->cdr) | |
1ab256cb | 1837 | { |
2eec3b4e RS |
1838 | Lisp_Object otherbeg, otheroverlay, follower; |
1839 | int win; | |
1840 | ||
1841 | otheroverlay = XCONS (other)->car; | |
1842 | if (! OVERLAY_VALID (otheroverlay)) | |
52f8ec73 | 1843 | abort (); |
2eec3b4e RS |
1844 | |
1845 | otherbeg = OVERLAY_START (otheroverlay); | |
1846 | if (OVERLAY_POSITION (otherbeg) >= where) | |
1847 | break; | |
1ab256cb | 1848 | } |
2eec3b4e RS |
1849 | |
1850 | /* Add TAIL to overlays_after before OTHER. */ | |
1851 | XCONS (tail)->cdr = other; | |
1852 | if (!NILP (other_prev)) | |
1853 | XCONS (other_prev)->cdr = tail; | |
1ab256cb | 1854 | else |
5c4f68f1 | 1855 | buf->overlays_after = tail; |
2eec3b4e | 1856 | tail = prev; |
1ab256cb | 1857 | } |
2eec3b4e RS |
1858 | else |
1859 | /* We've reached the things that should stay in overlays_before. | |
1860 | All the rest of overlays_before must end even earlier, | |
1861 | so stop now. */ | |
1862 | break; | |
1863 | } | |
1864 | ||
1865 | /* See if anything in overlays_after should be in overlays_before. */ | |
1866 | prev = Qnil; | |
5c4f68f1 | 1867 | for (tail = buf->overlays_after; |
2eec3b4e RS |
1868 | CONSP (tail); |
1869 | prev = tail, tail = next) | |
1870 | { | |
1871 | next = XCONS (tail)->cdr; | |
1872 | overlay = XCONS (tail)->car; | |
1873 | ||
1874 | /* If the overlay is not valid, get rid of it. */ | |
1875 | if (!OVERLAY_VALID (overlay)) | |
52f8ec73 JB |
1876 | #if 1 |
1877 | abort (); | |
1878 | #else | |
2eec3b4e RS |
1879 | { |
1880 | /* Splice the cons cell TAIL out of overlays_after. */ | |
1881 | if (!NILP (prev)) | |
1882 | XCONS (prev)->cdr = next; | |
1883 | else | |
5c4f68f1 | 1884 | buf->overlays_after = next; |
2eec3b4e RS |
1885 | tail = prev; |
1886 | continue; | |
1887 | } | |
52f8ec73 | 1888 | #endif |
2eec3b4e RS |
1889 | |
1890 | beg = OVERLAY_START (overlay); | |
1891 | end = OVERLAY_END (overlay); | |
1892 | ||
1893 | /* Stop looking, when we know that nothing further | |
1894 | can possibly end before POS. */ | |
1895 | if (OVERLAY_POSITION (beg) > pos) | |
1896 | break; | |
1897 | ||
1898 | if (OVERLAY_POSITION (end) <= pos) | |
1899 | { | |
1900 | /* OVERLAY needs to be moved. */ | |
1901 | int where = OVERLAY_POSITION (end); | |
1902 | Lisp_Object other, other_prev; | |
1903 | ||
1904 | /* Splice the cons cell TAIL out of overlays_after. */ | |
1905 | if (!NILP (prev)) | |
1906 | XCONS (prev)->cdr = next; | |
1907 | else | |
5c4f68f1 | 1908 | buf->overlays_after = next; |
2eec3b4e RS |
1909 | |
1910 | /* Search thru overlays_before for where to put it. */ | |
1911 | other_prev = Qnil; | |
5c4f68f1 | 1912 | for (other = buf->overlays_before; |
2eec3b4e RS |
1913 | CONSP (other); |
1914 | other_prev = other, other = XCONS (other)->cdr) | |
1915 | { | |
1916 | Lisp_Object otherend, otheroverlay; | |
1917 | int win; | |
1918 | ||
1919 | otheroverlay = XCONS (other)->car; | |
1920 | if (! OVERLAY_VALID (otheroverlay)) | |
52f8ec73 | 1921 | abort (); |
2eec3b4e RS |
1922 | |
1923 | otherend = OVERLAY_END (otheroverlay); | |
1924 | if (OVERLAY_POSITION (otherend) <= where) | |
1925 | break; | |
1926 | } | |
1927 | ||
1928 | /* Add TAIL to overlays_before before OTHER. */ | |
1929 | XCONS (tail)->cdr = other; | |
1930 | if (!NILP (other_prev)) | |
1931 | XCONS (other_prev)->cdr = tail; | |
1932 | else | |
5c4f68f1 | 1933 | buf->overlays_before = tail; |
2eec3b4e RS |
1934 | tail = prev; |
1935 | } | |
1936 | } | |
1937 | ||
8d7a4592 | 1938 | XSETFASTINT (buf->overlay_center, pos); |
2eec3b4e | 1939 | } |
2b1bdf65 KH |
1940 | |
1941 | /* Fix up overlays that were garbled as a result of permuting markers | |
1942 | in the range START through END. Any overlay with at least one | |
1943 | endpoint in this range will need to be unlinked from the overlay | |
1944 | list and reinserted in its proper place. | |
1945 | Such an overlay might even have negative size at this point. | |
1946 | If so, we'll reverse the endpoints. Can you think of anything | |
1947 | better to do in this situation? */ | |
1948 | void | |
1949 | fix_overlays_in_range (start, end) | |
1950 | register int start, end; | |
1951 | { | |
1952 | Lisp_Object tem, overlay; | |
1953 | Lisp_Object before_list, after_list; | |
1954 | Lisp_Object *ptail, *pbefore = &before_list, *pafter = &after_list; | |
1955 | int startpos, endpos; | |
1956 | ||
1957 | /* This algorithm shifts links around instead of consing and GCing. | |
1958 | The loop invariant is that before_list (resp. after_list) is a | |
1959 | well-formed list except that its last element, the one that | |
1960 | *pbefore (resp. *pafter) points to, is still uninitialized. | |
1961 | So it's not a bug that before_list isn't initialized, although | |
1962 | it may look strange. */ | |
1963 | for (ptail = ¤t_buffer->overlays_before; CONSP (*ptail);) | |
1964 | { | |
1965 | overlay = XCONS (*ptail)->car; | |
1966 | endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); | |
1967 | if (endpos < start) | |
1968 | break; | |
1969 | startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); | |
1970 | if (endpos < end | |
1971 | || (startpos >= start && startpos < end)) | |
1972 | { | |
1973 | /* If the overlay is backwards, fix that now. */ | |
1974 | if (startpos > endpos) | |
1975 | { | |
1976 | int tem; | |
1977 | Fset_marker (OVERLAY_START (overlay), endpos, Qnil); | |
1978 | Fset_marker (OVERLAY_END (overlay), startpos, Qnil); | |
1979 | tem = startpos; startpos = endpos; endpos = tem; | |
1980 | } | |
1981 | /* Add it to the end of the wrong list. Later on, | |
1982 | recenter_overlay_lists will move it to the right place. */ | |
1983 | if (endpos < XINT (current_buffer->overlay_center)) | |
1984 | { | |
1985 | *pafter = *ptail; | |
1986 | pafter = &XCONS (*ptail)->cdr; | |
1987 | } | |
1988 | else | |
1989 | { | |
1990 | *pbefore = *ptail; | |
1991 | pbefore = &XCONS (*ptail)->cdr; | |
1992 | } | |
1993 | *ptail = XCONS (*ptail)->cdr; | |
1994 | } | |
1995 | else | |
1996 | ptail = &XCONS (*ptail)->cdr; | |
1997 | } | |
1998 | for (ptail = ¤t_buffer->overlays_after; CONSP (*ptail);) | |
1999 | { | |
2000 | overlay = XCONS (*ptail)->car; | |
2001 | startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); | |
2002 | if (startpos >= end) | |
2003 | break; | |
2004 | endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); | |
2005 | if (startpos >= start | |
2006 | || (endpos >= start && endpos < end)) | |
2007 | { | |
2008 | if (startpos > endpos) | |
2009 | { | |
2010 | int tem; | |
2011 | Fset_marker (OVERLAY_START (overlay), endpos, Qnil); | |
2012 | Fset_marker (OVERLAY_END (overlay), startpos, Qnil); | |
2013 | tem = startpos; startpos = endpos; endpos = tem; | |
2014 | } | |
2015 | if (endpos < XINT (current_buffer->overlay_center)) | |
2016 | { | |
2017 | *pafter = *ptail; | |
2018 | pafter = &XCONS (*ptail)->cdr; | |
2019 | } | |
2020 | else | |
2021 | { | |
2022 | *pbefore = *ptail; | |
2023 | pbefore = &XCONS (*ptail)->cdr; | |
2024 | } | |
2025 | *ptail = XCONS (*ptail)->cdr; | |
2026 | } | |
2027 | else | |
2028 | ptail = &XCONS (*ptail)->cdr; | |
2029 | } | |
2030 | ||
2031 | /* Splice the constructed (wrong) lists into the buffer's lists, | |
2032 | and let the recenter function make it sane again. */ | |
2033 | *pbefore = current_buffer->overlays_before; | |
2034 | current_buffer->overlays_before = before_list; | |
2035 | recenter_overlay_lists (current_buffer, | |
2036 | XINT (current_buffer->overlay_center)); | |
2037 | ||
2038 | *pafter = current_buffer->overlays_after; | |
2039 | current_buffer->overlays_after = after_list; | |
2040 | recenter_overlay_lists (current_buffer, | |
2041 | XINT (current_buffer->overlay_center)); | |
2042 | } | |
2eec3b4e | 2043 | \f |
52f8ec73 JB |
2044 | DEFUN ("overlayp", Foverlayp, Soverlayp, 1, 1, 0, |
2045 | "Return t if OBJECT is an overlay.") | |
2046 | (object) | |
2047 | Lisp_Object object; | |
2048 | { | |
2049 | return (OVERLAYP (object) ? Qt : Qnil); | |
2050 | } | |
2051 | ||
5c4f68f1 JB |
2052 | DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 3, 0, |
2053 | "Create a new overlay with range BEG to END in BUFFER.\n\ | |
2054 | If omitted, BUFFER defaults to the current buffer.\n\ | |
2eec3b4e | 2055 | BEG and END may be integers or markers.") |
5c4f68f1 JB |
2056 | (beg, end, buffer) |
2057 | Lisp_Object beg, end, buffer; | |
2eec3b4e RS |
2058 | { |
2059 | Lisp_Object overlay; | |
5c4f68f1 | 2060 | struct buffer *b; |
2eec3b4e | 2061 | |
5c4f68f1 | 2062 | if (NILP (buffer)) |
67180c6a | 2063 | XSETBUFFER (buffer, current_buffer); |
883047b9 JB |
2064 | else |
2065 | CHECK_BUFFER (buffer, 2); | |
2066 | if (MARKERP (beg) | |
2067 | && ! EQ (Fmarker_buffer (beg), buffer)) | |
2068 | error ("Marker points into wrong buffer"); | |
2069 | if (MARKERP (end) | |
2070 | && ! EQ (Fmarker_buffer (end), buffer)) | |
2071 | error ("Marker points into wrong buffer"); | |
2eec3b4e | 2072 | |
883047b9 JB |
2073 | CHECK_NUMBER_COERCE_MARKER (beg, 1); |
2074 | CHECK_NUMBER_COERCE_MARKER (end, 1); | |
5c4f68f1 | 2075 | |
883047b9 | 2076 | if (XINT (beg) > XINT (end)) |
5c4f68f1 | 2077 | { |
c99fc30f KH |
2078 | Lisp_Object temp; |
2079 | temp = beg; beg = end; end = temp; | |
5c4f68f1 | 2080 | } |
883047b9 JB |
2081 | |
2082 | b = XBUFFER (buffer); | |
2083 | ||
2084 | beg = Fset_marker (Fmake_marker (), beg, buffer); | |
2085 | end = Fset_marker (Fmake_marker (), end, buffer); | |
5c4f68f1 | 2086 | |
48e2e3ba KH |
2087 | overlay = allocate_misc (); |
2088 | XMISC (overlay)->type = Lisp_Misc_Overlay; | |
2089 | XOVERLAY (overlay)->start = beg; | |
2090 | XOVERLAY (overlay)->end = end; | |
2091 | XOVERLAY (overlay)->plist = Qnil; | |
2eec3b4e RS |
2092 | |
2093 | /* Put the new overlay on the wrong list. */ | |
2094 | end = OVERLAY_END (overlay); | |
5c4f68f1 JB |
2095 | if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) |
2096 | b->overlays_after = Fcons (overlay, b->overlays_after); | |
2eec3b4e | 2097 | else |
5c4f68f1 | 2098 | b->overlays_before = Fcons (overlay, b->overlays_before); |
2eec3b4e RS |
2099 | |
2100 | /* This puts it in the right list, and in the right order. */ | |
5c4f68f1 | 2101 | recenter_overlay_lists (b, XINT (b->overlay_center)); |
2eec3b4e | 2102 | |
b61982dd JB |
2103 | /* We don't need to redisplay the region covered by the overlay, because |
2104 | the overlay has no properties at the moment. */ | |
2105 | ||
2eec3b4e RS |
2106 | return overlay; |
2107 | } | |
2108 | ||
5c4f68f1 JB |
2109 | DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0, |
2110 | "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\ | |
3ece337a JB |
2111 | If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.\n\ |
2112 | If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current\n\ | |
2113 | buffer.") | |
5c4f68f1 JB |
2114 | (overlay, beg, end, buffer) |
2115 | Lisp_Object overlay, beg, end, buffer; | |
2eec3b4e | 2116 | { |
0a4469c9 RS |
2117 | struct buffer *b, *ob; |
2118 | Lisp_Object obuffer; | |
2119 | int count = specpdl_ptr - specpdl; | |
5c4f68f1 | 2120 | |
52f8ec73 | 2121 | CHECK_OVERLAY (overlay, 0); |
5c4f68f1 JB |
2122 | if (NILP (buffer)) |
2123 | buffer = Fmarker_buffer (OVERLAY_START (overlay)); | |
3ece337a | 2124 | if (NILP (buffer)) |
67180c6a | 2125 | XSETBUFFER (buffer, current_buffer); |
5c4f68f1 | 2126 | CHECK_BUFFER (buffer, 3); |
883047b9 JB |
2127 | |
2128 | if (MARKERP (beg) | |
2129 | && ! EQ (Fmarker_buffer (beg), buffer)) | |
2130 | error ("Marker points into wrong buffer"); | |
2131 | if (MARKERP (end) | |
2132 | && ! EQ (Fmarker_buffer (end), buffer)) | |
2133 | error ("Marker points into wrong buffer"); | |
2134 | ||
b61982dd JB |
2135 | CHECK_NUMBER_COERCE_MARKER (beg, 1); |
2136 | CHECK_NUMBER_COERCE_MARKER (end, 1); | |
2137 | ||
9d7608b7 KH |
2138 | if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate))) |
2139 | return Fdelete_overlay (overlay); | |
0a4469c9 | 2140 | |
b61982dd JB |
2141 | if (XINT (beg) > XINT (end)) |
2142 | { | |
c99fc30f KH |
2143 | Lisp_Object temp; |
2144 | temp = beg; beg = end; end = temp; | |
b61982dd JB |
2145 | } |
2146 | ||
9d7608b7 KH |
2147 | specbind (Qinhibit_quit, Qt); |
2148 | ||
0a4469c9 | 2149 | obuffer = Fmarker_buffer (OVERLAY_START (overlay)); |
5c4f68f1 | 2150 | b = XBUFFER (buffer); |
0a4469c9 | 2151 | ob = XBUFFER (obuffer); |
2eec3b4e | 2152 | |
c82ed728 | 2153 | /* If the overlay has changed buffers, do a thorough redisplay. */ |
0a4469c9 | 2154 | if (!EQ (buffer, obuffer)) |
50760c4a RS |
2155 | { |
2156 | /* Redisplay where the overlay was. */ | |
2157 | if (!NILP (obuffer)) | |
2158 | { | |
2159 | Lisp_Object o_beg; | |
2160 | Lisp_Object o_end; | |
2161 | ||
2162 | o_beg = OVERLAY_START (overlay); | |
2163 | o_end = OVERLAY_END (overlay); | |
2164 | o_beg = OVERLAY_POSITION (o_beg); | |
2165 | o_end = OVERLAY_POSITION (o_end); | |
2166 | ||
efd90478 | 2167 | redisplay_region (ob, XINT (o_beg), XINT (o_end)); |
50760c4a RS |
2168 | } |
2169 | ||
2170 | /* Redisplay where the overlay is going to be. */ | |
efd90478 | 2171 | redisplay_region (b, XINT (beg), XINT (end)); |
50760c4a RS |
2172 | |
2173 | /* Don't limit redisplay to the selected window. */ | |
2174 | windows_or_buffers_changed = 1; | |
2175 | } | |
c82ed728 JB |
2176 | else |
2177 | /* Redisplay the area the overlay has just left, or just enclosed. */ | |
2178 | { | |
be8b1c6b RS |
2179 | Lisp_Object o_beg; |
2180 | Lisp_Object o_end; | |
c82ed728 JB |
2181 | int change_beg, change_end; |
2182 | ||
be8b1c6b RS |
2183 | o_beg = OVERLAY_START (overlay); |
2184 | o_end = OVERLAY_END (overlay); | |
c82ed728 JB |
2185 | o_beg = OVERLAY_POSITION (o_beg); |
2186 | o_end = OVERLAY_POSITION (o_end); | |
2187 | ||
2188 | if (XINT (o_beg) == XINT (beg)) | |
2189 | redisplay_region (b, XINT (o_end), XINT (end)); | |
2190 | else if (XINT (o_end) == XINT (end)) | |
2191 | redisplay_region (b, XINT (o_beg), XINT (beg)); | |
2192 | else | |
2193 | { | |
2194 | if (XINT (beg) < XINT (o_beg)) o_beg = beg; | |
2195 | if (XINT (end) > XINT (o_end)) o_end = end; | |
2196 | redisplay_region (b, XINT (o_beg), XINT (o_end)); | |
2197 | } | |
2198 | } | |
b61982dd | 2199 | |
0a4469c9 RS |
2200 | if (!NILP (obuffer)) |
2201 | { | |
2202 | ob->overlays_before = Fdelq (overlay, ob->overlays_before); | |
2203 | ob->overlays_after = Fdelq (overlay, ob->overlays_after); | |
2204 | } | |
5c4f68f1 JB |
2205 | |
2206 | Fset_marker (OVERLAY_START (overlay), beg, buffer); | |
2207 | Fset_marker (OVERLAY_END (overlay), end, buffer); | |
2eec3b4e RS |
2208 | |
2209 | /* Put the overlay on the wrong list. */ | |
2210 | end = OVERLAY_END (overlay); | |
5c4f68f1 JB |
2211 | if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) |
2212 | b->overlays_after = Fcons (overlay, b->overlays_after); | |
2eec3b4e | 2213 | else |
5c4f68f1 | 2214 | b->overlays_before = Fcons (overlay, b->overlays_before); |
2eec3b4e RS |
2215 | |
2216 | /* This puts it in the right list, and in the right order. */ | |
5c4f68f1 | 2217 | recenter_overlay_lists (b, XINT (b->overlay_center)); |
2eec3b4e | 2218 | |
0a4469c9 | 2219 | return unbind_to (count, overlay); |
2eec3b4e RS |
2220 | } |
2221 | ||
2222 | DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0, | |
5c4f68f1 | 2223 | "Delete the overlay OVERLAY from its buffer.") |
2eec3b4e | 2224 | (overlay) |
5c4f68f1 | 2225 | Lisp_Object overlay; |
2eec3b4e | 2226 | { |
0a4469c9 | 2227 | Lisp_Object buffer; |
5c4f68f1 | 2228 | struct buffer *b; |
0a4469c9 | 2229 | int count = specpdl_ptr - specpdl; |
5c4f68f1 | 2230 | |
52f8ec73 JB |
2231 | CHECK_OVERLAY (overlay, 0); |
2232 | ||
0a4469c9 RS |
2233 | buffer = Fmarker_buffer (OVERLAY_START (overlay)); |
2234 | if (NILP (buffer)) | |
2235 | return Qnil; | |
2236 | ||
2237 | b = XBUFFER (buffer); | |
2238 | ||
2239 | specbind (Qinhibit_quit, Qt); | |
5c4f68f1 JB |
2240 | |
2241 | b->overlays_before = Fdelq (overlay, b->overlays_before); | |
2242 | b->overlays_after = Fdelq (overlay, b->overlays_after); | |
2243 | ||
b61982dd | 2244 | redisplay_region (b, |
a927f5c9 RS |
2245 | marker_position (OVERLAY_START (overlay)), |
2246 | marker_position (OVERLAY_END (overlay))); | |
b61982dd | 2247 | |
3ece337a JB |
2248 | Fset_marker (OVERLAY_START (overlay), Qnil, Qnil); |
2249 | Fset_marker (OVERLAY_END (overlay), Qnil, Qnil); | |
2250 | ||
0a4469c9 | 2251 | return unbind_to (count, Qnil); |
2eec3b4e RS |
2252 | } |
2253 | \f | |
8ebafa8d JB |
2254 | /* Overlay dissection functions. */ |
2255 | ||
2256 | DEFUN ("overlay-start", Foverlay_start, Soverlay_start, 1, 1, 0, | |
2257 | "Return the position at which OVERLAY starts.") | |
2258 | (overlay) | |
2259 | Lisp_Object overlay; | |
2260 | { | |
2261 | CHECK_OVERLAY (overlay, 0); | |
2262 | ||
2263 | return (Fmarker_position (OVERLAY_START (overlay))); | |
2264 | } | |
2265 | ||
2266 | DEFUN ("overlay-end", Foverlay_end, Soverlay_end, 1, 1, 0, | |
2267 | "Return the position at which OVERLAY ends.") | |
2268 | (overlay) | |
2269 | Lisp_Object overlay; | |
2270 | { | |
2271 | CHECK_OVERLAY (overlay, 0); | |
2272 | ||
2273 | return (Fmarker_position (OVERLAY_END (overlay))); | |
2274 | } | |
2275 | ||
2276 | DEFUN ("overlay-buffer", Foverlay_buffer, Soverlay_buffer, 1, 1, 0, | |
2277 | "Return the buffer OVERLAY belongs to.") | |
2278 | (overlay) | |
2279 | Lisp_Object overlay; | |
2280 | { | |
2281 | CHECK_OVERLAY (overlay, 0); | |
2282 | ||
2283 | return Fmarker_buffer (OVERLAY_START (overlay)); | |
2284 | } | |
2285 | ||
2286 | DEFUN ("overlay-properties", Foverlay_properties, Soverlay_properties, 1, 1, 0, | |
2287 | "Return a list of the properties on OVERLAY.\n\ | |
2288 | This is a copy of OVERLAY's plist; modifying its conses has no effect on\n\ | |
2289 | OVERLAY.") | |
2290 | (overlay) | |
2291 | Lisp_Object overlay; | |
2292 | { | |
2293 | CHECK_OVERLAY (overlay, 0); | |
2294 | ||
48e2e3ba | 2295 | return Fcopy_sequence (XOVERLAY (overlay)->plist); |
8ebafa8d JB |
2296 | } |
2297 | ||
2298 | \f | |
2eec3b4e | 2299 | DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0, |
eb8c3be9 | 2300 | "Return a list of the overlays that contain position POS.") |
2eec3b4e RS |
2301 | (pos) |
2302 | Lisp_Object pos; | |
2303 | { | |
2304 | int noverlays; | |
2eec3b4e RS |
2305 | Lisp_Object *overlay_vec; |
2306 | int len; | |
2307 | Lisp_Object result; | |
2308 | ||
2309 | CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
2310 | ||
2311 | len = 10; | |
2312 | overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); | |
2313 | ||
2314 | /* Put all the overlays we want in a vector in overlay_vec. | |
2315 | Store the length in len. */ | |
239c932b | 2316 | noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, NULL, NULL); |
2eec3b4e RS |
2317 | |
2318 | /* Make a list of them all. */ | |
2319 | result = Flist (noverlays, overlay_vec); | |
2320 | ||
9ac0d9e0 | 2321 | xfree (overlay_vec); |
2eec3b4e RS |
2322 | return result; |
2323 | } | |
2324 | ||
2325 | DEFUN ("next-overlay-change", Fnext_overlay_change, Snext_overlay_change, | |
2326 | 1, 1, 0, | |
bbe20e81 KH |
2327 | "Return the next position after POS where an overlay starts or ends.\n\ |
2328 | If there are no more overlay boundaries after POS, return (point-max).") | |
2eec3b4e RS |
2329 | (pos) |
2330 | Lisp_Object pos; | |
2331 | { | |
2332 | int noverlays; | |
2333 | int endpos; | |
2334 | Lisp_Object *overlay_vec; | |
2335 | int len; | |
2eec3b4e RS |
2336 | int i; |
2337 | ||
2338 | CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
2339 | ||
2340 | len = 10; | |
2341 | overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); | |
2342 | ||
2343 | /* Put all the overlays we want in a vector in overlay_vec. | |
2344 | Store the length in len. | |
2345 | endpos gets the position where the next overlay starts. */ | |
239c932b | 2346 | noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, &endpos, NULL); |
2eec3b4e RS |
2347 | |
2348 | /* If any of these overlays ends before endpos, | |
2349 | use its ending point instead. */ | |
2350 | for (i = 0; i < noverlays; i++) | |
2351 | { | |
2352 | Lisp_Object oend; | |
2353 | int oendpos; | |
2354 | ||
2355 | oend = OVERLAY_END (overlay_vec[i]); | |
2356 | oendpos = OVERLAY_POSITION (oend); | |
2357 | if (oendpos < endpos) | |
2358 | endpos = oendpos; | |
1ab256cb RM |
2359 | } |
2360 | ||
9ac0d9e0 | 2361 | xfree (overlay_vec); |
2eec3b4e RS |
2362 | return make_number (endpos); |
2363 | } | |
239c932b RS |
2364 | |
2365 | DEFUN ("previous-overlay-change", Fprevious_overlay_change, | |
2366 | Sprevious_overlay_change, 1, 1, 0, | |
2367 | "Return the previous position before POS where an overlay starts or ends.\n\ | |
2368 | If there are no more overlay boundaries after POS, return (point-min).") | |
2369 | (pos) | |
2370 | Lisp_Object pos; | |
2371 | { | |
2372 | int noverlays; | |
2373 | int prevpos; | |
2374 | Lisp_Object *overlay_vec; | |
2375 | int len; | |
2376 | int i; | |
2377 | ||
2378 | CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
2379 | ||
2380 | len = 10; | |
2381 | overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); | |
2382 | ||
2383 | /* Put all the overlays we want in a vector in overlay_vec. | |
2384 | Store the length in len. | |
2385 | prevpos gets the position of an overlay end. */ | |
2386 | noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, NULL, &prevpos); | |
2387 | ||
2388 | /* If any of these overlays starts before endpos, | |
2389 | maybe use its starting point instead. */ | |
2390 | for (i = 0; i < noverlays; i++) | |
2391 | { | |
2392 | Lisp_Object ostart; | |
2393 | int ostartpos; | |
2394 | ||
2395 | ostart = OVERLAY_START (overlay_vec[i]); | |
2396 | ostartpos = OVERLAY_POSITION (ostart); | |
2397 | if (ostartpos > prevpos && ostartpos < XINT (pos)) | |
2398 | prevpos = ostartpos; | |
2399 | } | |
2400 | ||
2401 | xfree (overlay_vec); | |
2402 | return make_number (prevpos); | |
2403 | } | |
2eec3b4e RS |
2404 | \f |
2405 | /* These functions are for debugging overlays. */ | |
2406 | ||
2407 | DEFUN ("overlay-lists", Foverlay_lists, Soverlay_lists, 0, 0, 0, | |
2408 | "Return a pair of lists giving all the overlays of the current buffer.\n\ | |
2409 | The car has all the overlays before the overlay center;\n\ | |
bbe20e81 | 2410 | the cdr has all the overlays after the overlay center.\n\ |
2eec3b4e RS |
2411 | Recentering overlays moves overlays between these lists.\n\ |
2412 | The lists you get are copies, so that changing them has no effect.\n\ | |
2413 | However, the overlays you get are the real objects that the buffer uses.") | |
2414 | () | |
2415 | { | |
2416 | Lisp_Object before, after; | |
2417 | before = current_buffer->overlays_before; | |
2418 | if (CONSP (before)) | |
2419 | before = Fcopy_sequence (before); | |
2420 | after = current_buffer->overlays_after; | |
2421 | if (CONSP (after)) | |
2422 | after = Fcopy_sequence (after); | |
2423 | ||
2424 | return Fcons (before, after); | |
2425 | } | |
2426 | ||
2427 | DEFUN ("overlay-recenter", Foverlay_recenter, Soverlay_recenter, 1, 1, 0, | |
2428 | "Recenter the overlays of the current buffer around position POS.") | |
2429 | (pos) | |
2430 | Lisp_Object pos; | |
2431 | { | |
2432 | CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
2433 | ||
5c4f68f1 | 2434 | recenter_overlay_lists (current_buffer, XINT (pos)); |
2eec3b4e RS |
2435 | return Qnil; |
2436 | } | |
2437 | \f | |
2438 | DEFUN ("overlay-get", Foverlay_get, Soverlay_get, 2, 2, 0, | |
2439 | "Get the property of overlay OVERLAY with property name NAME.") | |
2440 | (overlay, prop) | |
2441 | Lisp_Object overlay, prop; | |
2442 | { | |
cab4777e | 2443 | Lisp_Object plist, fallback; |
52f8ec73 JB |
2444 | |
2445 | CHECK_OVERLAY (overlay, 0); | |
2446 | ||
cab4777e RS |
2447 | fallback = Qnil; |
2448 | ||
48e2e3ba | 2449 | for (plist = XOVERLAY (overlay)->plist; |
2eec3b4e RS |
2450 | CONSP (plist) && CONSP (XCONS (plist)->cdr); |
2451 | plist = XCONS (XCONS (plist)->cdr)->cdr) | |
2452 | { | |
2453 | if (EQ (XCONS (plist)->car, prop)) | |
2454 | return XCONS (XCONS (plist)->cdr)->car; | |
cab4777e RS |
2455 | else if (EQ (XCONS (plist)->car, Qcategory)) |
2456 | { | |
2457 | Lisp_Object tem; | |
2458 | tem = Fcar (Fcdr (plist)); | |
2459 | if (SYMBOLP (tem)) | |
2460 | fallback = Fget (tem, prop); | |
2461 | } | |
2eec3b4e | 2462 | } |
52f8ec73 | 2463 | |
cab4777e | 2464 | return fallback; |
2eec3b4e RS |
2465 | } |
2466 | ||
2467 | DEFUN ("overlay-put", Foverlay_put, Soverlay_put, 3, 3, 0, | |
2468 | "Set one property of overlay OVERLAY: give property PROP value VALUE.") | |
2469 | (overlay, prop, value) | |
2470 | Lisp_Object overlay, prop, value; | |
2471 | { | |
48e2e3ba | 2472 | Lisp_Object tail, buffer; |
9d7608b7 | 2473 | int changed; |
2eec3b4e | 2474 | |
52f8ec73 | 2475 | CHECK_OVERLAY (overlay, 0); |
b61982dd | 2476 | |
274a9425 RS |
2477 | buffer = Fmarker_buffer (OVERLAY_START (overlay)); |
2478 | ||
48e2e3ba | 2479 | for (tail = XOVERLAY (overlay)->plist; |
2eec3b4e RS |
2480 | CONSP (tail) && CONSP (XCONS (tail)->cdr); |
2481 | tail = XCONS (XCONS (tail)->cdr)->cdr) | |
274a9425 RS |
2482 | if (EQ (XCONS (tail)->car, prop)) |
2483 | { | |
9d7608b7 KH |
2484 | changed = !EQ (XCONS (XCONS (tail)->cdr)->car, value); |
2485 | XCONS (XCONS (tail)->cdr)->car = value; | |
2486 | goto found; | |
274a9425 | 2487 | } |
9d7608b7 KH |
2488 | /* It wasn't in the list, so add it to the front. */ |
2489 | changed = !NILP (value); | |
48e2e3ba KH |
2490 | XOVERLAY (overlay)->plist |
2491 | = Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist)); | |
9d7608b7 KH |
2492 | found: |
2493 | if (! NILP (buffer)) | |
2494 | { | |
2495 | if (changed) | |
2496 | redisplay_region (XBUFFER (buffer), | |
2497 | marker_position (OVERLAY_START (overlay)), | |
2498 | marker_position (OVERLAY_END (overlay))); | |
2499 | if (EQ (prop, Qevaporate) && ! NILP (value) | |
2500 | && (OVERLAY_POSITION (OVERLAY_START (overlay)) | |
2501 | == OVERLAY_POSITION (OVERLAY_END (overlay)))) | |
2502 | Fdelete_overlay (overlay); | |
2503 | } | |
2eec3b4e | 2504 | return value; |
1ab256cb RM |
2505 | } |
2506 | \f | |
173f2a64 RS |
2507 | /* Run the modification-hooks of overlays that include |
2508 | any part of the text in START to END. | |
2509 | Run the insert-before-hooks of overlay starting at END, | |
930a9140 RS |
2510 | and the insert-after-hooks of overlay ending at START. |
2511 | ||
2512 | This is called both before and after the modification. | |
2513 | AFTER is nonzero when we call after the modification. | |
2514 | ||
2515 | ARG1, ARG2, ARG3 are arguments to pass to the hook functions. */ | |
173f2a64 RS |
2516 | |
2517 | void | |
930a9140 | 2518 | report_overlay_modification (start, end, after, arg1, arg2, arg3) |
173f2a64 | 2519 | Lisp_Object start, end; |
930a9140 RS |
2520 | int after; |
2521 | Lisp_Object arg1, arg2, arg3; | |
173f2a64 RS |
2522 | { |
2523 | Lisp_Object prop, overlay, tail; | |
2524 | int insertion = EQ (start, end); | |
55b48893 | 2525 | int tail_copied; |
930a9140 | 2526 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
55b48893 RS |
2527 | |
2528 | overlay = Qnil; | |
2529 | tail = Qnil; | |
930a9140 | 2530 | GCPRO5 (overlay, tail, arg1, arg2, arg3); |
173f2a64 | 2531 | |
55b48893 | 2532 | tail_copied = 0; |
173f2a64 RS |
2533 | for (tail = current_buffer->overlays_before; |
2534 | CONSP (tail); | |
2535 | tail = XCONS (tail)->cdr) | |
2536 | { | |
2537 | int startpos, endpos; | |
be8b1c6b | 2538 | Lisp_Object ostart, oend; |
173f2a64 RS |
2539 | |
2540 | overlay = XCONS (tail)->car; | |
2541 | ||
2542 | ostart = OVERLAY_START (overlay); | |
2543 | oend = OVERLAY_END (overlay); | |
2544 | endpos = OVERLAY_POSITION (oend); | |
2545 | if (XFASTINT (start) > endpos) | |
2546 | break; | |
2547 | startpos = OVERLAY_POSITION (ostart); | |
2548 | if (XFASTINT (end) == startpos && insertion) | |
2549 | { | |
2550 | prop = Foverlay_get (overlay, Qinsert_in_front_hooks); | |
5fb5aa33 RS |
2551 | if (!NILP (prop)) |
2552 | { | |
2553 | /* Copy TAIL in case the hook recenters the overlay lists. */ | |
55b48893 RS |
2554 | if (!tail_copied) |
2555 | tail = Fcopy_sequence (tail); | |
2556 | tail_copied = 1; | |
930a9140 | 2557 | call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); |
5fb5aa33 | 2558 | } |
173f2a64 RS |
2559 | } |
2560 | if (XFASTINT (start) == endpos && insertion) | |
2561 | { | |
2562 | prop = Foverlay_get (overlay, Qinsert_behind_hooks); | |
5fb5aa33 RS |
2563 | if (!NILP (prop)) |
2564 | { | |
55b48893 RS |
2565 | if (!tail_copied) |
2566 | tail = Fcopy_sequence (tail); | |
2567 | tail_copied = 1; | |
930a9140 | 2568 | call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); |
5fb5aa33 | 2569 | } |
173f2a64 | 2570 | } |
3bd13e92 KH |
2571 | /* Test for intersecting intervals. This does the right thing |
2572 | for both insertion and deletion. */ | |
2573 | if (XFASTINT (end) > startpos && XFASTINT (start) < endpos) | |
173f2a64 RS |
2574 | { |
2575 | prop = Foverlay_get (overlay, Qmodification_hooks); | |
5fb5aa33 RS |
2576 | if (!NILP (prop)) |
2577 | { | |
55b48893 RS |
2578 | if (!tail_copied) |
2579 | tail = Fcopy_sequence (tail); | |
2580 | tail_copied = 1; | |
930a9140 | 2581 | call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); |
5fb5aa33 | 2582 | } |
173f2a64 RS |
2583 | } |
2584 | } | |
2585 | ||
55b48893 | 2586 | tail_copied = 0; |
173f2a64 RS |
2587 | for (tail = current_buffer->overlays_after; |
2588 | CONSP (tail); | |
2589 | tail = XCONS (tail)->cdr) | |
2590 | { | |
2591 | int startpos, endpos; | |
be8b1c6b | 2592 | Lisp_Object ostart, oend; |
173f2a64 RS |
2593 | |
2594 | overlay = XCONS (tail)->car; | |
2595 | ||
2596 | ostart = OVERLAY_START (overlay); | |
2597 | oend = OVERLAY_END (overlay); | |
2598 | startpos = OVERLAY_POSITION (ostart); | |
cdf0b096 | 2599 | endpos = OVERLAY_POSITION (oend); |
173f2a64 RS |
2600 | if (XFASTINT (end) < startpos) |
2601 | break; | |
2602 | if (XFASTINT (end) == startpos && insertion) | |
2603 | { | |
2604 | prop = Foverlay_get (overlay, Qinsert_in_front_hooks); | |
5fb5aa33 RS |
2605 | if (!NILP (prop)) |
2606 | { | |
55b48893 RS |
2607 | if (!tail_copied) |
2608 | tail = Fcopy_sequence (tail); | |
2609 | tail_copied = 1; | |
930a9140 | 2610 | call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); |
5fb5aa33 | 2611 | } |
173f2a64 RS |
2612 | } |
2613 | if (XFASTINT (start) == endpos && insertion) | |
2614 | { | |
2615 | prop = Foverlay_get (overlay, Qinsert_behind_hooks); | |
5fb5aa33 RS |
2616 | if (!NILP (prop)) |
2617 | { | |
55b48893 RS |
2618 | if (!tail_copied) |
2619 | tail = Fcopy_sequence (tail); | |
2620 | tail_copied = 1; | |
930a9140 | 2621 | call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); |
5fb5aa33 | 2622 | } |
173f2a64 | 2623 | } |
3bd13e92 KH |
2624 | /* Test for intersecting intervals. This does the right thing |
2625 | for both insertion and deletion. */ | |
2626 | if (XFASTINT (end) > startpos && XFASTINT (start) < endpos) | |
173f2a64 RS |
2627 | { |
2628 | prop = Foverlay_get (overlay, Qmodification_hooks); | |
5fb5aa33 RS |
2629 | if (!NILP (prop)) |
2630 | { | |
55b48893 RS |
2631 | if (!tail_copied) |
2632 | tail = Fcopy_sequence (tail); | |
2633 | tail_copied = 1; | |
930a9140 | 2634 | call_overlay_mod_hooks (prop, overlay, after, arg1, arg2, arg3); |
5fb5aa33 | 2635 | } |
173f2a64 RS |
2636 | } |
2637 | } | |
55b48893 RS |
2638 | |
2639 | UNGCPRO; | |
173f2a64 RS |
2640 | } |
2641 | ||
2642 | static void | |
930a9140 RS |
2643 | call_overlay_mod_hooks (list, overlay, after, arg1, arg2, arg3) |
2644 | Lisp_Object list, overlay; | |
2645 | int after; | |
2646 | Lisp_Object arg1, arg2, arg3; | |
173f2a64 | 2647 | { |
930a9140 RS |
2648 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
2649 | GCPRO4 (list, arg1, arg2, arg3); | |
173f2a64 RS |
2650 | while (!NILP (list)) |
2651 | { | |
930a9140 RS |
2652 | if (NILP (arg3)) |
2653 | call4 (Fcar (list), overlay, after ? Qt : Qnil, arg1, arg2); | |
2654 | else | |
2655 | call5 (Fcar (list), overlay, after ? Qt : Qnil, arg1, arg2, arg3); | |
173f2a64 RS |
2656 | list = Fcdr (list); |
2657 | } | |
2658 | UNGCPRO; | |
2659 | } | |
9d7608b7 KH |
2660 | |
2661 | /* Delete any zero-sized overlays at position POS, if the `evaporate' | |
2662 | property is set. */ | |
2663 | void | |
2664 | evaporate_overlays (pos) | |
2665 | int pos; | |
2666 | { | |
2667 | Lisp_Object tail, overlay, hit_list; | |
2668 | ||
2669 | hit_list = Qnil; | |
2670 | if (pos <= XFASTINT (current_buffer->overlay_center)) | |
2671 | for (tail = current_buffer->overlays_before; CONSP (tail); | |
2672 | tail = XCONS (tail)->cdr) | |
2673 | { | |
2674 | int endpos; | |
2675 | overlay = XCONS (tail)->car; | |
2676 | endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); | |
2677 | if (endpos < pos) | |
2678 | break; | |
2679 | if (endpos == pos && OVERLAY_POSITION (OVERLAY_START (overlay)) == pos | |
2680 | && Foverlay_get (overlay, Qevaporate)) | |
2681 | hit_list = Fcons (overlay, hit_list); | |
2682 | } | |
2683 | else | |
2684 | for (tail = current_buffer->overlays_after; CONSP (tail); | |
2685 | tail = XCONS (tail)->cdr) | |
2686 | { | |
2687 | int startpos; | |
889bf329 | 2688 | overlay = XCONS (tail)->car; |
9d7608b7 KH |
2689 | startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); |
2690 | if (startpos > pos) | |
2691 | break; | |
2692 | if (startpos == pos && OVERLAY_POSITION (OVERLAY_END (overlay)) == pos | |
2693 | && Foverlay_get (overlay, Qevaporate)) | |
2694 | hit_list = Fcons (overlay, hit_list); | |
2695 | } | |
2696 | for (; CONSP (hit_list); hit_list = XCONS (hit_list)->cdr) | |
2697 | Fdelete_overlay (XCONS (hit_list)->car); | |
2698 | } | |
173f2a64 | 2699 | \f |
54dfdeb0 KH |
2700 | /* Somebody has tried to store a value with an unacceptable type |
2701 | into the buffer-local slot with offset OFFSET. */ | |
0fa3ba92 | 2702 | void |
54dfdeb0 KH |
2703 | buffer_slot_type_mismatch (offset) |
2704 | int offset; | |
0fa3ba92 | 2705 | { |
54dfdeb0 | 2706 | Lisp_Object sym; |
0fa3ba92 | 2707 | char *type_name; |
54dfdeb0 | 2708 | sym = *(Lisp_Object *)(offset + (char *)&buffer_local_symbols); |
0fa3ba92 JB |
2709 | switch (XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_types))) |
2710 | { | |
2711 | case Lisp_Int: type_name = "integers"; break; | |
2712 | case Lisp_String: type_name = "strings"; break; | |
0fa3ba92 | 2713 | case Lisp_Symbol: type_name = "symbols"; break; |
0fa3ba92 JB |
2714 | default: |
2715 | abort (); | |
2716 | } | |
2717 | ||
2718 | error ("only %s should be stored in the buffer-local variable %s", | |
54dfdeb0 | 2719 | type_name, XSYMBOL (sym)->name->data); |
0fa3ba92 JB |
2720 | } |
2721 | \f | |
1ab256cb RM |
2722 | init_buffer_once () |
2723 | { | |
2724 | register Lisp_Object tem; | |
2725 | ||
2726 | /* Make sure all markable slots in buffer_defaults | |
2727 | are initialized reasonably, so mark_buffer won't choke. */ | |
2728 | reset_buffer (&buffer_defaults); | |
bcd40520 | 2729 | reset_buffer_local_variables (&buffer_defaults); |
1ab256cb | 2730 | reset_buffer (&buffer_local_symbols); |
bcd40520 | 2731 | reset_buffer_local_variables (&buffer_local_symbols); |
336cd056 RS |
2732 | /* Prevent GC from getting confused. */ |
2733 | buffer_defaults.text = &buffer_defaults.own_text; | |
2734 | buffer_local_symbols.text = &buffer_local_symbols.own_text; | |
2735 | #ifdef USE_TEXT_PROPERTIES | |
2736 | BUF_INTERVALS (&buffer_defaults) = 0; | |
2737 | BUF_INTERVALS (&buffer_local_symbols) = 0; | |
2738 | #endif | |
67180c6a KH |
2739 | XSETBUFFER (Vbuffer_defaults, &buffer_defaults); |
2740 | XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols); | |
1ab256cb RM |
2741 | |
2742 | /* Set up the default values of various buffer slots. */ | |
2743 | /* Must do these before making the first buffer! */ | |
2744 | ||
2745 | /* real setup is done in loaddefs.el */ | |
2746 | buffer_defaults.mode_line_format = build_string ("%-"); | |
2747 | buffer_defaults.abbrev_mode = Qnil; | |
2748 | buffer_defaults.overwrite_mode = Qnil; | |
2749 | buffer_defaults.case_fold_search = Qt; | |
2750 | buffer_defaults.auto_fill_function = Qnil; | |
2751 | buffer_defaults.selective_display = Qnil; | |
2752 | #ifndef old | |
2753 | buffer_defaults.selective_display_ellipses = Qt; | |
2754 | #endif | |
2755 | buffer_defaults.abbrev_table = Qnil; | |
2756 | buffer_defaults.display_table = Qnil; | |
1ab256cb | 2757 | buffer_defaults.undo_list = Qnil; |
c48f61ef | 2758 | buffer_defaults.mark_active = Qnil; |
be9aafdd | 2759 | buffer_defaults.file_format = Qnil; |
2eec3b4e RS |
2760 | buffer_defaults.overlays_before = Qnil; |
2761 | buffer_defaults.overlays_after = Qnil; | |
8d7a4592 | 2762 | XSETFASTINT (buffer_defaults.overlay_center, 1); |
1ab256cb | 2763 | |
8d7a4592 | 2764 | XSETFASTINT (buffer_defaults.tab_width, 8); |
1ab256cb RM |
2765 | buffer_defaults.truncate_lines = Qnil; |
2766 | buffer_defaults.ctl_arrow = Qt; | |
2767 | ||
f7975d07 | 2768 | #ifdef DOS_NT |
0776cb1b | 2769 | buffer_defaults.buffer_file_type = Qnil; /* TEXT */ |
54ad07d3 | 2770 | #endif |
8d7a4592 KH |
2771 | XSETFASTINT (buffer_defaults.fill_column, 70); |
2772 | XSETFASTINT (buffer_defaults.left_margin, 0); | |
28e969dd | 2773 | buffer_defaults.cache_long_line_scans = Qnil; |
f6ed2e84 | 2774 | buffer_defaults.file_truename = Qnil; |
1ab256cb RM |
2775 | |
2776 | /* Assign the local-flags to the slots that have default values. | |
2777 | The local flag is a bit that is used in the buffer | |
2778 | to say that it has its own local value for the slot. | |
2779 | The local flag bits are in the local_var_flags slot of the buffer. */ | |
2780 | ||
2781 | /* Nothing can work if this isn't true */ | |
4d2f1389 | 2782 | if (sizeof (EMACS_INT) != sizeof (Lisp_Object)) abort (); |
1ab256cb RM |
2783 | |
2784 | /* 0 means not a lisp var, -1 means always local, else mask */ | |
2785 | bzero (&buffer_local_flags, sizeof buffer_local_flags); | |
aab80822 KH |
2786 | XSETINT (buffer_local_flags.filename, -1); |
2787 | XSETINT (buffer_local_flags.directory, -1); | |
2788 | XSETINT (buffer_local_flags.backed_up, -1); | |
2789 | XSETINT (buffer_local_flags.save_length, -1); | |
2790 | XSETINT (buffer_local_flags.auto_save_file_name, -1); | |
2791 | XSETINT (buffer_local_flags.read_only, -1); | |
2792 | XSETINT (buffer_local_flags.major_mode, -1); | |
2793 | XSETINT (buffer_local_flags.mode_name, -1); | |
2794 | XSETINT (buffer_local_flags.undo_list, -1); | |
2795 | XSETINT (buffer_local_flags.mark_active, -1); | |
943e065b | 2796 | XSETINT (buffer_local_flags.point_before_scroll, -1); |
f6ed2e84 | 2797 | XSETINT (buffer_local_flags.file_truename, -1); |
3cb719bd | 2798 | XSETINT (buffer_local_flags.invisibility_spec, -1); |
8d7a4592 KH |
2799 | |
2800 | XSETFASTINT (buffer_local_flags.mode_line_format, 1); | |
2801 | XSETFASTINT (buffer_local_flags.abbrev_mode, 2); | |
2802 | XSETFASTINT (buffer_local_flags.overwrite_mode, 4); | |
2803 | XSETFASTINT (buffer_local_flags.case_fold_search, 8); | |
2804 | XSETFASTINT (buffer_local_flags.auto_fill_function, 0x10); | |
2805 | XSETFASTINT (buffer_local_flags.selective_display, 0x20); | |
1ab256cb | 2806 | #ifndef old |
8d7a4592 | 2807 | XSETFASTINT (buffer_local_flags.selective_display_ellipses, 0x40); |
1ab256cb | 2808 | #endif |
8d7a4592 KH |
2809 | XSETFASTINT (buffer_local_flags.tab_width, 0x80); |
2810 | XSETFASTINT (buffer_local_flags.truncate_lines, 0x100); | |
2811 | XSETFASTINT (buffer_local_flags.ctl_arrow, 0x200); | |
2812 | XSETFASTINT (buffer_local_flags.fill_column, 0x400); | |
2813 | XSETFASTINT (buffer_local_flags.left_margin, 0x800); | |
2814 | XSETFASTINT (buffer_local_flags.abbrev_table, 0x1000); | |
2815 | XSETFASTINT (buffer_local_flags.display_table, 0x2000); | |
2816 | XSETFASTINT (buffer_local_flags.syntax_table, 0x8000); | |
28e969dd | 2817 | XSETFASTINT (buffer_local_flags.cache_long_line_scans, 0x10000); |
be9aafdd | 2818 | XSETFASTINT (buffer_local_flags.file_format, 0x20000); |
f7975d07 | 2819 | #ifdef DOS_NT |
8d7a4592 | 2820 | XSETFASTINT (buffer_local_flags.buffer_file_type, 0x4000); |
54ad07d3 | 2821 | #endif |
1ab256cb RM |
2822 | |
2823 | Vbuffer_alist = Qnil; | |
2824 | current_buffer = 0; | |
2825 | all_buffers = 0; | |
2826 | ||
2827 | QSFundamental = build_string ("Fundamental"); | |
2828 | ||
2829 | Qfundamental_mode = intern ("fundamental-mode"); | |
2830 | buffer_defaults.major_mode = Qfundamental_mode; | |
2831 | ||
2832 | Qmode_class = intern ("mode-class"); | |
2833 | ||
2834 | Qprotected_field = intern ("protected-field"); | |
2835 | ||
2836 | Qpermanent_local = intern ("permanent-local"); | |
2837 | ||
2838 | Qkill_buffer_hook = intern ("kill-buffer-hook"); | |
2839 | ||
2840 | Vprin1_to_string_buffer = Fget_buffer_create (build_string (" prin1")); | |
2841 | /* super-magic invisible buffer */ | |
2842 | Vbuffer_alist = Qnil; | |
2843 | ||
ffd56f97 | 2844 | Fset_buffer (Fget_buffer_create (build_string ("*scratch*"))); |
1ab256cb RM |
2845 | } |
2846 | ||
2847 | init_buffer () | |
2848 | { | |
2849 | char buf[MAXPATHLEN+1]; | |
2381d133 JB |
2850 | char *pwd; |
2851 | struct stat dotstat, pwdstat; | |
136351b7 | 2852 | Lisp_Object temp; |
f7975d07 | 2853 | int rc; |
1ab256cb RM |
2854 | |
2855 | Fset_buffer (Fget_buffer_create (build_string ("*scratch*"))); | |
2381d133 JB |
2856 | |
2857 | /* If PWD is accurate, use it instead of calling getwd. This is faster | |
2858 | when PWD is right, and may avoid a fatal error. */ | |
f7975d07 | 2859 | if ((pwd = getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd) |
2381d133 JB |
2860 | && stat (pwd, &pwdstat) == 0 |
2861 | && stat (".", &dotstat) == 0 | |
2862 | && dotstat.st_ino == pwdstat.st_ino | |
2863 | && dotstat.st_dev == pwdstat.st_dev | |
2864 | && strlen (pwd) < MAXPATHLEN) | |
2865 | strcpy (buf, pwd); | |
2866 | else if (getwd (buf) == 0) | |
cf1e6391 | 2867 | fatal ("`getwd' failed: %s\n", buf); |
1ab256cb RM |
2868 | |
2869 | #ifndef VMS | |
2870 | /* Maybe this should really use some standard subroutine | |
2871 | whose definition is filename syntax dependent. */ | |
f7975d07 RS |
2872 | rc = strlen (buf); |
2873 | if (!(IS_DIRECTORY_SEP (buf[rc - 1]))) | |
2874 | { | |
2875 | buf[rc] = DIRECTORY_SEP; | |
2876 | buf[rc + 1] = '\0'; | |
2877 | } | |
1ab256cb RM |
2878 | #endif /* not VMS */ |
2879 | current_buffer->directory = build_string (buf); | |
136351b7 RS |
2880 | |
2881 | temp = get_minibuffer (0); | |
2882 | XBUFFER (temp)->directory = current_buffer->directory; | |
1ab256cb RM |
2883 | } |
2884 | ||
2885 | /* initialize the buffer routines */ | |
2886 | syms_of_buffer () | |
2887 | { | |
188d4d11 RM |
2888 | extern Lisp_Object Qdisabled; |
2889 | ||
1ab256cb RM |
2890 | staticpro (&Vbuffer_defaults); |
2891 | staticpro (&Vbuffer_local_symbols); | |
2892 | staticpro (&Qfundamental_mode); | |
2893 | staticpro (&Qmode_class); | |
2894 | staticpro (&QSFundamental); | |
2895 | staticpro (&Vbuffer_alist); | |
2896 | staticpro (&Qprotected_field); | |
2897 | staticpro (&Qpermanent_local); | |
2898 | staticpro (&Qkill_buffer_hook); | |
52f8ec73 | 2899 | staticpro (&Qoverlayp); |
9d7608b7 KH |
2900 | Qevaporate = intern ("evaporate"); |
2901 | staticpro (&Qevaporate); | |
294d215f RS |
2902 | staticpro (&Qmodification_hooks); |
2903 | Qmodification_hooks = intern ("modification-hooks"); | |
2904 | staticpro (&Qinsert_in_front_hooks); | |
2905 | Qinsert_in_front_hooks = intern ("insert-in-front-hooks"); | |
2906 | staticpro (&Qinsert_behind_hooks); | |
2907 | Qinsert_behind_hooks = intern ("insert-behind-hooks"); | |
5fe0b67e RS |
2908 | staticpro (&Qget_file_buffer); |
2909 | Qget_file_buffer = intern ("get-file-buffer"); | |
5985d248 KH |
2910 | Qpriority = intern ("priority"); |
2911 | staticpro (&Qpriority); | |
2912 | Qwindow = intern ("window"); | |
2913 | staticpro (&Qwindow); | |
52f8ec73 JB |
2914 | |
2915 | Qoverlayp = intern ("overlayp"); | |
1ab256cb RM |
2916 | |
2917 | Fput (Qprotected_field, Qerror_conditions, | |
2918 | Fcons (Qprotected_field, Fcons (Qerror, Qnil))); | |
2919 | Fput (Qprotected_field, Qerror_message, | |
2920 | build_string ("Attempt to modify a protected field")); | |
2921 | ||
2922 | /* All these use DEFVAR_LISP_NOPRO because the slots in | |
2923 | buffer_defaults will all be marked via Vbuffer_defaults. */ | |
2924 | ||
2925 | DEFVAR_LISP_NOPRO ("default-mode-line-format", | |
2926 | &buffer_defaults.mode_line_format, | |
2927 | "Default value of `mode-line-format' for buffers that don't override it.\n\ | |
2928 | This is the same as (default-value 'mode-line-format)."); | |
2929 | ||
2930 | DEFVAR_LISP_NOPRO ("default-abbrev-mode", | |
2931 | &buffer_defaults.abbrev_mode, | |
2932 | "Default value of `abbrev-mode' for buffers that do not override it.\n\ | |
2933 | This is the same as (default-value 'abbrev-mode)."); | |
2934 | ||
2935 | DEFVAR_LISP_NOPRO ("default-ctl-arrow", | |
2936 | &buffer_defaults.ctl_arrow, | |
2937 | "Default value of `ctl-arrow' for buffers that do not override it.\n\ | |
2938 | This is the same as (default-value 'ctl-arrow)."); | |
2939 | ||
2940 | DEFVAR_LISP_NOPRO ("default-truncate-lines", | |
2941 | &buffer_defaults.truncate_lines, | |
2942 | "Default value of `truncate-lines' for buffers that do not override it.\n\ | |
2943 | This is the same as (default-value 'truncate-lines)."); | |
2944 | ||
2945 | DEFVAR_LISP_NOPRO ("default-fill-column", | |
2946 | &buffer_defaults.fill_column, | |
2947 | "Default value of `fill-column' for buffers that do not override it.\n\ | |
2948 | This is the same as (default-value 'fill-column)."); | |
2949 | ||
2950 | DEFVAR_LISP_NOPRO ("default-left-margin", | |
2951 | &buffer_defaults.left_margin, | |
2952 | "Default value of `left-margin' for buffers that do not override it.\n\ | |
2953 | This is the same as (default-value 'left-margin)."); | |
2954 | ||
2955 | DEFVAR_LISP_NOPRO ("default-tab-width", | |
2956 | &buffer_defaults.tab_width, | |
2957 | "Default value of `tab-width' for buffers that do not override it.\n\ | |
2958 | This is the same as (default-value 'tab-width)."); | |
2959 | ||
2960 | DEFVAR_LISP_NOPRO ("default-case-fold-search", | |
2961 | &buffer_defaults.case_fold_search, | |
2962 | "Default value of `case-fold-search' for buffers that don't override it.\n\ | |
2963 | This is the same as (default-value 'case-fold-search)."); | |
2964 | ||
f7975d07 | 2965 | #ifdef DOS_NT |
54ad07d3 RS |
2966 | DEFVAR_LISP_NOPRO ("default-buffer-file-type", |
2967 | &buffer_defaults.buffer_file_type, | |
2968 | "Default file type for buffers that do not override it.\n\ | |
2969 | This is the same as (default-value 'buffer-file-type).\n\ | |
2970 | The file type is nil for text, t for binary."); | |
2971 | #endif | |
2972 | ||
0fa3ba92 JB |
2973 | DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format, |
2974 | Qnil, 0); | |
1ab256cb RM |
2975 | |
2976 | /* This doc string is too long for cpp; cpp dies if it isn't in a comment. | |
2977 | But make-docfile finds it! | |
2978 | DEFVAR_PER_BUFFER ("mode-line-format", ¤t_buffer->mode_line_format, | |
bec44fd6 | 2979 | Qnil, |
1ab256cb RM |
2980 | "Template for displaying mode line for current buffer.\n\ |
2981 | Each buffer has its own value of this variable.\n\ | |
2982 | Value may be a string, a symbol or a list or cons cell.\n\ | |
2983 | For a symbol, its value is used (but it is ignored if t or nil).\n\ | |
2984 | A string appearing directly as the value of a symbol is processed verbatim\n\ | |
2985 | in that the %-constructs below are not recognized.\n\ | |
2986 | For a list whose car is a symbol, the symbol's value is taken,\n\ | |
2987 | and if that is non-nil, the cadr of the list is processed recursively.\n\ | |
2988 | Otherwise, the caddr of the list (if there is one) is processed.\n\ | |
2989 | For a list whose car is a string or list, each element is processed\n\ | |
2990 | recursively and the results are effectively concatenated.\n\ | |
2991 | For a list whose car is an integer, the cdr of the list is processed\n\ | |
2992 | and padded (if the number is positive) or truncated (if negative)\n\ | |
2993 | to the width specified by that number.\n\ | |
2994 | A string is printed verbatim in the mode line except for %-constructs:\n\ | |
2995 | (%-constructs are allowed when the string is the entire mode-line-format\n\ | |
2996 | or when it is found in a cons-cell or a list)\n\ | |
2997 | %b -- print buffer name. %f -- print visited file name.\n\ | |
c2ff34f7 RS |
2998 | %* -- print %, * or hyphen. %+ -- print *, % or hyphen.\n\ |
2999 | % means buffer is read-only and * means it is modified.\n\ | |
3000 | For a modified read-only buffer, %* gives % and %+ gives *.\n\ | |
a97c374a | 3001 | %s -- print process status. %l -- print the current line number.\n\ |
dd24e6a6 | 3002 | %p -- print percent of buffer above top of window, or Top, Bot or All.\n\ |
9d130ffc | 3003 | %P -- print percent of buffer above bottom of window, perhaps plus Top,\n\ |
dd24e6a6 | 3004 | or print Bottom or All.\n\ |
1ab256cb | 3005 | %n -- print Narrow if appropriate.\n\ |
54ad07d3 | 3006 | %t -- print T if files is text, B if binary.\n\ |
1ab256cb RM |
3007 | %[ -- print one [ for each recursive editing level. %] similar.\n\ |
3008 | %% -- print %. %- -- print infinitely many dashes.\n\ | |
3009 | Decimal digits after the % specify field width to which to pad."); | |
3010 | */ | |
3011 | ||
3012 | DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults.major_mode, | |
3013 | "*Major mode for new buffers. Defaults to `fundamental-mode'.\n\ | |
3014 | nil here means use current buffer's major mode."); | |
3015 | ||
3016 | DEFVAR_PER_BUFFER ("major-mode", ¤t_buffer->major_mode, | |
0fa3ba92 | 3017 | make_number (Lisp_Symbol), |
1ab256cb RM |
3018 | "Symbol for current buffer's major mode."); |
3019 | ||
3020 | DEFVAR_PER_BUFFER ("mode-name", ¤t_buffer->mode_name, | |
0fa3ba92 | 3021 | make_number (Lisp_String), |
1ab256cb RM |
3022 | "Pretty name of current buffer's major mode (a string)."); |
3023 | ||
0fa3ba92 | 3024 | DEFVAR_PER_BUFFER ("abbrev-mode", ¤t_buffer->abbrev_mode, Qnil, |
1ab256cb RM |
3025 | "Non-nil turns on automatic expansion of abbrevs as they are inserted.\n\ |
3026 | Automatically becomes buffer-local when set in any fashion."); | |
3027 | ||
3028 | DEFVAR_PER_BUFFER ("case-fold-search", ¤t_buffer->case_fold_search, | |
0fa3ba92 | 3029 | Qnil, |
1ab256cb RM |
3030 | "*Non-nil if searches should ignore case.\n\ |
3031 | Automatically becomes buffer-local when set in any fashion."); | |
3032 | ||
3033 | DEFVAR_PER_BUFFER ("fill-column", ¤t_buffer->fill_column, | |
0fa3ba92 | 3034 | make_number (Lisp_Int), |
1ab256cb RM |
3035 | "*Column beyond which automatic line-wrapping should happen.\n\ |
3036 | Automatically becomes buffer-local when set in any fashion."); | |
3037 | ||
3038 | DEFVAR_PER_BUFFER ("left-margin", ¤t_buffer->left_margin, | |
0fa3ba92 | 3039 | make_number (Lisp_Int), |
1ab256cb RM |
3040 | "*Column for the default indent-line-function to indent to.\n\ |
3041 | Linefeed indents to this column in Fundamental mode.\n\ | |
3042 | Automatically becomes buffer-local when set in any fashion."); | |
3043 | ||
3044 | DEFVAR_PER_BUFFER ("tab-width", ¤t_buffer->tab_width, | |
0fa3ba92 | 3045 | make_number (Lisp_Int), |
1ab256cb RM |
3046 | "*Distance between tab stops (for display of tab characters), in columns.\n\ |
3047 | Automatically becomes buffer-local when set in any fashion."); | |
3048 | ||
0fa3ba92 | 3049 | DEFVAR_PER_BUFFER ("ctl-arrow", ¤t_buffer->ctl_arrow, Qnil, |
1ab256cb RM |
3050 | "*Non-nil means display control chars with uparrow.\n\ |
3051 | Nil means use backslash and octal digits.\n\ | |
3052 | Automatically becomes buffer-local when set in any fashion.\n\ | |
3053 | This variable does not apply to characters whose display is specified\n\ | |
3054 | in the current display table (if there is one)."); | |
3055 | ||
0fa3ba92 | 3056 | DEFVAR_PER_BUFFER ("truncate-lines", ¤t_buffer->truncate_lines, Qnil, |
1ab256cb RM |
3057 | "*Non-nil means do not display continuation lines;\n\ |
3058 | give each line of text one screen line.\n\ | |
3059 | Automatically becomes buffer-local when set in any fashion.\n\ | |
3060 | \n\ | |
3061 | Note that this is overridden by the variable\n\ | |
3062 | `truncate-partial-width-windows' if that variable is non-nil\n\ | |
502b9b64 | 3063 | and this buffer is not full-frame width."); |
1ab256cb | 3064 | |
f7975d07 | 3065 | #ifdef DOS_NT |
54ad07d3 RS |
3066 | DEFVAR_PER_BUFFER ("buffer-file-type", ¤t_buffer->buffer_file_type, |
3067 | Qnil, | |
006d3d34 RS |
3068 | "Non-nil if the visited file is a binary file.\n\ |
3069 | This variable is meaningful on MS-DOG and Windows NT.\n\ | |
3070 | On those systems, it is automatically local in every buffer.\n\ | |
e0585c64 | 3071 | On other systems, this variable is normally always nil."); |
54ad07d3 RS |
3072 | #endif |
3073 | ||
1ab256cb | 3074 | DEFVAR_PER_BUFFER ("default-directory", ¤t_buffer->directory, |
0fa3ba92 | 3075 | make_number (Lisp_String), |
1ab256cb RM |
3076 | "Name of default directory of current buffer. Should end with slash.\n\ |
3077 | Each buffer has its own value of this variable."); | |
3078 | ||
3079 | DEFVAR_PER_BUFFER ("auto-fill-function", ¤t_buffer->auto_fill_function, | |
0fa3ba92 | 3080 | Qnil, |
1ab256cb RM |
3081 | "Function called (if non-nil) to perform auto-fill.\n\ |
3082 | It is called after self-inserting a space at a column beyond `fill-column'.\n\ | |
3083 | Each buffer has its own value of this variable.\n\ | |
3084 | NOTE: This variable is not an ordinary hook;\n\ | |
3085 | It may not be a list of functions."); | |
3086 | ||
3087 | DEFVAR_PER_BUFFER ("buffer-file-name", ¤t_buffer->filename, | |
0fa3ba92 | 3088 | make_number (Lisp_String), |
1ab256cb RM |
3089 | "Name of file visited in current buffer, or nil if not visiting a file.\n\ |
3090 | Each buffer has its own value of this variable."); | |
3091 | ||
f6ed2e84 RS |
3092 | DEFVAR_PER_BUFFER ("buffer-file-truename", ¤t_buffer->file_truename, |
3093 | make_number (Lisp_String), | |
3094 | "Truename of file visited in current buffer, or nil if not visiting a file.\n\ | |
3095 | The truename of a file is calculated by `file-truename'.\n\ | |
3096 | Each buffer has its own value of this variable."); | |
3097 | ||
1ab256cb | 3098 | DEFVAR_PER_BUFFER ("buffer-auto-save-file-name", |
3f5fcd47 | 3099 | ¤t_buffer->auto_save_file_name, |
0fa3ba92 | 3100 | make_number (Lisp_String), |
1ab256cb RM |
3101 | "Name of file for auto-saving current buffer,\n\ |
3102 | or nil if buffer should not be auto-saved.\n\ | |
3103 | Each buffer has its own value of this variable."); | |
3104 | ||
0fa3ba92 | 3105 | DEFVAR_PER_BUFFER ("buffer-read-only", ¤t_buffer->read_only, Qnil, |
1ab256cb RM |
3106 | "Non-nil if this buffer is read-only.\n\ |
3107 | Each buffer has its own value of this variable."); | |
3108 | ||
0fa3ba92 | 3109 | DEFVAR_PER_BUFFER ("buffer-backed-up", ¤t_buffer->backed_up, Qnil, |
1ab256cb RM |
3110 | "Non-nil if this buffer's file has been backed up.\n\ |
3111 | Backing up is done before the first time the file is saved.\n\ | |
3112 | Each buffer has its own value of this variable."); | |
3113 | ||
3114 | DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer->save_length, | |
0fa3ba92 | 3115 | make_number (Lisp_Int), |
1ab256cb RM |
3116 | "Length of current buffer when last read in, saved or auto-saved.\n\ |
3117 | 0 initially.\n\ | |
3118 | Each buffer has its own value of this variable."); | |
3119 | ||
3120 | DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer->selective_display, | |
0fa3ba92 | 3121 | Qnil, |
1ab256cb RM |
3122 | "Non-nil enables selective display:\n\ |
3123 | Integer N as value means display only lines\n\ | |
3124 | that start with less than n columns of space.\n\ | |
3125 | A value of t means, after a ^M, all the rest of the line is invisible.\n\ | |
3126 | Then ^M's in the file are written into files as newlines.\n\n\ | |
3127 | Automatically becomes buffer-local when set in any fashion."); | |
3128 | ||
3129 | #ifndef old | |
3130 | DEFVAR_PER_BUFFER ("selective-display-ellipses", | |
3131 | ¤t_buffer->selective_display_ellipses, | |
0fa3ba92 | 3132 | Qnil, |
1ab256cb RM |
3133 | "t means display ... on previous line when a line is invisible.\n\ |
3134 | Automatically becomes buffer-local when set in any fashion."); | |
3135 | #endif | |
3136 | ||
0fa3ba92 | 3137 | DEFVAR_PER_BUFFER ("overwrite-mode", ¤t_buffer->overwrite_mode, Qnil, |
1ab256cb | 3138 | "Non-nil if self-insertion should replace existing text.\n\ |
5e05d0a5 RS |
3139 | The value should be one of `overwrite-mode-textual',\n\ |
3140 | `overwrite-mode-binary', or nil.\n\ | |
3141 | If it is `overwrite-mode-textual', self-insertion still\n\ | |
6bbb0d4a | 3142 | inserts at the end of a line, and inserts when point is before a tab,\n\ |
2e94b813 | 3143 | until the tab is filled in.\n\ |
6bbb0d4a | 3144 | If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\ |
1ab256cb RM |
3145 | Automatically becomes buffer-local when set in any fashion."); |
3146 | ||
54939090 RS |
3147 | #if 0 /* The doc string is too long for some compilers, |
3148 | but make-docfile can find it in this comment. */ | |
1ab256cb | 3149 | DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer->display_table, |
5d305367 | 3150 | Qnil, |
1ab256cb RM |
3151 | "Display table that controls display of the contents of current buffer.\n\ |
3152 | Automatically becomes buffer-local when set in any fashion.\n\ | |
3153 | The display table is a vector created with `make-display-table'.\n\ | |
3154 | The first 256 elements control how to display each possible text character.\n\ | |
6158b3b0 | 3155 | Each value should be a vector of characters or nil;\n\ |
1ab256cb | 3156 | nil means display the character in the default fashion.\n\ |
a45e35e1 | 3157 | The remaining six elements control the display of\n\ |
6158b3b0 JB |
3158 | the end of a truncated screen line (element 256, a single character);\n\ |
3159 | the end of a continued line (element 257, a single character);\n\ | |
3160 | the escape character used to display character codes in octal\n\ | |
3161 | (element 258, a single character);\n\ | |
3162 | the character used as an arrow for control characters (element 259,\n\ | |
3163 | a single character);\n\ | |
3164 | the decoration indicating the presence of invisible lines (element 260,\n\ | |
a45e35e1 JB |
3165 | a vector of characters);\n\ |
3166 | the character used to draw the border between side-by-side windows\n\ | |
3402827c | 3167 | (element 261, a single character).\n\ |
1ab256cb RM |
3168 | If this variable is nil, the value of `standard-display-table' is used.\n\ |
3169 | Each window can have its own, overriding display table."); | |
54939090 RS |
3170 | #endif |
3171 | DEFVAR_PER_BUFFER ("buffer-display-table", ¤t_buffer->display_table, | |
de15914a | 3172 | Qnil, 0); |
1ab256cb | 3173 | |
1ab256cb RM |
3174 | /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol, |
3175 | "Don't ask."); | |
3176 | */ | |
01050cb5 | 3177 | DEFVAR_LISP ("before-change-function", &Vbefore_change_function, |
1ab256cb RM |
3178 | "Function to call before each text change.\n\ |
3179 | Two arguments are passed to the function: the positions of\n\ | |
3180 | the beginning and end of the range of old text to be changed.\n\ | |
3181 | \(For an insertion, the beginning and end are at the same place.)\n\ | |
3182 | No information is given about the length of the text after the change.\n\ | |
1ab256cb | 3183 | \n\ |
5f079267 | 3184 | Buffer changes made while executing the `before-change-function'\n\ |
b86344d0 RS |
3185 | don't call any before-change or after-change functions.\n\ |
3186 | That's because these variables are temporarily set to nil.\n\ | |
3187 | As a result, a hook function cannot straightforwardly alter the value of\n\ | |
3188 | these variables. See the Emacs Lisp manual for a way of\n\ | |
d59698c4 | 3189 | accomplishing an equivalent result by using other variables."); |
1ab256cb RM |
3190 | Vbefore_change_function = Qnil; |
3191 | ||
3192 | DEFVAR_LISP ("after-change-function", &Vafter_change_function, | |
3193 | "Function to call after each text change.\n\ | |
3194 | Three arguments are passed to the function: the positions of\n\ | |
3195 | the beginning and end of the range of changed text,\n\ | |
3196 | and the length of the pre-change text replaced by that range.\n\ | |
3197 | \(For an insertion, the pre-change length is zero;\n\ | |
3198 | for a deletion, that length is the number of characters deleted,\n\ | |
3199 | and the post-change beginning and end are at the same place.)\n\ | |
3200 | \n\ | |
5f079267 | 3201 | Buffer changes made while executing the `after-change-function'\n\ |
b86344d0 RS |
3202 | don't call any before-change or after-change functions.\n\ |
3203 | That's because these variables are temporarily set to nil.\n\ | |
3204 | As a result, a hook function cannot straightforwardly alter the value of\n\ | |
3205 | these variables. See the Emacs Lisp manual for a way of\n\ | |
d59698c4 | 3206 | accomplishing an equivalent result by using other variables."); |
1ab256cb RM |
3207 | Vafter_change_function = Qnil; |
3208 | ||
5f079267 RS |
3209 | DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions, |
3210 | "List of functions to call before each text change.\n\ | |
3211 | Two arguments are passed to each function: the positions of\n\ | |
3212 | the beginning and end of the range of old text to be changed.\n\ | |
3213 | \(For an insertion, the beginning and end are at the same place.)\n\ | |
3214 | No information is given about the length of the text after the change.\n\ | |
5f079267 RS |
3215 | \n\ |
3216 | Buffer changes made while executing the `before-change-functions'\n\ | |
b86344d0 RS |
3217 | don't call any before-change or after-change functions.\n\ |
3218 | That's because these variables are temporarily set to nil.\n\ | |
3219 | As a result, a hook function cannot straightforwardly alter the value of\n\ | |
3220 | these variables. See the Emacs Lisp manual for a way of\n\ | |
d59698c4 | 3221 | accomplishing an equivalent result by using other variables."); |
5f079267 RS |
3222 | Vbefore_change_functions = Qnil; |
3223 | ||
3224 | DEFVAR_LISP ("after-change-functions", &Vafter_change_functions, | |
3225 | "List of function to call after each text change.\n\ | |
3226 | Three arguments are passed to each function: the positions of\n\ | |
3227 | the beginning and end of the range of changed text,\n\ | |
3228 | and the length of the pre-change text replaced by that range.\n\ | |
3229 | \(For an insertion, the pre-change length is zero;\n\ | |
3230 | for a deletion, that length is the number of characters deleted,\n\ | |
3231 | and the post-change beginning and end are at the same place.)\n\ | |
3232 | \n\ | |
3233 | Buffer changes made while executing the `after-change-functions'\n\ | |
b86344d0 RS |
3234 | don't call any before-change or after-change functions.\n\ |
3235 | That's because these variables are temporarily set to nil.\n\ | |
3236 | As a result, a hook function cannot straightforwardly alter the value of\n\ | |
3237 | these variables. See the Emacs Lisp manual for a way of\n\ | |
d59698c4 | 3238 | accomplishing an equivalent result by using other variables."); |
b86344d0 | 3239 | |
5f079267 RS |
3240 | Vafter_change_functions = Qnil; |
3241 | ||
dbc4e1c1 JB |
3242 | DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook, |
3243 | "A list of functions to call before changing a buffer which is unmodified.\n\ | |
3244 | The functions are run using the `run-hooks' function."); | |
3245 | Vfirst_change_hook = Qnil; | |
3246 | Qfirst_change_hook = intern ("first-change-hook"); | |
3247 | staticpro (&Qfirst_change_hook); | |
1ab256cb | 3248 | |
54939090 RS |
3249 | #if 0 /* The doc string is too long for some compilers, |
3250 | but make-docfile can find it in this comment. */ | |
3f5fcd47 | 3251 | DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer->undo_list, Qnil, |
1ab256cb RM |
3252 | "List of undo entries in current buffer.\n\ |
3253 | Recent changes come first; older changes follow newer.\n\ | |
3254 | \n\ | |
3255 | An entry (START . END) represents an insertion which begins at\n\ | |
3256 | position START and ends at position END.\n\ | |
3257 | \n\ | |
3258 | An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\ | |
3259 | from (abs POSITION). If POSITION is positive, point was at the front\n\ | |
3260 | of the text being deleted; if negative, point was at the end.\n\ | |
3261 | \n\ | |
6c0df54a RS |
3262 | An entry (t HIGH . LOW) indicates that the buffer previously had\n\ |
3263 | \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions\n\ | |
3264 | of the visited file's modification time, as of that time. If the\n\ | |
3265 | modification time of the most recent save is different, this entry is\n\ | |
1ab256cb RM |
3266 | obsolete.\n\ |
3267 | \n\ | |
6c0df54a RS |
3268 | An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\ |
3269 | was modified between BEG and END. PROPERTY is the property name,\n\ | |
3270 | and VALUE is the old value.\n\ | |
483c1fd3 | 3271 | \n\ |
bec44fd6 JB |
3272 | An entry of the form POSITION indicates that point was at the buffer\n\ |
3273 | location given by the integer. Undoing an entry of this form places\n\ | |
3274 | point at POSITION.\n\ | |
3275 | \n\ | |
1ab256cb RM |
3276 | nil marks undo boundaries. The undo command treats the changes\n\ |
3277 | between two undo boundaries as a single step to be undone.\n\ | |
3278 | \n\ | |
bec44fd6 | 3279 | If the value of the variable is t, undo information is not recorded."); |
54939090 RS |
3280 | #endif |
3281 | DEFVAR_PER_BUFFER ("buffer-undo-list", ¤t_buffer->undo_list, Qnil, | |
de15914a | 3282 | 0); |
1ab256cb | 3283 | |
c48f61ef RS |
3284 | DEFVAR_PER_BUFFER ("mark-active", ¤t_buffer->mark_active, Qnil, |
3285 | "Non-nil means the mark and region are currently active in this buffer.\n\ | |
3286 | Automatically local in all buffers."); | |
3287 | ||
28e969dd | 3288 | DEFVAR_PER_BUFFER ("cache-long-line-scans", ¤t_buffer->cache_long_line_scans, Qnil, |
f0c5b712 JB |
3289 | "Non-nil means that Emacs should use caches to handle long lines more quickly.\n\ |
3290 | This variable is buffer-local, in all buffers.\n\ | |
28e969dd | 3291 | \n\ |
f0c5b712 JB |
3292 | Normally, the line-motion functions work by scanning the buffer for\n\ |
3293 | newlines. Columnar operations (like move-to-column and\n\ | |
3294 | compute-motion) also work by scanning the buffer, summing character\n\ | |
3295 | widths as they go. This works well for ordinary text, but if the\n\ | |
28e969dd | 3296 | buffer's lines are very long (say, more than 500 characters), these\n\ |
f0c5b712 JB |
3297 | motion functions will take longer to execute. Emacs may also take\n\ |
3298 | longer to update the display.\n\ | |
28e969dd | 3299 | \n\ |
f0c5b712 JB |
3300 | If cache-long-line-scans is non-nil, these motion functions cache the\n\ |
3301 | results of their scans, and consult the cache to avoid rescanning\n\ | |
3302 | regions of the buffer until the text is modified. The caches are most\n\ | |
3303 | beneficial when they prevent the most searching---that is, when the\n\ | |
3304 | buffer contains long lines and large regions of characters with the\n\ | |
3305 | same, fixed screen width.\n\ | |
28e969dd | 3306 | \n\ |
f0c5b712 JB |
3307 | When cache-long-line-scans is non-nil, processing short lines will\n\ |
3308 | become slightly slower (because of the overhead of consulting the\n\ | |
3309 | cache), and the caches will use memory roughly proportional to the\n\ | |
3310 | number of newlines and characters whose screen width varies.\n\ | |
3311 | \n\ | |
3312 | The caches require no explicit maintenance; their accuracy is\n\ | |
3313 | maintained internally by the Emacs primitives. Enabling or disabling\n\ | |
3314 | the cache should not affect the behavior of any of the motion\n\ | |
3315 | functions; it should only affect their performance."); | |
28e969dd | 3316 | |
943e065b RS |
3317 | DEFVAR_PER_BUFFER ("point-before-scroll", ¤t_buffer->point_before_scroll, Qnil, |
3318 | "Value of point before the last series of scroll operations, or nil."); | |
3319 | ||
be9aafdd BG |
3320 | DEFVAR_PER_BUFFER ("buffer-file-format", ¤t_buffer->file_format, Qnil, |
3321 | "List of formats to use when saving this buffer.\n\ | |
3322 | Formats are defined by `format-alist'. This variable is\n\ | |
3323 | set when a file is visited. Automatically local in all buffers."); | |
3324 | ||
3cb719bd RS |
3325 | DEFVAR_PER_BUFFER ("buffer-invisibility-spec", |
3326 | ¤t_buffer->invisibility_spec, Qnil, | |
3327 | "Invisibility spec of this buffer.\n\ | |
3328 | The default is t, which means that text is invisible\n\ | |
3329 | if it has a non-nil `invisible' property.\n\ | |
3330 | If the value is a list, a text character is invisible if its `invisible'\n\ | |
3331 | property is an element in that list.\n\ | |
554216ad KH |
3332 | If an element is a cons cell of the form (PROP . ELLIPSIS),\n\ |
3333 | then characters with property value PROP are invisible,\n\ | |
3cb719bd RS |
3334 | and they have an ellipsis as well if ELLIPSIS is non-nil."); |
3335 | ||
c48f61ef RS |
3336 | DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode, |
3337 | "*Non-nil means deactivate the mark when the buffer contents change."); | |
3338 | Vtransient_mark_mode = Qnil; | |
3339 | ||
0a4469c9 | 3340 | DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only, |
a96b68f1 RS |
3341 | "*Non-nil means disregard read-only status of buffers or characters.\n\ |
3342 | If the value is t, disregard `buffer-read-only' and all `read-only'\n\ | |
3343 | text properties. If the value is a list, disregard `buffer-read-only'\n\ | |
3344 | and disregard a `read-only' text property if the property value\n\ | |
3345 | is a member of the list."); | |
3346 | Vinhibit_read_only = Qnil; | |
3347 | ||
dcdffbf6 RS |
3348 | DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions, |
3349 | "List of functions called with no args to query before killing a buffer."); | |
3350 | Vkill_buffer_query_functions = Qnil; | |
3351 | ||
1ab256cb RM |
3352 | defsubr (&Sbuffer_list); |
3353 | defsubr (&Sget_buffer); | |
3354 | defsubr (&Sget_file_buffer); | |
3355 | defsubr (&Sget_buffer_create); | |
336cd056 | 3356 | defsubr (&Smake_indirect_buffer); |
01050cb5 | 3357 | defsubr (&Sgenerate_new_buffer_name); |
1ab256cb RM |
3358 | defsubr (&Sbuffer_name); |
3359 | /*defsubr (&Sbuffer_number);*/ | |
3360 | defsubr (&Sbuffer_file_name); | |
336cd056 | 3361 | defsubr (&Sbuffer_base_buffer); |
1ab256cb RM |
3362 | defsubr (&Sbuffer_local_variables); |
3363 | defsubr (&Sbuffer_modified_p); | |
3364 | defsubr (&Sset_buffer_modified_p); | |
3365 | defsubr (&Sbuffer_modified_tick); | |
3366 | defsubr (&Srename_buffer); | |
3367 | defsubr (&Sother_buffer); | |
3368 | defsubr (&Sbuffer_disable_undo); | |
3369 | defsubr (&Sbuffer_enable_undo); | |
3370 | defsubr (&Skill_buffer); | |
3371 | defsubr (&Serase_buffer); | |
a9ee7a59 | 3372 | defsubr (&Sset_buffer_major_mode); |
1ab256cb RM |
3373 | defsubr (&Sswitch_to_buffer); |
3374 | defsubr (&Spop_to_buffer); | |
3375 | defsubr (&Scurrent_buffer); | |
3376 | defsubr (&Sset_buffer); | |
3377 | defsubr (&Sbarf_if_buffer_read_only); | |
3378 | defsubr (&Sbury_buffer); | |
1ab256cb | 3379 | defsubr (&Skill_all_local_variables); |
2eec3b4e | 3380 | |
52f8ec73 | 3381 | defsubr (&Soverlayp); |
2eec3b4e RS |
3382 | defsubr (&Smake_overlay); |
3383 | defsubr (&Sdelete_overlay); | |
3384 | defsubr (&Smove_overlay); | |
8ebafa8d JB |
3385 | defsubr (&Soverlay_start); |
3386 | defsubr (&Soverlay_end); | |
3387 | defsubr (&Soverlay_buffer); | |
3388 | defsubr (&Soverlay_properties); | |
2eec3b4e RS |
3389 | defsubr (&Soverlays_at); |
3390 | defsubr (&Snext_overlay_change); | |
239c932b | 3391 | defsubr (&Sprevious_overlay_change); |
2eec3b4e RS |
3392 | defsubr (&Soverlay_recenter); |
3393 | defsubr (&Soverlay_lists); | |
3394 | defsubr (&Soverlay_get); | |
3395 | defsubr (&Soverlay_put); | |
1ab256cb RM |
3396 | } |
3397 | ||
3398 | keys_of_buffer () | |
3399 | { | |
3400 | initial_define_key (control_x_map, 'b', "switch-to-buffer"); | |
3401 | initial_define_key (control_x_map, 'k', "kill-buffer"); | |
4158c17d RM |
3402 | |
3403 | /* This must not be in syms_of_buffer, because Qdisabled is not | |
3404 | initialized when that function gets called. */ | |
3405 | Fput (intern ("erase-buffer"), Qdisabled, Qt); | |
1ab256cb | 3406 | } |