unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Paweł Kraśnicki" <paul.krasnicki@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 46476@debbugs.gnu.org
Subject: bug#46476: Feature request: Right-aligning part of the modeline
Date: Sat, 13 Feb 2021 17:30:16 +0100	[thread overview]
Message-ID: <CAPZgK776KeZpvSX--bL-nf=cQTMLYah-BkeJpE45TmaTaBBkRA@mail.gmail.com> (raw)
In-Reply-To: <83ft20e5z0.fsf@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:

(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.





  reply	other threads:[~2021-02-13 16:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 22:59 bug#46476: Feature request: Right-aligning part of the modeline Paweł Kraśnicki
2021-02-13  8:18 ` Eli Zaretskii
2021-02-13 16:30   ` Paweł Kraśnicki [this message]
2021-02-13 16:58     ` Eli Zaretskii
2021-02-13 17:45       ` Paweł Kraśnicki
2021-02-13 18:08         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPZgK776KeZpvSX--bL-nf=cQTMLYah-BkeJpE45TmaTaBBkRA@mail.gmail.com' \
    --to=paul.krasnicki@gmail.com \
    --cc=46476@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).