diff options
author | Richard M. Stallman <rms@gnu.org> | 1995-07-18 23:07:23 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1995-07-18 23:07:23 +0000 |
commit | 6111e6898072250d9eb4ba6478f888e4f49c5337 (patch) | |
tree | 138b64e5ae7a813e7b5321c6ea3655fd9b72a5a0 | |
parent | c811a684f2979f2fc5cf8af1994c1ae661d4f838 (diff) | |
download | emacs-6111e6898072250d9eb4ba6478f888e4f49c5337.tar.gz |
(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.
-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) } else /* c == '%' */ { + register int minendcol; register int spec_width = 0; /* We can't allow -ve args due to the "%-" construct */ @@ -3247,9 +3248,12 @@ display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) spec_width = spec_width * 10 + (c - '0'); } - spec_width += hpos; - if (spec_width > maxendcol) - spec_width = maxendcol; + minendcol = hpos + spec_width; + if (minendcol > maxendcol) + { + spec_width = maxendcol - hpos; + minendcol = maxendcol; + } if (c == 'M') hpos = display_mode_element (w, vpos, hpos, depth, @@ -3257,13 +3261,14 @@ display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) Vglobal_mode_string); else if (c != 0) { - char *spec = decode_mode_spec (w, c, maxendcol - hpos); + char *spec = decode_mode_spec (w, c, spec_width, + maxendcol - hpos); if (frame_title_ptr) - hpos = store_frame_title (spec, spec_width, maxendcol); + hpos = store_frame_title (spec, minendcol, maxendcol); else hpos = display_string (w, vpos, spec, -1, hpos, 0, 1, - spec_width, maxendcol); + minendcol, maxendcol); } } } @@ -3397,15 +3402,47 @@ display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt) return hpos; } +/* Write a null-terminated, right justified decimal representation of + the positive integer D to BUF using a minimal field width WIDTH. */ + +static void +pint2str (buf, width, d) + register char *buf; + register int width; + register int d; +{ + register char *p = buf; + + if (d <= 0) + *p++ = '0'; + else + while (d > 0) + { + *p++ = d % 10 + '0'; + d /= 10; + } + for (width -= (int) (p - buf); width > 0; --width) *p++ = ' '; + *p-- = '\0'; + while (p > buf) + { + d = *buf; + *buf++ = *p; + *p-- = d; + } +} + /* Return a string for the output of a mode line %-spec for window W, - generated by character C and width MAXWIDTH. */ + generated by character C. SPEC_WIDTH is the field width when + padding to the left (%c, %l). The value returned from this + function will later be truncated to width MAXWIDTH. */ static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------"; static char * -decode_mode_spec (w, c, maxwidth) +decode_mode_spec (w, c, spec_width, maxwidth) struct window *w; register char c; + register int spec_width; register int maxwidth; { Lisp_Object obj; @@ -3504,7 +3541,7 @@ decode_mode_spec (w, c, maxwidth) { int col = current_column (); XSETFASTINT (w->column_number_displayed, col); - sprintf (decode_mode_spec_buf, "%d", col); + pint2str (decode_mode_spec_buf, spec_width, col); return decode_mode_spec_buf; } @@ -3542,14 +3579,14 @@ decode_mode_spec (w, c, maxwidth) /* If we decided that this buffer isn't suitable for line numbers, don't forget that too fast. */ if (EQ (w->base_line_pos, w->buffer)) - return "??"; + goto no_value; /* If the buffer is very big, don't waste time. */ if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit) { w->base_line_pos = Qnil; w->base_line_number = Qnil; - return "??"; + goto no_value; } if (!NILP (w->base_line_number) @@ -3599,7 +3636,7 @@ decode_mode_spec (w, c, maxwidth) { w->base_line_pos = w->buffer; w->base_line_number = Qnil; - return "??"; + goto no_value; } XSETFASTINT (w->base_line_number, topline - nlines); @@ -3613,8 +3650,15 @@ decode_mode_spec (w, c, maxwidth) line_number_displayed = 1; /* Make the string to show. */ - sprintf (decode_mode_spec_buf, "%d", topline + nlines); + pint2str (decode_mode_spec_buf, spec_width, topline + nlines); return decode_mode_spec_buf; + no_value: + { + char* p = decode_mode_spec_buf; + for (spec_width -= 2; spec_width > 0; --spec_width) *p++ = ' '; + strcpy (p, "??"); + return decode_mode_spec_buf; + } } break; |