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