unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Add a function that returns pixel distance between points?
Date: Sun, 31 Jan 2021 14:41:52 -0500	[thread overview]
Message-ID: <A877492F-9D69-4E68-8EA6-2DDFC394F093@gmail.com> (raw)
In-Reply-To: <83tuqx6sdz.fsf@gnu.org>



> On Jan 31, 2021, at 10:24 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sun, 31 Jan 2021 00:17:58 -0500
>> Cc: emacs-devel@gnu.org
>> 
>> I want to align text-based tables by pixel size, as in:
>> 
>> | header | header | header |
>> | 1      | 1      | 8      |
>> | 2      | 6      | 3      |
>> 
>> When the text is displayed in variable-pitch font, the bars aren’t aligned. I’m using display property (space :align-to) to align those bars. To know with pixel position to align to, I need to calculate each column’s pixel width, and met the difficulties mentioned earlier.
> 
> So the columns in your case have width that changes dynamically?  That
> is, if I type enough characters into a cell that the current width is
> no longer sufficient, the width of the cell's column will be
> increased?
> 

Yes, naturally you want to adapt the alignment while the user is editing.

> Also, I don't think I understand why it is a problem for you that
> posn-at-point requires point to be visible -- are you generating the
> table in a buffer that is not displayed, or in a portion of a buffer
> that is not visible?  Or is there some other reason why you have
> problems with this requirement of posn-at-point?

Using posn-at-point would be too complicated: Table might by partially visible, I need to make sure the alignment function is immediately called when an unaligned table is displayed in the window, etc. Comparing to that, adding my alignment function into jit-lock hooks is much simpler and cleaner.

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

Yuan




  reply	other threads:[~2021-01-31 19:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-30 20:47 Add a function that returns pixel distance between points? Yuan Fu
2021-01-31  3:31 ` Eli Zaretskii
2021-01-31  5:17   ` Yuan Fu
2021-01-31  5:52     ` Ihor Radchenko
2021-01-31 19:42       ` Yuan Fu
2021-01-31 15:24     ` Eli Zaretskii
2021-01-31 19:41       ` Yuan Fu [this message]
2021-01-31 20:13         ` Eli Zaretskii
2021-02-01 14:16           ` Yuan Fu
2021-02-01 18:22             ` Eli Zaretskii
2021-02-01 23:00               ` Yuan Fu
2021-02-02 16:29                 ` Eli Zaretskii
2021-02-03 15:04                   ` Eli Zaretskii
2021-02-03 16:48                     ` Yuan Fu
2021-02-04 16:02                       ` Eli Zaretskii
2021-02-05 10:15                         ` martin rudalics
2021-02-05 12:25                           ` Eli Zaretskii
2021-02-05 15:48                             ` martin rudalics

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=A877492F-9D69-4E68-8EA6-2DDFC394F093@gmail.com \
    --to=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@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).