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