emacs-devel
[Top][All Lists]
Advanced

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

Re: Add a function that returns pixel distance between points?


From: Yuan Fu
Subject: Re: Add a function that returns pixel distance between points?
Date: Mon, 1 Feb 2021 09:16:52 -0500


> On Jan 31, 2021, at 3:13 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sun, 31 Jan 2021 14:41:52 -0500
>> Cc: emacs-devel@gnu.org
>> 
>>> Finally, I'm not sure why the behavior of window-text-pixel-size is a
>>> problem: if you use :align-to with pixel units (as opposed to column
>>> units), then you should _want_ it to account for stuff like
>>> line-prefix, no?
>> 
>> Yes, value given to :align-to needs to account for line-prefix. But when I 
>> want to calculate the pixel width of a column, I don’t want to include the 
>> prefix: that makes the returned value larger than the actually width of the 
>> column (because the line-prefix width is added to it).
> 
> But the pixel coordinate to which you need to align also needs to be
> increased due to line-prefix, doesn't it?
> 
> IOW, can you show a test case where using window-text-pixel-size
> returns incorrect results for :align-to due to line-prefix?

Here is an example:

(let ((width))
  (insert "woome")
  (setq width (car (window-text-pixel-size
                    nil (line-beginning-position) (point))))
  (put-text-property (line-beginning-position) (point)
                     'line-prefix "   ")
  (message "true width: %d returned width: %d"
           width (car (window-text-pixel-size
                       nil (line-beginning-position) (point)))))

Run it in an empty buffer and it will print the expected width and returned 
width. In the snippet I’m trying to measure the width of the text.

Yuan


reply via email to

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