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