[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Proposal: new mode-line `%'-construct %o meaning "Degree of travel o
From: |
Alan Mackenzie |
Subject: |
Re: Proposal: new mode-line `%'-construct %o meaning "Degree of travel of window through buffer". [Patch] |
Date: |
Tue, 23 May 2017 20:24:57 +0000 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
Hello, Dani.
On Tue, May 23, 2017 at 10:00:55 +0200, Dani Moncayo wrote:
> > Here is a patch which implements %o and %q. Feedback would be welcome,
> > of course.
> I'm thinking of a further refinement for %q: On large enough buffers,
> %q may produce things like "43-43%". In those cases, where both
> percentages are the same, it'd be better (nicer, IMO) to just show one
> of them (e.g "43%").
OK, how about the following?
diff --git a/src/xdisp.c b/src/xdisp.c
index 0588061738..ef55e0f481 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -23990,21 +23990,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);
+ ptrdiff_t 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;
}
--
Alan Mackenzie (Nuremberg, Germany).
- Re: Difficulty applying multi-file patches from within emacs (Was: Proposal: new mode-line `%'-construct %o ..), (continued)
- Re: Difficulty applying multi-file patches from within emacs, Alan Mackenzie, 2017/05/21
- Re: Difficulty applying multi-file patches from within emacs, Philipp Stephani, 2017/05/21
- Re: Difficulty applying multi-file patches from within emacs, Alan Mackenzie, 2017/05/21
- Re: Difficulty applying multi-file patches from within emacs, Kaushal Modi, 2017/05/21
- Re: Difficulty applying multi-file patches from within emacs, Kaushal Modi, 2017/05/21
- Re: Difficulty applying multi-file patches from within emacs (Was: Proposal: new mode-line `%'-construct %o ..), Tino Calancha, 2017/05/23
Re: Proposal: new mode-line `%'-construct %o meaning "Degree of travel of window through buffer". [Patch], Dani Moncayo, 2017/05/23