[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/valign 1d2ecd2 09/11: * valign.el (valign--pixel-width-
From: |
Stefan Monnier |
Subject: |
[elpa] externals/valign 1d2ecd2 09/11: * valign.el (valign--pixel-width-from-to): Return 0 if FROM = TO. |
Date: |
Thu, 28 Jan 2021 00:10:25 -0500 (EST) |
branch: externals/valign
commit 1d2ecd2afdb77021eaffc213d9fbbc6d9c38ed82
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
* valign.el (valign--pixel-width-from-to): Return 0 if FROM = TO.
---
valign.el | 48 +++++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/valign.el b/valign.el
index 9b83371..6555a6c 100644
--- a/valign.el
+++ b/valign.el
@@ -311,27 +311,33 @@ 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))
- ;; 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))
- (if with-prefix 0 line-prefix)
- (if (bound-and-true-p display-line-numbers-mode)
- (line-number-display-width 'pixel)
- 0))))
+ ;; HACK: You would expect (window-text-pixel-size WINDOW FROM TO) to
+ ;; return line-number-display-width when FROM equals to TO, but no,
+ ;; it returns 0. Then if we still subtract line number width, we
+ ;; get a negative number. So if FROM = TO, we simply return 0.
+ (if (eq from to)
+ 0
+ (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: like (space :relative-width 1).
+ ;; That messes up the calculation of the 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))
+ (if with-prefix 0 line-prefix)
+ (if (bound-and-true-p display-line-numbers-mode)
+ (line-number-display-width 'pixel)
+ 0)))))
(defun valign--separator-p ()
"If the current cell is actually a separator.
- [elpa] externals/valign updated (3792225 -> 223407d), Stefan Monnier, 2021/01/28
- [elpa] externals/valign 4742db5 01/11: * valign.el (valign--cell-content-config): Add position info to error report., Stefan Monnier, 2021/01/28
- [elpa] externals/valign 9a9e778 02/11: * valign.el: Fix copyright line., Stefan Monnier, 2021/01/28
- [elpa] externals/valign be86359 10/11: * valign.el: Bump to 3.1.0., Stefan Monnier, 2021/01/28
- [elpa] externals/valign a880928 08/11: ; * README.org: Fix typo., Stefan Monnier, 2021/01/28
- [elpa] externals/valign 1c2c3b0 05/11: Add variable 'valign-signal-parse-error', Stefan Monnier, 2021/01/28
- [elpa] externals/valign 223407d 11/11: Merge remote-tracking branch 'elpa/externals/valign', Stefan Monnier, 2021/01/28
- [elpa] externals/valign 09f87c1 07/11: ; * test.org: New tests, Stefan Monnier, 2021/01/28
- [elpa] externals/valign 1d2ecd2 09/11: * valign.el (valign--pixel-width-from-to): Return 0 if FROM = TO.,
Stefan Monnier <=
- [elpa] externals/valign a0ff453 03/11: * README.org (Install with quelpa): Update Install instruction., Stefan Monnier, 2021/01/28
- [elpa] externals/valign 0fe9416 06/11: Add valign-max-table-size, Stefan Monnier, 2021/01/28
- [elpa] externals/valign 740d507 04/11: * valign.el (valign--at-table-p): Exclude +<space> pattern., Stefan Monnier, 2021/01/28