From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: Add a function that returns pixel distance between points? Date: Sun, 31 Jan 2021 13:52:05 +0800 Message-ID: <87mtwp4pru.fsf@localhost> References: <960DAE7C-A1AF-416A-ACA5-F6674C87A2C9@gmail.com> <837dnt9400.fsf@gnu.org> <1EDD0FA5-025C-4A87-BBA1-7B8944E91A12@gmail.com> Mime-Version: 1.0 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="17633"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Yuan Fu , Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jan 31 06:49:39 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 1l65cB-0004Uf-F4 for ged-emacs-devel@m.gmane-mx.org; Sun, 31 Jan 2021 06:49:39 +0100 Original-Received: from localhost ([::1]:35124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l65cA-0004B9-Ev for ged-emacs-devel@m.gmane-mx.org; Sun, 31 Jan 2021 00:49:38 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l65ad-0003hF-25 for emacs-devel@gnu.org; Sun, 31 Jan 2021 00:48:03 -0500 Original-Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:34130) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l65ab-0005CF-CV; Sun, 31 Jan 2021 00:48:02 -0500 Original-Received: by mail-pf1-x431.google.com with SMTP id m6so9342634pfk.1; Sat, 30 Jan 2021 21:48:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-transfer-encoding; bh=gqFE709qajtmGHOOsOUt1g5eaBZjFTbuctHh1K0nByk=; b=TPvlht5RZdttLVwEtQ8npFjMl22y4Wik4mNPMdomN39Uy8QPdP0iiMelW1RZQ/hJAO zMk1E15HaHdEoWmMYNnYwwouV/JvRAJVJdLXN3scvgGaFFg2pYac00NZmjQQFKeHh/dy +seb1cCQ77NNf6BD9MnWqd7r8E1JVM5n5YbsgQuFKbAQwsCQJ5FPXIrIcxbSdztfu0W5 XPoZYqQYl9Avc5KKz9bV9WBtVgrz+v6fvQ4pCePscjMhFU6d705NlvIxghr8c7uBsbLb cjO/tP+psCw6uCUjEhy6nZa2e4CZ1YW2zsa6jsU+3zlCWU1WNCzZ8HIBFpSy0qeZbKvL 8zEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=gqFE709qajtmGHOOsOUt1g5eaBZjFTbuctHh1K0nByk=; b=G0PQxCwCNSiDHr2bZjz7+nm83Mca1xgNYNimereNwkEvBMRONXTa1fZ+EIw1S6clOT croFVfl8ej8eV7re80z3bhCcP8RF+MDom059k0V88B6FIOQqoXpYVj8AE0ZoEWhDbUPx gXUWDoZ/PtObAU7SSmdJ26/wFRCw/IPpvVsSchWQQlZeZ9ZVCmp98y/OVyeTS74jhhfb w1Ye6YXi+jOJNKI1mui+SOK54aZNhi71nALlkGtcxUfsKYogLbzldxewR6REFOQjrbrQ fLTGsgl7M/QGiyQIPLWEj2xSXAYN9Z85QBDxJ/2RSzvFvgdsi+uU0SaLB4XCNLeCiapf kvrw== X-Gm-Message-State: AOAM532JbLRSyUoRAAgBX2dd7uF/++UkqNZFFBuab07ovjuGiceFZF8j atkzRvukDyOb24keh3z0NhE= X-Google-Smtp-Source: ABdhPJwb96c4Y0nE/qkaK9JmRqlBoUh4yQgpUNRsRjfq7jJT5ABPhn4zZOYslgNZpR/tQ5ou/YqBqQ== X-Received: by 2002:a62:1ad5:0:b029:1c5:111b:91cf with SMTP id a204-20020a621ad50000b02901c5111b91cfmr10818102pfa.13.1612072079654; Sat, 30 Jan 2021 21:47:59 -0800 (PST) Original-Received: from localhost ([104.250.131.79]) by smtp.gmail.com with ESMTPSA id 6sm12969857pfz.34.2021.01.30.21.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jan 2021 21:47:58 -0800 (PST) In-Reply-To: <1EDD0FA5-025C-4A87-BBA1-7B8944E91A12@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=yantar92@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, 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:263652 Archived-At: Yuan Fu writes: > 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 th= ose 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. You can do it in temp buffer with line numbers and wrap prefix disabled. Something like (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))= ))))) Best, Ihor