emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master b0b02ca: Enhance mode-line percentage offset facili


From: Alan Mackenzie
Subject: [Emacs-diffs] master b0b02ca: Enhance mode-line percentage offset facility, with "%o" and "%q"
Date: Sun, 21 May 2017 06:19:01 -0400 (EDT)

branch: master
commit b0b02ca7f3e06d0f092df6f81babd1277bf93b0f
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Enhance mode-line percentage offset facility, with "%o" and "%q"
    
    "%o" will display the percentage "travel" of the window through the buffer.
    "%q" will display a combination of the percentage offsets of the top and
    bottom of the window.  The new user option mode-line-percent-position will
    facilitate selecting a setting for this part of the mode line.
    
    * lisp/bindings.el (mode-line-percent-position): New customizable user 
option.
    (mode-line-position): Use mode-line-percent-position in place of "%p", etc.
    
    * src/xdisp.c (decode_mode_spec): Add handlers for "%o" and "%q".
    
    * doc/lispref/modes.texi (Mode Line Variables): Document
    mode-line-percent-position.
    (%-Constructs): Document %o and %q.
    
    * etc/NEWS: Add an entry for these new facilities.
---
 doc/lispref/modes.texi | 18 ++++++++++++++++++
 etc/NEWS               | 10 ++++++++++
 lisp/bindings.el       | 32 +++++++++++++++++++++++++-------
 src/xdisp.c            | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+), 7 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index eb72fcf..0e476b4 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1972,6 +1972,14 @@ displays the buffer percentage and, optionally, the 
buffer size, the
 line number and the column number.
 @end defvar
 
address@hidden 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"},
address@hidden"%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.
address@hidden 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 @@ of the buffer.
 @samp{Narrow} when narrowing is in effect; nothing otherwise (see
 @code{narrow-to-region} in @ref{Narrowing}).
 
address@hidden %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
address@hidden, @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 @@ the window (which includes the text visible in the 
window, as well as
 the text above the top), plus @samp{Top} if the top of the buffer is
 visible on screen; or @samp{Bottom} or @samp{All}.
 
address@hidden %q
+The percentages of text above both the @strong{top} and the
address@hidden 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 1b1fec3..2ca91d5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -379,6 +379,16 @@ displayed to be horizontally scrolled when lines are 
truncated on
 display and point moves outside the left or right window margin.
 
 +++
+** 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 85a5408..0b4c3bd 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -365,14 +365,32 @@ zero, otherwise they start from one."
   :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"
diff --git a/src/xdisp.c b/src/xdisp.c
index c0e821a..0588061 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -23924,6 +23924,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);
@@ -23961,6 +23982,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 ());



reply via email to

[Prev in Thread] Current Thread [Next in Thread]