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