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