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