diff options
| author | Richard M. Stallman | 1994-08-25 01:25:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-08-25 01:25:55 +0000 |
| commit | 59b49f63a6566b14cf8cef511dcde01800cca50b (patch) | |
| tree | bf5e3eac9cdee1cc7694c59f19e5307c495c42a1 /src | |
| parent | e2b721b7be61936d711bb441f9216b1679abafd9 (diff) | |
| download | emacs-59b49f63a6566b14cf8cef511dcde01800cca50b.tar.gz emacs-59b49f63a6566b14cf8cef511dcde01800cca50b.zip | |
(display_scan_buffer): New function.
(display_count_lines): Use that.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 103 |
1 files changed, 102 insertions, 1 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index 82e88fd9ab5..c67eeea232a 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -3123,6 +3123,107 @@ decode_mode_spec (w, c, maxwidth) | |||
| 3123 | else | 3123 | else |
| 3124 | return ""; | 3124 | return ""; |
| 3125 | } | 3125 | } |
| 3126 | |||
| 3127 | /* Search for COUNT instances of a line boundary, which means either a | ||
| 3128 | newline or (if selective display enabled) a carriage return. | ||
| 3129 | Start at START. If COUNT is negative, search backwards. | ||
| 3130 | |||
| 3131 | If we find COUNT instances, set *SHORTAGE to zero, and return the | ||
| 3132 | position after the COUNTth match. Note that for reverse motion | ||
| 3133 | this is not the same as the usual convention for Emacs motion commands. | ||
| 3134 | |||
| 3135 | If we don't find COUNT instances before reaching the end of the | ||
| 3136 | buffer (or the beginning, if scanning backwards), set *SHORTAGE to | ||
| 3137 | the number of line boundaries left unfound, and return the end of the | ||
| 3138 | buffer we bumped up against. */ | ||
| 3139 | |||
| 3140 | static int | ||
| 3141 | display_scan_buffer (start, count, shortage) | ||
| 3142 | int *shortage, start; | ||
| 3143 | register int count; | ||
| 3144 | { | ||
| 3145 | int limit = ((count > 0) ? ZV - 1 : BEGV); | ||
| 3146 | int direction = ((count > 0) ? 1 : -1); | ||
| 3147 | |||
| 3148 | register unsigned char *cursor; | ||
| 3149 | unsigned char *base; | ||
| 3150 | |||
| 3151 | register int ceiling; | ||
| 3152 | register unsigned char *ceiling_addr; | ||
| 3153 | |||
| 3154 | /* If we are not in selective display mode, | ||
| 3155 | check only for newlines. */ | ||
| 3156 | if (! (!NILP (current_buffer->selective_display) | ||
| 3157 | && !INTEGERP (current_buffer->selective_display))) | ||
| 3158 | return scan_buffer ('\n', start, count, shortage, 0); | ||
| 3159 | |||
| 3160 | /* The code that follows is like scan_buffer | ||
| 3161 | but checks for either newline or carriage return. */ | ||
| 3162 | |||
| 3163 | if (shortage != 0) | ||
| 3164 | *shortage = 0; | ||
| 3165 | |||
| 3166 | if (count > 0) | ||
| 3167 | while (start != limit + 1) | ||
| 3168 | { | ||
| 3169 | ceiling = BUFFER_CEILING_OF (start); | ||
| 3170 | ceiling = min (limit, ceiling); | ||
| 3171 | ceiling_addr = &FETCH_CHAR (ceiling) + 1; | ||
| 3172 | base = (cursor = &FETCH_CHAR (start)); | ||
| 3173 | while (1) | ||
| 3174 | { | ||
| 3175 | while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr) | ||
| 3176 | ; | ||
| 3177 | if (cursor != ceiling_addr) | ||
| 3178 | { | ||
| 3179 | if (--count == 0) | ||
| 3180 | { | ||
| 3181 | immediate_quit = 0; | ||
| 3182 | return (start + cursor - base + 1); | ||
| 3183 | } | ||
| 3184 | else | ||
| 3185 | if (++cursor == ceiling_addr) | ||
| 3186 | break; | ||
| 3187 | } | ||
| 3188 | else | ||
| 3189 | break; | ||
| 3190 | } | ||
| 3191 | start += cursor - base; | ||
| 3192 | } | ||
| 3193 | else | ||
| 3194 | { | ||
| 3195 | start--; /* first character we scan */ | ||
| 3196 | while (start > limit - 1) | ||
| 3197 | { /* we WILL scan under start */ | ||
| 3198 | ceiling = BUFFER_FLOOR_OF (start); | ||
| 3199 | ceiling = max (limit, ceiling); | ||
| 3200 | ceiling_addr = &FETCH_CHAR (ceiling) - 1; | ||
| 3201 | base = (cursor = &FETCH_CHAR (start)); | ||
| 3202 | cursor++; | ||
| 3203 | while (1) | ||
| 3204 | { | ||
| 3205 | while (--cursor != ceiling_addr | ||
| 3206 | && *cursor != '\n' && *cursor != 015) | ||
| 3207 | ; | ||
| 3208 | if (cursor != ceiling_addr) | ||
| 3209 | { | ||
| 3210 | if (++count == 0) | ||
| 3211 | { | ||
| 3212 | immediate_quit = 0; | ||
| 3213 | return (start + cursor - base + 1); | ||
| 3214 | } | ||
| 3215 | } | ||
| 3216 | else | ||
| 3217 | break; | ||
| 3218 | } | ||
| 3219 | start += cursor - base; | ||
| 3220 | } | ||
| 3221 | } | ||
| 3222 | |||
| 3223 | if (shortage != 0) | ||
| 3224 | *shortage = count * direction; | ||
| 3225 | return (start + ((direction == 1 ? 0 : 1))); | ||
| 3226 | } | ||
| 3126 | 3227 | ||
| 3127 | /* Count up to N lines starting from FROM. | 3228 | /* Count up to N lines starting from FROM. |
| 3128 | But don't go beyond LIMIT. | 3229 | But don't go beyond LIMIT. |
| @@ -3143,7 +3244,7 @@ display_count_lines (from, limit, n, pos_ptr) | |||
| 3143 | else | 3244 | else |
| 3144 | ZV = limit; | 3245 | ZV = limit; |
| 3145 | 3246 | ||
| 3146 | *pos_ptr = scan_buffer ('\n', from, n, &shortage, 0); | 3247 | *pos_ptr = display_scan_buffer (from, n, &shortage); |
| 3147 | 3248 | ||
| 3148 | ZV = oldzv; | 3249 | ZV = oldzv; |
| 3149 | BEGV = oldbegv; | 3250 | BEGV = oldbegv; |