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