emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/valign 84dc2ce 153/198: Fix misalignment


From: Stefan Monnier
Subject: [elpa] externals/valign 84dc2ce 153/198: Fix misalignment
Date: Tue, 1 Dec 2020 18:19:38 -0500 (EST)

branch: externals/valign
commit 84dc2ce537abdb24249e46b8f78357cd42d972b6
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Fix misalignment
    
    * valign.el (valign--pixel-width-from-to): Calculate line-prefix
    correctly.
---
 valign.el | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/valign.el b/valign.el
index 4e5774b..8831062 100644
--- a/valign.el
+++ b/valign.el
@@ -159,12 +159,24 @@ properties must be cleaned before using this.
 
 If WITH-PREFIX is non-nil, don’t subtract the width of line
 prefix."
-  (let ((window (get-buffer-window)))
+  (let* ((window (get-buffer-window))
+         ;; This computes the prefix width.  This trick doesn’t seem
+         ;; work if the point is at the beginning of a line, so we use
+         ;; TO instead of FROM.
+         ;;
+         ;; Why all this fuss: Org puts some display property on white
+         ;; spaces in a cell: (space :relative-width 1).  And that
+         ;; messes up the calculation of prefix: now it returns the
+         ;; width of a space instead of 0 when there is no line
+         ;; prefix.  So we move the test point around until it doesn’t
+         ;; sit on a character with display properties.
+         (line-prefix
+          (let ((pos to))
+            (while (get-char-property pos 'display)
+              (cl-decf pos))
+            (car (window-text-pixel-size window pos pos)))))
     (- (car (window-text-pixel-size window from to))
-       ;; This computes the prefix width.  This trick doesn’t seem work
-       ;; if the point is at the beginning of a line.
-       (if with-prefix 0 (car (window-text-pixel-size window to to)))
-       ;; FIXME: Workaround.
+       (if with-prefix 0 line-prefix)
        (if (bound-and-true-p display-line-numbers-mode)
            (line-number-display-width 'pixel)
          0))))



reply via email to

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