From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel 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 Message-ID: <20170523202456.GA10407@acm.fritz.box> References: <20170515204416.GA7349@acm.fritz.box> <20170520103428.GB4616@acm.fritz.box> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1495571203 20886 195.159.176.226 (23 May 2017 20:26:43 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 23 May 2017 20:26:43 +0000 (UTC) User-Agent: Mutt/1.5.24 (2015-08-30) Cc: Emacs development discussions To: Dani Moncayo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 23 22:26:35 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dDGO3-0005Eq-22 for ged-emacs-devel@m.gmane.org; Tue, 23 May 2017 22:26:35 +0200 Original-Received: from localhost ([::1]:51468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDGO8-0000K5-BN for ged-emacs-devel@m.gmane.org; Tue, 23 May 2017 16:26:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDGNU-0000Ii-Li for emacs-devel@gnu.org; Tue, 23 May 2017 16:26:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDGNP-0004aq-Lo for emacs-devel@gnu.org; Tue, 23 May 2017 16:26:00 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:45155 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1dDGNP-0004a6-EW for emacs-devel@gnu.org; Tue, 23 May 2017 16:25:55 -0400 Original-Received: (qmail 48993 invoked by uid 3782); 23 May 2017 20:25:52 -0000 Original-Received: from acm.muc.de (p548C7180.dip0.t-ipconnect.de [84.140.113.128]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 23 May 2017 22:25:51 +0200 Original-Received: (qmail 10465 invoked by uid 1000); 23 May 2017 20:24:57 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.4 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:215140 Archived-At: 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).