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