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