aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.h
diff options
context:
space:
mode:
authorKenichi Handa2012-07-17 07:25:00 +0900
committerKenichi Handa2012-07-17 07:25:00 +0900
commit69c41c4070c86baac11a627e9c3d366420aeb7cc (patch)
treee07fda92570b5e4f264c9a7869b57960940008f0 /src/buffer.h
parent8c536f15bf95916d56bb50495d22b7da7e09fff9 (diff)
parent758e556a7ab8f61c007e34310ba399a9aaf15362 (diff)
downloademacs-69c41c4070c86baac11a627e9c3d366420aeb7cc.tar.gz
emacs-69c41c4070c86baac11a627e9c3d366420aeb7cc.zip
merge trunk
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h385
1 files changed, 208 insertions, 177 deletions
diff --git a/src/buffer.h b/src/buffer.h
index 3aa4b11c450..0615f85bfe6 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -19,6 +19,7 @@ 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 */
22 23
23/* Accessing the parameters of the current buffer. */ 24/* Accessing the parameters of the current buffer. */
24 25
@@ -355,28 +356,6 @@ while (0)
355 356
356#define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n))) 357#define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n)))
357 358
358/* Variables used locally in FETCH_MULTIBYTE_CHAR. */
359extern unsigned char *_fetch_multibyte_char_p;
360
361/* Return character code of multi-byte form at byte position POS. If POS
362 doesn't point the head of valid multi-byte form, only the byte at
363 POS is returned. No range checking.
364
365 WARNING: The character returned by this macro could be "unified"
366 inside STRING_CHAR, if the original character in the buffer belongs
367 to one of the Private Use Areas (PUAs) of codepoints that Emacs
368 uses to support non-unified CJK characters. If that happens,
369 CHAR_BYTES will return a value that is different from the length of
370 the original multibyte sequence stored in the buffer. Therefore,
371 do _not_ use FETCH_MULTIBYTE_CHAR if you need to advance through
372 the buffer to the next character after fetching this one. Instead,
373 use either FETCH_CHAR_ADVANCE or STRING_CHAR_AND_LENGTH. */
374
375#define FETCH_MULTIBYTE_CHAR(pos) \
376 (_fetch_multibyte_char_p = (((pos) >= GPT_BYTE ? GAP_SIZE : 0) \
377 + (pos) + BEG_ADDR - BEG_BYTE), \
378 STRING_CHAR (_fetch_multibyte_char_p))
379
380/* Return character at byte position POS. If the current buffer is unibyte 359/* Return character at byte position POS. If the current buffer is unibyte
381 and the character is not ASCII, make the returning character 360 and the character is not ASCII, make the returning character
382 multibyte. */ 361 multibyte. */
@@ -425,16 +404,6 @@ extern unsigned char *_fetch_multibyte_char_p;
425 404
426#define BUF_FETCH_BYTE(buf, n) \ 405#define BUF_FETCH_BYTE(buf, n) \
427 *(BUF_BYTE_ADDRESS ((buf), (n))) 406 *(BUF_BYTE_ADDRESS ((buf), (n)))
428
429/* Return character code of multi-byte form at byte position POS in BUF.
430 If POS doesn't point the head of valid multi-byte form, only the byte at
431 POS is returned. No range checking. */
432
433#define BUF_FETCH_MULTIBYTE_CHAR(buf, pos) \
434 (_fetch_multibyte_char_p \
435 = (((pos) >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0) \
436 + (pos) + BUF_BEG_ADDR (buf) - BEG_BYTE), \
437 STRING_CHAR (_fetch_multibyte_char_p))
438 407
439/* Define the actual buffer data structures. */ 408/* Define the actual buffer data structures. */
440 409
@@ -513,139 +482,26 @@ struct buffer_text
513 482
514struct buffer 483struct buffer
515{ 484{
516 /* Everything before the `name' slot must be of a non-Lisp_Object type, 485 /* HEADER.NEXT is the next buffer, in chain of all buffers, including killed
517 and every slot after `name' must be a Lisp_Object. 486 buffers. This chain, starting from all_buffers, is used only for garbage
518 487 collection, in order to collect killed buffers properly. Note that large
519 Check out mark_buffer (alloc.c) to see why. */ 488 vectors and large pseudo-vector objects are all on another chain starting
520 489 from large_vectors. */
521 /* HEADER.NEXT is the next buffer, in chain of all buffers,
522 including killed buffers.
523 This chain is used only for garbage collection, in order to
524 collect killed buffers properly.
525 Note that vectors and most pseudovectors are all on one chain,
526 but buffers are on a separate chain of their own. */
527 struct vectorlike_header header; 490 struct vectorlike_header header;
528 491
529 /* This structure holds the coordinates of the buffer contents
530 in ordinary buffers. In indirect buffers, this is not used. */
531 struct buffer_text own_text;
532
533 /* This points to the `struct buffer_text' that used for this buffer.
534 In an ordinary buffer, this is the own_text field above.
535 In an indirect buffer, this is the own_text field of another buffer. */
536 struct buffer_text *text;
537
538 /* Char position of point in buffer. */
539 ptrdiff_t pt;
540 /* Byte position of point in buffer. */
541 ptrdiff_t pt_byte;
542 /* Char position of beginning of accessible range. */
543 ptrdiff_t begv;
544 /* Byte position of beginning of accessible range. */
545 ptrdiff_t begv_byte;
546 /* Char position of end of accessible range. */
547 ptrdiff_t zv;
548 /* Byte position of end of accessible range. */
549 ptrdiff_t zv_byte;
550
551 /* In an indirect buffer, this points to the base buffer.
552 In an ordinary buffer, it is 0. */
553 struct buffer *base_buffer;
554
555 /* A non-zero value in slot IDX means that per-buffer variable
556 with index IDX has a local value in this buffer. The index IDX
557 for a buffer-local variable is stored in that variable's slot
558 in buffer_local_flags as a Lisp integer. If the index is -1,
559 this means the variable is always local in all buffers. */
560#define MAX_PER_BUFFER_VARS 50
561 char local_flags[MAX_PER_BUFFER_VARS];
562
563 /* Set to the modtime of the visited file when read or written.
564 -1 means visited file was nonexistent.
565 0 means visited file modtime unknown; in no case complain
566 about any mismatch on next save attempt. */
567 time_t modtime;
568 /* Size of the file when modtime was set. This is used to detect the
569 case where the file grew while we were reading it, so the modtime
570 is still the same (since it's rounded up to seconds) but we're actually
571 not up-to-date. -1 means the size is unknown. Only meaningful if
572 modtime is actually set. */
573 off_t modtime_size;
574 /* The value of text->modiff at the last auto-save. */
575 EMACS_INT auto_save_modified;
576 /* The value of text->modiff at the last display error.
577 Redisplay of this buffer is inhibited until it changes again. */
578 EMACS_INT display_error_modiff;
579 /* The time at which we detected a failure to auto-save,
580 Or 0 if we didn't have a failure. */
581 time_t auto_save_failure_time;
582 /* Position in buffer at which display started
583 the last time this buffer was displayed. */
584 ptrdiff_t last_window_start;
585
586 /* Set nonzero whenever the narrowing is changed in this buffer. */
587 int clip_changed;
588
589 /* If the long line scan cache is enabled (i.e. the buffer-local
590 variable cache-long-line-scans is non-nil), newline_cache
591 points to the newline cache, and width_run_cache points to the
592 width run cache.
593
594 The newline cache records which stretches of the buffer are
595 known *not* to contain newlines, so that they can be skipped
596 quickly when we search for newlines.
597
598 The width run cache records which stretches of the buffer are
599 known to contain characters whose widths are all the same. If
600 the width run cache maps a character to a value > 0, that value is
601 the character's width; if it maps a character to zero, we don't
602 know what its width is. This allows compute_motion to process
603 such regions very quickly, using algebra instead of inspecting
604 each character. See also width_table, below. */
605 struct region_cache *newline_cache;
606 struct region_cache *width_run_cache;
607
608 /* Non-zero means don't use redisplay optimizations for
609 displaying this buffer. */
610 unsigned prevent_redisplay_optimizations_p : 1;
611
612 /* List of overlays that end at or before the current center,
613 in order of end-position. */
614 struct Lisp_Overlay *overlays_before;
615
616 /* List of overlays that end after the current center,
617 in order of start-position. */
618 struct Lisp_Overlay *overlays_after;
619
620 /* Position where the overlay lists are centered. */
621 ptrdiff_t overlay_center;
622
623 /* Everything from here down must be a Lisp_Object. */
624 /* buffer-local Lisp variables start at `undo_list',
625 tho only the ones from `name' on are GC'd normally. */
626 #define FIRST_FIELD_PER_BUFFER undo_list
627
628 /* Changes in the buffer are recorded here for undo.
629 t means don't record anything.
630 This information belongs to the base buffer of an indirect buffer,
631 But we can't store it in the struct buffer_text
632 because local variables have to be right in the struct buffer.
633 So we copy it around in set_buffer_internal.
634 This comes before `name' because it is marked in a special way. */
635 Lisp_Object BUFFER_INTERNAL_FIELD (undo_list);
636
637 /* The name of this buffer. */ 492 /* The name of this buffer. */
638 Lisp_Object BUFFER_INTERNAL_FIELD (name); 493 Lisp_Object BUFFER_INTERNAL_FIELD (name);
639 494
640 /* The name of the file visited in this buffer, or nil. */ 495 /* The name of the file visited in this buffer, or nil. */
641 Lisp_Object BUFFER_INTERNAL_FIELD (filename); 496 Lisp_Object BUFFER_INTERNAL_FIELD (filename);
642 /* Dir for expanding relative file names. */ 497
498 /* Directory for expanding relative file names. */
643 Lisp_Object BUFFER_INTERNAL_FIELD (directory); 499 Lisp_Object BUFFER_INTERNAL_FIELD (directory);
644 /* True if this buffer has been backed up (if you write to the 500
645 visited file and it hasn't been backed up, then a backup will 501 /* True if this buffer has been backed up (if you write to the visited
646 be made). */ 502 file and it hasn't been backed up, then a backup will be made). */
647 /* This isn't really used by the C code, so could be deleted. */
648 Lisp_Object BUFFER_INTERNAL_FIELD (backed_up); 503 Lisp_Object BUFFER_INTERNAL_FIELD (backed_up);
504
649 /* Length of file when last read or saved. 505 /* Length of file when last read or saved.
650 -1 means auto saving turned off because buffer shrank a lot. 506 -1 means auto saving turned off because buffer shrank a lot.
651 -2 means don't turn off auto saving if buffer shrinks. 507 -2 means don't turn off auto saving if buffer shrinks.
@@ -653,6 +509,7 @@ struct buffer
653 This is not in the struct buffer_text 509 This is not in the struct buffer_text
654 because it's not used in indirect buffers at all. */ 510 because it's not used in indirect buffers at all. */
655 Lisp_Object BUFFER_INTERNAL_FIELD (save_length); 511 Lisp_Object BUFFER_INTERNAL_FIELD (save_length);
512
656 /* File name used for auto-saving this buffer. 513 /* File name used for auto-saving this buffer.
657 This is not in the struct buffer_text 514 This is not in the struct buffer_text
658 because it's not used in indirect buffers at all. */ 515 because it's not used in indirect buffers at all. */
@@ -660,6 +517,7 @@ struct buffer
660 517
661 /* Non-nil if buffer read-only. */ 518 /* Non-nil if buffer read-only. */
662 Lisp_Object BUFFER_INTERNAL_FIELD (read_only); 519 Lisp_Object BUFFER_INTERNAL_FIELD (read_only);
520
663 /* "The mark". This is a marker which may 521 /* "The mark". This is a marker which may
664 point into this buffer or may point nowhere. */ 522 point into this buffer or may point nowhere. */
665 Lisp_Object BUFFER_INTERNAL_FIELD (mark); 523 Lisp_Object BUFFER_INTERNAL_FIELD (mark);
@@ -669,10 +527,12 @@ struct buffer
669 symbols, just the symbol appears as the element. */ 527 symbols, just the symbol appears as the element. */
670 Lisp_Object BUFFER_INTERNAL_FIELD (local_var_alist); 528 Lisp_Object BUFFER_INTERNAL_FIELD (local_var_alist);
671 529
672 /* Symbol naming major mode (eg, lisp-mode). */ 530 /* Symbol naming major mode (e.g., lisp-mode). */
673 Lisp_Object BUFFER_INTERNAL_FIELD (major_mode); 531 Lisp_Object BUFFER_INTERNAL_FIELD (major_mode);
674 /* Pretty name of major mode (eg, "Lisp"). */ 532
533 /* Pretty name of major mode (e.g., "Lisp"). */
675 Lisp_Object BUFFER_INTERNAL_FIELD (mode_name); 534 Lisp_Object BUFFER_INTERNAL_FIELD (mode_name);
535
676 /* Mode line element that controls format of mode line. */ 536 /* Mode line element that controls format of mode line. */
677 Lisp_Object BUFFER_INTERNAL_FIELD (mode_line_format); 537 Lisp_Object BUFFER_INTERNAL_FIELD (mode_line_format);
678 538
@@ -682,10 +542,13 @@ struct buffer
682 542
683 /* Keys that are bound local to this buffer. */ 543 /* Keys that are bound local to this buffer. */
684 Lisp_Object BUFFER_INTERNAL_FIELD (keymap); 544 Lisp_Object BUFFER_INTERNAL_FIELD (keymap);
545
685 /* This buffer's local abbrev table. */ 546 /* This buffer's local abbrev table. */
686 Lisp_Object BUFFER_INTERNAL_FIELD (abbrev_table); 547 Lisp_Object BUFFER_INTERNAL_FIELD (abbrev_table);
548
687 /* This buffer's syntax table. */ 549 /* This buffer's syntax table. */
688 Lisp_Object BUFFER_INTERNAL_FIELD (syntax_table); 550 Lisp_Object BUFFER_INTERNAL_FIELD (syntax_table);
551
689 /* This buffer's category table. */ 552 /* This buffer's category table. */
690 Lisp_Object BUFFER_INTERNAL_FIELD (category_table); 553 Lisp_Object BUFFER_INTERNAL_FIELD (category_table);
691 554
@@ -696,48 +559,61 @@ struct buffer
696 Lisp_Object BUFFER_INTERNAL_FIELD (tab_width); 559 Lisp_Object BUFFER_INTERNAL_FIELD (tab_width);
697 Lisp_Object BUFFER_INTERNAL_FIELD (fill_column); 560 Lisp_Object BUFFER_INTERNAL_FIELD (fill_column);
698 Lisp_Object BUFFER_INTERNAL_FIELD (left_margin); 561 Lisp_Object BUFFER_INTERNAL_FIELD (left_margin);
562
699 /* Function to call when insert space past fill column. */ 563 /* Function to call when insert space past fill column. */
700 Lisp_Object BUFFER_INTERNAL_FIELD (auto_fill_function); 564 Lisp_Object BUFFER_INTERNAL_FIELD (auto_fill_function);
701 565
702 /* Case table for case-conversion in this buffer. 566 /* Case table for case-conversion in this buffer.
703 This char-table maps each char into its lower-case version. */ 567 This char-table maps each char into its lower-case version. */
704 Lisp_Object BUFFER_INTERNAL_FIELD (downcase_table); 568 Lisp_Object BUFFER_INTERNAL_FIELD (downcase_table);
569
705 /* Char-table mapping each char to its upper-case version. */ 570 /* Char-table mapping each char to its upper-case version. */
706 Lisp_Object BUFFER_INTERNAL_FIELD (upcase_table); 571 Lisp_Object BUFFER_INTERNAL_FIELD (upcase_table);
572
707 /* Char-table for conversion for case-folding search. */ 573 /* Char-table for conversion for case-folding search. */
708 Lisp_Object BUFFER_INTERNAL_FIELD (case_canon_table); 574 Lisp_Object BUFFER_INTERNAL_FIELD (case_canon_table);
575
709 /* Char-table of equivalences for case-folding search. */ 576 /* Char-table of equivalences for case-folding search. */
710 Lisp_Object BUFFER_INTERNAL_FIELD (case_eqv_table); 577 Lisp_Object BUFFER_INTERNAL_FIELD (case_eqv_table);
711 578
712 /* Non-nil means do not display continuation lines. */ 579 /* Non-nil means do not display continuation lines. */
713 Lisp_Object BUFFER_INTERNAL_FIELD (truncate_lines); 580 Lisp_Object BUFFER_INTERNAL_FIELD (truncate_lines);
581
714 /* Non-nil means to use word wrapping when displaying continuation lines. */ 582 /* Non-nil means to use word wrapping when displaying continuation lines. */
715 Lisp_Object BUFFER_INTERNAL_FIELD (word_wrap); 583 Lisp_Object BUFFER_INTERNAL_FIELD (word_wrap);
584
716 /* Non-nil means display ctl chars with uparrow. */ 585 /* Non-nil means display ctl chars with uparrow. */
717 Lisp_Object BUFFER_INTERNAL_FIELD (ctl_arrow); 586 Lisp_Object BUFFER_INTERNAL_FIELD (ctl_arrow);
587
718 /* Non-nil means reorder bidirectional text for display in the 588 /* Non-nil means reorder bidirectional text for display in the
719 visual order. */ 589 visual order. */
720 Lisp_Object BUFFER_INTERNAL_FIELD (bidi_display_reordering); 590 Lisp_Object BUFFER_INTERNAL_FIELD (bidi_display_reordering);
591
721 /* If non-nil, specifies which direction of text to force in all the 592 /* If non-nil, specifies which direction of text to force in all the
722 paragraphs of the buffer. Nil means determine paragraph 593 paragraphs of the buffer. Nil means determine paragraph
723 direction dynamically for each paragraph. */ 594 direction dynamically for each paragraph. */
724 Lisp_Object BUFFER_INTERNAL_FIELD (bidi_paragraph_direction); 595 Lisp_Object BUFFER_INTERNAL_FIELD (bidi_paragraph_direction);
596
725 /* Non-nil means do selective display; 597 /* Non-nil means do selective display;
726 see doc string in syms_of_buffer (buffer.c) for details. */ 598 see doc string in syms_of_buffer (buffer.c) for details. */
727 Lisp_Object BUFFER_INTERNAL_FIELD (selective_display); 599 Lisp_Object BUFFER_INTERNAL_FIELD (selective_display);
728#ifndef old 600
729 /* Non-nil means show ... at end of line followed by invisible lines. */ 601 /* Non-nil means show ... at end of line followed by invisible lines. */
730 Lisp_Object BUFFER_INTERNAL_FIELD (selective_display_ellipses); 602 Lisp_Object BUFFER_INTERNAL_FIELD (selective_display_ellipses);
731#endif 603
732 /* Alist of (FUNCTION . STRING) for each minor mode enabled in buffer. */ 604 /* Alist of (FUNCTION . STRING) for each minor mode enabled in buffer. */
733 Lisp_Object BUFFER_INTERNAL_FIELD (minor_modes); 605 Lisp_Object BUFFER_INTERNAL_FIELD (minor_modes);
606
734 /* t if "self-insertion" should overwrite; `binary' if it should also 607 /* t if "self-insertion" should overwrite; `binary' if it should also
735 overwrite newlines and tabs - for editing executables and the like. */ 608 overwrite newlines and tabs - for editing executables and the like. */
736 Lisp_Object BUFFER_INTERNAL_FIELD (overwrite_mode); 609 Lisp_Object BUFFER_INTERNAL_FIELD (overwrite_mode);
737 /* non-nil means abbrev mode is on. Expand abbrevs automatically. */ 610
611 /* Non-nil means abbrev mode is on. Expand abbrevs automatically. */
738 Lisp_Object BUFFER_INTERNAL_FIELD (abbrev_mode); 612 Lisp_Object BUFFER_INTERNAL_FIELD (abbrev_mode);
613
739 /* Display table to use for text in this buffer. */ 614 /* Display table to use for text in this buffer. */
740 Lisp_Object BUFFER_INTERNAL_FIELD (display_table); 615 Lisp_Object BUFFER_INTERNAL_FIELD (display_table);
616
741 /* t means the mark and region are currently active. */ 617 /* t means the mark and region are currently active. */
742 Lisp_Object BUFFER_INTERNAL_FIELD (mark_active); 618 Lisp_Object BUFFER_INTERNAL_FIELD (mark_active);
743 619
@@ -804,11 +680,13 @@ struct buffer
804 680
805 /* Widths of left and right marginal areas for windows displaying 681 /* Widths of left and right marginal areas for windows displaying
806 this buffer. */ 682 this buffer. */
807 Lisp_Object BUFFER_INTERNAL_FIELD (left_margin_cols), BUFFER_INTERNAL_FIELD (right_margin_cols); 683 Lisp_Object BUFFER_INTERNAL_FIELD (left_margin_cols);
684 Lisp_Object BUFFER_INTERNAL_FIELD (right_margin_cols);
808 685
809 /* Widths of left and right fringe areas for windows displaying 686 /* Widths of left and right fringe areas for windows displaying
810 this buffer. */ 687 this buffer. */
811 Lisp_Object BUFFER_INTERNAL_FIELD (left_fringe_width), BUFFER_INTERNAL_FIELD (right_fringe_width); 688 Lisp_Object BUFFER_INTERNAL_FIELD (left_fringe_width);
689 Lisp_Object BUFFER_INTERNAL_FIELD (right_fringe_width);
812 690
813 /* Non-nil means fringes are drawn outside display margins; 691 /* Non-nil means fringes are drawn outside display margins;
814 othersize draw them between margin areas and text. */ 692 othersize draw them between margin areas and text. */
@@ -816,7 +694,8 @@ struct buffer
816 694
817 /* Width and type of scroll bar areas for windows displaying 695 /* Width and type of scroll bar areas for windows displaying
818 this buffer. */ 696 this buffer. */
819 Lisp_Object BUFFER_INTERNAL_FIELD (scroll_bar_width), BUFFER_INTERNAL_FIELD (vertical_scroll_bar_type); 697 Lisp_Object BUFFER_INTERNAL_FIELD (scroll_bar_width);
698 Lisp_Object BUFFER_INTERNAL_FIELD (vertical_scroll_bar_type);
820 699
821 /* Non-nil means indicate lines not displaying text (in a style 700 /* Non-nil means indicate lines not displaying text (in a style
822 like vi). */ 701 like vi). */
@@ -854,13 +733,127 @@ struct buffer
854 in the display of this buffer. */ 733 in the display of this buffer. */
855 Lisp_Object BUFFER_INTERNAL_FIELD (extra_line_spacing); 734 Lisp_Object BUFFER_INTERNAL_FIELD (extra_line_spacing);
856 735
857 /* *Cursor type to display in non-selected windows. 736 /* Cursor type to display in non-selected windows.
858 t means to use hollow box cursor. 737 t means to use hollow box cursor.
859 See `cursor-type' for other values. */ 738 See `cursor-type' for other values. */
860 Lisp_Object BUFFER_INTERNAL_FIELD (cursor_in_non_selected_windows); 739 Lisp_Object BUFFER_INTERNAL_FIELD (cursor_in_non_selected_windows);
861 740
862 /* This must be the last field in the above list. */ 741 /* No more Lisp_Object beyond this point. Except undo_list,
863 #define LAST_FIELD_PER_BUFFER cursor_in_non_selected_windows 742 which is handled specially in Fgarbage_collect . */
743
744 /* This structure holds the coordinates of the buffer contents
745 in ordinary buffers. In indirect buffers, this is not used. */
746 struct buffer_text own_text;
747
748 /* This points to the `struct buffer_text' that used for this buffer.
749 In an ordinary buffer, this is the own_text field above.
750 In an indirect buffer, this is the own_text field of another buffer. */
751 struct buffer_text *text;
752
753 /* Char position of point in buffer. */
754 ptrdiff_t pt;
755
756 /* Byte position of point in buffer. */
757 ptrdiff_t pt_byte;
758
759 /* Char position of beginning of accessible range. */
760 ptrdiff_t begv;
761
762 /* Byte position of beginning of accessible range. */
763 ptrdiff_t begv_byte;
764
765 /* Char position of end of accessible range. */
766 ptrdiff_t zv;
767
768 /* Byte position of end of accessible range. */
769 ptrdiff_t zv_byte;
770
771 /* In an indirect buffer, this points to the base buffer.
772 In an ordinary buffer, it is 0. */
773 struct buffer *base_buffer;
774
775 /* A non-zero value in slot IDX means that per-buffer variable
776 with index IDX has a local value in this buffer. The index IDX
777 for a buffer-local variable is stored in that variable's slot
778 in buffer_local_flags as a Lisp integer. If the index is -1,
779 this means the variable is always local in all buffers. */
780#define MAX_PER_BUFFER_VARS 50
781 char local_flags[MAX_PER_BUFFER_VARS];
782
783 /* Set to the modtime of the visited file when read or written.
784 EMACS_NSECS (modtime) == NONEXISTENT_MODTIME_NSECS means
785 visited file was nonexistent. EMACS_NSECS (modtime) ==
786 UNKNOWN_MODTIME_NSECS means visited file modtime unknown;
787 in no case complain about any mismatch on next save attempt. */
788#define NONEXISTENT_MODTIME_NSECS (-1)
789#define UNKNOWN_MODTIME_NSECS (-2)
790 EMACS_TIME modtime;
791
792 /* Size of the file when modtime was set. This is used to detect the
793 case where the file grew while we were reading it, so the modtime
794 is still the same (since it's rounded up to seconds) but we're actually
795 not up-to-date. -1 means the size is unknown. Only meaningful if
796 modtime is actually set. */
797 off_t modtime_size;
798
799 /* The value of text->modiff at the last auto-save. */
800 EMACS_INT auto_save_modified;
801
802 /* The value of text->modiff at the last display error.
803 Redisplay of this buffer is inhibited until it changes again. */
804 EMACS_INT display_error_modiff;
805
806 /* The time at which we detected a failure to auto-save,
807 Or 0 if we didn't have a failure. */
808 time_t auto_save_failure_time;
809
810 /* Position in buffer at which display started
811 the last time this buffer was displayed. */
812 ptrdiff_t last_window_start;
813
814 /* If the long line scan cache is enabled (i.e. the buffer-local
815 variable cache-long-line-scans is non-nil), newline_cache
816 points to the newline cache, and width_run_cache points to the
817 width run cache.
818
819 The newline cache records which stretches of the buffer are
820 known *not* to contain newlines, so that they can be skipped
821 quickly when we search for newlines.
822
823 The width run cache records which stretches of the buffer are
824 known to contain characters whose widths are all the same. If
825 the width run cache maps a character to a value > 0, that value is
826 the character's width; if it maps a character to zero, we don't
827 know what its width is. This allows compute_motion to process
828 such regions very quickly, using algebra instead of inspecting
829 each character. See also width_table, below. */
830 struct region_cache *newline_cache;
831 struct region_cache *width_run_cache;
832
833 /* Non-zero means don't use redisplay optimizations for
834 displaying this buffer. */
835 unsigned prevent_redisplay_optimizations_p : 1;
836
837 /* Non-zero whenever the narrowing is changed in this buffer. */
838 unsigned clip_changed : 1;
839
840 /* List of overlays that end at or before the current center,
841 in order of end-position. */
842 struct Lisp_Overlay *overlays_before;
843
844 /* List of overlays that end after the current center,
845 in order of start-position. */
846 struct Lisp_Overlay *overlays_after;
847
848 /* Position where the overlay lists are centered. */
849 ptrdiff_t overlay_center;
850
851 /* Changes in the buffer are recorded here for undo, and t means
852 don't record anything. This information belongs to the base
853 buffer of an indirect buffer. But we can't store it in the
854 struct buffer_text because local variables have to be right in
855 the struct buffer. So we copy it around in set_buffer_internal. */
856 Lisp_Object BUFFER_INTERNAL_FIELD (undo_list);
864}; 857};
865 858
866 859
@@ -914,7 +907,7 @@ extern void set_buffer_internal_1 (struct buffer *);
914extern void set_buffer_temp (struct buffer *); 907extern void set_buffer_temp (struct buffer *);
915extern Lisp_Object buffer_local_value_1 (Lisp_Object, Lisp_Object); 908extern Lisp_Object buffer_local_value_1 (Lisp_Object, Lisp_Object);
916extern void record_buffer (Lisp_Object); 909extern void record_buffer (Lisp_Object);
917extern void buffer_slot_type_mismatch (Lisp_Object, int) NO_RETURN; 910extern _Noreturn void buffer_slot_type_mismatch (Lisp_Object, int);
918extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t); 911extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
919extern void mmap_set_vars (int); 912extern void mmap_set_vars (int);
920 913
@@ -924,28 +917,57 @@ extern void mmap_set_vars (int);
924 917
925#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \ 918#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \
926 do { \ 919 do { \
927 ptrdiff_t maxlen = 40; \ 920 ptrdiff_t maxlen = 40; \
928 overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \ 921 overlays = alloca (maxlen * sizeof *overlays); \
929 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \ 922 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
930 nextp, NULL, chrq); \ 923 nextp, NULL, chrq); \
931 if (noverlays > maxlen) \ 924 if (noverlays > maxlen) \
932 { \ 925 { \
933 maxlen = noverlays; \ 926 maxlen = noverlays; \
934 overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \ 927 overlays = alloca (maxlen * sizeof *overlays); \
935 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \ 928 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
936 nextp, NULL, chrq); \ 929 nextp, NULL, chrq); \
937 } \ 930 } \
938 } while (0) 931 } while (0)
939 932
940EXFUN (Fbuffer_live_p, 1);
941EXFUN (Fbuffer_name, 1);
942EXFUN (Fnext_overlay_change, 1);
943EXFUN (Fbuffer_local_value, 2);
944
945extern Lisp_Object Qbefore_change_functions; 933extern Lisp_Object Qbefore_change_functions;
946extern Lisp_Object Qafter_change_functions; 934extern Lisp_Object Qafter_change_functions;
947extern Lisp_Object Qfirst_change_hook; 935extern Lisp_Object Qfirst_change_hook;
936
937/* Return character code of multi-byte form at byte position POS. If POS
938 doesn't point the head of valid multi-byte form, only the byte at
939 POS is returned. No range checking.
948 940
941 WARNING: The character returned by this macro could be "unified"
942 inside STRING_CHAR, if the original character in the buffer belongs
943 to one of the Private Use Areas (PUAs) of codepoints that Emacs
944 uses to support non-unified CJK characters. If that happens,
945 CHAR_BYTES will return a value that is different from the length of
946 the original multibyte sequence stored in the buffer. Therefore,
947 do _not_ use FETCH_MULTIBYTE_CHAR if you need to advance through
948 the buffer to the next character after fetching this one. Instead,
949 use either FETCH_CHAR_ADVANCE or STRING_CHAR_AND_LENGTH. */
950
951static inline int
952FETCH_MULTIBYTE_CHAR (ptrdiff_t pos)
953{
954 unsigned char *p = ((pos >= GPT_BYTE ? GAP_SIZE : 0)
955 + pos + BEG_ADDR - BEG_BYTE);
956 return STRING_CHAR (p);
957}
958
959/* Return character code of multi-byte form at byte position POS in BUF.
960 If POS doesn't point the head of valid multi-byte form, only the byte at
961 POS is returned. No range checking. */
962
963static inline int
964BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
965{
966 unsigned char *p
967 = ((pos >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0)
968 + pos + BUF_BEG_ADDR (buf) - BEG_BYTE);
969 return STRING_CHAR (p);
970}
949 971
950/* Overlays */ 972/* Overlays */
951 973
@@ -986,6 +1008,15 @@ extern int last_per_buffer_idx;
986#define PER_BUFFER_VAR_OFFSET(VAR) \ 1008#define PER_BUFFER_VAR_OFFSET(VAR) \
987 offsetof (struct buffer, BUFFER_INTERNAL_FIELD (VAR)) 1009 offsetof (struct buffer, BUFFER_INTERNAL_FIELD (VAR))
988 1010
1011/* Used to iterate over normal Lisp_Object fields of struct buffer (all
1012 Lisp_Objects except undo_list). If you add, remove, or reorder
1013 Lisp_Objects in a struct buffer, make sure that this is still correct. */
1014
1015#define for_each_per_buffer_object_at(offset) \
1016 for (offset = PER_BUFFER_VAR_OFFSET (name); \
1017 offset <= PER_BUFFER_VAR_OFFSET (cursor_in_non_selected_windows); \
1018 offset += sizeof (Lisp_Object))
1019
989/* Return the index of buffer-local variable VAR. Each per-buffer 1020/* Return the index of buffer-local variable VAR. Each per-buffer
990 variable has an index > 0 associated with it, except when it always 1021 variable has an index > 0 associated with it, except when it always
991 has buffer-local values, in which case the index is -1. If this is 1022 has buffer-local values, in which case the index is -1. If this is