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: Sat, 20 May 2017 10:34:29 +0000 Message-ID: <20170520103428.GB4616@acm.fritz.box> References: <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 1495276534 9820 195.159.176.226 (20 May 2017 10:35:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 20 May 2017 10:35:34 +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 Sat May 20 12:35:30 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 1dC1jO-0002Q3-0N for ged-emacs-devel@m.gmane.org; Sat, 20 May 2017 12:35:30 +0200 Original-Received: from localhost ([::1]:33709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dC1jT-0007HU-KE for ged-emacs-devel@m.gmane.org; Sat, 20 May 2017 06:35:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dC1jM-0007HP-Sw for emacs-devel@gnu.org; Sat, 20 May 2017 06:35:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dC1jJ-0006ex-Oq for emacs-devel@gnu.org; Sat, 20 May 2017 06:35:28 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:44090 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1dC1jJ-0006ek-Du for emacs-devel@gnu.org; Sat, 20 May 2017 06:35:25 -0400 Original-Received: (qmail 82090 invoked by uid 3782); 20 May 2017 10:35:24 -0000 Original-Received: from acm.muc.de (p548C67C5.dip0.t-ipconnect.de [84.140.103.197]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 20 May 2017 12:35:24 +0200 Original-Received: (qmail 4657 invoked by uid 1000); 20 May 2017 10:34:29 -0000 Content-Disposition: inline In-Reply-To: <20170515204416.GA7349@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:215010 Archived-At: On Mon, May 15, 2017 at 20:44:17 +0000, Alan Mackenzie wrote: > 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!). [ .... ] Here is a patch which implements %o and %q. Feedback would be welcome, of course. diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index eb72fcfd36..0e476b47a3 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi @@ -1972,6 +1972,14 @@ Mode Line Variables line number and the column number. @end defvar +@defopt mode-line-percent-position +This option is used in @code{mode-line-position}. Its value specifies +both the buffer percentage to display (one of @code{nil}, @code{"%o"}, +@code{"%p"}, @code{"%P"} or @code{"%q"}, @pxref{%-Constructs}) and a +width to space-fill or truncate to. You are recommended to set this +option with the @code{customize-variable} facility. +@end defopt + @defvar vc-mode The variable @code{vc-mode}, buffer-local in each buffer, records whether the buffer's visited file is maintained with version control, @@ -2147,6 +2155,12 @@ %-Constructs @samp{Narrow} when narrowing is in effect; nothing otherwise (see @code{narrow-to-region} in @ref{Narrowing}). +@item %o +The degree of @dfn{travel} of the window through (the visible portion +of) the buffer, i.e. the size of the text above the top of the window +expressed as a percentage of all the text outside the window, or +@samp{Top}, @samp{Bottom} or @samp{All}. + @item %p The percentage of the buffer text above the @strong{top} of window, or @samp{Top}, @samp{Bottom} or @samp{All}. Note that the default mode @@ -2158,6 +2172,10 @@ %-Constructs the text above the top), plus @samp{Top} if the top of the buffer is visible on screen; or @samp{Bottom} or @samp{All}. +@item %q +The percentages of text above both the @strong{top} and the +@strong{bottom} of the window, separated by @samp{-}, or @samp{All}. + @item %s The status of the subprocess belonging to the current buffer, obtained with @code{process-status}. @xref{Process Information}. diff --git a/etc/NEWS b/etc/NEWS index 9be6ee0f3f..4a8696ace4 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -358,6 +358,16 @@ new mode line construct, '%C', which operates exactly as '%c' does except that it counts from one.) +++ +** New mode line constructs '%o' and '%q', and user option +'mode-line-percent-position'. '%o' displays the "degree of travel" of +the window through the buffer. Unlike the default '%p', this +percentage approaches 100% as the window approaches the end of the +buffer. '%q' displays the percentage offsets of both the start and +the end of the window, e.g. "5-17%". The new option +'mode-line-percent-position' makes it easier to switch between '%p', +'%P', and these new constructs. + ++++ ** Two new user options 'list-matching-lines-jump-to-current-line' and 'list-matching-lines-current-line-face' to show highlighted the current line in *Occur* buffer. diff --git a/lisp/bindings.el b/lisp/bindings.el index 85a5408717..1f5c8b3bbf 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -365,14 +365,32 @@ column-number-indicator-zero-based :group 'mode-line :version "26.1") +(defcustom mode-line-percent-position '(-3 "%p") + "Specification of \"percentage offset\" of window through buffer +This option specifies both the field width and the type of offset +displayed in `mode-line-position', a component of the default +`mode-line-format'." + :type `(radio + (const :tag "nil: No offset is displayed" nil) + (const :tag "\"%o\": Proportion of \"travel\" of the window through the buffer" + (-3 "%o")) + (const :tag "\"%p\": Percentage offset of top of window" + (-3 "%p")) + (const :tag "\"%P\": Precentage offset of bottom of window" + (-3 "%P")) + (const :tag "\"%q\": Offsets of both top and bottom of window" + (6 "%q"))) + :version "26.1" + :group 'mode-line) + (defvar mode-line-position - `((-3 ,(propertize - "%p" - 'local-map mode-line-column-line-number-mode-map - 'mouse-face 'mode-line-highlight - ;; XXX needs better description - 'help-echo "Size indication mode\n\ -mouse-1: Display Line and Column Mode Menu")) + `((:propertize + mode-line-percent-position + 'local-map mode-line-column-line-number-mode-map + 'mouse-face 'mode-line-highlight + ;; XXX needs better description + 'help-echo "Size indication mode\n\ +mouse-1: Display Line and Column Mode Menu") (size-indication-mode (8 ,(propertize " of %I" @@ -419,6 +437,7 @@ mode-line-position "Mode line construct for displaying the position in the buffer. Normally displays the buffer percentage and, optionally, the buffer size, the line number and the column number.") + (put 'mode-line-position 'risky-local-variable t) (defvar mode-line-buffer-identification-keymap diff --git a/src/xdisp.c b/src/xdisp.c index cdea20993c..27349aeba3 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -23870,6 +23870,27 @@ 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 percentage of buffer above the top of the screen. */ case 'p': { ptrdiff_t pos = marker_position (w->start); @@ -23907,6 +23928,33 @@ decode_mode_spec (struct window *w, register int c, int field_width, } } + /* Display percentage offsets of top and bottom of the window, + using "All" (but not "Top" or "Bottom") 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, "0-"); + else + sprintf (decode_mode_spec_buf, "%d-", + percent99 (toppos - begv, zv - begv)); + + if (zv <= botpos) + strcat (decode_mode_spec_buf, "100%"); + else + sprintf (&decode_mode_spec_buf [strlen (decode_mode_spec_buf)], + "%d%%", 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).