| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
#include <config.h> |
|---|
| 25 |
|
|---|
| 26 |
#include <sys/types.h> |
|---|
| 27 |
#include <sys/stat.h> |
|---|
| 28 |
#include <sys/param.h> |
|---|
| 29 |
#include <errno.h> |
|---|
| 30 |
#include <stdio.h> |
|---|
| 31 |
|
|---|
| 32 |
#ifndef USE_CRT_DLL |
|---|
| 33 |
extern int errno; |
|---|
| 34 |
#endif |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
#ifdef HAVE_UNISTD_H |
|---|
| 38 |
#include <unistd.h> |
|---|
| 39 |
#endif |
|---|
| 40 |
|
|---|
| 41 |
#include "lisp.h" |
|---|
| 42 |
#include "intervals.h" |
|---|
| 43 |
#include "window.h" |
|---|
| 44 |
#include "commands.h" |
|---|
| 45 |
#include "buffer.h" |
|---|
| 46 |
#include "charset.h" |
|---|
| 47 |
#include "region-cache.h" |
|---|
| 48 |
#include "indent.h" |
|---|
| 49 |
#include "blockinput.h" |
|---|
| 50 |
#include "keyboard.h" |
|---|
| 51 |
#include "keymap.h" |
|---|
| 52 |
#include "frame.h" |
|---|
| 53 |
|
|---|
| 54 |
struct buffer *current_buffer; |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
struct buffer *all_buffers; |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
DECL_ALIGN (struct buffer, buffer_defaults); |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
static Lisp_Object Vbuffer_defaults; |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
struct buffer buffer_local_flags; |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
DECL_ALIGN (struct buffer, buffer_local_symbols); |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
static Lisp_Object Vbuffer_local_symbols; |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
struct buffer buffer_local_types; |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS]; |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
int last_per_buffer_idx; |
|---|
| 121 |
|
|---|
| 122 |
Lisp_Object Fset_buffer (); |
|---|
| 123 |
void set_buffer_internal (); |
|---|
| 124 |
void set_buffer_internal_1 (); |
|---|
| 125 |
static void call_overlay_mod_hooks (); |
|---|
| 126 |
static void swap_out_buffer_local_variables (); |
|---|
| 127 |
static void reset_buffer_local_variables (); |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
Lisp_Object Vbuffer_alist; |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
Lisp_Object Vbefore_change_functions; |
|---|
| 136 |
Lisp_Object Vafter_change_functions; |
|---|
| 137 |
|
|---|
| 138 |
Lisp_Object Vtransient_mark_mode; |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
Lisp_Object Vinhibit_read_only; |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
Lisp_Object Vkill_buffer_query_functions; |
|---|
| 148 |
Lisp_Object Qkill_buffer_query_functions; |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
Lisp_Object Vchange_major_mode_hook, Qchange_major_mode_hook; |
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
Lisp_Object Vfirst_change_hook; |
|---|
| 155 |
|
|---|
| 156 |
Lisp_Object Qfirst_change_hook; |
|---|
| 157 |
Lisp_Object Qbefore_change_functions; |
|---|
| 158 |
Lisp_Object Qafter_change_functions; |
|---|
| 159 |
Lisp_Object Qucs_set_table_for_input; |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
int inhibit_modification_hooks; |
|---|
| 163 |
|
|---|
| 164 |
Lisp_Object Qfundamental_mode, Qmode_class, Qpermanent_local; |
|---|
| 165 |
|
|---|
| 166 |
Lisp_Object Qprotected_field; |
|---|
| 167 |
|
|---|
| 168 |
Lisp_Object QSFundamental; |
|---|
| 169 |
|
|---|
| 170 |
Lisp_Object Qkill_buffer_hook; |
|---|
| 171 |
|
|---|
| 172 |
Lisp_Object Qget_file_buffer; |
|---|
| 173 |
|
|---|
| 174 |
Lisp_Object Qoverlayp; |
|---|
| 175 |
|
|---|
| 176 |
Lisp_Object Qpriority, Qwindow, Qevaporate, Qbefore_string, Qafter_string; |
|---|
| 177 |
|
|---|
| 178 |
Lisp_Object Qmodification_hooks; |
|---|
| 179 |
Lisp_Object Qinsert_in_front_hooks; |
|---|
| 180 |
Lisp_Object Qinsert_behind_hooks; |
|---|
| 181 |
|
|---|
| 182 |
static void alloc_buffer_text P_ ((struct buffer *, size_t)); |
|---|
| 183 |
static void free_buffer_text P_ ((struct buffer *b)); |
|---|
| 184 |
static struct Lisp_Overlay * copy_overlays P_ ((struct buffer *, struct Lisp_Overlay *)); |
|---|
| 185 |
static void modify_overlay P_ ((struct buffer *, EMACS_INT, EMACS_INT)); |
|---|
| 186 |
static Lisp_Object buffer_lisp_local_variables P_ ((struct buffer *)); |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
void |
|---|
| 193 |
nsberror (spec) |
|---|
| 194 |
Lisp_Object spec; |
|---|
| 195 |
{ |
|---|
| 196 |
if (STRINGP (spec)) |
|---|
| 197 |
error ("No buffer named %s", SDATA (spec)); |
|---|
| 198 |
error ("Invalid buffer argument"); |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
DEFUN ("buffer-live-p", Fbuffer_live_p, Sbuffer_live_p, 1, 1, 0, |
|---|
| 202 |
doc: |
|---|
| 203 |
Value is nil if OBJECT is not a buffer or if it has been killed. */) |
|---|
| 204 |
(object) |
|---|
| 205 |
Lisp_Object object; |
|---|
| 206 |
{ |
|---|
| 207 |
return ((BUFFERP (object) && ! NILP (XBUFFER (object)->name)) |
|---|
| 208 |
? Qt : Qnil); |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
DEFUN ("buffer-list", Fbuffer_list, Sbuffer_list, 0, 1, 0, |
|---|
| 212 |
doc: |
|---|
| 213 |
If the optional arg FRAME is a frame, we return the buffer list |
|---|
| 214 |
in the proper order for that frame: the buffers in FRAME's `buffer-list' |
|---|
| 215 |
frame parameter come first, followed by the rest of the buffers. */) |
|---|
| 216 |
(frame) |
|---|
| 217 |
Lisp_Object frame; |
|---|
| 218 |
{ |
|---|
| 219 |
Lisp_Object framelist, general; |
|---|
| 220 |
general = Fmapcar (Qcdr, Vbuffer_alist); |
|---|
| 221 |
|
|---|
| 222 |
if (FRAMEP (frame)) |
|---|
| 223 |
{ |
|---|
| 224 |
Lisp_Object tail; |
|---|
| 225 |
|
|---|
| 226 |
CHECK_FRAME (frame); |
|---|
| 227 |
|
|---|
| 228 |
framelist = Fcopy_sequence (XFRAME (frame)->buffer_list); |
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
tail = framelist; |
|---|
| 232 |
while (! NILP (tail)) |
|---|
| 233 |
{ |
|---|
| 234 |
general = Fdelq (XCAR (tail), general); |
|---|
| 235 |
tail = XCDR (tail); |
|---|
| 236 |
} |
|---|
| 237 |
return nconc2 (framelist, general); |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
return general; |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
static Lisp_Object |
|---|
| 248 |
assoc_ignore_text_properties (key, list) |
|---|
| 249 |
register Lisp_Object key; |
|---|
| 250 |
Lisp_Object list; |
|---|
| 251 |
{ |
|---|
| 252 |
register Lisp_Object tail; |
|---|
| 253 |
for (tail = list; CONSP (tail); tail = XCDR (tail)) |
|---|
| 254 |
{ |
|---|
| 255 |
register Lisp_Object elt, tem; |
|---|
| 256 |
elt = XCAR (tail); |
|---|
| 257 |
tem = Fstring_equal (Fcar (elt), key); |
|---|
| 258 |
if (!NILP (tem)) |
|---|
| 259 |
return elt; |
|---|
| 260 |
} |
|---|
| 261 |
return Qnil; |
|---|
| 262 |
} |
|---|
| 263 |
|
|---|
| 264 |
DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0, |
|---|
| 265 |
doc: |
|---|
| 266 |
If there is no live buffer named NAME, return nil. |
|---|
| 267 |
NAME may also be a buffer; if so, the value is that buffer. */) |
|---|
| 268 |
(name) |
|---|
| 269 |
register Lisp_Object name; |
|---|
| 270 |
{ |
|---|
| 271 |
if (BUFFERP (name)) |
|---|
| 272 |
return name; |
|---|
| 273 |
CHECK_STRING (name); |
|---|
| 274 |
|
|---|
| 275 |
return Fcdr (assoc_ignore_text_properties (name, Vbuffer_alist)); |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0, |
|---|
| 279 |
doc: |
|---|
| 280 |
The buffer's `buffer-file-name' must match exactly the expansion of FILENAME. |
|---|
| 281 |
If there is no such live buffer, return nil. |
|---|
| 282 |
See also `find-buffer-visiting'. */) |
|---|
| 283 |
(filename) |
|---|
| 284 |
register Lisp_Object filename; |
|---|
| 285 |
{ |
|---|
| 286 |
register Lisp_Object tail, buf, tem; |
|---|
| 287 |
Lisp_Object handler; |
|---|
| 288 |
|
|---|
| 289 |
CHECK_STRING (filename); |
|---|
| 290 |
filename = Fexpand_file_name (filename, Qnil); |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
handler = Ffind_file_name_handler (filename, Qget_file_buffer); |
|---|
| 295 |
if (!NILP (handler)) |
|---|
| 296 |
return call2 (handler, Qget_file_buffer, filename); |
|---|
| 297 |
|
|---|
| 298 |
for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) |
|---|
| 299 |
{ |
|---|
| 300 |
buf = Fcdr (XCAR (tail)); |
|---|
| 301 |
if (!BUFFERP (buf)) continue; |
|---|
| 302 |
if (!STRINGP (XBUFFER (buf)->filename)) continue; |
|---|
| 303 |
tem = Fstring_equal (XBUFFER (buf)->filename, filename); |
|---|
| 304 |
if (!NILP (tem)) |
|---|
| 305 |
return buf; |
|---|
| 306 |
} |
|---|
| 307 |
return Qnil; |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
Lisp_Object |
|---|
| 311 |
get_truename_buffer (filename) |
|---|
| 312 |
register Lisp_Object filename; |
|---|
| 313 |
{ |
|---|
| 314 |
register Lisp_Object tail, buf, tem; |
|---|
| 315 |
|
|---|
| 316 |
for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) |
|---|
| 317 |
{ |
|---|
| 318 |
buf = Fcdr (XCAR (tail)); |
|---|
| 319 |
if (!BUFFERP (buf)) continue; |
|---|
| 320 |
if (!STRINGP (XBUFFER (buf)->file_truename)) continue; |
|---|
| 321 |
tem = Fstring_equal (XBUFFER (buf)->file_truename, filename); |
|---|
| 322 |
if (!NILP (tem)) |
|---|
| 323 |
return buf; |
|---|
| 324 |
} |
|---|
| 325 |
return Qnil; |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
int buffer_count; |
|---|
| 330 |
|
|---|
| 331 |
DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0, |
|---|
| 332 |
doc: |
|---|
| 333 |
A new buffer is created if there is no live buffer named NAME. |
|---|
| 334 |
If NAME starts with a space, the new buffer does not keep undo information. |
|---|
| 335 |
If NAME is a buffer instead of a string, then it is the value returned. |
|---|
| 336 |
The value is never nil. */) |
|---|
| 337 |
(name) |
|---|
| 338 |
register Lisp_Object name; |
|---|
| 339 |
{ |
|---|
| 340 |
register Lisp_Object buf; |
|---|
| 341 |
register struct buffer *b; |
|---|
| 342 |
|
|---|
| 343 |
buf = Fget_buffer (name); |
|---|
| 344 |
if (!NILP (buf)) |
|---|
| 345 |
return buf; |
|---|
| 346 |
|
|---|
| 347 |
if (SCHARS (name) == 0) |
|---|
| 348 |
error ("Empty string for buffer name is not allowed"); |
|---|
| 349 |
|
|---|
| 350 |
b = (struct buffer *) allocate_buffer (); |
|---|
| 351 |
|
|---|
| 352 |
b->size = sizeof (struct buffer) / sizeof (EMACS_INT); |
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
b->text = &b->own_text; |
|---|
| 356 |
b->base_buffer = 0; |
|---|
| 357 |
|
|---|
| 358 |
BUF_GAP_SIZE (b) = 20; |
|---|
| 359 |
BLOCK_INPUT; |
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1); |
|---|
| 363 |
UNBLOCK_INPUT; |
|---|
| 364 |
if (! BUF_BEG_ADDR (b)) |
|---|
| 365 |
buffer_memory_full (); |
|---|
| 366 |
|
|---|
| 367 |
BUF_PT (b) = BEG; |
|---|
| 368 |
BUF_GPT (b) = BEG; |
|---|
| 369 |
BUF_BEGV (b) = BEG; |
|---|
| 370 |
BUF_ZV (b) = BEG; |
|---|
| 371 |
BUF_Z (b) = BEG; |
|---|
| 372 |
BUF_PT_BYTE (b) = BEG_BYTE; |
|---|
| 373 |
BUF_GPT_BYTE (b) = BEG_BYTE; |
|---|
| 374 |
BUF_BEGV_BYTE (b) = BEG_BYTE; |
|---|
| 375 |
BUF_ZV_BYTE (b) = BEG_BYTE; |
|---|
| 376 |
BUF_Z_BYTE (b) = BEG_BYTE; |
|---|
| 377 |
BUF_MODIFF (b) = 1; |
|---|
| 378 |
BUF_CHARS_MODIFF (b) = 1; |
|---|
| 379 |
BUF_OVERLAY_MODIFF (b) = 1; |
|---|
| 380 |
BUF_SAVE_MODIFF (b) = 1; |
|---|
| 381 |
BUF_INTERVALS (b) = 0; |
|---|
| 382 |
BUF_UNCHANGED_MODIFIED (b) = 1; |
|---|
| 383 |
BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1; |
|---|
| 384 |
BUF_END_UNCHANGED (b) = 0; |
|---|
| 385 |
BUF_BEG_UNCHANGED (b) = 0; |
|---|
| 386 |
*(BUF_GPT_ADDR (b)) = *(BUF_Z_ADDR (b)) = 0; |
|---|
| 387 |
|
|---|
| 388 |
b->newline_cache = 0; |
|---|
| 389 |
b->width_run_cache = 0; |
|---|
| 390 |
b->width_table = Qnil; |
|---|
| 391 |
b->prevent_redisplay_optimizations_p = 1; |
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
b->next = all_buffers; |
|---|
| 395 |
all_buffers = b; |
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
b->pt_marker = Qnil; |
|---|
| 400 |
b->begv_marker = Qnil; |
|---|
| 401 |
b->zv_marker = Qnil; |
|---|
| 402 |
|
|---|
| 403 |
name = Fcopy_sequence (name); |
|---|
| 404 |
STRING_SET_INTERVALS (name, NULL_INTERVAL); |
|---|
| 405 |
b->name = name; |
|---|
| 406 |
|
|---|
| 407 |
if (SREF (name, 0) != ' ') |
|---|
| 408 |
b->undo_list = Qnil; |
|---|
| 409 |
else |
|---|
| 410 |
b->undo_list = Qt; |
|---|
| 411 |
|
|---|
| 412 |
reset_buffer (b); |
|---|
| 413 |
reset_buffer_local_variables (b, 1); |
|---|
| 414 |
|
|---|
| 415 |
b->mark = Fmake_marker (); |
|---|
| 416 |
BUF_MARKERS (b) = NULL; |
|---|
| 417 |
b->name = name; |
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
XSETBUFFER (buf, b); |
|---|
| 421 |
Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil)); |
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
if (!NILP (Ffboundp (Qucs_set_table_for_input)) |
|---|
| 427 |
#ifdef MEADOW |
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
&& current_buffer != 0 |
|---|
| 432 |
#endif |
|---|
| 433 |
) |
|---|
| 434 |
|
|---|
| 435 |
call1 (Qucs_set_table_for_input, buf); |
|---|
| 436 |
|
|---|
| 437 |
return buf; |
|---|
| 438 |
} |
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 |
static struct Lisp_Overlay * |
|---|
| 445 |
copy_overlays (b, list) |
|---|
| 446 |
struct buffer *b; |
|---|
| 447 |
struct Lisp_Overlay *list; |
|---|
| 448 |
{ |
|---|
| 449 |
Lisp_Object buffer; |
|---|
| 450 |
struct Lisp_Overlay *result = NULL, *tail = NULL; |
|---|
| 451 |
|
|---|
| 452 |
XSETBUFFER (buffer, b); |
|---|
| 453 |
|
|---|
| 454 |
for (; list; list = list->next) |
|---|
| 455 |
{ |
|---|
| 456 |
Lisp_Object overlay, start, end, old_overlay; |
|---|
| 457 |
EMACS_INT charpos; |
|---|
| 458 |
|
|---|
| 459 |
XSETMISC (old_overlay, list); |
|---|
| 460 |
charpos = marker_position (OVERLAY_START (old_overlay)); |
|---|
| 461 |
start = Fmake_marker (); |
|---|
| 462 |
Fset_marker (start, make_number (charpos), buffer); |
|---|
| 463 |
XMARKER (start)->insertion_type |
|---|
| 464 |
= XMARKER (OVERLAY_START (old_overlay))->insertion_type; |
|---|
| 465 |
|
|---|
| 466 |
charpos = marker_position (OVERLAY_END (old_overlay)); |
|---|
| 467 |
end = Fmake_marker (); |
|---|
| 468 |
Fset_marker (end, make_number (charpos), buffer); |
|---|
| 469 |
XMARKER (end)->insertion_type |
|---|
| 470 |
= XMARKER (OVERLAY_END (old_overlay))->insertion_type; |
|---|
| 471 |
|
|---|
| 472 |
overlay = allocate_misc (); |
|---|
| 473 |
XMISCTYPE (overlay) = Lisp_Misc_Overlay; |
|---|
| 474 |
OVERLAY_START (overlay) = start; |
|---|
| 475 |
OVERLAY_END (overlay) = end; |
|---|
| 476 |
OVERLAY_PLIST (overlay) = Fcopy_sequence (OVERLAY_PLIST (old_overlay)); |
|---|
| 477 |
XOVERLAY (overlay)->next = NULL; |
|---|
| 478 |
|
|---|
| 479 |
if (tail) |
|---|
| 480 |
tail = tail->next = XOVERLAY (overlay); |
|---|
| 481 |
else |
|---|
| 482 |
result = tail = XOVERLAY (overlay); |
|---|
| 483 |
} |
|---|
| 484 |
|
|---|
| 485 |
return result; |
|---|
| 486 |
} |
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
static void |
|---|
| 497 |
clone_per_buffer_values (from, to) |
|---|
| 498 |
struct buffer *from, *to; |
|---|
| 499 |
{ |
|---|
| 500 |
Lisp_Object to_buffer; |
|---|
| 501 |
int offset; |
|---|
| 502 |
|
|---|
| 503 |
XSETBUFFER (to_buffer, to); |
|---|
| 504 |
|
|---|
| 505 |
for (offset = PER_BUFFER_VAR_OFFSET (name) + sizeof (Lisp_Object); |
|---|
| 506 |
offset < sizeof *to; |
|---|
| 507 |
offset += sizeof (Lisp_Object)) |
|---|
| 508 |
{ |
|---|
| 509 |
Lisp_Object obj; |
|---|
| 510 |
|
|---|
| 511 |
obj = PER_BUFFER_VALUE (from, offset); |
|---|
| 512 |
if (MARKERP (obj)) |
|---|
| 513 |
{ |
|---|
| 514 |
struct Lisp_Marker *m = XMARKER (obj); |
|---|
| 515 |
obj = Fmake_marker (); |
|---|
| 516 |
XMARKER (obj)->insertion_type = m->insertion_type; |
|---|
| 517 |
set_marker_both (obj, to_buffer, m->charpos, m->bytepos); |
|---|
| 518 |
} |
|---|
| 519 |
|
|---|
| 520 |
PER_BUFFER_VALUE (to, offset) = obj; |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
bcopy (from->local_flags, to->local_flags, sizeof to->local_flags); |
|---|
| 524 |
|
|---|
| 525 |
to->overlays_before = copy_overlays (to, from->overlays_before); |
|---|
| 526 |
to->overlays_after = copy_overlays (to, from->overlays_after); |
|---|
| 527 |
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
to->local_var_alist = buffer_lisp_local_variables (from); |
|---|
| 531 |
} |
|---|
| 532 |
|
|---|
| 533 |
DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, Smake_indirect_buffer, |
|---|
| 534 |
2, 3, |
|---|
| 535 |
"bMake indirect buffer (to buffer): \nBName of indirect buffer: ", |
|---|
| 536 |
doc: |
|---|
| 537 |
BASE-BUFFER should be a live buffer, or the name of an existing buffer. |
|---|
| 538 |
NAME should be a string which is not the name of an existing buffer. |
|---|
| 539 |
Optional argument CLONE non-nil means preserve BASE-BUFFER's state, |
|---|
| 540 |
such as major and minor modes, in the indirect buffer. |
|---|
| 541 |
CLONE nil means the indirect buffer's state is reset to default values. */) |
|---|
| 542 |
(base_buffer, name, clone) |
|---|
| 543 |
Lisp_Object base_buffer, name, clone; |
|---|
| 544 |
{ |
|---|
| 545 |
Lisp_Object buf, tem; |
|---|
| 546 |
struct buffer *b; |
|---|
| 547 |
|
|---|
| 548 |
CHECK_STRING (name); |
|---|
| 549 |
buf = Fget_buffer (name); |
|---|
| 550 |
if (!NILP (buf)) |
|---|
| 551 |
error ("Buffer name `%s' is in use", SDATA (name)); |
|---|
| 552 |
|
|---|
| 553 |
tem = base_buffer; |
|---|
| 554 |
base_buffer = Fget_buffer (base_buffer); |
|---|
| 555 |
if (NILP (base_buffer)) |
|---|
| 556 |
error ("No such buffer: `%s'", SDATA (tem)); |
|---|
| 557 |
if (NILP (XBUFFER (base_buffer)->name)) |
|---|
| 558 |
error ("Base buffer has been killed"); |
|---|
| 559 |
|
|---|
| 560 |
if (SCHARS (name) == 0) |
|---|
| 561 |
error ("Empty string for buffer name is not allowed"); |
|---|
| 562 |
|
|---|
| 563 |
b = (struct buffer *) allocate_buffer (); |
|---|
| 564 |
b->size = sizeof (struct buffer) / sizeof (EMACS_INT); |
|---|
| 565 |
|
|---|
| 566 |
if (XBUFFER (base_buffer)->base_buffer) |
|---|
| 567 |
b->base_buffer = XBUFFER (base_buffer)->base_buffer; |
|---|
| 568 |
else |
|---|
| 569 |
b->base_buffer = XBUFFER (base_buffer); |
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
b->text = b->base_buffer->text; |
|---|
| 573 |
|
|---|
| 574 |
BUF_BEGV (b) = BUF_BEGV (b->base_buffer); |
|---|
| 575 |
BUF_ZV (b) = BUF_ZV (b->base_buffer); |
|---|
| 576 |
BUF_PT (b) = BUF_PT (b->base_buffer); |
|---|
| 577 |
BUF_BEGV_BYTE (b) = BUF_BEGV_BYTE (b->base_buffer); |
|---|
| 578 |
BUF_ZV_BYTE (b) = BUF_ZV_BYTE (b->base_buffer); |
|---|
| 579 |
BUF_PT_BYTE (b) = BUF_PT_BYTE (b->base_buffer); |
|---|
| 580 |
|
|---|
| 581 |
b->newline_cache = 0; |
|---|
| 582 |
b->width_run_cache = 0; |
|---|
| 583 |
b->width_table = Qnil; |
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
b->next = all_buffers; |
|---|
| 587 |
all_buffers = b; |
|---|
| 588 |
|
|---|
| 589 |
name = Fcopy_sequence (name); |
|---|
| 590 |
STRING_SET_INTERVALS (name, NULL_INTERVAL); |
|---|
| 591 |
b->name = name; |
|---|
| 592 |
|
|---|
| 593 |
reset_buffer (b); |
|---|
| 594 |
reset_buffer_local_variables (b, 1); |
|---|
| 595 |
|
|---|
| 596 |
|
|---|