help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: right aligning a string, using display (space :align-to


From: Eli Zaretskii
Subject: Re: right aligning a string, using display (space :align-to
Date: Fri, 20 Oct 2023 09:41:31 +0300

> Date: Thu, 19 Oct 2023 20:05:05 +0200
> From: martianhiatus@riseup.net
> 
> what i'm aiming to do is create a space that is as wide as screen width minus 
> the length of my string.
> 
> currently, what works (but doesn't scale) is this (where str is the string to 
> align):
> 
> (concat
>   (propertize " "
>               'display
>               `(space :align-to (- right
>                                    ,(+ (length stats) 7))))
> str)
> 
> this returns a display prop of (space :align-to (- right 18)).
> 
> whereas working with the pixel-width of str does not work at all:
> 
> (concat
>   (propertize " "
>               'display
>               `(space :align-to (- right
>                                    ,(string-pixel-width stats))))
>   str)
> 
> this returns a display prop of: (space :align-to (- right 142))
> 
> 
> why does using length in a piexel-width expression work at all, and why 
> doesn't pixel-width? i've also tried using right-margin and ,(car 
> (window-text-pixel-size)) in place of right, and have tried various 
> alternatives in terms of (quasi-)quoting.

As the manual says, by default the :align-to expressions are
interpreted as being in character units, i.e. in units of columns, not
pixels.  You need to use (NUMBER) to have NUMBER interpreted as
pixels.  So your second snippet should be changed to

  (concat
    (propertize " "
                'display
                `(space :align-to (- right
                                     ,(list (string-pixel-width stats)))))
    str)

and then it will work.



reply via email to

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