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