aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.h
diff options
context:
space:
mode:
authorBill Wohler2012-11-24 19:43:02 -0800
committerBill Wohler2012-11-24 19:43:02 -0800
commit5244bc019bf7376caff3bb198ff674e0ad9fb0e6 (patch)
tree02ee1615e904771f692ec2957c79a08ae029a13d /src/buffer.h
parent9f7e719509474e92f85955e22e57ffeebd4e96f3 (diff)
parentc07a6ded1df2f4156badc9add2953579622c3722 (diff)
downloademacs-5244bc019bf7376caff3bb198ff674e0ad9fb0e6.tar.gz
emacs-5244bc019bf7376caff3bb198ff674e0ad9fb0e6.zip
Merge from trunk.
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h854
1 files changed, 558 insertions, 296 deletions
diff --git a/src/buffer.h b/src/buffer.h
index fa65a4b81fd..fbbbf1b8434 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1,6 +1,6 @@
1/* Header file for the buffer manipulation primitives. 1/* Header file for the buffer manipulation primitives.
2 2
3Copyright (C) 1985-1986, 1993-1995, 1997-2011 3Copyright (C) 1985-1986, 1993-1995, 1997-2012
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -19,6 +19,12 @@ You should have received a copy of the GNU General Public License
19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21#include <sys/types.h> /* for off_t, time_t */ 21#include <sys/types.h> /* for off_t, time_t */
22#include "systime.h" /* for EMACS_TIME */
23
24INLINE_HEADER_BEGIN
25#ifndef BUFFER_INLINE
26# define BUFFER_INLINE INLINE
27#endif
22 28
23/* Accessing the parameters of the current buffer. */ 29/* Accessing the parameters of the current buffer. */
24 30
@@ -187,9 +193,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
187/* FIXME: should we move this into ->text->auto_save_modiff? */ 193/* FIXME: should we move this into ->text->auto_save_modiff? */
188#define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified) 194#define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified)
189 195
190/* Interval tree of buffer. */
191#define BUF_INTERVALS(buf) ((buf)->text->intervals)
192
193/* Marker chain of buffer. */ 196/* Marker chain of buffer. */
194#define BUF_MARKERS(buf) ((buf)->text->markers) 197#define BUF_MARKERS(buf) ((buf)->text->markers)
195 198
@@ -245,12 +248,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
245#define BUF_TEMP_SET_PT(buffer, position) \ 248#define BUF_TEMP_SET_PT(buffer, position) \
246 (temp_set_point ((buffer), (position))) 249 (temp_set_point ((buffer), (position)))
247 250
248extern void set_point (EMACS_INT); 251extern void set_point (ptrdiff_t);
249extern void temp_set_point (struct buffer *, EMACS_INT); 252extern void temp_set_point (struct buffer *, ptrdiff_t);
250extern void set_point_both (EMACS_INT, EMACS_INT); 253extern void set_point_both (ptrdiff_t, ptrdiff_t);
251extern void temp_set_point_both (struct buffer *, 254extern void temp_set_point_both (struct buffer *,
252 EMACS_INT, EMACS_INT); 255 ptrdiff_t, ptrdiff_t);
253extern void enlarge_buffer_text (struct buffer *, EMACS_INT); 256extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
254 257
255 258
256/* Macros for setting the BEGV, ZV or PT of a given buffer. 259/* Macros for setting the BEGV, ZV or PT of a given buffer.
@@ -343,7 +346,8 @@ while (0)
343 - (ptr - (current_buffer)->text->beg <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) \ 346 - (ptr - (current_buffer)->text->beg <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) \
344 + BEG_BYTE) 347 + BEG_BYTE)
345 348
346/* Return character at byte position POS. */ 349/* Return character at byte position POS. See the caveat WARNING for
350 FETCH_MULTIBYTE_CHAR below. */
347 351
348#define FETCH_CHAR(pos) \ 352#define FETCH_CHAR(pos) \
349 (!NILP (BVAR (current_buffer, enable_multibyte_characters)) \ 353 (!NILP (BVAR (current_buffer, enable_multibyte_characters)) \
@@ -354,18 +358,6 @@ while (0)
354 358
355#define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n))) 359#define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n)))
356 360
357/* Variables used locally in FETCH_MULTIBYTE_CHAR. */
358extern unsigned char *_fetch_multibyte_char_p;
359
360/* Return character code of multi-byte form at byte position POS. If POS
361 doesn't point the head of valid multi-byte form, only the byte at
362 POS is returned. No range checking. */
363
364#define FETCH_MULTIBYTE_CHAR(pos) \
365 (_fetch_multibyte_char_p = (((pos) >= GPT_BYTE ? GAP_SIZE : 0) \
366 + (pos) + BEG_ADDR - BEG_BYTE), \
367 STRING_CHAR (_fetch_multibyte_char_p))
368
369/* Return character at byte position POS. If the current buffer is unibyte 361/* Return character at byte position POS. If the current buffer is unibyte
370 and the character is not ASCII, make the returning character 362 and the character is not ASCII, make the returning character
371 multibyte. */ 363 multibyte. */
@@ -414,16 +406,6 @@ extern unsigned char *_fetch_multibyte_char_p;
414 406
415#define BUF_FETCH_BYTE(buf, n) \ 407#define BUF_FETCH_BYTE(buf, n) \
416 *(BUF_BYTE_ADDRESS ((buf), (n))) 408 *(BUF_BYTE_ADDRESS ((buf), (n)))
417
418/* Return character code of multi-byte form at byte position POS in BUF.
419 If POS doesn't point the head of valid multi-byte form, only the byte at
420 POS is returned. No range checking. */
421
422#define BUF_FETCH_MULTIBYTE_CHAR(buf, pos) \
423 (_fetch_multibyte_char_p \
424 = (((pos) >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0) \
425 + (pos) + BUF_BEG_ADDR (buf) - BEG_BYTE), \
426 STRING_CHAR (_fetch_multibyte_char_p))
427 409
428/* Define the actual buffer data structures. */ 410/* Define the actual buffer data structures. */
429 411
@@ -438,38 +420,41 @@ struct buffer_text
438 into a buffer's text to functions that malloc. */ 420 into a buffer's text to functions that malloc. */
439 unsigned char *beg; 421 unsigned char *beg;
440 422
441 EMACS_INT gpt; /* Char pos of gap in buffer. */ 423 ptrdiff_t gpt; /* Char pos of gap in buffer. */
442 EMACS_INT z; /* Char pos of end of buffer. */ 424 ptrdiff_t z; /* Char pos of end of buffer. */
443 EMACS_INT gpt_byte; /* Byte pos of gap in buffer. */ 425 ptrdiff_t gpt_byte; /* Byte pos of gap in buffer. */
444 EMACS_INT z_byte; /* Byte pos of end of buffer. */ 426 ptrdiff_t z_byte; /* Byte pos of end of buffer. */
445 EMACS_INT gap_size; /* Size of buffer's gap. */ 427 ptrdiff_t gap_size; /* Size of buffer's gap. */
446 int modiff; /* This counts buffer-modification events 428 EMACS_INT modiff; /* This counts buffer-modification events
447 for this buffer. It is incremented for 429 for this buffer. It is incremented for
448 each such event, and never otherwise 430 each such event, and never otherwise
449 changed. */ 431 changed. */
450 int chars_modiff; /* This is modified with character change 432 EMACS_INT chars_modiff; /* This is modified with character change
451 events for this buffer. It is set to 433 events for this buffer. It is set to
452 modiff for each such event, and never 434 modiff for each such event, and never
453 otherwise changed. */ 435 otherwise changed. */
454 int save_modiff; /* Previous value of modiff, as of last 436 EMACS_INT save_modiff; /* Previous value of modiff, as of last
455 time buffer visited or saved a file. */ 437 time buffer visited or saved a file. */
456 438
457 int overlay_modiff; /* Counts modifications to overlays. */ 439 EMACS_INT overlay_modiff; /* Counts modifications to overlays. */
440
441 EMACS_INT compact; /* Set to modiff each time when compact_buffer
442 is called for this buffer. */
458 443
459 /* Minimum value of GPT - BEG since last redisplay that finished. */ 444 /* Minimum value of GPT - BEG since last redisplay that finished. */
460 EMACS_INT beg_unchanged; 445 ptrdiff_t beg_unchanged;
461 446
462 /* Minimum value of Z - GPT since last redisplay that finished. */ 447 /* Minimum value of Z - GPT since last redisplay that finished. */
463 EMACS_INT end_unchanged; 448 ptrdiff_t end_unchanged;
464 449
465 /* MODIFF as of last redisplay that finished; if it matches MODIFF, 450 /* MODIFF as of last redisplay that finished; if it matches MODIFF,
466 beg_unchanged and end_unchanged contain no useful information. */ 451 beg_unchanged and end_unchanged contain no useful information. */
467 int unchanged_modified; 452 EMACS_INT unchanged_modified;
468 453
469 /* BUF_OVERLAY_MODIFF of current buffer, as of last redisplay that 454 /* BUF_OVERLAY_MODIFF of current buffer, as of last redisplay that
470 finished; if it matches BUF_OVERLAY_MODIFF, beg_unchanged and 455 finished; if it matches BUF_OVERLAY_MODIFF, beg_unchanged and
471 end_unchanged contain no useful information. */ 456 end_unchanged contain no useful information. */
472 int overlay_unchanged_modified; 457 EMACS_INT overlay_unchanged_modified;
473 458
474 /* Properties of this buffer's text. */ 459 /* Properties of this buffer's text. */
475 INTERVAL intervals; 460 INTERVAL intervals;
@@ -486,267 +471,164 @@ struct buffer_text
486 /* Usually 0. Temporarily set to 1 in decode_coding_gap to 471 /* Usually 0. Temporarily set to 1 in decode_coding_gap to
487 prevent Fgarbage_collect from shrinking the gap and losing 472 prevent Fgarbage_collect from shrinking the gap and losing
488 not-yet-decoded bytes. */ 473 not-yet-decoded bytes. */
489 int inhibit_shrinking; 474 bool inhibit_shrinking;
490 }; 475 };
491 476
492/* Lisp fields in struct buffer are hidden from most code and accessed 477/* Most code should use this macro to access Lisp fields in struct buffer. */
493 via the BVAR macro, below. Only select pieces of code, like the GC,
494 are allowed to use BUFFER_INTERNAL_FIELD. */
495#define BUFFER_INTERNAL_FIELD(field) field ## _
496 478
497/* Most code should use this macro to access Lisp fields in struct 479#define BVAR(buf, field) ((buf)->INTERNAL_FIELD (field))
498 buffer. */
499#define BVAR(buf, field) ((buf)->BUFFER_INTERNAL_FIELD (field))
500 480
501/* This is the structure that the buffer Lisp object points to. */ 481/* This is the structure that the buffer Lisp object points to. */
502 482
503struct buffer 483struct buffer
504{ 484{
505 /* Everything before the `name' slot must be of a non-Lisp_Object type,
506 and every slot after `name' must be a Lisp_Object.
507
508 Check out mark_buffer (alloc.c) to see why. */
509
510 /* HEADER.NEXT is the next buffer, in chain of all buffers,
511 including killed buffers.
512 This chain is used only for garbage collection, in order to
513 collect killed buffers properly.
514 Note that vectors and most pseudovectors are all on one chain,
515 but buffers are on a separate chain of their own. */
516 struct vectorlike_header header; 485 struct vectorlike_header header;
517 486
518 /* This structure holds the coordinates of the buffer contents 487 /* The name of this buffer. */
519 in ordinary buffers. In indirect buffers, this is not used. */ 488 Lisp_Object INTERNAL_FIELD (name);
520 struct buffer_text own_text;
521
522 /* This points to the `struct buffer_text' that used for this buffer.
523 In an ordinary buffer, this is the own_text field above.
524 In an indirect buffer, this is the own_text field of another buffer. */
525 struct buffer_text *text;
526
527 /* Char position of point in buffer. */
528 EMACS_INT pt;
529 /* Byte position of point in buffer. */
530 EMACS_INT pt_byte;
531 /* Char position of beginning of accessible range. */
532 EMACS_INT begv;
533 /* Byte position of beginning of accessible range. */
534 EMACS_INT begv_byte;
535 /* Char position of end of accessible range. */
536 EMACS_INT zv;
537 /* Byte position of end of accessible range. */
538 EMACS_INT zv_byte;
539
540 /* In an indirect buffer, this points to the base buffer.
541 In an ordinary buffer, it is 0. */
542 struct buffer *base_buffer;
543
544 /* A non-zero value in slot IDX means that per-buffer variable
545 with index IDX has a local value in this buffer. The index IDX
546 for a buffer-local variable is stored in that variable's slot
547 in buffer_local_flags as a Lisp integer. If the index is -1,
548 this means the variable is always local in all buffers. */
549#define MAX_PER_BUFFER_VARS 50
550 char local_flags[MAX_PER_BUFFER_VARS];
551
552 /* Set to the modtime of the visited file when read or written.
553 -1 means visited file was nonexistent.
554 0 means visited file modtime unknown; in no case complain
555 about any mismatch on next save attempt. */
556 time_t modtime;
557 /* Size of the file when modtime was set. This is used to detect the
558 case where the file grew while we were reading it, so the modtime
559 is still the same (since it's rounded up to seconds) but we're actually
560 not up-to-date. -1 means the size is unknown. Only meaningful if
561 modtime is actually set. */
562 off_t modtime_size;
563 /* The value of text->modiff at the last auto-save. */
564 int auto_save_modified;
565 /* The value of text->modiff at the last display error.
566 Redisplay of this buffer is inhibited until it changes again. */
567 int display_error_modiff;
568 /* The time at which we detected a failure to auto-save,
569 Or 0 if we didn't have a failure. */
570 time_t auto_save_failure_time;
571 /* Position in buffer at which display started
572 the last time this buffer was displayed. */
573 EMACS_INT last_window_start;
574
575 /* Set nonzero whenever the narrowing is changed in this buffer. */
576 int clip_changed;
577
578 /* If the long line scan cache is enabled (i.e. the buffer-local
579 variable cache-long-line-scans is non-nil), newline_cache
580 points to the newline cache, and width_run_cache points to the
581 width run cache.
582
583 The newline cache records which stretches of the buffer are
584 known *not* to contain newlines, so that they can be skipped
585 quickly when we search for newlines.
586
587 The width run cache records which stretches of the buffer are
588 known to contain characters whose widths are all the same. If
589 the width run cache maps a character to a value > 0, that value is
590 the character's width; if it maps a character to zero, we don't
591 know what its width is. This allows compute_motion to process
592 such regions very quickly, using algebra instead of inspecting
593 each character. See also width_table, below. */
594 struct region_cache *newline_cache;
595 struct region_cache *width_run_cache;
596
597 /* Non-zero means don't use redisplay optimizations for
598 displaying this buffer. */
599 unsigned prevent_redisplay_optimizations_p : 1;
600
601 /* List of overlays that end at or before the current center,
602 in order of end-position. */
603 struct Lisp_Overlay *overlays_before;
604 489
605 /* List of overlays that end after the current center, 490 /* The name of the file visited in this buffer, or nil. */
606 in order of start-position. */ 491 Lisp_Object INTERNAL_FIELD (filename);
607 struct Lisp_Overlay *overlays_after;
608 492
609 /* Position where the overlay lists are centered. */ 493 /* Directory for expanding relative file names. */
610 EMACS_INT overlay_center; 494 Lisp_Object INTERNAL_FIELD (directory);
611
612 /* Everything from here down must be a Lisp_Object. */
613 /* buffer-local Lisp variables start at `undo_list',
614 tho only the ones from `name' on are GC'd normally. */
615 #define FIRST_FIELD_PER_BUFFER undo_list
616
617 /* Changes in the buffer are recorded here for undo.
618 t means don't record anything.
619 This information belongs to the base buffer of an indirect buffer,
620 But we can't store it in the struct buffer_text
621 because local variables have to be right in the struct buffer.
622 So we copy it around in set_buffer_internal.
623 This comes before `name' because it is marked in a special way. */
624 Lisp_Object BUFFER_INTERNAL_FIELD (undo_list);
625 495
626 /* The name of this buffer. */ 496 /* True if this buffer has been backed up (if you write to the visited
627 Lisp_Object BUFFER_INTERNAL_FIELD (name); 497 file and it hasn't been backed up, then a backup will be made). */
498 Lisp_Object INTERNAL_FIELD (backed_up);
628 499
629 /* The name of the file visited in this buffer, or nil. */
630 Lisp_Object BUFFER_INTERNAL_FIELD (filename);
631 /* Dir for expanding relative file names. */
632 Lisp_Object BUFFER_INTERNAL_FIELD (directory);
633 /* True if this buffer has been backed up (if you write to the
634 visited file and it hasn't been backed up, then a backup will
635 be made). */
636 /* This isn't really used by the C code, so could be deleted. */
637 Lisp_Object BUFFER_INTERNAL_FIELD (backed_up);
638 /* Length of file when last read or saved. 500 /* Length of file when last read or saved.
639 -1 means auto saving turned off because buffer shrank a lot. 501 -1 means auto saving turned off because buffer shrank a lot.
640 -2 means don't turn off auto saving if buffer shrinks. 502 -2 means don't turn off auto saving if buffer shrinks.
641 (That value is used with buffer-swap-text.) 503 (That value is used with buffer-swap-text.)
642 This is not in the struct buffer_text 504 This is not in the struct buffer_text
643 because it's not used in indirect buffers at all. */ 505 because it's not used in indirect buffers at all. */
644 Lisp_Object BUFFER_INTERNAL_FIELD (save_length); 506 Lisp_Object INTERNAL_FIELD (save_length);
507
645 /* File name used for auto-saving this buffer. 508 /* File name used for auto-saving this buffer.
646 This is not in the struct buffer_text 509 This is not in the struct buffer_text
647 because it's not used in indirect buffers at all. */ 510 because it's not used in indirect buffers at all. */
648 Lisp_Object BUFFER_INTERNAL_FIELD (auto_save_file_name); 511 Lisp_Object INTERNAL_FIELD (auto_save_file_name);
649 512
650 /* Non-nil if buffer read-only. */ 513 /* Non-nil if buffer read-only. */
651 Lisp_Object BUFFER_INTERNAL_FIELD (read_only); 514 Lisp_Object INTERNAL_FIELD (read_only);
515
652 /* "The mark". This is a marker which may 516 /* "The mark". This is a marker which may
653 point into this buffer or may point nowhere. */ 517 point into this buffer or may point nowhere. */
654 Lisp_Object BUFFER_INTERNAL_FIELD (mark); 518 Lisp_Object INTERNAL_FIELD (mark);
655 519
656 /* Alist of elements (SYMBOL . VALUE-IN-THIS-BUFFER) for all 520 /* Alist of elements (SYMBOL . VALUE-IN-THIS-BUFFER) for all
657 per-buffer variables of this buffer. For locally unbound 521 per-buffer variables of this buffer. For locally unbound
658 symbols, just the symbol appears as the element. */ 522 symbols, just the symbol appears as the element. */
659 Lisp_Object BUFFER_INTERNAL_FIELD (local_var_alist); 523 Lisp_Object INTERNAL_FIELD (local_var_alist);
524
525 /* Symbol naming major mode (e.g., lisp-mode). */
526 Lisp_Object INTERNAL_FIELD (major_mode);
527
528 /* Pretty name of major mode (e.g., "Lisp"). */
529 Lisp_Object INTERNAL_FIELD (mode_name);
660 530
661 /* Symbol naming major mode (eg, lisp-mode). */
662 Lisp_Object BUFFER_INTERNAL_FIELD (major_mode);
663 /* Pretty name of major mode (eg, "Lisp"). */
664 Lisp_Object BUFFER_INTERNAL_FIELD (mode_name);
665 /* Mode line element that controls format of mode line. */ 531 /* Mode line element that controls format of mode line. */
666 Lisp_Object BUFFER_INTERNAL_FIELD (mode_line_format); 532 Lisp_Object INTERNAL_FIELD (mode_line_format);
667 533
668 /* Analogous to mode_line_format for the line displayed at the top 534 /* Analogous to mode_line_format for the line displayed at the top
669 of windows. Nil means don't display that line. */ 535 of windows. Nil means don't display that line. */
670 Lisp_Object BUFFER_INTERNAL_FIELD (header_line_format); 536 Lisp_Object INTERNAL_FIELD (header_line_format);
671 537
672 /* Keys that are bound local to this buffer. */ 538 /* Keys that are bound local to this buffer. */
673 Lisp_Object BUFFER_INTERNAL_FIELD (keymap); 539 Lisp_Object INTERNAL_FIELD (keymap);
540
674 /* This buffer's local abbrev table. */ 541 /* This buffer's local abbrev table. */
675 Lisp_Object BUFFER_INTERNAL_FIELD (abbrev_table); 542 Lisp_Object INTERNAL_FIELD (abbrev_table);
543
676 /* This buffer's syntax table. */ 544 /* This buffer's syntax table. */
677 Lisp_Object BUFFER_INTERNAL_FIELD (syntax_table); 545 Lisp_Object INTERNAL_FIELD (syntax_table);
546
678 /* This buffer's category table. */ 547 /* This buffer's category table. */
679 Lisp_Object BUFFER_INTERNAL_FIELD (category_table); 548 Lisp_Object INTERNAL_FIELD (category_table);
680 549
681 /* Values of several buffer-local variables. */ 550 /* Values of several buffer-local variables. */
682 /* tab-width is buffer-local so that redisplay can find it 551 /* tab-width is buffer-local so that redisplay can find it
683 in buffers that are not current. */ 552 in buffers that are not current. */
684 Lisp_Object BUFFER_INTERNAL_FIELD (case_fold_search); 553 Lisp_Object INTERNAL_FIELD (case_fold_search);
685 Lisp_Object BUFFER_INTERNAL_FIELD (tab_width); 554 Lisp_Object INTERNAL_FIELD (tab_width);
686 Lisp_Object BUFFER_INTERNAL_FIELD (fill_column); 555 Lisp_Object INTERNAL_FIELD (fill_column);
687 Lisp_Object BUFFER_INTERNAL_FIELD (left_margin); 556 Lisp_Object INTERNAL_FIELD (left_margin);
557
688 /* Function to call when insert space past fill column. */ 558 /* Function to call when insert space past fill column. */
689 Lisp_Object BUFFER_INTERNAL_FIELD (auto_fill_function); 559 Lisp_Object INTERNAL_FIELD (auto_fill_function);
690 560
691 /* Case table for case-conversion in this buffer. 561 /* Case table for case-conversion in this buffer.
692 This char-table maps each char into its lower-case version. */ 562 This char-table maps each char into its lower-case version. */
693 Lisp_Object BUFFER_INTERNAL_FIELD (downcase_table); 563 Lisp_Object INTERNAL_FIELD (downcase_table);
564
694 /* Char-table mapping each char to its upper-case version. */ 565 /* Char-table mapping each char to its upper-case version. */
695 Lisp_Object BUFFER_INTERNAL_FIELD (upcase_table); 566 Lisp_Object INTERNAL_FIELD (upcase_table);
567
696 /* Char-table for conversion for case-folding search. */ 568 /* Char-table for conversion for case-folding search. */
697 Lisp_Object BUFFER_INTERNAL_FIELD (case_canon_table); 569 Lisp_Object INTERNAL_FIELD (case_canon_table);
570
698 /* Char-table of equivalences for case-folding search. */ 571 /* Char-table of equivalences for case-folding search. */
699 Lisp_Object BUFFER_INTERNAL_FIELD (case_eqv_table); 572 Lisp_Object INTERNAL_FIELD (case_eqv_table);
700 573
701 /* Non-nil means do not display continuation lines. */ 574 /* Non-nil means do not display continuation lines. */
702 Lisp_Object BUFFER_INTERNAL_FIELD (truncate_lines); 575 Lisp_Object INTERNAL_FIELD (truncate_lines);
576
703 /* Non-nil means to use word wrapping when displaying continuation lines. */ 577 /* Non-nil means to use word wrapping when displaying continuation lines. */
704 Lisp_Object BUFFER_INTERNAL_FIELD (word_wrap); 578 Lisp_Object INTERNAL_FIELD (word_wrap);
579
705 /* Non-nil means display ctl chars with uparrow. */ 580 /* Non-nil means display ctl chars with uparrow. */
706 Lisp_Object BUFFER_INTERNAL_FIELD (ctl_arrow); 581 Lisp_Object INTERNAL_FIELD (ctl_arrow);
582
707 /* Non-nil means reorder bidirectional text for display in the 583 /* Non-nil means reorder bidirectional text for display in the
708 visual order. */ 584 visual order. */
709 Lisp_Object BUFFER_INTERNAL_FIELD (bidi_display_reordering); 585 Lisp_Object INTERNAL_FIELD (bidi_display_reordering);
586
710 /* If non-nil, specifies which direction of text to force in all the 587 /* If non-nil, specifies which direction of text to force in all the
711 paragraphs of the buffer. Nil means determine paragraph 588 paragraphs of the buffer. Nil means determine paragraph
712 direction dynamically for each paragraph. */ 589 direction dynamically for each paragraph. */
713 Lisp_Object BUFFER_INTERNAL_FIELD (bidi_paragraph_direction); 590 Lisp_Object INTERNAL_FIELD (bidi_paragraph_direction);
591
714 /* Non-nil means do selective display; 592 /* Non-nil means do selective display;
715 see doc string in syms_of_buffer (buffer.c) for details. */ 593 see doc string in syms_of_buffer (buffer.c) for details. */
716 Lisp_Object BUFFER_INTERNAL_FIELD (selective_display); 594 Lisp_Object INTERNAL_FIELD (selective_display);
717#ifndef old 595
718 /* Non-nil means show ... at end of line followed by invisible lines. */ 596 /* Non-nil means show ... at end of line followed by invisible lines. */
719 Lisp_Object BUFFER_INTERNAL_FIELD (selective_display_ellipses); 597 Lisp_Object INTERNAL_FIELD (selective_display_ellipses);
720#endif 598
721 /* Alist of (FUNCTION . STRING) for each minor mode enabled in buffer. */ 599 /* Alist of (FUNCTION . STRING) for each minor mode enabled in buffer. */
722 Lisp_Object BUFFER_INTERNAL_FIELD (minor_modes); 600 Lisp_Object INTERNAL_FIELD (minor_modes);
601
723 /* t if "self-insertion" should overwrite; `binary' if it should also 602 /* t if "self-insertion" should overwrite; `binary' if it should also
724 overwrite newlines and tabs - for editing executables and the like. */ 603 overwrite newlines and tabs - for editing executables and the like. */
725 Lisp_Object BUFFER_INTERNAL_FIELD (overwrite_mode); 604 Lisp_Object INTERNAL_FIELD (overwrite_mode);
726 /* non-nil means abbrev mode is on. Expand abbrevs automatically. */ 605
727 Lisp_Object BUFFER_INTERNAL_FIELD (abbrev_mode); 606 /* Non-nil means abbrev mode is on. Expand abbrevs automatically. */
607 Lisp_Object INTERNAL_FIELD (abbrev_mode);
608
728 /* Display table to use for text in this buffer. */ 609 /* Display table to use for text in this buffer. */
729 Lisp_Object BUFFER_INTERNAL_FIELD (display_table); 610 Lisp_Object INTERNAL_FIELD (display_table);
611
730 /* t means the mark and region are currently active. */ 612 /* t means the mark and region are currently active. */
731 Lisp_Object BUFFER_INTERNAL_FIELD (mark_active); 613 Lisp_Object INTERNAL_FIELD (mark_active);
732 614
733 /* Non-nil means the buffer contents are regarded as multi-byte 615 /* Non-nil means the buffer contents are regarded as multi-byte
734 form of characters, not a binary code. */ 616 form of characters, not a binary code. */
735 Lisp_Object BUFFER_INTERNAL_FIELD (enable_multibyte_characters); 617 Lisp_Object INTERNAL_FIELD (enable_multibyte_characters);
736 618
737 /* Coding system to be used for encoding the buffer contents on 619 /* Coding system to be used for encoding the buffer contents on
738 saving. */ 620 saving. */
739 Lisp_Object BUFFER_INTERNAL_FIELD (buffer_file_coding_system); 621 Lisp_Object INTERNAL_FIELD (buffer_file_coding_system);
740 622
741 /* List of symbols naming the file format used for visited file. */ 623 /* List of symbols naming the file format used for visited file. */
742 Lisp_Object BUFFER_INTERNAL_FIELD (file_format); 624 Lisp_Object INTERNAL_FIELD (file_format);
743 625
744 /* List of symbols naming the file format used for auto-save file. */ 626 /* List of symbols naming the file format used for auto-save file. */
745 Lisp_Object BUFFER_INTERNAL_FIELD (auto_save_file_format); 627 Lisp_Object INTERNAL_FIELD (auto_save_file_format);
746 628
747 /* True if the newline position cache and width run cache are 629 /* True if the newline position cache and width run cache are
748 enabled. See search.c and indent.c. */ 630 enabled. See search.c and indent.c. */
749 Lisp_Object BUFFER_INTERNAL_FIELD (cache_long_line_scans); 631 Lisp_Object INTERNAL_FIELD (cache_long_line_scans);
750 632
751 /* If the width run cache is enabled, this table contains the 633 /* If the width run cache is enabled, this table contains the
752 character widths width_run_cache (see above) assumes. When we 634 character widths width_run_cache (see above) assumes. When we
@@ -754,105 +636,377 @@ struct buffer
754 current display table to see whether the display table has 636 current display table to see whether the display table has
755 affected the widths of any characters. If it has, we 637 affected the widths of any characters. If it has, we
756 invalidate the width run cache, and re-initialize width_table. */ 638 invalidate the width run cache, and re-initialize width_table. */
757 Lisp_Object BUFFER_INTERNAL_FIELD (width_table); 639 Lisp_Object INTERNAL_FIELD (width_table);
758 640
759 /* In an indirect buffer, or a buffer that is the base of an 641 /* In an indirect buffer, or a buffer that is the base of an
760 indirect buffer, this holds a marker that records 642 indirect buffer, this holds a marker that records
761 PT for this buffer when the buffer is not current. */ 643 PT for this buffer when the buffer is not current. */
762 Lisp_Object BUFFER_INTERNAL_FIELD (pt_marker); 644 Lisp_Object INTERNAL_FIELD (pt_marker);
763 645
764 /* In an indirect buffer, or a buffer that is the base of an 646 /* In an indirect buffer, or a buffer that is the base of an
765 indirect buffer, this holds a marker that records 647 indirect buffer, this holds a marker that records
766 BEGV for this buffer when the buffer is not current. */ 648 BEGV for this buffer when the buffer is not current. */
767 Lisp_Object BUFFER_INTERNAL_FIELD (begv_marker); 649 Lisp_Object INTERNAL_FIELD (begv_marker);
768 650
769 /* In an indirect buffer, or a buffer that is the base of an 651 /* In an indirect buffer, or a buffer that is the base of an
770 indirect buffer, this holds a marker that records 652 indirect buffer, this holds a marker that records
771 ZV for this buffer when the buffer is not current. */ 653 ZV for this buffer when the buffer is not current. */
772 Lisp_Object BUFFER_INTERNAL_FIELD (zv_marker); 654 Lisp_Object INTERNAL_FIELD (zv_marker);
773 655
774 /* This holds the point value before the last scroll operation. 656 /* This holds the point value before the last scroll operation.
775 Explicitly setting point sets this to nil. */ 657 Explicitly setting point sets this to nil. */
776 Lisp_Object BUFFER_INTERNAL_FIELD (point_before_scroll); 658 Lisp_Object INTERNAL_FIELD (point_before_scroll);
777 659
778 /* Truename of the visited file, or nil. */ 660 /* Truename of the visited file, or nil. */
779 Lisp_Object BUFFER_INTERNAL_FIELD (file_truename); 661 Lisp_Object INTERNAL_FIELD (file_truename);
780 662
781 /* Invisibility spec of this buffer. 663 /* Invisibility spec of this buffer.
782 t => any non-nil `invisible' property means invisible. 664 t => any non-nil `invisible' property means invisible.
783 A list => `invisible' property means invisible 665 A list => `invisible' property means invisible
784 if it is memq in that list. */ 666 if it is memq in that list. */
785 Lisp_Object BUFFER_INTERNAL_FIELD (invisibility_spec); 667 Lisp_Object INTERNAL_FIELD (invisibility_spec);
786 668
787 /* This is the last window that was selected with this buffer in it, 669 /* This is the last window that was selected with this buffer in it,
788 or nil if that window no longer displays this buffer. */ 670 or nil if that window no longer displays this buffer. */
789 Lisp_Object BUFFER_INTERNAL_FIELD (last_selected_window); 671 Lisp_Object INTERNAL_FIELD (last_selected_window);
790 672
791 /* Incremented each time the buffer is displayed in a window. */ 673 /* Incremented each time the buffer is displayed in a window. */
792 Lisp_Object BUFFER_INTERNAL_FIELD (display_count); 674 Lisp_Object INTERNAL_FIELD (display_count);
793 675
794 /* Widths of left and right marginal areas for windows displaying 676 /* Widths of left and right marginal areas for windows displaying
795 this buffer. */ 677 this buffer. */
796 Lisp_Object BUFFER_INTERNAL_FIELD (left_margin_cols), BUFFER_INTERNAL_FIELD (right_margin_cols); 678 Lisp_Object INTERNAL_FIELD (left_margin_cols);
679 Lisp_Object INTERNAL_FIELD (right_margin_cols);
797 680
798 /* Widths of left and right fringe areas for windows displaying 681 /* Widths of left and right fringe areas for windows displaying
799 this buffer. */ 682 this buffer. */
800 Lisp_Object BUFFER_INTERNAL_FIELD (left_fringe_width), BUFFER_INTERNAL_FIELD (right_fringe_width); 683 Lisp_Object INTERNAL_FIELD (left_fringe_width);
684 Lisp_Object INTERNAL_FIELD (right_fringe_width);
801 685
802 /* Non-nil means fringes are drawn outside display margins; 686 /* Non-nil means fringes are drawn outside display margins;
803 othersize draw them between margin areas and text. */ 687 othersize draw them between margin areas and text. */
804 Lisp_Object BUFFER_INTERNAL_FIELD (fringes_outside_margins); 688 Lisp_Object INTERNAL_FIELD (fringes_outside_margins);
805 689
806 /* Width and type of scroll bar areas for windows displaying 690 /* Width and type of scroll bar areas for windows displaying
807 this buffer. */ 691 this buffer. */
808 Lisp_Object BUFFER_INTERNAL_FIELD (scroll_bar_width), BUFFER_INTERNAL_FIELD (vertical_scroll_bar_type); 692 Lisp_Object INTERNAL_FIELD (scroll_bar_width);
693 Lisp_Object INTERNAL_FIELD (vertical_scroll_bar_type);
809 694
810 /* Non-nil means indicate lines not displaying text (in a style 695 /* Non-nil means indicate lines not displaying text (in a style
811 like vi). */ 696 like vi). */
812 Lisp_Object BUFFER_INTERNAL_FIELD (indicate_empty_lines); 697 Lisp_Object INTERNAL_FIELD (indicate_empty_lines);
813 698
814 /* Non-nil means indicate buffer boundaries and scrolling. */ 699 /* Non-nil means indicate buffer boundaries and scrolling. */
815 Lisp_Object BUFFER_INTERNAL_FIELD (indicate_buffer_boundaries); 700 Lisp_Object INTERNAL_FIELD (indicate_buffer_boundaries);
816 701
817 /* Logical to physical fringe bitmap mappings. */ 702 /* Logical to physical fringe bitmap mappings. */
818 Lisp_Object BUFFER_INTERNAL_FIELD (fringe_indicator_alist); 703 Lisp_Object INTERNAL_FIELD (fringe_indicator_alist);
819 704
820 /* Logical to physical cursor bitmap mappings. */ 705 /* Logical to physical cursor bitmap mappings. */
821 Lisp_Object BUFFER_INTERNAL_FIELD (fringe_cursor_alist); 706 Lisp_Object INTERNAL_FIELD (fringe_cursor_alist);
822 707
823 /* Time stamp updated each time this buffer is displayed in a window. */ 708 /* Time stamp updated each time this buffer is displayed in a window. */
824 Lisp_Object BUFFER_INTERNAL_FIELD (display_time); 709 Lisp_Object INTERNAL_FIELD (display_time);
825 710
826 /* If scrolling the display because point is below the bottom of a 711 /* If scrolling the display because point is below the bottom of a
827 window showing this buffer, try to choose a window start so 712 window showing this buffer, try to choose a window start so
828 that point ends up this number of lines from the top of the 713 that point ends up this number of lines from the top of the
829 window. Nil means that scrolling method isn't used. */ 714 window. Nil means that scrolling method isn't used. */
830 Lisp_Object BUFFER_INTERNAL_FIELD (scroll_up_aggressively); 715 Lisp_Object INTERNAL_FIELD (scroll_up_aggressively);
831 716
832 /* If scrolling the display because point is above the top of a 717 /* If scrolling the display because point is above the top of a
833 window showing this buffer, try to choose a window start so 718 window showing this buffer, try to choose a window start so
834 that point ends up this number of lines from the bottom of the 719 that point ends up this number of lines from the bottom of the
835 window. Nil means that scrolling method isn't used. */ 720 window. Nil means that scrolling method isn't used. */
836 Lisp_Object BUFFER_INTERNAL_FIELD (scroll_down_aggressively); 721 Lisp_Object INTERNAL_FIELD (scroll_down_aggressively);
837 722
838 /* Desired cursor type in this buffer. See the doc string of 723 /* Desired cursor type in this buffer. See the doc string of
839 per-buffer variable `cursor-type'. */ 724 per-buffer variable `cursor-type'. */
840 Lisp_Object BUFFER_INTERNAL_FIELD (cursor_type); 725 Lisp_Object INTERNAL_FIELD (cursor_type);
841 726
842 /* An integer > 0 means put that number of pixels below text lines 727 /* An integer > 0 means put that number of pixels below text lines
843 in the display of this buffer. */ 728 in the display of this buffer. */
844 Lisp_Object BUFFER_INTERNAL_FIELD (extra_line_spacing); 729 Lisp_Object INTERNAL_FIELD (extra_line_spacing);
845 730
846 /* *Cursor type to display in non-selected windows. 731 /* Cursor type to display in non-selected windows.
847 t means to use hollow box cursor. 732 t means to use hollow box cursor.
848 See `cursor-type' for other values. */ 733 See `cursor-type' for other values. */
849 Lisp_Object BUFFER_INTERNAL_FIELD (cursor_in_non_selected_windows); 734 Lisp_Object INTERNAL_FIELD (cursor_in_non_selected_windows);
735
736 /* No more Lisp_Object beyond this point. Except undo_list,
737 which is handled specially in Fgarbage_collect . */
738
739 /* This structure holds the coordinates of the buffer contents
740 in ordinary buffers. In indirect buffers, this is not used. */
741 struct buffer_text own_text;
742
743 /* This points to the `struct buffer_text' that used for this buffer.
744 In an ordinary buffer, this is the own_text field above.
745 In an indirect buffer, this is the own_text field of another buffer. */
746 struct buffer_text *text;
747
748 /* Next buffer, in chain of all buffers, including killed ones. */
749 struct buffer *next;
750
751 /* Char position of point in buffer. */
752 ptrdiff_t pt;
753
754 /* Byte position of point in buffer. */
755 ptrdiff_t pt_byte;
756
757 /* Char position of beginning of accessible range. */
758 ptrdiff_t begv;
759
760 /* Byte position of beginning of accessible range. */
761 ptrdiff_t begv_byte;
762
763 /* Char position of end of accessible range. */
764 ptrdiff_t zv;
765
766 /* Byte position of end of accessible range. */
767 ptrdiff_t zv_byte;
768
769 /* In an indirect buffer, this points to the base buffer.
770 In an ordinary buffer, it is 0. */
771 struct buffer *base_buffer;
772
773 /* In an indirect buffer, this is -1. In an ordinary buffer,
774 it's the number of indirect buffers that share our text;
775 zero means that we're the only owner of this text. */
776 int indirections;
777
778 /* A non-zero value in slot IDX means that per-buffer variable
779 with index IDX has a local value in this buffer. The index IDX
780 for a buffer-local variable is stored in that variable's slot
781 in buffer_local_flags as a Lisp integer. If the index is -1,
782 this means the variable is always local in all buffers. */
783#define MAX_PER_BUFFER_VARS 50
784 char local_flags[MAX_PER_BUFFER_VARS];
785
786 /* Set to the modtime of the visited file when read or written.
787 EMACS_NSECS (modtime) == NONEXISTENT_MODTIME_NSECS means
788 visited file was nonexistent. EMACS_NSECS (modtime) ==
789 UNKNOWN_MODTIME_NSECS means visited file modtime unknown;
790 in no case complain about any mismatch on next save attempt. */
791#define NONEXISTENT_MODTIME_NSECS (-1)
792#define UNKNOWN_MODTIME_NSECS (-2)
793 EMACS_TIME modtime;
794
795 /* Size of the file when modtime was set. This is used to detect the
796 case where the file grew while we were reading it, so the modtime
797 is still the same (since it's rounded up to seconds) but we're actually
798 not up-to-date. -1 means the size is unknown. Only meaningful if
799 modtime is actually set. */
800 off_t modtime_size;
801
802 /* The value of text->modiff at the last auto-save. */
803 EMACS_INT auto_save_modified;
804
805 /* The value of text->modiff at the last display error.
806 Redisplay of this buffer is inhibited until it changes again. */
807 EMACS_INT display_error_modiff;
808
809 /* The time at which we detected a failure to auto-save,
810 Or 0 if we didn't have a failure. */
811 time_t auto_save_failure_time;
812
813 /* Position in buffer at which display started
814 the last time this buffer was displayed. */
815 ptrdiff_t last_window_start;
816
817 /* If the long line scan cache is enabled (i.e. the buffer-local
818 variable cache-long-line-scans is non-nil), newline_cache
819 points to the newline cache, and width_run_cache points to the
820 width run cache.
821
822 The newline cache records which stretches of the buffer are
823 known *not* to contain newlines, so that they can be skipped
824 quickly when we search for newlines.
825
826 The width run cache records which stretches of the buffer are
827 known to contain characters whose widths are all the same. If
828 the width run cache maps a character to a value > 0, that value is
829 the character's width; if it maps a character to zero, we don't
830 know what its width is. This allows compute_motion to process
831 such regions very quickly, using algebra instead of inspecting
832 each character. See also width_table, below. */
833 struct region_cache *newline_cache;
834 struct region_cache *width_run_cache;
835
836 /* Non-zero means don't use redisplay optimizations for
837 displaying this buffer. */
838 unsigned prevent_redisplay_optimizations_p : 1;
839
840 /* Non-zero whenever the narrowing is changed in this buffer. */
841 unsigned clip_changed : 1;
842
843 /* List of overlays that end at or before the current center,
844 in order of end-position. */
845 struct Lisp_Overlay *overlays_before;
846
847 /* List of overlays that end after the current center,
848 in order of start-position. */
849 struct Lisp_Overlay *overlays_after;
850 850
851 /* This must be the last field in the above list. */ 851 /* Position where the overlay lists are centered. */
852 #define LAST_FIELD_PER_BUFFER cursor_in_non_selected_windows 852 ptrdiff_t overlay_center;
853
854 /* Changes in the buffer are recorded here for undo, and t means
855 don't record anything. This information belongs to the base
856 buffer of an indirect buffer. But we can't store it in the
857 struct buffer_text because local variables have to be right in
858 the struct buffer. So we copy it around in set_buffer_internal. */
859 Lisp_Object INTERNAL_FIELD (undo_list);
853}; 860};
854 861
855 862/* Most code should use these functions to set Lisp fields in struct
863 buffer. */
864BUFFER_INLINE void
865bset_bidi_paragraph_direction (struct buffer *b, Lisp_Object val)
866{
867 b->INTERNAL_FIELD (bidi_paragraph_direction) = val;
868}
869BUFFER_INLINE void
870bset_case_canon_table (struct buffer *b, Lisp_Object val)
871{
872 b->INTERNAL_FIELD (case_canon_table) = val;
873}
874BUFFER_INLINE void
875bset_case_eqv_table (struct buffer *b, Lisp_Object val)
876{
877 b->INTERNAL_FIELD (case_eqv_table) = val;
878}
879BUFFER_INLINE void
880bset_directory (struct buffer *b, Lisp_Object val)
881{
882 b->INTERNAL_FIELD (directory) = val;
883}
884BUFFER_INLINE void
885bset_display_count (struct buffer *b, Lisp_Object val)
886{
887 b->INTERNAL_FIELD (display_count) = val;
888}
889BUFFER_INLINE void
890bset_display_time (struct buffer *b, Lisp_Object val)
891{
892 b->INTERNAL_FIELD (display_time) = val;
893}
894BUFFER_INLINE void
895bset_downcase_table (struct buffer *b, Lisp_Object val)
896{
897 b->INTERNAL_FIELD (downcase_table) = val;
898}
899BUFFER_INLINE void
900bset_enable_multibyte_characters (struct buffer *b, Lisp_Object val)
901{
902 b->INTERNAL_FIELD (enable_multibyte_characters) = val;
903}
904BUFFER_INLINE void
905bset_filename (struct buffer *b, Lisp_Object val)
906{
907 b->INTERNAL_FIELD (filename) = val;
908}
909BUFFER_INLINE void
910bset_keymap (struct buffer *b, Lisp_Object val)
911{
912 b->INTERNAL_FIELD (keymap) = val;
913}
914BUFFER_INLINE void
915bset_last_selected_window (struct buffer *b, Lisp_Object val)
916{
917 b->INTERNAL_FIELD (last_selected_window) = val;
918}
919BUFFER_INLINE void
920bset_local_var_alist (struct buffer *b, Lisp_Object val)
921{
922 b->INTERNAL_FIELD (local_var_alist) = val;
923}
924BUFFER_INLINE void
925bset_mark_active (struct buffer *b, Lisp_Object val)
926{
927 b->INTERNAL_FIELD (mark_active) = val;
928}
929BUFFER_INLINE void
930bset_point_before_scroll (struct buffer *b, Lisp_Object val)
931{
932 b->INTERNAL_FIELD (point_before_scroll) = val;
933}
934BUFFER_INLINE void
935bset_read_only (struct buffer *b, Lisp_Object val)
936{
937 b->INTERNAL_FIELD (read_only) = val;
938}
939BUFFER_INLINE void
940bset_truncate_lines (struct buffer *b, Lisp_Object val)
941{
942 b->INTERNAL_FIELD (truncate_lines) = val;
943}
944BUFFER_INLINE void
945bset_undo_list (struct buffer *b, Lisp_Object val)
946{
947 b->INTERNAL_FIELD (undo_list) = val;
948}
949BUFFER_INLINE void
950bset_upcase_table (struct buffer *b, Lisp_Object val)
951{
952 b->INTERNAL_FIELD (upcase_table) = val;
953}
954BUFFER_INLINE void
955bset_width_table (struct buffer *b, Lisp_Object val)
956{
957 b->INTERNAL_FIELD (width_table) = val;
958}
959
960/* Number of Lisp_Objects at the beginning of struct buffer.
961 If you add, remove, or reorder Lisp_Objects within buffer
962 structure, make sure that this is still correct. */
963
964#define BUFFER_LISP_SIZE \
965 ((offsetof (struct buffer, own_text) - header_size) / word_size)
966
967/* Size of the struct buffer part beyond leading Lisp_Objects, in word_size
968 units. Rounding is needed for --with-wide-int configuration. */
969
970#define BUFFER_REST_SIZE \
971 ((((sizeof (struct buffer) - offsetof (struct buffer, own_text)) \
972 + (word_size - 1)) & ~(word_size - 1)) / word_size)
973
974/* Initialize the pseudovector header of buffer object. BUFFER_LISP_SIZE
975 is required for GC, but BUFFER_REST_SIZE is set up just to be consistent
976 with other pseudovectors. */
977
978#define BUFFER_PVEC_INIT(b) \
979 XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE)
980
981/* Convenient check whether buffer B is live. */
982
983#define BUFFER_LIVE_P(b) (!NILP (BVAR (b, name)))
984
985/* Verify indirection counters. */
986
987#define BUFFER_CHECK_INDIRECTION(b) \
988 do { \
989 if (BUFFER_LIVE_P (b)) \
990 { \
991 if (b->base_buffer) \
992 { \
993 eassert (b->indirections == -1); \
994 eassert (b->base_buffer->indirections > 0); \
995 } \
996 else \
997 eassert (b->indirections >= 0); \
998 } \
999 } while (0)
1000
1001/* Chain of all buffers, including killed ones. */
1002
1003extern struct buffer *all_buffers;
1004
1005/* Used to iterate over the chain above. */
1006
1007#define FOR_EACH_BUFFER(b) \
1008 for ((b) = all_buffers; (b); (b) = (b)->next)
1009
856/* This points to the current buffer. */ 1010/* This points to the current buffer. */
857 1011
858extern struct buffer *current_buffer; 1012extern struct buffer *current_buffer;
@@ -890,21 +1044,46 @@ extern struct buffer buffer_local_symbols;
890 1044
891extern void delete_all_overlays (struct buffer *); 1045extern void delete_all_overlays (struct buffer *);
892extern void reset_buffer (struct buffer *); 1046extern void reset_buffer (struct buffer *);
893extern void evaporate_overlays (EMACS_INT); 1047extern void compact_buffer (struct buffer *);
894extern ptrdiff_t overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 1048extern void evaporate_overlays (ptrdiff_t);
895 ptrdiff_t *len_ptr, EMACS_INT *next_ptr, 1049extern ptrdiff_t overlays_at (EMACS_INT, bool, Lisp_Object **,
896 EMACS_INT *prev_ptr, int change_req); 1050 ptrdiff_t *, ptrdiff_t *, ptrdiff_t *, bool);
897extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *); 1051extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
898extern void recenter_overlay_lists (struct buffer *, EMACS_INT); 1052extern void recenter_overlay_lists (struct buffer *, ptrdiff_t);
899extern EMACS_INT overlay_strings (EMACS_INT, struct window *, unsigned char **); 1053extern ptrdiff_t overlay_strings (ptrdiff_t, struct window *, unsigned char **);
900extern void validate_region (Lisp_Object *, Lisp_Object *); 1054extern void validate_region (Lisp_Object *, Lisp_Object *);
901extern void set_buffer_internal (struct buffer *);
902extern void set_buffer_internal_1 (struct buffer *); 1055extern void set_buffer_internal_1 (struct buffer *);
903extern void set_buffer_temp (struct buffer *); 1056extern void set_buffer_temp (struct buffer *);
1057extern Lisp_Object buffer_local_value_1 (Lisp_Object, Lisp_Object);
904extern void record_buffer (Lisp_Object); 1058extern void record_buffer (Lisp_Object);
905extern void buffer_slot_type_mismatch (Lisp_Object, int) NO_RETURN; 1059extern _Noreturn void buffer_slot_type_mismatch (Lisp_Object, int);
906extern void fix_overlays_before (struct buffer *, EMACS_INT, EMACS_INT); 1060extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
907extern void mmap_set_vars (int); 1061extern void mmap_set_vars (bool);
1062
1063/* Set the current buffer to B.
1064
1065 We previously set windows_or_buffers_changed here to invalidate
1066 global unchanged information in beg_unchanged and end_unchanged.
1067 This is no longer necessary because we now compute unchanged
1068 information on a buffer-basis. Every action affecting other
1069 windows than the selected one requires a select_window at some
1070 time, and that increments windows_or_buffers_changed. */
1071
1072BUFFER_INLINE void
1073set_buffer_internal (struct buffer *b)
1074{
1075 if (current_buffer != b)
1076 set_buffer_internal_1 (b);
1077}
1078
1079/* Arrange to go back to the original buffer after the next
1080 call to unbind_to if the original buffer is still alive. */
1081
1082BUFFER_INLINE void
1083record_unwind_current_buffer (void)
1084{
1085 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
1086}
908 1087
909/* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements. 1088/* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements.
910 If NEXTP is non-NULL, return next overlay there. 1089 If NEXTP is non-NULL, return next overlay there.
@@ -912,52 +1091,103 @@ extern void mmap_set_vars (int);
912 1091
913#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \ 1092#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \
914 do { \ 1093 do { \
915 ptrdiff_t maxlen = 40; \ 1094 ptrdiff_t maxlen = 40; \
916 overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \ 1095 overlays = alloca (maxlen * sizeof *overlays); \
917 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \ 1096 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
918 nextp, NULL, chrq); \ 1097 nextp, NULL, chrq); \
919 if (noverlays > maxlen) \ 1098 if (noverlays > maxlen) \
920 { \ 1099 { \
921 maxlen = noverlays; \ 1100 maxlen = noverlays; \
922 overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \ 1101 overlays = alloca (maxlen * sizeof *overlays); \
923 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \ 1102 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
924 nextp, NULL, chrq); \ 1103 nextp, NULL, chrq); \
925 } \ 1104 } \
926 } while (0) 1105 } while (0)
927 1106
928EXFUN (Fbuffer_live_p, 1);
929EXFUN (Fbuffer_name, 1);
930EXFUN (Fnext_overlay_change, 1);
931EXFUN (Fbuffer_local_value, 2);
932
933extern Lisp_Object Qbefore_change_functions; 1107extern Lisp_Object Qbefore_change_functions;
934extern Lisp_Object Qafter_change_functions; 1108extern Lisp_Object Qafter_change_functions;
935extern Lisp_Object Qfirst_change_hook; 1109extern Lisp_Object Qfirst_change_hook;
936 1110
937 1111/* Get text properties of B. */
938/* Overlays */
939 1112
940/* 1 if the OV is an overlay object. */ 1113BUFFER_INLINE INTERVAL
1114buffer_intervals (struct buffer *b)
1115{
1116 eassert (b->text != NULL);
1117 return b->text->intervals;
1118}
1119
1120/* Set text properties of B to I. */
1121
1122BUFFER_INLINE void
1123set_buffer_intervals (struct buffer *b, INTERVAL i)
1124{
1125 eassert (b->text != NULL);
1126 b->text->intervals = i;
1127}
1128
1129/* Non-zero if current buffer has overlays. */
1130
1131BUFFER_INLINE bool
1132buffer_has_overlays (void)
1133{
1134 return current_buffer->overlays_before || current_buffer->overlays_after;
1135}
1136
1137/* Return character code of multi-byte form at byte position POS. If POS
1138 doesn't point the head of valid multi-byte form, only the byte at
1139 POS is returned. No range checking.
1140
1141 WARNING: The character returned by this macro could be "unified"
1142 inside STRING_CHAR, if the original character in the buffer belongs
1143 to one of the Private Use Areas (PUAs) of codepoints that Emacs
1144 uses to support non-unified CJK characters. If that happens,
1145 CHAR_BYTES will return a value that is different from the length of
1146 the original multibyte sequence stored in the buffer. Therefore,
1147 do _not_ use FETCH_MULTIBYTE_CHAR if you need to advance through
1148 the buffer to the next character after fetching this one. Instead,
1149 use either FETCH_CHAR_ADVANCE or STRING_CHAR_AND_LENGTH. */
1150
1151BUFFER_INLINE int
1152FETCH_MULTIBYTE_CHAR (ptrdiff_t pos)
1153{
1154 unsigned char *p = ((pos >= GPT_BYTE ? GAP_SIZE : 0)
1155 + pos + BEG_ADDR - BEG_BYTE);
1156 return STRING_CHAR (p);
1157}
941 1158
942#define OVERLAY_VALID(OV) (OVERLAYP (OV)) 1159/* Return character code of multi-byte form at byte position POS in BUF.
1160 If POS doesn't point the head of valid multi-byte form, only the byte at
1161 POS is returned. No range checking. */
1162
1163BUFFER_INLINE int
1164BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
1165{
1166 unsigned char *p
1167 = ((pos >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0)
1168 + pos + BUF_BEG_ADDR (buf) - BEG_BYTE);
1169 return STRING_CHAR (p);
1170}
1171
1172/* Overlays */
943 1173
944/* Return the marker that stands for where OV starts in the buffer. */ 1174/* Return the marker that stands for where OV starts in the buffer. */
945 1175
946#define OVERLAY_START(OV) (XOVERLAY (OV)->start) 1176#define OVERLAY_START(OV) XOVERLAY (OV)->start
947 1177
948/* Return the marker that stands for where OV ends in the buffer. */ 1178/* Return the marker that stands for where OV ends in the buffer. */
949 1179
950#define OVERLAY_END(OV) (XOVERLAY (OV)->end) 1180#define OVERLAY_END(OV) XOVERLAY (OV)->end
951 1181
952/* Return the plist of overlay OV. */ 1182/* Return the plist of overlay OV. */
953 1183
954#define OVERLAY_PLIST(OV) XOVERLAY ((OV))->plist 1184#define OVERLAY_PLIST(OV) XOVERLAY (OV)->plist
955 1185
956/* Return the actual buffer position for the marker P. 1186/* Return the actual buffer position for the marker P.
957 We assume you know which buffer it's pointing into. */ 1187 We assume you know which buffer it's pointing into. */
958 1188
959#define OVERLAY_POSITION(P) \ 1189#define OVERLAY_POSITION(P) \
960 (MARKERP (P) ? marker_position (P) : (abort (), 0)) 1190 (MARKERP (P) ? marker_position (P) : (emacs_abort (), 0))
961 1191
962 1192
963/*********************************************************************** 1193/***********************************************************************
@@ -972,7 +1202,16 @@ extern int last_per_buffer_idx;
972 from the start of a buffer structure. */ 1202 from the start of a buffer structure. */
973 1203
974#define PER_BUFFER_VAR_OFFSET(VAR) \ 1204#define PER_BUFFER_VAR_OFFSET(VAR) \
975 offsetof (struct buffer, BUFFER_INTERNAL_FIELD (VAR)) 1205 offsetof (struct buffer, INTERNAL_FIELD (VAR))
1206
1207/* Used to iterate over normal Lisp_Object fields of struct buffer (all
1208 Lisp_Objects except undo_list). If you add, remove, or reorder
1209 Lisp_Objects in a struct buffer, make sure that this is still correct. */
1210
1211#define FOR_EACH_PER_BUFFER_OBJECT_AT(offset) \
1212 for (offset = PER_BUFFER_VAR_OFFSET (name); \
1213 offset <= PER_BUFFER_VAR_OFFSET (cursor_in_non_selected_windows); \
1214 offset += word_size)
976 1215
977/* Return the index of buffer-local variable VAR. Each per-buffer 1216/* Return the index of buffer-local variable VAR. Each per-buffer
978 variable has an index > 0 associated with it, except when it always 1217 variable has an index > 0 associated with it, except when it always
@@ -988,7 +1227,7 @@ extern int last_per_buffer_idx;
988 1227
989#define PER_BUFFER_VALUE_P(B, IDX) \ 1228#define PER_BUFFER_VALUE_P(B, IDX) \
990 (((IDX) < 0 || IDX >= last_per_buffer_idx) \ 1229 (((IDX) < 0 || IDX >= last_per_buffer_idx) \
991 ? (abort (), 0) \ 1230 ? (emacs_abort (), 0) \
992 : ((B)->local_flags[IDX] != 0)) 1231 : ((B)->local_flags[IDX] != 0))
993 1232
994/* Set whether per-buffer variable with index IDX has a buffer-local 1233/* Set whether per-buffer variable with index IDX has a buffer-local
@@ -997,7 +1236,7 @@ extern int last_per_buffer_idx;
997#define SET_PER_BUFFER_VALUE_P(B, IDX, VAL) \ 1236#define SET_PER_BUFFER_VALUE_P(B, IDX, VAL) \
998 do { \ 1237 do { \
999 if ((IDX) < 0 || (IDX) >= last_per_buffer_idx) \ 1238 if ((IDX) < 0 || (IDX) >= last_per_buffer_idx) \
1000 abort (); \ 1239 emacs_abort (); \
1001 (B)->local_flags[IDX] = (VAL); \ 1240 (B)->local_flags[IDX] = (VAL); \
1002 } while (0) 1241 } while (0)
1003 1242
@@ -1025,20 +1264,38 @@ extern int last_per_buffer_idx;
1025#define PER_BUFFER_IDX(OFFSET) \ 1264#define PER_BUFFER_IDX(OFFSET) \
1026 XINT (*(Lisp_Object *)((OFFSET) + (char *) &buffer_local_flags)) 1265 XINT (*(Lisp_Object *)((OFFSET) + (char *) &buffer_local_flags))
1027 1266
1028/* Return the default value of the per-buffer variable at offset 1267/* Functions to get and set default value of the per-buffer
1029 OFFSET in the buffer structure. */ 1268 variable at offset OFFSET in the buffer structure. */
1269
1270BUFFER_INLINE Lisp_Object
1271per_buffer_default (int offset)
1272{
1273 return *(Lisp_Object *)(offset + (char *) &buffer_defaults);
1274}
1030 1275
1031#define PER_BUFFER_DEFAULT(OFFSET) \ 1276BUFFER_INLINE void
1032 (*(Lisp_Object *)((OFFSET) + (char *) &buffer_defaults)) 1277set_per_buffer_default (int offset, Lisp_Object value)
1278{
1279 *(Lisp_Object *)(offset + (char *) &buffer_defaults) = value;
1280}
1033 1281
1034/* Return the buffer-local value of the per-buffer variable at offset 1282/* Functions to get and set buffer-local value of the per-buffer
1035 OFFSET in the buffer structure. */ 1283 variable at offset OFFSET in the buffer structure. */
1284
1285BUFFER_INLINE Lisp_Object
1286per_buffer_value (struct buffer *b, int offset)
1287{
1288 return *(Lisp_Object *)(offset + (char *) b);
1289}
1290
1291BUFFER_INLINE void
1292set_per_buffer_value (struct buffer *b, int offset, Lisp_Object value)
1293{
1294 *(Lisp_Object *)(offset + (char *) b) = value;
1295}
1036 1296
1037#define PER_BUFFER_VALUE(BUFFER, OFFSET) \
1038 (*(Lisp_Object *)((OFFSET) + (char *) (BUFFER)))
1039
1040/* Downcase a character C, or make no change if that cannot be done. */ 1297/* Downcase a character C, or make no change if that cannot be done. */
1041static inline int 1298BUFFER_INLINE int
1042downcase (int c) 1299downcase (int c)
1043{ 1300{
1044 Lisp_Object downcase_table = BVAR (current_buffer, downcase_table); 1301 Lisp_Object downcase_table = BVAR (current_buffer, downcase_table);
@@ -1047,10 +1304,10 @@ downcase (int c)
1047} 1304}
1048 1305
1049/* 1 if C is upper case. */ 1306/* 1 if C is upper case. */
1050static inline int uppercasep (int c) { return downcase (c) != c; } 1307BUFFER_INLINE bool uppercasep (int c) { return downcase (c) != c; }
1051 1308
1052/* Upcase a character C known to be not upper case. */ 1309/* Upcase a character C known to be not upper case. */
1053static inline int 1310BUFFER_INLINE int
1054upcase1 (int c) 1311upcase1 (int c)
1055{ 1312{
1056 Lisp_Object upcase_table = BVAR (current_buffer, upcase_table); 1313 Lisp_Object upcase_table = BVAR (current_buffer, upcase_table);
@@ -1059,8 +1316,13 @@ upcase1 (int c)
1059} 1316}
1060 1317
1061/* 1 if C is lower case. */ 1318/* 1 if C is lower case. */
1062static inline int lowercasep (int c) 1319BUFFER_INLINE bool
1063{ return !uppercasep (c) && upcase1 (c) != c; } 1320lowercasep (int c)
1321{
1322 return !uppercasep (c) && upcase1 (c) != c;
1323}
1064 1324
1065/* Upcase a character C, or make no change if that cannot be done. */ 1325/* Upcase a character C, or make no change if that cannot be done. */
1066static inline int upcase (int c) { return uppercasep (c) ? c : upcase1 (c); } 1326BUFFER_INLINE int upcase (int c) { return uppercasep (c) ? c : upcase1 (c); }
1327
1328INLINE_HEADER_END