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
- 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 cursor_in_non_selected_windows_;
573
574
575
576
577
578
579 struct buffer_text own_text;
580
581
582
583
584 struct buffer_text *text;
585
586
587 ptrdiff_t pt;
588
589
590 ptrdiff_t pt_byte;
591
592
593 ptrdiff_t begv;
594
595
596 ptrdiff_t begv_byte;
597
598
599 ptrdiff_t zv;
600
601
602 ptrdiff_t zv_byte;
603
604
605
606 struct buffer *base_buffer;
607
608
609
610
611 int indirections;
612
613
614
615 int window_count;
616
617
618
619
620
621
622 char local_flags[MAX_PER_BUFFER_VARS];
623
624
625
626
627
628
629 struct timespec modtime;
630
631
632
633
634
635
636 off_t modtime_size;
637
638
639 modiff_count auto_save_modified;
640
641
642
643 modiff_count display_error_modiff;
644
645
646
647 time_t auto_save_failure_time;
648
649
650
651 ptrdiff_t last_window_start;
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671 struct region_cache *newline_cache;
672 struct region_cache *width_run_cache;
673 struct region_cache *bidi_paragraph_cache;
674
675
676
677 bool_bf prevent_redisplay_optimizations_p : 1;
678
679
680 bool_bf clip_changed : 1;
681
682
683
684
685
686
687 bool_bf inhibit_buffer_hooks : 1;
688
689
690
691 bool_bf long_line_optimizations_p : 1;
692
693
694 struct itree_tree *overlays;
695
696
697
698
699
700
701 Lisp_Object undo_list_;
702 };
703
704 struct sortvec
705 {
706 Lisp_Object overlay;
707 ptrdiff_t beg, end;
708 EMACS_INT priority;
709 EMACS_INT spriority;
710 };
711
712 INLINE bool
713 BUFFERP (Lisp_Object a)
714 {
715 return PSEUDOVECTORP (a, PVEC_BUFFER);
716 }
717
718 INLINE void
719 CHECK_BUFFER (Lisp_Object x)
720 {
721 CHECK_TYPE (BUFFERP (x), Qbufferp, x);
722 }
723
724 INLINE struct buffer *
725 XBUFFER (Lisp_Object a)
726 {
727 eassert (BUFFERP (a));
728 return XUNTAG (a, Lisp_Vectorlike, struct buffer);
729 }
730
731
732
733
734 INLINE void
735 bset_bidi_paragraph_direction (struct buffer *b, Lisp_Object val)
736 {
737 b->bidi_paragraph_direction_ = val;
738 }
739 INLINE void
740 bset_cache_long_scans (struct buffer *b, Lisp_Object val)
741 {
742 b->cache_long_scans_ = val;
743 }
744 INLINE void
745 bset_case_canon_table (struct buffer *b, Lisp_Object val)
746 {
747 b->case_canon_table_ = val;
748 }
749 INLINE void
750 bset_case_eqv_table (struct buffer *b, Lisp_Object val)
751 {
752 b->case_eqv_table_ = val;
753 }
754 INLINE void
755 bset_directory (struct buffer *b, Lisp_Object val)
756 {
757 b->directory_ = val;
758 }
759 INLINE void
760 bset_display_count (struct buffer *b, Lisp_Object val)
761 {
762 b->display_count_ = val;
763 }
764 INLINE void
765 bset_left_margin_cols (struct buffer *b, Lisp_Object val)
766 {
767 b->left_margin_cols_ = val;
768 }
769 INLINE void
770 bset_right_margin_cols (struct buffer *b, Lisp_Object val)
771 {
772 b->right_margin_cols_ = val;
773 }
774 INLINE void
775 bset_display_time (struct buffer *b, Lisp_Object val)
776 {
777 b->display_time_ = val;
778 }
779 INLINE void
780 bset_downcase_table (struct buffer *b, Lisp_Object val)
781 {
782 b->downcase_table_ = val;
783 }
784 INLINE void
785 bset_enable_multibyte_characters (struct buffer *b, Lisp_Object val)
786 {
787 b->enable_multibyte_characters_ = val;
788 }
789 INLINE void
790 bset_filename (struct buffer *b, Lisp_Object val)
791 {
792 b->filename_ = val;
793 }
794 INLINE void
795 bset_keymap (struct buffer *b, Lisp_Object val)
796 {
797 b->keymap_ = val;
798 }
799 INLINE void
800 bset_last_selected_window (struct buffer *b, Lisp_Object val)
801 {
802 b->last_selected_window_ = val;
803 }
804 INLINE void
805 bset_local_var_alist (struct buffer *b, Lisp_Object val)
806 {
807 b->local_var_alist_ = val;
808 }
809 INLINE void
810 bset_mark_active (struct buffer *b, Lisp_Object val)
811 {
812 b->mark_active_ = val;
813 }
814 INLINE void
815 bset_point_before_scroll (struct buffer *b, Lisp_Object val)
816 {
817 b->point_before_scroll_ = val;
818 }
819 INLINE void
820 bset_read_only (struct buffer *b, Lisp_Object val)
821 {
822 b->read_only_ = val;
823 }
824 INLINE void
825 bset_truncate_lines (struct buffer *b, Lisp_Object val)
826 {
827 b->truncate_lines_ = val;
828 }
829 INLINE void
830 bset_undo_list (struct buffer *b, Lisp_Object val)
831 {
832 b->undo_list_ = val;
833 }
834 INLINE void
835 bset_upcase_table (struct buffer *b, Lisp_Object val)
836 {
837 b->upcase_table_ = val;
838 }
839 INLINE void
840 bset_width_table (struct buffer *b, Lisp_Object val)
841 {
842 b->width_table_ = val;
843 }
844
845
846
847
848
849
850 INLINE ptrdiff_t
851 BUFFER_CEILING_OF (ptrdiff_t bytepos)
852 {
853 return (bytepos < GPT_BYTE && GPT < ZV ? GPT_BYTE : ZV_BYTE) - 1;
854 }
855
856 INLINE ptrdiff_t
857 BUFFER_FLOOR_OF (ptrdiff_t bytepos)
858 {
859 return BEGV <= GPT && GPT_BYTE <= bytepos ? GPT_BYTE : BEGV_BYTE;
860 }
861
862
863
864
865
866 INLINE ptrdiff_t
867 BUF_BEGV (struct buffer *buf)
868 {
869 return (buf == current_buffer ? BEGV
870 : NILP (BVAR (buf, begv_marker)) ? buf->begv
871 : marker_position (BVAR (buf, begv_marker)));
872 }
873
874 INLINE ptrdiff_t
875 BUF_BEGV_BYTE (struct buffer *buf)
876 {
877 return (buf == current_buffer ? BEGV_BYTE
878 : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte
879 : marker_byte_position (BVAR (buf, begv_marker)));
880 }
881
882
883 INLINE ptrdiff_t
884 BUF_PT (struct buffer *buf)
885 {
886 return (buf == current_buffer ? PT
887 : NILP (BVAR (buf, pt_marker)) ? buf->pt
888 : marker_position (BVAR (buf, pt_marker)));
889 }
890
891 INLINE ptrdiff_t
892 BUF_PT_BYTE (struct buffer *buf)
893 {
894 return (buf == current_buffer ? PT_BYTE
895 : NILP (BVAR (buf, pt_marker)) ? buf->pt_byte
896 : marker_byte_position (BVAR (buf, pt_marker)));
897 }
898
899
900 INLINE ptrdiff_t
901 BUF_ZV (struct buffer *buf)
902 {
903 return (buf == current_buffer ? ZV
904 : NILP (BVAR (buf, zv_marker)) ? buf->zv
905 : marker_position (BVAR (buf, zv_marker)));
906 }
907
908 INLINE ptrdiff_t
909 BUF_ZV_BYTE (struct buffer *buf)
910 {
911 return (buf == current_buffer ? ZV_BYTE
912 : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte
913 : marker_byte_position (BVAR (buf, zv_marker)));
914 }
915
916
917
918
919 INLINE ptrdiff_t
920 BUF_BEG (struct buffer *buf)
921 {
922 return BEG;
923 }
924
925 INLINE ptrdiff_t
926 BUF_BEG_BYTE (struct buffer *buf)
927 {
928 return BEG_BYTE;
929 }
930
931
932 INLINE unsigned char *
933 BUF_GPT_ADDR (struct buffer *buf)
934 {
935 return buf->text->beg + buf->text->gpt_byte - BEG_BYTE;
936 }
937
938
939 INLINE unsigned char *
940 BUF_Z_ADDR (struct buffer *buf)
941 {
942 return buf->text->beg + buf->text->gap_size + buf->text->z_byte - BEG_BYTE;
943 }
944
945
946 INLINE unsigned char *
947 BUF_GAP_END_ADDR (struct buffer *buf)
948 {
949 return buf->text->beg + buf->text->gpt_byte + buf->text->gap_size - BEG_BYTE;
950 }
951
952
953
954
955
956 INLINE void
957 BUF_COMPUTE_UNCHANGED (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
958 {
959 if (BUF_UNCHANGED_MODIFIED (buf) == BUF_MODIFF (buf)
960 && (BUF_OVERLAY_UNCHANGED_MODIFIED (buf)
961 == BUF_OVERLAY_MODIFF (buf)))
962 {
963 buf->text->beg_unchanged = start - BUF_BEG (buf);
964 buf->text->end_unchanged = BUF_Z (buf) - (end);
965 }
966 else
967 {
968 if (BUF_Z (buf) - end < BUF_END_UNCHANGED (buf))
969 buf->text->end_unchanged = BUF_Z (buf) - end;
970 if (start - BUF_BEG (buf) < BUF_BEG_UNCHANGED (buf))
971 buf->text->beg_unchanged = start - BUF_BEG (buf);
972 }
973 }
974
975
976
977
978
979
980
981
982
983 INLINE void
984 SET_BUF_BEGV (struct buffer *buf, ptrdiff_t charpos)
985 {
986 buf->begv_byte = buf_charpos_to_bytepos (buf, charpos);
987 buf->begv = charpos;
988 }
989
990 INLINE void
991 SET_BUF_ZV (struct buffer *buf, ptrdiff_t charpos)
992 {
993 buf->zv_byte = buf_charpos_to_bytepos (buf, charpos);
994 buf->zv = charpos;
995 }
996
997 INLINE void
998 SET_BUF_BEGV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
999 {
1000 buf->begv = charpos;
1001 buf->begv_byte = byte;
1002 }
1003
1004 INLINE void
1005 SET_BUF_ZV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
1006 {
1007 buf->zv = charpos;
1008 buf->zv_byte = byte;
1009 }
1010
1011 INLINE void
1012 SET_BUF_PT_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
1013 {
1014 buf->pt = charpos;
1015 buf->pt_byte = byte;
1016 }
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027 INLINE unsigned char *
1028 BYTE_POS_ADDR (ptrdiff_t n)
1029 {
1030 return (n < GPT_BYTE ? 0 : GAP_SIZE) + n + BEG_ADDR - BEG_BYTE;
1031 }
1032
1033
1034
1035 INLINE unsigned char *
1036 CHAR_POS_ADDR (ptrdiff_t n)
1037 {
1038 return ((n < GPT ? 0 : GAP_SIZE)
1039 + buf_charpos_to_bytepos (current_buffer, n)
1040 + BEG_ADDR - BEG_BYTE);
1041 }
1042
1043
1044
1045 INLINE ptrdiff_t
1046 CHAR_TO_BYTE (ptrdiff_t charpos)
1047 {
1048 return buf_charpos_to_bytepos (current_buffer, charpos);
1049 }
1050
1051
1052
1053 INLINE ptrdiff_t
1054 BYTE_TO_CHAR (ptrdiff_t bytepos)
1055 {
1056 return buf_bytepos_to_charpos (current_buffer, bytepos);
1057 }
1058
1059
1060
1061 INLINE ptrdiff_t
1062 PTR_BYTE_POS (unsigned char const *ptr)
1063 {
1064 ptrdiff_t byte = ptr - current_buffer->text->beg;
1065 return byte - (byte <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) + BEG_BYTE;
1066 }
1067
1068
1069
1070
1071
1072 enum { BUFFER_LISP_SIZE = PSEUDOVECSIZE (struct buffer,
1073 cursor_in_non_selected_windows_) };
1074
1075
1076
1077
1078 enum { BUFFER_REST_SIZE = VECSIZE (struct buffer) - BUFFER_LISP_SIZE };
1079
1080
1081
1082
1083
1084 INLINE void
1085 BUFFER_PVEC_INIT (struct buffer *b)
1086 {
1087 XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE);
1088 }
1089
1090
1091
1092 INLINE bool
1093 BUFFER_LIVE_P (struct buffer *b)
1094 {
1095 return !NILP (BVAR (b, name));
1096 }
1097
1098
1099
1100
1101 INLINE bool
1102 BUFFER_HIDDEN_P (struct buffer *b)
1103 {
1104 return SREF (BVAR (b, name), 0) == ' ';
1105 }
1106
1107
1108
1109 INLINE void
1110 BUFFER_CHECK_INDIRECTION (struct buffer *b)
1111 {
1112 if (BUFFER_LIVE_P (b))
1113 {
1114 if (b->base_buffer)
1115 {
1116 eassert (b->indirections == -1);
1117 eassert (b->base_buffer->indirections > 0);
1118 }
1119 else
1120 eassert (b->indirections >= 0);
1121 }
1122 }
1123
1124
1125
1126
1127
1128
1129
1130
1131 extern struct buffer buffer_defaults;
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147 extern struct buffer buffer_local_flags;
1148
1149
1150
1151
1152
1153 extern struct buffer buffer_local_symbols;
1154
1155
1156
1157 extern Lisp_Object interval_insert_behind_hooks;
1158 extern Lisp_Object interval_insert_in_front_hooks;
1159
1160
1161 extern EMACS_INT fix_position (Lisp_Object);
1162 #define CHECK_FIXNUM_COERCE_MARKER(x) ((x) = make_fixnum (fix_position (x)))
1163 extern void delete_all_overlays (struct buffer *);
1164 extern void reset_buffer (struct buffer *);
1165 extern void compact_buffer (struct buffer *);
1166 extern ptrdiff_t overlays_at (ptrdiff_t, bool, Lisp_Object **, ptrdiff_t *, ptrdiff_t *);
1167 extern ptrdiff_t overlays_in (ptrdiff_t, ptrdiff_t, bool, Lisp_Object **,
1168 ptrdiff_t *, bool, bool, ptrdiff_t *);
1169 extern ptrdiff_t previous_overlay_change (ptrdiff_t);
1170 extern ptrdiff_t next_overlay_change (ptrdiff_t);
1171 extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
1172 extern void recenter_overlay_lists (struct buffer *, ptrdiff_t);
1173 extern ptrdiff_t overlay_strings (ptrdiff_t, struct window *, unsigned char **);
1174 extern void validate_region (Lisp_Object *, Lisp_Object *);
1175 extern void set_buffer_internal_1 (struct buffer *);
1176 extern void set_buffer_internal_2 (struct buffer *);
1177 extern void set_buffer_temp (struct buffer *);
1178 extern Lisp_Object buffer_local_value (Lisp_Object, Lisp_Object);
1179 extern void record_buffer (Lisp_Object);
1180 extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
1181 extern void mmap_set_vars (bool);
1182 extern void restore_buffer (Lisp_Object);
1183 extern void set_buffer_if_live (Lisp_Object);
1184 extern Lisp_Object build_overlay (bool, bool, Lisp_Object);
1185
1186
1187
1188 INLINE struct buffer *
1189 decode_buffer (Lisp_Object b)
1190 {
1191 return NILP (b) ? current_buffer : (CHECK_BUFFER (b), XBUFFER (b));
1192 }
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203 INLINE void
1204 set_buffer_internal (struct buffer *b)
1205 {
1206 if (current_buffer != b)
1207 set_buffer_internal_1 (b);
1208 }
1209
1210
1211
1212
1213 INLINE void
1214 record_unwind_current_buffer (void)
1215 {
1216 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
1217 }
1218
1219
1220
1221
1222
1223
1224
1225 #define GET_OVERLAYS_AT(posn, overlays, noverlays, next) \
1226 do { \
1227 ptrdiff_t maxlen = 40; \
1228 SAFE_NALLOCA (overlays, 1, maxlen); \
1229 (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, next); \
1230 if ((noverlays) > maxlen) \
1231 { \
1232 maxlen = noverlays; \
1233 SAFE_NALLOCA (overlays, 1, maxlen); \
1234 (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, next); \
1235 } \
1236 } while (false)
1237
1238 extern Lisp_Object Vbuffer_alist;
1239
1240
1241
1242
1243 #define FOR_EACH_LIVE_BUFFER(list_var, buf_var) \
1244 FOR_EACH_ALIST_VALUE (Vbuffer_alist, list_var, buf_var)
1245
1246
1247
1248 INLINE INTERVAL
1249 buffer_intervals (struct buffer *b)
1250 {
1251 eassert (b->text != NULL);
1252 return b->text->intervals;
1253 }
1254
1255
1256
1257 INLINE void
1258 set_buffer_intervals (struct buffer *b, INTERVAL i)
1259 {
1260 eassert (b->text != NULL);
1261 b->text->intervals = i;
1262 }
1263
1264
1265
1266 INLINE bool
1267 buffer_has_overlays (void)
1268 {
1269 return current_buffer->overlays
1270 && (current_buffer->overlays->root != NULL);
1271 }
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281 INLINE int
1282 FETCH_MULTIBYTE_CHAR (ptrdiff_t pos)
1283 {
1284 unsigned char *p = BYTE_POS_ADDR (pos);
1285 return STRING_CHAR (p);
1286 }
1287
1288
1289
1290
1291
1292 INLINE int
1293 BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
1294 {
1295 unsigned char *p
1296 = ((pos >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0)
1297 + pos + BUF_BEG_ADDR (buf) - BEG_BYTE);
1298 return STRING_CHAR (p);
1299 }
1300
1301
1302
1303
1304
1305 INLINE int
1306 FETCH_CHAR_AS_MULTIBYTE (ptrdiff_t pos)
1307 {
1308 return (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1309 ? FETCH_MULTIBYTE_CHAR (pos)
1310 : UNIBYTE_TO_CHAR (FETCH_BYTE (pos)));
1311 }
1312
1313
1314
1315
1316 INLINE int
1317 FETCH_CHAR (ptrdiff_t pos)
1318 {
1319 return (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1320 ? FETCH_MULTIBYTE_CHAR (pos)
1321 : FETCH_BYTE (pos));
1322 }
1323
1324
1325
1326
1327 INLINE unsigned char *
1328 BUF_BYTE_ADDRESS (struct buffer *buf, ptrdiff_t pos)
1329 {
1330 return (buf->text->beg + pos - BEG_BYTE
1331 + (pos < buf->text->gpt_byte ? 0 : buf->text->gap_size));
1332 }
1333
1334
1335
1336
1337 INLINE unsigned char *
1338 BUF_CHAR_ADDRESS (struct buffer *buf, ptrdiff_t pos)
1339 {
1340 return (buf->text->beg + buf_charpos_to_bytepos (buf, pos) - BEG_BYTE
1341 + (pos < buf->text->gpt ? 0 : buf->text->gap_size));
1342 }
1343
1344
1345
1346
1347 INLINE ptrdiff_t
1348 BUF_PTR_BYTE_POS (struct buffer *buf, unsigned char *ptr)
1349 {
1350 ptrdiff_t byte = ptr - buf->text->beg;
1351 return (byte - (byte <= BUF_GPT_BYTE (buf) - BEG_BYTE ? 0 : BUF_GAP_SIZE (buf))
1352 + BEG_BYTE);
1353 }
1354
1355
1356
1357 INLINE unsigned char
1358 BUF_FETCH_BYTE (struct buffer *buf, ptrdiff_t n)
1359 {
1360 return *BUF_BYTE_ADDRESS (buf, n);
1361 }
1362
1363
1364
1365
1366
1367 INLINE int
1368 BUF_FETCH_CHAR_AS_MULTIBYTE (struct buffer *buf, ptrdiff_t pos)
1369 {
1370 return (! NILP (BVAR (buf, enable_multibyte_characters))
1371 ? BUF_FETCH_MULTIBYTE_CHAR (buf, pos)
1372 : UNIBYTE_TO_CHAR (BUF_FETCH_BYTE (buf, pos)));
1373 }
1374
1375
1376
1377 INLINE int
1378 buffer_window_count (struct buffer *b)
1379 {
1380 if (b->base_buffer)
1381 b = b->base_buffer;
1382 eassert (b->window_count >= 0);
1383 return b->window_count;
1384 }
1385
1386
1387
1388 INLINE ptrdiff_t
1389 overlay_start (struct Lisp_Overlay *ov)
1390 {
1391 if (! ov->buffer)
1392 return -1;
1393 return itree_node_begin (ov->buffer->overlays, ov->interval);
1394 }
1395
1396 INLINE ptrdiff_t
1397 overlay_end (struct Lisp_Overlay *ov)
1398 {
1399 if (! ov->buffer)
1400 return -1;
1401 return itree_node_end (ov->buffer->overlays, ov->interval);
1402 }
1403
1404
1405
1406
1407 INLINE ptrdiff_t
1408 OVERLAY_START (Lisp_Object ov)
1409 {
1410 return overlay_start (XOVERLAY (ov));
1411 }
1412
1413
1414
1415 INLINE ptrdiff_t
1416 OVERLAY_END (Lisp_Object ov)
1417 {
1418 return overlay_end (XOVERLAY (ov));
1419 }
1420
1421
1422
1423 INLINE Lisp_Object
1424 OVERLAY_PLIST (Lisp_Object ov)
1425 {
1426 return XOVERLAY (ov)->plist;
1427 }
1428
1429
1430
1431 INLINE struct buffer *
1432 OVERLAY_BUFFER (Lisp_Object ov)
1433 {
1434 return XOVERLAY (ov)->buffer;
1435 }
1436
1437
1438
1439 INLINE bool
1440 OVERLAY_REAR_ADVANCE_P (Lisp_Object ov)
1441 {
1442 return XOVERLAY (ov)->interval->rear_advance;
1443 }
1444
1445
1446
1447 INLINE bool
1448 OVERLAY_FRONT_ADVANCE_P (Lisp_Object ov)
1449 {
1450 return XOVERLAY (ov)->interval->front_advance;
1451 }
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461 #define PER_BUFFER_VAR_OFFSET(VAR) \
1462 offsetof (struct buffer, VAR ## _)
1463
1464
1465
1466
1467
1468 #define FOR_EACH_PER_BUFFER_OBJECT_AT(offset) \
1469 for (offset = PER_BUFFER_VAR_OFFSET (name); \
1470 offset <= PER_BUFFER_VAR_OFFSET (cursor_in_non_selected_windows); \
1471 offset += word_size)
1472
1473
1474
1475
1476
1477
1478
1479 #define PER_BUFFER_VAR_IDX(VAR) \
1480 PER_BUFFER_IDX (PER_BUFFER_VAR_OFFSET (VAR))
1481
1482 extern bool valid_per_buffer_idx (int);
1483
1484
1485
1486
1487 INLINE bool
1488 PER_BUFFER_VALUE_P (struct buffer *b, int idx)
1489 {
1490 eassert (valid_per_buffer_idx (idx));
1491 return b->local_flags[idx];
1492 }
1493
1494
1495
1496
1497 INLINE void
1498 SET_PER_BUFFER_VALUE_P (struct buffer *b, int idx, bool val)
1499 {
1500 eassert (valid_per_buffer_idx (idx));
1501 b->local_flags[idx] = val;
1502 }
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524 INLINE int
1525 PER_BUFFER_IDX (ptrdiff_t offset)
1526 {
1527 return XFIXNUM (*(Lisp_Object *) (offset + (char *) &buffer_local_flags));
1528 }
1529
1530
1531
1532
1533 INLINE Lisp_Object
1534 per_buffer_default (int offset)
1535 {
1536 return *(Lisp_Object *)(offset + (char *) &buffer_defaults);
1537 }
1538
1539 INLINE void
1540 set_per_buffer_default (int offset, Lisp_Object value)
1541 {
1542 *(Lisp_Object *)(offset + (char *) &buffer_defaults) = value;
1543 }
1544
1545
1546
1547
1548 INLINE Lisp_Object
1549 per_buffer_value (struct buffer *b, int offset)
1550 {
1551 return *(Lisp_Object *)(offset + (char *) b);
1552 }
1553
1554 INLINE void
1555 set_per_buffer_value (struct buffer *b, int offset, Lisp_Object value)
1556 {
1557 *(Lisp_Object *)(offset + (char *) b) = value;
1558 }
1559
1560
1561 INLINE int
1562 downcase (int c)
1563 {
1564 Lisp_Object downcase_table = BVAR (current_buffer, downcase_table);
1565 Lisp_Object down = CHAR_TABLE_REF (downcase_table, c);
1566 return FIXNATP (down) ? XFIXNAT (down) : c;
1567 }
1568
1569
1570 INLINE int
1571 upcase (int c)
1572 {
1573 Lisp_Object upcase_table = BVAR (current_buffer, upcase_table);
1574 Lisp_Object up = CHAR_TABLE_REF (upcase_table, c);
1575 return FIXNATP (up) ? XFIXNAT (up) : c;
1576 }
1577
1578
1579 INLINE bool
1580 uppercasep (int c)
1581 {
1582 return downcase (c) != c;
1583 }
1584
1585
1586 INLINE bool
1587 lowercasep (int c)
1588 {
1589 return !uppercasep (c) && upcase (c) != c;
1590 }
1591
1592
1593
1594 INLINE int
1595 sanitize_tab_width (Lisp_Object width)
1596 {
1597 return (FIXNUMP (width) && 0 < XFIXNUM (width) && XFIXNUM (width) <= 1000
1598 ? XFIXNUM (width) : 8);
1599 }
1600
1601 INLINE int
1602 SANE_TAB_WIDTH (struct buffer *buf)
1603 {
1604 return sanitize_tab_width (BVAR (buf, tab_width));
1605 }
1606
1607
1608
1609 INLINE int
1610 sanitize_char_width (EMACS_INT width)
1611 {
1612 return 0 <= width && width <= 1000 ? width : 1000;
1613 }
1614
1615
1616
1617
1618
1619
1620 INLINE int
1621 CHARACTER_WIDTH (int c)
1622 {
1623 return (0x20 <= c && c < 0x7f ? 1
1624 : 0x7f < c ? (sanitize_char_width
1625 (XFIXNUM (CHAR_TABLE_REF (Vchar_width_table, c))))
1626 : c == '\t' ? SANE_TAB_WIDTH (current_buffer)
1627 : c == '\n' ? 0
1628 : !NILP (BVAR (current_buffer, ctl_arrow)) ? 2 : 4);
1629 }
1630
1631
1632
1633
1634
1635 INLINE int
1636 fetch_char_advance (ptrdiff_t *charidx, ptrdiff_t *byteidx)
1637 {
1638 int output;
1639 ptrdiff_t c = *charidx, b = *byteidx;
1640 c++;
1641 unsigned char *chp = BYTE_POS_ADDR (b);
1642 if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
1643 {
1644 int chlen;
1645 output = string_char_and_length (chp, &chlen);
1646 b += chlen;
1647 }
1648 else
1649 {
1650 output = *chp;
1651 b++;
1652 }
1653 *charidx = c;
1654 *byteidx = b;
1655 return output;
1656 }
1657
1658
1659
1660
1661 INLINE int
1662 fetch_char_advance_no_check (ptrdiff_t *charidx, ptrdiff_t *byteidx)
1663 {
1664 int output;
1665 ptrdiff_t c = *charidx, b = *byteidx;
1666 c++;
1667 unsigned char *chp = BYTE_POS_ADDR (b);
1668 int chlen;
1669 output = string_char_and_length (chp, &chlen);
1670 b += chlen;
1671 *charidx = c;
1672 *byteidx = b;
1673 return output;
1674 }
1675
1676
1677
1678
1679
1680
1681 INLINE int
1682 buf_next_char_len (struct buffer *buf, ptrdiff_t pos_byte)
1683 {
1684 unsigned char *chp = BUF_BYTE_ADDRESS (buf, pos_byte);
1685 return BYTES_BY_CHAR_HEAD (*chp);
1686 }
1687
1688 INLINE int
1689 next_char_len (ptrdiff_t pos_byte)
1690 {
1691 return buf_next_char_len (current_buffer, pos_byte);
1692 }
1693
1694
1695
1696
1697 INLINE int
1698 buf_prev_char_len (struct buffer *buf, ptrdiff_t pos_byte)
1699 {
1700 unsigned char *chp
1701 = (BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE
1702 + (pos_byte <= BUF_GPT_BYTE (buf) ? 0 : BUF_GAP_SIZE (buf)));
1703 return raw_prev_char_len (chp);
1704 }
1705
1706 INLINE int
1707 prev_char_len (ptrdiff_t pos_byte)
1708 {
1709 return buf_prev_char_len (current_buffer, pos_byte);
1710 }
1711
1712
1713
1714 INLINE void
1715 inc_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
1716 {
1717 (*charpos)++;
1718 (*bytepos) += (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1719 ? next_char_len (*bytepos) : 1);
1720 }
1721
1722
1723
1724 INLINE void
1725 dec_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
1726 {
1727 (*charpos)--;
1728 (*bytepos) -= (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1729 ? prev_char_len (*bytepos) : 1);
1730 }
1731
1732 INLINE_HEADER_END
1733
1734 int compare_overlays (const void *v1, const void *v2);
1735 void make_sortvec_item (struct sortvec *item, Lisp_Object overlay);
1736
1737 #endif