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". Date: Wed, 17 May 2017 21:32:38 +0000 Message-ID: <20170517213237.GA4156@acm.fritz.box> References: <20170515204416.GA7349@acm.fritz.box> <8337c57bgj.fsf@gnu.org> <20170516203759.GA5238@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 1495056865 15719 195.159.176.226 (17 May 2017 21:34:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 May 2017 21:34:25 +0000 (UTC) User-Agent: Mutt/1.5.24 (2015-08-30) Cc: emacs-devel@gnu.org To: Eli Zaretskii , Dani Moncayo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 17 23:34:21 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 1dB6aJ-0003yi-Ea for ged-emacs-devel@m.gmane.org; Wed, 17 May 2017 23:34:19 +0200 Original-Received: from localhost ([::1]:50826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB6aP-0005D4-6F for ged-emacs-devel@m.gmane.org; Wed, 17 May 2017 17:34:25 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB6Zh-0005Be-9f for emacs-devel@gnu.org; Wed, 17 May 2017 17:33:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB6Ze-0001aP-5C for emacs-devel@gnu.org; Wed, 17 May 2017 17:33:41 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:14757 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1dB6Zd-0001ZB-Q7 for emacs-devel@gnu.org; Wed, 17 May 2017 17:33:38 -0400 Original-Received: (qmail 8934 invoked by uid 3782); 17 May 2017 21:33:33 -0000 Original-Received: from acm.muc.de (p548C6DA5.dip0.t-ipconnect.de [84.140.109.165]) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 17 May 2017 23:33:32 +0200 Original-Received: (qmail 5252 invoked by uid 1000); 17 May 2017 21:32:38 -0000 Content-Disposition: inline In-Reply-To: <20170516203759.GA5238@acm.fritz.box> 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:214932 Archived-At: Hello, Eli and Dani. On Tue, May 16, 2017 at 20:37:59 +0000, Alan Mackenzie wrote: > On Tue, May 16, 2017 at 06:00:12 +0300, Eli Zaretskii wrote: > > > Date: Mon, 15 May 2017 20:44:17 +0000 > > > From: Alan Mackenzie > > > Numerically, "%p" is 100 * a / (a + W + b). > > > "%o" is 100 * a / (a + b). > > Isn't it better to display 100 * (a + W/2) / (a + W + b) instead? > > This shows the portion of buffer before the window-center. It will > > show 50% in the first use case and 73% in the second. IMO, showing > > 98% in the second case sounds misleading, not unlike the current 49%, > > because it effectively disregards the text inside the window, and thus > > can lead to skewed estimations when the part inside the window is > > non-negligible relative to the part that outside. Dani Moncayo wrote > FWIW: I'd love to have these placeholders supported in Emacs, so that > I could show in the modeline the range of text (lines) I'm currently > seeing in the window. E.g.: "(15-25%)". I've hacked these two formulae into xdisp.c, Eli's formula as %O, Dani's as %q. For what it's worth, having tried it, I don't think %O is very useful - it displays a value which (unless it is All, Top, or Bot) ranges between, say 36% and 64%. For %q, I haven't included the parentheses Dani suggested, and it's a bit DWIMy, with things like "All", "Top-5%", "63%-Bot", "15-25%". Just to save you some work, I found the following useful for trying them out, by setting the pertinent part of the standard mode-line format. (i) (For %O): (aset (cadr (car mode-line-position)) 1 ?O) (ii) (For %q): (aset (cadr (car mode-line-position)) 1 ?q) and (setcar (car mode-line-position) -7) Thoughts? diff --git a/src/xdisp.c b/src/xdisp.c index cdea20993c..a2dc595155 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -23870,6 +23870,48 @@ decode_mode_spec (struct window *w, register int c, int field_width, return " Narrow"; break; + /* Display the "degree of travel" of the window through the buffer. */ + case 'o': + { + ptrdiff_t toppos = marker_position (w->start); + ptrdiff_t botpos = BUF_Z (b) - w->window_end_pos; + ptrdiff_t begv = BUF_BEGV (b); + ptrdiff_t zv = BUF_ZV (b); + + if (zv <= botpos) + return toppos <= begv ? "All" : "Bottom"; + else if (toppos <= begv) + return "Top"; + else + { + sprintf (decode_mode_spec_buf, "%2d%%", + percent99 (toppos - begv, (toppos - begv) + (zv - botpos))); + return decode_mode_spec_buf; + } + } + + /* Display the percentage of the buffer above the middle of the screen. */ + case 'O': + { + ptrdiff_t toppos = marker_position (w->start); + ptrdiff_t botpos = BUF_Z (b) - w->window_end_pos; + ptrdiff_t begv = BUF_BEGV (b); + ptrdiff_t zv = BUF_ZV (b); + + if (zv <= botpos) + return toppos <= begv ? "All" : "Bottom"; + else if (toppos <= begv) + return "Top"; + else + { + sprintf (decode_mode_spec_buf, "%2d%%", + percent99 ((toppos + botpos)/2 - begv, + zv - begv)); + return decode_mode_spec_buf; + } + } + + /* Display percentage of buffer above the top of the screen. */ case 'p': { ptrdiff_t pos = marker_position (w->start); @@ -23907,6 +23949,38 @@ decode_mode_spec (struct window *w, register int c, int field_width, } } + /* Display percentage offsets of top and bottom of the window, + using "Top", "Bot" and "All" where appropriate. */ + case 'q': + { + ptrdiff_t toppos = marker_position (w->start); + ptrdiff_t botpos = BUF_Z (b) - w->window_end_pos; + ptrdiff_t begv = BUF_BEGV (b); + ptrdiff_t zv = BUF_ZV (b); + + if ((toppos <= begv) && (zv <= botpos)) + return "All"; + + if (toppos <= begv) + strcpy (decode_mode_spec_buf, "Beg"); + else + sprintf (decode_mode_spec_buf, "%2d", + percent99 (toppos - begv, zv - begv)); + + if (zv <= botpos) + strcat (decode_mode_spec_buf, "%-"); + else + strcat (decode_mode_spec_buf, "-"); + + if (zv <= botpos) + strcat (decode_mode_spec_buf, "Bot"); + else + sprintf (&decode_mode_spec_buf [strlen (decode_mode_spec_buf)], + "%2d%%", percent99 (botpos - begv, zv - begv)); + + return decode_mode_spec_buf; + } + case 's': /* status of process */ obj = Fget_buffer_process (Fcurrent_buffer ()); -- Alan Mackenzie (Nuremberg, Germany).