(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.
This commit is contained in:
Richard M. Stallman 1995-07-18 23:07:23 +00:00
parent 0fea6c408f
commit 766525bccb

View file

@ -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;