GNU bug report logs -
#46476
Feature request: Right-aligning part of the modeline
Previous Next
To reply to this bug, email your comments to 46476 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46476
; Package
emacs
.
(Sat, 13 Feb 2021 01:08:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Paweł Kraśnicki <paul.krasnicki <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 13 Feb 2021 01:08:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Many people who use Emacs with significant customization have their modeline
split into left and right aligned parts. I've also seen the Lisp code for this
in several packages. I think it would be useful to have this feature as a
%-construct so that the users who want it wouldn't have to install a package or
write custom Lisp that uses the `display' text property.
Everything after this construct would be aligned to the right. For example,
assuming the construct was %=, the mode-line-format
"l%=r"
would cause the modeline in a 20 character wide window to look like
l r
It could also be useful to generalize this to centering, though I've seen this
used less often. Then, the mode-line-format
"lllll%=c%=r"
would cause the modeline to look like
lllll c r
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46476
; Package
emacs
.
(Sat, 13 Feb 2021 08:19:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 46476 <at> debbugs.gnu.org (full text, mbox):
> From: Paweł Kraśnicki
> <paul.krasnicki <at> gmail.com>
> Date: Fri, 12 Feb 2021 23:59:26 +0100
>
> Many people who use Emacs with significant customization have their modeline
> split into left and right aligned parts. I've also seen the Lisp code for this
> in several packages.
Can you describe how is this done in Lisp?
> I think it would be useful to have this feature as a
> %-construct so that the users who want it wouldn't have to install a package or
> write custom Lisp that uses the `display' text property.
>
> Everything after this construct would be aligned to the right. For example,
> assuming the construct was %=, the mode-line-format
>
> "l%=r"
>
> would cause the modeline in a 20 character wide window to look like
>
> l r
>
> It could also be useful to generalize this to centering, though I've seen this
> used less often. Then, the mode-line-format
>
> "lllll%=c%=r"
>
> would cause the modeline to look like
>
> lllll c r
The immediate question about this I have is what to do when the
mode-line string is too long for the window's width? Right now, we
simply chop the stuff on the right that doesn't fit, but if the
mode-line string has 2 or 3 different part, that should be revised,
right?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46476
; Package
emacs
.
(Sat, 13 Feb 2021 16:31:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 46476 <at> debbugs.gnu.org (full text, mbox):
> Can you describe how is this done in Lisp?
Sure. The most common solution is to use a text property that displays a space
with the `:align-to' property. Here's a simplified version of the code from the
popular `powerline' package:
(defvar ml-text-scale-factor 1.0
"Ratio of mode-line text size to default text size, as a float.
This is needed to make sure the text is properly aligned.")
(defun ml-fill-to-center (reserve face)
"Return empty space to the center, leaving RESERVE space on the right."
(setq reserve (* ml-text-scale-factor reserve))
(propertize " "
'display `((space :align-to (- (+ center (.5 . right-margin))
,reserve
(.5 . left-margin))))
'face face))
(defun ml-fill-to-right (reserve face)
"Return empty space, leaving RESERVE space on the right."
(setq reserve (* ml-text-scale-factor reserve))
(when (and window-system (eq 'right (get-scroll-bar-mode)))
(setq reserve (- reserve 2))) ; May be 3 instead of 2 with some toolkits?
(propertize " "
'display `((space :align-to (- (+ right right-fringe right-margin)
,reserve)))
'face face))
(defun ml-render-2-part (left right &optional fill-face)
"Show a modeline with left and right aligned parts."
(concat left
(ml-fill-to-right (string-width (format-mode-line right)) fill-face)
right))
(defun ml-render-3-part (left center right &optional fill-face)
"Show a modeline with left, center, and right aligned parts."
(concat left
(ml-fill-to-center (/ (string-width (format-mode-line center)) 2.0)
fill-face)
center
(ml-fill-to-right (string-width (format-mode-line right)) fill-face)
right))
;; (setq mode-line-format '((:eval (ml-render-2-part "l" "r"))))
;; (setq mode-line-format '((:eval (ml-render-3-part "lllll" "c" "r"))))
> The immediate question about this I have is what to do when the
> mode-line string is too long for the window's width? Right now, we
> simply chop the stuff on the right that doesn't fit, but if the
> mode-line string has 2 or 3 different part, that should be revised,
> right?
I'm not sure. With the current Lisp solutions, the modeline gets chopped on the
right too, and it seems that people either don't mind that at all, or they use
custom "segment" logic. The idea here is that the modeline is composed of a few
segments, with each having a priority number. As the window shrinks, the
segments get hidden in discrete jumps starting from the lowest priority, until
only the segment(s) with the highest priority number remain. I think there may
not be any demand for an intermediate solution that would let the user configure
hiding with granularity of left/center/right.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46476
; Package
emacs
.
(Sat, 13 Feb 2021 17:00:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 46476 <at> debbugs.gnu.org (full text, mbox):
> From: Paweł Kraśnicki <paul.krasnicki <at> gmail.com>
> Date: Sat, 13 Feb 2021 17:30:16 +0100
> Cc: 46476 <at> debbugs.gnu.org
>
> > Can you describe how is this done in Lisp?
>
> Sure. The most common solution is to use a text property that displays a space
> with the `:align-to' property. Here's a simplified version of the code from the
> popular `powerline' package:
If people use :align-to, then what would be the advantage of providing
%-constructs to produce the same?
> > The immediate question about this I have is what to do when the
> > mode-line string is too long for the window's width? Right now, we
> > simply chop the stuff on the right that doesn't fit, but if the
> > mode-line string has 2 or 3 different part, that should be revised,
> > right?
>
> I'm not sure. With the current Lisp solutions, the modeline gets chopped on the
> right too, and it seems that people either don't mind that at all, or they use
> custom "segment" logic. The idea here is that the modeline is composed of a few
> segments, with each having a priority number. As the window shrinks, the
> segments get hidden in discrete jumps starting from the lowest priority, until
> only the segment(s) with the highest priority number remain. I think there may
> not be any demand for an intermediate solution that would let the user configure
> hiding with granularity of left/center/right.
That'd require two passes to generate the mode-line display, right?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46476
; Package
emacs
.
(Sat, 13 Feb 2021 17:46:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 46476 <at> debbugs.gnu.org (full text, mbox):
> If people use :align-to, then what would be the advantage of providing
> %-constructs to produce the same?
Well, the only advantage is that people wouldn't need to install an external
package or write a short but advanced piece of Lisp. I think that right
alignment is such a commonly used feature that it would be good to have it
accessible very easily. (Center alignment and segments are less popular.)
I actually got the idea for using %= in particular from Vim, which has right
alignment under this %-construct.
> That'd require two passes to generate the mode-line display, right?
I think so. Emacs would have to first expand the modeline constructs in the
segments separately into some internal data structure, then decide which ones to
actually display.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#46476
; Package
emacs
.
(Sat, 13 Feb 2021 18:09:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 46476 <at> debbugs.gnu.org (full text, mbox):
> From: Paweł Kraśnicki <paul.krasnicki <at> gmail.com>
> Date: Sat, 13 Feb 2021 18:45:14 +0100
> Cc: 46476 <at> debbugs.gnu.org
>
> > If people use :align-to, then what would be the advantage of providing
> > %-constructs to produce the same?
>
> Well, the only advantage is that people wouldn't need to install an external
> package or write a short but advanced piece of Lisp. I think that right
> alignment is such a commonly used feature that it would be good to have it
> accessible very easily. (Center alignment and segments are less popular.)
> I actually got the idea for using %= in particular from Vim, which has right
> alignment under this %-construct.
This currently seems to be somewhat problematic, given the recursive
manner in which the mode line elements are produced by the display
code.
> > That'd require two passes to generate the mode-line display, right?
>
> I think so. Emacs would have to first expand the modeline constructs in the
> segments separately into some internal data structure, then decide which ones to
> actually display.
Patches welcome.
Added tag(s) confirmed.
Request was from
Stefan Kangas <stefan <at> marxist.se>
to
control <at> debbugs.gnu.org
.
(Wed, 21 Apr 2021 03:05:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 119 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.