Mercurial > emacs
comparison src/buffer.h @ 20553:a49deda9f5e6
(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.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Thu, 01 Jan 1998 06:49:17 +0000 |
| parents | a385b772f453 |
| children | ed9ed828415e |
comparison
equal
deleted
inserted
replaced
| 20552:1a0cb8cd5615 | 20553:a49deda9f5e6 |
|---|---|
| 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 |
| 4 This file is part of GNU Emacs. | 4 This file is part of GNU Emacs. |
| 5 | 5 |
| 6 GNU Emacs is free software; you can redistribute it and/or modify | 6 GNU Emacs is free software; you can redistribute it and/or modify |
| 7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
| 17 along with GNU Emacs; see the file COPYING. If not, write to | 17 along with GNU Emacs; see the file COPYING. If not, write to |
| 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 Boston, MA 02111-1307, USA. */ | 19 Boston, MA 02111-1307, USA. */ |
| 20 | 20 |
| 21 | 21 |
| 22 /* Accessing the parameters of the current buffer. */ | |
| 23 | |
| 24 /* These macros come in pairs, one for the char position | |
| 25 and one for the byte position. */ | |
| 26 | |
| 27 /* Position of beginning of buffer. */ | |
| 28 #define BEG (1) | |
| 29 #define BEG_BYTE (1) | |
| 30 | |
| 31 /* Position of beginning of accessible range of buffer. */ | |
| 32 #define BEGV (current_buffer->begv) | |
| 33 #define BEGV_BYTE (current_buffer->begv_byte) | |
| 34 | |
| 35 /* Position of point in buffer. The "+ 0" makes this | |
| 36 not an l-value, so you can't assign to it. Use SET_PT instead. */ | |
| 37 #define PT (current_buffer->pt + 0) | |
| 38 #define PT_BYTE (current_buffer->pt_byte + 0) | |
| 39 | |
| 40 /* Position of gap in buffer. */ | |
| 41 #define GPT (current_buffer->text->gpt) | |
| 42 #define GPT_BYTE (current_buffer->text->gpt_byte) | |
| 43 | |
| 44 /* Position of end of accessible range of buffer. */ | |
| 45 #define ZV (current_buffer->zv) | |
| 46 #define ZV_BYTE (current_buffer->zv_byte) | |
| 47 | |
| 48 /* Position of end of buffer. */ | |
| 49 #define Z (current_buffer->text->z) | |
| 50 #define Z_BYTE (current_buffer->text->z_byte) | |
| 51 | |
| 52 /* Macros for the addresses of places in the buffer. */ | |
| 53 | |
| 54 /* Address of beginning of buffer. */ | |
| 55 #define BEG_ADDR (current_buffer->text->beg) | |
| 56 | |
| 57 /* Address of beginning of accessible range of buffer. */ | |
| 58 #define BEGV_ADDR (BYTE_POS_ADDR (current_buffer->begv_byte)) | |
| 59 | |
| 60 /* Address of point in buffer. */ | |
| 61 #define PT_ADDR (BYTE_POS_ADDR (current_buffer->pt_byte)) | |
| 62 | |
| 63 /* Address of beginning of gap in buffer. */ | |
| 64 #define GPT_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte - 1) | |
| 65 | |
| 66 /* Address of end of gap in buffer. */ | |
| 67 #define GAP_END_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte + current_buffer->text->gap_size - 1) | |
| 68 | |
| 69 /* Address of end of accessible range of buffer. */ | |
| 70 #define ZV_ADDR (BYTE_POS_ADDR (current_buffer->zv_byte)) | |
| 71 | |
| 72 /* Address of end of buffer. */ | |
| 73 #define Z_ADDR (current_buffer->text->beg + current_buffer->text->gap_size + current_buffer->text->z_byte - 1) | |
| 74 | |
| 75 /* Size of gap. */ | |
| 76 #define GAP_SIZE (current_buffer->text->gap_size) | |
| 77 | |
| 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. | |
| 101 Note that many of these evaluate the buffer argument more than once. */ | |
| 102 | |
| 103 /* Position of beginning of buffer. */ | |
| 104 #define BUF_BEG(buf) (1) | |
| 105 #define BUF_BEG_BYTE(buf) (1) | |
| 106 | |
| 107 /* Position of beginning of accessible range of buffer. */ | |
| 108 #define BUF_BEGV(buf) ((buf)->begv) | |
| 109 #define BUF_BEGV_BYTE(buf) ((buf)->begv_byte) | |
| 110 | |
| 111 /* Position of point in buffer. */ | |
| 112 #define BUF_PT(buf) ((buf)->pt) | |
| 113 #define BUF_PT_BYTE(buf) ((buf)->pt_byte) | |
| 114 | |
| 115 /* Position of gap in buffer. */ | |
| 116 #define BUF_GPT(buf) ((buf)->text->gpt) | |
| 117 #define BUF_GPT_BYTE(buf) ((buf)->text->gpt_byte) | |
| 118 | |
| 119 /* Position of end of accessible range of buffer. */ | |
| 120 #define BUF_ZV(buf) ((buf)->zv) | |
| 121 #define BUF_ZV_BYTE(buf) ((buf)->zv_byte) | |
| 122 | |
| 123 /* Position of end of buffer. */ | |
| 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) | |
| 138 | |
| 139 /* Size of gap. */ | |
| 140 #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size) | |
| 141 | |
| 142 /* Is this buffer narrowed? */ | |
| 143 #define BUF_NARROWED(buf) ((BUF_BEGV (buf) != BUF_BEG (buf)) \ | |
| 144 || (BUF_ZV (buf) != BUF_Z (buf))) | |
| 145 | |
| 146 /* Modification count. */ | |
| 147 #define BUF_MODIFF(buf) ((buf)->text->modiff) | |
| 148 | |
| 149 /* Modification count as of last visit or save. */ | |
| 150 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff) | |
| 151 | |
| 152 /* Overlay modification count. */ | |
| 153 #define BUF_OVERLAY_MODIFF(buf) ((buf)->text->overlay_modiff) | |
| 154 | |
| 155 /* Interval tree of buffer. */ | |
| 156 #define BUF_INTERVALS(buf) ((buf)->text->intervals) | |
| 157 | |
| 158 /* Marker chain of buffer. */ | |
| 159 #define BUF_MARKERS(buf) ((buf)->text->markers) | |
| 160 | |
| 161 /* Macros to set PT in the current buffer, or another buffer.. */ | |
| 162 | |
| 22 #ifdef USE_TEXT_PROPERTIES | 163 #ifdef USE_TEXT_PROPERTIES |
| 23 #define SET_PT(position) (set_point ((position), current_buffer)) | 164 #define SET_PT(position) (set_point (current_buffer, (position))) |
| 24 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer)) | 165 #define TEMP_SET_PT(position) (temp_set_point (current_buffer, (position))) |
| 25 | 166 |
| 26 #define BUF_SET_PT(buffer, position) (set_point ((position), (buffer))) | 167 #define SET_PT_BOTH(position, byte) \ |
| 27 #define BUF_TEMP_SET_PT(buffer, position) (temp_set_point ((position), (buffer))) | 168 (set_point_both (current_buffer, (position), (byte))) |
| 28 | 169 #define TEMP_SET_PT_BOTH(position, byte) \ |
| 29 extern void set_point P_ ((int, struct buffer *)); | 170 (temp_set_point_both (current_buffer, (position), (byte))) |
| 30 extern INLINE void temp_set_point P_ ((int, struct buffer *)); | 171 |
| 172 #define BUF_SET_PT(buffer, position) \ | |
| 173 (set_point ((buffer), (position))) | |
| 174 #define BUF_TEMP_SET_PT(buffer, position) \ | |
| 175 (temp_set_point ((buffer), (position))) | |
| 176 | |
| 177 extern void set_point P_ ((struct buffer *, int)); | |
| 178 extern INLINE void temp_set_point P_ ((struct buffer *, int)); | |
| 179 extern void set_point_both P_ ((struct buffer *, int, int)); | |
| 180 extern INLINE void temp_set_point_both P_ ((struct buffer *, int, int)); | |
| 31 | 181 |
| 32 #else /* don't support text properties */ | 182 #else /* don't support text properties */ |
| 33 | 183 |
| 34 #define SET_PT(position) (current_buffer->pt = (position)) | 184 #define SET_PT(position) (current_buffer->pt = (position)) |
| 35 #define TEMP_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)) | |
| 36 | 194 |
| 37 #define BUF_SET_PT(buffer, position) (buffer->pt = (position)) | 195 #define BUF_SET_PT(buffer, position) (buffer->pt = (position)) |
| 38 #define BUF_TEMP_SET_PT(buffer, position) (buffer->pt = (position)) | 196 #define BUF_TEMP_SET_PT(buffer, position) (buffer->pt = (position)) |
| 39 #endif /* don't support text properties */ | 197 #endif /* don't support text properties */ |
| 40 | 198 |
| 41 /* Character position of beginning of buffer. */ | 199 /* Macros for setting the BEGV, ZV or PT of a given buffer. |
| 42 #define BEG (1) | 200 |
| 43 | 201 SET_BUF_PT* seet to be redundant. Get rid of them? |
| 44 /* Character position of beginning of accessible range of buffer. */ | 202 |
| 45 #define BEGV (current_buffer->begv) | 203 The ..._BOTH macros take both a charpos and a bytepos, |
| 46 | 204 which must correspond to each other. |
| 47 /* Character position of point in buffer. The "+ 0" makes this | 205 |
| 48 not an l-value, so you can't assign to it. Use SET_PT instead. */ | 206 The macros without ..._BOTH take just a charpos, |
| 49 #define PT (current_buffer->pt + 0) | 207 and compute the bytepos from it. */ |
| 50 | 208 |
| 51 /* Character position of gap in buffer. */ | 209 #define SET_BUF_BEGV(buf, charpos) \ |
| 52 #define GPT (current_buffer->text->gpt) | 210 ((buf)->begv_byte = buf_charpos_to_bytepos ((buf), (charpos)), \ |
| 53 | 211 (buf)->begv = (charpos)) |
| 54 /* Character position of end of accessible range of buffer. */ | 212 |
| 55 #define ZV (current_buffer->zv) | 213 #define SET_BUF_ZV(buf, charpos) \ |
| 56 | 214 ((buf)->zv_byte = buf_charpos_to_bytepos ((buf), (charpos)), \ |
| 57 /* Character position of end of buffer. */ | 215 (buf)->zv = (charpos)) |
| 58 #define Z (current_buffer->text->z) | 216 |
| 59 | 217 #define SET_BUF_BEGV_BOTH(buf, charpos, byte) \ |
| 60 /* Is the current buffer narrowed? */ | 218 ((buf)->begv = (charpos), \ |
| 61 #define NARROWED ((BEGV != BEG) || (ZV != Z)) | 219 (buf)->begv_byte = (byte)) |
| 62 | 220 |
| 63 /* Modification count. */ | 221 #define SET_BUF_ZV_BOTH(buf, charpos, byte) \ |
| 64 #define MODIFF (current_buffer->text->modiff) | 222 ((buf)->zv = (charpos), \ |
| 65 | 223 (buf)->zv_byte = (byte)) |
| 66 /* Overlay modification count. */ | 224 |
| 67 #define OVERLAY_MODIFF (current_buffer->text->overlay_modiff) | 225 #define SET_BUF_PT_BOTH(buf, charpos, byte) \ |
| 68 | 226 ((buf)->pt = (charpos), \ |
| 69 /* Modification count as of last visit or save. */ | 227 (buf)->pt_byte = (byte)) |
| 70 #define SAVE_MODIFF (current_buffer->text->save_modiff) | 228 |
| 71 | 229 /* Macros to access a character or byte in the current buffer, |
| 72 /* Address of beginning of buffer. */ | 230 or convert between a byte position and an address. |
| 73 #define BEG_ADDR (current_buffer->text->beg) | 231 These macros do not check that the position is in range. */ |
| 74 | 232 |
| 75 /* Address of beginning of accessible range of buffer. */ | 233 /* Access a Lisp position value in POS, |
| 76 #define BEGV_ADDR (POS_ADDR (current_buffer->begv)) | 234 and store the charpos in CHARPOS and the bypepos in BYPEPOS. */ |
| 77 | 235 |
| 78 /* Address of point in buffer. */ | 236 #define DECODE_POSITION(charpos, bytepos, pos) \ |
| 79 #define PT_ADDR (POS_ADDR (current_buffer->pt)) | 237 if (1) \ |
| 80 | 238 { \ |
| 81 /* Address of beginning of gap in buffer. */ | 239 Lisp_Object __pos = (pos); \ |
| 82 #define GPT_ADDR (current_buffer->text->beg + current_buffer->text->gpt - 1) | 240 if (NUMBERP (__pos)) \ |
| 83 | 241 { \ |
| 84 /* Address of end of gap in buffer. */ | 242 charpos = __pos; \ |
| 85 #define GAP_END_ADDR (current_buffer->text->beg + current_buffer->text->gpt + current_buffer->text->gap_size - 1) | 243 bytepos = buf_charpos_to_bytepos (current_buffer, __pos); \ |
| 86 | 244 } \ |
| 87 /* Address of end of accessible range of buffer. */ | 245 else if (MARKERP (__pos)) \ |
| 88 #define ZV_ADDR (POS_ADDR (current_buffer->zv)) | 246 { \ |
| 89 | 247 charpos = marker_position (__pos); \ |
| 90 /* Address of end of buffer. */ | 248 bytepos = marker_byte_position (__pos); \ |
| 91 #define Z_ADDR (current_buffer->text->beg + current_buffer->text->gap_size + current_buffer->text->z - 1) | 249 } \ |
| 92 | 250 else \ |
| 93 /* Size of gap. */ | 251 wrong_type_argument (Qinteger_or_marker_p, __pos); \ |
| 94 #define GAP_SIZE (current_buffer->text->gap_size) | 252 } \ |
| 95 | 253 else |
| 96 /* Now similar macros for a specified buffer. | 254 |
| 97 Note that many of these evaluate the buffer argument more than once. */ | 255 /* Return the address of byte position N in current buffer. */ |
| 98 | 256 |
| 99 /* Character position of beginning of buffer. */ | 257 #define BYTE_POS_ADDR(n) \ |
| 100 #define BUF_BEG(buf) (1) | 258 (((n) >= GPT_BYTE ? GAP_SIZE : 0) + (n) + BEG_ADDR - 1) |
| 101 | 259 |
| 102 /* Character position of beginning of accessible range of buffer. */ | 260 /* Return the address of char position N. */ |
| 103 #define BUF_BEGV(buf) ((buf)->begv) | 261 |
| 104 | 262 #define CHAR_POS_ADDR(n) \ |
| 105 /* Character position of point in buffer. */ | 263 (((n) >= GPT ? GAP_SIZE : 0) \ |
| 106 #define BUF_PT(buf) ((buf)->pt) | 264 + buf_charpos_to_bytepos (current_buffer, n) \ |
| 107 | 265 + BEG_ADDR - 1) |
| 108 /* Character position of gap in buffer. */ | 266 |
| 109 #define BUF_GPT(buf) ((buf)->text->gpt) | 267 /* Convert a character position to a byte position. */ |
| 110 | 268 |
| 111 /* Character position of end of accessible range of buffer. */ | 269 #define CHAR_TO_BYTE(charpos) \ |
| 112 #define BUF_ZV(buf) ((buf)->zv) | 270 (buf_charpos_to_bytepos (current_buffer, charpos)) |
| 113 | 271 |
| 114 /* Character position of end of buffer. */ | 272 /* Convert a byte position to a character position. */ |
| 115 #define BUF_Z(buf) ((buf)->text->z) | 273 |
| 116 | 274 #define BYTE_TO_CHAR(bytepos) \ |
| 117 /* Is this buffer narrowed? */ | 275 (buf_bytepos_to_charpos (current_buffer, bytepos)) |
| 118 #define BUF_NARROWED(buf) ((BUF_BEGV (buf) != BUF_BEG (buf)) \ | 276 |
| 119 || (BUF_ZV (buf) != BUF_Z (buf))) | 277 /* Convert PTR, the address of a byte in the buffer, into a byte position. */ |
| 120 | 278 |
| 121 /* Modification count. */ | 279 #define PTR_BYTE_POS(ptr) \ |
| 122 #define BUF_MODIFF(buf) ((buf)->text->modiff) | 280 ((ptr) - (current_buffer)->text->beg \ |
| 123 | 281 - (ptr - (current_buffer)->text->beg < (unsigned) GPT_BYTE ? 0 : GAP_SIZE) \ |
| 124 /* Modification count as of last visit or save. */ | 282 + 1) |
| 125 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff) | 283 |
| 126 | 284 /* Return character at position POS. */ |
| 127 /* Overlay modification count. */ | 285 |
| 128 #define BUF_OVERLAY_MODIFF(buf) ((buf)->text->overlay_modiff) | 286 #define FETCH_CHAR(pos) \ |
| 129 | 287 (!NILP (current_buffer->enable_multibyte_characters) \ |
| 130 /* Interval tree of buffer. */ | 288 ? FETCH_MULTIBYTE_CHAR ((pos)) \ |
| 131 #define BUF_INTERVALS(buf) ((buf)->text->intervals) | 289 : FETCH_BYTE ((pos))) |
| 132 | 290 |
| 133 /* Marker chain of buffer. */ | 291 /* Return the byte at byte position N. */ |
| 134 #define BUF_MARKERS(buf) ((buf)->text->markers) | 292 |
| 135 | 293 #define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n))) |
| 136 /* Address of beginning of buffer. */ | 294 |
| 137 #define BUF_BEG_ADDR(buf) ((buf)->text->beg) | 295 /* Variables used locally in FETCH_MULTIBYTE_CHAR. */ |
| 138 | 296 extern unsigned char *_fetch_multibyte_char_p; |
| 139 /* Address of beginning of gap of buffer. */ | 297 extern int _fetch_multibyte_char_len; |
| 140 #define BUF_GPT_ADDR(buf) ((buf)->text->beg + (buf)->text->gpt - 1) | 298 |
| 141 | 299 /* Return character code of multi-byte form at position POS. If POS |
| 142 /* Address of end of buffer. */ | 300 doesn't point the head of valid multi-byte form, only the byte at |
| 143 #define BUF_Z_ADDR(buf) ((buf)->text->beg + (buf)->text->gap_size + (buf)->text->z - 1) | 301 POS is returned. No range checking. */ |
| 144 | 302 |
| 145 /* Macro for setting the value of BUF_ZV (BUF) to VALUE, | 303 #define FETCH_MULTIBYTE_CHAR(pos) \ |
| 146 by varying the end of the accessible region. */ | 304 (_fetch_multibyte_char_p = (((pos) >= GPT_BYTE ? GAP_SIZE : 0) \ |
| 147 #define SET_BUF_ZV(buf, value) ((buf)->zv = (value)) | 305 + (pos) + BEG_ADDR - 1), \ |
| 148 #define SET_BUF_PT(buf, value) ((buf)->pt = (value)) | 306 _fetch_multibyte_char_len \ |
| 149 | 307 = ((pos) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE) - (pos), \ |
| 150 /* Size of gap. */ | 308 STRING_CHAR (_fetch_multibyte_char_p, _fetch_multibyte_char_len)) |
| 151 #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size) | 309 |
| 152 | 310 /* Macros for accessing a character or byte, |
| 153 /* Return the address of character at position POS in buffer BUF. | 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. */ |
| 316 | |
| 317 #define BUF_BYTE_ADDRESS(buf, pos) \ | |
| 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 | |
| 155 #define BUF_CHAR_ADDRESS(buf, pos) \ | 324 #define BUF_CHAR_ADDRESS(buf, pos) \ |
| 156 ((buf)->text->beg + (pos) - 1 \ | 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 \ | 330 |
| 162 - (ptr - (current_buffer)->text->beg < (unsigned) GPT ? 0 : GAP_SIZE) \ | 331 #define BUF_PTR_BYTE_POS(buf, ptr) \ |
| 332 ((ptr) - (buf)->text->beg \ | |
| 333 - (ptr - (buf)->text->beg < (unsigned) BUF_GPT_BYTE ((buf)) \ | |
| 334 ? 0 : BUF_GAP_SIZE ((buf))) \ | |
| 163 + 1) | 335 + 1) |
| 164 | 336 |
| 165 /* Convert the address of a char in the buffer into a character position. */ | 337 /* Return the character at byte position POS in buffer BUF. */ |
| 166 #define BUF_PTR_CHAR_POS(buf, ptr) \ | 338 |
| 167 ((ptr) - (buf)->text->beg \ | 339 #define BUF_FETCH_CHAR(buf, pos) \ |
| 168 - (ptr - (buf)->text->beg < (unsigned) BUF_GPT ((buf)) \ | 340 (!NILP (buf->enable_multibyte_characters) \ |
| 169 ? 0 : BUF_GAP_SIZE ((buf))) \ | 341 ? BUF_FETCH_MULTIBYTE_CHAR ((buf), (pos)) \ |
| 170 + 1) | 342 : BUF_FETCH_BYTE ((buf), (pos))) |
| 171 | 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)) | |
| 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 | |
| 172 struct buffer_text | 367 struct 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 |
| 180 each such event, and never otherwise | 377 each such event, and never otherwise |
| 181 changed. */ | 378 changed. */ |
| 192 successive elements in its marker `chain' | 389 successive elements in its marker `chain' |
| 193 are the other markers referring to this buffer. */ | 390 are the other markers referring to this buffer. */ |
| 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 | |
| 197 struct buffer | 396 struct 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, |
| 200 and every slot after `name' must be a Lisp_Object. | 399 and every slot after `name' must be a Lisp_Object. |
| 201 | 400 |
| 217 /* This points to the `struct buffer_text' that used for this buffer. | 416 /* This points to the `struct buffer_text' that used for this buffer. |
| 218 In an ordinary buffer, this is the own_text field above. | 417 In an ordinary buffer, this is the own_text field above. |
| 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. */ |
| 231 struct buffer *base_buffer; | 436 struct buffer *base_buffer; |
| 232 | 437 |
| 492 equal to that integer. When a tag does not match, the function | 697 equal to that integer. When a tag does not match, the function |
| 493 buffer_slot_type_mismatch will signal an error. The value Qnil may | 698 buffer_slot_type_mismatch will signal an error. The value Qnil may |
| 494 always be safely stored in any slot. */ | 699 always be safely stored in any slot. */ |
| 495 extern struct buffer buffer_local_types; | 700 extern 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. */ | |
| 504 extern unsigned char *_fetch_multibyte_char_p; | |
| 505 extern 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 | |
| 531 extern void reset_buffer P_ ((struct buffer *)); | 702 extern void reset_buffer P_ ((struct buffer *)); |
| 532 extern void evaporate_overlays P_ ((int)); | 703 extern void evaporate_overlays P_ ((int)); |
| 533 extern int overlays_at P_ ((int, int, Lisp_Object **, int *, int *, int *)); | 704 extern int overlays_at P_ ((int, int, Lisp_Object **, int *, int *, int *)); |
| 534 extern int sort_overlays P_ ((Lisp_Object *, int, struct window *)); | 705 extern int sort_overlays P_ ((Lisp_Object *, int, struct window *)); |
| 535 extern void recenter_overlay_lists P_ ((struct buffer *, int)); | 706 extern void recenter_overlay_lists P_ ((struct buffer *, int)); |
