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