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: Proposal: new mode-line `%'-construct %o meaning "Degree of travel of window through buffer". Date: Mon, 15 May 2017 20:44:17 +0000 Message-ID: <20170515204416.GA7349@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 1494881155 18211 195.159.176.226 (15 May 2017 20:45:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 15 May 2017 20:45:55 +0000 (UTC) User-Agent: Mutt/1.5.24 (2015-08-30) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 15 22:45:50 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 1dAMsH-0004cz-Dz for ged-emacs-devel@m.gmane.org; Mon, 15 May 2017 22:45:49 +0200 Original-Received: from localhost ([::1]:38768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dAMsN-0004Tv-2q for ged-emacs-devel@m.gmane.org; Mon, 15 May 2017 16:45:55 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dAMrn-0004TO-SV for emacs-devel@gnu.org; Mon, 15 May 2017 16:45:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dAMri-0001R4-UC for emacs-devel@gnu.org; Mon, 15 May 2017 16:45:19 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:64375 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1dAMri-0001O0-I1 for emacs-devel@gnu.org; Mon, 15 May 2017 16:45:14 -0400 Original-Received: (qmail 88592 invoked by uid 3782); 15 May 2017 20:45:11 -0000 Original-Received: from acm.muc.de (p548C6C5F.dip0.t-ipconnect.de [84.140.108.95]) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 15 May 2017 22:45:10 +0200 Original-Received: (qmail 7493 invoked by uid 1000); 15 May 2017 20:44:17 -0000 Content-Disposition: inline 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:214864 Archived-At: Hello, Emacs. I've always been annoyed by the percentage output by the mode-line construct "%p" - so much so that I patched my personal copy of `decode-mode-spec' in xdisp.c over ten years ago (thanks for the tip then, Eli!). What I don't like about it is that is indicates the wrong thing, i.e. the relative position of the top of the window in the buffer. What I want is the degree of travel of the window through the buffer, for which I propose "%o". To illustrate the difference, in the following diagrams, the letters a, W, and b will make up the entire (visible portion of) a buffer, with a being the part above the window, W being the window itself, and b the part below the window. So, if we have a buffer which is twice as big as the portion which fits into the window, and the window is in the middle of the buffer, we have: aaaaaaaaaaaaaaaaWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWbbbbbbbbbbbbbbbb . In this configuration, "%p" reports 25%. The new "%o" would be 50% As the window approaches the end of the buffer: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWb , "%p" reports 49%. I find this disconcerting, since that 49% suggests to me we should be near the middle of the buffer, although we're almost at its end. "%o" here would report 98%. Numerically, "%p" is 100 * a / (a + W + b). "%o" is 100 * a / (a + b). Here is (the code part of) a patch which implements this "%o": diff --git a/src/xdisp.c b/src/xdisp.c index cdea20993c..f1236e1583 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -23870,6 +23870,26 @@ 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; + } + } + case 'p': { ptrdiff_t pos = marker_position (w->start); What do people say? -- Alan Mackenzie (Nuremberg, Germany).