This source file includes following definitions.
- SET_PT
- TEMP_SET_PT
- SET_PT_BOTH
- TEMP_SET_PT_BOTH
- BUF_TEMP_SET_PT
- BUFFERP
- CHECK_BUFFER
- XBUFFER
- bset_bidi_paragraph_direction
- bset_cache_long_scans
- bset_case_canon_table
- bset_case_eqv_table
- bset_directory
- bset_display_count
- bset_left_margin_cols
- bset_right_margin_cols
- bset_display_time
- bset_downcase_table
- bset_enable_multibyte_characters
- bset_filename
- bset_keymap
- bset_last_selected_window
- bset_local_var_alist
- bset_mark_active
- bset_point_before_scroll
- bset_read_only
- bset_truncate_lines
- bset_undo_list
- bset_upcase_table
- bset_width_table
- bset_text_conversion_style
- BUFFER_CEILING_OF
- BUFFER_FLOOR_OF
- BUF_BEGV
- BUF_BEGV_BYTE
- BUF_PT
- BUF_PT_BYTE
- BUF_ZV
- BUF_ZV_BYTE
- BUF_BEG
- BUF_BEG_BYTE
- BUF_GPT_ADDR
- BUF_Z_ADDR
- BUF_GAP_END_ADDR
- BUF_COMPUTE_UNCHANGED
- SET_BUF_BEGV
- SET_BUF_ZV
- SET_BUF_BEGV_BOTH
- SET_BUF_ZV_BOTH
- SET_BUF_PT_BOTH
- BYTE_POS_ADDR
- CHAR_POS_ADDR
- CHAR_TO_BYTE
- BYTE_TO_CHAR
- PTR_BYTE_POS
- BUFFER_PVEC_INIT
- BUFFER_LIVE_P
- BUFFER_HIDDEN_P
- BUFFER_CHECK_INDIRECTION
- decode_buffer
- set_buffer_internal
- record_unwind_current_buffer
- buffer_intervals
- set_buffer_intervals
- buffer_has_overlays
- FETCH_MULTIBYTE_CHAR
- BUF_FETCH_MULTIBYTE_CHAR
- FETCH_CHAR_AS_MULTIBYTE
- FETCH_CHAR
- BUF_BYTE_ADDRESS
- BUF_CHAR_ADDRESS
- BUF_PTR_BYTE_POS
- BUF_FETCH_BYTE
- BUF_FETCH_CHAR_AS_MULTIBYTE
- buffer_window_count
- overlay_start
- overlay_end
- OVERLAY_START
- OVERLAY_END
- OVERLAY_PLIST
- OVERLAY_BUFFER
- OVERLAY_REAR_ADVANCE_P
- OVERLAY_FRONT_ADVANCE_P
- PER_BUFFER_VALUE_P
- SET_PER_BUFFER_VALUE_P
- PER_BUFFER_IDX
- per_buffer_default
- set_per_buffer_default
- per_buffer_value
- set_per_buffer_value
- downcase
- upcase
- uppercasep
- lowercasep
- sanitize_tab_width
- SANE_TAB_WIDTH
- sanitize_char_width
- CHARACTER_WIDTH
- fetch_char_advance
- fetch_char_advance_no_check
- buf_next_char_len
- next_char_len
- buf_prev_char_len
- prev_char_len
- inc_both
- dec_both
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #ifndef EMACS_BUFFER_H
21 #define EMACS_BUFFER_H
22
23 #include <sys/types.h>
24 #include <time.h>
25
26 #include "character.h"
27 #include "lisp.h"
28 #include "itree.h"
29
30 INLINE_HEADER_BEGIN
31
32
33
34
35
36
37
38 enum { BEG = 1, BEG_BYTE = BEG };
39
40
41 #define BEGV (current_buffer->begv)
42 #define BEGV_BYTE (current_buffer->begv_byte)
43
44
45
46 #define PT (current_buffer->pt + 0)
47 #define PT_BYTE (current_buffer->pt_byte + 0)
48
49
50 #define GPT (current_buffer->text->gpt)
51 #define GPT_BYTE (current_buffer->text->gpt_byte)
52
53
54 #define ZV (current_buffer->zv)
55 #define ZV_BYTE (current_buffer->zv_byte)
56
57
58 #define Z (current_buffer->text->z)
59 #define Z_BYTE (current_buffer->text->z_byte)
60
61
62
63
64
65
66
67
68
69
70
71
72 #define BEG_ADDR (current_buffer->text->beg)
73
74
75 #define BEGV_ADDR (BYTE_POS_ADDR (current_buffer->begv_byte))
76
77
78 #define PT_ADDR (BYTE_POS_ADDR (current_buffer->pt_byte))
79
80
81 #define GPT_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte - BEG_BYTE)
82
83
84 #define GAP_END_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte + current_buffer->text->gap_size - BEG_BYTE)
85
86
87 #define ZV_ADDR (BYTE_POS_ADDR (current_buffer->zv_byte))
88
89
90 #define Z_ADDR (current_buffer->text->beg + current_buffer->text->gap_size + current_buffer->text->z_byte - BEG_BYTE)
91
92
93 #define GAP_SIZE (current_buffer->text->gap_size)
94
95
96 #define MODIFF (current_buffer->text->modiff)
97
98
99 #define CHARS_MODIFF (current_buffer->text->chars_modiff)
100
101
102 #define OVERLAY_MODIFF (current_buffer->text->overlay_modiff)
103
104
105 #define SAVE_MODIFF (current_buffer->text->save_modiff)
106
107
108
109 #define BUF_GPT(buf) ((buf)->text->gpt)
110 #define BUF_GPT_BYTE(buf) ((buf)->text->gpt_byte)
111
112
113 #define BUF_Z(buf) ((buf)->text->z)
114 #define BUF_Z_BYTE(buf) ((buf)->text->z_byte)
115
116
117 #define BUF_BEG_ADDR(buf) ((buf)->text->beg)
118
119
120 #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size)
121
122
123 #define BUF_MODIFF(buf) ((buf)->text->modiff)
124
125
126 #define BUF_CHARS_MODIFF(buf) ((buf)->text->chars_modiff)
127
128
129 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff)
130
131
132 #define BUF_OVERLAY_MODIFF(buf) ((buf)->text->overlay_modiff)
133
134
135
136 #define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified)
137
138
139 #define BUF_COMPACT(buf) ((buf)->text->compact)
140
141
142 #define BUF_MARKERS(buf) ((buf)->text->markers)
143
144 #define BUF_UNCHANGED_MODIFIED(buf) \
145 ((buf)->text->unchanged_modified)
146
147 #define BUF_OVERLAY_UNCHANGED_MODIFIED(buf) \
148 ((buf)->text->overlay_unchanged_modified)
149 #define BUF_BEG_UNCHANGED(buf) ((buf)->text->beg_unchanged)
150 #define BUF_END_UNCHANGED(buf) ((buf)->text->end_unchanged)
151
152 #define UNCHANGED_MODIFIED \
153 BUF_UNCHANGED_MODIFIED (current_buffer)
154 #define OVERLAY_UNCHANGED_MODIFIED \
155 BUF_OVERLAY_UNCHANGED_MODIFIED (current_buffer)
156 #define BEG_UNCHANGED BUF_BEG_UNCHANGED (current_buffer)
157 #define END_UNCHANGED BUF_END_UNCHANGED (current_buffer)
158
159
160
161 extern void set_point (ptrdiff_t);
162 extern void temp_set_point (struct buffer *, ptrdiff_t);
163 extern void set_point_both (ptrdiff_t, ptrdiff_t);
164 extern void temp_set_point_both (struct buffer *,
165 ptrdiff_t, ptrdiff_t);
166 extern void set_point_from_marker (Lisp_Object);
167 extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
168
169 INLINE void
170 SET_PT (ptrdiff_t position)
171 {
172 set_point (position);
173 }
174 INLINE void
175 TEMP_SET_PT (ptrdiff_t position)
176 {
177 temp_set_point (current_buffer, position);
178 }
179 INLINE void
180 SET_PT_BOTH (ptrdiff_t position, ptrdiff_t byte)
181 {
182 set_point_both (position, byte);
183 }
184 INLINE void
185 TEMP_SET_PT_BOTH (ptrdiff_t position, ptrdiff_t byte)
186 {
187 temp_set_point_both (current_buffer, position, byte);
188 }
189 INLINE void
190 BUF_TEMP_SET_PT (struct buffer *buffer, ptrdiff_t position)
191 {
192 temp_set_point (buffer, position);
193 }
194
195
196
197
198
199 #define BUF_BYTES_MAX \
200 (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
201
202
203
204
205 enum { GAP_BYTES_DFL = 2000 };
206
207
208
209
210 enum { GAP_BYTES_MIN = 20 };
211
212
213
214 extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos);
215
216
217
218
219 #define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n)))
220
221
222
223
224
225
226 struct buffer_text
227 {
228
229
230
231
232 unsigned char *beg;
233
234 ptrdiff_t gpt;
235 ptrdiff_t z;
236 ptrdiff_t gpt_byte;
237 ptrdiff_t z_byte;
238 ptrdiff_t gap_size;
239 modiff_count modiff;
240
241
242
243
244 modiff_count chars_modiff;
245
246
247
248 modiff_count save_modiff;
249
250
251 modiff_count overlay_modiff;
252
253 modiff_count compact;
254
255
256
257 ptrdiff_t beg_unchanged;
258
259
260 ptrdiff_t end_unchanged;
261
262
263
264 modiff_count unchanged_modified;
265
266
267
268
269 modiff_count overlay_unchanged_modified;
270
271
272 INTERVAL intervals;
273
274
275
276
277
278
279
280
281 struct Lisp_Marker *markers;
282
283
284
285
286 bool_bf inhibit_shrinking : 1;
287
288
289 bool_bf redisplay : 1;
290 };
291
292
293
294 #define BVAR(buf, field) ((buf)->field ## _)
295
296
297 enum { MAX_PER_BUFFER_VARS = 50 };
298
299
300 enum { NONEXISTENT_MODTIME_NSECS = -1 };
301 enum { UNKNOWN_MODTIME_NSECS = -2 };
302
303
304
305 struct buffer
306 {
307 union vectorlike_header header;
308
309
310 Lisp_Object name_;
311
312
313 Lisp_Object filename_;
314
315
316 Lisp_Object directory_;
317
318
319
320 Lisp_Object backed_up_;
321
322
323
324
325
326
327
328 Lisp_Object save_length_;
329
330
331
332
333 Lisp_Object auto_save_file_name_;
334
335
336 Lisp_Object read_only_;
337
338
339
340 Lisp_Object mark_;
341
342
343
344
345 Lisp_Object local_var_alist_;
346
347
348 Lisp_Object major_mode_;
349
350
351 Lisp_Object local_minor_modes_;
352
353
354 Lisp_Object mode_name_;
355
356
357 Lisp_Object mode_line_format_;
358
359
360
361 Lisp_Object header_line_format_;
362
363
364
365 Lisp_Object tab_line_format_;
366
367
368 Lisp_Object keymap_;
369
370
371 Lisp_Object abbrev_table_;
372
373
374 Lisp_Object syntax_table_;
375
376
377 Lisp_Object category_table_;
378
379
380
381
382 Lisp_Object case_fold_search_;
383 Lisp_Object tab_width_;
384 Lisp_Object fill_column_;
385 Lisp_Object left_margin_;
386
387
388 Lisp_Object auto_fill_function_;
389
390
391
392 Lisp_Object downcase_table_;
393
394
395 Lisp_Object upcase_table_;
396
397
398 Lisp_Object case_canon_table_;
399
400
401 Lisp_Object case_eqv_table_;
402
403
404 Lisp_Object truncate_lines_;
405
406
407 Lisp_Object word_wrap_;
408
409
410 Lisp_Object ctl_arrow_;
411
412
413
414 Lisp_Object bidi_display_reordering_;
415
416
417
418
419 Lisp_Object bidi_paragraph_direction_;
420
421
422 Lisp_Object bidi_paragraph_separate_re_;
423
424
425 Lisp_Object bidi_paragraph_start_re_;
426
427
428
429 Lisp_Object selective_display_;
430
431
432 Lisp_Object selective_display_ellipses_;
433
434
435
436 Lisp_Object overwrite_mode_;
437
438
439 Lisp_Object abbrev_mode_;
440
441
442 Lisp_Object display_table_;
443
444
445 Lisp_Object mark_active_;
446
447
448
449 Lisp_Object enable_multibyte_characters_;
450
451
452
453 Lisp_Object buffer_file_coding_system_;
454
455
456 Lisp_Object file_format_;
457
458
459 Lisp_Object auto_save_file_format_;
460
461
462
463 Lisp_Object cache_long_scans_;
464
465
466
467
468
469
470
471 Lisp_Object width_table_;
472
473
474
475
476 Lisp_Object pt_marker_;
477
478
479
480
481 Lisp_Object begv_marker_;
482
483
484
485
486 Lisp_Object zv_marker_;
487
488
489
490 Lisp_Object point_before_scroll_;
491
492
493 Lisp_Object file_truename_;
494
495
496
497
498
499 Lisp_Object invisibility_spec_;
500
501
502
503 Lisp_Object last_selected_window_;
504
505
506 Lisp_Object display_count_;
507
508
509
510 Lisp_Object left_margin_cols_;
511 Lisp_Object right_margin_cols_;
512
513
514
515 Lisp_Object left_fringe_width_;
516 Lisp_Object right_fringe_width_;
517
518
519
520 Lisp_Object fringes_outside_margins_;
521
522
523
524 Lisp_Object scroll_bar_width_;
525 Lisp_Object scroll_bar_height_;
526 Lisp_Object vertical_scroll_bar_type_;
527 Lisp_Object horizontal_scroll_bar_type_;
528
529
530
531 Lisp_Object indicate_empty_lines_;
532
533
534 Lisp_Object indicate_buffer_boundaries_;
535
536
537 Lisp_Object fringe_indicator_alist_;
538
539
540 Lisp_Object fringe_cursor_alist_;
541
542
543 Lisp_Object display_time_;
544
545
546
547
548
549 Lisp_Object scroll_up_aggressively_;
550
551
552
553
554
555 Lisp_Object scroll_down_aggressively_;
556
557
558
559 Lisp_Object cursor_type_;
560
561
562
563 Lisp_Object extra_line_spacing_;
564
565 #ifdef HAVE_TREE_SITTER
566
567 Lisp_Object ts_parser_list_;
568 #endif
569
570
571
572 Lisp_Object text_conversion_style_;
573
574
575
576
577 Lisp_Object cursor_in_non_selected_windows_;
578
579
580
581
582
583
584 struct buffer_text own_text;
585
586
587
588
589 struct buffer_text *text;
590
591
592 ptrdiff_t pt;
593
594
595 ptrdiff_t pt_byte;
596
597
598 ptrdiff_t begv;
599
600
601 ptrdiff_t begv_byte;
602
603
604 ptrdiff_t zv;
605
606
607 ptrdiff_t zv_byte;
608
609
610
611 struct buffer *base_buffer;
612
613
614
615
616 int indirections;
617
618
619
620 int window_count;
621
622
623
624
625
626
627 char local_flags[MAX_PER_BUFFER_VARS];
628
629
630
631
632
633
634 struct timespec modtime;
635
636
637
638
639
640
641 off_t modtime_size;
642
643
644 modiff_count auto_save_modified;
645
646
647
648 modiff_count display_error_modiff;
649
650
651
652 time_t auto_save_failure_time;
653
654
655
656 ptrdiff_t last_window_start;
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676 struct region_cache *newline_cache;
677 struct region_cache *width_run_cache;
678 struct region_cache *bidi_paragraph_cache;
679
680
681
682 bool_bf prevent_redisplay_optimizations_p : 1;
683
684
685 bool_bf clip_changed : 1;
686
687
688
689
690
691
692 bool_bf inhibit_buffer_hooks : 1;
693
694
695
696 bool_bf long_line_optimizations_p : 1;
697
698
699 struct itree_tree *overlays;
700
701
702
703
704
705
706 Lisp_Object undo_list_;
707 };
708
709 struct sortvec
710 {
711 Lisp_Object overlay;
712 ptrdiff_t beg, end;
713 EMACS_INT priority;
714 EMACS_INT spriority;
715 };
716
717 INLINE bool
718 BUFFERP (Lisp_Object a)
719 {
720 return PSEUDOVECTORP (a, PVEC_BUFFER);
721 }
722
723 INLINE void
724 CHECK_BUFFER (Lisp_Object x)
725 {
726 CHECK_TYPE (BUFFERP (x), Qbufferp, x);
727 }
728
729 INLINE struct buffer *
730 XBUFFER (Lisp_Object a)
731 {
732 eassert (BUFFERP (a));
733 return XUNTAG (a, Lisp_Vectorlike, struct buffer);
734 }
735
736
737
738
739 INLINE void
740 bset_bidi_paragraph_direction (struct buffer *b, Lisp_Object val)
741 {
742 b->bidi_paragraph_direction_ = val;
743 }
744 INLINE void
745 bset_cache_long_scans (struct buffer *b, Lisp_Object val)
746 {
747 b->cache_long_scans_ = val;
748 }
749 INLINE void
750 bset_case_canon_table (struct buffer *b, Lisp_Object val)
751 {
752 b->case_canon_table_ = val;
753 }
754 INLINE void
755 bset_case_eqv_table (struct buffer *b, Lisp_Object val)
756 {
757 b->case_eqv_table_ = val;
758 }
759 INLINE void
760 bset_directory (struct buffer *b, Lisp_Object val)
761 {
762 b->directory_ = val;
763 }
764 INLINE void
765 bset_display_count (struct buffer *b, Lisp_Object val)
766 {
767 b->display_count_ = val;
768 }
769 INLINE void
770 bset_left_margin_cols (struct buffer *b, Lisp_Object val)
771 {
772 b->left_margin_cols_ = val;
773 }
774 INLINE void
775 bset_right_margin_cols (struct buffer *b, Lisp_Object val)
776 {
777 b->right_margin_cols_ = val;
778 }
779 INLINE void
780 bset_display_time (struct buffer *b, Lisp_Object val)
781 {
782 b->display_time_ = val;
783 }
784 INLINE void
785 bset_downcase_table (struct buffer *b, Lisp_Object val)
786 {
787 b->downcase_table_ = val;
788 }
789 INLINE void
790 bset_enable_multibyte_characters (struct buffer *b, Lisp_Object val)
791 {
792 b->enable_multibyte_characters_ = val;
793 }
794 INLINE void
795 bset_filename (struct buffer *b, Lisp_Object val)
796 {
797 b->filename_ = val;
798 }
799 INLINE void
800 bset_keymap (struct buffer *b, Lisp_Object val)
801 {
802 b->keymap_ = val;
803 }
804 INLINE void
805 bset_last_selected_window (struct buffer *b, Lisp_Object val)
806 {
807 b->last_selected_window_ = val;
808 }
809 INLINE void
810 bset_local_var_alist (struct buffer *b, Lisp_Object val)
811 {
812 b->local_var_alist_ = val;
813 }
814 INLINE void
815 bset_mark_active (struct buffer *b, Lisp_Object val)
816 {
817 b->mark_active_ = val;
818 }
819 INLINE void
820 bset_point_before_scroll (struct buffer *b, Lisp_Object val)
821 {
822 b->point_before_scroll_ = val;
823 }
824 INLINE void
825 bset_read_only (struct buffer *b, Lisp_Object val)
826 {
827 b->read_only_ = val;
828 }
829 INLINE void
830 bset_truncate_lines (struct buffer *b, Lisp_Object val)
831 {
832 b->truncate_lines_ = val;
833 }
834 INLINE void
835 bset_undo_list (struct buffer *b, Lisp_Object val)
836 {
837 b->undo_list_ = val;
838 }
839 INLINE void
840 bset_upcase_table (struct buffer *b, Lisp_Object val)
841 {
842 b->upcase_table_ = val;
843 }
844 INLINE void
845 bset_width_table (struct buffer *b, Lisp_Object val)
846 {
847 b->width_table_ = val;
848 }
849
850 INLINE void
851 bset_text_conversion_style (struct buffer *b, Lisp_Object val)
852 {
853 b->text_conversion_style_ = val;
854 }
855
856
857
858
859
860
861 INLINE ptrdiff_t
862 BUFFER_CEILING_OF (ptrdiff_t bytepos)
863 {
864 return (bytepos < GPT_BYTE && GPT < ZV ? GPT_BYTE : ZV_BYTE) - 1;
865 }
866
867 INLINE ptrdiff_t
868 BUFFER_FLOOR_OF (ptrdiff_t bytepos)
869 {
870 return BEGV <= GPT && GPT_BYTE <= bytepos ? GPT_BYTE : BEGV_BYTE;
871 }
872
873
874
875
876
877 INLINE ptrdiff_t
878 BUF_BEGV (struct buffer *buf)
879 {
880 return (buf == current_buffer ? BEGV
881 : NILP (BVAR (buf, begv_marker)) ? buf->begv
882 : marker_position (BVAR (buf, begv_marker)));
883 }
884
885 INLINE ptrdiff_t
886 BUF_BEGV_BYTE (struct buffer *buf)
887 {
888 return (buf == current_buffer ? BEGV_BYTE
889 : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte
890 : marker_byte_position (BVAR (buf, begv_marker)));
891 }
892
893
894 INLINE ptrdiff_t
895 BUF_PT (struct buffer *buf)
896 {
897 return (buf == current_buffer ? PT
898 : NILP (BVAR (buf, pt_marker)) ? buf->pt
899 : marker_position (BVAR (buf, pt_marker)));
900 }
901
902 INLINE ptrdiff_t
903 BUF_PT_BYTE (struct buffer *buf)
904 {
905 return (buf == current_buffer ? PT_BYTE
906 : NILP (BVAR (buf, pt_marker)) ? buf->pt_byte
907 : marker_byte_position (BVAR (buf, pt_marker)));
908 }
909
910
911 INLINE ptrdiff_t
912 BUF_ZV (struct buffer *buf)
913 {
914 return (buf == current_buffer ? ZV
915 : NILP (BVAR (buf, zv_marker)) ? buf->zv
916 : marker_position (BVAR (buf, zv_marker)));
917 }
918
919 INLINE ptrdiff_t
920 BUF_ZV_BYTE (struct buffer *buf)
921 {
922 return (buf == current_buffer ? ZV_BYTE
923 : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte
924 : marker_byte_position (BVAR (buf, zv_marker)));
925 }
926
927
928
929
930 INLINE ptrdiff_t
931 BUF_BEG (struct buffer *buf)
932 {
933 return BEG;
934 }
935
936 INLINE ptrdiff_t
937 BUF_BEG_BYTE (struct buffer *buf)
938 {
939 return BEG_BYTE;
940 }
941
942
943 INLINE unsigned char *
944 BUF_GPT_ADDR (struct buffer *buf)
945 {
946 return buf->text->beg + buf->text->gpt_byte - BEG_BYTE;
947 }
948
949
950 INLINE unsigned char *
951 BUF_Z_ADDR (struct buffer *buf)
952 {
953 return buf->text->beg + buf->text->gap_size + buf->text->z_byte - BEG_BYTE;
954 }
955
956
957 INLINE unsigned char *
958 BUF_GAP_END_ADDR (struct buffer *buf)
959 {
960 return buf->text->beg + buf->text->gpt_byte + buf->text->gap_size - BEG_BYTE;
961 }
962
963
964
965
966
967 INLINE void
968 BUF_COMPUTE_UNCHANGED (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
969 {
970 if (BUF_UNCHANGED_MODIFIED (buf) == BUF_MODIFF (buf)
971 && (BUF_OVERLAY_UNCHANGED_MODIFIED (buf)
972 == BUF_OVERLAY_MODIFF (buf)))
973 {
974 buf->text->beg_unchanged = start - BUF_BEG (buf);
975 buf->text->end_unchanged = BUF_Z (buf) - (end);
976 }
977 else
978 {
979 if (BUF_Z (buf) - end < BUF_END_UNCHANGED (buf))
980 buf->text->end_unchanged = BUF_Z (buf) - end;
981 if (start - BUF_BEG (buf) < BUF_BEG_UNCHANGED (buf))
982 buf->text->beg_unchanged = start - BUF_BEG (buf);
983 }
984 }
985
986
987
988
989
990
991
992
993
994 INLINE void
995 SET_BUF_BEGV (struct buffer *buf, ptrdiff_t charpos)
996 {
997 buf->begv_byte = buf_charpos_to_bytepos (buf, charpos);
998 buf->begv = charpos;
999 }
1000
1001 INLINE void
1002 SET_BUF_ZV (struct buffer *buf, ptrdiff_t charpos)
1003 {
1004 buf->zv_byte = buf_charpos_to_bytepos (buf, charpos);
1005 buf->zv = charpos;
1006 }
1007
1008 INLINE void
1009 SET_BUF_BEGV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
1010 {
1011 buf->begv = charpos;
1012 buf->begv_byte = byte;
1013 }
1014
1015 INLINE void
1016 SET_BUF_ZV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
1017 {
1018 buf->zv = charpos;
1019 buf->zv_byte = byte;
1020 }
1021
1022 INLINE void
1023 SET_BUF_PT_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
1024 {
1025 buf->pt = charpos;
1026 buf->pt_byte = byte;
1027 }
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038 INLINE unsigned char *
1039 BYTE_POS_ADDR (ptrdiff_t n)
1040 {
1041 return (n < GPT_BYTE ? 0 : GAP_SIZE) + n + BEG_ADDR - BEG_BYTE;
1042 }
1043
1044
1045
1046 INLINE unsigned char *
1047 CHAR_POS_ADDR (ptrdiff_t n)
1048 {
1049 return ((n < GPT ? 0 : GAP_SIZE)
1050 + buf_charpos_to_bytepos (current_buffer, n)
1051 + BEG_ADDR - BEG_BYTE);
1052 }
1053
1054
1055
1056 INLINE ptrdiff_t
1057 CHAR_TO_BYTE (ptrdiff_t charpos)
1058 {
1059 return buf_charpos_to_bytepos (current_buffer, charpos);
1060 }
1061
1062
1063
1064 INLINE ptrdiff_t
1065 BYTE_TO_CHAR (ptrdiff_t bytepos)
1066 {
1067 return buf_bytepos_to_charpos (current_buffer, bytepos);
1068 }
1069
1070
1071
1072 INLINE ptrdiff_t
1073 PTR_BYTE_POS (unsigned char const *ptr)
1074 {
1075 ptrdiff_t byte = ptr - current_buffer->text->beg;
1076 return byte - (byte <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) + BEG_BYTE;
1077 }
1078
1079
1080
1081
1082
1083 enum { BUFFER_LISP_SIZE = PSEUDOVECSIZE (struct buffer,
1084 cursor_in_non_selected_windows_) };
1085
1086
1087
1088
1089 enum { BUFFER_REST_SIZE = VECSIZE (struct buffer) - BUFFER_LISP_SIZE };
1090
1091
1092
1093
1094
1095 INLINE void
1096 BUFFER_PVEC_INIT (struct buffer *b)
1097 {
1098 XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE);
1099 }
1100
1101
1102
1103 INLINE bool
1104 BUFFER_LIVE_P (struct buffer *b)
1105 {
1106 return !NILP (BVAR (b, name));
1107 }
1108
1109
1110
1111
1112 INLINE bool
1113 BUFFER_HIDDEN_P (struct buffer *b)
1114 {
1115 return SREF (BVAR (b, name), 0) == ' ';
1116 }
1117
1118
1119
1120 INLINE void
1121 BUFFER_CHECK_INDIRECTION (struct buffer *b)
1122 {
1123 if (BUFFER_LIVE_P (b))
1124 {
1125 if (b->base_buffer)
1126 {
1127 eassert (b->indirections == -1);
1128 eassert (b->base_buffer->indirections > 0);
1129 }
1130 else
1131 eassert (b->indirections >= 0);
1132 }
1133 }
1134
1135
1136
1137
1138
1139
1140
1141
1142 extern struct buffer buffer_defaults;
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158 extern struct buffer buffer_local_flags;
1159
1160
1161
1162
1163
1164 extern struct buffer buffer_local_symbols;
1165
1166
1167
1168 extern Lisp_Object interval_insert_behind_hooks;
1169 extern Lisp_Object interval_insert_in_front_hooks;
1170
1171
1172 extern EMACS_INT fix_position (Lisp_Object);
1173 #define CHECK_FIXNUM_COERCE_MARKER(x) ((x) = make_fixnum (fix_position (x)))
1174 extern void delete_all_overlays (struct buffer *);
1175 extern void reset_buffer (struct buffer *);
1176 extern void compact_buffer (struct buffer *);
1177 extern ptrdiff_t overlays_at (ptrdiff_t, bool, Lisp_Object **, ptrdiff_t *, ptrdiff_t *);
1178 extern ptrdiff_t overlays_in (ptrdiff_t, ptrdiff_t, bool, Lisp_Object **,
1179 ptrdiff_t *, bool, bool, ptrdiff_t *);
1180 extern ptrdiff_t previous_overlay_change (ptrdiff_t);
1181 extern ptrdiff_t next_overlay_change (ptrdiff_t);
1182 extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
1183 extern void recenter_overlay_lists (struct buffer *, ptrdiff_t);
1184 extern ptrdiff_t overlay_strings (ptrdiff_t, struct window *, unsigned char **);
1185 extern void validate_region (Lisp_Object *, Lisp_Object *);
1186 extern void set_buffer_internal_1 (struct buffer *);
1187 extern void set_buffer_internal_2 (struct buffer *);
1188 extern void set_buffer_temp (struct buffer *);
1189 extern Lisp_Object buffer_local_value (Lisp_Object, Lisp_Object);
1190 extern void record_buffer (Lisp_Object);
1191 extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
1192 extern void mmap_set_vars (bool);
1193 extern void restore_buffer (Lisp_Object);
1194 extern void set_buffer_if_live (Lisp_Object);
1195 extern Lisp_Object build_overlay (bool, bool, Lisp_Object);
1196
1197
1198
1199 INLINE struct buffer *
1200 decode_buffer (Lisp_Object b)
1201 {
1202 return NILP (b) ? current_buffer : (CHECK_BUFFER (b), XBUFFER (b));
1203 }
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214 INLINE void
1215 set_buffer_internal (struct buffer *b)
1216 {
1217 if (current_buffer != b)
1218 set_buffer_internal_1 (b);
1219 }
1220
1221
1222
1223
1224 INLINE void
1225 record_unwind_current_buffer (void)
1226 {
1227 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
1228 }
1229
1230
1231
1232
1233
1234
1235
1236 #define GET_OVERLAYS_AT(posn, overlays, noverlays, next) \
1237 do { \
1238 ptrdiff_t maxlen = 40; \
1239 SAFE_NALLOCA (overlays, 1, maxlen); \
1240 (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, next); \
1241 if ((noverlays) > maxlen) \
1242 { \
1243 maxlen = noverlays; \
1244 SAFE_NALLOCA (overlays, 1, maxlen); \
1245 (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, next); \
1246 } \
1247 } while (false)
1248
1249 extern Lisp_Object Vbuffer_alist;
1250
1251
1252
1253
1254 #define FOR_EACH_LIVE_BUFFER(list_var, buf_var) \
1255 FOR_EACH_ALIST_VALUE (Vbuffer_alist, list_var, buf_var)
1256
1257
1258
1259 INLINE INTERVAL
1260 buffer_intervals (struct buffer *b)
1261 {
1262 eassert (b->text != NULL);
1263 return b->text->intervals;
1264 }
1265
1266
1267
1268 INLINE void
1269 set_buffer_intervals (struct buffer *b, INTERVAL i)
1270 {
1271 eassert (b->text != NULL);
1272 b->text->intervals = i;
1273 }
1274
1275
1276
1277 INLINE bool
1278 buffer_has_overlays (void)
1279 {
1280 return !itree_empty_p (current_buffer->overlays);
1281 }
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291 INLINE int
1292 FETCH_MULTIBYTE_CHAR (ptrdiff_t pos)
1293 {
1294 unsigned char *p = BYTE_POS_ADDR (pos);
1295 return STRING_CHAR (p);
1296 }
1297
1298
1299
1300
1301
1302 INLINE int
1303 BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
1304 {
1305 unsigned char *p
1306 = ((pos >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0)
1307 + pos + BUF_BEG_ADDR (buf) - BEG_BYTE);
1308 return STRING_CHAR (p);
1309 }
1310
1311
1312
1313
1314
1315 INLINE int
1316 FETCH_CHAR_AS_MULTIBYTE (ptrdiff_t pos)
1317 {
1318 return (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1319 ? FETCH_MULTIBYTE_CHAR (pos)
1320 : UNIBYTE_TO_CHAR (FETCH_BYTE (pos)));
1321 }
1322
1323
1324
1325
1326 INLINE int
1327 FETCH_CHAR (ptrdiff_t pos)
1328 {
1329 return (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1330 ? FETCH_MULTIBYTE_CHAR (pos)
1331 : FETCH_BYTE (pos));
1332 }
1333
1334
1335
1336
1337 INLINE unsigned char *
1338 BUF_BYTE_ADDRESS (struct buffer *buf, ptrdiff_t pos)
1339 {
1340 return (buf->text->beg + pos - BEG_BYTE
1341 + (pos < buf->text->gpt_byte ? 0 : buf->text->gap_size));
1342 }
1343
1344
1345
1346
1347 INLINE unsigned char *
1348 BUF_CHAR_ADDRESS (struct buffer *buf, ptrdiff_t pos)
1349 {
1350 return (buf->text->beg + buf_charpos_to_bytepos (buf, pos) - BEG_BYTE
1351 + (pos < buf->text->gpt ? 0 : buf->text->gap_size));
1352 }
1353
1354
1355
1356
1357 INLINE ptrdiff_t
1358 BUF_PTR_BYTE_POS (struct buffer *buf, unsigned char *ptr)
1359 {
1360 ptrdiff_t byte = ptr - buf->text->beg;
1361 return (byte - (byte <= BUF_GPT_BYTE (buf) - BEG_BYTE ? 0 : BUF_GAP_SIZE (buf))
1362 + BEG_BYTE);
1363 }
1364
1365
1366
1367 INLINE unsigned char
1368 BUF_FETCH_BYTE (struct buffer *buf, ptrdiff_t n)
1369 {
1370 return *BUF_BYTE_ADDRESS (buf, n);
1371 }
1372
1373
1374
1375
1376
1377 INLINE int
1378 BUF_FETCH_CHAR_AS_MULTIBYTE (struct buffer *buf, ptrdiff_t pos)
1379 {
1380 return (! NILP (BVAR (buf, enable_multibyte_characters))
1381 ? BUF_FETCH_MULTIBYTE_CHAR (buf, pos)
1382 : UNIBYTE_TO_CHAR (BUF_FETCH_BYTE (buf, pos)));
1383 }
1384
1385
1386
1387 INLINE int
1388 buffer_window_count (struct buffer *b)
1389 {
1390 if (b->base_buffer)
1391 b = b->base_buffer;
1392 eassert (b->window_count >= 0);
1393 return b->window_count;
1394 }
1395
1396
1397
1398 INLINE ptrdiff_t
1399 overlay_start (struct Lisp_Overlay *ov)
1400 {
1401 if (! ov->buffer)
1402 return -1;
1403 return itree_node_begin (ov->buffer->overlays, ov->interval);
1404 }
1405
1406 INLINE ptrdiff_t
1407 overlay_end (struct Lisp_Overlay *ov)
1408 {
1409 if (! ov->buffer)
1410 return -1;
1411 return itree_node_end (ov->buffer->overlays, ov->interval);
1412 }
1413
1414
1415
1416
1417 INLINE ptrdiff_t
1418 OVERLAY_START (Lisp_Object ov)
1419 {
1420 return overlay_start (XOVERLAY (ov));
1421 }
1422
1423
1424
1425 INLINE ptrdiff_t
1426 OVERLAY_END (Lisp_Object ov)
1427 {
1428 return overlay_end (XOVERLAY (ov));
1429 }
1430
1431
1432
1433 INLINE Lisp_Object
1434 OVERLAY_PLIST (Lisp_Object ov)
1435 {
1436 return XOVERLAY (ov)->plist;
1437 }
1438
1439
1440
1441 INLINE struct buffer *
1442 OVERLAY_BUFFER (Lisp_Object ov)
1443 {
1444 return XOVERLAY (ov)->buffer;
1445 }
1446
1447
1448
1449 INLINE bool
1450 OVERLAY_REAR_ADVANCE_P (Lisp_Object ov)
1451 {
1452 return XOVERLAY (ov)->interval->rear_advance;
1453 }
1454
1455
1456
1457 INLINE bool
1458 OVERLAY_FRONT_ADVANCE_P (Lisp_Object ov)
1459 {
1460 return XOVERLAY (ov)->interval->front_advance;
1461 }
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471 #define PER_BUFFER_VAR_OFFSET(VAR) \
1472 offsetof (struct buffer, VAR ## _)
1473
1474
1475
1476
1477
1478 #define FOR_EACH_PER_BUFFER_OBJECT_AT(offset) \
1479 for (offset = PER_BUFFER_VAR_OFFSET (name); \
1480 offset <= PER_BUFFER_VAR_OFFSET (cursor_in_non_selected_windows); \
1481 offset += word_size)
1482
1483
1484
1485
1486
1487
1488
1489 #define PER_BUFFER_VAR_IDX(VAR) \
1490 PER_BUFFER_IDX (PER_BUFFER_VAR_OFFSET (VAR))
1491
1492 extern bool valid_per_buffer_idx (int);
1493
1494
1495
1496
1497 INLINE bool
1498 PER_BUFFER_VALUE_P (struct buffer *b, int idx)
1499 {
1500 eassert (valid_per_buffer_idx (idx));
1501 return b->local_flags[idx];
1502 }
1503
1504
1505
1506
1507 INLINE void
1508 SET_PER_BUFFER_VALUE_P (struct buffer *b, int idx, bool val)
1509 {
1510 eassert (valid_per_buffer_idx (idx));
1511 b->local_flags[idx] = val;
1512 }
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534 INLINE int
1535 PER_BUFFER_IDX (ptrdiff_t offset)
1536 {
1537 return XFIXNUM (*(Lisp_Object *) (offset + (char *) &buffer_local_flags));
1538 }
1539
1540
1541
1542
1543 INLINE Lisp_Object
1544 per_buffer_default (int offset)
1545 {
1546 return *(Lisp_Object *)(offset + (char *) &buffer_defaults);
1547 }
1548
1549 INLINE void
1550 set_per_buffer_default (int offset, Lisp_Object value)
1551 {
1552 *(Lisp_Object *)(offset + (char *) &buffer_defaults) = value;
1553 }
1554
1555
1556
1557
1558 INLINE Lisp_Object
1559 per_buffer_value (struct buffer *b, int offset)
1560 {
1561 return *(Lisp_Object *)(offset + (char *) b);
1562 }
1563
1564 INLINE void
1565 set_per_buffer_value (struct buffer *b, int offset, Lisp_Object value)
1566 {
1567 *(Lisp_Object *)(offset + (char *) b) = value;
1568 }
1569
1570
1571 INLINE int
1572 downcase (int c)
1573 {
1574 Lisp_Object downcase_table = BVAR (current_buffer, downcase_table);
1575 Lisp_Object down = CHAR_TABLE_REF (downcase_table, c);
1576 return FIXNATP (down) ? XFIXNAT (down) : c;
1577 }
1578
1579
1580 INLINE int
1581 upcase (int c)
1582 {
1583 Lisp_Object upcase_table = BVAR (current_buffer, upcase_table);
1584 Lisp_Object up = CHAR_TABLE_REF (upcase_table, c);
1585 return FIXNATP (up) ? XFIXNAT (up) : c;
1586 }
1587
1588
1589 INLINE bool
1590 uppercasep (int c)
1591 {
1592 return downcase (c) != c;
1593 }
1594
1595
1596 INLINE bool
1597 lowercasep (int c)
1598 {
1599 return !uppercasep (c) && upcase (c) != c;
1600 }
1601
1602
1603
1604 INLINE int
1605 sanitize_tab_width (Lisp_Object width)
1606 {
1607 return (FIXNUMP (width) && 0 < XFIXNUM (width) && XFIXNUM (width) <= 1000
1608 ? XFIXNUM (width) : 8);
1609 }
1610
1611 INLINE int
1612 SANE_TAB_WIDTH (struct buffer *buf)
1613 {
1614 return sanitize_tab_width (BVAR (buf, tab_width));
1615 }
1616
1617
1618
1619 INLINE int
1620 sanitize_char_width (EMACS_INT width)
1621 {
1622 return 0 <= width && width <= 1000 ? width : 1000;
1623 }
1624
1625
1626
1627
1628
1629
1630 INLINE int
1631 CHARACTER_WIDTH (int c)
1632 {
1633 return (0x20 <= c && c < 0x7f ? 1
1634 : 0x7f < c ? (sanitize_char_width
1635 (XFIXNUM (CHAR_TABLE_REF (Vchar_width_table, c))))
1636 : c == '\t' ? SANE_TAB_WIDTH (current_buffer)
1637 : c == '\n' ? 0
1638 : !NILP (BVAR (current_buffer, ctl_arrow)) ? 2 : 4);
1639 }
1640
1641
1642
1643
1644
1645 INLINE int
1646 fetch_char_advance (ptrdiff_t *charidx, ptrdiff_t *byteidx)
1647 {
1648 int output;
1649 ptrdiff_t c = *charidx, b = *byteidx;
1650 c++;
1651 unsigned char *chp = BYTE_POS_ADDR (b);
1652 if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
1653 {
1654 int chlen;
1655 output = string_char_and_length (chp, &chlen);
1656 b += chlen;
1657 }
1658 else
1659 {
1660 output = *chp;
1661 b++;
1662 }
1663 *charidx = c;
1664 *byteidx = b;
1665 return output;
1666 }
1667
1668
1669
1670
1671 INLINE int
1672 fetch_char_advance_no_check (ptrdiff_t *charidx, ptrdiff_t *byteidx)
1673 {
1674 int output;
1675 ptrdiff_t c = *charidx, b = *byteidx;
1676 c++;
1677 unsigned char *chp = BYTE_POS_ADDR (b);
1678 int chlen;
1679 output = string_char_and_length (chp, &chlen);
1680 b += chlen;
1681 *charidx = c;
1682 *byteidx = b;
1683 return output;
1684 }
1685
1686
1687
1688
1689
1690
1691 INLINE int
1692 buf_next_char_len (struct buffer *buf, ptrdiff_t pos_byte)
1693 {
1694 unsigned char *chp = BUF_BYTE_ADDRESS (buf, pos_byte);
1695 return BYTES_BY_CHAR_HEAD (*chp);
1696 }
1697
1698 INLINE int
1699 next_char_len (ptrdiff_t pos_byte)
1700 {
1701 return buf_next_char_len (current_buffer, pos_byte);
1702 }
1703
1704
1705
1706
1707 INLINE int
1708 buf_prev_char_len (struct buffer *buf, ptrdiff_t pos_byte)
1709 {
1710 unsigned char *chp
1711 = (BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE
1712 + (pos_byte <= BUF_GPT_BYTE (buf) ? 0 : BUF_GAP_SIZE (buf)));
1713 return raw_prev_char_len (chp);
1714 }
1715
1716 INLINE int
1717 prev_char_len (ptrdiff_t pos_byte)
1718 {
1719 return buf_prev_char_len (current_buffer, pos_byte);
1720 }
1721
1722
1723
1724 INLINE void
1725 inc_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
1726 {
1727 (*charpos)++;
1728 (*bytepos) += (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1729 ? next_char_len (*bytepos) : 1);
1730 }
1731
1732
1733
1734 INLINE void
1735 dec_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
1736 {
1737 (*charpos)--;
1738 (*bytepos) -= (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1739 ? prev_char_len (*bytepos) : 1);
1740 }
1741
1742 INLINE_HEADER_END
1743
1744 int compare_overlays (const void *v1, const void *v2);
1745 void make_sortvec_item (struct sortvec *item, Lisp_Object overlay);
1746
1747 #endif