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