Mercurial > hg > xemacs-beta
comparison src/line-number.c @ 373:6240c7796c7a r21-2b2
Import from CVS: tag r21-2b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:04:06 +0200 |
parents | 70ad99077275 |
children | 8626e4521993 |
comparison
equal
deleted
inserted
replaced
372:49e1ed2d7ed8 | 373:6240c7796c7a |
---|---|
72 /* How large a string has to be to give up searching it for newlines, | 72 /* How large a string has to be to give up searching it for newlines, |
73 before change. */ | 73 before change. */ |
74 #define LINE_NUMBER_LARGE_STRING 256 | 74 #define LINE_NUMBER_LARGE_STRING 256 |
75 | 75 |
76 /* To be used only when you *know* the cache has been allocated! */ | 76 /* To be used only when you *know* the cache has been allocated! */ |
77 #define LINE_NUMBER_RING(b) (XCAR ((b)->line_number_cache)) | 77 #define LINE_NUMBER_RING(b) (XCAR ((b)->text->line_number_cache)) |
78 #define LINE_NUMBER_BEGV(b) (XCDR ((b)->line_number_cache)) | 78 #define LINE_NUMBER_BEGV(b) (XCDR ((b)->text->line_number_cache)) |
79 | 79 |
80 | 80 |
81 /* Initialize the cache. Cache is (in pseudo-BNF): | 81 /* Initialize the cache. Cache is (in pseudo-BNF): |
82 | 82 |
83 CACHE = nil | INITIALIZED-CACHE | 83 CACHE = nil | INITIALIZED-CACHE |
87 RING-PAIR = cons (marker, integer) | 87 RING-PAIR = cons (marker, integer) |
88 BEGV-LINE = integer | 88 BEGV-LINE = integer |
89 | 89 |
90 Line number cache should never, ever, be visible to Lisp (because | 90 Line number cache should never, ever, be visible to Lisp (because |
91 destructively modifying its elements can cause crashes.) Debug it | 91 destructively modifying its elements can cause crashes.) Debug it |
92 using debug_print (current_buffer->last_number_cache). */ | 92 using debug_print (current_buffer->text->last_number_cache). */ |
93 static void | 93 static void |
94 allocate_line_number_cache (struct buffer *b) | 94 allocate_line_number_cache (struct buffer *b) |
95 { | 95 { |
96 b->line_number_cache = Fcons (make_vector (LINE_NUMBER_RING_SIZE, Qnil), | 96 b->text->line_number_cache = Fcons (make_vector (LINE_NUMBER_RING_SIZE, Qnil), |
97 Qzero); | 97 Qzero); |
98 narrow_line_number_cache (b); | 98 narrow_line_number_cache (b); |
99 } | 99 } |
100 | 100 |
101 /* Flag LINE_NUMBER_BEGV (b) as dirty. Do it only if the line number | 101 /* Flag LINE_NUMBER_BEGV (b) as dirty. Do it only if the line number |
102 cache is already initialized. */ | 102 cache is already initialized. */ |
103 void | 103 void |
104 narrow_line_number_cache (struct buffer *b) | 104 narrow_line_number_cache (struct buffer *b) |
105 { | 105 { |
106 if (NILP (b->line_number_cache)) | 106 if (NILP (b->text->line_number_cache)) |
107 return; | 107 return; |
108 | 108 |
109 if (BUF_BEG (b) == BUF_BEGV (b)) | 109 if (BUF_BEG (b) == BUF_BEGV (b)) |
110 /* The is the case Fwiden and save_restriction_restore. Since we | 110 /* The is the case Fwiden and save_restriction_restore. Since we |
111 know the correct value, we can update it now. */ | 111 know the correct value, we can update it now. */ |
159 This will do nothing if the cache is uninitialized. */ | 159 This will do nothing if the cache is uninitialized. */ |
160 void | 160 void |
161 insert_invalidate_line_number_cache (struct buffer *b, Bufpos pos, | 161 insert_invalidate_line_number_cache (struct buffer *b, Bufpos pos, |
162 CONST Bufbyte *nonreloc, Bytecount length) | 162 CONST Bufbyte *nonreloc, Bytecount length) |
163 { | 163 { |
164 if (NILP (b->line_number_cache)) | 164 if (NILP (b->text->line_number_cache)) |
165 return; | 165 return; |
166 | 166 |
167 if (length > LINE_NUMBER_LARGE_STRING | 167 if (length > LINE_NUMBER_LARGE_STRING |
168 || | 168 || |
169 /* We could also count how many newlines there are in the string | 169 /* We could also count how many newlines there are in the string |
180 | 180 |
181 This will do nothing if the cache is uninitialized. */ | 181 This will do nothing if the cache is uninitialized. */ |
182 void | 182 void |
183 delete_invalidate_line_number_cache (struct buffer *b, Bufpos from, Bufpos to) | 183 delete_invalidate_line_number_cache (struct buffer *b, Bufpos from, Bufpos to) |
184 { | 184 { |
185 if (NILP (b->line_number_cache)) | 185 if (NILP (b->text->line_number_cache)) |
186 return; | 186 return; |
187 | 187 |
188 if ((to - from) > LINE_NUMBER_LARGE_STRING) | 188 if ((to - from) > LINE_NUMBER_LARGE_STRING) |
189 invalidate_line_number_cache (b, from); | 189 invalidate_line_number_cache (b, from); |
190 else | 190 else |
278 if ((pos > beg ? pos - beg : beg - pos) <= LINE_NUMBER_FAR) | 278 if ((pos > beg ? pos - beg : beg - pos) <= LINE_NUMBER_FAR) |
279 cachep = 0; | 279 cachep = 0; |
280 | 280 |
281 if (cachep) | 281 if (cachep) |
282 { | 282 { |
283 if (NILP (b->line_number_cache)) | 283 if (NILP (b->text->line_number_cache)) |
284 allocate_line_number_cache (b); | 284 allocate_line_number_cache (b); |
285 /* If we don't know the line number of BUF_BEGV, calculate it now. */ | 285 /* If we don't know the line number of BUF_BEGV, calculate it now. */ |
286 if (XINT (LINE_NUMBER_BEGV (b)) == -1) | 286 if (XINT (LINE_NUMBER_BEGV (b)) == -1) |
287 { | 287 { |
288 LINE_NUMBER_BEGV (b) = Qzero; | 288 LINE_NUMBER_BEGV (b) = Qzero; |