}
else /* c == '%' */
{
+ register int minendcol;
register int spec_width = 0;
/* We can't allow -ve args due to the "%-" construct */
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,
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);
}
}
}
return hpos;
}
\f
+/* 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;
{
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;
}
/* 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)
{
w->base_line_pos = w->buffer;
w->base_line_number = Qnil;
- return "??";
+ goto no_value;
}
XSETFASTINT (w->base_line_number, topline - nlines);
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;