diff options
| author | Richard M. Stallman | 1995-07-18 23:07:23 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-07-18 23:07:23 +0000 |
| commit | 766525bccb8e3fe827819ca6c219ebf1002a675b (patch) | |
| tree | a5cc60d1146134a05835774004281f2dbe8ee116 /src | |
| parent | 0fea6c408ff0be60247cd3280a9a6f37d45425d7 (diff) | |
| download | emacs-766525bccb8e3fe827819ca6c219ebf1002a675b.tar.gz emacs-766525bccb8e3fe827819ca6c219ebf1002a675b.zip | |
(decode_mode_spec): New arg spec_width.
Use pint2str for %l and %c. New code to output ??.
(display_mode_element): New var minendcol.
Pass new arg to decode_mode_spec.
(pint2str): New function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index f7cdcdacfe1..b2b338a7831 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -3235,6 +3235,7 @@ display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) | |||
| 3235 | } | 3235 | } |
| 3236 | else /* c == '%' */ | 3236 | else /* c == '%' */ |
| 3237 | { | 3237 | { |
| 3238 | register int minendcol; | ||
| 3238 | register int spec_width = 0; | 3239 | register int spec_width = 0; |
| 3239 | 3240 | ||
| 3240 | /* We can't allow -ve args due to the "%-" construct */ | 3241 | /* We can't allow -ve args due to the "%-" construct */ |
| @@ -3247,9 +3248,12 @@ display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) | |||
| 3247 | spec_width = spec_width * 10 + (c - '0'); | 3248 | spec_width = spec_width * 10 + (c - '0'); |
| 3248 | } | 3249 | } |
| 3249 | 3250 | ||
| 3250 | spec_width += hpos; | 3251 | minendcol = hpos + spec_width; |
| 3251 | if (spec_width > maxendcol) | 3252 | if (minendcol > maxendcol) |
| 3252 | spec_width = maxendcol; | 3253 | { |
| 3254 | spec_width = maxendcol - hpos; | ||
| 3255 | minendcol = maxendcol; | ||
| 3256 | } | ||
| 3253 | 3257 | ||
| 3254 | if (c == 'M') | 3258 | if (c == 'M') |
| 3255 | hpos = display_mode_element (w, vpos, hpos, depth, | 3259 | hpos = display_mode_element (w, vpos, hpos, depth, |
| @@ -3257,13 +3261,14 @@ display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) | |||
| 3257 | Vglobal_mode_string); | 3261 | Vglobal_mode_string); |
| 3258 | else if (c != 0) | 3262 | else if (c != 0) |
| 3259 | { | 3263 | { |
| 3260 | char *spec = decode_mode_spec (w, c, maxendcol - hpos); | 3264 | char *spec = decode_mode_spec (w, c, spec_width, |
| 3265 | maxendcol - hpos); | ||
| 3261 | if (frame_title_ptr) | 3266 | if (frame_title_ptr) |
| 3262 | hpos = store_frame_title (spec, spec_width, maxendcol); | 3267 | hpos = store_frame_title (spec, minendcol, maxendcol); |
| 3263 | else | 3268 | else |
| 3264 | hpos = display_string (w, vpos, spec, -1, | 3269 | hpos = display_string (w, vpos, spec, -1, |
| 3265 | hpos, 0, 1, | 3270 | hpos, 0, 1, |
| 3266 | spec_width, maxendcol); | 3271 | minendcol, maxendcol); |
| 3267 | } | 3272 | } |
| 3268 | } | 3273 | } |
| 3269 | } | 3274 | } |
| @@ -3397,15 +3402,47 @@ display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) | |||
| 3397 | return hpos; | 3402 | return hpos; |
| 3398 | } | 3403 | } |
| 3399 | 3404 | ||
| 3405 | /* Write a null-terminated, right justified decimal representation of | ||
| 3406 | the positive integer D to BUF using a minimal field width WIDTH. */ | ||
| 3407 | |||
| 3408 | static void | ||
| 3409 | pint2str (buf, width, d) | ||
| 3410 | register char *buf; | ||
| 3411 | register int width; | ||
| 3412 | register int d; | ||
| 3413 | { | ||
| 3414 | register char *p = buf; | ||
| 3415 | |||
| 3416 | if (d <= 0) | ||
| 3417 | *p++ = '0'; | ||
| 3418 | else | ||
| 3419 | while (d > 0) | ||
| 3420 | { | ||
| 3421 | *p++ = d % 10 + '0'; | ||
| 3422 | d /= 10; | ||
| 3423 | } | ||
| 3424 | for (width -= (int) (p - buf); width > 0; --width) *p++ = ' '; | ||
| 3425 | *p-- = '\0'; | ||
| 3426 | while (p > buf) | ||
| 3427 | { | ||
| 3428 | d = *buf; | ||
| 3429 | *buf++ = *p; | ||
| 3430 | *p-- = d; | ||
| 3431 | } | ||
| 3432 | } | ||
| 3433 | |||
| 3400 | /* Return a string for the output of a mode line %-spec for window W, | 3434 | /* Return a string for the output of a mode line %-spec for window W, |
| 3401 | generated by character C and width MAXWIDTH. */ | 3435 | generated by character C. SPEC_WIDTH is the field width when |
| 3436 | padding to the left (%c, %l). The value returned from this | ||
| 3437 | function will later be truncated to width MAXWIDTH. */ | ||
| 3402 | 3438 | ||
| 3403 | static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------"; | 3439 | static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------"; |
| 3404 | 3440 | ||
| 3405 | static char * | 3441 | static char * |
| 3406 | decode_mode_spec (w, c, maxwidth) | 3442 | decode_mode_spec (w, c, spec_width, maxwidth) |
| 3407 | struct window *w; | 3443 | struct window *w; |
| 3408 | register char c; | 3444 | register char c; |
| 3445 | register int spec_width; | ||
| 3409 | register int maxwidth; | 3446 | register int maxwidth; |
| 3410 | { | 3447 | { |
| 3411 | Lisp_Object obj; | 3448 | Lisp_Object obj; |
| @@ -3504,7 +3541,7 @@ decode_mode_spec (w, c, maxwidth) | |||
| 3504 | { | 3541 | { |
| 3505 | int col = current_column (); | 3542 | int col = current_column (); |
| 3506 | XSETFASTINT (w->column_number_displayed, col); | 3543 | XSETFASTINT (w->column_number_displayed, col); |
| 3507 | sprintf (decode_mode_spec_buf, "%d", col); | 3544 | pint2str (decode_mode_spec_buf, spec_width, col); |
| 3508 | return decode_mode_spec_buf; | 3545 | return decode_mode_spec_buf; |
| 3509 | } | 3546 | } |
| 3510 | 3547 | ||
| @@ -3542,14 +3579,14 @@ decode_mode_spec (w, c, maxwidth) | |||
| 3542 | /* If we decided that this buffer isn't suitable for line numbers, | 3579 | /* If we decided that this buffer isn't suitable for line numbers, |
| 3543 | don't forget that too fast. */ | 3580 | don't forget that too fast. */ |
| 3544 | if (EQ (w->base_line_pos, w->buffer)) | 3581 | if (EQ (w->base_line_pos, w->buffer)) |
| 3545 | return "??"; | 3582 | goto no_value; |
| 3546 | 3583 | ||
| 3547 | /* If the buffer is very big, don't waste time. */ | 3584 | /* If the buffer is very big, don't waste time. */ |
| 3548 | if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit) | 3585 | if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit) |
| 3549 | { | 3586 | { |
| 3550 | w->base_line_pos = Qnil; | 3587 | w->base_line_pos = Qnil; |
| 3551 | w->base_line_number = Qnil; | 3588 | w->base_line_number = Qnil; |
| 3552 | return "??"; | 3589 | goto no_value; |
| 3553 | } | 3590 | } |
| 3554 | 3591 | ||
| 3555 | if (!NILP (w->base_line_number) | 3592 | if (!NILP (w->base_line_number) |
| @@ -3599,7 +3636,7 @@ decode_mode_spec (w, c, maxwidth) | |||
| 3599 | { | 3636 | { |
| 3600 | w->base_line_pos = w->buffer; | 3637 | w->base_line_pos = w->buffer; |
| 3601 | w->base_line_number = Qnil; | 3638 | w->base_line_number = Qnil; |
| 3602 | return "??"; | 3639 | goto no_value; |
| 3603 | } | 3640 | } |
| 3604 | 3641 | ||
| 3605 | XSETFASTINT (w->base_line_number, topline - nlines); | 3642 | XSETFASTINT (w->base_line_number, topline - nlines); |
| @@ -3613,8 +3650,15 @@ decode_mode_spec (w, c, maxwidth) | |||
| 3613 | line_number_displayed = 1; | 3650 | line_number_displayed = 1; |
| 3614 | 3651 | ||
| 3615 | /* Make the string to show. */ | 3652 | /* Make the string to show. */ |
| 3616 | sprintf (decode_mode_spec_buf, "%d", topline + nlines); | 3653 | pint2str (decode_mode_spec_buf, spec_width, topline + nlines); |
| 3617 | return decode_mode_spec_buf; | 3654 | return decode_mode_spec_buf; |
| 3655 | no_value: | ||
| 3656 | { | ||
| 3657 | char* p = decode_mode_spec_buf; | ||
| 3658 | for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' '; | ||
| 3659 | strcpy (p, "??"); | ||
| 3660 | return decode_mode_spec_buf; | ||
| 3661 | } | ||
| 3618 | } | 3662 | } |
| 3619 | break; | 3663 | break; |
| 3620 | 3664 | ||