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