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