Mercurial > hg > xemacs-beta
annotate src/buffer.c @ 5359:f5a5501814f5
Document the CL set functions and #'eql in the Lispref, not just cl.texi
man/ChangeLog addition:
2011-02-19 Aidan Kehoe <kehoea@parhasard.net>
* lispref/lists.texi (Sets And Lists):
Document #'member*, #'remove*, #'delete* in this file. Document
#'memq, #'member, #'remq, #'remove, #'delq, #'delete in terms of
the former functions.
Document #'subsetp, #'union, #'intersection, #'set-difference,
#'set-exclusive-or and their destructive analogues in this file.
* lispref/lists.texi (Association Lists):
Document #'assoc*, #'rassoc* in this file. Document #'assq,
#'assoc, #'rassq, #'rassoc in terms of the first two functions.
* lispref/objects.texi (Equality Predicates):
Document #'eql here, don't leave it to cl.texi.
src/ChangeLog addition:
2011-02-19 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (Fset_exclusive_or):
This function accepts the :stable keyword too, document this in
its arglist.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sat, 19 Feb 2011 11:03:46 +0000 |
| parents | d804e621add0 |
| children | 3889ef128488 308d34e9f07d |
| 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, | |
|
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5170
diff
changeset
|
643 Qeq); |
| 428 | 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 { | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1755 struct usage_stats u; |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1756 Bytecount text; |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
1757 /* Ancillary Lisp */ |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1758 Bytecount markers; |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1759 Bytecount extents; |
| 428 | 1760 }; |
| 1761 | |
| 665 | 1762 static Bytecount |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1763 compute_buffer_text_usage (struct buffer *b, struct usage_stats *ustats) |
| 428 | 1764 { |
|
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1765 Bytecount was_requested, gap, malloc_use; |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1766 |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1767 /* Killed buffer? */ |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1768 if (!b->text) |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1769 return 0; |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1770 |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1771 /* Indirect buffer shares its text with someone else, so don't double- |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1772 count the text */ |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1773 if (b->base_buffer) |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1774 return 0; |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1775 |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1776 was_requested = b->text->z - 1; |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1777 gap = b->text->gap_size + b->text->end_gap_size; |
|
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1778 malloc_use = malloced_storage_size (b->text->beg, was_requested + gap, 0); |
| 428 | 1779 |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1780 ustats->gap_overhead += gap; |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1781 ustats->was_requested += was_requested; |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1782 ustats->malloc_overhead += malloc_use - (was_requested + gap); |
| 428 | 1783 return malloc_use; |
| 1784 } | |
| 1785 | |
| 1786 static void | |
| 1787 compute_buffer_usage (struct buffer *b, struct buffer_stats *stats, | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1788 struct usage_stats *ustats) |
| 428 | 1789 { |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1790 stats->text += compute_buffer_text_usage (b, ustats); |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
1791 stats->markers += compute_buffer_marker_usage (b); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
1792 stats->extents += compute_buffer_extent_usage (b); |
| 428 | 1793 } |
| 1794 | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1795 static void |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1796 buffer_memory_usage (Lisp_Object buffer, struct generic_usage_stats *gustats) |
| 428 | 1797 { |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1798 struct buffer_stats *stats = (struct buffer_stats *) gustats; |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1799 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1800 compute_buffer_usage (XBUFFER (buffer), stats, &stats->u); |
| 428 | 1801 } |
| 1802 | |
| 1803 #endif /* MEMORY_USAGE_STATS */ | |
| 814 | 1804 |
| 1805 #if defined (DEBUG_XEMACS) && defined (MULE) | |
| 1806 | |
| 1807 DEFUN ("buffer-char-byte-conversion-info", Fbuffer_char_byte_converion_info, | |
| 1808 1, 1, 0, /* | |
| 1809 Return the current info used for char-byte conversion in BUFFER. | |
| 1810 The values returned are in the form of a plist of properties and values. | |
| 1811 */ | |
| 1812 (buffer)) | |
| 1813 { | |
| 1814 struct buffer *b; | |
| 1815 Lisp_Object plist = Qnil; | |
| 1816 | |
| 1817 CHECK_BUFFER (buffer); /* dead buffers should be allowed, no? */ | |
| 1818 b = XBUFFER (buffer); | |
| 1819 | |
| 1820 #define ADD_INT(field) \ | |
| 1821 plist = cons3 (make_int (b->text->field), \ | |
|
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5214
diff
changeset
|
1822 intern_massaging_name (#field), plist) |
| 814 | 1823 #define ADD_BOOL(field) \ |
| 1824 plist = cons3 (b->text->field ? Qt : Qnil, \ | |
|
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5214
diff
changeset
|
1825 intern_massaging_name (#field), plist) |
| 814 | 1826 ADD_INT (bufz); |
| 1827 ADD_INT (z); | |
| 2367 | 1828 #ifdef OLD_BYTE_CHAR |
| 814 | 1829 ADD_INT (mule_bufmin); |
| 1830 ADD_INT (mule_bufmax); | |
| 1831 ADD_INT (mule_bytmin); | |
| 1832 ADD_INT (mule_bytmax); | |
| 1833 ADD_INT (mule_shifter); | |
| 1834 ADD_BOOL (mule_three_p); | |
| 2367 | 1835 #endif |
| 826 | 1836 ADD_BOOL (entirely_one_byte_p); |
| 1837 ADD_INT (num_ascii_chars); | |
| 1838 ADD_INT (num_8_bit_fixed_chars); | |
| 1839 ADD_INT (num_16_bit_fixed_chars); | |
| 2367 | 1840 ADD_INT (cached_charpos); |
| 1841 ADD_INT (cached_bytepos); | |
| 1842 ADD_INT (next_cache_pos); | |
| 1843 | |
| 814 | 1844 { |
| 2367 | 1845 Lisp_Object pos[NUM_CACHED_POSITIONS]; |
| 814 | 1846 int i; |
| 2367 | 1847 for (i = 0; i < b->text->next_cache_pos; i++) |
| 814 | 1848 pos[i] = make_int (b->text->mule_charbpos_cache[i]); |
| 2367 | 1849 plist = cons3 (Flist (b->text->next_cache_pos, pos), |
| 1850 intern ("mule-charbpos-cache"), plist); | |
| 1851 for (i = 0; i < b->text->next_cache_pos; i++) | |
| 814 | 1852 pos[i] = make_int (b->text->mule_bytebpos_cache[i]); |
| 2367 | 1853 plist = cons3 (Flist (b->text->next_cache_pos, pos), |
| 1854 intern ("mule-bytebpos-cache"), plist); | |
| 814 | 1855 } |
| 1856 #undef ADD_INT | |
| 1857 #undef ADD_BOOL | |
| 1858 | |
| 1859 return Fnreverse (plist); | |
| 1860 } | |
| 1861 | |
| 1862 DEFUN ("string-char-byte-conversion-info", Fstring_char_byte_converion_info, 1, 1, 0, /* | |
| 1863 Return the current info used for char-byte conversion in STRING. | |
| 1864 The values returned are in the form of a plist of properties and values. | |
| 1865 */ | |
| 1866 (string)) | |
| 1867 { | |
| 1868 Lisp_Object plist = Qnil; | |
| 1869 CHECK_STRING (string); | |
| 1870 | |
| 1871 plist = cons3 (make_int (XSTRING_LENGTH (string)), | |
| 1872 intern ("byte-length"), plist); | |
| 1873 plist = cons3 (make_int (XSTRING_ASCII_BEGIN (string)), | |
| 1874 intern ("ascii-begin"), plist); | |
| 1875 | |
| 1876 return Fnreverse (plist); | |
| 1877 } | |
| 1878 | |
| 1879 #endif /* defined (DEBUG_XEMACS) && defined (MULE) */ | |
| 1880 | |
| 440 | 1881 |
| 1882 | |
| 428 | 1883 void |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1884 buffer_objects_create (void) |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1885 { |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1886 #ifdef MEMORY_USAGE_STATS |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1887 OBJECT_HAS_METHOD (buffer, memory_usage); |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1888 #endif |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1889 } |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1890 |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1891 void |
| 428 | 1892 syms_of_buffer (void) |
| 1893 { | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
1894 INIT_LISP_OBJECT (buffer); |
| 3092 | 1895 #ifdef NEW_GC |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1896 INIT_LISP_OBJECT (buffer_text); |
| 3092 | 1897 #endif /* NEW_GC */ |
| 442 | 1898 |
| 563 | 1899 DEFSYMBOL (Qbuffer_live_p); |
| 1900 DEFSYMBOL (Qbuffer_or_string_p); | |
| 1901 DEFSYMBOL (Qmode_class); | |
| 1902 DEFSYMBOL (Qrename_auto_save_file); | |
| 1903 DEFSYMBOL (Qkill_buffer_hook); | |
| 1904 DEFSYMBOL (Qpermanent_local); | |
| 1905 | |
| 1906 DEFSYMBOL (Qfirst_change_hook); | |
| 1907 DEFSYMBOL (Qbefore_change_functions); | |
| 1908 DEFSYMBOL (Qafter_change_functions); | |
| 428 | 1909 |
| 1910 /* #### Obsolete, for compatibility */ | |
| 563 | 1911 DEFSYMBOL (Qbefore_change_function); |
| 1912 DEFSYMBOL (Qafter_change_function); | |
| 1913 | |
| 1914 DEFSYMBOL (Qdefault_directory); | |
| 1915 | |
| 1916 DEFSYMBOL (Qget_file_buffer); | |
| 1917 DEFSYMBOL (Qchange_major_mode_hook); | |
| 1918 | |
| 1919 DEFSYMBOL (Qfundamental_mode); | |
| 1920 | |
| 1921 DEFSYMBOL (Qfind_file_compare_truenames); | |
| 1922 | |
| 1923 DEFSYMBOL (Qswitch_to_buffer); | |
| 428 | 1924 |
| 1925 DEFSUBR (Fbufferp); | |
| 1926 DEFSUBR (Fbuffer_live_p); | |
| 1927 DEFSUBR (Fbuffer_list); | |
| 1928 DEFSUBR (Fdecode_buffer); | |
| 1929 DEFSUBR (Fget_buffer); | |
| 1930 DEFSUBR (Fget_file_buffer); | |
| 1931 DEFSUBR (Fget_buffer_create); | |
| 1932 DEFSUBR (Fmake_indirect_buffer); | |
| 1933 | |
| 1934 DEFSUBR (Fgenerate_new_buffer_name); | |
| 1935 DEFSUBR (Fbuffer_name); | |
| 1936 DEFSUBR (Fbuffer_file_name); | |
| 1937 DEFSUBR (Fbuffer_base_buffer); | |
| 1938 DEFSUBR (Fbuffer_indirect_children); | |
| 1939 DEFSUBR (Fbuffer_local_variables); | |
| 1940 DEFSUBR (Fbuffer_modified_p); | |
| 1941 DEFSUBR (Fset_buffer_modified_p); | |
| 1942 DEFSUBR (Fbuffer_modified_tick); | |
| 1943 DEFSUBR (Frename_buffer); | |
| 1944 DEFSUBR (Fother_buffer); | |
| 1945 DEFSUBR (Fbuffer_disable_undo); | |
| 1946 DEFSUBR (Fbuffer_enable_undo); | |
| 1947 DEFSUBR (Fkill_buffer); | |
| 1948 DEFSUBR (Ferase_buffer); | |
| 1949 DEFSUBR (Frecord_buffer); | |
| 1950 DEFSUBR (Fset_buffer_major_mode); | |
| 1951 DEFSUBR (Fcurrent_buffer); | |
| 1952 DEFSUBR (Fset_buffer); | |
| 1953 DEFSUBR (Fbarf_if_buffer_read_only); | |
| 1954 DEFSUBR (Fbury_buffer); | |
| 1955 DEFSUBR (Fkill_all_local_variables); | |
| 814 | 1956 #if defined (DEBUG_XEMACS) && defined (MULE) |
| 1957 DEFSUBR (Fbuffer_char_byte_converion_info); | |
| 1958 DEFSUBR (Fstring_char_byte_converion_info); | |
| 1959 #endif | |
| 428 | 1960 |
| 442 | 1961 DEFERROR (Qprotected_field, "Attempt to modify a protected field", |
| 1962 Qinvalid_change); | |
| 428 | 1963 } |
| 1964 | |
| 1965 void | |
| 1966 reinit_vars_of_buffer (void) | |
| 1967 { | |
| 1968 staticpro_nodump (&Vbuffer_alist); | |
| 1969 Vbuffer_alist = Qnil; | |
| 1970 current_buffer = 0; | |
| 1971 } | |
| 1972 | |
| 1973 /* initialize the buffer routines */ | |
| 1974 void | |
| 1975 vars_of_buffer (void) | |
| 1976 { | |
| 1977 /* This function can GC */ | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1978 #ifdef MEMORY_USAGE_STATS |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1979 OBJECT_HAS_PROPERTY |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
1980 (buffer, memusage_stats_list, list4 (Qtext, Qt, Qmarkers, Qextents)); |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1981 #endif /* MEMORY_USAGE_STATS */ |
|
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1982 |
| 428 | 1983 staticpro (&QSFundamental); |
| 1984 staticpro (&QSscratch); | |
| 1985 | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4761
diff
changeset
|
1986 QSFundamental = build_ascstring ("Fundamental"); |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4761
diff
changeset
|
1987 QSscratch = build_ascstring ("*scratch*"); |
| 428 | 1988 |
| 1989 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook /* | |
| 1990 List of hooks to be run before killing local variables in a buffer. | |
| 1991 This should be used by any mode that temporarily alters the contents or | |
| 1992 the read-only state of the buffer. See also `kill-all-local-variables'. | |
| 1993 */ ); | |
| 1994 Vchange_major_mode_hook = Qnil; | |
| 1995 | |
| 1996 DEFVAR_BOOL ("find-file-compare-truenames", &find_file_compare_truenames /* | |
| 444 | 1997 If this is true, then the `find-file' command will check the truenames |
| 428 | 1998 of all visited files when deciding whether a given file is already in |
| 444 | 1999 a buffer, instead of just `buffer-file-name'. This means that if you |
| 2000 attempt to visit another file which is a symbolic link to a file which | |
| 2001 is already in a buffer, the existing buffer will be found instead of a | |
| 2002 newly-created one. This works if any component of the pathname | |
| 2003 (including a non-terminal component) is a symbolic link as well, but | |
| 2004 doesn't work with hard links (nothing does). | |
| 2005 | |
| 2006 See also the variable `find-file-use-truenames'. | |
| 428 | 2007 */ ); |
| 446 | 2008 #if defined(CYGWIN) || defined(WIN32_NATIVE) |
| 2009 find_file_compare_truenames = 1; | |
| 2010 #else | |
| 428 | 2011 find_file_compare_truenames = 0; |
| 446 | 2012 #endif |
| 428 | 2013 |
| 2014 DEFVAR_BOOL ("find-file-use-truenames", &find_file_use_truenames /* | |
| 2015 If this is true, then a buffer's visited file-name will always be | |
| 2016 chased back to the real file; it will never be a symbolic link, and there | |
| 2017 will never be a symbolic link anywhere in its directory path. | |
| 2018 That is, the buffer-file-name and buffer-file-truename will be equal. | |
| 2019 This doesn't work with hard links. | |
| 2020 | |
| 444 | 2021 See also the variable `find-file-compare-truenames'. |
| 428 | 2022 */ ); |
| 2023 find_file_use_truenames = 0; | |
| 2024 | |
| 2025 DEFVAR_LISP ("before-change-functions", &Vbefore_change_functions /* | |
| 2026 List of functions to call before each text change. | |
| 2027 Two arguments are passed to each function: the positions of | |
| 2028 the beginning and end of the range of old text to be changed. | |
| 2029 \(For an insertion, the beginning and end are at the same place.) | |
| 2030 No information is given about the length of the text after the change. | |
| 2031 | |
| 2032 Buffer changes made while executing the `before-change-functions' | |
| 2033 don't call any before-change or after-change functions. | |
| 2034 */ ); | |
| 2035 Vbefore_change_functions = Qnil; | |
| 2036 | |
| 2037 /* FSF Emacs has the following additional doc at the end of | |
| 2038 before-change-functions and after-change-functions: | |
| 2039 | |
| 2040 That's because these variables are temporarily set to nil. | |
| 2041 As a result, a hook function cannot straightforwardly alter the value of | |
| 2042 these variables. See the Emacs Lisp manual for a way of | |
| 2043 accomplishing an equivalent result by using other variables. | |
| 2044 | |
| 2045 But this doesn't apply under XEmacs because things are | |
| 2046 handled better. */ | |
| 2047 | |
| 2048 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions /* | |
| 2049 List of functions to call after each text change. | |
| 2050 Three arguments are passed to each function: the positions of | |
| 2051 the beginning and end of the range of changed text, | |
| 2052 and the length of the pre-change text replaced by that range. | |
| 2053 \(For an insertion, the pre-change length is zero; | |
| 2054 for a deletion, that length is the number of characters deleted, | |
| 2055 and the post-change beginning and end are at the same place.) | |
| 2056 | |
| 2057 Buffer changes made while executing `after-change-functions' | |
| 2058 don't call any before-change or after-change functions. | |
| 2059 */ ); | |
| 2060 Vafter_change_functions = Qnil; | |
| 2061 | |
| 2062 DEFVAR_LISP ("before-change-function", &Vbefore_change_function /* | |
| 2063 | |
| 2064 */ ); /* obsoleteness will be documented */ | |
| 2065 Vbefore_change_function = Qnil; | |
| 2066 | |
| 2067 DEFVAR_LISP ("after-change-function", &Vafter_change_function /* | |
| 2068 | |
| 2069 */ ); /* obsoleteness will be documented */ | |
| 2070 Vafter_change_function = Qnil; | |
| 2071 | |
| 2072 DEFVAR_LISP ("first-change-hook", &Vfirst_change_hook /* | |
| 2073 A list of functions to call before changing a buffer which is unmodified. | |
| 2074 The functions are run using the `run-hooks' function. | |
| 2075 */ ); | |
| 2076 Vfirst_change_hook = Qnil; | |
| 2077 | |
| 2078 #if 0 /* FSFmacs */ | |
| 2079 xxDEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode /* | |
| 2080 *Non-nil means deactivate the mark when the buffer contents change. | |
| 2081 */ ); | |
| 2082 Vtransient_mark_mode = Qnil; | |
| 2083 #endif /* FSFmacs */ | |
| 2084 | |
| 2085 DEFVAR_INT ("undo-threshold", &undo_threshold /* | |
| 2086 Keep no more undo information once it exceeds this size. | |
| 2087 This threshold is applied when garbage collection happens. | |
| 2088 The size is counted as the number of bytes occupied, | |
| 2089 which includes both saved text and other data. | |
| 2090 */ ); | |
| 2091 undo_threshold = 20000; | |
| 2092 | |
| 2093 DEFVAR_INT ("undo-high-threshold", &undo_high_threshold /* | |
| 2094 Don't keep more than this much size of undo information. | |
| 2095 A command which pushes past this size is itself forgotten. | |
| 2096 This threshold is applied when garbage collection happens. | |
| 2097 The size is counted as the number of bytes occupied, | |
| 2098 which includes both saved text and other data. | |
| 2099 */ ); | |
| 2100 undo_high_threshold = 30000; | |
| 2101 | |
| 2102 DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only /* | |
| 2103 *Non-nil means disregard read-only status of buffers or characters. | |
| 2104 If the value is t, disregard `buffer-read-only' and all `read-only' | |
| 2105 text properties. If the value is a list, disregard `buffer-read-only' | |
| 2106 and disregard a `read-only' extent property or text property if the | |
| 2107 property value is a member of the list. | |
| 2108 */ ); | |
| 2109 Vinhibit_read_only = Qnil; | |
| 2110 | |
| 2111 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions /* | |
| 2112 List of functions called with no args to query before killing a buffer. | |
| 2113 */ ); | |
| 2114 Vkill_buffer_query_functions = Qnil; | |
| 2115 | |
| 2116 DEFVAR_BOOL ("delete-auto-save-files", &delete_auto_save_files /* | |
| 2117 *Non-nil means delete auto-save file when a buffer is saved or killed. | |
| 2118 */ ); | |
| 2119 delete_auto_save_files = 1; | |
| 2120 } | |
| 2121 | |
| 2122 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */ | |
| 2123 | |
| 3263 | 2124 #ifdef NEW_GC |
| 2720 | 2125 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magic_fun) \ |
| 2126 do \ | |
| 2127 { \ | |
| 2128 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
|
2129 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
|
2130 /*mcpro ((Lisp_Object) I_hate_C);*/ \ |
| 2720 | 2131 \ |
| 2132 I_hate_C->magic.value = &(buffer_local_flags.field_name); \ | |
| 2133 I_hate_C->magic.type = forward_type; \ | |
| 2134 I_hate_C->magicfun = magic_fun; \ | |
| 2135 \ | |
| 2136 MARK_LRECORD_AS_LISP_READONLY (I_hate_C); \ | |
| 2137 \ | |
| 2138 { \ | |
| 2139 int offset = ((char *)symbol_value_forward_forward (I_hate_C) - \ | |
| 2140 (char *)&buffer_local_flags); \ | |
| 2141 defvar_magic (lname, I_hate_C); \ | |
| 2142 \ | |
| 2143 *((Lisp_Object *)(offset + (char *)XBUFFER (Vbuffer_local_symbols))) \ | |
| 2144 = intern (lname); \ | |
| 2145 } \ | |
| 2146 } while (0) | |
| 2147 | |
| 3263 | 2148 #else /* not NEW_GC */ |
| 428 | 2149 /* Renamed from DEFVAR_PER_BUFFER because FSFmacs D_P_B takes |
| 2150 a bogus extra arg, which confuses an otherwise identical make-docfile.c */ | |
| 2720 | 2151 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magicfun) \ |
| 2152 do { \ | |
| 2153 static const struct symbol_value_forward I_hate_C = \ | |
| 2154 { /* struct symbol_value_forward */ \ | |
| 2155 { /* struct symbol_value_magic */ \ | |
| 3024 | 2156 { /* struct old_lcrecord_header */ \ |
| 2720 | 2157 { /* struct lrecord_header */ \ |
| 2158 lrecord_type_symbol_value_forward, /* lrecord_type_index */ \ | |
| 2159 1, /* mark bit */ \ | |
| 2160 1, /* c_readonly bit */ \ | |
| 2161 1 /* lisp_readonly bit */ \ | |
| 2162 }, \ | |
| 2163 0, /* next */ \ | |
| 2164 }, \ | |
| 2165 &(buffer_local_flags.field_name), \ | |
| 2166 forward_type \ | |
| 2167 }, \ | |
| 2168 magicfun \ | |
| 2169 }; \ | |
| 2170 \ | |
| 2171 { \ | |
| 2172 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) - \ | |
| 2173 (char *)&buffer_local_flags); \ | |
| 2174 defvar_magic (lname, &I_hate_C); \ | |
| 2175 \ | |
| 2176 *((Lisp_Object *)(offset + (char *)XBUFFER (Vbuffer_local_symbols))) \ | |
| 2177 = intern (lname); \ | |
| 2178 } \ | |
| 428 | 2179 } while (0) |
| 3263 | 2180 #endif /* not NEW_GC */ |
| 2720 | 2181 |
| 428 | 2182 #define DEFVAR_BUFFER_LOCAL_MAGIC(lname, field_name, magicfun) \ |
| 2183 DEFVAR_BUFFER_LOCAL_1 (lname, field_name, \ | |
| 2184 SYMVAL_CURRENT_BUFFER_FORWARD, magicfun) | |
| 2185 #define DEFVAR_BUFFER_LOCAL(lname, field_name) \ | |
| 2186 DEFVAR_BUFFER_LOCAL_MAGIC (lname, field_name, 0) | |
| 2187 #define DEFVAR_CONST_BUFFER_LOCAL_MAGIC(lname, field_name, magicfun) \ | |
| 2188 DEFVAR_BUFFER_LOCAL_1 (lname, field_name, \ | |
| 2189 SYMVAL_CONST_CURRENT_BUFFER_FORWARD, magicfun) | |
| 2190 #define DEFVAR_CONST_BUFFER_LOCAL(lname, field_name) \ | |
| 2191 DEFVAR_CONST_BUFFER_LOCAL_MAGIC (lname, field_name, 0) | |
| 2192 | |
| 2193 #define DEFVAR_BUFFER_DEFAULTS_MAGIC(lname, field_name, magicfun) \ | |
| 2194 DEFVAR_SYMVAL_FWD (lname, &(buffer_local_flags.field_name), \ | |
| 2195 SYMVAL_DEFAULT_BUFFER_FORWARD, magicfun) | |
| 2196 #define DEFVAR_BUFFER_DEFAULTS(lname, field_name) \ | |
| 2197 DEFVAR_BUFFER_DEFAULTS_MAGIC (lname, field_name, 0) | |
| 2198 | |
| 2199 static void | |
| 2200 nuke_all_buffer_slots (struct buffer *b, Lisp_Object zap) | |
| 2201 { | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2202 zero_nonsized_lisp_object (wrap_buffer (b)); |
| 428 | 2203 |
| 2204 b->extent_info = Qnil; | |
| 2205 b->indirect_children = Qnil; | |
| 2206 b->own_text.line_number_cache = Qnil; | |
| 2207 | |
| 1204 | 2208 #define MARKED_SLOT(x) b->x = zap; |
| 428 | 2209 #include "bufslots.h" |
| 2210 } | |
| 2211 | |
| 2212 static void | |
| 2213 common_init_complex_vars_of_buffer (void) | |
| 2214 { | |
| 2215 /* Make sure all markable slots in buffer_defaults | |
| 2216 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
|
2217 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
|
2218 struct buffer *defs = XBUFFER (defobj); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2219 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
|
2220 struct buffer *syms = XBUFFER (symobj); |
| 428 | 2221 |
| 2222 staticpro_nodump (&Vbuffer_defaults); | |
| 2223 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
|
2224 Vbuffer_defaults = defobj; |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
2225 Vbuffer_local_symbols = symobj; |
| 428 | 2226 |
| 2227 nuke_all_buffer_slots (syms, Qnil); | |
| 2228 nuke_all_buffer_slots (defs, Qnil); | |
| 2229 defs->text = &defs->own_text; | |
| 2230 syms->text = &syms->own_text; | |
| 2231 | |
| 2232 /* Set up the non-nil default values of various buffer slots. | |
| 2233 Must do these before making the first buffer. */ | |
| 2234 defs->major_mode = Qfundamental_mode; | |
| 2235 defs->mode_name = QSFundamental; | |
| 2236 defs->abbrev_table = Qnil; /* real default setup by Lisp code */ | |
| 2237 | |
| 446 | 2238 defs->case_table = Vstandard_case_table; |
| 428 | 2239 #ifdef MULE |
| 2240 defs->category_table = Vstandard_category_table; | |
| 2241 #endif /* MULE */ | |
| 2242 defs->syntax_table = Vstandard_syntax_table; | |
| 2243 defs->mirror_syntax_table = | |
| 2244 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
|
2245 defs->modeline_format = build_ascstring ("%-"); /* reset in loaddefs.el */ |
| 428 | 2246 defs->case_fold_search = Qt; |
| 2247 defs->selective_display_ellipses = Qt; | |
| 2248 defs->tab_width = make_int (8); | |
| 2249 defs->ctl_arrow = Qt; | |
| 2250 defs->fill_column = make_int (70); | |
| 2251 defs->left_margin = Qzero; | |
| 2252 defs->saved_size = Qzero; /* lisp code wants int-or-nil */ | |
| 2253 defs->modtime = 0; | |
| 2254 defs->auto_save_modified = 0; | |
| 2255 defs->auto_save_failure_time = -1; | |
| 2256 defs->invisibility_spec = Qt; | |
| 448 | 2257 defs->buffer_local_face_property = 0; |
| 428 | 2258 |
| 2259 defs->indirect_children = Qnil; | |
| 2260 syms->indirect_children = Qnil; | |
| 2261 | |
| 2262 { | |
| 2263 /* 0 means var is always local. Default used only at creation. | |
| 2264 * -1 means var is always local. Default used only at reset and | |
| 2265 * creation. | |
| 2266 * -2 means there's no lisp variable corresponding to this slot | |
| 2267 * and the default is only used at creation. | |
| 2268 * -3 means no Lisp variable. Default used only at reset and creation. | |
| 2269 * >0 is mask. Var is local if ((buffer->local_var_flags & mask) != 0) | |
| 2270 * Otherwise default is used. | |
| 2271 */ | |
| 2272 Lisp_Object always_local_no_default = make_int (0); | |
| 2273 Lisp_Object always_local_resettable = make_int (-1); | |
| 2274 Lisp_Object resettable = make_int (-3); | |
| 2275 | |
| 2276 /* Assign the local-flags to the slots that have default values. | |
| 2277 The local flag is a bit that is used in the buffer | |
| 2278 to say that it has its own local value for the slot. | |
| 2279 The local flag bits are in the local_var_flags slot of the | |
| 2280 buffer. */ | |
| 2281 | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2282 set_lheader_implementation ((struct lrecord_header *) |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
2283 &buffer_local_flags, &lrecord_buffer); |
| 428 | 2284 nuke_all_buffer_slots (&buffer_local_flags, make_int (-2)); |
| 2285 buffer_local_flags.filename = always_local_no_default; | |
| 2286 buffer_local_flags.directory = always_local_no_default; | |
| 2287 buffer_local_flags.backed_up = always_local_no_default; | |
| 2288 buffer_local_flags.saved_size = always_local_no_default; | |
| 2289 buffer_local_flags.auto_save_file_name = always_local_no_default; | |
| 2290 buffer_local_flags.read_only = always_local_no_default; | |
| 2291 | |
| 2292 buffer_local_flags.major_mode = always_local_resettable; | |
| 2293 buffer_local_flags.mode_name = always_local_resettable; | |
| 2294 buffer_local_flags.undo_list = always_local_no_default; | |
| 2295 #if 0 /* FSFmacs */ | |
| 2296 buffer_local_flags.mark_active = always_local_resettable; | |
| 2297 #endif | |
| 2298 buffer_local_flags.point_before_scroll = always_local_resettable; | |
| 2299 buffer_local_flags.file_truename = always_local_no_default; | |
| 2300 buffer_local_flags.invisibility_spec = always_local_resettable; | |
| 2301 buffer_local_flags.file_format = always_local_resettable; | |
| 2302 buffer_local_flags.generated_modeline_string = always_local_no_default; | |
| 2303 | |
| 2304 buffer_local_flags.keymap = resettable; | |
| 446 | 2305 buffer_local_flags.case_table = resettable; |
| 428 | 2306 buffer_local_flags.syntax_table = resettable; |
| 2307 #ifdef MULE | |
| 2308 buffer_local_flags.category_table = resettable; | |
| 2309 #endif | |
|
5214
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2310 buffer_local_flags.display_time = always_local_no_default; |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2311 buffer_local_flags.display_count = make_int (0); |
| 428 | 2312 |
| 2313 buffer_local_flags.modeline_format = make_int (1<<0); | |
| 2314 buffer_local_flags.abbrev_mode = make_int (1<<1); | |
| 2315 buffer_local_flags.overwrite_mode = make_int (1<<2); | |
| 2316 buffer_local_flags.case_fold_search = make_int (1<<3); | |
| 2317 buffer_local_flags.auto_fill_function = make_int (1<<4); | |
| 2318 buffer_local_flags.selective_display = make_int (1<<5); | |
| 2319 buffer_local_flags.selective_display_ellipses = make_int (1<<6); | |
| 2320 buffer_local_flags.tab_width = make_int (1<<7); | |
| 2321 buffer_local_flags.truncate_lines = make_int (1<<8); | |
| 2322 buffer_local_flags.ctl_arrow = make_int (1<<9); | |
| 2323 buffer_local_flags.fill_column = make_int (1<<10); | |
| 2324 buffer_local_flags.left_margin = make_int (1<<11); | |
| 2325 buffer_local_flags.abbrev_table = make_int (1<<12); | |
| 2326 #ifdef REGION_CACHE_NEEDS_WORK | |
| 2327 buffer_local_flags.cache_long_line_scans = make_int (1<<13); | |
| 2328 #endif | |
| 2329 buffer_local_flags.buffer_file_coding_system = make_int (1<<14); | |
| 2330 | |
| 2331 /* #### Warning: 1<<31 is the largest number currently allowable | |
| 2332 due to the XINT() handling of this value. With some | |
| 558 | 2333 rearrangement you can get 3 more bits. |
| 2334 | |
| 2335 #### 3 more? 34 bits???? -ben */ | |
| 428 | 2336 } |
| 2337 } | |
| 2338 | |
| 2339 #define BUFFER_SLOTS_SIZE (offsetof (struct buffer, BUFFER_SLOTS_LAST_NAME) - offsetof (struct buffer, BUFFER_SLOTS_FIRST_NAME) + sizeof (Lisp_Object)) | |
| 2340 #define BUFFER_SLOTS_COUNT (BUFFER_SLOTS_SIZE / sizeof (Lisp_Object)) | |
| 2341 | |
| 2342 void | |
| 771 | 2343 reinit_complex_vars_of_buffer_runtime_only (void) |
| 428 | 2344 { |
| 2345 struct buffer *defs, *syms; | |
| 2346 | |
| 2347 common_init_complex_vars_of_buffer (); | |
| 2348 | |
| 2349 defs = XBUFFER (Vbuffer_defaults); | |
| 2350 syms = XBUFFER (Vbuffer_local_symbols); | |
| 2351 memcpy (&defs->BUFFER_SLOTS_FIRST_NAME, | |
| 2352 buffer_defaults_saved_slots, | |
| 2353 BUFFER_SLOTS_SIZE); | |
| 2354 memcpy (&syms->BUFFER_SLOTS_FIRST_NAME, | |
| 2355 buffer_local_symbols_saved_slots, | |
| 2356 BUFFER_SLOTS_SIZE); | |
| 2357 } | |
| 2358 | |
| 2359 | |
| 1204 | 2360 static const struct memory_description buffer_slots_description_1[] = { |
| 440 | 2361 { XD_LISP_OBJECT_ARRAY, 0, BUFFER_SLOTS_COUNT }, |
| 428 | 2362 { XD_END } |
| 2363 }; | |
| 2364 | |
| 1204 | 2365 static const struct sized_memory_description buffer_slots_description = { |
| 428 | 2366 BUFFER_SLOTS_SIZE, |
| 2367 buffer_slots_description_1 | |
| 2368 }; | |
| 2369 | |
| 2370 void | |
| 2371 complex_vars_of_buffer (void) | |
| 2372 { | |
| 2373 struct buffer *defs, *syms; | |
| 2374 | |
| 2375 common_init_complex_vars_of_buffer (); | |
| 2376 | |
| 2377 defs = XBUFFER (Vbuffer_defaults); | |
| 2378 syms = XBUFFER (Vbuffer_local_symbols); | |
| 2379 buffer_defaults_saved_slots = &defs->BUFFER_SLOTS_FIRST_NAME; | |
| 2380 buffer_local_symbols_saved_slots = &syms->BUFFER_SLOTS_FIRST_NAME; | |
| 2367 | 2381 dump_add_root_block_ptr (&buffer_defaults_saved_slots, &buffer_slots_description); |
| 2382 dump_add_root_block_ptr (&buffer_local_symbols_saved_slots, &buffer_slots_description); | |
| 440 | 2383 |
| 428 | 2384 DEFVAR_BUFFER_DEFAULTS ("default-modeline-format", modeline_format /* |
| 2385 Default value of `modeline-format' for buffers that don't override it. | |
| 2386 This is the same as (default-value 'modeline-format). | |
| 2387 */ ); | |
| 2388 | |
| 2389 DEFVAR_BUFFER_DEFAULTS ("default-abbrev-mode", abbrev_mode /* | |
| 2390 Default value of `abbrev-mode' for buffers that do not override it. | |
| 2391 This is the same as (default-value 'abbrev-mode). | |
| 2392 */ ); | |
| 2393 | |
| 2394 DEFVAR_BUFFER_DEFAULTS ("default-ctl-arrow", ctl_arrow /* | |
| 2395 Default value of `ctl-arrow' for buffers that do not override it. | |
| 2396 This is the same as (default-value 'ctl-arrow). | |
| 2397 */ ); | |
| 2398 | |
| 2399 #if 0 /* #### make this a specifier! */ | |
| 2400 DEFVAR_BUFFER_DEFAULTS ("default-display-direction", display_direction /* | |
| 2401 Default display-direction for buffers that do not override it. | |
| 2402 This is the same as (default-value 'display-direction). | |
| 2403 Note: This is not yet implemented. | |
| 2404 */ ); | |
| 2405 #endif | |
| 2406 | |
| 2407 DEFVAR_BUFFER_DEFAULTS ("default-truncate-lines", truncate_lines /* | |
| 2408 Default value of `truncate-lines' for buffers that do not override it. | |
| 2409 This is the same as (default-value 'truncate-lines). | |
| 2410 */ ); | |
| 2411 | |
| 2412 DEFVAR_BUFFER_DEFAULTS ("default-fill-column", fill_column /* | |
| 2413 Default value of `fill-column' for buffers that do not override it. | |
| 2414 This is the same as (default-value 'fill-column). | |
| 2415 */ ); | |
| 2416 | |
| 2417 DEFVAR_BUFFER_DEFAULTS ("default-left-margin", left_margin /* | |
| 2418 Default value of `left-margin' for buffers that do not override it. | |
| 2419 This is the same as (default-value 'left-margin). | |
| 2420 */ ); | |
| 2421 | |
| 2422 DEFVAR_BUFFER_DEFAULTS ("default-tab-width", tab_width /* | |
| 2423 Default value of `tab-width' for buffers that do not override it. | |
| 2424 This is the same as (default-value 'tab-width). | |
| 2425 */ ); | |
| 2426 | |
| 2427 DEFVAR_BUFFER_DEFAULTS ("default-case-fold-search", case_fold_search /* | |
| 2428 Default value of `case-fold-search' for buffers that don't override it. | |
| 2429 This is the same as (default-value 'case-fold-search). | |
| 2430 */ ); | |
| 2431 | |
| 2432 DEFVAR_BUFFER_LOCAL ("modeline-format", modeline_format /* | |
| 2433 Template for displaying modeline for current buffer. | |
| 2434 Each buffer has its own value of this variable. | |
| 442 | 2435 Value may be a string, symbol, glyph, generic specifier, list or cons cell. |
| 2436 For a symbol, its value is processed (but it is ignored if t or nil). | |
| 428 | 2437 A string appearing directly as the value of a symbol is processed verbatim |
| 2438 in that the %-constructs below are not recognized. | |
| 2439 For a glyph, it is inserted as is. | |
| 442 | 2440 For a generic specifier (i.e. a specifier of type `generic'), its instance |
| 2441 is computed in the current window using the equivalent of `specifier-instance' | |
| 2442 and the value is processed. | |
| 428 | 2443 For a list whose car is a symbol, the symbol's value is taken, |
| 2444 and if that is non-nil, the cadr of the list is processed recursively. | |
| 2445 Otherwise, the caddr of the list (if there is one) is processed. | |
| 771 | 2446 For a list whose car is a boolean specifier, its instance is computed |
| 2447 in the current window using the equivalent of `specifier-instance', | |
| 2448 and if that is non-nil, the cadr of the list is processed recursively. | |
| 2449 Otherwise, the caddr of the list (if there is one) is processed. | |
| 428 | 2450 For a list whose car is a string or list, each element is processed |
| 2451 recursively and the results are effectively concatenated. | |
| 2452 For a list whose car is an integer, the cdr of the list is processed | |
| 442 | 2453 and padded (if the number is positive) or truncated (if negative) |
| 2454 to the width specified by that number. | |
| 428 | 2455 For a list whose car is an extent, the cdr of the list is processed |
| 2456 normally but the results are displayed using the face of the | |
| 2457 extent, and mouse clicks over this section are processed using the | |
| 2458 keymap of the extent. (In addition, if the extent has a help-echo | |
| 2459 property, that string will be echoed when the mouse moves over this | |
| 442 | 2460 section.) If extents are nested, all keymaps are properly consulted |
| 2461 when processing mouse clicks, but multiple faces are not correctly | |
| 2462 merged (only the first face is used), and lists of faces are not | |
| 2463 correctly handled. See `generated-modeline-string' for more information. | |
| 428 | 2464 A string is printed verbatim in the modeline except for %-constructs: |
| 2465 (%-constructs are processed when the string is the entire modeline-format | |
| 2466 or when it is found in a cons-cell or a list) | |
| 2467 %b -- print buffer name. %c -- print the current column number. | |
| 2468 %f -- print visited file name. | |
| 2469 %* -- print %, * or hyphen. %+ -- print *, % or hyphen. | |
| 2470 % means buffer is read-only and * means it is modified. | |
| 2471 For a modified read-only buffer, %* gives % and %+ gives *. | |
| 2472 %s -- print process status. %l -- print the current line number. | |
| 2473 %S -- print name of selected frame (only meaningful under X Windows). | |
| 2474 %p -- print percent of buffer above top of window, or Top, Bot or All. | |
| 2475 %P -- print percent of buffer above bottom of window, perhaps plus Top, | |
| 2476 or print Bottom or All. | |
| 2477 %n -- print Narrow if appropriate. | |
| 771 | 2478 %C -- print the mnemonic for `buffer-file-coding-system'. |
| 428 | 2479 %[ -- print one [ for each recursive editing level. %] similar. |
| 2480 %% -- print %. %- -- print infinitely many dashes. | |
| 2481 Decimal digits after the % specify field width to which to pad. | |
| 2482 */ ); | |
| 2483 | |
| 2484 DEFVAR_BUFFER_DEFAULTS ("default-major-mode", major_mode /* | |
| 2485 *Major mode for new buffers. Defaults to `fundamental-mode'. | |
| 2486 nil here means use current buffer's major mode. | |
| 2487 */ ); | |
| 2488 | |
| 2489 DEFVAR_BUFFER_DEFAULTS ("fundamental-mode-abbrev-table", abbrev_table /* | |
| 2490 The abbrev table of mode-specific abbrevs for Fundamental Mode. | |
| 2491 */ ); | |
| 2492 | |
| 2493 DEFVAR_BUFFER_LOCAL ("major-mode", major_mode /* | |
| 2494 Symbol for current buffer's major mode. | |
| 2495 */ ); | |
| 2496 | |
| 2497 DEFVAR_BUFFER_LOCAL ("mode-name", mode_name /* | |
| 2498 Pretty name of current buffer's major mode (a string). | |
| 2499 */ ); | |
| 2500 | |
| 2501 DEFVAR_BUFFER_LOCAL ("abbrev-mode", abbrev_mode /* | |
| 2502 Non-nil turns on automatic expansion of abbrevs as they are inserted. | |
| 2503 Automatically becomes buffer-local when set in any fashion. | |
| 2504 */ ); | |
| 2505 | |
| 2506 DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search /* | |
| 2507 *Non-nil if searches should ignore case. | |
| 2508 Automatically becomes buffer-local when set in any fashion. | |
| 2509 */ ); | |
| 2510 | |
| 2511 DEFVAR_BUFFER_LOCAL ("fill-column", fill_column /* | |
| 2512 *Column beyond which automatic line-wrapping should happen. | |
| 2513 Automatically becomes buffer-local when set in any fashion. | |
| 2514 */ ); | |
| 2515 | |
| 2516 DEFVAR_BUFFER_LOCAL ("left-margin", left_margin /* | |
| 2517 *Column for the default indent-line-function to indent to. | |
| 2518 Linefeed indents to this column in Fundamental mode. | |
| 2519 Automatically becomes buffer-local when set in any fashion. | |
| 2520 Do not confuse this with the specifier `left-margin-width'; | |
| 2521 that controls the size of a margin that is displayed outside | |
| 2522 of the text area. | |
| 2523 */ ); | |
| 2524 | |
| 2525 DEFVAR_BUFFER_LOCAL_MAGIC ("tab-width", tab_width /* | |
| 2526 *Distance between tab stops (for display of tab characters), in columns. | |
| 2527 Automatically becomes buffer-local when set in any fashion. | |
| 2528 */ , redisplay_variable_changed); | |
| 2529 | |
| 2530 DEFVAR_BUFFER_LOCAL_MAGIC ("ctl-arrow", ctl_arrow /* | |
| 2531 *Non-nil means display control chars with uparrow. | |
| 2532 Nil means use backslash and octal digits. | |
| 2533 An integer means characters >= ctl-arrow are assumed to be printable, and | |
| 2534 will be displayed as a single glyph. | |
| 2535 Any other value is the same as 160 - the code SPC with the high bit on. | |
| 2536 | |
| 2537 The interpretation of this variable is likely to change in the future. | |
| 2538 | |
| 2539 Automatically becomes buffer-local when set in any fashion. | |
| 2540 This variable does not apply to characters whose display is specified | |
| 2541 in the current display table (if there is one). | |
| 2542 */ , redisplay_variable_changed); | |
| 2543 | |
| 2544 #if 0 /* #### Make this a specifier! */ | |
| 2545 xxDEFVAR_BUFFER_LOCAL ("display-direction", display_direction /* | |
| 2546 *Non-nil means lines in the buffer are displayed right to left. | |
| 2547 Nil means left to right. (Not yet implemented.) | |
| 2548 */ ); | |
| 2549 #endif /* Not yet implemented */ | |
| 2550 | |
| 2551 DEFVAR_BUFFER_LOCAL_MAGIC ("truncate-lines", truncate_lines /* | |
| 2552 *Non-nil means do not display continuation lines; | |
| 2553 give each line of text one frame line. | |
| 2554 Automatically becomes buffer-local when set in any fashion. | |
| 2555 | |
| 2556 Note that this is overridden by the variable | |
| 2557 `truncate-partial-width-windows' if that variable is non-nil | |
| 2558 and this buffer is not full-frame width. | |
| 2559 */ , redisplay_variable_changed); | |
| 2560 | |
| 2561 DEFVAR_BUFFER_LOCAL ("default-directory", directory /* | |
| 2562 Name of default directory of current buffer. Should end with slash. | |
| 2563 Each buffer has its own value of this variable. | |
| 2564 */ ); | |
| 2565 | |
| 771 | 2566 /* NOTE: The default value is set in code-init.el. */ |
| 428 | 2567 DEFVAR_BUFFER_DEFAULTS ("default-buffer-file-coding-system", buffer_file_coding_system /* |
| 2568 Default value of `buffer-file-coding-system' for buffers that do not override it. | |
| 2569 This is the same as (default-value 'buffer-file-coding-system). | |
| 2570 This value is used both for buffers without associated files and | |
| 2571 for buffers whose files do not have any apparent coding system. | |
| 2572 See `buffer-file-coding-system'. | |
| 2573 */ ); | |
| 2574 | |
| 2575 DEFVAR_BUFFER_LOCAL ("buffer-file-coding-system", buffer_file_coding_system /* | |
| 2576 *Current coding system for the current buffer. | |
| 2577 When the buffer is written out into a file, this coding system will be | |
| 2578 used for the encoding. Automatically buffer-local when set in any | |
| 2579 fashion. This is normally set automatically when a file is loaded in | |
| 2580 based on the determined coding system of the file (assuming that | |
| 2581 `buffer-file-coding-system-for-read' is set to `undecided', which | |
| 2582 calls for automatic determination of the file's coding system). | |
| 2583 Normally the modeline indicates the current file coding system using | |
| 2584 its mnemonic abbreviation. | |
| 2585 | |
| 2586 The default value for this variable (which is normally used for | |
| 2587 buffers without associated files) is also used when automatic | |
| 2588 detection of a file's encoding is called for and there was no | |
| 2589 discernible encoding in the file (i.e. it was entirely or almost | |
| 2590 entirely ASCII). The default value should generally *not* be set to | |
| 2591 nil (equivalent to `no-conversion'), because if extended characters | |
| 2592 are ever inserted into the buffer, they will be lost when the file is | |
| 2593 written out. A good choice is `iso-2022-8' (the simple ISO 2022 8-bit | |
| 2594 encoding), which will write out ASCII and Latin-1 characters in the | |
| 2595 standard (and highly portable) fashion and use standard escape | |
| 2596 sequences for other charsets. Another reasonable choice is | |
| 2597 `escape-quoted', which is equivalent to `iso-2022-8' but prefixes | |
| 2598 certain control characters with ESC to make sure they are not | |
| 2599 interpreted as escape sequences when read in. This latter coding | |
| 2600 system results in more "correct" output in the presence of control | |
| 2601 characters in the buffer, in the sense that when read in again using | |
| 2602 the same coding system, the result will virtually always match the | |
| 2603 original contents of the buffer, which is not the case with | |
| 2604 `iso-2022-8'; but the output is less portable when dealing with binary | |
| 2605 data -- there may be stray ESC characters when the file is read by | |
| 2606 another program. | |
| 2607 | |
| 2608 `buffer-file-coding-system' does *not* control the coding system used when | |
| 2609 a file is read in. Use the variables `buffer-file-coding-system-for-read' | |
| 771 | 2610 and `file-coding-system-alist' for that. From a Lisp program, if |
| 428 | 2611 you wish to unilaterally specify the coding system used for one |
| 2612 particular operation, you should bind the variable | |
| 2613 `coding-system-for-read' rather than changing the other two | |
| 2614 variables just mentioned, which are intended to be used for | |
| 2615 global environment specification. | |
| 771 | 2616 |
| 2617 See `insert-file-contents' for a full description of how a file's | |
| 2618 coding system is determined when it is read in. | |
| 428 | 2619 */ ); |
| 2620 | |
| 2621 DEFVAR_BUFFER_LOCAL ("auto-fill-function", auto_fill_function /* | |
| 2622 Function called (if non-nil) to perform auto-fill. | |
| 2623 It is called after self-inserting a space at a column beyond `fill-column'. | |
| 2624 Each buffer has its own value of this variable. | |
| 2625 NOTE: This variable is not an ordinary hook; | |
| 2626 It may not be a list of functions. | |
| 2627 */ ); | |
| 2628 | |
| 2629 DEFVAR_BUFFER_LOCAL ("buffer-file-name", filename /* | |
| 2630 Name of file visited in current buffer, or nil if not visiting a file. | |
| 2631 Each buffer has its own value of this variable. | |
| 3693 | 2632 Code that changes this variable must maintain the invariant |
| 2633 `(equal buffer-file-truename (file-truename buffer-file-name))'. | |
| 428 | 2634 */ ); |
| 2635 | |
| 2636 #if 0 /* FSFmacs */ | |
| 2637 /* | |
| 2638 Abbreviated truename of file visited in current buffer, or nil if none. | |
| 2639 The truename of a file is calculated by `file-truename' | |
| 2640 and then abbreviated with `abbreviate-file-name'. | |
| 2641 Each buffer has its own value of this variable. | |
| 2642 */ | |
| 2643 #endif /* FSFmacs */ | |
| 2644 | |
| 2645 DEFVAR_BUFFER_LOCAL ("buffer-file-truename", file_truename /* | |
| 3693 | 2646 The real name of the file visited in the current buffer, or nil if not |
| 2647 visiting a file. This is the result of passing `buffer-file-name' to the | |
| 2648 `file-truename' function. Every buffer has its own value of this variable. | |
| 2649 Code that changes the file name associated with a buffer maintains the | |
| 2650 invariant `(equal buffer-file-truename (file-truename buffer-file-name))'. | |
| 428 | 2651 */ ); |
| 2652 | |
| 2653 DEFVAR_BUFFER_LOCAL ("buffer-auto-save-file-name", auto_save_file_name /* | |
| 2654 Name of file for auto-saving current buffer, | |
| 2655 or nil if buffer should not be auto-saved. | |
| 2656 Each buffer has its own value of this variable. | |
| 2657 */ ); | |
| 2658 | |
| 2659 DEFVAR_BUFFER_LOCAL ("buffer-read-only", read_only /* | |
| 2660 Non-nil if this buffer is read-only. | |
| 2661 Each buffer has its own value of this variable. | |
| 2662 */ ); | |
| 2663 | |
| 2664 DEFVAR_BUFFER_LOCAL ("buffer-backed-up", backed_up /* | |
| 2665 Non-nil if this buffer's file has been backed up. | |
| 2666 Backing up is done before the first time the file is saved. | |
| 2667 Each buffer has its own value of this variable. | |
| 2668 */ ); | |
| 2669 | |
| 2670 DEFVAR_BUFFER_LOCAL ("buffer-saved-size", saved_size /* | |
| 2671 Length of current buffer when last read in, saved or auto-saved. | |
| 2672 0 initially. | |
| 2673 Each buffer has its own value of this variable. | |
| 2674 */ ); | |
| 2675 | |
| 2676 DEFVAR_BUFFER_LOCAL_MAGIC ("selective-display", selective_display /* | |
| 2677 Non-nil enables selective display: | |
| 2678 Integer N as value means display only lines | |
| 2679 that start with less than n columns of space. | |
| 2680 A value of t means, after a ^M, all the rest of the line is invisible. | |
| 2681 Then ^M's in the file are written into files as newlines. | |
| 2682 | |
| 2683 Automatically becomes buffer-local when set in any fashion. | |
| 2684 */, redisplay_variable_changed); | |
| 2685 | |
| 2686 #ifndef old | |
| 2687 DEFVAR_BUFFER_LOCAL_MAGIC ("selective-display-ellipses", | |
| 2688 selective_display_ellipses /* | |
| 2689 t means display ... on previous line when a line is invisible. | |
| 2690 Automatically becomes buffer-local when set in any fashion. | |
| 2691 */, redisplay_variable_changed); | |
| 2692 #endif | |
| 2693 | |
| 2694 DEFVAR_BUFFER_LOCAL ("local-abbrev-table", abbrev_table /* | |
| 2695 Local (mode-specific) abbrev table of current buffer. | |
| 2696 */ ); | |
| 2697 | |
| 2698 DEFVAR_BUFFER_LOCAL ("overwrite-mode", overwrite_mode /* | |
| 2699 Non-nil if self-insertion should replace existing text. | |
| 2700 The value should be one of `overwrite-mode-textual', | |
| 2701 `overwrite-mode-binary', or nil. | |
| 2702 If it is `overwrite-mode-textual', self-insertion still | |
| 2703 inserts at the end of a line, and inserts when point is before a tab, | |
| 2704 until the tab is filled in. | |
| 2705 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too. | |
| 2706 Automatically becomes buffer-local when set in any fashion. | |
| 2707 | |
| 2708 Normally, you shouldn't modify this variable by hand, but use the functions | |
| 2709 `overwrite-mode' and `binary-overwrite-mode' instead. However, you can | |
| 2710 customize the default value from the options menu. | |
| 2711 */ ); | |
| 2712 | |
| 2713 #if 0 /* FSFmacs */ | |
| 2714 /* Adds the following to the doc string for buffer-undo-list: | |
| 2715 | |
| 2716 An entry (nil PROPERTY VALUE BEG . END) indicates that a text property | |
| 2717 was modified between BEG and END. PROPERTY is the property name, | |
| 2718 and VALUE is the old value. | |
| 2719 */ | |
| 2720 #endif /* FSFmacs */ | |
| 2721 | |
| 2722 DEFVAR_BUFFER_LOCAL ("buffer-undo-list", undo_list /* | |
| 2723 List of undo entries in current buffer. | |
| 2724 Recent changes come first; older changes follow newer. | |
| 2725 | |
| 444 | 2726 An entry (START . END) represents an insertion which begins at |
| 2727 position START and ends at position END. | |
| 428 | 2728 |
| 2729 An entry (TEXT . POSITION) represents the deletion of the string TEXT | |
| 2730 from (abs POSITION). If POSITION is positive, point was at the front | |
| 2731 of the text being deleted; if negative, point was at the end. | |
| 2732 | |
| 2733 An entry (t HIGH . LOW) indicates that the buffer previously had | |
| 2734 "unmodified" status. HIGH and LOW are the high and low 16-bit portions | |
| 2735 of the visited file's modification time, as of that time. If the | |
| 2736 modification time of the most recent save is different, this entry is | |
| 2737 obsolete. | |
| 2738 | |
| 2739 An entry of the form EXTENT indicates that EXTENT was attached in | |
| 2740 the buffer. Undoing an entry of this form detaches EXTENT. | |
| 2741 | |
| 2742 An entry of the form (EXTENT START END) indicates that EXTENT was | |
| 2743 detached from the buffer. Undoing an entry of this form attaches | |
| 2744 EXTENT from START to END. | |
| 2745 | |
| 2746 An entry of the form POSITION indicates that point was at the buffer | |
| 2747 location given by the integer. Undoing an entry of this form places | |
| 2748 point at POSITION. | |
| 2749 | |
| 2750 nil marks undo boundaries. The undo command treats the changes | |
| 2751 between two undo boundaries as a single step to be undone. | |
| 2752 | |
| 2753 If the value of the variable is t, undo information is not recorded. | |
| 2754 */ ); | |
| 2755 | |
| 2756 #if 0 /* FSFmacs */ | |
| 2757 xxDEFVAR_BUFFER_LOCAL ("mark-active", mark_active /* | |
| 2758 Non-nil means the mark and region are currently active in this buffer. | |
| 2759 Automatically local in all buffers. | |
| 2760 */ ); | |
| 2761 #endif /* FSFmacs */ | |
| 2762 | |
| 2763 #ifdef REGION_CACHE_NEEDS_WORK | |
| 2764 xxDEFVAR_BUFFER_LOCAL ("cache-long-line-scans", cache_long_line_scans /* | |
| 2765 Non-nil means that Emacs should use caches to handle long lines more quickly. | |
| 2766 This variable is buffer-local, in all buffers. | |
| 2767 | |
| 2768 Normally, the line-motion functions work by scanning the buffer for | |
| 2769 newlines. Columnar operations (like move-to-column and | |
| 2770 compute-motion) also work by scanning the buffer, summing character | |
| 2771 widths as they go. This works well for ordinary text, but if the | |
| 2772 buffer's lines are very long (say, more than 500 characters), these | |
| 2773 motion functions will take longer to execute. Emacs may also take | |
| 2774 longer to update the display. | |
| 2775 | |
| 2776 If cache-long-line-scans is non-nil, these motion functions cache the | |
| 2777 results of their scans, and consult the cache to avoid rescanning | |
| 2778 regions of the buffer until the text is modified. The caches are most | |
| 2779 beneficial when they prevent the most searching---that is, when the | |
| 2780 buffer contains long lines and large regions of characters with the | |
| 2781 same, fixed screen width. | |
| 2782 | |
| 2783 When cache-long-line-scans is non-nil, processing short lines will | |
| 2784 become slightly slower (because of the overhead of consulting the | |
| 2785 cache), and the caches will use memory roughly proportional to the | |
| 2786 number of newlines and characters whose screen width varies. | |
| 2787 | |
| 2788 The caches require no explicit maintenance; their accuracy is | |
| 2789 maintained internally by the Emacs primitives. Enabling or disabling | |
| 2790 the cache should not affect the behavior of any of the motion | |
| 2791 functions; it should only affect their performance. | |
| 2792 */ ); | |
| 2793 #endif /* REGION_CACHE_NEEDS_WORK */ | |
| 2794 | |
| 2795 DEFVAR_BUFFER_LOCAL ("point-before-scroll", point_before_scroll /* | |
| 2796 Value of point before the last series of scroll operations, or nil. | |
| 2797 */ ); | |
| 2798 | |
| 2799 DEFVAR_BUFFER_LOCAL ("buffer-file-format", file_format /* | |
| 2800 List of formats to use when saving this buffer. | |
| 2801 Formats are defined by `format-alist'. This variable is | |
| 2802 set when a file is visited. Automatically local in all buffers. | |
| 2803 */ ); | |
| 2804 | |
|
5214
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2805 DEFVAR_BUFFER_LOCAL ("buffer-display-count", display_count /* |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2806 A number incremented each time this buffer is displayed in a window. |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2807 The function `set-window-buffer' updates it. |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2808 */ ); |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2809 |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2810 DEFVAR_BUFFER_LOCAL ("buffer-display-time", display_time /* |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2811 Time stamp updated each time this buffer is displayed in a window. |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2812 The function `set-window-buffer' updates this variable |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2813 to the value obtained by calling `current-time'. |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2814 If the buffer has never been shown in a window, the value is nil. |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2815 */); |
|
0b4d355771bd
Import buffer-display-count, buffer-display-time; thank you, Jeff Sparkes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2816 |
| 428 | 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 } |
