mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-30 04:10:54 -08:00
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.
This commit is contained in:
parent
9759b249e9
commit
b0b02ca7f3
4 changed files with 101 additions and 7 deletions
|
|
@ -1972,6 +1972,14 @@ displays the buffer percentage and, optionally, the buffer size, the
|
|||
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 @@ of the buffer.
|
|||
@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 @@ 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}.
|
||||
|
||||
@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}.
|
||||
|
|
|
|||
10
etc/NEWS
10
etc/NEWS
|
|
@ -378,6 +378,16 @@ The 'auto-hscroll-mode' variable can now have a new special value,
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
48
src/xdisp.c
48
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 ());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue