Mercurial > hg > xemacs-beta
annotate src/buffer.c @ 5117:3742ea8250b5 ben-lisp-object ben-lisp-object-final-ws-year-2005
Checking in final CVS version of workspace 'ben-lisp-object'
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sat, 26 Dec 2009 00:20:27 -0600 |
parents | b7f26b2f78bd |
children | e0db3c197671 |
rev | line source |
---|---|
428 | 1 /* Buffer manipulation primitives for XEmacs. |
2 Copyright (C) 1985-1989, 1992-1995 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Sun Microsystems, Inc. | |
2367 | 4 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2004 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: Mule 2.0, FSF 19.30. */ | |
24 | |
25 /* Authorship: | |
26 | |
853 | 27 Based on code from pre-release FSF 19, c. 1991. |
28 Some changes by Jamie Zawinski, c. 1991-1994 (e.g. separate buffer | |
29 list per frame, buffer slots). | |
30 A few changes for buffer-local vars by Richard Mlynarik for | |
31 19.8 or 19.9, c. 1993. | |
32 Many changes by Ben Wing: changes and cleanups for Mule, esp. the | |
33 macros in buffer.h and the intial version of the coding-system | |
34 conversion macros (in buffer.h) and associated fns. (in this file), | |
35 19.12 (c. 1995); synch. to FSF 19.30 c. 1994; memory usage stats | |
36 c. 1996; generated-modeline-string c. 1996 for mousable modeline in | |
37 19.14. | |
38 Indirect buffer code by Hrvoje Niksic, c. 1997? | |
39 Coding conversion code rewritten by Martin Buchholz, early 2000, | |
40 based on design by Ben Wing. */ | |
428 | 41 |
42 /* This file contains functions that work with buffer objects. | |
43 Functions that manipulate a buffer's text, however, are not | |
44 in this file: | |
45 | |
46 1) The low-level functions that actually know about the | |
47 implementation of a buffer's text are located in insdel.c. | |
48 2) The higher-level (mostly Lisp) functions that manipulate a | |
49 buffer's text are in editfns.c. | |
50 3) The highest-level Lisp commands are in cmds.c. | |
51 | |
52 However: | |
53 | |
54 -- Functions that know about syntax tables (forward-word, | |
55 scan-sexps, etc.) are in syntax.c, as are functions | |
56 that manipulate syntax tables. | |
57 -- Functions that know about case tables (upcase, downcase, | |
58 etc.) are in casefiddle.c. Functions that manipulate | |
59 case tables (case-table-p, set-case-table, etc.) are | |
60 in casetab.c. | |
61 -- Functions that do searching and replacing are in | |
62 search.c. The low-level functions that implement | |
63 regular expressions are in regex.c. | |
64 | |
65 Also: | |
66 | |
67 -- Some file and process functions (in fileio.c and process.c) | |
68 copy text from or insert text into a buffer; they call | |
69 low-level functions in insdel.c to do this. | |
70 -- insdel.c calls low-level functions in undo.c and extents.c | |
71 to record buffer modifications for undoing and to handle | |
72 extent adjustment and extent-data creation and insertion. | |
73 | |
74 */ | |
75 | |
76 #include <config.h> | |
77 #include "lisp.h" | |
78 | |
79 #include "buffer.h" | |
80 #include "chartab.h" | |
446 | 81 #include "casetab.h" |
428 | 82 #include "commands.h" |
872 | 83 #include "device-impl.h" |
428 | 84 #include "elhash.h" |
85 #include "extents.h" | |
86 #include "faces.h" | |
440 | 87 #include "file-coding.h" |
872 | 88 #include "frame-impl.h" |
428 | 89 #include "insdel.h" |
440 | 90 #include "lstream.h" |
428 | 91 #include "process.h" /* for kill_buffer_processes */ |
92 #ifdef REGION_CACHE_NEEDS_WORK | |
93 #include "region-cache.h" | |
94 #endif | |
442 | 95 #include "select.h" /* for select_notify_buffer_kill */ |
428 | 96 #include "specifier.h" |
97 #include "syntax.h" | |
98 #include "window.h" | |
99 | |
100 #include "sysfile.h" | |
771 | 101 #include "sysdir.h" |
102 | |
103 #ifdef WIN32_NATIVE | |
104 #include "syswindows.h" | |
105 #endif | |
428 | 106 |
107 struct buffer *current_buffer; /* the current buffer */ | |
108 | |
109 /* This structure holds the default values of the buffer-local variables | |
110 defined with DEFVAR_BUFFER_LOCAL, that have special slots in each buffer. | |
111 The default value occupies the same slot in this structure | |
112 as an individual buffer's value occupies in that buffer. | |
113 Setting the default value also goes through the alist of buffers | |
114 and stores into each buffer that does not say it has a local value. */ | |
115 Lisp_Object Vbuffer_defaults; | |
116 static void *buffer_defaults_saved_slots; | |
117 | |
118 /* This structure marks which slots in a buffer have corresponding | |
119 default values in Vbuffer_defaults. | |
120 Each such slot has a nonzero value in this structure. | |
121 The value has only one nonzero bit. | |
122 | |
123 When a buffer has its own local value for a slot, | |
124 the bit for that slot (found in the same slot in this structure) | |
125 is turned on in the buffer's local_var_flags slot. | |
126 | |
127 If a slot in this structure is 0, then there is a DEFVAR_BUFFER_LOCAL | |
128 for the slot, but there is no default value for it; the corresponding | |
129 slot in Vbuffer_defaults is not used except to initialize newly-created | |
130 buffers. | |
131 | |
132 If a slot is -1, then there is a DEFVAR_BUFFER_LOCAL for it | |
133 as well as a default value which is used to initialize newly-created | |
134 buffers and as a reset-value when local-vars are killed. | |
135 | |
136 If a slot is -2, there is no DEFVAR_BUFFER_LOCAL for it. | |
137 (The slot is always local, but there's no lisp variable for it.) | |
138 The default value is only used to initialize newly-creation buffers. | |
139 | |
140 If a slot is -3, then there is no DEFVAR_BUFFER_LOCAL for it but | |
141 there is a default which is used to initialize newly-creation | |
142 buffers and as a reset-value when local-vars are killed. */ | |
143 struct buffer buffer_local_flags; | |
144 | |
145 /* This is the initial (startup) directory, as used for the *scratch* buffer. | |
771 | 146 This is no longer global. Use get_initial_directory() to retrieve it. |
428 | 147 */ |
867 | 148 static Ibyte *initial_directory; |
428 | 149 |
150 /* This structure holds the names of symbols whose values may be | |
151 buffer-local. It is indexed and accessed in the same way as the above. */ | |
152 static Lisp_Object Vbuffer_local_symbols; | |
153 static void *buffer_local_symbols_saved_slots; | |
154 | |
155 /* Alist of all buffer names vs the buffers. */ | |
156 /* This used to be a variable, but is no longer, | |
157 to prevent lossage due to user rplac'ing this alist or its elements. | |
158 Note that there is a per-frame copy of this as well; the frame slot | |
159 and the global variable contain the same data, but possibly in different | |
160 orders, so that the buffer ordering can be per-frame. | |
161 */ | |
162 Lisp_Object Vbuffer_alist; | |
163 | |
164 /* Functions to call before and after each text change. */ | |
165 Lisp_Object Qbefore_change_functions; | |
166 Lisp_Object Qafter_change_functions; | |
167 Lisp_Object Vbefore_change_functions; | |
168 Lisp_Object Vafter_change_functions; | |
169 | |
170 /* #### Obsolete, for compatibility */ | |
171 Lisp_Object Qbefore_change_function; | |
172 Lisp_Object Qafter_change_function; | |
173 Lisp_Object Vbefore_change_function; | |
174 Lisp_Object Vafter_change_function; | |
175 | |
176 #if 0 /* FSFmacs */ | |
177 Lisp_Object Vtransient_mark_mode; | |
178 #endif | |
179 | |
180 /* t means ignore all read-only text properties. | |
181 A list means ignore such a property if its value is a member of the list. | |
182 Any non-nil value means ignore buffer-read-only. */ | |
183 Lisp_Object Vinhibit_read_only; | |
184 | |
185 /* List of functions to call that can query about killing a buffer. | |
186 If any of these functions returns nil, we don't kill it. */ | |
187 Lisp_Object Vkill_buffer_query_functions; | |
188 | |
189 /* Non-nil means delete a buffer's auto-save file when the buffer is saved. */ | |
190 int delete_auto_save_files; | |
191 | |
192 Lisp_Object Qbuffer_live_p; | |
193 Lisp_Object Qbuffer_or_string_p; | |
194 | |
195 /* List of functions to call before changing an unmodified buffer. */ | |
196 Lisp_Object Vfirst_change_hook; | |
197 Lisp_Object Qfirst_change_hook; | |
198 | |
199 Lisp_Object Qfundamental_mode; | |
200 Lisp_Object Qmode_class; | |
201 Lisp_Object Qpermanent_local; | |
202 | |
203 Lisp_Object Qprotected_field; | |
204 | |
205 Lisp_Object QSFundamental; /* A string "Fundamental" */ | |
206 Lisp_Object QSscratch; /* "*scratch*" */ | |
207 Lisp_Object Qdefault_directory; | |
208 | |
209 Lisp_Object Qkill_buffer_hook; | |
210 | |
211 Lisp_Object Qrename_auto_save_file; | |
212 | |
213 Lisp_Object Qget_file_buffer; | |
214 Lisp_Object Qchange_major_mode_hook, Vchange_major_mode_hook; | |
215 | |
216 Lisp_Object Qfind_file_compare_truenames; | |
217 | |
218 Lisp_Object Qswitch_to_buffer; | |
219 | |
220 /* Two thresholds controlling how much undo information to keep. */ | |
458 | 221 Fixnum undo_threshold; |
222 Fixnum undo_high_threshold; | |
428 | 223 |
224 int find_file_compare_truenames; | |
225 int find_file_use_truenames; | |
226 | |
227 | |
228 static void reset_buffer_local_variables (struct buffer *, int first_time); | |
229 static void nuke_all_buffer_slots (struct buffer *b, Lisp_Object zap); | |
230 | |
1204 | 231 static const struct memory_description buffer_text_description_1 [] = { |
232 { XD_LISP_OBJECT, offsetof (struct buffer_text, line_number_cache) }, | |
233 { XD_END } | |
234 }; | |
235 | |
236 static const struct sized_memory_description buffer_text_description = { | |
237 sizeof (struct buffer_text), | |
238 buffer_text_description_1 | |
239 }; | |
240 | |
241 static const struct memory_description buffer_description [] = { | |
242 #define MARKED_SLOT(x) { XD_LISP_OBJECT, offsetof (struct buffer, x) }, | |
243 #include "bufslots.h" | |
244 | |
245 { XD_LISP_OBJECT, offsetof (struct buffer, extent_info) }, | |
246 | |
2367 | 247 { XD_BLOCK_PTR, offsetof (struct buffer, text), |
2551 | 248 1, { &buffer_text_description } }, |
2367 | 249 { XD_BLOCK_PTR, offsetof (struct buffer, syntax_cache), |
2551 | 250 1, { &syntax_cache_description } }, |
1204 | 251 |
252 { XD_LISP_OBJECT, offsetof (struct buffer, indirect_children) }, | |
253 { XD_LISP_OBJECT, offsetof (struct buffer, base_buffer) }, | |
254 { XD_END } | |
255 }; | |
256 | |
428 | 257 static Lisp_Object |
258 mark_buffer (Lisp_Object obj) | |
259 { | |
260 struct buffer *buf = XBUFFER (obj); | |
261 | |
1204 | 262 #define MARKED_SLOT(x) mark_object (buf->x); |
428 | 263 #include "bufslots.h" |
264 | |
265 mark_object (buf->extent_info); | |
266 if (buf->text) | |
267 mark_object (buf->text->line_number_cache); | |
826 | 268 mark_buffer_syntax_cache (buf); |
428 | 269 |
1204 | 270 /* [[ Don't mark normally through the children slot. Actually, in this |
271 case, it doesn't matter. ]] | |
272 | |
273 Indirect buffers, like all buffers, are permanent objects and stay | |
274 around by themselves, so it doesn't matter whether we mark their | |
275 children. This used to contain a call to mark_conses_in_list(), to | |
276 mark only the conses. I deleted that function, since it's not used | |
277 any more and causes problems with KKCC. If we really needed such a | |
278 weak list, just use a weak list object, like extents do. --ben */ | |
428 | 279 if (! EQ (buf->indirect_children, Qnull_pointer)) |
1204 | 280 mark_object (buf->indirect_children); |
428 | 281 |
771 | 282 return buf->base_buffer ? wrap_buffer (buf->base_buffer) : Qnil; |
428 | 283 } |
284 | |
285 static void | |
286 print_buffer (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
287 { | |
288 struct buffer *b = XBUFFER (obj); | |
289 | |
290 if (print_readably) | |
291 { | |
292 if (!BUFFER_LIVE_P (b)) | |
563 | 293 printing_unreadable_object ("#<killed buffer>"); |
428 | 294 else |
563 | 295 printing_unreadable_object ("#<buffer %s>", XSTRING_DATA (b->name)); |
428 | 296 } |
297 else if (!BUFFER_LIVE_P (b)) | |
826 | 298 write_c_string (printcharfun, "#<killed buffer>"); |
428 | 299 else if (escapeflag) |
800 | 300 write_fmt_string_lisp (printcharfun, "#<buffer %S>", 1, b->name); |
428 | 301 else |
800 | 302 print_internal (b->name, printcharfun, 0); |
428 | 303 } |
304 | |
1204 | 305 void |
306 cleanup_buffer_undo_lists (void) | |
307 { | |
308 /* Truncate undo information at GC time. Used to be in mark_object() but | |
309 moved here for KKCC purposes. */ | |
310 | |
311 ALIST_LOOP_3 (name, buf, Vbuffer_alist) | |
312 { | |
313 XBUFFER (buf)->undo_list = truncate_undo_list (XBUFFER (buf)->undo_list, | |
314 undo_threshold, | |
315 undo_high_threshold); | |
316 } | |
317 } | |
318 | |
428 | 319 /* We do not need a finalize method to handle a buffer's children list |
320 because all buffers have `kill-buffer' applied to them before | |
321 they disappear, and the children removal happens then. */ | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
322 DEFINE_NONDUMPABLE_LISP_OBJECT ("buffer", buffer, mark_buffer, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
323 print_buffer, 0, 0, 0, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
324 buffer_description, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
325 struct buffer); |
428 | 326 |
327 DEFUN ("bufferp", Fbufferp, 1, 1, 0, /* | |
328 Return t if OBJECT is an editor buffer. | |
329 */ | |
330 (object)) | |
331 { | |
332 return BUFFERP (object) ? Qt : Qnil; | |
333 } | |
334 | |
335 DEFUN ("buffer-live-p", Fbuffer_live_p, 1, 1, 0, /* | |
336 Return t if OBJECT is an editor buffer that has not been deleted. | |
337 */ | |
338 (object)) | |
339 { | |
340 return BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)) ? Qt : Qnil; | |
341 } | |
342 | |
2268 | 343 static DECLARE_DOESNT_RETURN (nsberror (Lisp_Object)); |
344 | |
345 static DOESNT_RETURN | |
428 | 346 nsberror (Lisp_Object spec) |
347 { | |
348 if (STRINGP (spec)) | |
563 | 349 invalid_argument ("No buffer named", spec); |
350 invalid_argument ("Invalid buffer argument", spec); | |
428 | 351 } |
352 | |
353 DEFUN ("buffer-list", Fbuffer_list, 0, 1, 0, /* | |
354 Return a list of all existing live buffers. | |
355 The order is specific to the selected frame; if the optional FRAME | |
356 argument is provided, the ordering for that frame is returned instead. | |
357 If the FRAME argument is t, then the global (non-frame) ordering is | |
358 returned instead. | |
359 */ | |
360 (frame)) | |
361 { | |
362 return Fmapcar (Qcdr, | |
363 EQ (frame, Qt) ? Vbuffer_alist : | |
364 decode_frame (frame)->buffer_alist); | |
365 } | |
366 | |
367 Lisp_Object | |
368 get_buffer (Lisp_Object name, int error_if_deleted_or_does_not_exist) | |
369 { | |
370 if (BUFFERP (name)) | |
371 { | |
372 if (!BUFFER_LIVE_P (XBUFFER (name))) | |
373 { | |
374 if (error_if_deleted_or_does_not_exist) | |
375 nsberror (name); | |
376 return Qnil; | |
377 } | |
378 return name; | |
379 } | |
380 else | |
381 { | |
382 Lisp_Object buf; | |
383 struct gcpro gcpro1; | |
384 | |
385 CHECK_STRING (name); | |
771 | 386 name = LISP_GETTEXT (name); |
428 | 387 GCPRO1 (name); |
388 buf = Fcdr (Fassoc (name, Vbuffer_alist)); | |
389 UNGCPRO; | |
390 if (NILP (buf) && error_if_deleted_or_does_not_exist) | |
391 nsberror (name); | |
392 return buf; | |
393 } | |
394 } | |
395 | |
396 struct buffer * | |
397 decode_buffer (Lisp_Object buffer, int allow_string) | |
398 { | |
707 | 399 if (NILP (buffer) || (!POINTER_TYPE_P( XTYPE(buffer)))) |
428 | 400 return current_buffer; |
401 | |
402 if (allow_string && STRINGP (buffer)) | |
403 return XBUFFER (get_buffer (buffer, 1)); | |
404 | |
405 CHECK_LIVE_BUFFER (buffer); | |
406 return XBUFFER (buffer); | |
407 } | |
408 | |
409 DEFUN ("decode-buffer", Fdecode_buffer, 1, 1, 0, /* | |
410 Validate BUFFER or if BUFFER is nil, return the current buffer. | |
411 If BUFFER is a valid buffer or a string representing a valid buffer, | |
412 the corresponding buffer object will be returned. Otherwise an error | |
413 will be signaled. | |
414 */ | |
415 (buffer)) | |
416 { | |
417 struct buffer *b = decode_buffer (buffer, 1); | |
793 | 418 return wrap_buffer (b); |
428 | 419 } |
420 | |
421 #if 0 /* FSFmacs */ | |
422 /* bleagh!!! */ | |
423 /* Like Fassoc, but use Fstring_equal to compare | |
424 (which ignores text properties), | |
425 and don't ever QUIT. */ | |
426 | |
427 static Lisp_Object | |
428 assoc_ignore_text_properties (REGISTER Lisp_Object key, Lisp_Object list) | |
429 { | |
430 REGISTER Lisp_Object tail; | |
431 for (tail = list; !NILP (tail); tail = Fcdr (tail)) | |
432 { | |
433 REGISTER Lisp_Object elt, tem; | |
434 elt = Fcar (tail); | |
435 tem = Fstring_equal (Fcar (elt), key); | |
436 if (!NILP (tem)) | |
437 return elt; | |
438 } | |
439 return Qnil; | |
440 } | |
441 | |
442 #endif /* FSFmacs */ | |
443 | |
444 DEFUN ("get-buffer", Fget_buffer, 1, 1, 0, /* | |
444 | 445 Return the buffer named BUFFER-NAME (a string), or nil if there is none. |
446 BUFFER-NAME may also be a buffer; if so, the value is that buffer. | |
428 | 447 */ |
444 | 448 (buffer_name)) |
428 | 449 { |
450 #ifdef I18N3 | |
451 /* #### Doc string should indicate that the buffer name will get | |
452 translated. */ | |
453 #endif | |
454 | |
455 /* #### This might return a dead buffer. This is gross. This is | |
456 called FSF compatibility. */ | |
444 | 457 if (BUFFERP (buffer_name)) |
458 return buffer_name; | |
459 return get_buffer (buffer_name, 0); | |
428 | 460 /* FSFmacs 19.29 calls assoc_ignore_text_properties() here. |
461 Bleagh!! */ | |
462 } | |
463 | |
464 | |
465 DEFUN ("get-file-buffer", Fget_file_buffer, 1, 1, 0, /* | |
466 Return the buffer visiting file FILENAME (a string). | |
467 The buffer's `buffer-file-name' must match exactly the expansion of FILENAME. | |
468 If there is no such live buffer, return nil. | |
469 | |
470 Normally, the comparison is done by canonicalizing FILENAME (using | |
471 `expand-file-name') and comparing that to the value of `buffer-file-name' | |
472 for each existing buffer. However, If `find-file-compare-truenames' is | |
473 non-nil, FILENAME will be converted to its truename and the search will be | |
474 done on each buffer's value of `buffer-file-truename' instead of | |
475 `buffer-file-name'. Otherwise, if `find-file-use-truenames' is non-nil, | |
476 FILENAME will be converted to its truename and used for searching, but | |
477 the search will still be done on `buffer-file-name'. | |
478 */ | |
479 (filename)) | |
480 { | |
442 | 481 /* This function can GC. GC checked and fixed 7-11-2000 ben. */ |
428 | 482 struct gcpro gcpro1; |
483 | |
484 #ifdef I18N3 | |
485 /* DO NOT translate the filename. */ | |
486 #endif | |
487 GCPRO1 (filename); | |
488 CHECK_STRING (filename); | |
489 filename = Fexpand_file_name (filename, Qnil); | |
490 { | |
491 /* If the file name has special constructs in it, | |
492 call the corresponding file handler. */ | |
493 Lisp_Object handler = Ffind_file_name_handler (filename, Qget_file_buffer); | |
494 if (!NILP (handler)) | |
495 { | |
496 UNGCPRO; | |
497 return call2 (handler, Qget_file_buffer, filename); | |
498 } | |
499 } | |
500 UNGCPRO; | |
501 | |
502 if (find_file_compare_truenames || find_file_use_truenames) | |
503 { | |
504 struct gcpro ngcpro1, ngcpro2, ngcpro3; | |
505 Lisp_Object fn = Qnil; | |
506 Lisp_Object dn = Qnil; | |
507 | |
508 NGCPRO3 (fn, dn, filename); | |
509 fn = Ffile_truename (filename, Qnil); | |
510 if (NILP (fn)) | |
511 { | |
512 dn = Ffile_name_directory (filename); | |
513 fn = Ffile_truename (dn, Qnil); | |
514 if (! NILP (fn)) dn = fn; | |
442 | 515 /* Formerly the two calls below were combined, but that is |
516 not GC-safe because the first call returns unprotected | |
517 data and the second call can GC. --ben */ | |
518 fn = Ffile_name_nondirectory (filename); | |
519 fn = Fexpand_file_name (fn, dn); | |
428 | 520 } |
521 filename = fn; | |
522 NUNGCPRO; | |
523 } | |
524 | |
525 { | |
1204 | 526 ALIST_LOOP_3 (name, buf, Vbuffer_alist) |
428 | 527 { |
528 if (!STRINGP (XBUFFER (buf)->filename)) continue; | |
529 if (!NILP (Fstring_equal (filename, | |
530 (find_file_compare_truenames | |
531 ? XBUFFER (buf)->file_truename | |
532 : XBUFFER (buf)->filename)))) | |
533 return buf; | |
534 } | |
535 } | |
536 return Qnil; | |
537 } | |
538 | |
539 | |
540 static void | |
541 push_buffer_alist (Lisp_Object name, Lisp_Object buf) | |
542 { | |
543 Lisp_Object cons = Fcons (name, buf); | |
544 Lisp_Object frmcons, devcons, concons; | |
545 | |
546 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (cons, Qnil)); | |
547 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons) | |
548 { | |
549 struct frame *f; | |
550 f = XFRAME (XCAR (frmcons)); | |
551 f->buffer_alist = nconc2 (f->buffer_alist, Fcons (cons, Qnil)); | |
552 } | |
553 } | |
554 | |
555 static void | |
556 delete_from_buffer_alist (Lisp_Object buf) | |
557 { | |
558 Lisp_Object cons = Frassq (buf, Vbuffer_alist); | |
559 Lisp_Object frmcons, devcons, concons; | |
560 if (NILP (cons)) | |
2500 | 561 return; /* ABORT() ? */ |
428 | 562 Vbuffer_alist = delq_no_quit (cons, Vbuffer_alist); |
563 | |
564 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons) | |
565 { | |
566 struct frame *f; | |
567 f = XFRAME (XCAR (frmcons)); | |
568 f->buffer_alist = delq_no_quit (cons, f->buffer_alist); | |
569 } | |
570 } | |
571 | |
572 Lisp_Object | |
573 get_truename_buffer (REGISTER Lisp_Object filename) | |
574 { | |
442 | 575 /* This function can GC. GC correct 7-11-00 ben */ |
428 | 576 /* FSFmacs has its own code here and doesn't call get-file-buffer. |
577 That's because their equivalent of find-file-compare-truenames | |
578 (find-file-existing-other-name) isn't looked at in get-file-buffer. | |
579 This way is more correct. */ | |
580 int count = specpdl_depth (); | |
581 | |
582 specbind (Qfind_file_compare_truenames, Qt); | |
771 | 583 return unbind_to_1 (count, Fget_file_buffer (filename)); |
428 | 584 } |
585 | |
586 static struct buffer * | |
587 allocate_buffer (void) | |
588 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
589 Lisp_Object obj = ALLOC_LISP_OBJECT (buffer); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
590 struct buffer *b = XBUFFER (obj); |
3017 | 591 |
592 COPY_LCRECORD (b, XBUFFER (Vbuffer_defaults)); | |
428 | 593 |
594 return b; | |
595 } | |
596 | |
597 static Lisp_Object | |
598 finish_init_buffer (struct buffer *b, Lisp_Object name) | |
599 { | |
793 | 600 Lisp_Object buf = wrap_buffer (b); |
428 | 601 |
602 name = Fcopy_sequence (name); | |
603 /* #### This really does not need to be called. We already | |
604 initialized the buffer-local variables in allocate_buffer(). | |
605 local_var_alist is set to Qnil at the same point, in | |
606 nuke_all_buffer_slots(). */ | |
607 reset_buffer_local_variables (b, 1); | |
442 | 608 b->directory = current_buffer ? current_buffer->directory : Qnil; |
428 | 609 |
610 b->last_window_start = 1; | |
611 | |
612 b->name = name; | |
826 | 613 if (string_byte (name, 0) != ' ') |
428 | 614 b->undo_list = Qnil; |
615 else | |
616 b->undo_list = Qt; | |
617 | |
618 /* initialize the extent list */ | |
619 init_buffer_extents (b); | |
620 | |
621 /* Put this in the alist of all live buffers. */ | |
622 push_buffer_alist (name, buf); | |
853 | 623 note_object_created (buf); |
428 | 624 |
625 init_buffer_markers (b); | |
826 | 626 init_buffer_syntax_cache (b); |
428 | 627 |
628 b->generated_modeline_string = Fmake_string (make_int (84), make_int (' ')); | |
629 b->modeline_extent_table = make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK, | |
630 HASH_TABLE_EQ); | |
631 | |
853 | 632 |
428 | 633 return buf; |
634 } | |
635 | |
636 DEFUN ("get-buffer-create", Fget_buffer_create, 1, 1, 0, /* | |
637 Return the buffer named NAME, or create such a buffer and return it. | |
638 A new buffer is created if there is no live buffer named NAME. | |
639 If NAME starts with a space, the new buffer does not keep undo information. | |
640 If NAME is a buffer instead of a string, then it is the value returned. | |
641 The value is never nil. | |
642 */ | |
643 (name)) | |
644 { | |
645 /* This function can GC */ | |
646 Lisp_Object buf; | |
647 REGISTER struct buffer *b; | |
648 | |
649 #ifdef I18N3 | |
650 /* #### Doc string should indicate that the buffer name will get | |
651 translated. */ | |
652 #endif | |
653 | |
654 name = LISP_GETTEXT (name); | |
655 buf = Fget_buffer (name); | |
656 if (!NILP (buf)) | |
657 return buf; | |
658 | |
659 if (XSTRING_LENGTH (name) == 0) | |
563 | 660 invalid_argument ("Empty string for buffer name is not allowed", |
661 Qunbound); | |
428 | 662 |
663 b = allocate_buffer (); | |
664 | |
665 b->text = &b->own_text; | |
666 b->base_buffer = 0; | |
667 b->indirect_children = Qnil; | |
668 init_buffer_text (b); | |
669 | |
670 return finish_init_buffer (b, name); | |
671 } | |
672 | |
673 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, 2, 2, | |
674 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ", /* | |
444 | 675 Create and return an indirect buffer for buffer BASE-BUFFER, named NAME. |
676 BASE-BUFFER should be an existing buffer (or buffer name). | |
428 | 677 NAME should be a string which is not the name of an existing buffer. |
444 | 678 |
679 If BASE-BUFFER is itself an indirect buffer, the base buffer for that buffer | |
428 | 680 is made the base buffer for the newly created buffer. (Thus, there will |
681 never be indirect buffers whose base buffers are themselves indirect.) | |
682 */ | |
683 (base_buffer, name)) | |
684 { | |
685 /* This function can GC */ | |
686 | |
687 /* #### The above interactive specification is totally bogus, | |
688 because it offers an existing buffer as default answer to the | |
689 second question. However, the second argument may not BE an | |
690 existing buffer! */ | |
691 struct buffer *b; | |
692 | |
693 base_buffer = get_buffer (base_buffer, 1); | |
694 | |
695 #ifdef I18N3 | |
696 /* #### Doc string should indicate that the buffer name will get | |
697 translated. */ | |
698 #endif | |
699 CHECK_STRING (name); | |
700 name = LISP_GETTEXT (name); | |
701 if (!NILP (Fget_buffer (name))) | |
563 | 702 invalid_argument ("Buffer name already in use", name); |
428 | 703 if (XSTRING_LENGTH (name) == 0) |
563 | 704 invalid_argument ("Empty string for buffer name is not allowed", Qunbound); |
428 | 705 |
706 b = allocate_buffer (); | |
707 | |
708 b->base_buffer = BUFFER_BASE_BUFFER (XBUFFER (base_buffer)); | |
709 | |
710 /* Use the base buffer's text object. */ | |
711 b->text = b->base_buffer->text; | |
712 b->indirect_children = Qnil; | |
713 b->base_buffer->indirect_children = | |
771 | 714 Fcons (wrap_buffer (b), b->base_buffer->indirect_children); |
428 | 715 init_buffer_text (b); |
716 | |
717 return finish_init_buffer (b, name); | |
718 } | |
719 | |
720 | |
721 | |
722 static void | |
723 reset_buffer_local_variables (struct buffer *b, int first_time) | |
724 { | |
725 struct buffer *def = XBUFFER (Vbuffer_defaults); | |
726 | |
727 b->local_var_flags = 0; | |
728 /* For each slot that has a default value, | |
729 copy that into the slot. */ | |
730 #define MARKED_SLOT(slot) \ | |
731 { int mask = XINT (buffer_local_flags.slot); \ | |
732 if ((mask > 0 || mask == -1 || mask == -3) \ | |
733 && (first_time \ | |
734 || NILP (Fget (XBUFFER (Vbuffer_local_symbols)->slot, \ | |
735 Qpermanent_local, Qnil)))) \ | |
736 b->slot = def->slot; \ | |
737 } | |
738 #include "bufslots.h" | |
739 } | |
740 | |
741 | |
742 /* We split this away from generate-new-buffer, because rename-buffer | |
743 and set-visited-file-name ought to be able to use this to really | |
744 rename the buffer properly. */ | |
745 | |
746 DEFUN ("generate-new-buffer-name", Fgenerate_new_buffer_name, 1, 2, 0, /* | |
747 Return a string that is the name of no existing buffer based on NAME. | |
748 If there is no live buffer named NAME, then return NAME. | |
749 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER | |
750 until an unused name is found, and then return that name. | |
751 Optional second argument IGNORE specifies a name that is okay to use | |
752 \(if it is in the sequence to be tried) | |
753 even if a buffer with that name exists. | |
754 */ | |
755 (name, ignore)) | |
756 { | |
757 REGISTER Lisp_Object gentemp, tem; | |
758 int count; | |
867 | 759 Ibyte number[10]; |
428 | 760 |
761 CHECK_STRING (name); | |
762 | |
763 name = LISP_GETTEXT (name); | |
764 #ifdef I18N3 | |
765 /* #### Doc string should indicate that the buffer name will get | |
766 translated. */ | |
767 #endif | |
768 | |
769 tem = Fget_buffer (name); | |
770 if (NILP (tem)) | |
771 return name; | |
772 | |
773 count = 1; | |
774 while (1) | |
775 { | |
771 | 776 qxesprintf (number, "<%d>", ++count); |
777 gentemp = concat2 (name, build_intstring (number)); | |
428 | 778 if (!NILP (ignore)) |
779 { | |
780 tem = Fstring_equal (gentemp, ignore); | |
781 if (!NILP (tem)) | |
782 return gentemp; | |
783 } | |
784 tem = Fget_buffer (gentemp); | |
785 if (NILP (tem)) | |
786 return gentemp; | |
787 } | |
788 } | |
789 | |
790 | |
791 DEFUN ("buffer-name", Fbuffer_name, 0, 1, 0, /* | |
792 Return the name of BUFFER, as a string. | |
793 With no argument or nil as argument, return the name of the current buffer. | |
794 */ | |
795 (buffer)) | |
796 { | |
797 /* For compatibility, we allow a dead buffer here. | |
798 Earlier versions of Emacs didn't provide buffer-live-p. */ | |
799 if (NILP (buffer)) | |
800 return current_buffer->name; | |
801 CHECK_BUFFER (buffer); | |
802 return XBUFFER (buffer)->name; | |
803 } | |
804 | |
805 DEFUN ("buffer-file-name", Fbuffer_file_name, 0, 1, 0, /* | |
806 Return name of file BUFFER is visiting, or nil if none. | |
807 No argument or nil as argument means use the current buffer. | |
808 */ | |
809 (buffer)) | |
810 { | |
811 /* For compatibility, we allow a dead buffer here. Yuck! */ | |
812 if (NILP (buffer)) | |
813 return current_buffer->filename; | |
814 CHECK_BUFFER (buffer); | |
815 return XBUFFER (buffer)->filename; | |
816 } | |
817 | |
818 DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, 0, 1, 0, /* | |
819 Return the base buffer of indirect buffer BUFFER. | |
820 If BUFFER is not indirect, return nil. | |
821 */ | |
822 (buffer)) | |
823 { | |
824 struct buffer *buf = decode_buffer (buffer, 0); | |
825 | |
771 | 826 return buf->base_buffer ? wrap_buffer (buf->base_buffer) : Qnil; |
428 | 827 } |
828 | |
829 DEFUN ("buffer-indirect-children", Fbuffer_indirect_children, 0, 1, 0, /* | |
830 Return a list of all indirect buffers whose base buffer is BUFFER. | |
831 If BUFFER is indirect, the return value will always be nil; see | |
832 `make-indirect-buffer'. | |
833 */ | |
834 (buffer)) | |
835 { | |
836 struct buffer *buf = decode_buffer (buffer, 0); | |
837 | |
838 return Fcopy_sequence (buf->indirect_children); | |
839 } | |
840 | |
841 DEFUN ("buffer-local-variables", Fbuffer_local_variables, 0, 1, 0, /* | |
842 Return an alist of variables that are buffer-local in BUFFER. | |
843 Most elements look like (SYMBOL . VALUE), describing one variable. | |
844 For a symbol that is locally unbound, just the symbol appears in the value. | |
845 Note that storing new VALUEs in these elements doesn't change the variables. | |
846 No argument or nil as argument means use current buffer as BUFFER. | |
847 */ | |
848 (buffer)) | |
849 { | |
850 struct buffer *buf = decode_buffer (buffer, 0); | |
851 Lisp_Object result = Qnil; | |
852 | |
853 { | |
854 Lisp_Object tail; | |
855 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail)) | |
856 { | |
857 Lisp_Object elt = XCAR (tail); | |
858 /* Reference each variable in the alist in buf. | |
859 If inquiring about the current buffer, this gets the current values, | |
860 so store them into the alist so the alist is up to date. | |
861 If inquiring about some other buffer, this swaps out any values | |
862 for that buffer, making the alist up to date automatically. */ | |
863 Lisp_Object val = find_symbol_value (XCAR (elt)); | |
864 /* Use the current buffer value only if buf is the current buffer. */ | |
865 if (buf != current_buffer) | |
866 val = XCDR (elt); | |
867 | |
868 /* If symbol is unbound, put just the symbol in the list. */ | |
869 if (UNBOUNDP (val)) | |
870 result = Fcons (XCAR (elt), result); | |
871 /* Otherwise, put (symbol . value) in the list. */ | |
872 else | |
873 result = Fcons (Fcons (XCAR (elt), val), result); | |
874 } | |
875 } | |
876 | |
877 /* Add on all the variables stored in special slots. */ | |
878 { | |
879 struct buffer *syms = XBUFFER (Vbuffer_local_symbols); | |
880 #define MARKED_SLOT(slot) \ | |
881 { int mask = XINT (buffer_local_flags.slot); \ | |
882 if (mask == 0 || mask == -1 \ | |
883 || ((mask > 0) && (buf->local_var_flags & mask))) \ | |
884 result = Fcons (Fcons (syms->slot, buf->slot), result); \ | |
885 } | |
886 #include "bufslots.h" | |
887 } | |
888 return result; | |
889 } | |
890 | |
891 | |
892 DEFUN ("buffer-modified-p", Fbuffer_modified_p, 0, 1, 0, /* | |
893 Return t if BUFFER was modified since its file was last read or saved. | |
894 No argument or nil as argument means use current buffer as BUFFER. | |
895 */ | |
896 (buffer)) | |
897 { | |
898 struct buffer *buf = decode_buffer (buffer, 0); | |
899 | |
900 return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; | |
901 } | |
902 | |
903 DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, 1, 2, 0, /* | |
904 Mark BUFFER as modified or unmodified according to FLAG. | |
905 A non-nil FLAG means mark the buffer modified. No argument or nil | |
906 as BUFFER means use current buffer. | |
907 */ | |
908 (flag, buffer)) | |
909 { | |
910 /* This function can GC */ | |
911 struct buffer *buf = decode_buffer (buffer, 0); | |
912 | |
913 #ifdef CLASH_DETECTION | |
914 /* If buffer becoming modified, lock the file. | |
915 If buffer becoming unmodified, unlock the file. */ | |
916 | |
917 Lisp_Object fn = buf->file_truename; | |
918 if (!NILP (fn)) | |
919 { | |
920 int already = BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf); | |
921 if (already == NILP (flag)) | |
922 { | |
923 int count = specpdl_depth (); | |
924 /* lock_file() and unlock_file() currently use current_buffer */ | |
925 /* #### - dmoore, what if lock_file or unlock_file kill | |
926 the current buffer? */ | |
927 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
928 set_buffer_internal (buf); | |
929 if (!already && !NILP (flag)) | |
930 lock_file (fn); | |
931 else if (already && NILP (flag)) | |
932 unlock_file (fn); | |
771 | 933 unbind_to (count); |
428 | 934 } |
935 } | |
936 #endif /* CLASH_DETECTION */ | |
937 | |
938 /* This is often called when the buffer contents are altered but we | |
939 don't want to treat the changes that way (e.g. selective | |
940 display). We still need to make sure redisplay realizes that the | |
941 contents have potentially altered and it needs to do some | |
942 work. */ | |
444 | 943 buf = decode_buffer (buffer, 0); |
428 | 944 BUF_MODIFF (buf)++; |
945 BUF_SAVE_MODIFF (buf) = NILP (flag) ? BUF_MODIFF (buf) : 0; | |
946 MARK_MODELINE_CHANGED; | |
947 | |
948 return flag; | |
949 } | |
950 | |
951 DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, 0, 1, 0, /* | |
952 Return BUFFER's tick counter, incremented for each change in text. | |
953 Each buffer has a tick counter which is incremented each time the text in | |
954 that buffer is changed. It wraps around occasionally. | |
955 No argument or nil as argument means use current buffer as BUFFER. | |
956 */ | |
957 (buffer)) | |
958 { | |
959 struct buffer *buf = decode_buffer (buffer, 0); | |
960 | |
961 return make_int (BUF_MODIFF (buf)); | |
962 } | |
963 | |
964 DEFUN ("rename-buffer", Frename_buffer, 1, 2, | |
965 "sRename buffer (to new name): \nP", /* | |
966 Change current buffer's name to NEWNAME (a string). | |
967 If second arg UNIQUE is nil or omitted, it is an error if a | |
968 buffer named NEWNAME already exists. | |
969 If UNIQUE is non-nil, come up with a new name using | |
970 `generate-new-buffer-name'. | |
971 Interactively, one can set UNIQUE with a prefix argument. | |
972 Returns the name we actually gave the buffer. | |
973 This does not change the name of the visited file (if any). | |
974 */ | |
975 (newname, unique)) | |
976 { | |
977 /* This function can GC */ | |
978 Lisp_Object tem, buf; | |
979 | |
980 #ifdef I18N3 | |
981 /* #### Doc string should indicate that the buffer name will get | |
982 translated. */ | |
983 #endif | |
984 CHECK_STRING (newname); | |
985 newname = LISP_GETTEXT (newname); | |
986 | |
987 if (XSTRING_LENGTH (newname) == 0) | |
563 | 988 invalid_argument ("Empty string is invalid as a buffer name", Qunbound); |
428 | 989 |
990 tem = Fget_buffer (newname); | |
991 /* Don't short-circuit if UNIQUE is t. That is a useful way to rename | |
992 the buffer automatically so you can create another with the original name. | |
993 It makes UNIQUE equivalent to | |
994 (rename-buffer (generate-new-buffer-name NEWNAME)). */ | |
995 /* XEmacs change: added check for nil */ | |
996 if (NILP (unique) && !NILP (tem) && XBUFFER (tem) == current_buffer) | |
997 return current_buffer->name; | |
998 if (!NILP (tem)) | |
999 { | |
1000 if (!NILP (unique)) | |
1001 newname = Fgenerate_new_buffer_name (newname, current_buffer->name); | |
1002 else | |
563 | 1003 invalid_argument ("Buffer name is in use", newname); |
428 | 1004 } |
1005 | |
1006 current_buffer->name = newname; | |
1007 | |
1008 /* Catch redisplay's attention. Unless we do this, the modelines for | |
1009 any windows displaying current_buffer will stay unchanged. */ | |
1010 MARK_MODELINE_CHANGED; | |
1011 | |
1012 buf = Fcurrent_buffer (); | |
1013 | |
1014 /* The aconses in the Vbuffer_alist are shared with frame->buffer_alist, | |
1015 so this will change it in the per-frame ordering as well. */ | |
1016 Fsetcar (Frassq (buf, Vbuffer_alist), newname); | |
442 | 1017 |
428 | 1018 if (NILP (current_buffer->filename) |
1019 && !NILP (current_buffer->auto_save_file_name)) | |
1020 call0 (Qrename_auto_save_file); | |
1021 /* refetch since that last call may have done GC */ | |
1022 /* (hypothetical relocating GC) */ | |
1023 return current_buffer->name; | |
1024 } | |
1025 | |
1026 DEFUN ("other-buffer", Fother_buffer, 0, 3, 0, /* | |
1027 Return most recently selected buffer other than BUFFER. | |
1028 Buffers not visible in windows are preferred to visible buffers, | |
1029 unless optional third argument VISIBLE-OK is non-nil. | |
1030 If no other buffer exists, the buffer `*scratch*' is returned. | |
1031 If BUFFER is omitted or nil, some interesting buffer is returned. | |
1032 | |
1033 The ordering is for this frame; If second optional argument FRAME | |
1034 is provided, then the ordering is for that frame. If the second arg | |
1035 is t, then the global ordering is returned. | |
1036 | |
1037 Note: In FSF Emacs, this function takes two arguments: BUFFER and | |
1038 VISIBLE-OK. | |
1039 */ | |
1040 (buffer, frame, visible_ok)) | |
1041 { | |
1042 /* This function can GC */ | |
1043 Lisp_Object tail, buf, notsogood, tem; | |
1044 Lisp_Object alist; | |
1045 | |
1046 notsogood = Qnil; | |
1047 | |
1048 if (EQ (frame, Qt)) | |
1049 alist = Vbuffer_alist; | |
1050 else | |
1051 { | |
1052 struct frame *f = decode_frame (frame); | |
1053 | |
793 | 1054 frame = wrap_frame (f); |
428 | 1055 alist = f->buffer_alist; |
1056 } | |
1057 | |
1058 for (tail = alist; !NILP (tail); tail = Fcdr (tail)) | |
1059 { | |
1060 buf = Fcdr (Fcar (tail)); | |
1061 if (EQ (buf, buffer)) | |
1062 continue; | |
826 | 1063 if (string_byte (XBUFFER (buf)->name, 0) == ' ') |
428 | 1064 continue; |
1065 /* If FRAME has a buffer_predicate, | |
1066 disregard buffers that don't fit the predicate. */ | |
1067 if (FRAMEP (frame)) | |
1068 { | |
1069 tem = XFRAME (frame)->buffer_predicate; | |
1070 if (!NILP (tem)) | |
1071 { | |
1072 tem = call1 (tem, buf); | |
1073 if (NILP (tem)) | |
1074 continue; | |
1075 } | |
1076 } | |
1077 | |
1078 if (NILP (visible_ok)) | |
1079 { | |
1080 /* get-buffer-window will handle nil or t frame */ | |
1081 tem = Fget_buffer_window (buf, frame, Qnil); | |
1082 } | |
1083 else | |
1084 tem = Qnil; | |
1085 if (NILP (tem)) | |
1086 return buf; | |
1087 if (NILP (notsogood)) | |
1088 notsogood = buf; | |
1089 } | |
1090 if (!NILP (notsogood)) | |
1091 return notsogood; | |
1092 return Fget_buffer_create (QSscratch); | |
1093 } | |
1094 | |
1095 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, 0, 1, "", /* | |
444 | 1096 Stop keeping undo information for BUFFER. |
428 | 1097 Any undo records it already has are discarded. |
1098 No argument or nil as argument means do this for the current buffer. | |
1099 */ | |
1100 (buffer)) | |
1101 { | |
1102 /* Allowing nil is an RMSism */ | |
1103 struct buffer *real_buf = decode_buffer (buffer, 1); | |
1104 real_buf->undo_list = Qt; | |
1105 return Qnil; | |
1106 } | |
1107 | |
1108 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, 0, 1, "", /* | |
444 | 1109 Start keeping undo information for BUFFER. |
428 | 1110 No argument or nil as argument means do this for the current buffer. |
1111 */ | |
1112 (buffer)) | |
1113 { | |
1114 /* Allowing nil is an RMSism */ | |
1115 struct buffer *real_buf = decode_buffer (buffer, 1); | |
1116 if (EQ (real_buf->undo_list, Qt)) | |
1117 real_buf->undo_list = Qnil; | |
1118 | |
1119 return Qnil; | |
1120 } | |
1121 | |
1122 DEFUN ("kill-buffer", Fkill_buffer, 1, 1, "bKill buffer: ", /* | |
1123 Kill the buffer BUFFER. | |
1124 The argument may be a buffer or may be the name of a buffer. | |
1125 An argument of nil means kill the current buffer. | |
1126 | |
1127 Value is t if the buffer is actually killed, nil if user says no. | |
1128 | |
1129 The value of `kill-buffer-hook' (which may be local to that buffer), | |
1130 if not void, is a list of functions to be called, with no arguments, | |
1131 before the buffer is actually killed. The buffer to be killed is current | |
1132 when the hook functions are called. | |
1133 | |
1134 Any processes that have this buffer as the `process-buffer' are killed | |
1135 with `delete-process'. | |
1136 */ | |
1137 (buffer)) | |
1138 { | |
1139 /* This function can call lisp */ | |
1140 Lisp_Object buf; | |
1141 REGISTER struct buffer *b; | |
2367 | 1142 struct gcpro gcpro1; |
428 | 1143 |
1144 if (NILP (buffer)) | |
1145 buf = Fcurrent_buffer (); | |
1146 else if (BUFFERP (buffer)) | |
1147 buf = buffer; | |
1148 else | |
1149 { | |
1150 buf = get_buffer (buffer, 0); | |
1151 if (NILP (buf)) nsberror (buffer); | |
1152 } | |
1153 | |
1154 b = XBUFFER (buf); | |
1155 | |
1156 /* OK to delete an already-deleted buffer. */ | |
1157 if (!BUFFER_LIVE_P (b)) | |
1158 return Qnil; | |
1159 | |
853 | 1160 check_allowed_operation (OPERATION_DELETE_OBJECT, buf, Qnil); |
1161 | |
428 | 1162 /* Don't kill the minibuffer now current. */ |
1163 if (EQ (buf, Vminibuffer_zero)) | |
1164 return Qnil; | |
1165 | |
1166 /* Or the echo area. */ | |
1167 if (EQ (buf, Vecho_area_buffer)) | |
1168 return Qnil; | |
1169 | |
1170 /* Query if the buffer is still modified. */ | |
1171 if (INTERACTIVE && !NILP (b->filename) | |
1172 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
1173 { | |
1174 Lisp_Object killp; | |
1175 GCPRO1 (buf); | |
771 | 1176 killp = |
1177 call1 (Qyes_or_no_p, | |
1178 (emacs_sprintf_string ("Buffer %s modified; kill anyway? ", | |
1179 XSTRING_DATA (b->name)))); | |
428 | 1180 UNGCPRO; |
1181 if (NILP (killp)) | |
1182 return Qnil; | |
1183 b = XBUFFER (buf); /* Hypothetical relocating GC. */ | |
1184 } | |
1185 | |
1186 /* Run hooks with the buffer to be killed temporarily selected, | |
1187 unless the buffer is already dead (could have been deleted | |
1188 in the question above). | |
1189 */ | |
1190 if (BUFFER_LIVE_P (b)) | |
1191 { | |
1192 int speccount = specpdl_depth (); | |
2367 | 1193 |
1194 GCPRO1 (buf); | |
428 | 1195 record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
1196 Fset_buffer (buf); | |
1197 | |
2367 | 1198 { |
1199 /* First run the query functions; if any query is answered no, | |
1200 don't kill the buffer. */ | |
1201 EXTERNAL_LIST_LOOP_2 (arg, Vkill_buffer_query_functions) | |
1202 { | |
1203 if (NILP (call0 (arg))) | |
1204 { | |
1205 UNGCPRO; | |
1206 return unbind_to (speccount); | |
1207 } | |
1208 } | |
1209 } | |
428 | 1210 |
1211 /* Then run the hooks. */ | |
1212 run_hook (Qkill_buffer_hook); | |
442 | 1213 |
1214 /* Inform the selection code that a buffer just got killed. | |
1215 We do this in C because (a) it's faster, and (b) it needs | |
1216 to access data internal to select.c that can't be seen from | |
1217 Lisp (so the Lisp code would just call into C anyway. */ | |
1218 select_notify_buffer_kill (buf); | |
1219 | |
771 | 1220 unbind_to (speccount); |
428 | 1221 UNGCPRO; |
1222 b = XBUFFER (buf); /* Hypothetical relocating GC. */ | |
1223 } | |
1224 | |
1225 /* We have no more questions to ask. Verify that it is valid | |
1226 to kill the buffer. This must be done after the questions | |
1227 since anything can happen within yes-or-no-p. */ | |
1228 | |
1229 /* Might have been deleted during the last question above */ | |
1230 if (!BUFFER_LIVE_P (b)) | |
1231 return Qnil; | |
1232 | |
1233 /* Don't kill the minibuffer now current. */ | |
872 | 1234 if (EQ (buf, XWINDOW_BUFFER (minibuf_window))) |
428 | 1235 return Qnil; |
1236 | |
1237 /* When we kill a base buffer, kill all its indirect buffers. | |
1238 We do it at this stage so nothing terrible happens if they | |
1239 ask questions or their hooks get errors. */ | |
1240 if (! b->base_buffer) | |
1241 { | |
1242 Lisp_Object rest; | |
1243 | |
1244 GCPRO1 (buf); | |
1245 | |
1246 LIST_LOOP (rest, b->indirect_children) | |
1247 { | |
1248 Fkill_buffer (XCAR (rest)); | |
1249 /* Keep indirect_children updated in case a | |
1250 query-function/hook throws. */ | |
1251 b->indirect_children = XCDR (rest); | |
1252 } | |
1253 | |
1254 UNGCPRO; | |
1255 } | |
1256 | |
1257 /* Make this buffer not be current. | |
1258 In the process, notice if this is the sole visible buffer | |
1259 and give up if so. */ | |
1260 if (b == current_buffer) | |
1261 { | |
1262 Fset_buffer (Fother_buffer (buf, Qnil, Qnil)); | |
1263 if (b == current_buffer) | |
1264 return Qnil; | |
1265 } | |
1266 | |
1267 /* Now there is no question: we can kill the buffer. */ | |
1268 | |
1269 #ifdef CLASH_DETECTION | |
1270 /* Unlock this buffer's file, if it is locked. unlock_buffer | |
1271 can both GC and kill the current buffer, and wreak general | |
1272 havok by running lisp code. */ | |
1273 GCPRO1 (buf); | |
1274 unlock_buffer (b); | |
1275 UNGCPRO; | |
1276 b = XBUFFER (buf); | |
1277 | |
1278 if (!BUFFER_LIVE_P (b)) | |
1279 return Qnil; | |
1280 | |
1281 if (b == current_buffer) | |
1282 { | |
1283 Fset_buffer (Fother_buffer (buf, Qnil, Qnil)); | |
1284 if (b == current_buffer) | |
1285 return Qnil; | |
1286 } | |
1287 #endif /* CLASH_DETECTION */ | |
1288 | |
1289 { | |
1290 int speccount = specpdl_depth (); | |
1291 specbind (Qinhibit_quit, Qt); | |
1292 | |
1293 kill_buffer_processes (buf); | |
1294 | |
442 | 1295 delete_from_buffer_alist (buf); |
1296 | |
428 | 1297 /* #### This is a problem if this buffer is in a dedicated window. |
1298 Need to undedicate any windows of this buffer first (and delete them?) | |
1299 */ | |
448 | 1300 GCPRO1 (buf); |
1301 Freplace_buffer_in_windows (buf, Qnil, Qall); | |
1302 UNGCPRO; | |
428 | 1303 |
826 | 1304 #ifdef USE_C_FONT_LOCK |
428 | 1305 font_lock_buffer_was_killed (b); |
826 | 1306 #endif |
428 | 1307 |
1308 /* Delete any auto-save file, if we saved it in this session. */ | |
1309 if (STRINGP (b->auto_save_file_name) | |
1310 && b->auto_save_modified != 0 | |
1311 && BUF_SAVE_MODIFF (b) < b->auto_save_modified) | |
1312 { | |
1313 if (delete_auto_save_files != 0) | |
1314 { | |
1315 /* deleting the auto save file might kill b! */ | |
1316 /* #### dmoore - fix this crap, we do this same gcpro and | |
1317 buffer liveness check multiple times. Let's get a | |
1318 macro or something for it. */ | |
1319 GCPRO1 (buf); | |
1320 internal_delete_file (b->auto_save_file_name); | |
1321 UNGCPRO; | |
1322 b = XBUFFER (buf); | |
1323 | |
1324 if (!BUFFER_LIVE_P (b)) | |
1325 return Qnil; | |
1326 | |
1327 if (b == current_buffer) | |
1328 { | |
1329 Fset_buffer (Fother_buffer (buf, Qnil, Qnil)); | |
1330 if (b == current_buffer) | |
1331 return Qnil; | |
1332 } | |
1333 } | |
1334 } | |
1335 | |
1336 uninit_buffer_markers (b); | |
826 | 1337 uninit_buffer_syntax_cache (b); |
428 | 1338 |
1339 kill_buffer_local_variables (b); | |
1340 | |
1341 b->name = Qnil; | |
1342 uninit_buffer_text (b); | |
1343 b->undo_list = Qnil; | |
1344 uninit_buffer_extents (b); | |
1345 if (b->base_buffer) | |
1346 { | |
800 | 1347 #ifdef ERROR_CHECK_STRUCTURES |
428 | 1348 assert (!NILP (memq_no_quit (buf, b->base_buffer->indirect_children))); |
1349 #endif | |
1350 b->base_buffer->indirect_children = | |
1351 delq_no_quit (buf, b->base_buffer->indirect_children); | |
1352 } | |
1353 | |
1354 /* Clear away all Lisp objects, so that they | |
1355 won't be protected from GC. */ | |
1356 nuke_all_buffer_slots (b, Qnil); | |
1357 | |
853 | 1358 note_object_deleted (buf); |
1359 | |
771 | 1360 unbind_to (speccount); |
428 | 1361 } |
1362 return Qt; | |
1363 } | |
1364 | |
1365 DEFUN ("record-buffer", Frecord_buffer, 1, 1, 0, /* | |
1366 Place buffer BUFFER first in the buffer order. | |
1367 Call this function when a buffer is selected "visibly". | |
1368 | |
1369 This function changes the global buffer order and the per-frame buffer | |
1370 order for the selected frame. The buffer order keeps track of recency | |
1371 of selection so that `other-buffer' will return a recently selected | |
1372 buffer. See `other-buffer' for more information. | |
1373 */ | |
1374 (buffer)) | |
1375 { | |
1376 REGISTER Lisp_Object lynk, prev; | |
1377 struct frame *f = selected_frame (); | |
2353 | 1378 int buffer_found = 0; |
1379 | |
1380 CHECK_BUFFER (buffer); | |
1381 if (!BUFFER_LIVE_P (XBUFFER (buffer))) | |
1382 return Qnil; | |
428 | 1383 prev = Qnil; |
1384 for (lynk = Vbuffer_alist; CONSP (lynk); lynk = XCDR (lynk)) | |
1385 { | |
1386 if (EQ (XCDR (XCAR (lynk)), buffer)) | |
2353 | 1387 { |
1388 buffer_found = 1; | |
1389 break; | |
1390 } | |
428 | 1391 prev = lynk; |
1392 } | |
2353 | 1393 if (buffer_found) |
1394 { | |
1395 /* Effectively do Vbuffer_alist = delq_no_quit (lynk, Vbuffer_alist) */ | |
1396 if (NILP (prev)) | |
1397 Vbuffer_alist = XCDR (Vbuffer_alist); | |
1398 else | |
1399 XCDR (prev) = XCDR (XCDR (prev)); | |
1400 XCDR (lynk) = Vbuffer_alist; | |
1401 Vbuffer_alist = lynk; | |
1402 } | |
428 | 1403 else |
2353 | 1404 Vbuffer_alist = Fcons (Fcons (Fbuffer_name(buffer), buffer), Vbuffer_alist); |
428 | 1405 |
1406 /* That was the global one. Now do the same thing for the | |
1407 per-frame buffer-alist. */ | |
2353 | 1408 buffer_found = 0; |
428 | 1409 prev = Qnil; |
1410 for (lynk = f->buffer_alist; CONSP (lynk); lynk = XCDR (lynk)) | |
1411 { | |
1412 if (EQ (XCDR (XCAR (lynk)), buffer)) | |
2353 | 1413 { |
1414 buffer_found = 1; | |
1415 break; | |
1416 } | |
428 | 1417 prev = lynk; |
1418 } | |
2353 | 1419 if (buffer_found) |
1420 { | |
1421 /* Effectively do f->buffer_alist = delq_no_quit (lynk, f->buffer_alist) */ | |
1422 if (NILP (prev)) | |
1423 f->buffer_alist = XCDR (f->buffer_alist); | |
1424 else | |
1425 XCDR (prev) = XCDR (XCDR (prev)); | |
1426 XCDR (lynk) = f->buffer_alist; | |
1427 f->buffer_alist = lynk; | |
1428 } | |
428 | 1429 else |
2353 | 1430 f->buffer_alist = Fcons (Fcons (Fbuffer_name(buffer), buffer), |
1431 f->buffer_alist); | |
428 | 1432 |
1433 return Qnil; | |
1434 } | |
1435 | |
1436 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, 1, 1, 0, /* | |
1437 Set an appropriate major mode for BUFFER, according to `default-major-mode'. | |
1438 Use this function before selecting the buffer, since it may need to inspect | |
1439 the current buffer's major mode. | |
1440 */ | |
1441 (buffer)) | |
1442 { | |
1443 int speccount = specpdl_depth (); | |
1444 Lisp_Object function = XBUFFER (Vbuffer_defaults)->major_mode; | |
1445 | |
1446 if (NILP (function)) | |
1447 { | |
1448 Lisp_Object tem = Fget (current_buffer->major_mode, Qmode_class, Qnil); | |
1449 if (NILP (tem)) | |
1450 function = current_buffer->major_mode; | |
1451 } | |
1452 | |
1453 if (NILP (function) || EQ (function, Qfundamental_mode)) | |
1454 return Qnil; | |
1455 | |
1456 /* To select a nonfundamental mode, | |
1457 select the buffer temporarily and then call the mode function. */ | |
1458 | |
1459 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
1460 | |
1461 Fset_buffer (buffer); | |
1462 call0 (function); | |
1463 | |
771 | 1464 return unbind_to (speccount); |
428 | 1465 } |
1466 | |
1467 void | |
1468 switch_to_buffer (Lisp_Object bufname, Lisp_Object norecord) | |
1469 { | |
1470 call2 (Qswitch_to_buffer, bufname, norecord); | |
1471 } | |
1472 | |
1473 | |
1474 DEFUN ("current-buffer", Fcurrent_buffer, 0, 0, 0, /* | |
1475 Return the current buffer as a Lisp object. | |
1476 */ | |
1477 ()) | |
1478 { | |
793 | 1479 return wrap_buffer (current_buffer); |
428 | 1480 } |
1481 | |
1482 /* Set the current buffer to B. */ | |
1483 | |
1484 void | |
1485 set_buffer_internal (struct buffer *b) | |
1486 { | |
1487 REGISTER struct buffer *old_buf; | |
1488 REGISTER Lisp_Object tail; | |
1489 | |
1490 if (current_buffer == b) | |
1491 return; | |
1492 | |
1493 INVALIDATE_PIXEL_TO_GLYPH_CACHE; | |
1494 | |
1495 old_buf = current_buffer; | |
1496 current_buffer = b; | |
1497 invalidate_current_column (); /* invalidate indentation cache */ | |
1498 | |
1499 if (old_buf) | |
1500 { | |
1501 /* Put the undo list back in the base buffer, so that it appears | |
1502 that an indirect buffer shares the undo list of its base. */ | |
1503 if (old_buf->base_buffer) | |
1504 old_buf->base_buffer->undo_list = old_buf->undo_list; | |
1505 } | |
1506 | |
1507 /* Get the undo list from the base buffer, so that it appears | |
1508 that an indirect buffer shares the undo list of its base. */ | |
1509 if (b->base_buffer) | |
1510 b->undo_list = b->base_buffer->undo_list; | |
1511 | |
1512 /* Look down buffer's list of local Lisp variables | |
1513 to find and update any that forward into C variables. */ | |
1514 | |
1515 LIST_LOOP (tail, b->local_var_alist) | |
1516 { | |
1517 Lisp_Object sym = XCAR (XCAR (tail)); | |
1518 Lisp_Object valcontents = XSYMBOL (sym)->value; | |
1519 if (SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1520 { | |
1521 /* Just reference the variable | |
1522 to cause it to become set for this buffer. */ | |
1523 /* Use find_symbol_value_quickly to avoid an unnecessary O(n) | |
1524 lookup. */ | |
1525 (void) find_symbol_value_quickly (XCAR (tail), 1); | |
1526 } | |
1527 } | |
1528 | |
1529 /* Do the same with any others that were local to the previous buffer */ | |
1530 | |
1531 if (old_buf) | |
1532 { | |
1533 LIST_LOOP (tail, old_buf->local_var_alist) | |
1534 { | |
1535 Lisp_Object sym = XCAR (XCAR (tail)); | |
1536 Lisp_Object valcontents = XSYMBOL (sym)->value; | |
1537 | |
1538 if (SYMBOL_VALUE_MAGIC_P (valcontents)) | |
1539 { | |
1540 /* Just reference the variable | |
1541 to cause it to become set for this buffer. */ | |
1542 /* Use find_symbol_value_quickly with find_it_p as 0 to avoid an | |
1543 unnecessary O(n) lookup which is guaranteed to be worst case. | |
1544 Any symbols which are local are guaranteed to have been | |
1545 handled in the previous loop, above. */ | |
1546 (void) find_symbol_value_quickly (sym, 0); | |
1547 } | |
1548 } | |
1549 } | |
1550 } | |
1551 | |
1552 DEFUN ("set-buffer", Fset_buffer, 1, 1, 0, /* | |
1553 Make the buffer BUFFER current for editing operations. | |
1554 BUFFER may be a buffer or the name of an existing buffer. | |
1555 See also `save-excursion' when you want to make a buffer current temporarily. | |
1556 This function does not display the buffer, so its effect ends | |
1557 when the current command terminates. | |
1558 Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently. | |
1559 */ | |
1560 (buffer)) | |
1561 { | |
1562 buffer = get_buffer (buffer, 0); | |
1563 if (NILP (buffer)) | |
563 | 1564 invalid_operation ("Selecting deleted or non-existent buffer", Qunbound); |
428 | 1565 set_buffer_internal (XBUFFER (buffer)); |
1566 return buffer; | |
1567 } | |
1568 | |
1569 | |
1570 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, 0, 3, 0, /* | |
444 | 1571 Signal a `buffer-read-only' error if BUFFER is read-only. |
428 | 1572 Optional argument BUFFER defaults to the current buffer. |
1573 | |
1574 If optional argument START is non-nil, all extents in the buffer | |
1575 which overlap that part of the buffer are checked to ensure none has a | |
1576 `read-only' property. (Extents that lie completely within the range, | |
1577 however, are not checked.) END defaults to the value of START. | |
1578 | |
1579 If START and END are equal, the range checked is [START, END] (i.e. | |
1580 closed on both ends); otherwise, the range checked is (START, END) | |
1581 \(open on both ends), except that extents that lie completely within | |
1582 [START, END] are not checked. See `extent-in-region-p' for a fuller | |
1583 discussion. | |
1584 */ | |
1585 (buffer, start, end)) | |
1586 { | |
1587 struct buffer *b = decode_buffer (buffer, 0); | |
665 | 1588 Charbpos s, e; |
428 | 1589 |
1590 if (NILP (start)) | |
1591 s = e = -1; | |
1592 else | |
1593 { | |
1594 if (NILP (end)) | |
1595 end = start; | |
1596 get_buffer_range_char (b, start, end, &s, &e, 0); | |
1597 } | |
1598 barf_if_buffer_read_only (b, s, e); | |
1599 | |
1600 return Qnil; | |
1601 } | |
1602 | |
1603 static void | |
1604 bury_buffer_1 (Lisp_Object buffer, Lisp_Object before, | |
1605 Lisp_Object *buffer_alist) | |
1606 { | |
1607 Lisp_Object aelt = rassq_no_quit (buffer, *buffer_alist); | |
1608 Lisp_Object lynk = memq_no_quit (aelt, *buffer_alist); | |
1609 Lisp_Object iter, before_before; | |
1610 | |
1611 *buffer_alist = delq_no_quit (aelt, *buffer_alist); | |
1612 for (before_before = Qnil, iter = *buffer_alist; | |
1613 !NILP (iter) && !EQ (XCDR (XCAR (iter)), before); | |
1614 before_before = iter, iter = XCDR (iter)) | |
1615 ; | |
1616 XCDR (lynk) = iter; | |
1617 if (!NILP (before_before)) | |
1618 XCDR (before_before) = lynk; | |
1619 else | |
1620 *buffer_alist = lynk; | |
1621 } | |
1622 | |
1623 DEFUN ("bury-buffer", Fbury_buffer, 0, 2, "", /* | |
1624 Put BUFFER at the end of the list of all buffers. | |
1625 There it is the least likely candidate for `other-buffer' to return; | |
1626 thus, the least likely buffer for \\[switch-to-buffer] to select by default. | |
1627 If BUFFER is nil or omitted, bury the current buffer. | |
1628 Also, if BUFFER is nil or omitted, remove the current buffer from the | |
1629 selected window if it is displayed there. | |
434 | 1630 Because of this, you may need to specify (current-buffer) as |
1631 BUFFER when calling from minibuffer. | |
428 | 1632 If BEFORE is non-nil, it specifies a buffer before which BUFFER |
1633 will be placed, instead of being placed at the end. | |
1634 */ | |
1635 (buffer, before)) | |
1636 { | |
1637 /* This function can GC */ | |
1638 struct buffer *buf = decode_buffer (buffer, 1); | |
1639 /* If we're burying the current buffer, unshow it. */ | |
1640 /* Note that the behavior of (bury-buffer nil) and | |
1641 (bury-buffer (current-buffer)) is not the same. | |
1642 This is illogical but is historical. Changing it | |
1643 breaks mh-e and TeX and such packages. */ | |
1644 if (NILP (buffer)) | |
1645 switch_to_buffer (Fother_buffer (Fcurrent_buffer (), Qnil, Qnil), Qnil); | |
793 | 1646 buffer = wrap_buffer (buf); |
428 | 1647 |
1648 if (!NILP (before)) | |
1649 before = get_buffer (before, 1); | |
1650 | |
1651 if (EQ (before, buffer)) | |
563 | 1652 invalid_operation ("Cannot place a buffer before itself", Qunbound); |
428 | 1653 |
1654 bury_buffer_1 (buffer, before, &Vbuffer_alist); | |
1655 bury_buffer_1 (buffer, before, &selected_frame ()->buffer_alist); | |
1656 | |
1657 return Qnil; | |
1658 } | |
1659 | |
1660 | |
1661 DEFUN ("erase-buffer", Ferase_buffer, 0, 1, "*", /* | |
1662 Delete the entire contents of the BUFFER. | |
1663 Any clipping restriction in effect (see `narrow-to-region') is removed, | |
1664 so the buffer is truly empty after this. | |
1665 BUFFER defaults to the current buffer if omitted. | |
1666 */ | |
1667 (buffer)) | |
1668 { | |
1669 /* This function can GC */ | |
1670 struct buffer *b = decode_buffer (buffer, 1); | |
1671 /* #### yuck yuck yuck. This is gross. The old echo-area code, | |
1672 however, was the only place that called erase_buffer() with a | |
1673 non-zero NO_CLIP argument. | |
1674 | |
1675 Someone needs to fix up the redisplay code so it is smarter | |
1676 about this, so that the NO_CLIP junk isn't necessary. */ | |
1677 int no_clip = (b == XBUFFER (Vecho_area_buffer)); | |
1678 | |
1679 INVALIDATE_PIXEL_TO_GLYPH_CACHE; | |
1680 | |
1681 widen_buffer (b, no_clip); | |
1682 buffer_delete_range (b, BUF_BEG (b), BUF_Z (b), 0); | |
1683 b->last_window_start = 1; | |
1684 | |
1685 /* Prevent warnings, or suspension of auto saving, that would happen | |
1686 if future size is less than past size. Use of erase-buffer | |
1687 implies that the future text is not really related to the past text. */ | |
1688 b->saved_size = Qzero; | |
1689 | |
1690 return Qnil; | |
1691 } | |
1692 | |
1693 | |
1694 | |
1695 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, 0, 0, 0, /* | |
1696 Switch to Fundamental mode by killing current buffer's local variables. | |
1697 Most local variable bindings are eliminated so that the default values | |
1698 become effective once more. Also, the syntax table is set from | |
1699 `standard-syntax-table', the category table is set from | |
1700 `standard-category-table' (if support for Mule exists), local keymap is set | |
1701 to nil, the abbrev table is set from `fundamental-mode-abbrev-table', | |
1702 and all specifier specifications whose locale is the current buffer | |
1703 are removed. This function also forces redisplay of the modeline. | |
1704 | |
1705 Every function to select a new major mode starts by | |
1706 calling this function. | |
1707 | |
1708 As a special exception, local variables whose names have | |
1709 a non-nil `permanent-local' property are not eliminated by this function. | |
1710 | |
1711 The first thing this function does is run | |
1712 the normal hook `change-major-mode-hook'. | |
1713 */ | |
1714 ()) | |
1715 { | |
1716 /* This function can GC */ | |
1717 run_hook (Qchange_major_mode_hook); | |
1718 | |
1719 reset_buffer_local_variables (current_buffer, 0); | |
1720 | |
1721 kill_buffer_local_variables (current_buffer); | |
1722 | |
1723 kill_specifier_buffer_locals (Fcurrent_buffer ()); | |
1724 | |
1725 /* Force modeline redisplay. Useful here because all major mode | |
1726 commands call this function. */ | |
1727 MARK_MODELINE_CHANGED; | |
1728 | |
1729 return Qnil; | |
1730 } | |
1731 | |
1732 #ifdef MEMORY_USAGE_STATS | |
1733 | |
1734 struct buffer_stats | |
1735 { | |
1736 int text; | |
1737 int markers; | |
1738 int extents; | |
1739 int other; | |
1740 }; | |
1741 | |
665 | 1742 static Bytecount |
428 | 1743 compute_buffer_text_usage (struct buffer *b, struct overhead_stats *ovstats) |
1744 { | |
1745 int was_requested = b->text->z - 1; | |
665 | 1746 Bytecount gap = b->text->gap_size + b->text->end_gap_size; |
1747 Bytecount malloc_use = malloced_storage_size (b->text->beg, was_requested + gap, 0); | |
428 | 1748 |
1749 ovstats->gap_overhead += gap; | |
1750 ovstats->was_requested += was_requested; | |
1751 ovstats->malloc_overhead += malloc_use - (was_requested + gap); | |
1752 return malloc_use; | |
1753 } | |
1754 | |
1755 static void | |
1756 compute_buffer_usage (struct buffer *b, struct buffer_stats *stats, | |
1757 struct overhead_stats *ovstats) | |
1758 { | |
1759 xzero (*stats); | |
3024 | 1760 stats->other += LISPOBJ_STORAGE_SIZE (b, sizeof (*b), ovstats); |
428 | 1761 stats->text += compute_buffer_text_usage (b, ovstats); |
1762 stats->markers += compute_buffer_marker_usage (b, ovstats); | |
1763 stats->extents += compute_buffer_extent_usage (b, ovstats); | |
1764 } | |
1765 | |
1766 DEFUN ("buffer-memory-usage", Fbuffer_memory_usage, 1, 1, 0, /* | |
1767 Return stats about the memory usage of buffer BUFFER. | |
1768 The values returned are in the form of an alist of usage types and byte | |
1769 counts. The byte counts attempt to encompass all the memory used | |
1770 by the buffer (separate from the memory logically associated with a | |
1771 buffer or frame), including internal structures and any malloc() | |
1772 overhead associated with them. In practice, the byte counts are | |
1773 underestimated because certain memory usage is very hard to determine | |
1774 \(e.g. the amount of memory used inside the Xt library or inside the | |
1775 X server) and because there is other stuff that might logically | |
1776 be associated with a window, buffer, or frame (e.g. window configurations, | |
1777 glyphs) but should not obviously be included in the usage counts. | |
1778 | |
1779 Multiple slices of the total memory usage may be returned, separated | |
1780 by a nil. Each slice represents a particular view of the memory, a | |
1781 particular way of partitioning it into groups. Within a slice, there | |
1782 is no overlap between the groups of memory, and each slice collectively | |
1783 represents all the memory concerned. | |
1784 */ | |
1785 (buffer)) | |
1786 { | |
1787 struct buffer_stats stats; | |
1788 struct overhead_stats ovstats; | |
1789 Lisp_Object val = Qnil; | |
1790 | |
1791 CHECK_BUFFER (buffer); /* dead buffers should be allowed, no? */ | |
1792 xzero (ovstats); | |
1793 compute_buffer_usage (XBUFFER (buffer), &stats, &ovstats); | |
1794 | |
1795 val = acons (Qtext, make_int (stats.text), val); | |
1796 val = acons (Qmarkers, make_int (stats.markers), val); | |
1797 val = acons (Qextents, make_int (stats.extents), val); | |
1798 val = acons (Qother, make_int (stats.other), val); | |
1799 val = Fcons (Qnil, val); | |
1800 val = acons (Qactually_requested, make_int (ovstats.was_requested), val); | |
1801 val = acons (Qmalloc_overhead, make_int (ovstats.malloc_overhead), val); | |
1802 val = acons (Qgap_overhead, make_int (ovstats.gap_overhead), val); | |
1803 val = acons (Qdynarr_overhead, make_int (ovstats.dynarr_overhead), val); | |
1804 | |
1805 return Fnreverse (val); | |
1806 } | |
1807 | |
1808 #endif /* MEMORY_USAGE_STATS */ | |
814 | 1809 |
1810 #if defined (DEBUG_XEMACS) && defined (MULE) | |
1811 | |
1812 DEFUN ("buffer-char-byte-conversion-info", Fbuffer_char_byte_converion_info, | |
1813 1, 1, 0, /* | |
1814 Return the current info used for char-byte conversion in BUFFER. | |
1815 The values returned are in the form of a plist of properties and values. | |
1816 */ | |
1817 (buffer)) | |
1818 { | |
1819 struct buffer *b; | |
1820 Lisp_Object plist = Qnil; | |
1821 | |
1822 CHECK_BUFFER (buffer); /* dead buffers should be allowed, no? */ | |
1823 b = XBUFFER (buffer); | |
1824 | |
1825 #define ADD_INT(field) \ | |
1826 plist = cons3 (make_int (b->text->field), \ | |
1827 intern_converting_underscores_to_dashes (#field), plist) | |
1828 #define ADD_BOOL(field) \ | |
1829 plist = cons3 (b->text->field ? Qt : Qnil, \ | |
1830 intern_converting_underscores_to_dashes (#field), plist) | |
1831 ADD_INT (bufz); | |
1832 ADD_INT (z); | |
2367 | 1833 #ifdef OLD_BYTE_CHAR |
814 | 1834 ADD_INT (mule_bufmin); |
1835 ADD_INT (mule_bufmax); | |
1836 ADD_INT (mule_bytmin); | |
1837 ADD_INT (mule_bytmax); | |
1838 ADD_INT (mule_shifter); | |
1839 ADD_BOOL (mule_three_p); | |
2367 | 1840 #endif |
826 | 1841 ADD_BOOL (entirely_one_byte_p); |
1842 ADD_INT (num_ascii_chars); | |
1843 ADD_INT (num_8_bit_fixed_chars); | |
1844 ADD_INT (num_16_bit_fixed_chars); | |
2367 | 1845 ADD_INT (cached_charpos); |
1846 ADD_INT (cached_bytepos); | |
1847 ADD_INT (next_cache_pos); | |
1848 | |
814 | 1849 { |
2367 | 1850 Lisp_Object pos[NUM_CACHED_POSITIONS]; |
814 | 1851 int i; |
2367 | 1852 for (i = 0; i < b->text->next_cache_pos; i++) |
814 | 1853 pos[i] = make_int (b->text->mule_charbpos_cache[i]); |
2367 | 1854 plist = cons3 (Flist (b->text->next_cache_pos, pos), |
1855 intern ("mule-charbpos-cache"), plist); | |
1856 for (i = 0; i < b->text->next_cache_pos; i++) | |
814 | 1857 pos[i] = make_int (b->text->mule_bytebpos_cache[i]); |
2367 | 1858 plist = cons3 (Flist (b->text->next_cache_pos, pos), |
1859 intern ("mule-bytebpos-cache"), plist); | |
814 | 1860 } |
1861 #undef ADD_INT | |
1862 #undef ADD_BOOL | |
1863 | |
1864 return Fnreverse (plist); | |
1865 } | |
1866 | |
1867 DEFUN ("string-char-byte-conversion-info", Fstring_char_byte_converion_info, 1, 1, 0, /* | |
1868 Return the current info used for char-byte conversion in STRING. | |
1869 The values returned are in the form of a plist of properties and values. | |
1870 */ | |
1871 (string)) | |
1872 { | |
1873 Lisp_Object plist = Qnil; | |
1874 CHECK_STRING (string); | |
1875 | |
1876 plist = cons3 (make_int (XSTRING_LENGTH (string)), | |
1877 intern ("byte-length"), plist); | |
1878 plist = cons3 (make_int (XSTRING_ASCII_BEGIN (string)), | |
1879 intern ("ascii-begin"), plist); | |
1880 | |
1881 return Fnreverse (plist); | |
1882 } | |
1883 | |
1884 #endif /* defined (DEBUG_XEMACS) && defined (MULE) */ | |
1885 | |
440 | 1886 |
1887 | |
428 | 1888 void |
1889 syms_of_buffer (void) | |
1890 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
1891 INIT_LISP_OBJECT (buffer); |
442 | 1892 |
563 | 1893 DEFSYMBOL (Qbuffer_live_p); |
1894 DEFSYMBOL (Qbuffer_or_string_p); | |
1895 DEFSYMBOL (Qmode_class); | |
1896 DEFSYMBOL (Qrename_auto_save_file); | |
1897 DEFSYMBOL (Qkill_buffer_hook); | |
1898 DEFSYMBOL (Qpermanent_local); | |
1899 | |
1900 DEFSYMBOL (Qfirst_change_hook); | |
1901 DEFSYMBOL (Qbefore_change_functions); | |
1902 DEFSYMBOL (Qafter_change_functions); | |
428 | 1903 |
1904 /* #### Obsolete, for compatibility */ | |
563 | 1905 DEFSYMBOL (Qbefore_change_function); |
1906 DEFSYMBOL (Qafter_change_function); | |
1907 | |
1908 DEFSYMBOL (Qdefault_directory); | |
1909 | |
1910 DEFSYMBOL (Qget_file_buffer); | |
1911 DEFSYMBOL (Qchange_major_mode_hook); | |
1912 | |
1913 DEFSYMBOL (Qfundamental_mode); | |
1914 | |
1915 DEFSYMBOL (Qfind_file_compare_truenames); | |
1916 | |
1917 DEFSYMBOL (Qswitch_to_buffer); | |
428 | 1918 |
1919 DEFSUBR (Fbufferp); | |
1920 DEFSUBR (Fbuffer_live_p); | |
1921 DEFSUBR (Fbuffer_list); | |
1922 DEFSUBR (Fdecode_buffer); | |
1923 DEFSUBR (Fget_buffer); | |
1924 DEFSUBR (Fget_file_buffer); | |
1925 DEFSUBR (Fget_buffer_create); | |
1926 DEFSUBR (Fmake_indirect_buffer); | |
1927 | |
1928 DEFSUBR (Fgenerate_new_buffer_name); | |
1929 DEFSUBR (Fbuffer_name); | |
1930 DEFSUBR (Fbuffer_file_name); | |
1931 DEFSUBR (Fbuffer_base_buffer); | |
1932 DEFSUBR (Fbuffer_indirect_children); | |
1933 DEFSUBR (Fbuffer_local_variables); | |
1934 DEFSUBR (Fbuffer_modified_p); | |
1935 DEFSUBR (Fset_buffer_modified_p); | |
1936 DEFSUBR (Fbuffer_modified_tick); | |
1937 DEFSUBR (Frename_buffer); | |
1938 DEFSUBR (Fother_buffer); | |
1939 DEFSUBR (Fbuffer_disable_undo); | |
1940 DEFSUBR (Fbuffer_enable_undo); | |
1941 DEFSUBR (Fkill_buffer); | |
1942 DEFSUBR (Ferase_buffer); | |
1943 DEFSUBR (Frecord_buffer); | |
1944 DEFSUBR (Fset_buffer_major_mode); | |
1945 DEFSUBR (Fcurrent_buffer); | |
1946 DEFSUBR (Fset_buffer); | |
1947 DEFSUBR (Fbarf_if_buffer_read_only); | |
1948 DEFSUBR (Fbury_buffer); | |
1949 DEFSUBR (Fkill_all_local_variables); | |
1950 #ifdef MEMORY_USAGE_STATS | |
1951 DEFSUBR (Fbuffer_memory_usage); | |
1952 #endif | |
814 | 1953 #if defined (DEBUG_XEMACS) && defined (MULE) |
1954 DEFSUBR (Fbuffer_char_byte_converion_info); | |
1955 DEFSUBR (Fstring_char_byte_converion_info); | |
1956 #endif | |
428 | 1957 |
442 | 1958 DEFERROR (Qprotected_field, "Attempt to modify a protected field", |
1959 Qinvalid_change); | |
428 | 1960 } |
1961 | |
1962 void | |
1963 reinit_vars_of_buffer (void) | |
1964 { | |
1965 staticpro_nodump (&Vbuffer_alist); | |
1966 Vbuffer_alist = Qnil; | |
1967 current_buffer = 0; | |
1968 } | |
1969 | |
1970 /* initialize the buffer routines */ | |
1971 void | |
1972 vars_of_buffer (void) | |
1973 { | |
1974 /* This function can GC */ | |
1975 staticpro (&QSFundamental); | |
1976 staticpro (&QSscratch); | |
1977 | |
1978 QSFundamental = build_string ("Fundamental"); | |
1979 QSscratch = build_string (DEFER_GETTEXT ("*scratch*")); | |
1980 | |
1981 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook /* | |
1982 List of hooks to be run before killing local variables in a buffer. | |
1983 This should be used by any mode that temporarily alters the contents or | |
1984 the read-only state of the buffer. See also `kill-all-local-variables'. | |
1985 */ ); | |
1986 Vchange_major_mode_hook = Qnil; | |
1987 | |
1988 DEFVAR_BOOL ("find-file-compare-truenames", &find_file_compare_truenames /* | |
444 | 1989 If this is true, then the `find-file' command will check the truenames |
428 | 1990 of all visited files when deciding whether a given file is already in |
444 | 1991 a buffer, instead of just `buffer-file-name'. This means that if you |
1992 attempt to visit another file which is a symbolic link to a file which | |
1993 is already in a buffer, the existing buffer will be found instead of a | |
1994 newly-created one. This works if any component of the pathname | |
1995 (including a non-terminal component) is a symbolic link as well, but | |
1996 doesn't work with hard links (nothing does). | |
1997 | |
1998 See also the variable `find-file-use-truenames'. | |
428 | 1999 */ ); |
446 | 2000 #if defined(CYGWIN) || defined(WIN32_NATIVE) |
2001 find_file_compare_truenames = 1; | |
2002 #else | |
428 | 2003 find_file_compare_truenames = 0; |
446 | 2004 #endif |
428 | 2005 |
2006 DEFVAR_BOOL ("find-file-use-truenames", &find_file_use_truenames /* | |
2007 If this is true, then a buffer's visited file-name will always be | |
2008 chased back to the real file; it will never be a symbolic link, and there | |
2009 will never be a symbolic link anywhere in its directory path. | |
2010 That is, the buffer-file-name and buffer-file-truename will be equal. | |
2011 This doesn't work with hard links. | |
2012 | |
444 | 2013 See also the variable `find-file-compare-truenames'. |
428 | 2014 */ ); |
2015 find_file_use_truenames = 0; | |
2016 | |
2017 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions /* | |
2018 List of functions to call before each text change. | |
2019 Two arguments are passed to each function: the positions of | |
2020 the beginning and end of the range of old text to be changed. | |
2021 \(For an insertion, the beginning and end are at the same place.) | |
2022 No information is given about the length of the text after the change. | |
2023 | |
2024 Buffer changes made while executing the `before-change-functions' | |
2025 don't call any before-change or after-change functions. | |
2026 */ ); | |
2027 Vbefore_change_functions = Qnil; | |
2028 | |
2029 /* FSF Emacs has the following additional doc at the end of | |
2030 before-change-functions and after-change-functions: | |
2031 | |
2032 That's because these variables are temporarily set to nil. | |
2033 As a result, a hook function cannot straightforwardly alter the value of | |
2034 these variables. See the Emacs Lisp manual for a way of | |
2035 accomplishing an equivalent result by using other variables. | |
2036 | |
2037 But this doesn't apply under XEmacs because things are | |
2038 handled better. */ | |
2039 | |
2040 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions /* | |
2041 List of functions to call after each text change. | |
2042 Three arguments are passed to each function: the positions of | |
2043 the beginning and end of the range of changed text, | |
2044 and the length of the pre-change text replaced by that range. | |
2045 \(For an insertion, the pre-change length is zero; | |
2046 for a deletion, that length is the number of characters deleted, | |
2047 and the post-change beginning and end are at the same place.) | |
2048 | |
2049 Buffer changes made while executing `after-change-functions' | |
2050 don't call any before-change or after-change functions. | |
2051 */ ); | |
2052 Vafter_change_functions = Qnil; | |
2053 | |
2054 DEFVAR_LISP ("before-change-function", &Vbefore_change_function /* | |
2055 | |
2056 */ ); /* obsoleteness will be documented */ | |
2057 Vbefore_change_function = Qnil; | |
2058 | |
2059 DEFVAR_LISP ("after-change-function", &Vafter_change_function /* | |
2060 | |
2061 */ ); /* obsoleteness will be documented */ | |
2062 Vafter_change_function = Qnil; | |
2063 | |
2064 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook /* | |
2065 A list of functions to call before changing a buffer which is unmodified. | |
2066 The functions are run using the `run-hooks' function. | |
2067 */ ); | |
2068 Vfirst_change_hook = Qnil; | |
2069 | |
2070 #if 0 /* FSFmacs */ | |
2071 xxDEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode /* | |
2072 *Non-nil means deactivate the mark when the buffer contents change. | |
2073 */ ); | |
2074 Vtransient_mark_mode = Qnil; | |
2075 #endif /* FSFmacs */ | |
2076 | |
2077 DEFVAR_INT ("undo-threshold", &undo_threshold /* | |
2078 Keep no more undo information once it exceeds this size. | |
2079 This threshold is applied when garbage collection happens. | |
2080 The size is counted as the number of bytes occupied, | |
2081 which includes both saved text and other data. | |
2082 */ ); | |
2083 undo_threshold = 20000; | |
2084 | |
2085 DEFVAR_INT ("undo-high-threshold", &undo_high_threshold /* | |
2086 Don't keep more than this much size of undo information. | |
2087 A command which pushes past this size is itself forgotten. | |
2088 This threshold is applied when garbage collection happens. | |
2089 The size is counted as the number of bytes occupied, | |
2090 which includes both saved text and other data. | |
2091 */ ); | |
2092 undo_high_threshold = 30000; | |
2093 | |
2094 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only /* | |
2095 *Non-nil means disregard read-only status of buffers or characters. | |
2096 If the value is t, disregard `buffer-read-only' and all `read-only' | |
2097 text properties. If the value is a list, disregard `buffer-read-only' | |
2098 and disregard a `read-only' extent property or text property if the | |
2099 property value is a member of the list. | |
2100 */ ); | |
2101 Vinhibit_read_only = Qnil; | |
2102 | |
2103 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions /* | |
2104 List of functions called with no args to query before killing a buffer. | |
2105 */ ); | |
2106 Vkill_buffer_query_functions = Qnil; | |
2107 | |
2108 DEFVAR_BOOL ("delete-auto-save-files", &delete_auto_save_files /* | |
2109 *Non-nil means delete auto-save file when a buffer is saved or killed. | |
2110 */ ); | |
2111 delete_auto_save_files = 1; | |
2112 } | |
2113 | |
2114 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */ | |
2115 | |
2720 | 2116 #ifdef MC_ALLOC |
2117 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magic_fun) \ | |
2118 do \ | |
2119 { \ | |
2120 struct symbol_value_forward *I_hate_C = \ | |
2121 alloc_lrecord_type (struct symbol_value_forward, \ | |
2122 &lrecord_symbol_value_forward); \ | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2123 /*mcpro ((Lisp_Object) I_hate_C);*/ \ |
2720 | 2124 \ |
2125 I_hate_C->magic.value = &(buffer_local_flags.field_name); \ | |
2126 I_hate_C->magic.type = forward_type; \ | |
2127 I_hate_C->magicfun = magic_fun; \ | |
2128 \ | |
2129 MARK_LRECORD_AS_LISP_READONLY (I_hate_C); \ | |
2130 \ | |
2131 { \ | |
2132 int offset = ((char *)symbol_value_forward_forward (I_hate_C) - \ | |
2133 (char *)&buffer_local_flags); \ | |
2134 defvar_magic (lname, I_hate_C); \ | |
2135 \ | |
2136 *((Lisp_Object *)(offset + (char *)XBUFFER (Vbuffer_local_symbols))) \ | |
2137 = intern (lname); \ | |
2138 } \ | |
2139 } while (0) | |
2140 | |
2141 #else /* not MC_ALLOC */ | |
428 | 2142 /* Renamed from DEFVAR_PER_BUFFER because FSFmacs D_P_B takes |
2143 a bogus extra arg, which confuses an otherwise identical make-docfile.c */ | |
2720 | 2144 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magicfun) \ |
2145 do { \ | |
2146 static const struct symbol_value_forward I_hate_C = \ | |
2147 { /* struct symbol_value_forward */ \ | |
2148 { /* struct symbol_value_magic */ \ | |
3024 | 2149 { /* struct old_lcrecord_header */ \ |
2720 | 2150 { /* struct lrecord_header */ \ |
2151 lrecord_type_symbol_value_forward, /* lrecord_type_index */ \ | |
2152 1, /* mark bit */ \ | |
2153 1, /* c_readonly bit */ \ | |
2154 1 /* lisp_readonly bit */ \ | |
2155 }, \ | |
2156 0, /* next */ \ | |
2157 0, /* uid */ \ | |
2158 0 /* free */ \ | |
2159 }, \ | |
2160 &(buffer_local_flags.field_name), \ | |
2161 forward_type \ | |
2162 }, \ | |
2163 magicfun \ | |
2164 }; \ | |
2165 \ | |
2166 { \ | |
2167 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) - \ | |
2168 (char *)&buffer_local_flags); \ | |
2169 defvar_magic (lname, &I_hate_C); \ | |
2170 \ | |
2171 *((Lisp_Object *)(offset + (char *)XBUFFER (Vbuffer_local_symbols))) \ | |
2172 = intern (lname); \ | |
2173 } \ | |
428 | 2174 } while (0) |
2720 | 2175 #endif /* not MC_ALLOC */ |
2176 | |
428 | 2177 #define DEFVAR_BUFFER_LOCAL_MAGIC(lname, field_name, magicfun) \ |
2178 DEFVAR_BUFFER_LOCAL_1 (lname, field_name, \ | |
2179 SYMVAL_CURRENT_BUFFER_FORWARD, magicfun) | |
2180 #define DEFVAR_BUFFER_LOCAL(lname, field_name) \ | |
2181 DEFVAR_BUFFER_LOCAL_MAGIC (lname, field_name, 0) | |
2182 #define DEFVAR_CONST_BUFFER_LOCAL_MAGIC(lname, field_name, magicfun) \ | |
2183 DEFVAR_BUFFER_LOCAL_1 (lname, field_name, \ | |
2184 SYMVAL_CONST_CURRENT_BUFFER_FORWARD, magicfun) | |
2185 #define DEFVAR_CONST_BUFFER_LOCAL(lname, field_name) \ | |
2186 DEFVAR_CONST_BUFFER_LOCAL_MAGIC (lname, field_name, 0) | |
2187 | |
2188 #define DEFVAR_BUFFER_DEFAULTS_MAGIC(lname, field_name, magicfun) \ | |
2189 DEFVAR_SYMVAL_FWD (lname, &(buffer_local_flags.field_name), \ | |
2190 SYMVAL_DEFAULT_BUFFER_FORWARD, magicfun) | |
2191 #define DEFVAR_BUFFER_DEFAULTS(lname, field_name) \ | |
2192 DEFVAR_BUFFER_DEFAULTS_MAGIC (lname, field_name, 0) | |
2193 | |
2194 static void | |
2195 nuke_all_buffer_slots (struct buffer *b, Lisp_Object zap) | |
2196 { | |
3017 | 2197 ZERO_LCRECORD (b); |
428 | 2198 |
2199 b->extent_info = Qnil; | |
2200 b->indirect_children = Qnil; | |
2201 b->own_text.line_number_cache = Qnil; | |
2202 | |
1204 | 2203 #define MARKED_SLOT(x) b->x = zap; |
428 | 2204 #include "bufslots.h" |
2205 } | |
2206 | |
2207 static void | |
2208 common_init_complex_vars_of_buffer (void) | |
2209 { | |
2210 /* Make sure all markable slots in buffer_defaults | |
2211 are initialized reasonably, so mark_buffer won't choke. */ | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2212 Lisp_Object defobj = ALLOC_LISP_OBJECT (buffer); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2213 struct buffer *defs = XBUFFER (defobj); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2214 Lisp_Object symobj = ALLOC_LISP_OBJECT (buffer); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2215 struct buffer *syms = XBUFFER (symobj); |
428 | 2216 |
2217 staticpro_nodump (&Vbuffer_defaults); | |
2218 staticpro_nodump (&Vbuffer_local_symbols); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2219 Vbuffer_defaults = defobj; |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2220 Vbuffer_local_symbols = symobj; |
428 | 2221 |
2222 nuke_all_buffer_slots (syms, Qnil); | |
2223 nuke_all_buffer_slots (defs, Qnil); | |
2224 defs->text = &defs->own_text; | |
2225 syms->text = &syms->own_text; | |
2226 | |
2227 /* Set up the non-nil default values of various buffer slots. | |
2228 Must do these before making the first buffer. */ | |
2229 defs->major_mode = Qfundamental_mode; | |
2230 defs->mode_name = QSFundamental; | |
2231 defs->abbrev_table = Qnil; /* real default setup by Lisp code */ | |
2232 | |
446 | 2233 defs->case_table = Vstandard_case_table; |
428 | 2234 #ifdef MULE |
2235 defs->category_table = Vstandard_category_table; | |
2236 #endif /* MULE */ | |
2237 defs->syntax_table = Vstandard_syntax_table; | |
2238 defs->mirror_syntax_table = | |
2239 XCHAR_TABLE (Vstandard_syntax_table)->mirror_table; | |
2240 defs->modeline_format = build_string ("%-"); /* reset in loaddefs.el */ | |
2241 defs->case_fold_search = Qt; | |
2242 defs->selective_display_ellipses = Qt; | |
2243 defs->tab_width = make_int (8); | |
2244 defs->ctl_arrow = Qt; | |
2245 defs->fill_column = make_int (70); | |
2246 defs->left_margin = Qzero; | |
2247 defs->saved_size = Qzero; /* lisp code wants int-or-nil */ | |
2248 defs->modtime = 0; | |
2249 defs->auto_save_modified = 0; | |
2250 defs->auto_save_failure_time = -1; | |
2251 defs->invisibility_spec = Qt; | |
448 | 2252 defs->buffer_local_face_property = 0; |
428 | 2253 |
2254 defs->indirect_children = Qnil; | |
2255 syms->indirect_children = Qnil; | |
2256 | |
2257 { | |
2258 /* 0 means var is always local. Default used only at creation. | |
2259 * -1 means var is always local. Default used only at reset and | |
2260 * creation. | |
2261 * -2 means there's no lisp variable corresponding to this slot | |
2262 * and the default is only used at creation. | |
2263 * -3 means no Lisp variable. Default used only at reset and creation. | |
2264 * >0 is mask. Var is local if ((buffer->local_var_flags & mask) != 0) | |
2265 * Otherwise default is used. | |
2266 */ | |
2267 Lisp_Object always_local_no_default = make_int (0); | |
2268 Lisp_Object always_local_resettable = make_int (-1); | |
2269 Lisp_Object resettable = make_int (-3); | |
2270 | |
2271 /* Assign the local-flags to the slots that have default values. | |
2272 The local flag is a bit that is used in the buffer | |
2273 to say that it has its own local value for the slot. | |
2274 The local flag bits are in the local_var_flags slot of the | |
2275 buffer. */ | |
2276 | |
2277 nuke_all_buffer_slots (&buffer_local_flags, make_int (-2)); | |
2278 buffer_local_flags.filename = always_local_no_default; | |
2279 buffer_local_flags.directory = always_local_no_default; | |
2280 buffer_local_flags.backed_up = always_local_no_default; | |
2281 buffer_local_flags.saved_size = always_local_no_default; | |
2282 buffer_local_flags.auto_save_file_name = always_local_no_default; | |
2283 buffer_local_flags.read_only = always_local_no_default; | |
2284 | |
2285 buffer_local_flags.major_mode = always_local_resettable; | |
2286 buffer_local_flags.mode_name = always_local_resettable; | |
2287 buffer_local_flags.undo_list = always_local_no_default; | |
2288 #if 0 /* FSFmacs */ | |
2289 buffer_local_flags.mark_active = always_local_resettable; | |
2290 #endif | |
2291 buffer_local_flags.point_before_scroll = always_local_resettable; | |
2292 buffer_local_flags.file_truename = always_local_no_default; | |
2293 buffer_local_flags.invisibility_spec = always_local_resettable; | |
2294 buffer_local_flags.file_format = always_local_resettable; | |
2295 buffer_local_flags.generated_modeline_string = always_local_no_default; | |
2296 | |
2297 buffer_local_flags.keymap = resettable; | |
446 | 2298 buffer_local_flags.case_table = resettable; |
428 | 2299 buffer_local_flags.syntax_table = resettable; |
2300 #ifdef MULE | |
2301 buffer_local_flags.category_table = resettable; | |
2302 #endif | |
2303 | |
2304 buffer_local_flags.modeline_format = make_int (1<<0); | |
2305 buffer_local_flags.abbrev_mode = make_int (1<<1); | |
2306 buffer_local_flags.overwrite_mode = make_int (1<<2); | |
2307 buffer_local_flags.case_fold_search = make_int (1<<3); | |
2308 buffer_local_flags.auto_fill_function = make_int (1<<4); | |
2309 buffer_local_flags.selective_display = make_int (1<<5); | |
2310 buffer_local_flags.selective_display_ellipses = make_int (1<<6); | |
2311 buffer_local_flags.tab_width = make_int (1<<7); | |
2312 buffer_local_flags.truncate_lines = make_int (1<<8); | |
2313 buffer_local_flags.ctl_arrow = make_int (1<<9); | |
2314 buffer_local_flags.fill_column = make_int (1<<10); | |
2315 buffer_local_flags.left_margin = make_int (1<<11); | |
2316 buffer_local_flags.abbrev_table = make_int (1<<12); | |
2317 #ifdef REGION_CACHE_NEEDS_WORK | |
2318 buffer_local_flags.cache_long_line_scans = make_int (1<<13); | |
2319 #endif | |
2320 buffer_local_flags.buffer_file_coding_system = make_int (1<<14); | |
2321 | |
2322 /* #### Warning: 1<<31 is the largest number currently allowable | |
2323 due to the XINT() handling of this value. With some | |
558 | 2324 rearrangement you can get 3 more bits. |
2325 | |
2326 #### 3 more? 34 bits???? -ben */ | |
428 | 2327 } |
2328 } | |
2329 | |
2330 #define BUFFER_SLOTS_SIZE (offsetof (struct buffer, BUFFER_SLOTS_LAST_NAME) - offsetof (struct buffer, BUFFER_SLOTS_FIRST_NAME) + sizeof (Lisp_Object)) | |
2331 #define BUFFER_SLOTS_COUNT (BUFFER_SLOTS_SIZE / sizeof (Lisp_Object)) | |
2332 | |
2333 void | |
771 | 2334 reinit_complex_vars_of_buffer_runtime_only (void) |
428 | 2335 { |
2336 struct buffer *defs, *syms; | |
2337 | |
2338 common_init_complex_vars_of_buffer (); | |
2339 | |
2340 defs = XBUFFER (Vbuffer_defaults); | |
2341 syms = XBUFFER (Vbuffer_local_symbols); | |
2342 memcpy (&defs->BUFFER_SLOTS_FIRST_NAME, | |
2343 buffer_defaults_saved_slots, | |
2344 BUFFER_SLOTS_SIZE); | |
2345 memcpy (&syms->BUFFER_SLOTS_FIRST_NAME, | |
2346 buffer_local_symbols_saved_slots, | |
2347 BUFFER_SLOTS_SIZE); | |
2348 } | |
2349 | |
2350 | |
1204 | 2351 static const struct memory_description buffer_slots_description_1[] = { |
440 | 2352 { XD_LISP_OBJECT_ARRAY, 0, BUFFER_SLOTS_COUNT }, |
428 | 2353 { XD_END } |
2354 }; | |
2355 | |
1204 | 2356 static const struct sized_memory_description buffer_slots_description = { |
428 | 2357 BUFFER_SLOTS_SIZE, |
2358 buffer_slots_description_1 | |
2359 }; | |
2360 | |
2361 void | |
2362 complex_vars_of_buffer (void) | |
2363 { | |
2364 struct buffer *defs, *syms; | |
2365 | |
2366 common_init_complex_vars_of_buffer (); | |
2367 | |
2368 defs = XBUFFER (Vbuffer_defaults); | |
2369 syms = XBUFFER (Vbuffer_local_symbols); | |
2370 buffer_defaults_saved_slots = &defs->BUFFER_SLOTS_FIRST_NAME; | |
2371 buffer_local_symbols_saved_slots = &syms->BUFFER_SLOTS_FIRST_NAME; | |
2367 | 2372 dump_add_root_block_ptr (&buffer_defaults_saved_slots, &buffer_slots_description); |
2373 dump_add_root_block_ptr (&buffer_local_symbols_saved_slots, &buffer_slots_description); | |
440 | 2374 |
428 | 2375 DEFVAR_BUFFER_DEFAULTS ("default-modeline-format", modeline_format /* |
2376 Default value of `modeline-format' for buffers that don't override it. | |
2377 This is the same as (default-value 'modeline-format). | |
2378 */ ); | |
2379 | |
2380 DEFVAR_BUFFER_DEFAULTS ("default-abbrev-mode", abbrev_mode /* | |
2381 Default value of `abbrev-mode' for buffers that do not override it. | |
2382 This is the same as (default-value 'abbrev-mode). | |
2383 */ ); | |
2384 | |
2385 DEFVAR_BUFFER_DEFAULTS ("default-ctl-arrow", ctl_arrow /* | |
2386 Default value of `ctl-arrow' for buffers that do not override it. | |
2387 This is the same as (default-value 'ctl-arrow). | |
2388 */ ); | |
2389 | |
2390 #if 0 /* #### make this a specifier! */ | |
2391 DEFVAR_BUFFER_DEFAULTS ("default-display-direction", display_direction /* | |
2392 Default display-direction for buffers that do not override it. | |
2393 This is the same as (default-value 'display-direction). | |
2394 Note: This is not yet implemented. | |
2395 */ ); | |
2396 #endif | |
2397 | |
2398 DEFVAR_BUFFER_DEFAULTS ("default-truncate-lines", truncate_lines /* | |
2399 Default value of `truncate-lines' for buffers that do not override it. | |
2400 This is the same as (default-value 'truncate-lines). | |
2401 */ ); | |
2402 | |
2403 DEFVAR_BUFFER_DEFAULTS ("default-fill-column", fill_column /* | |
2404 Default value of `fill-column' for buffers that do not override it. | |
2405 This is the same as (default-value 'fill-column). | |
2406 */ ); | |
2407 | |
2408 DEFVAR_BUFFER_DEFAULTS ("default-left-margin", left_margin /* | |
2409 Default value of `left-margin' for buffers that do not override it. | |
2410 This is the same as (default-value 'left-margin). | |
2411 */ ); | |
2412 | |
2413 DEFVAR_BUFFER_DEFAULTS ("default-tab-width", tab_width /* | |
2414 Default value of `tab-width' for buffers that do not override it. | |
2415 This is the same as (default-value 'tab-width). | |
2416 */ ); | |
2417 | |
2418 DEFVAR_BUFFER_DEFAULTS ("default-case-fold-search", case_fold_search /* | |
2419 Default value of `case-fold-search' for buffers that don't override it. | |
2420 This is the same as (default-value 'case-fold-search). | |
2421 */ ); | |
2422 | |
2423 DEFVAR_BUFFER_LOCAL ("modeline-format", modeline_format /* | |
2424 Template for displaying modeline for current buffer. | |
2425 Each buffer has its own value of this variable. | |
442 | 2426 Value may be a string, symbol, glyph, generic specifier, list or cons cell. |
2427 For a symbol, its value is processed (but it is ignored if t or nil). | |
428 | 2428 A string appearing directly as the value of a symbol is processed verbatim |
2429 in that the %-constructs below are not recognized. | |
2430 For a glyph, it is inserted as is. | |
442 | 2431 For a generic specifier (i.e. a specifier of type `generic'), its instance |
2432 is computed in the current window using the equivalent of `specifier-instance' | |
2433 and the value is processed. | |
428 | 2434 For a list whose car is a symbol, the symbol's value is taken, |
2435 and if that is non-nil, the cadr of the list is processed recursively. | |
2436 Otherwise, the caddr of the list (if there is one) is processed. | |
771 | 2437 For a list whose car is a boolean specifier, its instance is computed |
2438 in the current window using the equivalent of `specifier-instance', | |
2439 and if that is non-nil, the cadr of the list is processed recursively. | |
2440 Otherwise, the caddr of the list (if there is one) is processed. | |
428 | 2441 For a list whose car is a string or list, each element is processed |
2442 recursively and the results are effectively concatenated. | |
2443 For a list whose car is an integer, the cdr of the list is processed | |
442 | 2444 and padded (if the number is positive) or truncated (if negative) |
2445 to the width specified by that number. | |
428 | 2446 For a list whose car is an extent, the cdr of the list is processed |
2447 normally but the results are displayed using the face of the | |
2448 extent, and mouse clicks over this section are processed using the | |
2449 keymap of the extent. (In addition, if the extent has a help-echo | |
2450 property, that string will be echoed when the mouse moves over this | |
442 | 2451 section.) If extents are nested, all keymaps are properly consulted |
2452 when processing mouse clicks, but multiple faces are not correctly | |
2453 merged (only the first face is used), and lists of faces are not | |
2454 correctly handled. See `generated-modeline-string' for more information. | |
428 | 2455 A string is printed verbatim in the modeline except for %-constructs: |
2456 (%-constructs are processed when the string is the entire modeline-format | |
2457 or when it is found in a cons-cell or a list) | |
2458 %b -- print buffer name. %c -- print the current column number. | |
2459 %f -- print visited file name. | |
2460 %* -- print %, * or hyphen. %+ -- print *, % or hyphen. | |
2461 % means buffer is read-only and * means it is modified. | |
2462 For a modified read-only buffer, %* gives % and %+ gives *. | |
2463 %s -- print process status. %l -- print the current line number. | |
2464 %S -- print name of selected frame (only meaningful under X Windows). | |
2465 %p -- print percent of buffer above top of window, or Top, Bot or All. | |
2466 %P -- print percent of buffer above bottom of window, perhaps plus Top, | |
2467 or print Bottom or All. | |
2468 %n -- print Narrow if appropriate. | |
771 | 2469 %C -- print the mnemonic for `buffer-file-coding-system'. |
428 | 2470 %[ -- print one [ for each recursive editing level. %] similar. |
2471 %% -- print %. %- -- print infinitely many dashes. | |
2472 Decimal digits after the % specify field width to which to pad. | |
2473 */ ); | |
2474 | |
2475 DEFVAR_BUFFER_DEFAULTS ("default-major-mode", major_mode /* | |
2476 *Major mode for new buffers. Defaults to `fundamental-mode'. | |
2477 nil here means use current buffer's major mode. | |
2478 */ ); | |
2479 | |
2480 DEFVAR_BUFFER_DEFAULTS ("fundamental-mode-abbrev-table", abbrev_table /* | |
2481 The abbrev table of mode-specific abbrevs for Fundamental Mode. | |
2482 */ ); | |
2483 | |
2484 DEFVAR_BUFFER_LOCAL ("major-mode", major_mode /* | |
2485 Symbol for current buffer's major mode. | |
2486 */ ); | |
2487 | |
2488 DEFVAR_BUFFER_LOCAL ("mode-name", mode_name /* | |
2489 Pretty name of current buffer's major mode (a string). | |
2490 */ ); | |
2491 | |
2492 DEFVAR_BUFFER_LOCAL ("abbrev-mode", abbrev_mode /* | |
2493 Non-nil turns on automatic expansion of abbrevs as they are inserted. | |
2494 Automatically becomes buffer-local when set in any fashion. | |
2495 */ ); | |
2496 | |
2497 DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search /* | |
2498 *Non-nil if searches should ignore case. | |
2499 Automatically becomes buffer-local when set in any fashion. | |
2500 */ ); | |
2501 | |
2502 DEFVAR_BUFFER_LOCAL ("fill-column", fill_column /* | |
2503 *Column beyond which automatic line-wrapping should happen. | |
2504 Automatically becomes buffer-local when set in any fashion. | |
2505 */ ); | |
2506 | |
2507 DEFVAR_BUFFER_LOCAL ("left-margin", left_margin /* | |
2508 *Column for the default indent-line-function to indent to. | |
2509 Linefeed indents to this column in Fundamental mode. | |
2510 Automatically becomes buffer-local when set in any fashion. | |
2511 Do not confuse this with the specifier `left-margin-width'; | |
2512 that controls the size of a margin that is displayed outside | |
2513 of the text area. | |
2514 */ ); | |
2515 | |
2516 DEFVAR_BUFFER_LOCAL_MAGIC ("tab-width", tab_width /* | |
2517 *Distance between tab stops (for display of tab characters), in columns. | |
2518 Automatically becomes buffer-local when set in any fashion. | |
2519 */ , redisplay_variable_changed); | |
2520 | |
2521 DEFVAR_BUFFER_LOCAL_MAGIC ("ctl-arrow", ctl_arrow /* | |
2522 *Non-nil means display control chars with uparrow. | |
2523 Nil means use backslash and octal digits. | |
2524 An integer means characters >= ctl-arrow are assumed to be printable, and | |
2525 will be displayed as a single glyph. | |
2526 Any other value is the same as 160 - the code SPC with the high bit on. | |
2527 | |
2528 The interpretation of this variable is likely to change in the future. | |
2529 | |
2530 Automatically becomes buffer-local when set in any fashion. | |
2531 This variable does not apply to characters whose display is specified | |
2532 in the current display table (if there is one). | |
2533 */ , redisplay_variable_changed); | |
2534 | |
2535 #if 0 /* #### Make this a specifier! */ | |
2536 xxDEFVAR_BUFFER_LOCAL ("display-direction", display_direction /* | |
2537 *Non-nil means lines in the buffer are displayed right to left. | |
2538 Nil means left to right. (Not yet implemented.) | |
2539 */ ); | |
2540 #endif /* Not yet implemented */ | |
2541 | |
2542 DEFVAR_BUFFER_LOCAL_MAGIC ("truncate-lines", truncate_lines /* | |
2543 *Non-nil means do not display continuation lines; | |
2544 give each line of text one frame line. | |
2545 Automatically becomes buffer-local when set in any fashion. | |
2546 | |
2547 Note that this is overridden by the variable | |
2548 `truncate-partial-width-windows' if that variable is non-nil | |
2549 and this buffer is not full-frame width. | |
2550 */ , redisplay_variable_changed); | |
2551 | |
2552 DEFVAR_BUFFER_LOCAL ("default-directory", directory /* | |
2553 Name of default directory of current buffer. Should end with slash. | |
2554 Each buffer has its own value of this variable. | |
2555 */ ); | |
2556 | |
771 | 2557 /* NOTE: The default value is set in code-init.el. */ |
428 | 2558 DEFVAR_BUFFER_DEFAULTS ("default-buffer-file-coding-system", buffer_file_coding_system /* |
2559 Default value of `buffer-file-coding-system' for buffers that do not override it. | |
2560 This is the same as (default-value 'buffer-file-coding-system). | |
2561 This value is used both for buffers without associated files and | |
2562 for buffers whose files do not have any apparent coding system. | |
2563 See `buffer-file-coding-system'. | |
2564 */ ); | |
2565 | |
2566 DEFVAR_BUFFER_LOCAL ("buffer-file-coding-system", buffer_file_coding_system /* | |
2567 *Current coding system for the current buffer. | |
2568 When the buffer is written out into a file, this coding system will be | |
2569 used for the encoding. Automatically buffer-local when set in any | |
2570 fashion. This is normally set automatically when a file is loaded in | |
2571 based on the determined coding system of the file (assuming that | |
2572 `buffer-file-coding-system-for-read' is set to `undecided', which | |
2573 calls for automatic determination of the file's coding system). | |
2574 Normally the modeline indicates the current file coding system using | |
2575 its mnemonic abbreviation. | |
2576 | |
2577 The default value for this variable (which is normally used for | |
2578 buffers without associated files) is also used when automatic | |
2579 detection of a file's encoding is called for and there was no | |
2580 discernible encoding in the file (i.e. it was entirely or almost | |
2581 entirely ASCII). The default value should generally *not* be set to | |
2582 nil (equivalent to `no-conversion'), because if extended characters | |
2583 are ever inserted into the buffer, they will be lost when the file is | |
2584 written out. A good choice is `iso-2022-8' (the simple ISO 2022 8-bit | |
2585 encoding), which will write out ASCII and Latin-1 characters in the | |
2586 standard (and highly portable) fashion and use standard escape | |
2587 sequences for other charsets. Another reasonable choice is | |
2588 `escape-quoted', which is equivalent to `iso-2022-8' but prefixes | |
2589 certain control characters with ESC to make sure they are not | |
2590 interpreted as escape sequences when read in. This latter coding | |
2591 system results in more "correct" output in the presence of control | |
2592 characters in the buffer, in the sense that when read in again using | |
2593 the same coding system, the result will virtually always match the | |
2594 original contents of the buffer, which is not the case with | |
2595 `iso-2022-8'; but the output is less portable when dealing with binary | |
2596 data -- there may be stray ESC characters when the file is read by | |
2597 another program. | |
2598 | |
2599 `buffer-file-coding-system' does *not* control the coding system used when | |
2600 a file is read in. Use the variables `buffer-file-coding-system-for-read' | |
771 | 2601 and `file-coding-system-alist' for that. From a Lisp program, if |
428 | 2602 you wish to unilaterally specify the coding system used for one |
2603 particular operation, you should bind the variable | |
2604 `coding-system-for-read' rather than changing the other two | |
2605 variables just mentioned, which are intended to be used for | |
2606 global environment specification. | |
771 | 2607 |
2608 See `insert-file-contents' for a full description of how a file's | |
2609 coding system is determined when it is read in. | |
428 | 2610 */ ); |
2611 | |
2612 DEFVAR_BUFFER_LOCAL ("auto-fill-function", auto_fill_function /* | |
2613 Function called (if non-nil) to perform auto-fill. | |
2614 It is called after self-inserting a space at a column beyond `fill-column'. | |
2615 Each buffer has its own value of this variable. | |
2616 NOTE: This variable is not an ordinary hook; | |
2617 It may not be a list of functions. | |
2618 */ ); | |
2619 | |
2620 DEFVAR_BUFFER_LOCAL ("buffer-file-name", filename /* | |
2621 Name of file visited in current buffer, or nil if not visiting a file. | |
2622 Each buffer has its own value of this variable. | |
2623 */ ); | |
2624 | |
2625 #if 0 /* FSFmacs */ | |
2626 /* | |
2627 Abbreviated truename of file visited in current buffer, or nil if none. | |
2628 The truename of a file is calculated by `file-truename' | |
2629 and then abbreviated with `abbreviate-file-name'. | |
2630 Each buffer has its own value of this variable. | |
2631 */ | |
2632 #endif /* FSFmacs */ | |
2633 | |
2634 DEFVAR_BUFFER_LOCAL ("buffer-file-truename", file_truename /* | |
2635 The real name of the file visited in the current buffer, | |
2636 or nil if not visiting a file. This is the result of passing | |
2637 buffer-file-name to the `file-truename' function. Every buffer has | |
2638 its own value of this variable. This variable is automatically | |
2639 maintained by the functions that change the file name associated | |
2640 with a buffer. | |
2641 */ ); | |
2642 | |
2643 DEFVAR_BUFFER_LOCAL ("buffer-auto-save-file-name", auto_save_file_name /* | |
2644 Name of file for auto-saving current buffer, | |
2645 or nil if buffer should not be auto-saved. | |
2646 Each buffer has its own value of this variable. | |
2647 */ ); | |
2648 | |
2649 DEFVAR_BUFFER_LOCAL ("buffer-read-only", read_only /* | |
2650 Non-nil if this buffer is read-only. | |
2651 Each buffer has its own value of this variable. | |
2652 */ ); | |
2653 | |
2654 DEFVAR_BUFFER_LOCAL ("buffer-backed-up", backed_up /* | |
2655 Non-nil if this buffer's file has been backed up. | |
2656 Backing up is done before the first time the file is saved. | |
2657 Each buffer has its own value of this variable. | |
2658 */ ); | |
2659 | |
2660 DEFVAR_BUFFER_LOCAL ("buffer-saved-size", saved_size /* | |
2661 Length of current buffer when last read in, saved or auto-saved. | |
2662 0 initially. | |
2663 Each buffer has its own value of this variable. | |
2664 */ ); | |
2665 | |
2666 DEFVAR_BUFFER_LOCAL_MAGIC ("selective-display", selective_display /* | |
2667 Non-nil enables selective display: | |
2668 Integer N as value means display only lines | |
2669 that start with less than n columns of space. | |
2670 A value of t means, after a ^M, all the rest of the line is invisible. | |
2671 Then ^M's in the file are written into files as newlines. | |
2672 | |
2673 Automatically becomes buffer-local when set in any fashion. | |
2674 */, redisplay_variable_changed); | |
2675 | |
2676 #ifndef old | |
2677 DEFVAR_BUFFER_LOCAL_MAGIC ("selective-display-ellipses", | |
2678 selective_display_ellipses /* | |
2679 t means display ... on previous line when a line is invisible. | |
2680 Automatically becomes buffer-local when set in any fashion. | |
2681 */, redisplay_variable_changed); | |
2682 #endif | |
2683 | |
2684 DEFVAR_BUFFER_LOCAL ("local-abbrev-table", abbrev_table /* | |
2685 Local (mode-specific) abbrev table of current buffer. | |
2686 */ ); | |
2687 | |
2688 DEFVAR_BUFFER_LOCAL ("overwrite-mode", overwrite_mode /* | |
2689 Non-nil if self-insertion should replace existing text. | |
2690 The value should be one of `overwrite-mode-textual', | |
2691 `overwrite-mode-binary', or nil. | |
2692 If it is `overwrite-mode-textual', self-insertion still | |
2693 inserts at the end of a line, and inserts when point is before a tab, | |
2694 until the tab is filled in. | |
2695 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too. | |
2696 Automatically becomes buffer-local when set in any fashion. | |
2697 | |
2698 Normally, you shouldn't modify this variable by hand, but use the functions | |
2699 `overwrite-mode' and `binary-overwrite-mode' instead. However, you can | |
2700 customize the default value from the options menu. | |
2701 */ ); | |
2702 | |
2703 #if 0 /* FSFmacs */ | |
2704 /* Adds the following to the doc string for buffer-undo-list: | |
2705 | |
2706 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property | |
2707 was modified between BEG and END. PROPERTY is the property name, | |
2708 and VALUE is the old value. | |
2709 */ | |
2710 #endif /* FSFmacs */ | |
2711 | |
2712 DEFVAR_BUFFER_LOCAL ("buffer-undo-list", undo_list /* | |
2713 List of undo entries in current buffer. | |
2714 Recent changes come first; older changes follow newer. | |
2715 | |
444 | 2716 An entry (START . END) represents an insertion which begins at |
2717 position START and ends at position END. | |
428 | 2718 |
2719 An entry (TEXT . POSITION) represents the deletion of the string TEXT | |
2720 from (abs POSITION). If POSITION is positive, point was at the front | |
2721 of the text being deleted; if negative, point was at the end. | |
2722 | |
2723 An entry (t HIGH . LOW) indicates that the buffer previously had | |
2724 "unmodified" status. HIGH and LOW are the high and low 16-bit portions | |
2725 of the visited file's modification time, as of that time. If the | |
2726 modification time of the most recent save is different, this entry is | |
2727 obsolete. | |
2728 | |
2729 An entry of the form EXTENT indicates that EXTENT was attached in | |
2730 the buffer. Undoing an entry of this form detaches EXTENT. | |
2731 | |
2732 An entry of the form (EXTENT START END) indicates that EXTENT was | |
2733 detached from the buffer. Undoing an entry of this form attaches | |
2734 EXTENT from START to END. | |
2735 | |
2736 An entry of the form POSITION indicates that point was at the buffer | |
2737 location given by the integer. Undoing an entry of this form places | |
2738 point at POSITION. | |
2739 | |
2740 nil marks undo boundaries. The undo command treats the changes | |
2741 between two undo boundaries as a single step to be undone. | |
2742 | |
2743 If the value of the variable is t, undo information is not recorded. | |
2744 */ ); | |
2745 | |
2746 #if 0 /* FSFmacs */ | |
2747 xxDEFVAR_BUFFER_LOCAL ("mark-active", mark_active /* | |
2748 Non-nil means the mark and region are currently active in this buffer. | |
2749 Automatically local in all buffers. | |
2750 */ ); | |
2751 #endif /* FSFmacs */ | |
2752 | |
2753 #ifdef REGION_CACHE_NEEDS_WORK | |
2754 xxDEFVAR_BUFFER_LOCAL ("cache-long-line-scans", cache_long_line_scans /* | |
2755 Non-nil means that Emacs should use caches to handle long lines more quickly. | |
2756 This variable is buffer-local, in all buffers. | |
2757 | |
2758 Normally, the line-motion functions work by scanning the buffer for | |
2759 newlines. Columnar operations (like move-to-column and | |
2760 compute-motion) also work by scanning the buffer, summing character | |
2761 widths as they go. This works well for ordinary text, but if the | |
2762 buffer's lines are very long (say, more than 500 characters), these | |
2763 motion functions will take longer to execute. Emacs may also take | |
2764 longer to update the display. | |
2765 | |
2766 If cache-long-line-scans is non-nil, these motion functions cache the | |
2767 results of their scans, and consult the cache to avoid rescanning | |
2768 regions of the buffer until the text is modified. The caches are most | |
2769 beneficial when they prevent the most searching---that is, when the | |
2770 buffer contains long lines and large regions of characters with the | |
2771 same, fixed screen width. | |
2772 | |
2773 When cache-long-line-scans is non-nil, processing short lines will | |
2774 become slightly slower (because of the overhead of consulting the | |
2775 cache), and the caches will use memory roughly proportional to the | |
2776 number of newlines and characters whose screen width varies. | |
2777 | |
2778 The caches require no explicit maintenance; their accuracy is | |
2779 maintained internally by the Emacs primitives. Enabling or disabling | |
2780 the cache should not affect the behavior of any of the motion | |
2781 functions; it should only affect their performance. | |
2782 */ ); | |
2783 #endif /* REGION_CACHE_NEEDS_WORK */ | |
2784 | |
2785 DEFVAR_BUFFER_LOCAL ("point-before-scroll", point_before_scroll /* | |
2786 Value of point before the last series of scroll operations, or nil. | |
2787 */ ); | |
2788 | |
2789 DEFVAR_BUFFER_LOCAL ("buffer-file-format", file_format /* | |
2790 List of formats to use when saving this buffer. | |
2791 Formats are defined by `format-alist'. This variable is | |
2792 set when a file is visited. Automatically local in all buffers. | |
2793 */ ); | |
2794 | |
2795 DEFVAR_BUFFER_LOCAL_MAGIC ("buffer-invisibility-spec", invisibility_spec /* | |
2796 Invisibility spec of this buffer. | |
2797 The default is t, which means that text is invisible | |
2798 if it has (or is covered by an extent with) a non-nil `invisible' property. | |
2799 If the value is a list, a text character is invisible if its `invisible' | |
2800 property is an element in that list. | |
444 | 2801 If an element is a cons cell of the form (PROPERTY . ELLIPSIS), |
2802 then characters with property value PROPERTY are invisible, | |
428 | 2803 and they have an ellipsis as well if ELLIPSIS is non-nil. |
2804 Note that the actual characters used for the ellipsis are controllable | |
2805 using `invisible-text-glyph', and default to "...". | |
2806 */, redisplay_variable_changed); | |
2807 | |
2808 DEFVAR_CONST_BUFFER_LOCAL ("generated-modeline-string", | |
2809 generated_modeline_string /* | |
2810 String of characters in this buffer's modeline as of the last redisplay. | |
2811 Each time the modeline is recomputed, the resulting characters are | |
2812 stored in this string, which is resized as necessary. You may not | |
2813 set this variable, and modifying this string will not change the | |
2814 modeline; you have to change `modeline-format' if you want that. | |
2815 | |
2816 For each extent in `modeline-format' that is encountered when | |
2817 processing the modeline, a corresponding extent is placed in | |
2818 `generated-modeline-string' and covers the text over which the | |
2819 extent in `modeline-format' applies. The extent in | |
2820 `generated-modeline-string' is made a child of the extent in | |
2821 `modeline-format', which means that it inherits all properties from | |
2822 that extent. Note that the extents in `generated-modeline-string' | |
2823 are managed automatically. You should not explicitly put any extents | |
2824 in `generated-modeline-string'; if you do, they will disappear the | |
2825 next time the modeline is processed. | |
2826 | |
2827 For extents in `modeline-format', the following properties are currently | |
2828 handled: | |
2829 | |
2830 `face' | |
2831 Affects the face of the modeline text. Currently, faces do | |
2832 not merge properly; only the most recently encountered face | |
2833 is used. This is a bug. | |
2834 | |
2835 `keymap' | |
2836 Affects the disposition of button events over the modeline | |
2837 text. Multiple applicable keymaps *are* handled properly, | |
2838 and `modeline-map' still applies to any events that don't | |
2839 have bindings in extent-specific keymaps. | |
2840 | |
2841 `help-echo' | |
2842 If a string, causes the string to be displayed when the mouse | |
2843 moves over the text. | |
2844 */ ); | |
2845 | |
2846 /* Check for DEFVAR_BUFFER_LOCAL without initializing the corresponding | |
2847 slot of buffer_local_flags and vice-versa. Must be done after all | |
2848 DEFVAR_BUFFER_LOCAL() calls. */ | |
2849 #define MARKED_SLOT(slot) \ | |
2850 if ((XINT (buffer_local_flags.slot) != -2 && \ | |
2851 XINT (buffer_local_flags.slot) != -3) \ | |
2852 != !(NILP (XBUFFER (Vbuffer_local_symbols)->slot))) \ | |
2500 | 2853 ABORT (); |
428 | 2854 #include "bufslots.h" |
2855 | |
2856 { | |
2857 Lisp_Object scratch = Fget_buffer_create (QSscratch); | |
2858 Fset_buffer (scratch); | |
2859 /* Want no undo records for *scratch* until after Emacs is dumped */ | |
2860 Fbuffer_disable_undo (scratch); | |
2861 } | |
2862 } | |
2863 | |
442 | 2864 #ifndef WIN32_NATIVE |
428 | 2865 /* Is PWD another name for `.' ? */ |
2866 static int | |
867 | 2867 directory_is_current_directory (Ibyte *pwd) |
428 | 2868 { |
2869 struct stat dotstat, pwdstat; | |
2870 | |
771 | 2871 return (IS_DIRECTORY_SEP (*pwd) |
2872 && qxe_stat (pwd, &pwdstat) == 0 | |
867 | 2873 && qxe_stat ((Ibyte *) ".", &dotstat) == 0 |
428 | 2874 && dotstat.st_ino == pwdstat.st_ino |
771 | 2875 && dotstat.st_dev == pwdstat.st_dev); |
428 | 2876 } |
442 | 2877 #endif |
428 | 2878 |
771 | 2879 /* A stand-in for getcwd() #### Fix not to depend on arbitrary size limits */ |
2880 | |
867 | 2881 Ibyte * |
2882 get_initial_directory (Ibyte *pathname, Bytecount size) | |
771 | 2883 { |
2884 if (pathname) | |
2885 { | |
2886 qxestrncpy (pathname, initial_directory, size); | |
2887 pathname[size - 1] = '\0'; | |
2888 } | |
2889 return initial_directory; | |
2890 } | |
2891 | |
428 | 2892 void |
2893 init_initial_directory (void) | |
2894 { | |
2895 /* This function can GC */ | |
2896 | |
442 | 2897 #ifndef WIN32_NATIVE |
867 | 2898 Ibyte *pwd; |
442 | 2899 #endif |
428 | 2900 |
2901 /* If PWD is accurate, use it instead of calling getcwd. This is faster | |
2902 when PWD is right, and may avoid a fatal error. */ | |
442 | 2903 #ifndef WIN32_NATIVE |
771 | 2904 if ((pwd = egetenv ("PWD")) != NULL |
428 | 2905 && directory_is_current_directory (pwd)) |
771 | 2906 initial_directory = qxestrdup (pwd); |
442 | 2907 else |
2908 #endif | |
771 | 2909 if ((initial_directory = qxe_allocating_getcwd ()) == NULL) |
2910 { | |
867 | 2911 Ibyte *errmess; |
771 | 2912 GET_STRERROR (errmess, errno); |
2913 fatal ("`getcwd' failed: %s\n", errmess); | |
2914 } | |
428 | 2915 |
2916 /* Make sure pwd is DIRECTORY_SEP-terminated. | |
2917 Maybe this should really use some standard subroutine | |
2918 whose definition is filename syntax dependent. */ | |
2919 { | |
771 | 2920 Bytecount len = qxestrlen (initial_directory); |
428 | 2921 |
2922 if (! IS_DIRECTORY_SEP (initial_directory[len - 1])) | |
2923 { | |
867 | 2924 XREALLOC_ARRAY (initial_directory, Ibyte, len + 2); |
428 | 2925 initial_directory[len] = DIRECTORY_SEP; |
2926 initial_directory[len + 1] = '\0'; | |
2927 } | |
2928 } | |
2929 | |
771 | 2930 #ifdef WIN32_NATIVE |
2931 { | |
867 | 2932 Ibyte *newinit = mswindows_canonicalize_filename (initial_directory); |
1726 | 2933 xfree (initial_directory, Ibyte *); |
771 | 2934 initial_directory = newinit; |
2935 } | |
2936 | |
2937 { | |
2938 /* Make the real wd be the location of xemacs.exe to avoid conflicts | |
2939 when renaming or deleting directories. (We also don't call chdir | |
2940 when running subprocesses for the same reason.) */ | |
2941 | |
2942 Extbyte *p; | |
814 | 2943 Extbyte *modname = mswindows_get_module_file_name (); |
771 | 2944 |
814 | 2945 assert (modname); |
2421 | 2946 p = qxetcsrchr (modname, '\\'); |
859 | 2947 assert (p); |
771 | 2948 XECOPY_TCHAR (p, '\0'); |
2949 | |
2950 qxeSetCurrentDirectory (modname); | |
1726 | 2951 xfree (modname, Extbyte *); |
771 | 2952 } |
428 | 2953 #endif |
2954 } | |
2955 | |
2956 void | |
771 | 2957 init_buffer_1 (void) |
2958 { | |
2959 Fset_buffer (Fget_buffer_create (QSscratch)); | |
2960 } | |
2961 | |
2962 void | |
2963 init_buffer_2 (void) | |
428 | 2964 { |
2965 /* This function can GC */ | |
771 | 2966 Fset_buffer (Fget_buffer (QSscratch)); |
2967 | |
2968 current_buffer->directory = build_intstring (initial_directory); | |
428 | 2969 |
2970 #if 0 /* FSFmacs */ | |
2971 /* #### is this correct? */ | |
2972 temp = get_minibuffer (0); | |
2973 XBUFFER (temp)->directory = current_buffer->directory; | |
2974 #endif /* FSFmacs */ | |
2975 } |