diff options
Diffstat (limited to 'src/buffer.h')
| -rw-r--r-- | src/buffer.h | 661 |
1 files changed, 395 insertions, 266 deletions
diff --git a/src/buffer.h b/src/buffer.h index 14de70c6482..82d9350bfc2 100644 --- a/src/buffer.h +++ b/src/buffer.h | |||
| @@ -31,12 +31,11 @@ INLINE_HEADER_BEGIN | |||
| 31 | 31 | ||
| 32 | /* Accessing the parameters of the current buffer. */ | 32 | /* Accessing the parameters of the current buffer. */ |
| 33 | 33 | ||
| 34 | /* These macros come in pairs, one for the char position | 34 | /* These constants and macros come in pairs, one for the char position |
| 35 | and one for the byte position. */ | 35 | and one for the byte position. */ |
| 36 | 36 | ||
| 37 | /* Position of beginning of buffer. */ | 37 | /* Position of beginning of buffer. */ |
| 38 | #define BEG (1) | 38 | enum { BEG = 1, BEG_BYTE = BEG }; |
| 39 | #define BEG_BYTE (BEG) | ||
| 40 | 39 | ||
| 41 | /* Position of beginning of accessible range of buffer. */ | 40 | /* Position of beginning of accessible range of buffer. */ |
| 42 | #define BEGV (current_buffer->begv) | 41 | #define BEGV (current_buffer->begv) |
| @@ -96,59 +95,7 @@ INLINE_HEADER_BEGIN | |||
| 96 | 95 | ||
| 97 | /* Modification count as of last visit or save. */ | 96 | /* Modification count as of last visit or save. */ |
| 98 | #define SAVE_MODIFF (current_buffer->text->save_modiff) | 97 | #define SAVE_MODIFF (current_buffer->text->save_modiff) |
| 99 | |||
| 100 | /* BUFFER_CEILING_OF (resp. BUFFER_FLOOR_OF), when applied to n, return | ||
| 101 | the max (resp. min) p such that | ||
| 102 | |||
| 103 | BYTE_POS_ADDR (p) - BYTE_POS_ADDR (n) == p - n */ | ||
| 104 | |||
| 105 | #define BUFFER_CEILING_OF(BYTEPOS) \ | ||
| 106 | (((BYTEPOS) < GPT_BYTE && GPT < ZV ? GPT_BYTE : ZV_BYTE) - 1) | ||
| 107 | #define BUFFER_FLOOR_OF(BYTEPOS) \ | ||
| 108 | (BEGV <= GPT && GPT_BYTE <= (BYTEPOS) ? GPT_BYTE : BEGV_BYTE) | ||
| 109 | 98 | ||
| 110 | /* Similar macros to operate on a specified buffer. | ||
| 111 | Note that many of these evaluate the buffer argument more than once. */ | ||
| 112 | |||
| 113 | /* Position of beginning of buffer. */ | ||
| 114 | #define BUF_BEG(buf) (BEG) | ||
| 115 | #define BUF_BEG_BYTE(buf) (BEG_BYTE) | ||
| 116 | |||
| 117 | /* The BUF_BEGV[_BYTE], BUF_ZV[_BYTE], and BUF_PT[_BYTE] macros cannot | ||
| 118 | be used for assignment; use SET_BUF_* macros below for that. */ | ||
| 119 | |||
| 120 | /* Position of beginning of accessible range of buffer. */ | ||
| 121 | #define BUF_BEGV(buf) \ | ||
| 122 | (buf == current_buffer ? BEGV \ | ||
| 123 | : NILP (BVAR (buf, begv_marker)) ? buf->begv \ | ||
| 124 | : marker_position (BVAR (buf, begv_marker))) | ||
| 125 | |||
| 126 | #define BUF_BEGV_BYTE(buf) \ | ||
| 127 | (buf == current_buffer ? BEGV_BYTE \ | ||
| 128 | : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte \ | ||
| 129 | : marker_byte_position (BVAR (buf, begv_marker))) | ||
| 130 | |||
| 131 | /* Position of point in buffer. */ | ||
| 132 | #define BUF_PT(buf) \ | ||
| 133 | (buf == current_buffer ? PT \ | ||
| 134 | : NILP (BVAR (buf, pt_marker)) ? buf->pt \ | ||
| 135 | : marker_position (BVAR (buf, pt_marker))) | ||
| 136 | |||
| 137 | #define BUF_PT_BYTE(buf) \ | ||
| 138 | (buf == current_buffer ? PT_BYTE \ | ||
| 139 | : NILP (BVAR (buf, pt_marker)) ? buf->pt_byte \ | ||
| 140 | : marker_byte_position (BVAR (buf, pt_marker))) | ||
| 141 | |||
| 142 | /* Position of end of accessible range of buffer. */ | ||
| 143 | #define BUF_ZV(buf) \ | ||
| 144 | (buf == current_buffer ? ZV \ | ||
| 145 | : NILP (BVAR (buf, zv_marker)) ? buf->zv \ | ||
| 146 | : marker_position (BVAR (buf, zv_marker))) | ||
| 147 | |||
| 148 | #define BUF_ZV_BYTE(buf) \ | ||
| 149 | (buf == current_buffer ? ZV_BYTE \ | ||
| 150 | : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte \ | ||
| 151 | : marker_byte_position (BVAR (buf, zv_marker))) | ||
| 152 | 99 | ||
| 153 | /* Position of gap in buffer. */ | 100 | /* Position of gap in buffer. */ |
| 154 | #define BUF_GPT(buf) ((buf)->text->gpt) | 101 | #define BUF_GPT(buf) ((buf)->text->gpt) |
| @@ -161,15 +108,6 @@ INLINE_HEADER_BEGIN | |||
| 161 | /* Address of beginning of buffer. */ | 108 | /* Address of beginning of buffer. */ |
| 162 | #define BUF_BEG_ADDR(buf) ((buf)->text->beg) | 109 | #define BUF_BEG_ADDR(buf) ((buf)->text->beg) |
| 163 | 110 | ||
| 164 | /* Address of beginning of gap of buffer. */ | ||
| 165 | #define BUF_GPT_ADDR(buf) ((buf)->text->beg + (buf)->text->gpt_byte - BEG_BYTE) | ||
| 166 | |||
| 167 | /* Address of end of buffer. */ | ||
| 168 | #define BUF_Z_ADDR(buf) ((buf)->text->beg + (buf)->text->gap_size + (buf)->text->z_byte - BEG_BYTE) | ||
| 169 | |||
| 170 | /* Address of end of gap in buffer. */ | ||
| 171 | #define BUF_GAP_END_ADDR(buf) ((buf)->text->beg + (buf)->text->gpt_byte + (buf)->text->gap_size - BEG_BYTE) | ||
| 172 | |||
| 173 | /* Size of gap. */ | 111 | /* Size of gap. */ |
| 174 | #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size) | 112 | #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size) |
| 175 | 113 | ||
| @@ -209,43 +147,8 @@ INLINE_HEADER_BEGIN | |||
| 209 | BUF_OVERLAY_UNCHANGED_MODIFIED (current_buffer) | 147 | BUF_OVERLAY_UNCHANGED_MODIFIED (current_buffer) |
| 210 | #define BEG_UNCHANGED BUF_BEG_UNCHANGED (current_buffer) | 148 | #define BEG_UNCHANGED BUF_BEG_UNCHANGED (current_buffer) |
| 211 | #define END_UNCHANGED BUF_END_UNCHANGED (current_buffer) | 149 | #define END_UNCHANGED BUF_END_UNCHANGED (current_buffer) |
| 212 | |||
| 213 | /* Compute how many characters at the top and bottom of BUF are | ||
| 214 | unchanged when the range START..END is modified. This computation | ||
| 215 | must be done each time BUF is modified. */ | ||
| 216 | |||
| 217 | #define BUF_COMPUTE_UNCHANGED(buf, start, end) \ | ||
| 218 | do \ | ||
| 219 | { \ | ||
| 220 | if (BUF_UNCHANGED_MODIFIED (buf) == BUF_MODIFF (buf) \ | ||
| 221 | && (BUF_OVERLAY_UNCHANGED_MODIFIED (buf) \ | ||
| 222 | == BUF_OVERLAY_MODIFF (buf))) \ | ||
| 223 | { \ | ||
| 224 | BUF_BEG_UNCHANGED (buf) = (start) - BUF_BEG (buf); \ | ||
| 225 | BUF_END_UNCHANGED (buf) = BUF_Z (buf) - (end); \ | ||
| 226 | } \ | ||
| 227 | else \ | ||
| 228 | { \ | ||
| 229 | if (BUF_Z (buf) - (end) < BUF_END_UNCHANGED (buf)) \ | ||
| 230 | BUF_END_UNCHANGED (buf) = BUF_Z (buf) - (end); \ | ||
| 231 | if ((start) - BUF_BEG (buf) < BUF_BEG_UNCHANGED (buf)) \ | ||
| 232 | BUF_BEG_UNCHANGED (buf) = (start) - BUF_BEG (buf); \ | ||
| 233 | } \ | ||
| 234 | } \ | ||
| 235 | while (false) | ||
| 236 | |||
| 237 | 150 | ||
| 238 | /* Macros to set PT in the current buffer, or another buffer. */ | 151 | /* Functions to set PT in the current buffer, or another buffer. */ |
| 239 | |||
| 240 | #define SET_PT(position) (set_point (position)) | ||
| 241 | #define TEMP_SET_PT(position) (temp_set_point (current_buffer, (position))) | ||
| 242 | |||
| 243 | #define SET_PT_BOTH(position, byte) (set_point_both (position, byte)) | ||
| 244 | #define TEMP_SET_PT_BOTH(position, byte) \ | ||
| 245 | (temp_set_point_both (current_buffer, (position), (byte))) | ||
| 246 | |||
| 247 | #define BUF_TEMP_SET_PT(buffer, position) \ | ||
| 248 | (temp_set_point ((buffer), (position))) | ||
| 249 | 152 | ||
| 250 | extern void set_point (ptrdiff_t); | 153 | extern void set_point (ptrdiff_t); |
| 251 | extern void temp_set_point (struct buffer *, ptrdiff_t); | 154 | extern void temp_set_point (struct buffer *, ptrdiff_t); |
| @@ -255,39 +158,32 @@ extern void temp_set_point_both (struct buffer *, | |||
| 255 | extern void set_point_from_marker (Lisp_Object); | 158 | extern void set_point_from_marker (Lisp_Object); |
| 256 | extern void enlarge_buffer_text (struct buffer *, ptrdiff_t); | 159 | extern void enlarge_buffer_text (struct buffer *, ptrdiff_t); |
| 257 | 160 | ||
| 161 | INLINE void | ||
| 162 | SET_PT (ptrdiff_t position) | ||
| 163 | { | ||
| 164 | set_point (position); | ||
| 165 | } | ||
| 166 | INLINE void | ||
| 167 | TEMP_SET_PT (ptrdiff_t position) | ||
| 168 | { | ||
| 169 | temp_set_point (current_buffer, position); | ||
| 170 | } | ||
| 171 | INLINE void | ||
| 172 | SET_PT_BOTH (ptrdiff_t position, ptrdiff_t byte) | ||
| 173 | { | ||
| 174 | set_point_both (position, byte); | ||
| 175 | } | ||
| 176 | INLINE void | ||
| 177 | TEMP_SET_PT_BOTH (ptrdiff_t position, ptrdiff_t byte) | ||
| 178 | { | ||
| 179 | temp_set_point_both (current_buffer, position, byte); | ||
| 180 | } | ||
| 181 | INLINE void | ||
| 182 | BUF_TEMP_SET_PT (struct buffer *buffer, ptrdiff_t position) | ||
| 183 | { | ||
| 184 | temp_set_point (buffer, position); | ||
| 185 | } | ||
| 258 | 186 | ||
| 259 | /* Macros for setting the BEGV, ZV or PT of a given buffer. | ||
| 260 | |||
| 261 | The ..._BOTH macros take both a charpos and a bytepos, | ||
| 262 | which must correspond to each other. | ||
| 263 | |||
| 264 | The macros without ..._BOTH take just a charpos, | ||
| 265 | and compute the bytepos from it. */ | ||
| 266 | |||
| 267 | #define SET_BUF_BEGV(buf, charpos) \ | ||
| 268 | ((buf)->begv_byte = buf_charpos_to_bytepos ((buf), (charpos)), \ | ||
| 269 | (buf)->begv = (charpos)) | ||
| 270 | |||
| 271 | #define SET_BUF_ZV(buf, charpos) \ | ||
| 272 | ((buf)->zv_byte = buf_charpos_to_bytepos ((buf), (charpos)), \ | ||
| 273 | (buf)->zv = (charpos)) | ||
| 274 | |||
| 275 | #define SET_BUF_BEGV_BOTH(buf, charpos, byte) \ | ||
| 276 | ((buf)->begv = (charpos), \ | ||
| 277 | (buf)->begv_byte = (byte)) | ||
| 278 | |||
| 279 | #define SET_BUF_ZV_BOTH(buf, charpos, byte) \ | ||
| 280 | ((buf)->zv = (charpos), \ | ||
| 281 | (buf)->zv_byte = (byte)) | ||
| 282 | |||
| 283 | #define SET_BUF_PT_BOTH(buf, charpos, byte) \ | ||
| 284 | ((buf)->pt = (charpos), \ | ||
| 285 | (buf)->pt_byte = (byte)) | ||
| 286 | |||
| 287 | /* Macros to access a character or byte in the current buffer, | ||
| 288 | or convert between a byte position and an address. | ||
| 289 | These macros do not check that the position is in range. */ | ||
| 290 | |||
| 291 | /* Maximum number of bytes in a buffer. | 187 | /* Maximum number of bytes in a buffer. |
| 292 | A buffer cannot contain more bytes than a 1-origin fixnum can represent, | 188 | A buffer cannot contain more bytes than a 1-origin fixnum can represent, |
| 293 | nor can it be so large that C pointer arithmetic stops working. | 189 | nor can it be so large that C pointer arithmetic stops working. |
| @@ -298,115 +194,21 @@ extern void enlarge_buffer_text (struct buffer *, ptrdiff_t); | |||
| 298 | /* Maximum gap size after compact_buffer, in bytes. Also | 194 | /* Maximum gap size after compact_buffer, in bytes. Also |
| 299 | used in make_gap_larger to get some extra reserved space. */ | 195 | used in make_gap_larger to get some extra reserved space. */ |
| 300 | 196 | ||
| 301 | #define GAP_BYTES_DFL 2000 | 197 | enum { GAP_BYTES_DFL = 2000 }; |
| 302 | 198 | ||
| 303 | /* Minimum gap size after compact_buffer, in bytes. Also | 199 | /* Minimum gap size after compact_buffer, in bytes. Also |
| 304 | used in make_gap_smaller to avoid too small gap size. */ | 200 | used in make_gap_smaller to avoid too small gap size. */ |
| 305 | 201 | ||
| 306 | #define GAP_BYTES_MIN 20 | 202 | enum { GAP_BYTES_MIN = 20 }; |
| 307 | |||
| 308 | /* Return the address of byte position N in current buffer. */ | ||
| 309 | |||
| 310 | #define BYTE_POS_ADDR(n) \ | ||
| 311 | (((n) >= GPT_BYTE ? GAP_SIZE : 0) + (n) + BEG_ADDR - BEG_BYTE) | ||
| 312 | |||
| 313 | /* Return the address of char position N. */ | ||
| 314 | |||
| 315 | #define CHAR_POS_ADDR(n) \ | ||
| 316 | (((n) >= GPT ? GAP_SIZE : 0) \ | ||
| 317 | + buf_charpos_to_bytepos (current_buffer, n) \ | ||
| 318 | + BEG_ADDR - BEG_BYTE) | ||
| 319 | |||
| 320 | /* Convert a character position to a byte position. */ | ||
| 321 | |||
| 322 | #define CHAR_TO_BYTE(charpos) \ | ||
| 323 | (buf_charpos_to_bytepos (current_buffer, charpos)) | ||
| 324 | |||
| 325 | /* Convert a byte position to a character position. */ | ||
| 326 | |||
| 327 | #define BYTE_TO_CHAR(bytepos) \ | ||
| 328 | (buf_bytepos_to_charpos (current_buffer, bytepos)) | ||
| 329 | 203 | ||
| 330 | /* For those very rare cases where you may have a "random" pointer into | 204 | /* For those very rare cases where you may have a "random" pointer into |
| 331 | the middle of a multibyte char, this moves to the next boundary. */ | 205 | the middle of a multibyte char, this moves to the next boundary. */ |
| 332 | extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos); | 206 | extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos); |
| 333 | 207 | ||
| 334 | /* Convert PTR, the address of a byte in the buffer, into a byte position. */ | 208 | /* Return the byte at byte position N. |
| 335 | 209 | Do not check that the position is in range. */ | |
| 336 | #define PTR_BYTE_POS(ptr) \ | ||
| 337 | ((ptr) - (current_buffer)->text->beg \ | ||
| 338 | - (ptr - (current_buffer)->text->beg <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) \ | ||
| 339 | + BEG_BYTE) | ||
| 340 | |||
| 341 | /* Return character at byte position POS. See the caveat WARNING for | ||
| 342 | FETCH_MULTIBYTE_CHAR below. */ | ||
| 343 | |||
| 344 | #define FETCH_CHAR(pos) \ | ||
| 345 | (!NILP (BVAR (current_buffer, enable_multibyte_characters)) \ | ||
| 346 | ? FETCH_MULTIBYTE_CHAR ((pos)) \ | ||
| 347 | : FETCH_BYTE ((pos))) | ||
| 348 | |||
| 349 | /* Return the byte at byte position N. */ | ||
| 350 | 210 | ||
| 351 | #define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n))) | 211 | #define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n))) |
| 352 | |||
| 353 | /* Return character at byte position POS. If the current buffer is unibyte | ||
| 354 | and the character is not ASCII, make the returning character | ||
| 355 | multibyte. */ | ||
| 356 | |||
| 357 | #define FETCH_CHAR_AS_MULTIBYTE(pos) \ | ||
| 358 | (!NILP (BVAR (current_buffer, enable_multibyte_characters)) \ | ||
| 359 | ? FETCH_MULTIBYTE_CHAR ((pos)) \ | ||
| 360 | : UNIBYTE_TO_CHAR (FETCH_BYTE ((pos)))) | ||
| 361 | |||
| 362 | |||
| 363 | /* Macros for accessing a character or byte, | ||
| 364 | or converting between byte positions and addresses, | ||
| 365 | in a specified buffer. */ | ||
| 366 | |||
| 367 | /* Return the address of character at byte position POS in buffer BUF. | ||
| 368 | Note that both arguments can be computed more than once. */ | ||
| 369 | |||
| 370 | #define BUF_BYTE_ADDRESS(buf, pos) \ | ||
| 371 | ((buf)->text->beg + (pos) - BEG_BYTE \ | ||
| 372 | + ((pos) >= (buf)->text->gpt_byte ? (buf)->text->gap_size : 0)) | ||
| 373 | |||
| 374 | /* Return the address of character at char position POS in buffer BUF. | ||
| 375 | Note that both arguments can be computed more than once. */ | ||
| 376 | |||
| 377 | #define BUF_CHAR_ADDRESS(buf, pos) \ | ||
| 378 | ((buf)->text->beg + buf_charpos_to_bytepos ((buf), (pos)) - BEG_BYTE \ | ||
| 379 | + ((pos) >= (buf)->text->gpt ? (buf)->text->gap_size : 0)) | ||
| 380 | |||
| 381 | /* Convert PTR, the address of a char in buffer BUF, | ||
| 382 | into a character position. */ | ||
| 383 | |||
| 384 | #define BUF_PTR_BYTE_POS(buf, ptr) \ | ||
| 385 | ((ptr) - (buf)->text->beg \ | ||
| 386 | - (ptr - (buf)->text->beg <= BUF_GPT_BYTE (buf) - BEG_BYTE \ | ||
| 387 | ? 0 : BUF_GAP_SIZE ((buf))) \ | ||
| 388 | + BEG_BYTE) | ||
| 389 | |||
| 390 | /* Return the character at byte position POS in buffer BUF. */ | ||
| 391 | |||
| 392 | #define BUF_FETCH_CHAR(buf, pos) \ | ||
| 393 | (!NILP (buf->enable_multibyte_characters) \ | ||
| 394 | ? BUF_FETCH_MULTIBYTE_CHAR ((buf), (pos)) \ | ||
| 395 | : BUF_FETCH_BYTE ((buf), (pos))) | ||
| 396 | |||
| 397 | /* Return character at byte position POS in buffer BUF. If BUF is | ||
| 398 | unibyte and the character is not ASCII, make the returning | ||
| 399 | character multibyte. */ | ||
| 400 | |||
| 401 | #define BUF_FETCH_CHAR_AS_MULTIBYTE(buf, pos) \ | ||
| 402 | (! NILP (BVAR ((buf), enable_multibyte_characters)) \ | ||
| 403 | ? BUF_FETCH_MULTIBYTE_CHAR ((buf), (pos)) \ | ||
| 404 | : UNIBYTE_TO_CHAR (BUF_FETCH_BYTE ((buf), (pos)))) | ||
| 405 | |||
| 406 | /* Return the byte at byte position N in buffer BUF. */ | ||
| 407 | |||
| 408 | #define BUF_FETCH_BYTE(buf, n) \ | ||
| 409 | *(BUF_BYTE_ADDRESS ((buf), (n))) | ||
| 410 | 212 | ||
| 411 | /* Define the actual buffer data structures. */ | 213 | /* Define the actual buffer data structures. */ |
| 412 | 214 | ||
| @@ -482,6 +284,13 @@ struct buffer_text | |||
| 482 | 284 | ||
| 483 | #define BVAR(buf, field) ((buf)->field ## _) | 285 | #define BVAR(buf, field) ((buf)->field ## _) |
| 484 | 286 | ||
| 287 | /* Max number of builtin per-buffer variables. */ | ||
| 288 | enum { MAX_PER_BUFFER_VARS = 50 }; | ||
| 289 | |||
| 290 | /* Special values for struct buffer.modtime. */ | ||
| 291 | enum { NONEXISTENT_MODTIME_NSECS = -1 }; | ||
| 292 | enum { UNKNOWN_MODTIME_NSECS = -2 }; | ||
| 293 | |||
| 485 | /* This is the structure that the buffer Lisp object points to. */ | 294 | /* This is the structure that the buffer Lisp object points to. */ |
| 486 | 295 | ||
| 487 | struct buffer | 296 | struct buffer |
| @@ -796,7 +605,6 @@ struct buffer | |||
| 796 | for a buffer-local variable is stored in that variable's slot | 605 | for a buffer-local variable is stored in that variable's slot |
| 797 | in buffer_local_flags as a Lisp integer. If the index is -1, | 606 | in buffer_local_flags as a Lisp integer. If the index is -1, |
| 798 | this means the variable is always local in all buffers. */ | 607 | this means the variable is always local in all buffers. */ |
| 799 | #define MAX_PER_BUFFER_VARS 50 | ||
| 800 | char local_flags[MAX_PER_BUFFER_VARS]; | 608 | char local_flags[MAX_PER_BUFFER_VARS]; |
| 801 | 609 | ||
| 802 | /* Set to the modtime of the visited file when read or written. | 610 | /* Set to the modtime of the visited file when read or written. |
| @@ -804,8 +612,6 @@ struct buffer | |||
| 804 | visited file was nonexistent. modtime.tv_nsec == | 612 | visited file was nonexistent. modtime.tv_nsec == |
| 805 | UNKNOWN_MODTIME_NSECS means visited file modtime unknown; | 613 | UNKNOWN_MODTIME_NSECS means visited file modtime unknown; |
| 806 | in no case complain about any mismatch on next save attempt. */ | 614 | in no case complain about any mismatch on next save attempt. */ |
| 807 | #define NONEXISTENT_MODTIME_NSECS (-1) | ||
| 808 | #define UNKNOWN_MODTIME_NSECS (-2) | ||
| 809 | struct timespec modtime; | 615 | struct timespec modtime; |
| 810 | 616 | ||
| 811 | /* Size of the file when modtime was set. This is used to detect the | 617 | /* Size of the file when modtime was set. This is used to detect the |
| @@ -1018,49 +824,281 @@ bset_width_table (struct buffer *b, Lisp_Object val) | |||
| 1018 | b->width_table_ = val; | 824 | b->width_table_ = val; |
| 1019 | } | 825 | } |
| 1020 | 826 | ||
| 827 | /* BUFFER_CEILING_OF (resp. BUFFER_FLOOR_OF), when applied to n, return | ||
| 828 | the max (resp. min) p such that | ||
| 829 | |||
| 830 | BYTE_POS_ADDR (p) - BYTE_POS_ADDR (n) == p - n */ | ||
| 831 | |||
| 832 | INLINE ptrdiff_t | ||
| 833 | BUFFER_CEILING_OF (ptrdiff_t bytepos) | ||
| 834 | { | ||
| 835 | return (bytepos < GPT_BYTE && GPT < ZV ? GPT_BYTE : ZV_BYTE) - 1; | ||
| 836 | } | ||
| 837 | |||
| 838 | INLINE ptrdiff_t | ||
| 839 | BUFFER_FLOOR_OF (ptrdiff_t bytepos) | ||
| 840 | { | ||
| 841 | return BEGV <= GPT && GPT_BYTE <= bytepos ? GPT_BYTE : BEGV_BYTE; | ||
| 842 | } | ||
| 843 | |||
| 844 | /* The BUF_BEGV[_BYTE], BUF_ZV[_BYTE], and BUF_PT[_BYTE] functions cannot | ||
| 845 | be used for assignment; use SET_BUF_* functions below for that. */ | ||
| 846 | |||
| 847 | /* Position of beginning of accessible range of buffer. */ | ||
| 848 | INLINE ptrdiff_t | ||
| 849 | BUF_BEGV (struct buffer *buf) | ||
| 850 | { | ||
| 851 | return (buf == current_buffer ? BEGV | ||
| 852 | : NILP (BVAR (buf, begv_marker)) ? buf->begv | ||
| 853 | : marker_position (BVAR (buf, begv_marker))); | ||
| 854 | } | ||
| 855 | |||
| 856 | INLINE ptrdiff_t | ||
| 857 | BUF_BEGV_BYTE (struct buffer *buf) | ||
| 858 | { | ||
| 859 | return (buf == current_buffer ? BEGV_BYTE | ||
| 860 | : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte | ||
| 861 | : marker_byte_position (BVAR (buf, begv_marker))); | ||
| 862 | } | ||
| 863 | |||
| 864 | /* Position of point in buffer. */ | ||
| 865 | INLINE ptrdiff_t | ||
| 866 | BUF_PT (struct buffer *buf) | ||
| 867 | { | ||
| 868 | return (buf == current_buffer ? PT | ||
| 869 | : NILP (BVAR (buf, pt_marker)) ? buf->pt | ||
| 870 | : marker_position (BVAR (buf, pt_marker))); | ||
| 871 | } | ||
| 872 | |||
| 873 | INLINE ptrdiff_t | ||
| 874 | BUF_PT_BYTE (struct buffer *buf) | ||
| 875 | { | ||
| 876 | return (buf == current_buffer ? PT_BYTE | ||
| 877 | : NILP (BVAR (buf, pt_marker)) ? buf->pt_byte | ||
| 878 | : marker_byte_position (BVAR (buf, pt_marker))); | ||
| 879 | } | ||
| 880 | |||
| 881 | /* Position of end of accessible range of buffer. */ | ||
| 882 | INLINE ptrdiff_t | ||
| 883 | BUF_ZV (struct buffer *buf) | ||
| 884 | { | ||
| 885 | return (buf == current_buffer ? ZV | ||
| 886 | : NILP (BVAR (buf, zv_marker)) ? buf->zv | ||
| 887 | : marker_position (BVAR (buf, zv_marker))); | ||
| 888 | } | ||
| 889 | |||
| 890 | INLINE ptrdiff_t | ||
| 891 | BUF_ZV_BYTE (struct buffer *buf) | ||
| 892 | { | ||
| 893 | return (buf == current_buffer ? ZV_BYTE | ||
| 894 | : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte | ||
| 895 | : marker_byte_position (BVAR (buf, zv_marker))); | ||
| 896 | } | ||
| 897 | |||
| 898 | /* Similar functions to operate on a specified buffer. */ | ||
| 899 | |||
| 900 | /* Position of beginning of buffer. */ | ||
| 901 | INLINE ptrdiff_t | ||
| 902 | BUF_BEG (struct buffer *buf) | ||
| 903 | { | ||
| 904 | return BEG; | ||
| 905 | } | ||
| 906 | |||
| 907 | INLINE ptrdiff_t | ||
| 908 | BUF_BEG_BYTE (struct buffer *buf) | ||
| 909 | { | ||
| 910 | return BEG_BYTE; | ||
| 911 | } | ||
| 912 | |||
| 913 | /* Address of beginning of gap of buffer. */ | ||
| 914 | INLINE unsigned char * | ||
| 915 | BUF_GPT_ADDR (struct buffer *buf) | ||
| 916 | { | ||
| 917 | return buf->text->beg + buf->text->gpt_byte - BEG_BYTE; | ||
| 918 | } | ||
| 919 | |||
| 920 | /* Address of end of buffer. */ | ||
| 921 | INLINE unsigned char * | ||
| 922 | BUF_Z_ADDR (struct buffer *buf) | ||
| 923 | { | ||
| 924 | return buf->text->beg + buf->text->gap_size + buf->text->z_byte - BEG_BYTE; | ||
| 925 | } | ||
| 926 | |||
| 927 | /* Address of end of gap in buffer. */ | ||
| 928 | INLINE unsigned char * | ||
| 929 | BUF_GAP_END_ADDR (struct buffer *buf) | ||
| 930 | { | ||
| 931 | return buf->text->beg + buf->text->gpt_byte + buf->text->gap_size - BEG_BYTE; | ||
| 932 | } | ||
| 933 | |||
| 934 | /* Compute how many characters at the top and bottom of BUF are | ||
| 935 | unchanged when the range START..END is modified. This computation | ||
| 936 | must be done each time BUF is modified. */ | ||
| 937 | |||
| 938 | INLINE void | ||
| 939 | BUF_COMPUTE_UNCHANGED (struct buffer *buf, ptrdiff_t start, ptrdiff_t end) | ||
| 940 | { | ||
| 941 | if (BUF_UNCHANGED_MODIFIED (buf) == BUF_MODIFF (buf) | ||
| 942 | && (BUF_OVERLAY_UNCHANGED_MODIFIED (buf) | ||
| 943 | == BUF_OVERLAY_MODIFF (buf))) | ||
| 944 | { | ||
| 945 | buf->text->beg_unchanged = start - BUF_BEG (buf); | ||
| 946 | buf->text->end_unchanged = BUF_Z (buf) - (end); | ||
| 947 | } | ||
| 948 | else | ||
| 949 | { | ||
| 950 | if (BUF_Z (buf) - end < BUF_END_UNCHANGED (buf)) | ||
| 951 | buf->text->end_unchanged = BUF_Z (buf) - end; | ||
| 952 | if (start - BUF_BEG (buf) < BUF_BEG_UNCHANGED (buf)) | ||
| 953 | buf->text->beg_unchanged = start - BUF_BEG (buf); | ||
| 954 | } | ||
| 955 | } | ||
| 956 | |||
| 957 | /* Functions for setting the BEGV, ZV or PT of a given buffer. | ||
| 958 | |||
| 959 | The ..._BOTH functions take both a charpos and a bytepos, | ||
| 960 | which must correspond to each other. | ||
| 961 | |||
| 962 | The functions without ..._BOTH take just a charpos, | ||
| 963 | and compute the bytepos from it. */ | ||
| 964 | |||
| 965 | INLINE void | ||
| 966 | SET_BUF_BEGV (struct buffer *buf, ptrdiff_t charpos) | ||
| 967 | { | ||
| 968 | buf->begv_byte = buf_charpos_to_bytepos (buf, charpos); | ||
| 969 | buf->begv = charpos; | ||
| 970 | } | ||
| 971 | |||
| 972 | INLINE void | ||
| 973 | SET_BUF_ZV (struct buffer *buf, ptrdiff_t charpos) | ||
| 974 | { | ||
| 975 | buf->zv_byte = buf_charpos_to_bytepos (buf, charpos); | ||
| 976 | buf->zv = charpos; | ||
| 977 | } | ||
| 978 | |||
| 979 | INLINE void | ||
| 980 | SET_BUF_BEGV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte) | ||
| 981 | { | ||
| 982 | buf->begv = charpos; | ||
| 983 | buf->begv_byte = byte; | ||
| 984 | } | ||
| 985 | |||
| 986 | INLINE void | ||
| 987 | SET_BUF_ZV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte) | ||
| 988 | { | ||
| 989 | buf->zv = charpos; | ||
| 990 | buf->zv_byte = byte; | ||
| 991 | } | ||
| 992 | |||
| 993 | INLINE void | ||
| 994 | SET_BUF_PT_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte) | ||
| 995 | { | ||
| 996 | buf->pt = charpos; | ||
| 997 | buf->pt_byte = byte; | ||
| 998 | } | ||
| 999 | |||
| 1000 | /* Functions to access a character or byte in the current buffer, | ||
| 1001 | or convert between a byte position and an address. | ||
| 1002 | These functions do not check that the position is in range. */ | ||
| 1003 | |||
| 1004 | /* Return the address of byte position N in current buffer. */ | ||
| 1005 | |||
| 1006 | INLINE unsigned char * | ||
| 1007 | BYTE_POS_ADDR (ptrdiff_t n) | ||
| 1008 | { | ||
| 1009 | return (n < GPT_BYTE ? 0 : GAP_SIZE) + n + BEG_ADDR - BEG_BYTE; | ||
| 1010 | } | ||
| 1011 | |||
| 1012 | /* Return the address of char position N. */ | ||
| 1013 | |||
| 1014 | INLINE unsigned char * | ||
| 1015 | CHAR_POS_ADDR (ptrdiff_t n) | ||
| 1016 | { | ||
| 1017 | return ((n < GPT ? 0 : GAP_SIZE) | ||
| 1018 | + buf_charpos_to_bytepos (current_buffer, n) | ||
| 1019 | + BEG_ADDR - BEG_BYTE); | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | /* Convert a character position to a byte position. */ | ||
| 1023 | |||
| 1024 | INLINE ptrdiff_t | ||
| 1025 | CHAR_TO_BYTE (ptrdiff_t charpos) | ||
| 1026 | { | ||
| 1027 | return buf_charpos_to_bytepos (current_buffer, charpos); | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | /* Convert a byte position to a character position. */ | ||
| 1031 | |||
| 1032 | INLINE ptrdiff_t | ||
| 1033 | BYTE_TO_CHAR (ptrdiff_t bytepos) | ||
| 1034 | { | ||
| 1035 | return buf_bytepos_to_charpos (current_buffer, bytepos); | ||
| 1036 | } | ||
| 1037 | |||
| 1038 | /* Convert PTR, the address of a byte in the buffer, into a byte position. */ | ||
| 1039 | |||
| 1040 | INLINE ptrdiff_t | ||
| 1041 | PTR_BYTE_POS (unsigned char const *ptr) | ||
| 1042 | { | ||
| 1043 | ptrdiff_t byte = ptr - current_buffer->text->beg; | ||
| 1044 | return byte - (byte <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) + BEG_BYTE; | ||
| 1045 | } | ||
| 1046 | |||
| 1021 | /* Number of Lisp_Objects at the beginning of struct buffer. | 1047 | /* Number of Lisp_Objects at the beginning of struct buffer. |
| 1022 | If you add, remove, or reorder Lisp_Objects within buffer | 1048 | If you add, remove, or reorder Lisp_Objects within buffer |
| 1023 | structure, make sure that this is still correct. */ | 1049 | structure, make sure that this is still correct. */ |
| 1024 | 1050 | ||
| 1025 | #define BUFFER_LISP_SIZE \ | 1051 | enum { BUFFER_LISP_SIZE = PSEUDOVECSIZE (struct buffer, |
| 1026 | PSEUDOVECSIZE (struct buffer, cursor_in_non_selected_windows_) | 1052 | cursor_in_non_selected_windows_) }; |
| 1027 | 1053 | ||
| 1028 | /* Allocated size of the struct buffer part beyond leading | 1054 | /* Allocated size of the struct buffer part beyond leading |
| 1029 | Lisp_Objects, in word_size units. */ | 1055 | Lisp_Objects, in word_size units. */ |
| 1030 | 1056 | ||
| 1031 | #define BUFFER_REST_SIZE (VECSIZE (struct buffer) - BUFFER_LISP_SIZE) | 1057 | enum { BUFFER_REST_SIZE = VECSIZE (struct buffer) - BUFFER_LISP_SIZE }; |
| 1032 | 1058 | ||
| 1033 | /* Initialize the pseudovector header of buffer object. BUFFER_LISP_SIZE | 1059 | /* Initialize the pseudovector header of buffer object. BUFFER_LISP_SIZE |
| 1034 | is required for GC, but BUFFER_REST_SIZE is set up just to be consistent | 1060 | is required for GC, but BUFFER_REST_SIZE is set up just to be consistent |
| 1035 | with other pseudovectors. */ | 1061 | with other pseudovectors. */ |
| 1036 | 1062 | ||
| 1037 | #define BUFFER_PVEC_INIT(b) \ | 1063 | INLINE void |
| 1038 | XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE) | 1064 | BUFFER_PVEC_INIT (struct buffer *b) |
| 1065 | { | ||
| 1066 | XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE); | ||
| 1067 | } | ||
| 1039 | 1068 | ||
| 1040 | /* Convenient check whether buffer B is live. */ | 1069 | /* Convenient check whether buffer B is live. */ |
| 1041 | 1070 | ||
| 1042 | #define BUFFER_LIVE_P(b) (!NILP (BVAR (b, name))) | 1071 | INLINE bool |
| 1072 | BUFFER_LIVE_P (struct buffer *b) | ||
| 1073 | { | ||
| 1074 | return !NILP (BVAR (b, name)); | ||
| 1075 | } | ||
| 1043 | 1076 | ||
| 1044 | /* Convenient check whether buffer B is hidden (i.e. its name | 1077 | /* Convenient check whether buffer B is hidden (i.e. its name |
| 1045 | starts with a space). Caller must ensure that B is live. */ | 1078 | starts with a space). Caller must ensure that B is live. */ |
| 1046 | 1079 | ||
| 1047 | #define BUFFER_HIDDEN_P(b) (SREF (BVAR (b, name), 0) == ' ') | 1080 | INLINE bool |
| 1081 | BUFFER_HIDDEN_P (struct buffer *b) | ||
| 1082 | { | ||
| 1083 | return SREF (BVAR (b, name), 0) == ' '; | ||
| 1084 | } | ||
| 1048 | 1085 | ||
| 1049 | /* Verify indirection counters. */ | 1086 | /* Verify indirection counters. */ |
| 1050 | 1087 | ||
| 1051 | #define BUFFER_CHECK_INDIRECTION(b) \ | 1088 | INLINE void |
| 1052 | do { \ | 1089 | BUFFER_CHECK_INDIRECTION (struct buffer *b) |
| 1053 | if (BUFFER_LIVE_P (b)) \ | 1090 | { |
| 1054 | { \ | 1091 | if (BUFFER_LIVE_P (b)) |
| 1055 | if (b->base_buffer) \ | 1092 | { |
| 1056 | { \ | 1093 | if (b->base_buffer) |
| 1057 | eassert (b->indirections == -1); \ | 1094 | { |
| 1058 | eassert (b->base_buffer->indirections > 0); \ | 1095 | eassert (b->indirections == -1); |
| 1059 | } \ | 1096 | eassert (b->base_buffer->indirections > 0); |
| 1060 | else \ | 1097 | } |
| 1061 | eassert (b->indirections >= 0); \ | 1098 | else |
| 1062 | } \ | 1099 | eassert (b->indirections >= 0); |
| 1063 | } while (false) | 1100 | } |
| 1101 | } | ||
| 1064 | 1102 | ||
| 1065 | /* Chain of all buffers, including killed ones. */ | 1103 | /* Chain of all buffers, including killed ones. */ |
| 1066 | 1104 | ||
| @@ -1157,7 +1195,9 @@ record_unwind_current_buffer (void) | |||
| 1157 | 1195 | ||
| 1158 | /* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements. | 1196 | /* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements. |
| 1159 | If NEXTP is non-NULL, return next overlay there. | 1197 | If NEXTP is non-NULL, return next overlay there. |
| 1160 | See overlay_at arg CHANGE_REQ for meaning of CHRQ arg. */ | 1198 | See overlay_at arg CHANGE_REQ for meaning of CHRQ arg. |
| 1199 | This macro might evaluate its args multiple times, | ||
| 1200 | and it treat some args as lvalues. */ | ||
| 1161 | 1201 | ||
| 1162 | #define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \ | 1202 | #define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \ |
| 1163 | do { \ | 1203 | do { \ |
| @@ -1207,6 +1247,10 @@ buffer_has_overlays (void) | |||
| 1207 | { | 1247 | { |
| 1208 | return current_buffer->overlays_before || current_buffer->overlays_after; | 1248 | return current_buffer->overlays_before || current_buffer->overlays_after; |
| 1209 | } | 1249 | } |
| 1250 | |||
| 1251 | /* Functions for accessing a character or byte, | ||
| 1252 | or converting between byte positions and addresses, | ||
| 1253 | in a specified buffer. */ | ||
| 1210 | 1254 | ||
| 1211 | /* Return character code of multi-byte form at byte position POS. If POS | 1255 | /* Return character code of multi-byte form at byte position POS. If POS |
| 1212 | doesn't point the head of valid multi-byte form, only the byte at | 1256 | doesn't point the head of valid multi-byte form, only the byte at |
| @@ -1232,6 +1276,80 @@ BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos) | |||
| 1232 | return STRING_CHAR (p); | 1276 | return STRING_CHAR (p); |
| 1233 | } | 1277 | } |
| 1234 | 1278 | ||
| 1279 | /* Return character at byte position POS. | ||
| 1280 | If the current buffer is unibyte and the character is not ASCII, | ||
| 1281 | make the returning character multibyte. */ | ||
| 1282 | |||
| 1283 | INLINE int | ||
| 1284 | FETCH_CHAR_AS_MULTIBYTE (ptrdiff_t pos) | ||
| 1285 | { | ||
| 1286 | return (!NILP (BVAR (current_buffer, enable_multibyte_characters)) | ||
| 1287 | ? FETCH_MULTIBYTE_CHAR (pos) | ||
| 1288 | : UNIBYTE_TO_CHAR (FETCH_BYTE (pos))); | ||
| 1289 | } | ||
| 1290 | |||
| 1291 | /* Return character at byte position POS. | ||
| 1292 | See the caveat WARNING for FETCH_MULTIBYTE_CHAR above. */ | ||
| 1293 | |||
| 1294 | INLINE int | ||
| 1295 | FETCH_CHAR (ptrdiff_t pos) | ||
| 1296 | { | ||
| 1297 | return (!NILP (BVAR (current_buffer, enable_multibyte_characters)) | ||
| 1298 | ? FETCH_MULTIBYTE_CHAR (pos) | ||
| 1299 | : FETCH_BYTE (pos)); | ||
| 1300 | } | ||
| 1301 | |||
| 1302 | /* Return the address of character at byte position POS in buffer BUF. | ||
| 1303 | Note that both arguments can be computed more than once. */ | ||
| 1304 | |||
| 1305 | INLINE unsigned char * | ||
| 1306 | BUF_BYTE_ADDRESS (struct buffer *buf, ptrdiff_t pos) | ||
| 1307 | { | ||
| 1308 | return (buf->text->beg + pos - BEG_BYTE | ||
| 1309 | + (pos < buf->text->gpt_byte ? 0 : buf->text->gap_size)); | ||
| 1310 | } | ||
| 1311 | |||
| 1312 | /* Return the address of character at char position POS in buffer BUF. | ||
| 1313 | Note that both arguments can be computed more than once. */ | ||
| 1314 | |||
| 1315 | INLINE unsigned char * | ||
| 1316 | BUF_CHAR_ADDRESS (struct buffer *buf, ptrdiff_t pos) | ||
| 1317 | { | ||
| 1318 | return (buf->text->beg + buf_charpos_to_bytepos (buf, pos) - BEG_BYTE | ||
| 1319 | + (pos < buf->text->gpt ? 0 : buf->text->gap_size)); | ||
| 1320 | } | ||
| 1321 | |||
| 1322 | /* Convert PTR, the address of a char in buffer BUF, | ||
| 1323 | into a character position. */ | ||
| 1324 | |||
| 1325 | INLINE ptrdiff_t | ||
| 1326 | BUF_PTR_BYTE_POS (struct buffer *buf, unsigned char *ptr) | ||
| 1327 | { | ||
| 1328 | ptrdiff_t byte = ptr - buf->text->beg; | ||
| 1329 | return (byte - (byte <= BUF_GPT_BYTE (buf) - BEG_BYTE ? 0 : BUF_GAP_SIZE (buf)) | ||
| 1330 | + BEG_BYTE); | ||
| 1331 | } | ||
| 1332 | |||
| 1333 | /* Return the byte at byte position N in buffer BUF. */ | ||
| 1334 | |||
| 1335 | INLINE unsigned char | ||
| 1336 | BUF_FETCH_BYTE (struct buffer *buf, ptrdiff_t n) | ||
| 1337 | { | ||
| 1338 | return *BUF_BYTE_ADDRESS (buf, n); | ||
| 1339 | } | ||
| 1340 | |||
| 1341 | /* Return character at byte position POS in buffer BUF. If BUF is | ||
| 1342 | unibyte and the character is not ASCII, make the returning | ||
| 1343 | character multibyte. */ | ||
| 1344 | |||
| 1345 | INLINE int | ||
| 1346 | BUF_FETCH_CHAR_AS_MULTIBYTE (struct buffer *buf, ptrdiff_t pos) | ||
| 1347 | { | ||
| 1348 | return (! NILP (BVAR (buf, enable_multibyte_characters)) | ||
| 1349 | ? BUF_FETCH_MULTIBYTE_CHAR (buf, pos) | ||
| 1350 | : UNIBYTE_TO_CHAR (BUF_FETCH_BYTE (buf, pos))); | ||
| 1351 | } | ||
| 1352 | |||
| 1235 | /* Return number of windows showing B. */ | 1353 | /* Return number of windows showing B. */ |
| 1236 | 1354 | ||
| 1237 | INLINE int | 1355 | INLINE int |
| @@ -1260,8 +1378,11 @@ buffer_window_count (struct buffer *b) | |||
| 1260 | /* Return the actual buffer position for the marker P. | 1378 | /* Return the actual buffer position for the marker P. |
| 1261 | We assume you know which buffer it's pointing into. */ | 1379 | We assume you know which buffer it's pointing into. */ |
| 1262 | 1380 | ||
| 1263 | #define OVERLAY_POSITION(P) \ | 1381 | INLINE ptrdiff_t |
| 1264 | (MARKERP (P) ? marker_position (P) : (emacs_abort (), 0)) | 1382 | OVERLAY_POSITION (Lisp_Object p) |
| 1383 | { | ||
| 1384 | return marker_position (p); | ||
| 1385 | } | ||
| 1265 | 1386 | ||
| 1266 | 1387 | ||
| 1267 | /*********************************************************************** | 1388 | /*********************************************************************** |
| @@ -1297,16 +1418,22 @@ extern bool valid_per_buffer_idx (int); | |||
| 1297 | /* Value is true if the variable with index IDX has a local value | 1418 | /* Value is true if the variable with index IDX has a local value |
| 1298 | in buffer B. */ | 1419 | in buffer B. */ |
| 1299 | 1420 | ||
| 1300 | #define PER_BUFFER_VALUE_P(B, IDX) \ | 1421 | INLINE bool |
| 1301 | (eassert (valid_per_buffer_idx (IDX)), \ | 1422 | PER_BUFFER_VALUE_P (struct buffer *b, int idx) |
| 1302 | (B)->local_flags[IDX]) | 1423 | { |
| 1424 | eassert (valid_per_buffer_idx (idx)); | ||
| 1425 | return b->local_flags[idx]; | ||
| 1426 | } | ||
| 1303 | 1427 | ||
| 1304 | /* Set whether per-buffer variable with index IDX has a buffer-local | 1428 | /* Set whether per-buffer variable with index IDX has a buffer-local |
| 1305 | value in buffer B. VAL zero means it hasn't. */ | 1429 | value in buffer B. VAL zero means it hasn't. */ |
| 1306 | 1430 | ||
| 1307 | #define SET_PER_BUFFER_VALUE_P(B, IDX, VAL) \ | 1431 | INLINE void |
| 1308 | (eassert (valid_per_buffer_idx (IDX)), \ | 1432 | SET_PER_BUFFER_VALUE_P (struct buffer *b, int idx, bool val) |
| 1309 | (B)->local_flags[IDX] = (VAL)) | 1433 | { |
| 1434 | eassert (valid_per_buffer_idx (idx)); | ||
| 1435 | b->local_flags[idx] = val; | ||
| 1436 | } | ||
| 1310 | 1437 | ||
| 1311 | /* Return the index value of the per-buffer variable at offset OFFSET | 1438 | /* Return the index value of the per-buffer variable at offset OFFSET |
| 1312 | in the buffer structure. | 1439 | in the buffer structure. |
| @@ -1326,11 +1453,13 @@ extern bool valid_per_buffer_idx (int); | |||
| 1326 | new buffer. | 1453 | new buffer. |
| 1327 | 1454 | ||
| 1328 | If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is | 1455 | If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is |
| 1329 | zero, that is a bug */ | 1456 | zero, that is a bug. */ |
| 1330 | 1457 | ||
| 1331 | 1458 | INLINE int | |
| 1332 | #define PER_BUFFER_IDX(OFFSET) \ | 1459 | PER_BUFFER_IDX (ptrdiff_t offset) |
| 1333 | XFIXNUM (*(Lisp_Object *)((OFFSET) + (char *) &buffer_local_flags)) | 1460 | { |
| 1461 | return XFIXNUM (*(Lisp_Object *) (offset + (char *) &buffer_local_flags)); | ||
| 1462 | } | ||
| 1334 | 1463 | ||
| 1335 | /* Functions to get and set default value of the per-buffer | 1464 | /* Functions to get and set default value of the per-buffer |
| 1336 | variable at offset OFFSET in the buffer structure. */ | 1465 | variable at offset OFFSET in the buffer structure. */ |