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