emacs-devel
[Top][All Lists]
Advanced

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

Re: Proportional fonts in the mode line (one month test)


From: Yuan Fu
Subject: Re: Proportional fonts in the mode line (one month test)
Date: Wed, 24 Nov 2021 09:32:01 -0800


> On Nov 24, 2021, at 8:55 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>> The only complication is that with proportional font,
>> there is no nontrivial way to right-align some text: In fixed-width
>> environment, you just pad enough spaces, but in proportional
>> environment, you have to pad (space :align-to (- (+ right
>> right-margin) (PIXEL_WIDTH))) where PIXEL_WIDTH = pixel width of the
>> stuff on right.
> 
> Yes, I guess right-aligning text on the mode line is pretty hard (unless
> you switch to l2r on the mode line)?
> 
>> And there is no easy way to calculate the pixel width
>> of a piece of text.
> 
> There's `string-pixel-width' in Emacs 29 now, and it actually works now
> (after Martin's fix yesterdayish 😄).


Fantastic! I pulled the master and it works really well. I remember trying 
window-text-pixel-size but had some problem with it, I guess Martin fixed that 
:-D

(defun luna-mode-line-with-padding (text)
  "Return TEXT with padding on the left.
The padding pushes TEXT to the right edge of the mode-line."
  (let* ((len (string-pixel-width text))
         (padding (propertize
                   "-" 'display
                   `(space :align-to
                           (- (+ right right-margin) (,len))))))
    (concat padding text)))

Yuan


reply via email to

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