Mercurial > hg > xemacs-beta
annotate src/buffer.h @ 5581:56144c8593a8
Mechanically change INT to FIXNUM in our sources.
src/ChangeLog addition:
2011-10-09 Aidan Kehoe <kehoea@parhasard.net>
[...]
Mechanically change INT (where it refers to non-bignum Lisp
integers) to FIXNUM in our sources. Done for the following
functions, enums, and macros: Lisp_Type_Int_Even,
Lisp_Type_Int_Odd, INT_GCBITS, INT_VALBITS, make_int(), INTP(),
XINT(), CHECK_INT(), XREALINT(), INT_PLUS(), INT_MINUS(),
EMACS_INT_MAX (to MOST_POSITIVE_FIXNUM), EMACS_INT_MIN (to
MOST_NEGATIVE_FIXNUM), NUMBER_FITS_IN_AN_EMACS_INT() to
NUMBER_FITS_IN_A_FIXNUM(), XFLOATINT, XCHAR_OR_INT, INT_OR_FLOAT.
The EMACS_INT typedef was not changed, it does not describe
non-bignum Lisp integers.
Script that did the change available in
http://mid.gmane.org/20067.17650.181273.12014@parhasard.net .
modules/ChangeLog addition:
2011-10-09 Aidan Kehoe <kehoea@parhasard.net>
[...]
Mechanically change INT to FIXNUM, where the usage describes non-bignum
Lisp integers. See the src/ChangeLog entry for more details.
man/ChangeLog addition:
2011-10-09 Aidan Kehoe <kehoea@parhasard.net>
* internals/internals.texi (How Lisp Objects Are Represented in C):
* internals/internals.texi (Integers and Characters):
Mechanically change INT to FIXNUM, where the usage describes non-bignum
Lisp integers.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 09 Oct 2011 09:51:57 +0100 |
parents | 308d34e9f07d |
children |
rev | line source |
---|---|
428 | 1 /* Header file for the buffer manipulation primitives. |
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995 | |
3 Free Software Foundation, Inc. | |
4 Copyright (C) 1995 Sun Microsystems, Inc. | |
2367 | 5 Copyright (C) 2001, 2002, 2004 Ben Wing. |
428 | 6 |
7 This file is part of XEmacs. | |
8 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5127
diff
changeset
|
9 XEmacs is free software: you can redistribute it and/or modify it |
428 | 10 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5127
diff
changeset
|
11 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5127
diff
changeset
|
12 option) any later version. |
428 | 13 |
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5127
diff
changeset
|
20 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 21 |
22 /* Synched up with: FSF 19.30. */ | |
23 | |
24 /* Authorship: | |
25 | |
26 FSF: long ago. | |
27 JWZ: separated out bufslots.h, early in Lemacs. | |
28 Ben Wing: almost completely rewritten for Mule, 19.12. | |
29 */ | |
30 | |
440 | 31 #ifndef INCLUDED_buffer_h_ |
32 #define INCLUDED_buffer_h_ | |
428 | 33 |
446 | 34 #include "casetab.h" |
35 #include "chartab.h" | |
36 | |
428 | 37 /************************************************************************/ |
38 /* */ | |
39 /* definition of Lisp buffer object */ | |
40 /* */ | |
41 /************************************************************************/ | |
42 | |
665 | 43 /* Note: we keep both Bytebpos and Charbpos versions of some of the |
428 | 44 important buffer positions because they are accessed so much. |
45 If we didn't do this, we would constantly be invalidating the | |
665 | 46 charbpos<->bytebpos cache under Mule. |
428 | 47 |
48 Note that under non-Mule, both versions will always be the | |
49 same so we don't really need to keep track of them. But it | |
50 simplifies the logic to go ahead and do so all the time and | |
51 the memory loss is insignificant. */ | |
52 | |
53 /* Formerly, it didn't much matter what went inside the struct buffer_text | |
54 and what went outside it. Now it does, with the advent of "indirect | |
55 buffers" that share text with another buffer. An indirect buffer | |
56 shares the same *text* as another buffer, but has its own buffer-local | |
57 variables, its own accessible region, and its own markers and extents. | |
58 (Due to the nature of markers, it doesn't actually matter much whether | |
59 we stick them inside or out of the struct buffer_text -- the user won't | |
60 notice any difference -- but we go ahead and put them outside for | |
61 consistency and overall saneness of algorithm.) | |
62 | |
63 FSFmacs gets away with not maintaining any "children" pointers from | |
64 a buffer to the indirect buffers that refer to it by putting the | |
65 markers inside of the struct buffer_text, using markers to keep track | |
66 of BEGV and ZV in indirect buffers, and relying on the fact that | |
67 all intervals (text properties and overlays) use markers for their | |
68 start and end points. We don't do this for extents (markers are | |
69 inefficient anyway and take up space), so we have to maintain | |
70 children pointers. This is not terribly hard, though, and the | |
71 code to maintain this is just like the code already present in | |
72 extent-parent and extent-children. | |
73 */ | |
74 | |
2367 | 75 #define NUM_CACHED_POSITIONS 50 |
76 #define NUM_MOVED_POSITIONS 10 | |
77 | |
428 | 78 struct buffer_text |
79 { | |
3092 | 80 #ifdef NEW_GC |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
81 NORMAL_LISP_OBJECT_HEADER header; |
3092 | 82 #endif /* NEW_GC */ |
867 | 83 Ibyte *beg; /* Actual address of buffer contents. */ |
665 | 84 Bytebpos gpt; /* Index of gap in buffer. */ |
2367 | 85 Charbpos bufgpt; /* Equivalent as a Charbpos. */ |
665 | 86 Bytebpos z; /* Index of end of buffer. */ |
2367 | 87 Charbpos bufz; /* Equivalent as a Charbpos. */ |
665 | 88 Bytecount gap_size;/* Size of buffer's gap */ |
89 Bytecount end_gap_size;/* Size of buffer's end gap */ | |
428 | 90 long modiff; /* This counts buffer-modification events |
91 for this buffer. It is incremented for | |
92 each such event, and never otherwise | |
93 changed. */ | |
94 long save_modiff; /* Previous value of modiff, as of last | |
95 time buffer visited or saved a file. */ | |
96 | |
97 #ifdef MULE | |
2367 | 98 |
99 #ifdef OLD_BYTE_CHAR | |
771 | 100 /* We keep track of a "known" region for very fast access. This |
101 information is text-only so it goes here. We update this at each | |
102 change to the buffer, so if it's entirely ASCII, these will always | |
103 contain the minimum and maximum positions of the buffer. */ | |
665 | 104 Charbpos mule_bufmin, mule_bufmax; |
105 Bytebpos mule_bytmin, mule_bytmax; | |
428 | 106 int mule_shifter, mule_three_p; |
2367 | 107 #endif |
428 | 108 |
2367 | 109 /* And we also cache NUM_CACHED_POSITIONS positions for fairly fast |
110 access near those positions. */ | |
111 Charbpos mule_charbpos_cache[NUM_CACHED_POSITIONS]; | |
112 Bytebpos mule_bytebpos_cache[NUM_CACHED_POSITIONS]; | |
113 int next_cache_pos; | |
114 | |
115 Charbpos cached_charpos; | |
116 Bytebpos cached_bytepos; | |
771 | 117 |
826 | 118 /* True if all chars fit into one byte; |
119 == (format == FORMAT_8_BIT_FIXED || | |
120 (format == FORMAT_DEFAULT && num_ascii_chars == bufz - 1)) | |
121 kept around to speed up (slightly?) the byte-char conversion routines. */ | |
122 int entirely_one_byte_p; | |
123 /* Number of ASCII chars in buffer (0 - 127) */ | |
124 Charcount num_ascii_chars; | |
125 /* Number of chars in buffer that would fit in an 8-bit-fixed buffer. */ | |
126 Charcount num_8_bit_fixed_chars; | |
127 /* Number of chars in buffer that would fit in an 16-bit-fixed buffer. */ | |
128 Charcount num_16_bit_fixed_chars; | |
129 | |
130 /* Currently we only handle 8 bit fixed and default */ | |
131 Internal_Format format; | |
2367 | 132 #endif /* MULE */ |
428 | 133 |
134 /* Similar to the above, we keep track of positions for which line | |
135 number has last been calculated. See line-number.c. */ | |
136 Lisp_Object line_number_cache; | |
137 | |
138 /* Change data that goes with the text. */ | |
139 struct buffer_text_change_data *changes; | |
140 }; | |
141 | |
3092 | 142 #ifdef NEW_GC |
143 typedef struct buffer_text Lisp_Buffer_Text; | |
144 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3092
diff
changeset
|
145 DECLARE_LISP_OBJECT (buffer_text, Lisp_Buffer_Text); |
3092 | 146 |
147 #define XBUFFER_TEXT(x) \ | |
148 XRECORD (x, buffer_text, Lisp_Buffer_Text) | |
149 #define wrap_buffer_text(p) wrap_record (p, buffer_text) | |
150 #define BUFFER_TEXT_P(x) RECORDP (x, buffer_text) | |
151 #define CHECK_BUFFER_TEXT(x) CHECK_RECORD (x, buffer_text) | |
152 #define CONCHECK_BUFFER_TEXT(x) CONCHECK_RECORD (x, buffer_text) | |
153 #endif /* NEW_GC */ | |
154 | |
155 | |
428 | 156 struct buffer |
157 { | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
158 NORMAL_LISP_OBJECT_HEADER header; |
428 | 159 |
160 /* This structure holds the coordinates of the buffer contents | |
161 in ordinary buffers. In indirect buffers, this is not used. */ | |
162 struct buffer_text own_text; | |
163 | |
164 /* This points to the `struct buffer_text' that is used for this buffer. | |
165 In an ordinary buffer, this is the own_text field above. | |
166 In an indirect buffer, this is the own_text field of another buffer. */ | |
167 struct buffer_text *text; | |
168 | |
665 | 169 Bytebpos pt; /* Position of point in buffer. */ |
170 Charbpos bufpt; /* Equivalent as a Charbpos. */ | |
171 Bytebpos begv; /* Index of beginning of accessible range. */ | |
172 Charbpos bufbegv; /* Equivalent as a Charbpos. */ | |
173 Bytebpos zv; /* Index of end of accessible range. */ | |
174 Charbpos bufzv; /* Equivalent as a Charbpos. */ | |
428 | 175 |
176 int face_change; /* This is set when a change in how the text should | |
177 be displayed (e.g., font, color) is made. */ | |
178 | |
448 | 179 /* Whether buffer specific face is specified. */ |
180 int buffer_local_face_property; | |
181 | |
428 | 182 /* change data indicating what portion of the text has changed |
183 since the last time this was reset. Used by redisplay. | |
184 Logically we should keep this with the text structure, but | |
185 redisplay resets it for each buffer individually and we don't | |
186 want interference between an indirect buffer and its base | |
187 buffer. */ | |
188 struct each_buffer_change_data *changes; | |
189 | |
190 #ifdef REGION_CACHE_NEEDS_WORK | |
191 /* If the long line scan cache is enabled (i.e. the buffer-local | |
192 variable cache-long-line-scans is non-nil), newline_cache | |
193 points to the newline cache, and width_run_cache points to the | |
194 width run cache. | |
195 | |
196 The newline cache records which stretches of the buffer are | |
197 known *not* to contain newlines, so that they can be skipped | |
198 quickly when we search for newlines. | |
199 | |
200 The width run cache records which stretches of the buffer are | |
201 known to contain characters whose widths are all the same. If | |
202 the width run cache maps a character to a value > 0, that value | |
203 is the character's width; if it maps a character to zero, we | |
204 don't know what its width is. This allows compute_motion to | |
205 process such regions very quickly, using algebra instead of | |
206 inspecting each character. See also width_table, below. */ | |
207 struct region_cache *newline_cache; | |
208 struct region_cache *width_run_cache; | |
209 #endif /* REGION_CACHE_NEEDS_WORK */ | |
210 | |
211 /* The markers that refer to this buffer. This is actually a single | |
212 marker -- successive elements in its marker `chain' are the other | |
213 markers referring to this buffer */ | |
440 | 214 Lisp_Marker *markers; |
428 | 215 |
216 /* The buffer's extent info. This is its own type, an extent-info | |
217 object (done this way for ease in marking / finalizing). */ | |
218 Lisp_Object extent_info; | |
219 | |
826 | 220 /* The buffer's syntax cache. This caches a known region where the |
221 `syntax-table' property is unchanged, for quick lookup in the routines | |
222 that scan a buffer looking for a particular syntax (regex routines, | |
223 parse-partial-sexp, etc.). */ | |
224 struct syntax_cache *syntax_cache; | |
225 | |
428 | 226 /* ----------------------------------------------------------------- */ |
227 /* All the stuff above this line is the responsibility of insdel.c, | |
826 | 228 with some help from marker.c, extents.c and syntax.c. |
428 | 229 All the stuff below this line is the responsibility of buffer.c. */ |
230 | |
231 /* In an indirect buffer, this points to the base buffer. | |
232 In an ordinary buffer, it is 0. | |
233 We DO mark through this slot. */ | |
234 struct buffer *base_buffer; | |
235 | |
236 /* List of indirect buffers whose base is this buffer. | |
237 If we are an indirect buffer, this will be nil. | |
238 Do NOT mark through this. */ | |
239 Lisp_Object indirect_children; | |
240 | |
241 /* Flags saying which DEFVAR_PER_BUFFER variables | |
242 are local to this buffer. */ | |
243 int local_var_flags; | |
244 | |
245 /* Set to the modtime of the visited file when read or written. | |
246 -1 means visited file was nonexistent. | |
247 0 means visited file modtime unknown; in no case complain | |
248 about any mismatch on next save attempt. */ | |
249 int modtime; | |
250 | |
251 /* the value of text->modiff at the last auto-save. */ | |
442 | 252 long auto_save_modified; |
428 | 253 |
254 /* The time at which we detected a failure to auto-save, | |
255 Or -1 if we didn't have a failure. */ | |
256 int auto_save_failure_time; | |
257 | |
258 /* Position in buffer at which display started | |
259 the last time this buffer was displayed. */ | |
260 int last_window_start; | |
261 | |
262 /* Everything from here down must be a Lisp_Object */ | |
263 | |
1204 | 264 #define MARKED_SLOT(x) Lisp_Object x; |
428 | 265 #include "bufslots.h" |
266 #undef MARKED_SLOT | |
267 }; | |
268 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3092
diff
changeset
|
269 DECLARE_LISP_OBJECT (buffer, struct buffer); |
428 | 270 #define XBUFFER(x) XRECORD (x, buffer, struct buffer) |
617 | 271 #define wrap_buffer(p) wrap_record (p, buffer) |
428 | 272 #define BUFFERP(x) RECORDP (x, buffer) |
273 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer) | |
274 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer) | |
275 | |
276 #define BUFFER_LIVE_P(b) (!NILP ((b)->name)) | |
277 | |
278 #define CHECK_LIVE_BUFFER(x) do { \ | |
279 CHECK_BUFFER (x); \ | |
280 if (!BUFFER_LIVE_P (XBUFFER (x))) \ | |
281 dead_wrong_type_argument (Qbuffer_live_p, (x)); \ | |
282 } while (0) | |
283 | |
284 #define CONCHECK_LIVE_BUFFER(x) do { \ | |
285 CONCHECK_BUFFER (x); \ | |
286 if (!BUFFER_LIVE_P (XBUFFER (x))) \ | |
287 x = wrong_type_argument (Qbuffer_live_p, (x)); \ | |
288 } while (0) | |
289 | |
290 | |
291 #define BUFFER_BASE_BUFFER(b) ((b)->base_buffer ? (b)->base_buffer : (b)) | |
292 | |
293 /* Map over buffers sharing the same text as MPS_BUF. MPS_BUFVAR is a | |
294 variable that gets the buffer values (beginning with the base | |
295 buffer, then the children), and MPS_BUFCONS should be a temporary | |
296 Lisp_Object variable. */ | |
647 | 297 #define MAP_INDIRECT_BUFFERS(mps_buf, mps_bufvar, mps_bufcons) \ |
298 for (mps_bufcons = Qunbound, \ | |
299 mps_bufvar = BUFFER_BASE_BUFFER (mps_buf); \ | |
300 UNBOUNDP (mps_bufcons) ? \ | |
301 (mps_bufcons = mps_bufvar->indirect_children, \ | |
302 1) \ | |
303 : (!NILP (mps_bufcons) \ | |
304 && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \ | |
305 && (mps_bufcons = XCDR (mps_bufcons), 1)); \ | |
428 | 306 ) |
307 | |
308 | |
826 | 309 /* All macros below follow the three golden rules of macros (see text.h), |
310 with the following exception: | |
311 | |
312 -- 'struct buffer *' arguments can be evaluated more than once. | |
313 */ | |
314 | |
428 | 315 /*----------------------------------------------------------------------*/ |
316 /* Accessor macros for important positions in a buffer */ | |
317 /*----------------------------------------------------------------------*/ | |
318 | |
319 /* We put them here because some stuff below wants them before the | |
320 place where we would normally put them. */ | |
321 | |
322 /* None of these are lvalues. Use the settor macros below to change | |
323 the positions. */ | |
324 | |
325 /* Beginning of buffer. */ | |
826 | 326 #define BYTE_BUF_BEG(buf) ((Bytebpos) 1) |
665 | 327 #define BUF_BEG(buf) ((Charbpos) 1) |
428 | 328 |
329 /* Beginning of accessible range of buffer. */ | |
826 | 330 #define BYTE_BUF_BEGV(buf) ((buf)->begv + 0) |
428 | 331 #define BUF_BEGV(buf) ((buf)->bufbegv + 0) |
332 | |
333 /* End of accessible range of buffer. */ | |
826 | 334 #define BYTE_BUF_ZV(buf) ((buf)->zv + 0) |
428 | 335 #define BUF_ZV(buf) ((buf)->bufzv + 0) |
336 | |
337 /* End of buffer. */ | |
826 | 338 #define BYTE_BUF_Z(buf) ((buf)->text->z + 0) |
428 | 339 #define BUF_Z(buf) ((buf)->text->bufz + 0) |
340 | |
2367 | 341 /* Gap location. */ |
342 #define BYTE_BUF_GPT(buf) ((buf)->text->gpt + 0) | |
343 #define BUF_GPT(buf) ((buf)->text->bufgpt + 0) | |
344 | |
428 | 345 /* Point. */ |
826 | 346 #define BYTE_BUF_PT(buf) ((buf)->pt + 0) |
428 | 347 #define BUF_PT(buf) ((buf)->bufpt + 0) |
348 | |
826 | 349 /* Internal format of buffer. */ |
350 #ifdef MULE | |
351 #define BUF_FORMAT(buf) ((buf)->text->format) | |
352 #else | |
353 #define BUF_FORMAT(buf) FORMAT_DEFAULT | |
354 #endif | |
355 | |
428 | 356 /*----------------------------------------------------------------------*/ |
826 | 357 /* Validating byte positions */ |
428 | 358 /*----------------------------------------------------------------------*/ |
359 | |
826 | 360 /* Address of byte at position POS in buffer, no error checking. */ |
361 DECLARE_INLINE_HEADER ( | |
867 | 362 Ibyte * |
826 | 363 BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (struct buffer *buf, Bytebpos pos) |
364 ) | |
428 | 365 { |
366 return (buf->text->beg + | |
367 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos) | |
368 - 1)); | |
369 } | |
370 | |
826 | 371 /* Given a byte position, does it point to the beginning of a character? |
372 */ | |
373 #ifdef MULE | |
374 DECLARE_INLINE_HEADER ( | |
375 int | |
376 VALID_BYTEBPOS_P (struct buffer *buf, Bytebpos x) | |
377 ) | |
428 | 378 { |
826 | 379 switch (BUF_FORMAT (buf)) |
380 { | |
381 case FORMAT_DEFAULT: | |
867 | 382 return ibyte_first_byte_p (*BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x)); |
826 | 383 case FORMAT_16_BIT_FIXED: |
384 return ((x - 1) & 1) == 0; | |
385 case FORMAT_32_BIT_FIXED: | |
386 return ((x - 1) & 3) == 0; | |
387 default: | |
388 return 1; | |
389 } | |
428 | 390 } |
391 #else | |
665 | 392 # define VALID_BYTEBPOS_P(buf, x) 1 |
428 | 393 #endif |
394 | |
826 | 395 /* If error-checking is enabled, assert that the given char position is |
396 within range. Otherwise, do nothing. | |
397 */ | |
398 # define ASSERT_VALID_CHARBPOS_UNSAFE(buf, x) do { \ | |
399 text_checking_assert (BUFFER_LIVE_P (buf)); \ | |
400 text_checking_assert ((x) >= BUF_BEG (buf) && x <= BUF_Z (buf)); \ | |
428 | 401 } while (0) |
826 | 402 |
403 /* If error-checking is enabled, assert that the given byte position is | |
404 within range and points to the beginning of a character or to the end of | |
405 the buffer. Otherwise, do nothing. | |
406 */ | |
407 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x) do { \ | |
408 text_checking_assert (BUFFER_LIVE_P (buf)); \ | |
409 text_checking_assert ((x) >= BYTE_BUF_BEG (buf) && x <= BYTE_BUF_Z (buf)); \ | |
410 text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ | |
428 | 411 } while (0) |
826 | 412 |
413 /* If error-checking is enabled, assert that the given byte position is | |
414 within range and satisfies ASSERT_VALID_BYTEBPOS() and also does not | |
415 refer to the beginning of the buffer. (i.e. movement backwards is OK.) | |
416 Otherwise, do nothing. | |
417 */ | |
418 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x) do { \ | |
419 text_checking_assert (BUFFER_LIVE_P (buf)); \ | |
420 text_checking_assert ((x) > BYTE_BUF_BEG (buf) && x <= BYTE_BUF_Z (buf)); \ | |
421 text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ | |
428 | 422 } while (0) |
423 | |
826 | 424 /* If error-checking is enabled, assert that the given byte position is |
425 within range and satisfies ASSERT_VALID_BYTEBPOS() and also does not | |
426 refer to the end of the buffer. (i.e. movement forwards is OK.) | |
427 Otherwise, do nothing. | |
428 */ | |
429 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x) do { \ | |
430 text_checking_assert (BUFFER_LIVE_P (buf)); \ | |
431 text_checking_assert ((x) >= BYTE_BUF_BEG (buf) && x < BYTE_BUF_Z (buf)); \ | |
432 text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ | |
433 } while (0) | |
428 | 434 |
435 #ifdef MULE | |
826 | 436 /* Make sure that the given byte position is pointing to the beginning of a |
437 character. If not, back up until this is the case. Note that there are | |
438 not too many places where it is legitimate to do this sort of thing. | |
439 It's an error if you're passed an "invalid" byte position. | |
440 */ | |
441 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \ | |
442 switch (BUF_FORMAT (buf)) \ | |
443 { \ | |
444 case FORMAT_DEFAULT: \ | |
445 { \ | |
867 | 446 Ibyte *VBB_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \ |
447 while (!ibyte_first_byte_p (*VBB_ptr)) \ | |
826 | 448 VBB_ptr--, (x)--; \ |
449 } \ | |
450 break; \ | |
451 case FORMAT_16_BIT_FIXED: \ | |
452 if (((x - 1) & 1) != 0) \ | |
453 x--; \ | |
454 break; \ | |
455 case FORMAT_32_BIT_FIXED: \ | |
456 while (((x - 1) & 3) != 0) \ | |
457 x--; \ | |
458 break; \ | |
459 default: \ | |
460 break; \ | |
461 } \ | |
428 | 462 } while (0) |
463 #else | |
665 | 464 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) |
428 | 465 #endif |
466 | |
467 #ifdef MULE | |
826 | 468 /* Make sure that the given byte position is pointing to the beginning of a |
469 character. If not, move forward until this is the case. Note that | |
470 there are not too many places where it is legitimate to do this sort of | |
471 thing. It's an error if you're passed an "invalid" byte position. | |
472 */ | |
473 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \ | |
474 switch (BUF_FORMAT (buf)) \ | |
475 { \ | |
476 case FORMAT_DEFAULT: \ | |
477 { \ | |
867 | 478 Ibyte *VBF_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \ |
479 while (!ibyte_first_byte_p (*VBF_ptr)) \ | |
826 | 480 VBF_ptr++, (x)++; \ |
481 } \ | |
482 break; \ | |
483 case FORMAT_16_BIT_FIXED: \ | |
484 if (((x - 1) & 1) != 0) \ | |
485 x++; \ | |
486 break; \ | |
487 case FORMAT_32_BIT_FIXED: \ | |
488 while (((x - 1) & 3) != 0) \ | |
489 x++; \ | |
490 break; \ | |
491 default: \ | |
492 break; \ | |
493 } \ | |
428 | 494 } while (0) |
495 #else | |
665 | 496 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) |
428 | 497 #endif |
498 | |
826 | 499 /*----------------------------------------------------------------------*/ |
500 /* Working with byte positions */ | |
501 /*----------------------------------------------------------------------*/ | |
502 | |
503 | |
504 /* Given a byte position (assumed to point at the beginning of a | |
505 character), modify that value so it points to the beginning of the next | |
506 character. | |
507 | |
508 Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), | |
509 this crap reduces down to simply (x)++. */ | |
428 | 510 |
665 | 511 #define INC_BYTEBPOS(buf, x) do \ |
428 | 512 { \ |
826 | 513 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE (buf, x); \ |
428 | 514 /* Note that we do the increment first to \ |
515 make sure that the pointer in \ | |
665 | 516 VALIDATE_BYTEBPOS_FORWARD() ends up on \ |
428 | 517 the correct side of the gap */ \ |
518 (x)++; \ | |
665 | 519 VALIDATE_BYTEBPOS_FORWARD (buf, x); \ |
428 | 520 } while (0) |
521 | |
826 | 522 /* Given a byte position (assumed to point at the beginning of a |
523 character), modify that value so it points to the beginning of the | |
867 | 524 previous character. Unlike for DEC_IBYTEPTR(), we can do all the |
826 | 525 assert()s because there are sentinels at the beginning of the gap and |
526 the end of the buffer. | |
527 | |
528 Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), this | |
529 crap reduces down to simply (x)--. */ | |
428 | 530 |
665 | 531 #define DEC_BYTEBPOS(buf, x) do \ |
428 | 532 { \ |
771 | 533 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE (buf, x); \ |
428 | 534 /* Note that we do the decrement first to \ |
535 make sure that the pointer in \ | |
665 | 536 VALIDATE_BYTEBPOS_BACKWARD() ends up on \ |
428 | 537 the correct side of the gap */ \ |
538 (x)--; \ | |
665 | 539 VALIDATE_BYTEBPOS_BACKWARD (buf, x); \ |
428 | 540 } while (0) |
541 | |
826 | 542 DECLARE_INLINE_HEADER ( |
543 Bytebpos | |
4860 | 544 prev_bytebpos (struct buffer *buf, Bytebpos x) |
826 | 545 ) |
428 | 546 { |
665 | 547 DEC_BYTEBPOS (buf, x); |
428 | 548 return x; |
549 } | |
550 | |
826 | 551 DECLARE_INLINE_HEADER ( |
552 Bytebpos | |
4860 | 553 next_bytebpos (struct buffer *buf, Bytebpos x) |
826 | 554 ) |
428 | 555 { |
665 | 556 INC_BYTEBPOS (buf, x); |
428 | 557 return x; |
558 } | |
559 | |
826 | 560 /* A constant representing an invalid Bytebpos. Valid Bytebposes |
561 can never have this value. */ | |
562 | |
665 | 563 #define BYTEBPOS_INVALID ((Bytebpos) -1) |
428 | 564 |
565 /*----------------------------------------------------------------------*/ | |
826 | 566 /* Converting between byte and character positions */ |
428 | 567 /*----------------------------------------------------------------------*/ |
568 | |
2367 | 569 /* |
771 | 570 |
2367 | 571 Info on Byte-Char conversion: |
428 | 572 |
2367 | 573 (Info-goto-node "(internals)Byte-Char Position Conversion") |
574 */ | |
428 | 575 |
2367 | 576 #ifdef MULE |
428 | 577 |
826 | 578 Bytebpos charbpos_to_bytebpos_func (struct buffer *buf, Charbpos x); |
579 Charbpos bytebpos_to_charbpos_func (struct buffer *buf, Bytebpos x); | |
428 | 580 extern short three_to_one_table[]; |
581 | |
826 | 582 #endif /* MULE */ |
583 | |
584 /* Given a Charbpos, return the equivalent Bytebpos. */ | |
585 | |
586 DECLARE_INLINE_HEADER ( | |
587 Bytebpos | |
4860 | 588 charbpos_to_bytebpos (struct buffer *buf, Charbpos x) |
826 | 589 ) |
428 | 590 { |
826 | 591 Bytebpos retval; |
592 ASSERT_VALID_CHARBPOS_UNSAFE (buf, x); | |
593 #ifdef MULE | |
594 if (buf->text->entirely_one_byte_p) | |
595 retval = (Bytebpos) x; | |
596 else if (BUF_FORMAT (buf) == FORMAT_16_BIT_FIXED) | |
597 retval = (Bytebpos) (x << 1); | |
598 else if (BUF_FORMAT (buf) == FORMAT_32_BIT_FIXED) | |
599 retval = (Bytebpos) (x << 2); | |
2367 | 600 #ifdef OLD_BYTE_CHAR |
826 | 601 else if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax) |
602 retval = (buf->text->mule_bytmin + | |
428 | 603 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) + |
814 | 604 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : |
605 (Bytebpos) 0)); | |
2367 | 606 #endif /* OLD_BYTE_CHAR */ |
428 | 607 else |
826 | 608 retval = charbpos_to_bytebpos_func (buf, x); |
609 #else | |
610 retval = (Bytebpos) x; | |
611 #endif | |
612 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); | |
613 return retval; | |
614 } | |
615 | |
616 /* Given a Bytebpos, return the equivalent Charbpos. */ | |
617 | |
618 DECLARE_INLINE_HEADER ( | |
619 Charbpos | |
4860 | 620 bytebpos_to_charbpos (struct buffer *buf, Bytebpos x) |
826 | 621 ) |
622 { | |
623 Charbpos retval; | |
624 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, x); | |
625 #ifdef MULE | |
626 if (buf->text->entirely_one_byte_p) | |
627 retval = (Charbpos) x; | |
628 else if (BUF_FORMAT (buf) == FORMAT_16_BIT_FIXED) | |
629 retval = (Charbpos) (x >> 1); | |
630 else if (BUF_FORMAT (buf) == FORMAT_32_BIT_FIXED) | |
631 retval = (Charbpos) (x >> 2); | |
2367 | 632 #ifdef OLD_BYTE_CHAR |
826 | 633 else if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax) |
634 retval = (buf->text->mule_bufmin + | |
635 ((buf->text->mule_three_p | |
636 ? three_to_one_table[x - buf->text->mule_bytmin] | |
637 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter))); | |
2367 | 638 #endif /* OLD_BYTE_CHAR */ |
826 | 639 else |
640 retval = bytebpos_to_charbpos_func (buf, x); | |
641 #else | |
642 retval = (Charbpos) x; | |
643 #endif | |
644 ASSERT_VALID_CHARBPOS_UNSAFE (buf, retval); | |
645 return retval; | |
646 } | |
647 | |
648 /* Given a Bytebpos, return the equivalent Charbpos as a Lisp Object. */ | |
649 | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
650 #define make_charbpos(buf, ind) make_fixnum (bytebpos_to_charbpos (buf, ind)) |
826 | 651 |
652 /*----------------------------------------------------------------------*/ | |
653 /* Converting between byte and memory positions */ | |
654 /*----------------------------------------------------------------------*/ | |
655 | |
656 DECLARE_INLINE_HEADER ( | |
657 int | |
658 valid_membpos_p (struct buffer *buf, Membpos x) | |
659 ) | |
660 { | |
661 return ((x >= 1 && x <= (Membpos) buf->text->gpt) || | |
662 (x > (Membpos) (buf->text->gpt + buf->text->gap_size) && | |
663 x <= (Membpos) (buf->text->z + buf->text->gap_size))); | |
428 | 664 } |
665 | |
826 | 666 DECLARE_INLINE_HEADER ( |
667 Membpos | |
668 bytebpos_to_membpos (struct buffer *buf, Bytebpos x) | |
669 ) | |
670 { | |
671 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, x); | |
672 return (Membpos) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x); | |
673 } | |
674 | |
675 | |
676 DECLARE_INLINE_HEADER ( | |
677 Bytebpos | |
678 membpos_to_bytebpos (struct buffer *buf, Membpos x) | |
679 ) | |
680 { | |
681 Bytebpos retval; | |
682 text_checking_assert (valid_membpos_p (buf, x)); | |
683 retval = (Bytebpos) ((x > (Membpos) buf->text->gpt) ? | |
684 x - buf->text->gap_size : | |
685 x); | |
686 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); | |
687 return retval; | |
688 } | |
689 | |
690 DECLARE_INLINE_HEADER ( | |
691 Charbpos | |
692 membpos_to_charbpos (struct buffer *buf, Membpos x) | |
693 ) | |
428 | 694 { |
826 | 695 return bytebpos_to_charbpos (buf, membpos_to_bytebpos (buf, x)); |
696 } | |
697 | |
698 DECLARE_INLINE_HEADER ( | |
699 Membpos | |
700 charbpos_to_membpos (struct buffer *buf, Charbpos x) | |
701 ) | |
702 { | |
703 return bytebpos_to_membpos (buf, charbpos_to_bytebpos (buf, x)); | |
704 } | |
705 | |
706 /*----------------------------------------------------------------------*/ | |
707 /* Generalized buffer/string position convertors */ | |
708 /*----------------------------------------------------------------------*/ | |
709 | |
710 /* These macros generalize many standard buffer-position functions to | |
711 either a buffer or a string. */ | |
712 | |
713 /* Converting between Memxpos's and Bytexpos's, for a buffer-or-string. | |
714 For strings, this is a no-op. For buffers, this resolves | |
715 to the standard membpos<->bytebpos converters. */ | |
716 | |
717 DECLARE_INLINE_HEADER ( | |
718 Memxpos buffer_or_string_bytexpos_to_memxpos (Lisp_Object obj, Bytexpos pos) | |
719 ) | |
720 { | |
721 return (BUFFERP (obj) ? bytebpos_to_membpos (XBUFFER (obj), pos) : | |
722 (Memxpos) pos); | |
428 | 723 } |
724 | |
826 | 725 DECLARE_INLINE_HEADER ( |
726 Bytexpos buffer_or_string_memxpos_to_bytexpos (Lisp_Object obj, Memxpos pos) | |
727 ) | |
728 { | |
729 return (BUFFERP (obj) ? membpos_to_bytebpos (XBUFFER (obj), pos) : | |
730 (Bytexpos) pos); | |
731 } | |
732 | |
733 /* Converting between Charxpos's and Bytexpos's, for a buffer-or-string. | |
734 For strings, this maps to the bytecount<->charcount converters. */ | |
735 | |
736 DECLARE_INLINE_HEADER ( | |
737 Bytexpos buffer_or_string_charxpos_to_bytexpos (Lisp_Object obj, Charxpos pos) | |
738 ) | |
739 { | |
740 return (BUFFERP (obj) ? charbpos_to_bytebpos (XBUFFER (obj), pos) : | |
741 (Bytexpos) string_index_char_to_byte (obj, pos)); | |
742 } | |
743 | |
744 DECLARE_INLINE_HEADER ( | |
745 Charxpos buffer_or_string_bytexpos_to_charxpos (Lisp_Object obj, Bytexpos pos) | |
746 ) | |
747 { | |
748 return (BUFFERP (obj) ? bytebpos_to_charbpos (XBUFFER (obj), pos) : | |
749 (Charxpos) string_index_byte_to_char (obj, pos)); | |
750 } | |
428 | 751 |
826 | 752 /* Similar for Charxpos's and Memxpos's. */ |
753 | |
754 DECLARE_INLINE_HEADER ( | |
755 Memxpos buffer_or_string_charxpos_to_memxpos (Lisp_Object obj, Charxpos pos) | |
756 ) | |
757 { | |
758 return (BUFFERP (obj) ? charbpos_to_membpos (XBUFFER (obj), pos) : | |
759 (Memxpos) string_index_char_to_byte (obj, pos)); | |
760 } | |
428 | 761 |
826 | 762 DECLARE_INLINE_HEADER ( |
763 Charxpos buffer_or_string_memxpos_to_charxpos (Lisp_Object obj, Memxpos pos) | |
764 ) | |
765 { | |
766 return (BUFFERP (obj) ? membpos_to_charbpos (XBUFFER (obj), pos) : | |
767 (Charxpos) string_index_byte_to_char (obj, pos)); | |
768 } | |
428 | 769 |
826 | 770 DECLARE_INLINE_HEADER ( |
771 Internal_Format buffer_or_other_internal_format (Lisp_Object obj) | |
772 ) | |
773 { | |
774 return BUFFERP (obj) ? BUF_FORMAT (XBUFFER (obj)) : FORMAT_DEFAULT; | |
775 } | |
776 | |
777 /* Return the index to the character before the one at X, | |
778 in a buffer or string. */ | |
428 | 779 |
826 | 780 DECLARE_INLINE_HEADER ( |
781 Bytebpos | |
782 prev_bytexpos (Lisp_Object obj, Bytebpos x) | |
783 ) | |
784 { | |
785 return BUFFERP (obj) ? prev_bytebpos (XBUFFER (obj), x) : | |
786 prev_string_index (obj, x); | |
787 } | |
788 | |
789 /* Return the index to the character after the one at X, | |
790 in a buffer or string. */ | |
428 | 791 |
826 | 792 DECLARE_INLINE_HEADER ( |
793 Bytebpos | |
794 next_bytexpos (Lisp_Object obj, Bytebpos x) | |
795 ) | |
796 { | |
797 return BUFFERP (obj) ? next_bytebpos (XBUFFER (obj), x) : | |
798 next_string_index (obj, x); | |
799 } | |
800 | |
801 /*----------------------------------------------------------------------*/ | |
802 /* Converting between positions and addresses */ | |
803 /*----------------------------------------------------------------------*/ | |
428 | 804 |
826 | 805 /* Convert the address of a byte in the buffer into a position. */ |
806 DECLARE_INLINE_HEADER ( | |
807 Bytebpos | |
867 | 808 BYTE_BUF_PTR_BYTE_POS (struct buffer *buf, Ibyte *ptr) |
826 | 809 ) |
810 { | |
811 Bytebpos retval = (ptr - buf->text->beg + 1 | |
812 - ((ptr - buf->text->beg + 1) > buf->text->gpt | |
813 ? buf->text->gap_size : (Bytebpos) 0)); | |
814 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); | |
815 return retval; | |
816 } | |
817 | |
818 #define BUF_PTR_BYTE_POS(buf, ptr) \ | |
819 bytebpos_to_charbpos (buf, BYTE_BUF_PTR_BYTE_POS (buf, ptr)) | |
428 | 820 |
826 | 821 /* Address of byte at position POS in buffer. */ |
822 DECLARE_INLINE_HEADER ( | |
867 | 823 Ibyte * |
826 | 824 BYTE_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos) |
825 ) | |
826 { | |
827 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos); | |
828 return BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos); | |
829 } | |
830 | |
831 #define BUF_BYTE_ADDRESS(buf, pos) \ | |
832 BYTE_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos)) | |
428 | 833 |
826 | 834 /* Address of byte before position POS in buffer. */ |
835 DECLARE_INLINE_HEADER ( | |
867 | 836 Ibyte * |
826 | 837 BYTE_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos) |
838 ) | |
839 { | |
840 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos); | |
841 return (buf->text->beg + | |
842 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos) | |
843 - 2)); | |
844 } | |
845 | |
846 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \ | |
847 BYTE_BUF_BYTE_ADDRESS_BEFORE (buf, charbpos_to_bytebpos (buf, pos)) | |
428 | 848 |
849 /*----------------------------------------------------------------------*/ | |
850 /* Converting between buffer bytes and Emacs characters */ | |
851 /*----------------------------------------------------------------------*/ | |
852 | |
853 /* The character at position POS in buffer. */ | |
826 | 854 |
855 #define BYTE_BUF_FETCH_CHAR(buf, pos) \ | |
867 | 856 itext_ichar_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf), \ |
826 | 857 wrap_buffer (buf)) |
428 | 858 #define BUF_FETCH_CHAR(buf, pos) \ |
826 | 859 BYTE_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos)) |
860 | |
861 /* The "raw value" of the character at position POS in buffer. | |
867 | 862 See ichar_to_raw(). */ |
826 | 863 |
864 #define BYTE_BUF_FETCH_CHAR_RAW(buf, pos) \ | |
867 | 865 itext_ichar_raw_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf)) |
826 | 866 #define BUF_FETCH_CHAR_RAW(buf, pos) \ |
867 BYTE_BUF_FETCH_CHAR_RAW (buf, charbpos_to_bytebpos (buf, pos)) | |
428 | 868 |
869 /* The character at position POS in buffer, as a string. This is | |
867 | 870 equivalent to set_itext_ichar (str, BUF_FETCH_CHAR (buf, pos)) |
428 | 871 but is faster for Mule. */ |
872 | |
867 | 873 # define BYTE_BUF_ITEXT_COPY_ICHAR(buf, pos, str) \ |
826 | 874 (BUF_FORMAT (buf) == FORMAT_DEFAULT ? \ |
867 | 875 itext_copy_ichar (BYTE_BUF_BYTE_ADDRESS (buf, pos), str) : \ |
876 set_itext_ichar (str, BYTE_BUF_FETCH_CHAR (buf, pos))) | |
877 #define BUF_ITEXT_COPY_ICHAR(buf, pos, str) \ | |
878 BYTE_BUF_ITEXT_COPY_ICHAR (buf, charbpos_to_bytebpos (buf, pos), str) | |
428 | 879 |
880 | |
881 /************************************************************************/ | |
440 | 882 /* */ |
428 | 883 /* higher-level buffer-position functions */ |
884 /* */ | |
885 /************************************************************************/ | |
886 | |
887 /*----------------------------------------------------------------------*/ | |
888 /* Settor macros for important positions in a buffer */ | |
889 /*----------------------------------------------------------------------*/ | |
890 | |
891 /* Set beginning of accessible range of buffer. */ | |
826 | 892 #define SET_BOTH_BUF_BEGV(buf, val, bpval) \ |
428 | 893 do \ |
894 { \ | |
826 | 895 (buf)->begv = (bpval); \ |
428 | 896 (buf)->bufbegv = (val); \ |
897 } while (0) | |
898 | |
899 /* Set end of accessible range of buffer. */ | |
826 | 900 #define SET_BOTH_BUF_ZV(buf, val, bpval) \ |
428 | 901 do \ |
902 { \ | |
826 | 903 (buf)->zv = (bpval); \ |
428 | 904 (buf)->bufzv = (val); \ |
905 } while (0) | |
906 | |
907 /* Set point. */ | |
908 /* Since BEGV and ZV are almost never set, it's reasonable to enforce | |
665 | 909 the restriction that the Charbpos and Bytebpos values must both be |
428 | 910 specified. However, point is set in lots and lots of places. So |
911 we provide the ability to specify both (for efficiency) or just | |
912 one. */ | |
826 | 913 #define BOTH_BUF_SET_PT(buf, val, bpval) set_buffer_point (buf, val, bpval) |
914 #define BYTE_BUF_SET_PT(buf, bpval) \ | |
915 do \ | |
916 { \ | |
917 Bytebpos __bpbsp_bpval = (bpval); \ | |
918 BOTH_BUF_SET_PT (buf, bytebpos_to_charbpos (buf, __bpbsp_bpval), \ | |
919 __bpbsp_bpval); \ | |
920 } while (0) | |
921 #define BUF_SET_PT(buf, value) \ | |
922 do \ | |
923 { \ | |
924 Bytebpos __bsp_val = (value); \ | |
925 BOTH_BUF_SET_PT (buf, __bsp_val, charbpos_to_bytebpos (buf, __bsp_val)); \ | |
926 } while (0) | |
428 | 927 |
928 | |
929 #if 0 /* FSFmacs */ | |
930 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly | |
931 does too much stuff, such as moving out of invisible extents. */ | |
932 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer)) | |
933 #define SET_BUF_PT(buf, value) ((buf)->pt = (value)) | |
934 #endif /* FSFmacs */ | |
935 | |
936 /*----------------------------------------------------------------------*/ | |
937 /* Miscellaneous buffer values */ | |
938 /*----------------------------------------------------------------------*/ | |
939 | |
940 /* Number of characters in buffer */ | |
941 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf)) | |
942 | |
943 /* Is this buffer narrowed? */ | |
944 #define BUF_NARROWED(buf) \ | |
826 | 945 ((BYTE_BUF_BEGV (buf) != BYTE_BUF_BEG (buf)) || \ |
946 (BYTE_BUF_ZV (buf) != BYTE_BUF_Z (buf))) | |
428 | 947 |
826 | 948 /* Modification count */ |
428 | 949 #define BUF_MODIFF(buf) ((buf)->text->modiff) |
950 | |
826 | 951 /* Saved modification count */ |
428 | 952 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff) |
953 | |
954 /* Face changed. */ | |
955 #define BUF_FACECHANGE(buf) ((buf)->face_change) | |
956 | |
826 | 957 DECLARE_INLINE_HEADER ( |
958 int | |
959 POINT_MARKER_P (Lisp_Object marker) | |
960 ) | |
961 { | |
962 return (XMARKER (marker)->buffer != 0 && | |
963 EQ (marker, XMARKER (marker)->buffer->point_marker)); | |
964 } | |
428 | 965 |
966 #define BUF_MARKERS(buf) ((buf)->markers) | |
967 | |
826 | 968 #ifdef MULE |
969 | |
970 DECLARE_INLINE_HEADER ( | |
971 Lisp_Object | |
972 BUFFER_CATEGORY_TABLE (struct buffer *buf) | |
973 ) | |
974 { | |
975 return buf ? buf->category_table : Vstandard_category_table; | |
976 } | |
977 | |
978 #endif /* MULE */ | |
979 | |
980 DECLARE_INLINE_HEADER ( | |
981 Lisp_Object | |
982 BUFFER_SYNTAX_TABLE (struct buffer *buf) | |
983 ) | |
984 { | |
985 return buf ? buf->syntax_table : Vstandard_syntax_table; | |
986 } | |
987 | |
988 DECLARE_INLINE_HEADER ( | |
989 Lisp_Object | |
990 BUFFER_MIRROR_SYNTAX_TABLE (struct buffer *buf) | |
991 ) | |
992 { | |
993 return buf ? buf->mirror_syntax_table : | |
994 XCHAR_TABLE (Vstandard_syntax_table)->mirror_table; | |
995 } | |
996 | |
428 | 997 /* WARNING: |
998 | |
999 The new definitions of CEILING_OF() and FLOOR_OF() differ semantically | |
1000 from the old ones (in FSF Emacs and XEmacs 19.11 and before). | |
1001 Conversion is as follows: | |
1002 | |
826 | 1003 OLD_BYTE_CEILING_OF(n) = NEW_BYTE_CEILING_OF(n) - 1 |
1004 OLD_BYTE_FLOOR_OF(n) = NEW_BYTE_FLOOR_OF(n + 1) | |
428 | 1005 |
1006 The definitions were changed because the new definitions are more | |
771 | 1007 consistent with the way everything else works in XEmacs. |
428 | 1008 */ |
1009 | |
826 | 1010 /* Properties of CEILING_OF and FLOOR_OF (also apply to BYTE_ variants): |
428 | 1011 |
1012 1) FLOOR_OF (CEILING_OF (n)) = n | |
1013 CEILING_OF (FLOOR_OF (n)) = n | |
1014 | |
1015 2) CEILING_OF (n) = n if and only if n = ZV | |
1016 FLOOR_OF (n) = n if and only if n = BEGV | |
1017 | |
1018 3) CEILING_OF (CEILING_OF (n)) = ZV | |
1019 FLOOR_OF (FLOOR_OF (n)) = BEGV | |
1020 | |
1021 4) The bytes in the regions | |
1022 | |
1023 [BYTE_ADDRESS (n), BYTE_ADDRESS_BEFORE (CEILING_OF (n))] | |
1024 | |
1025 and | |
1026 | |
1027 [BYTE_ADDRESS (FLOOR_OF (n)), BYTE_ADDRESS_BEFORE (n)] | |
1028 | |
1029 are contiguous. | |
771 | 1030 |
1031 A typical loop using CEILING_OF to process contiguous ranges of text | |
1032 between [from, to) looks like this: | |
1033 | |
1034 { | |
1035 Bytebpos pos = from; | |
1036 | |
1037 while (pos < to) | |
1038 { | |
826 | 1039 Bytebpos ceil = BYTE_BUF_CEILING_OF (buf, pos); |
771 | 1040 ceil = min (to, ceil); |
867 | 1041 process_ibyte_string (BYTE_BUF_BYTE_ADDRESS (buf, pos), ceil - pos); |
771 | 1042 pos = ceil; |
1043 } | |
1044 } | |
1045 | |
1046 Currently there will be at most two iterations in the loop, but it is | |
1047 written in such a way that it will still work if the buffer | |
1048 representation is changed to have multiple gaps in it. | |
1049 */ | |
428 | 1050 |
826 | 1051 /* Return the maximum position in the buffer it is safe to scan forwards |
428 | 1052 past N to. This is used to prevent buffer scans from running into |
1053 the gap (e.g. search.c). All characters between N and CEILING_OF(N) | |
1054 are located contiguous in memory. Note that the character *at* | |
1055 CEILING_OF(N) is not contiguous in memory. */ | |
826 | 1056 #define BYTE_BUF_CEILING_OF(b, n) \ |
2367 | 1057 ((n) < BYTE_BUF_GPT (b) && BYTE_BUF_GPT (b) < BYTE_BUF_ZV (b) ? \ |
1058 BYTE_BUF_GPT (b) : BYTE_BUF_ZV (b)) | |
1059 #define BUF_CEILING_OF(b, n) \ | |
1060 ((n) < BUF_GPT (b) && BUF_GPT (b) < BUF_ZV (b) ? \ | |
1061 BUF_GPT (b) : BUF_ZV (b)) | |
428 | 1062 |
826 | 1063 /* Return the minimum position in the buffer it is safe to scan backwards |
428 | 1064 past N to. All characters between FLOOR_OF(N) and N are located |
1065 contiguous in memory. Note that the character *at* N may not be | |
1066 contiguous in memory. */ | |
2367 | 1067 #define BYTE_BUF_FLOOR_OF(b, n) \ |
1068 (BYTE_BUF_BEGV (b) < BYTE_BUF_GPT (b) && BYTE_BUF_GPT (b) < (n) ? \ | |
1069 BYTE_BUF_GPT (b) : BYTE_BUF_BEGV (b)) | |
1070 #define BUF_FLOOR_OF(b, n) \ | |
1071 (BUF_BEGV (b) < BUF_GPT (b) && BUF_GPT (b) < (n) ? \ | |
1072 BUF_GPT (b) : BUF_BEGV (b)) | |
428 | 1073 |
826 | 1074 #define BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ |
2367 | 1075 ((n) < BYTE_BUF_GPT (b) && BYTE_BUF_GPT (b) < BYTE_BUF_Z (b) ? \ |
1076 BYTE_BUF_GPT (b) : BYTE_BUF_Z (b)) | |
1077 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ | |
1078 ((n) < BUF_GPT (b) && BUF_GPT (b) < BUF_Z (b) ? \ | |
1079 BUF_GPT (b) : BUF_Z (b)) | |
428 | 1080 |
2367 | 1081 #define BYTE_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ |
1082 (BYTE_BUF_BEG (b) < BYTE_BUF_GPT (b) && BYTE_BUF_GPT (b) < (n) ? \ | |
1083 BYTE_BUF_GPT (b) : BYTE_BUF_BEG (b)) | |
1084 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ | |
1085 (BUF_BEG (b) < BUF_GPT (b) && BUF_GPT (b) < (n) ? \ | |
1086 BUF_GPT (b) : BUF_BEG (b)) | |
826 | 1087 |
1088 /* Iterate over contiguous chunks of text in buffer BUF, starting at POS, | |
1089 of length LEN. Evaluates POS and LEN only once, but BUF multiply. In | |
1090 each iteration, store the current chunk into RUNPTR/RUNLEN, which will | |
1091 be automatically declared (don't declare them yourself). This does not | |
1092 respect the limits of accessibility (BUF_BEGV/BUF_ZV); if you want these | |
1093 limits respected, you need to impose them yourself. | |
1094 | |
1095 NOTE: This must be surrounded with braces! */ | |
1096 | |
1097 #define BUFFER_TEXT_LOOP(buf, pos, len, runptr, runlen) \ | |
2367 | 1098 Ibyte *runptr; \ |
826 | 1099 Bytecount runlen; \ |
1100 Bytebpos BTL_pos = (pos); \ | |
1101 Bytebpos BTL_len = (len); \ | |
1102 for (runptr = BYTE_BUF_BYTE_ADDRESS (buf, BTL_pos), \ | |
1103 runlen = BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, BTL_pos) - BTL_pos, \ | |
1104 runlen = min (BTL_len, runlen); \ | |
1105 BTL_len > 0; \ | |
1106 BTL_pos += runlen, \ | |
1107 BTL_len -= runlen, \ | |
1108 runptr = BYTE_BUF_BYTE_ADDRESS (buf, BTL_pos), \ | |
1109 runlen = BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, BTL_pos) - BTL_pos, \ | |
1110 runlen = min (BTL_len, runlen)) | |
428 | 1111 |
1112 /* This structure marks which slots in a buffer have corresponding | |
1113 default values in Vbuffer_defaults. | |
1114 Each such slot has a nonzero value in this structure. | |
1115 The value has only one nonzero bit. | |
1116 | |
1117 When a buffer has its own local value for a slot, | |
1118 the bit for that slot (found in the same slot in this structure) | |
1119 is turned on in the buffer's local_var_flags slot. | |
1120 | |
1121 If a slot in this structure is zero, then even though there may | |
1122 be a DEFVAR_BUFFER_LOCAL for the slot, there is no default value for it; | |
1123 and the corresponding slot in Vbuffer_defaults is not used. */ | |
1124 | |
1125 extern struct buffer buffer_local_flags; | |
1126 | |
1127 | |
1128 /* Allocation of buffer data. */ | |
1129 | |
1130 #ifdef REL_ALLOC | |
1131 | |
440 | 1132 char *r_alloc (unsigned char **, size_t); |
1133 char *r_re_alloc (unsigned char **, size_t); | |
428 | 1134 void r_alloc_free (unsigned char **); |
1135 | |
1136 #define BUFFER_ALLOC(data, size) \ | |
867 | 1137 ((Ibyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Ibyte))) |
428 | 1138 #define BUFFER_REALLOC(data, size) \ |
867 | 1139 ((Ibyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Ibyte))) |
428 | 1140 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data)) |
1141 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data) | |
1142 | |
1143 #else /* !REL_ALLOC */ | |
1144 | |
1145 #define BUFFER_ALLOC(data,size)\ | |
867 | 1146 (data = xnew_array (Ibyte, size)) |
428 | 1147 #define BUFFER_REALLOC(data,size)\ |
867 | 1148 ((Ibyte *) xrealloc (data, (size) * sizeof(Ibyte))) |
428 | 1149 /* Avoid excess parentheses, or syntax errors may rear their heads. */ |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4906
diff
changeset
|
1150 #define BUFFER_FREE(data) xfree (data) |
428 | 1151 #define R_ALLOC_DECLARE(var,data) |
1152 | |
1153 #endif /* !REL_ALLOC */ | |
1154 | |
1155 | |
1156 /************************************************************************/ | |
1157 /* Case conversion */ | |
1158 /************************************************************************/ | |
1159 | |
1160 /* A "trt" table is a mapping from characters to other characters, | |
826 | 1161 typically used to convert between uppercase and lowercase. |
428 | 1162 */ |
1163 | |
1164 /* The _1 macros are named as such because they assume that you have | |
1165 already guaranteed that the character values are all in the range | |
1166 0 - 255. Bad lossage will happen otherwise. */ | |
1167 | |
446 | 1168 #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric) |
826 | 1169 DECLARE_INLINE_HEADER ( |
867 | 1170 Ichar |
1171 TRT_TABLE_OF (Lisp_Object table, Ichar ch) | |
826 | 1172 ) |
446 | 1173 { |
1174 Lisp_Object TRT_char; | |
826 | 1175 TRT_char = get_char_table (ch, table); |
446 | 1176 if (NILP (TRT_char)) |
1177 return ch; | |
1178 else | |
1179 return XCHAR (TRT_char); | |
1180 } | |
826 | 1181 #define SET_TRT_TABLE_OF(table, ch1, ch2) \ |
1182 Fput_char_table (make_char (ch1), make_char (ch2), table) | |
428 | 1183 |
826 | 1184 DECLARE_INLINE_HEADER ( |
1185 Lisp_Object | |
771 | 1186 BUFFER_CASE_TABLE (struct buffer *buf) |
826 | 1187 ) |
771 | 1188 { |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1189 return buf ? buf->case_table : current_buffer->case_table; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1190 /* When buf=0, was Vstandard_case_table, but this sucks. If I set a |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1191 different case table in this buffer, operations that use a case table |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1192 by default should use the current one. */ |
771 | 1193 } |
1194 | |
428 | 1195 /* Macros used below. */ |
446 | 1196 #define DOWNCASE_TABLE_OF(buf, c) \ |
771 | 1197 TRT_TABLE_OF (XCASE_TABLE_DOWNCASE (BUFFER_CASE_TABLE (buf)), c) |
446 | 1198 #define UPCASE_TABLE_OF(buf, c) \ |
771 | 1199 TRT_TABLE_OF (XCASE_TABLE_UPCASE (BUFFER_CASE_TABLE (buf)), c) |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1200 #define CANON_TABLE_OF(buf, c) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1201 TRT_TABLE_OF (XCASE_TABLE_CANON (BUFFER_CASE_TABLE (buf)), c) |
428 | 1202 |
1203 /* 1 if CH is upper case. */ | |
1204 | |
826 | 1205 DECLARE_INLINE_HEADER ( |
1206 int | |
867 | 1207 UPPERCASEP (struct buffer *buf, Ichar ch) |
826 | 1208 ) |
428 | 1209 { |
1210 return DOWNCASE_TABLE_OF (buf, ch) != ch; | |
1211 } | |
1212 | |
1213 /* 1 if CH is lower case. */ | |
1214 | |
826 | 1215 DECLARE_INLINE_HEADER ( |
1216 int | |
867 | 1217 LOWERCASEP (struct buffer *buf, Ichar ch) |
826 | 1218 ) |
428 | 1219 { |
1220 return (UPCASE_TABLE_OF (buf, ch) != ch && | |
1221 DOWNCASE_TABLE_OF (buf, ch) == ch); | |
1222 } | |
1223 | |
1224 /* 1 if CH is neither upper nor lower case. */ | |
1225 | |
826 | 1226 DECLARE_INLINE_HEADER ( |
1227 int | |
867 | 1228 NOCASEP (struct buffer *buf, Ichar ch) |
826 | 1229 ) |
428 | 1230 { |
1231 return UPCASE_TABLE_OF (buf, ch) == ch; | |
1232 } | |
1233 | |
1234 /* Upcase a character, or make no change if that cannot be done. */ | |
1235 | |
826 | 1236 DECLARE_INLINE_HEADER ( |
867 | 1237 Ichar |
1238 UPCASE (struct buffer *buf, Ichar ch) | |
826 | 1239 ) |
428 | 1240 { |
1241 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; | |
1242 } | |
1243 | |
1244 /* Upcase a character known to be not upper case. Unused. */ | |
1245 | |
1246 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch) | |
1247 | |
1248 /* Downcase a character, or make no change if that cannot be done. */ | |
1249 | |
1250 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch) | |
1251 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1252 /* Convert a character to a canonical representation, so that case-independent |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1253 comparisons will work. */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1254 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1255 #define CANONCASE(buf, ch) CANON_TABLE_OF (buf, ch) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
1256 |
440 | 1257 #endif /* INCLUDED_buffer_h_ */ |