From f8f58fe37ee932996f61b4c568512cc5dfc4e3fa Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Tue, 30 May 2017 17:42:52 +0000 Subject: [PATCH] Mode line "%q" construct: Just use one number when both would be the same. * src/xdisp (decode_mode_spec): recode the "%q" bit appropriately. --- src/xdisp.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/xdisp.c b/src/xdisp.c index ddb26b8defd..c03689bf616 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -23992,21 +23992,18 @@ decode_mode_spec (struct window *w, register int c, int field_width, ptrdiff_t botpos = BUF_Z (b) - w->window_end_pos; ptrdiff_t begv = BUF_BEGV (b); ptrdiff_t zv = BUF_ZV (b); + int top_perc, bot_perc; if ((toppos <= begv) && (zv <= botpos)) return "All "; - if (toppos <= begv) - strcpy (decode_mode_spec_buf, "0-"); - else - sprintf (decode_mode_spec_buf, "%d-", - percent99 (toppos - begv, zv - begv)); + top_perc = toppos <= begv ? 0 : percent99 (toppos - begv, zv - begv); + bot_perc = zv <= botpos ? 100 : percent99 (botpos - begv, zv - begv); - if (zv <= botpos) - strcat (decode_mode_spec_buf, "100%"); + if (top_perc == bot_perc) + sprintf (decode_mode_spec_buf, "%d%%", top_perc); else - sprintf (&decode_mode_spec_buf [strlen (decode_mode_spec_buf)], - "%d%%", percent99 (botpos - begv, zv - begv)); + sprintf (decode_mode_spec_buf, "%d-%d%%", top_perc, bot_perc); return decode_mode_spec_buf; } -- 2.39.2