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: Sun, 31 Jan 2021 14:42:27 -0500 Message-ID: <1378BC8F-C997-4BC6-A414-A4086A3E3AE9@gmail.com> References: <960DAE7C-A1AF-416A-ACA5-F6674C87A2C9@gmail.com> <837dnt9400.fsf@gnu.org> <1EDD0FA5-025C-4A87-BBA1-7B8944E91A12@gmail.com> <87mtwp4pru.fsf@localhost> 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="19628"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: Ihor Radchenko Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jan 31 20:44:23 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 1l6Idz-00051X-OV for ged-emacs-devel@m.gmane-mx.org; Sun, 31 Jan 2021 20:44:23 +0100 Original-Received: from localhost ([::1]:57594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6Idy-0007IJ-Oc for ged-emacs-devel@m.gmane-mx.org; Sun, 31 Jan 2021 14:44:22 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6IcF-0006Fq-PY for emacs-devel@gnu.org; Sun, 31 Jan 2021 14:42:35 -0500 Original-Received: from mail-qv1-xf2b.google.com ([2607:f8b0:4864:20::f2b]:35322) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l6IcD-0005C4-DK; Sun, 31 Jan 2021 14:42:35 -0500 Original-Received: by mail-qv1-xf2b.google.com with SMTP id l14so7192651qvp.2; Sun, 31 Jan 2021 11:42:29 -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=joDlN5noYc2cFHef6Wi1ND1Da1RJFZyNtiJFPhVto80=; b=qrp5zwXxgZ5mMgSSF7mF1xnuINs5xz8EsTMhIG3CKXD3EjPRdyjMwnVy9T4CnfHMKG 1Jo/iYQRY1io806yDx7MjFcOlw5PL0zJENFiN1gO4m82n+sDNoAKqcEd/MMSz3OAx0Fn 47i9Zmri8gjgy1hT8tA45XBrlqmpEMJmzTVCxC902g5DdzraMjLk010f+2kte5/FKAi1 zKsC0X0vMLc6V/IptfFrv0nxLiCdtfQJ9kMH+r0ZpnVnQx6oe77jtuYf3pMsDUKRPB2h s/cpGk2Td6DVYodeGgz4j6qX+rxHGzjw5LQD2Jw57AIZWX5UXLjQWP0ixMSSjQ7YhsSv s2OA== 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=joDlN5noYc2cFHef6Wi1ND1Da1RJFZyNtiJFPhVto80=; b=oIQ6sH72rTHdFTCMPs2mviEXQFOCvyFx/5pXSHrBgznzl7lMY6mpkll4OnRhHyhJx2 DBFYS5gFG+POaZt/4cpEAGi9My6iPVk+2vHaKqO9wpbJiF/u2kuMa+P/kAaH4vYlmrpa mzpt50R84TDIq7SsuAc6oP5pSKsfYMdw+kBpos9bIQim38zt+Hyd7lK+d7bW6nhVFMZ9 DfOacb+NhJD58j9bgyCC+HLA6kTIkbN1xdgXFLcj9jviYQbbuMDpjuCnO1XPDvEehgQQ saJ+/rOfL3wSmcF5OjEl8OJE+vz0xVrOzeQD4RUpqImall5c4Mnop5vXDTdyizQUkxfO nyMw== X-Gm-Message-State: AOAM532aEFBkrLS0rwBJmpzq2xpkT1n3XUx3fAFtQJlQQXHoHi0zg8CG CEvy6blHDdutR2nF3eYPMeM= X-Google-Smtp-Source: ABdhPJxvwTbyGDYjZlPlMLm9Ow2Kqv3kIKCv73IgRYnyQIzfgaGmcdUvhgY5ftL2+bzp/XbiKL51vw== X-Received: by 2002:a05:6214:588:: with SMTP id bx8mr12288935qvb.47.1612122148623; Sun, 31 Jan 2021 11:42:28 -0800 (PST) Original-Received: from ?IPv6:2601:98a:4200:9210:d580:9ad5:a27e:26fc? ([2601:98a:4200:9210:d580:9ad5:a27e:26fc]) by smtp.gmail.com with ESMTPSA id y26sm12424152qth.53.2021.01.31.11.42.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jan 2021 11:42:28 -0800 (PST) In-Reply-To: <87mtwp4pru.fsf@localhost> X-Mailer: Apple Mail (2.3654.40.0.2.32) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2b; envelope-from=casouri@gmail.com; helo=mail-qv1-xf2b.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:263665 Archived-At: > On Jan 31, 2021, at 12:52 AM, Ihor Radchenko = wrote: >=20 > Yuan Fu writes: >=20 >> When the text is displayed in variable-pitch font, the bars aren=E2=80=99= t aligned. I=E2=80=99m using display property (space :align-to) to align = those bars. To know with pixel position to align to, I need to calculate = each column=E2=80=99s pixel width, and met the difficulties mentioned = earlier. >=20 > You can do it in temp buffer with line numbers and wrap prefix = disabled. > Something like >=20 > (defun string-display-pixel-width (string &optional mode) > "Calculate pixel width of STRING. > Optional MODE specifies major mode used for display." > (with-temp-buffer > (with-silent-modifications > (setf (buffer-string) string)) > (when (fboundp mode) > (funcall mode) > (font-lock-fontify-buffer)) > (let (wrap-prefix display-line-numbers) > (if (get-buffer-window (current-buffer)) > (car (window-text-pixel-size nil (line-beginning-position) = (point))) > (set-window-buffer nil (current-buffer)) > (car (window-text-pixel-size nil (line-beginning-position) = (point))))))) >=20 > Best, > Ihor Thanks, I=E2=80=99ll try that and see if it is fast enough for my use = :-) Yuan=