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