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