emacs-devel
[Top][All Lists]
Advanced

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

Re: Horizontal centering in the display engine


From: Eli Zaretskii
Subject: Re: Horizontal centering in the display engine
Date: Thu, 15 Apr 2021 10:04:51 +0300

> From: "Paul W. Rankin" <pwr@bydasein.com>
> Date: Thu, 15 Apr 2021 15:13:43 +1000
> Cc: Eli Zaretskii <eliz@gnu.org>,
>  emacs-devel@gnu.org
> 
> (defun center-align-line ()
>   (let (line-width align-col)
>     (setq line-width (- (line-end-position)
>                         (line-beginning-position)))

This calculation of line-width is, of course, only valid when there's
a single face used by the line's characters.

Using window-text-pixel-size will produce more accurate results, but
OP's main problem is not how to compute the line's width, it is how to
make the alignment adjust itself automatically to any changes in the
line's text and in the window's width.



reply via email to

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