From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Add a function that returns pixel distance between points? Date: Mon, 1 Feb 2021 18:00:18 -0500 Message-ID: References: <960DAE7C-A1AF-416A-ACA5-F6674C87A2C9@gmail.com> <837dnt9400.fsf@gnu.org> <1EDD0FA5-025C-4A87-BBA1-7B8944E91A12@gmail.com> <83tuqx6sdz.fsf@gnu.org> <83ft2g7tlr.fsf@gnu.org> <51016978-4D2F-45A8-8589-F4562B6DC4A8@gmail.com> <83v9bb6429.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17879"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Feb 02 00:02:13 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l6iCy-0004Wu-M7 for ged-emacs-devel@m.gmane-mx.org; Tue, 02 Feb 2021 00:02:12 +0100 Original-Received: from localhost ([::1]:43518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6iCx-0003On-Lc for ged-emacs-devel@m.gmane-mx.org; Mon, 01 Feb 2021 18:02:11 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6iBG-0002QZ-Ac for emacs-devel@gnu.org; Mon, 01 Feb 2021 18:00:27 -0500 Original-Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:34610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l6iBD-00056H-63; Mon, 01 Feb 2021 18:00:26 -0500 Original-Received: by mail-qk1-x72e.google.com with SMTP id t63so18112722qkc.1; Mon, 01 Feb 2021 15:00:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=4YRq8SN0XJSFZ9bEchVn1j5FEPgKr86p0aXfZHtNLSM=; b=tuuwWNRj5fFogO8u9cceH/AiDe14bEyR1pEiGcsTnpnzf/h4+HrPEwavhOwrHKLp5I ExS4w4QaaDc25CWUQBQSufJ6kVi/E1xpurPepY/AW/dfxEHBYAbFnOVxS58DqxgUN4ZK QJtQ/P4pUICXlqZe2AbODrzCDu/othtT5BqCM5SJd+WIwS1/iB8+EC4SIhZVb2ym0rVD JcFo0LyhU+UFyiamknCEqO4AcWk8WNMsusDvQ11ipAhY18rRORQol1o4JQtsPv6WJB31 xZJoUj/h0Eo6Jjiec9QwRrYc7CdpHR8FaoFE3MBJBKtFYX83PrruQqIvketInSv0d5GY bt/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=4YRq8SN0XJSFZ9bEchVn1j5FEPgKr86p0aXfZHtNLSM=; b=pwhc/gC1tjkOhtpxGFGDrTBFuxlJ75eNQHGZhlbbRIzZW94BtzWweruwAFGMgPrnh3 OqIhO834PUP5WiZoXPwCrX+NVgXFkooHSVcONl2ZeXh+ztG22rq20KKf2FEAkrU7d3z2 OfLye6ndu9Ee/T+dCALCbx8eZliewaF1IPENgXIMAyyQQoIKUSspDu8IEjYiUGIahvzN RVue0TuLEkMSZHleIix8o4j7CP3/YdqV/2jcdhdd3hxd2sOFFyaY8reeyTG39Kb40jsF nkeYWb0S5S0mL0iqOO0dF08VRQ+2t4SOsNXjJ6odebZfkunf27dE2fmZg/fSAOm5OIxa pkhA== X-Gm-Message-State: AOAM531KMsM+Eh5rFlHd7R+HM9pz2o/fCzL9yA+zFjo8jd0Nr3PKU9Xm cXmhGpwYAzy5Fadq0SjyAl5LPBjCEi0s1A== X-Google-Smtp-Source: ABdhPJwEvuiNo9LTkH5RWB9gn2h4jBZaBwnJadNVAU+0kZEx3FDu6c4bAb/zIfO2mVjxCgpbk/LARw== X-Received: by 2002:a37:8e06:: with SMTP id q6mr18707888qkd.402.1612220420463; Mon, 01 Feb 2021 15:00:20 -0800 (PST) Original-Received: from ?IPv6:2601:98a:4102:3d80:fdff:45a8:11a1:9ff7? ([2601:98a:4102:3d80:fdff:45a8:11a1:9ff7]) by smtp.gmail.com with ESMTPSA id o76sm16020811qke.104.2021.02.01.15.00.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Feb 2021 15:00:19 -0800 (PST) In-Reply-To: <83v9bb6429.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.40.0.2.32) Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=casouri@gmail.com; helo=mail-qk1-x72e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:263699 Archived-At: > On Feb 1, 2021, at 1:22 PM, Eli Zaretskii wrote: >=20 >> From: Yuan Fu >> Date: Mon, 1 Feb 2021 09:16:52 -0500 >> Cc: "emacs-devel\\@gnu.org" >>=20 >>> IOW, can you show a test case where using window-text-pixel-size >>> returns incorrect results for :align-to due to line-prefix? >>=20 >> Here is an example: >>=20 >> (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))))) >>=20 >> Run it in an empty buffer and it will print the expected width and = returned width. In the snippet I=E2=80=99m trying to measure the width = of the text. >=20 > This says: >=20 > true width: 40 returned width: 64 >=20 > However, if I use :align-to with the value of 64 pixels, the stretch > of whitespace ends where I'd expect it to end: aligned to right after > "woome". >=20 > So I still don't understand the problem you are facing. Which is why > I asked for an example code which uses :align-to in a way similar to > what you intend to do in your table rendering code, because I wanted > to see a situation where :align-to produces incorrect results when > using the return value of window-text-pixel-size in the presence of > line-prefix. But the example you show doesn't use :align-to. Ah, I see. Here is a demo that should show that. (let (width-1 width-2 (start (point))) (insert (propertize "| loooooong |\n| world |" 'line-prefix " ")) (goto-char start) (search-forward "|") (let ((start (point))) (search-forward "|") (setq width-1 (car (window-text-pixel-size nil (1+ start) (- (point) 2))))) (search-forward "|") (let ((start (point))) (search-forward "|") (setq width-2 (car (window-text-pixel-size nil (1+ start) (- (point) 2))))) (let ((col-width (+ 2 (max width-1 width-2))) cell-start) (goto-char start) (search-forward "|") (setq cell-start (car (window-text-pixel-size nil (line-beginning-position) (point)))) (search-forward "|") (put-text-property (- (point) 2) (1- (point)) 'display `(space :align-to (,(+ cell-start col-width)))) (search-forward "|") (setq cell-start (car (window-text-pixel-size nil (line-beginning-position) (point)))) (search-forward "|") (put-text-property (- (point) 2) (1- (point)) 'display `(space :align-to (,(+ cell-start col-width)))))) This code inserts a mini table | looooong | | world | And tries to aligns it to | looooong | | world | You will notice there are extra white space on the right of the cells, = and the table actually looks like this: | loooooong | | world | That=E2=80=99s because window-text-pixel-size returned a width that=E2=80=99= s larger than the true with of the cells. If you enlarge the = line-prefix, the extra space grows. Yuan=