aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.h
diff options
context:
space:
mode:
authorRichard M. Stallman1998-01-01 06:49:17 +0000
committerRichard M. Stallman1998-01-01 06:49:17 +0000
commit69f9064e5dc5be3b2503726c0d8f90e9a47ac4cd (patch)
tree2178a9e4db21a09645e00279f35d494a418e54c8 /src/buffer.h
parentdc33013920608a286554f6b48aa645532d589892 (diff)
downloademacs-69f9064e5dc5be3b2503726c0d8f90e9a47ac4cd.tar.gz
emacs-69f9064e5dc5be3b2503726c0d8f90e9a47ac4cd.zip
(DECODE_POSITION): New macro.
(CHAR_TO_BYTE, BYTE_TO_CHAR): New macros. (BEG_BYTE, BEGV_BYTE, PT_BYTE, GPT_BYTE) (ZV_BYTE, Z_BYTE): New macros. (BUF_BEG_BYTE, BUF_BEGV_BYTE, BUF_PT_BYTE, BUF_GPT_BYTE) (BUF_ZV_BYTE, BUF_Z_BYTE): New macros. (BUF_GAP_END_ADDR): New macro. (BEGV_ADDR, PT_ADDR, GPT_ADDR, GAP_END_ADDR, ZV_ADDR, Z_ADDR): Use the new ..._byte buffer data. (BUFFER_CEILING_OF, BUFFER_FLOOR_OF): Likewise. (BUF_GPT_ADDR, BUF_Z_ADDR): Likewise. (SET_PT_BOTH, TEMP_SET_PT_BOTH): New macros. (SET_PT, TEMP_SET_PT, BUF_SET_PT, BUF_TEMP_SET_PT): Call functions with new arg order. (SET_BUF_BEGV, SET_BUF_BEGV_BOTH): New macros. (SET_BUF_PT): Macro deleted. (SET_BUF_ZV): Set charpos and bytepos. (SET_BUF_ZV_BOTH, SET_BUF_PT_BOTH): New macros. (BYTE_POS_ADDR): Renamed from POS_ADDR. (CHAR_POS_ADDR): New macro. (FETCH_BYTE): Use BYTE_POS_ADDR. (FETCH_MULTIBYTE_CHAR): Use ..._BYTE macros. (BUF_CHAR_ADDRESS): Convert charpos to bytepos. (BUF_BYTE_ADDRESS): New macro, like the old BUF_CHAR_ADDRESS. (PTR_BYTE_POS): Renamed from PTR_CHAR_POS. (BUF_PTR_BYTE_POS): New macro. (BUF_FETCH_CHAR, BUF_FETCH_BYTE, BUF_FETCH_MULTIBYTE_CHAR): New macros. (struct buffer_text): New fields gpt_byte, z_byte. (struct buffer): New fields pt_byte, begv_byte, zv_byte.
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h395
1 files changed, 283 insertions, 112 deletions
diff --git a/src/buffer.h b/src/buffer.h
index c47d6a7300b..1be2b232bbc 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1,5 +1,5 @@
1/* Header file for the buffer manipulation primitives. 1/* Header file for the buffer manipulation primitives.
2 Copyright (C) 1985, 1986, 1993, 1994, 1995 Free Software Foundation, Inc. 2 Copyright (C) 1985, 86, 93, 94, 95, 1997 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -19,102 +19,127 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21 21
22#ifdef USE_TEXT_PROPERTIES 22/* Accessing the parameters of the current buffer. */
23#define SET_PT(position) (set_point ((position), current_buffer))
24#define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer))
25
26#define BUF_SET_PT(buffer, position) (set_point ((position), (buffer)))
27#define BUF_TEMP_SET_PT(buffer, position) (temp_set_point ((position), (buffer)))
28
29extern void set_point P_ ((int, struct buffer *));
30extern INLINE void temp_set_point P_ ((int, struct buffer *));
31
32#else /* don't support text properties */
33 23
34#define SET_PT(position) (current_buffer->pt = (position)) 24/* These macros come in pairs, one for the char position
35#define TEMP_SET_PT(position) (current_buffer->pt = (position)) 25 and one for the byte position. */
36
37#define BUF_SET_PT(buffer, position) (buffer->pt = (position))
38#define BUF_TEMP_SET_PT(buffer, position) (buffer->pt = (position))
39#endif /* don't support text properties */
40 26
41/* Character position of beginning of buffer. */ 27/* Position of beginning of buffer. */
42#define BEG (1) 28#define BEG (1)
29#define BEG_BYTE (1)
43 30
44/* Character position of beginning of accessible range of buffer. */ 31/* Position of beginning of accessible range of buffer. */
45#define BEGV (current_buffer->begv) 32#define BEGV (current_buffer->begv)
33#define BEGV_BYTE (current_buffer->begv_byte)
46 34
47/* Character position of point in buffer. The "+ 0" makes this 35/* Position of point in buffer. The "+ 0" makes this
48 not an l-value, so you can't assign to it. Use SET_PT instead. */ 36 not an l-value, so you can't assign to it. Use SET_PT instead. */
49#define PT (current_buffer->pt + 0) 37#define PT (current_buffer->pt + 0)
38#define PT_BYTE (current_buffer->pt_byte + 0)
50 39
51/* Character position of gap in buffer. */ 40/* Position of gap in buffer. */
52#define GPT (current_buffer->text->gpt) 41#define GPT (current_buffer->text->gpt)
42#define GPT_BYTE (current_buffer->text->gpt_byte)
53 43
54/* Character position of end of accessible range of buffer. */ 44/* Position of end of accessible range of buffer. */
55#define ZV (current_buffer->zv) 45#define ZV (current_buffer->zv)
46#define ZV_BYTE (current_buffer->zv_byte)
56 47
57/* Character position of end of buffer. */ 48/* Position of end of buffer. */
58#define Z (current_buffer->text->z) 49#define Z (current_buffer->text->z)
50#define Z_BYTE (current_buffer->text->z_byte)
59 51
60/* Is the current buffer narrowed? */ 52/* Macros for the addresses of places in the buffer. */
61#define NARROWED ((BEGV != BEG) || (ZV != Z))
62
63/* Modification count. */
64#define MODIFF (current_buffer->text->modiff)
65
66/* Overlay modification count. */
67#define OVERLAY_MODIFF (current_buffer->text->overlay_modiff)
68
69/* Modification count as of last visit or save. */
70#define SAVE_MODIFF (current_buffer->text->save_modiff)
71 53
72/* Address of beginning of buffer. */ 54/* Address of beginning of buffer. */
73#define BEG_ADDR (current_buffer->text->beg) 55#define BEG_ADDR (current_buffer->text->beg)
74 56
75/* Address of beginning of accessible range of buffer. */ 57/* Address of beginning of accessible range of buffer. */
76#define BEGV_ADDR (POS_ADDR (current_buffer->begv)) 58#define BEGV_ADDR (BYTE_POS_ADDR (current_buffer->begv_byte))
77 59
78/* Address of point in buffer. */ 60/* Address of point in buffer. */
79#define PT_ADDR (POS_ADDR (current_buffer->pt)) 61#define PT_ADDR (BYTE_POS_ADDR (current_buffer->pt_byte))
80 62
81/* Address of beginning of gap in buffer. */ 63/* Address of beginning of gap in buffer. */
82#define GPT_ADDR (current_buffer->text->beg + current_buffer->text->gpt - 1) 64#define GPT_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte - 1)
83 65
84/* Address of end of gap in buffer. */ 66/* Address of end of gap in buffer. */
85#define GAP_END_ADDR (current_buffer->text->beg + current_buffer->text->gpt + current_buffer->text->gap_size - 1) 67#define GAP_END_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte + current_buffer->text->gap_size - 1)
86 68
87/* Address of end of accessible range of buffer. */ 69/* Address of end of accessible range of buffer. */
88#define ZV_ADDR (POS_ADDR (current_buffer->zv)) 70#define ZV_ADDR (BYTE_POS_ADDR (current_buffer->zv_byte))
89 71
90/* Address of end of buffer. */ 72/* Address of end of buffer. */
91#define Z_ADDR (current_buffer->text->beg + current_buffer->text->gap_size + current_buffer->text->z - 1) 73#define Z_ADDR (current_buffer->text->beg + current_buffer->text->gap_size + current_buffer->text->z_byte - 1)
92 74
93/* Size of gap. */ 75/* Size of gap. */
94#define GAP_SIZE (current_buffer->text->gap_size) 76#define GAP_SIZE (current_buffer->text->gap_size)
95 77
96/* Now similar macros for a specified buffer. 78/* Is the current buffer narrowed? */
79#define NARROWED ((BEGV != BEG) || (ZV != Z))
80
81/* Modification count. */
82#define MODIFF (current_buffer->text->modiff)
83
84/* Overlay modification count. */
85#define OVERLAY_MODIFF (current_buffer->text->overlay_modiff)
86
87/* Modification count as of last visit or save. */
88#define SAVE_MODIFF (current_buffer->text->save_modiff)
89
90/* BUFFER_CEILING_OF (resp. BUFFER_FLOOR_OF), when applied to n, return
91 the max (resp. min) p such that
92
93 BYTE_POS_ADDR (p) - BYTE_POS_ADDR (n) == p - n */
94
95#define BUFFER_CEILING_OF(BYTEPOS) \
96 (((BYTEPOS) < GPT_BYTE && GPT < ZV ? GPT_BYTE : ZV_BYTE) - 1)
97#define BUFFER_FLOOR_OF(BYTEPOS) \
98 (BEGV <= GPT && GPT_BYTE <= (BYTEPOS) ? GPT_BYTE : BEGV_BYTE)
99
100/* Similar macros to operate on a specified buffer.
97 Note that many of these evaluate the buffer argument more than once. */ 101 Note that many of these evaluate the buffer argument more than once. */
98 102
99/* Character position of beginning of buffer. */ 103/* Position of beginning of buffer. */
100#define BUF_BEG(buf) (1) 104#define BUF_BEG(buf) (1)
105#define BUF_BEG_BYTE(buf) (1)
101 106
102/* Character position of beginning of accessible range of buffer. */ 107/* Position of beginning of accessible range of buffer. */
103#define BUF_BEGV(buf) ((buf)->begv) 108#define BUF_BEGV(buf) ((buf)->begv)
109#define BUF_BEGV_BYTE(buf) ((buf)->begv_byte)
104 110
105/* Character position of point in buffer. */ 111/* Position of point in buffer. */
106#define BUF_PT(buf) ((buf)->pt) 112#define BUF_PT(buf) ((buf)->pt)
113#define BUF_PT_BYTE(buf) ((buf)->pt_byte)
107 114
108/* Character position of gap in buffer. */ 115/* Position of gap in buffer. */
109#define BUF_GPT(buf) ((buf)->text->gpt) 116#define BUF_GPT(buf) ((buf)->text->gpt)
117#define BUF_GPT_BYTE(buf) ((buf)->text->gpt_byte)
110 118
111/* Character position of end of accessible range of buffer. */ 119/* Position of end of accessible range of buffer. */
112#define BUF_ZV(buf) ((buf)->zv) 120#define BUF_ZV(buf) ((buf)->zv)
121#define BUF_ZV_BYTE(buf) ((buf)->zv_byte)
113 122
114/* Character position of end of buffer. */ 123/* Position of end of buffer. */
115#define BUF_Z(buf) ((buf)->text->z) 124#define BUF_Z(buf) ((buf)->text->z)
125#define BUF_Z_BYTE(buf) ((buf)->text->z_byte)
126
127/* Address of beginning of buffer. */
128#define BUF_BEG_ADDR(buf) ((buf)->text->beg)
129
130/* Address of beginning of gap of buffer. */
131#define BUF_GPT_ADDR(buf) ((buf)->text->beg + (buf)->text->gpt_byte - 1)
132
133/* Address of end of buffer. */
134#define BUF_Z_ADDR(buf) ((buf)->text->beg + (buf)->text->gap_size + (buf)->text->z_byte - 1)
135
136/* Address of end of gap in buffer. */
137#define BUF_GAP_END_ADDR(buf) ((buf)->text->beg + (buf)->text->gpt_byte + (buf)->text->gap_size - 1)
116 138
117/* Is this buffer narrowed? */ 139/* Size of gap. */
140#define BUF_GAP_SIZE(buf) ((buf)->text->gap_size)
141
142/* Is this buffer narrowed? */
118#define BUF_NARROWED(buf) ((BUF_BEGV (buf) != BUF_BEG (buf)) \ 143#define BUF_NARROWED(buf) ((BUF_BEGV (buf) != BUF_BEG (buf)) \
119 || (BUF_ZV (buf) != BUF_Z (buf))) 144 || (BUF_ZV (buf) != BUF_Z (buf)))
120 145
@@ -132,48 +157,220 @@ extern INLINE void temp_set_point P_ ((int, struct buffer *));
132 157
133/* Marker chain of buffer. */ 158/* Marker chain of buffer. */
134#define BUF_MARKERS(buf) ((buf)->text->markers) 159#define BUF_MARKERS(buf) ((buf)->text->markers)
160
161/* Macros to set PT in the current buffer, or another buffer.. */
135 162
136/* Address of beginning of buffer. */ 163#ifdef USE_TEXT_PROPERTIES
137#define BUF_BEG_ADDR(buf) ((buf)->text->beg) 164#define SET_PT(position) (set_point (current_buffer, (position)))
165#define TEMP_SET_PT(position) (temp_set_point (current_buffer, (position)))
138 166
139/* Address of beginning of gap of buffer. */ 167#define SET_PT_BOTH(position, byte) \
140#define BUF_GPT_ADDR(buf) ((buf)->text->beg + (buf)->text->gpt - 1) 168 (set_point_both (current_buffer, (position), (byte)))
169#define TEMP_SET_PT_BOTH(position, byte) \
170 (temp_set_point_both (current_buffer, (position), (byte)))
141 171
142/* Address of end of buffer. */ 172#define BUF_SET_PT(buffer, position) \
143#define BUF_Z_ADDR(buf) ((buf)->text->beg + (buf)->text->gap_size + (buf)->text->z - 1) 173 (set_point ((buffer), (position)))
174#define BUF_TEMP_SET_PT(buffer, position) \
175 (temp_set_point ((buffer), (position)))
144 176
145/* Macro for setting the value of BUF_ZV (BUF) to VALUE, 177extern void set_point P_ ((struct buffer *, int));
146 by varying the end of the accessible region. */ 178extern INLINE void temp_set_point P_ ((struct buffer *, int));
147#define SET_BUF_ZV(buf, value) ((buf)->zv = (value)) 179extern void set_point_both P_ ((struct buffer *, int, int));
148#define SET_BUF_PT(buf, value) ((buf)->pt = (value)) 180extern INLINE void temp_set_point_both P_ ((struct buffer *, int, int));
149 181
150/* Size of gap. */ 182#else /* don't support text properties */
151#define BUF_GAP_SIZE(buf) ((buf)->text->gap_size) 183
184#define SET_PT(position) (current_buffer->pt = (position))
185#define TEMP_SET_PT(position) (current_buffer->pt = (position))
186
187#define SET_PT_BOTH(position, byte) \
188 (current_buffer->pt = (position), \
189 current_buffer->pt_byte = (byte))
190
191#define TEMP_SET_PT_BOTH(position, byte) \
192 (current_buffer->pt = (position), \
193 current_buffer->pt_byte = (byte))
194
195#define BUF_SET_PT(buffer, position) (buffer->pt = (position))
196#define BUF_TEMP_SET_PT(buffer, position) (buffer->pt = (position))
197#endif /* don't support text properties */
198
199/* Macros for setting the BEGV, ZV or PT of a given buffer.
200
201 SET_BUF_PT* seet to be redundant. Get rid of them?
202
203 The ..._BOTH macros take both a charpos and a bytepos,
204 which must correspond to each other.
205
206 The macros without ..._BOTH take just a charpos,
207 and compute the bytepos from it. */
152 208
153/* Return the address of character at position POS in buffer BUF. 209#define SET_BUF_BEGV(buf, charpos) \
210 ((buf)->begv_byte = buf_charpos_to_bytepos ((buf), (charpos)), \
211 (buf)->begv = (charpos))
212
213#define SET_BUF_ZV(buf, charpos) \
214 ((buf)->zv_byte = buf_charpos_to_bytepos ((buf), (charpos)), \
215 (buf)->zv = (charpos))
216
217#define SET_BUF_BEGV_BOTH(buf, charpos, byte) \
218 ((buf)->begv = (charpos), \
219 (buf)->begv_byte = (byte))
220
221#define SET_BUF_ZV_BOTH(buf, charpos, byte) \
222 ((buf)->zv = (charpos), \
223 (buf)->zv_byte = (byte))
224
225#define SET_BUF_PT_BOTH(buf, charpos, byte) \
226 ((buf)->pt = (charpos), \
227 (buf)->pt_byte = (byte))
228
229/* Macros to access a character or byte in the current buffer,
230 or convert between a byte position and an address.
231 These macros do not check that the position is in range. */
232
233/* Access a Lisp position value in POS,
234 and store the charpos in CHARPOS and the bypepos in BYPEPOS. */
235
236#define DECODE_POSITION(charpos, bytepos, pos) \
237if (1) \
238 { \
239 Lisp_Object __pos = (pos); \
240 if (NUMBERP (__pos)) \
241 { \
242 charpos = __pos; \
243 bytepos = buf_charpos_to_bytepos (current_buffer, __pos); \
244 } \
245 else if (MARKERP (__pos)) \
246 { \
247 charpos = marker_position (__pos); \
248 bytepos = marker_byte_position (__pos); \
249 } \
250 else \
251 wrong_type_argument (Qinteger_or_marker_p, __pos); \
252 } \
253else
254
255/* Return the address of byte position N in current buffer. */
256
257#define BYTE_POS_ADDR(n) \
258 (((n) >= GPT_BYTE ? GAP_SIZE : 0) + (n) + BEG_ADDR - 1)
259
260/* Return the address of char position N. */
261
262#define CHAR_POS_ADDR(n) \
263 (((n) >= GPT ? GAP_SIZE : 0) \
264 + buf_charpos_to_bytepos (current_buffer, n) \
265 + BEG_ADDR - 1)
266
267/* Convert a character position to a byte position. */
268
269#define CHAR_TO_BYTE(charpos) \
270 (buf_charpos_to_bytepos (current_buffer, charpos))
271
272/* Convert a byte position to a character position. */
273
274#define BYTE_TO_CHAR(bytepos) \
275 (buf_bytepos_to_charpos (current_buffer, bytepos))
276
277/* Convert PTR, the address of a byte in the buffer, into a byte position. */
278
279#define PTR_BYTE_POS(ptr) \
280((ptr) - (current_buffer)->text->beg \
281 - (ptr - (current_buffer)->text->beg < (unsigned) GPT_BYTE ? 0 : GAP_SIZE) \
282 + 1)
283
284/* Return character at position POS. */
285
286#define FETCH_CHAR(pos) \
287 (!NILP (current_buffer->enable_multibyte_characters) \
288 ? FETCH_MULTIBYTE_CHAR ((pos)) \
289 : FETCH_BYTE ((pos)))
290
291/* Return the byte at byte position N. */
292
293#define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n)))
294
295/* Variables used locally in FETCH_MULTIBYTE_CHAR. */
296extern unsigned char *_fetch_multibyte_char_p;
297extern int _fetch_multibyte_char_len;
298
299/* Return character code of multi-byte form at position POS. If POS
300 doesn't point the head of valid multi-byte form, only the byte at
301 POS is returned. No range checking. */
302
303#define FETCH_MULTIBYTE_CHAR(pos) \
304 (_fetch_multibyte_char_p = (((pos) >= GPT_BYTE ? GAP_SIZE : 0) \
305 + (pos) + BEG_ADDR - 1), \
306 _fetch_multibyte_char_len \
307 = ((pos) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE) - (pos), \
308 STRING_CHAR (_fetch_multibyte_char_p, _fetch_multibyte_char_len))
309
310/* Macros for accessing a character or byte,
311 or converting between byte positions and addresses,
312 in a specified buffer. */
313
314/* Return the address of character at byte position POS in buffer BUF.
154 Note that both arguments can be computed more than once. */ 315 Note that both arguments can be computed more than once. */
155#define BUF_CHAR_ADDRESS(buf, pos) \ 316
317#define BUF_BYTE_ADDRESS(buf, pos) \
156((buf)->text->beg + (pos) - 1 \ 318((buf)->text->beg + (pos) - 1 \
319 + ((pos) >= (buf)->text->gpt_byte ? (buf)->text->gap_size : 0))
320
321/* Return the address of character at char position POS in buffer BUF.
322 Note that both arguments can be computed more than once. */
323
324#define BUF_CHAR_ADDRESS(buf, pos) \
325((buf)->text->beg + buf_charpos_to_bytepos ((buf), (pos)) - 1 \
157 + ((pos) >= (buf)->text->gpt ? (buf)->text->gap_size : 0)) 326 + ((pos) >= (buf)->text->gpt ? (buf)->text->gap_size : 0))
158 327
159/* Convert the address of a char in the buffer into a character position. */ 328/* Convert PTR, the address of a char in buffer BUF,
160#define PTR_CHAR_POS(ptr) \ 329 into a character position. */
161((ptr) - (current_buffer)->text->beg \
162 - (ptr - (current_buffer)->text->beg < (unsigned) GPT ? 0 : GAP_SIZE) \
163 + 1)
164 330
165/* Convert the address of a char in the buffer into a character position. */ 331#define BUF_PTR_BYTE_POS(buf, ptr) \
166#define BUF_PTR_CHAR_POS(buf, ptr) \ 332((ptr) - (buf)->text->beg \
167((ptr) - (buf)->text->beg \ 333 - (ptr - (buf)->text->beg < (unsigned) BUF_GPT_BYTE ((buf)) \
168 - (ptr - (buf)->text->beg < (unsigned) BUF_GPT ((buf)) \ 334 ? 0 : BUF_GAP_SIZE ((buf))) \
169 ? 0 : BUF_GAP_SIZE ((buf))) \
170 + 1) 335 + 1)
336
337/* Return the character at byte position POS in buffer BUF. */
338
339#define BUF_FETCH_CHAR(buf, pos) \
340 (!NILP (buf->enable_multibyte_characters) \
341 ? BUF_FETCH_MULTIBYTE_CHAR ((buf), (pos)) \
342 : BUF_FETCH_BYTE ((buf), (pos)))
343
344/* Return the byte at byte position N in buffer BUF. */
345
346#define BUF_FETCH_BYTE(buf, n) \
347 *(BUF_BYTE_ADDRESS ((buf), (n)))
348
349/* Return character code of multi-byte form at byte position POS in BUF.
350 If POS doesn't point the head of valid multi-byte form, only the byte at
351 POS is returned. No range checking. */
352
353#define BUF_FETCH_MULTIBYTE_CHAR(buf, pos) \
354 (_fetch_multibyte_char_p \
355 = (((pos) >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0) \
356 + (pos) + BUF_BEG_ADDR (buf) - 1), \
357 _fetch_multibyte_char_len \
358 = (((pos) >= BUF_GPT_BYTE (buf) ? BUF_ZV_BYTE (buf) : BUF_GPT_BYTE (buf)) \
359 - (pos)), \
360 STRING_CHAR (_fetch_multibyte_char_p, _fetch_multibyte_char_len))
171 361
362/* Define the actual buffer data structures. */
363
364/* This data structure describes the actual text contents of a buffer.
365 It is shared between indirect buffers and their base buffer. */
366
172struct buffer_text 367struct buffer_text
173 { 368 {
174 unsigned char *beg; /* Actual address of buffer contents. */ 369 unsigned char *beg; /* Actual address of buffer contents. */
175 int gpt; /* Index of gap in buffer. */ 370 int gpt; /* Char pos of gap in buffer. */
176 int z; /* Index of end of buffer. */ 371 int z; /* Char pos of end of buffer. */
372 int gpt_byte; /* Byte pos of gap in buffer. */
373 int z_byte; /* Byte pos of end of buffer. */
177 int gap_size; /* Size of buffer's gap. */ 374 int gap_size; /* Size of buffer's gap. */
178 int modiff; /* This counts buffer-modification events 375 int modiff; /* This counts buffer-modification events
179 for this buffer. It is incremented for 376 for this buffer. It is incremented for
@@ -194,6 +391,8 @@ struct buffer_text
194 Lisp_Object markers; 391 Lisp_Object markers;
195 }; 392 };
196 393
394/* This is the structure that the buffer Lisp object points to. */
395
197struct buffer 396struct buffer
198 { 397 {
199 /* Everything before the `name' slot must be of a non-Lisp_Object type, 398 /* Everything before the `name' slot must be of a non-Lisp_Object type,
@@ -219,12 +418,18 @@ struct buffer
219 In an indirect buffer, this is the own_text field of another buffer. */ 418 In an indirect buffer, this is the own_text field of another buffer. */
220 struct buffer_text *text; 419 struct buffer_text *text;
221 420
222 /* Position of point in buffer. */ 421 /* Char position of point in buffer. */
223 int pt; 422 int pt;
224 /* Index of beginning of accessible range. */ 423 /* Byte position of point in buffer. */
424 int pt_byte;
425 /* Char position of beginning of accessible range. */
225 int begv; 426 int begv;
226 /* Index of end of accessible range. */ 427 /* Byte position of beginning of accessible range. */
428 int begv_byte;
429 /* Char position of end of accessible range. */
227 int zv; 430 int zv;
431 /* Byte position of end of accessible range. */
432 int zv_byte;
228 433
229 /* In an indirect buffer, this points to the base buffer. 434 /* In an indirect buffer, this points to the base buffer.
230 In an ordinary buffer, it is 0. */ 435 In an ordinary buffer, it is 0. */
@@ -494,40 +699,6 @@ extern struct buffer buffer_local_symbols;
494 always be safely stored in any slot. */ 699 always be safely stored in any slot. */
495extern struct buffer buffer_local_types; 700extern struct buffer buffer_local_types;
496 701
497/* Return the address of position N. No range checking. */
498#define POS_ADDR(n) (((n)>= GPT ? GAP_SIZE : 0) + (n) + BEG_ADDR - 1)
499
500/* Return the byte at position N. No range checking. */
501#define FETCH_BYTE(n) *(POS_ADDR ((n)))
502
503/* Variables used locally in FETCH_MULTIBYTE_CHAR. */
504extern unsigned char *_fetch_multibyte_char_p;
505extern int _fetch_multibyte_char_len;
506
507/* Return character code of multi-byte form at position POS. If POS
508 doesn't point the head of valid multi-byte form, only the byte at
509 POS is returned. No range checking. */
510
511#define FETCH_MULTIBYTE_CHAR(pos) \
512 (_fetch_multibyte_char_p = (((pos) >= GPT ? GAP_SIZE : 0) \
513 + (pos) + BEG_ADDR - 1), \
514 _fetch_multibyte_char_len = ((pos) >= GPT ? ZV : GPT) - (pos), \
515 STRING_CHAR (_fetch_multibyte_char_p, _fetch_multibyte_char_len))
516
517/* Return character at position POS. No range checking. */
518#define FETCH_CHAR(pos) \
519 (!NILP (current_buffer->enable_multibyte_characters) \
520 ? FETCH_MULTIBYTE_CHAR ((pos)) \
521 : FETCH_BYTE ((pos)))
522
523/* BUFFER_CEILING_OF (resp. BUFFER_FLOOR_OF), when applied to n, return
524 the max (resp. min) p such that
525
526 POS_ADDR (p) - POS_ADDR (n) == p - n */
527
528#define BUFFER_CEILING_OF(n) (((n) < GPT && GPT < ZV ? GPT : ZV) - 1)
529#define BUFFER_FLOOR_OF(n) (BEGV <= GPT && GPT <= (n) ? GPT : BEGV)
530
531extern void reset_buffer P_ ((struct buffer *)); 702extern void reset_buffer P_ ((struct buffer *));
532extern void evaporate_overlays P_ ((int)); 703extern void evaporate_overlays P_ ((int));
533extern int overlays_at P_ ((int, int, Lisp_Object **, int *, int *, int *)); 704extern int overlays_at P_ ((int, int, Lisp_Object **, int *, int *, int *));