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