aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.h
diff options
context:
space:
mode:
authorStephen Berman2013-06-14 22:07:55 +0200
committerStephen Berman2013-06-14 22:07:55 +0200
commitbd358779861f265a7acff31ead40172735af693e (patch)
tree345217a9889dbd29b09bdc80a94265c17719d41f /src/buffer.h
parent2a97b47f0878cbda86cb6ba0e7e744924810b70e (diff)
parentf7394b12358ae453a0c8b85fc307afc1b740010d (diff)
downloademacs-bd358779861f265a7acff31ead40172735af693e.tar.gz
emacs-bd358779861f265a7acff31ead40172735af693e.zip
Merge from trunk.
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h132
1 files changed, 96 insertions, 36 deletions
diff --git a/src/buffer.h b/src/buffer.h
index d18ef30ea38..276cca32e48 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1,7 +1,7 @@
1/* Header file for the buffer manipulation primitives. 1/* Header file for the buffer manipulation primitives.
2 2
3Copyright (C) 1985-1986, 1993-1995, 1997-2012 3Copyright (C) 1985-1986, 1993-1995, 1997-2013 Free Software Foundation,
4 Free Software Foundation, Inc. 4Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
7 7
@@ -82,9 +82,6 @@ INLINE_HEADER_BEGIN
82/* Size of gap. */ 82/* Size of gap. */
83#define GAP_SIZE (current_buffer->text->gap_size) 83#define GAP_SIZE (current_buffer->text->gap_size)
84 84
85/* Is the current buffer narrowed? */
86#define NARROWED ((BEGV != BEG) || (ZV != Z))
87
88/* Modification count. */ 85/* Modification count. */
89#define MODIFF (current_buffer->text->modiff) 86#define MODIFF (current_buffer->text->modiff)
90 87
@@ -173,10 +170,6 @@ INLINE_HEADER_BEGIN
173/* Size of gap. */ 170/* Size of gap. */
174#define BUF_GAP_SIZE(buf) ((buf)->text->gap_size) 171#define BUF_GAP_SIZE(buf) ((buf)->text->gap_size)
175 172
176/* Is this buffer narrowed? */
177#define BUF_NARROWED(buf) ((BUF_BEGV (buf) != BUF_BEG (buf)) \
178 || (BUF_ZV (buf) != BUF_Z (buf)))
179
180/* Modification count. */ 173/* Modification count. */
181#define BUF_MODIFF(buf) ((buf)->text->modiff) 174#define BUF_MODIFF(buf) ((buf)->text->modiff)
182 175
@@ -193,6 +186,9 @@ INLINE_HEADER_BEGIN
193/* FIXME: should we move this into ->text->auto_save_modiff? */ 186/* FIXME: should we move this into ->text->auto_save_modiff? */
194#define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified) 187#define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified)
195 188
189/* Compaction count. */
190#define BUF_COMPACT(buf) ((buf)->text->compact)
191
196/* Marker chain of buffer. */ 192/* Marker chain of buffer. */
197#define BUF_MARKERS(buf) ((buf)->text->markers) 193#define BUF_MARKERS(buf) ((buf)->text->markers)
198 194
@@ -291,24 +287,24 @@ extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
291/* Access a Lisp position value in POS, 287/* Access a Lisp position value in POS,
292 and store the charpos in CHARPOS and the bytepos in BYTEPOS. */ 288 and store the charpos in CHARPOS and the bytepos in BYTEPOS. */
293 289
294#define DECODE_POSITION(charpos, bytepos, pos) \ 290#define DECODE_POSITION(charpos, bytepos, pos) \
295do \ 291 do \
296 { \ 292 { \
297 Lisp_Object __pos = (pos); \ 293 Lisp_Object __pos = (pos); \
298 if (NUMBERP (__pos)) \ 294 if (NUMBERP (__pos)) \
299 { \ 295 { \
300 charpos = __pos; \ 296 charpos = __pos; \
301 bytepos = buf_charpos_to_bytepos (current_buffer, __pos); \ 297 bytepos = buf_charpos_to_bytepos (current_buffer, __pos); \
302 } \ 298 } \
303 else if (MARKERP (__pos)) \ 299 else if (MARKERP (__pos)) \
304 { \ 300 { \
305 charpos = marker_position (__pos); \ 301 charpos = marker_position (__pos); \
306 bytepos = marker_byte_position (__pos); \ 302 bytepos = marker_byte_position (__pos); \
307 } \ 303 } \
308 else \ 304 else \
309 wrong_type_argument (Qinteger_or_marker_p, __pos); \ 305 wrong_type_argument (Qinteger_or_marker_p, __pos); \
310 } \ 306 } \
311while (0) 307 while (0)
312 308
313/* Maximum number of bytes in a buffer. 309/* Maximum number of bytes in a buffer.
314 A buffer cannot contain more bytes than a 1-origin fixnum can represent, 310 A buffer cannot contain more bytes than a 1-origin fixnum can represent,
@@ -317,6 +313,16 @@ while (0)
317#define BUF_BYTES_MAX \ 313#define BUF_BYTES_MAX \
318 (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX)) 314 (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
319 315
316/* Maximum gap size after compact_buffer, in bytes. Also
317 used in make_gap_larger to get some extra reserved space. */
318
319#define GAP_BYTES_DFL 2000
320
321/* Minimum gap size after compact_buffer, in bytes. Also
322 used in make_gap_smaller to avoid too small gap size. */
323
324#define GAP_BYTES_MIN 20
325
320/* Return the address of byte position N in current buffer. */ 326/* Return the address of byte position N in current buffer. */
321 327
322#define BYTE_POS_ADDR(n) \ 328#define BYTE_POS_ADDR(n) \
@@ -482,11 +488,6 @@ struct buffer_text
482 488
483struct buffer 489struct buffer
484{ 490{
485 /* HEADER.NEXT is the next buffer, in chain of all buffers, including killed
486 buffers. This chain, starting from all_buffers, is used only for garbage
487 collection, in order to collect killed buffers properly. Note that large
488 vectors and large pseudo-vector objects are all on another chain starting
489 from large_vectors. */
490 struct vectorlike_header header; 491 struct vectorlike_header header;
491 492
492 /* The name of this buffer. */ 493 /* The name of this buffer. */
@@ -750,6 +751,9 @@ struct buffer
750 In an indirect buffer, this is the own_text field of another buffer. */ 751 In an indirect buffer, this is the own_text field of another buffer. */
751 struct buffer_text *text; 752 struct buffer_text *text;
752 753
754 /* Next buffer, in chain of all buffers, including killed ones. */
755 struct buffer *next;
756
753 /* Char position of point in buffer. */ 757 /* Char position of point in buffer. */
754 ptrdiff_t pt; 758 ptrdiff_t pt;
755 759
@@ -772,11 +776,15 @@ struct buffer
772 In an ordinary buffer, it is 0. */ 776 In an ordinary buffer, it is 0. */
773 struct buffer *base_buffer; 777 struct buffer *base_buffer;
774 778
775 /* In an indirect buffer, this is -1. In an ordinary buffer, 779 /* In an indirect buffer, this is -1. In an ordinary buffer,
776 it's the number of indirect buffers that share our text; 780 it's the number of indirect buffers that share our text;
777 zero means that we're the only owner of this text. */ 781 zero means that we're the only owner of this text. */
778 int indirections; 782 int indirections;
779 783
784 /* Number of windows showing this buffer. Always -1 for
785 an indirect buffer since it counts as its base buffer. */
786 int window_count;
787
780 /* A non-zero value in slot IDX means that per-buffer variable 788 /* A non-zero value in slot IDX means that per-buffer variable
781 with index IDX has a local value in this buffer. The index IDX 789 with index IDX has a local value in this buffer. The index IDX
782 for a buffer-local variable is stored in that variable's slot 790 for a buffer-local variable is stored in that variable's slot
@@ -959,10 +967,52 @@ bset_width_table (struct buffer *b, Lisp_Object val)
959 b->INTERNAL_FIELD (width_table) = val; 967 b->INTERNAL_FIELD (width_table) = val;
960} 968}
961 969
970/* Number of Lisp_Objects at the beginning of struct buffer.
971 If you add, remove, or reorder Lisp_Objects within buffer
972 structure, make sure that this is still correct. */
973
974#define BUFFER_LISP_SIZE \
975 ((offsetof (struct buffer, own_text) - header_size) / word_size)
976
977/* Size of the struct buffer part beyond leading Lisp_Objects, in word_size
978 units. Rounding is needed for --with-wide-int configuration. */
979
980#define BUFFER_REST_SIZE \
981 ((((sizeof (struct buffer) - offsetof (struct buffer, own_text)) \
982 + (word_size - 1)) & ~(word_size - 1)) / word_size)
983
984/* Initialize the pseudovector header of buffer object. BUFFER_LISP_SIZE
985 is required for GC, but BUFFER_REST_SIZE is set up just to be consistent
986 with other pseudovectors. */
987
988#define BUFFER_PVEC_INIT(b) \
989 XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE)
990
962/* Convenient check whether buffer B is live. */ 991/* Convenient check whether buffer B is live. */
963 992
964#define BUFFER_LIVE_P(b) (!NILP (BVAR (b, name))) 993#define BUFFER_LIVE_P(b) (!NILP (BVAR (b, name)))
965 994
995/* Convenient check whether buffer B is hidden (i.e. its name
996 starts with a space). Caller must ensure that B is live. */
997
998#define BUFFER_HIDDEN_P(b) (SREF (BVAR (b, name), 0) == ' ')
999
1000/* Verify indirection counters. */
1001
1002#define BUFFER_CHECK_INDIRECTION(b) \
1003 do { \
1004 if (BUFFER_LIVE_P (b)) \
1005 { \
1006 if (b->base_buffer) \
1007 { \
1008 eassert (b->indirections == -1); \
1009 eassert (b->base_buffer->indirections > 0); \
1010 } \
1011 else \
1012 eassert (b->indirections >= 0); \
1013 } \
1014 } while (0)
1015
966/* Chain of all buffers, including killed ones. */ 1016/* Chain of all buffers, including killed ones. */
967 1017
968extern struct buffer *all_buffers; 1018extern struct buffer *all_buffers;
@@ -970,7 +1020,7 @@ extern struct buffer *all_buffers;
970/* Used to iterate over the chain above. */ 1020/* Used to iterate over the chain above. */
971 1021
972#define FOR_EACH_BUFFER(b) \ 1022#define FOR_EACH_BUFFER(b) \
973 for ((b) = all_buffers; (b); (b) = (b)->header.next.buffer) 1023 for ((b) = all_buffers; (b); (b) = (b)->next)
974 1024
975/* This points to the current buffer. */ 1025/* This points to the current buffer. */
976 1026
@@ -1021,7 +1071,6 @@ extern void set_buffer_internal_1 (struct buffer *);
1021extern void set_buffer_temp (struct buffer *); 1071extern void set_buffer_temp (struct buffer *);
1022extern Lisp_Object buffer_local_value_1 (Lisp_Object, Lisp_Object); 1072extern Lisp_Object buffer_local_value_1 (Lisp_Object, Lisp_Object);
1023extern void record_buffer (Lisp_Object); 1073extern void record_buffer (Lisp_Object);
1024extern _Noreturn void buffer_slot_type_mismatch (Lisp_Object, int);
1025extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t); 1074extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
1026extern void mmap_set_vars (bool); 1075extern void mmap_set_vars (bool);
1027 1076
@@ -1133,7 +1182,18 @@ BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
1133 + pos + BUF_BEG_ADDR (buf) - BEG_BYTE); 1182 + pos + BUF_BEG_ADDR (buf) - BEG_BYTE);
1134 return STRING_CHAR (p); 1183 return STRING_CHAR (p);
1135} 1184}
1136 1185
1186/* Return number of windows showing B. */
1187
1188BUFFER_INLINE int
1189buffer_window_count (struct buffer *b)
1190{
1191 if (b->base_buffer)
1192 b = b->base_buffer;
1193 eassert (b->window_count >= 0);
1194 return b->window_count;
1195}
1196
1137/* Overlays */ 1197/* Overlays */
1138 1198
1139/* Return the marker that stands for where OV starts in the buffer. */ 1199/* Return the marker that stands for where OV starts in the buffer. */