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