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