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