comparison src/xdisp.c @ 8622:4ce43042e7ad

(display_scan_buffer): New function. (display_count_lines): Use that.
author Richard M. Stallman <rms@gnu.org>
date Thu, 25 Aug 1994 01:25:55 +0000
parents 4d8d02befd11
children 020c4d5b685b
comparison
equal deleted inserted replaced
8621:e292e9adde9b 8622:4ce43042e7ad
3121 if (XTYPE (obj) == Lisp_String) 3121 if (XTYPE (obj) == Lisp_String)
3122 return (char *) XSTRING (obj)->data; 3122 return (char *) XSTRING (obj)->data;
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.
3129 Return the number of lines thus found (always positive). 3230 Return the number of lines thus found (always positive).
3130 Store the position after what was found into *POS_PTR. */ 3231 Store the position after what was found into *POS_PTR. */
3141 if (limit < from) 3242 if (limit < from)
3142 BEGV = limit; 3243 BEGV = limit;
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;
3150 3251
3151 if (n < 0) 3252 if (n < 0)