[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/valign acdb551 01/15: Really really fix org-indent and
From: |
Stefan Monnier |
Subject: |
[elpa] externals/valign acdb551 01/15: Really really fix org-indent and line-number problem |
Date: |
Tue, 16 Mar 2021 00:01:10 -0400 (EDT) |
branch: externals/valign
commit acdb5518ce21ddcf8dadb4728076cd4a3b6babf9
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Really really fix org-indent and line-number problem
* valign.el (valign--pixel-width-from-to): Remove WITH-PREFIX
parameter, remove hacks and use simple subtraction to get true width.
(valign--pixel-x): New function.
(valign--align-separator-row, valign-table-1, valign--table-2): Use
new function.
---
valign.el | 46 ++++++++++++++--------------------------------
1 file changed, 14 insertions(+), 32 deletions(-)
diff --git a/valign.el b/valign.el
index 3228e57..bd118ae 100644
--- a/valign.el
+++ b/valign.el
@@ -303,41 +303,26 @@ width. BAR-CHAR is the bar character (“|”)."
;; has some limitations, including not working right with face remapping.
;; With this function we can avoid some of them. However we still can’t
;; get the true tab width, see comment in ‘valgn--tab-width’ for more.
-(defun valign--pixel-width-from-to (from to &optional with-prefix)
+(defun valign--pixel-width-from-to (from to)
"Return the width of the glyphs from FROM (inclusive) to TO (exclusive).
The buffer has to be in a live window. FROM has to be less than
TO and they should be on the same line. Valign display
-properties must be cleaned before using this.
-
-If WITH-PREFIX is non-nil, don’t subtract the width of line
-prefix."
+properties must be cleaned before using this."
;; 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)))))
+ (- (car (window-text-pixel-size
+ nil (line-beginning-position) to))
+ (car (window-text-pixel-size
+ nil (line-beginning-position) from)))))
+
+(defun valign--pixel-x (point)
+ "Return the x pixel position of POINT."
+ (- (car (window-text-pixel-size nil (line-beginning-position) point))
+ (line-number-display-width 'pixel)))
(defun valign--separator-p ()
"If the current cell is actually a separator.
@@ -668,8 +653,7 @@ COLUMN-WIDTH-LIST is returned by
`valign--calculate-cell-width'."
(space-width (valign--glyph-width-of " " (point)))
(column-start (point))
(col-idx 0)
- (pos (valign--pixel-width-from-to
- (line-beginning-position) (point) t)))
+ (pos (valign--pixel-x (point))))
;; Render the first left bar.
(valign--maybe-render-bar (1- (point)))
;; Add overlay in each column.
@@ -784,8 +768,7 @@ at the end of the table."
;; Not separator row, align each cell. ‘column-start’ is the
;; pixel position of the current point, i.e., after the left
;; bar.
- (setq column-start (valign--pixel-width-from-to
- (line-beginning-position) (point) t))
+ (setq column-start (valign--pixel-x (point)))
(valign--do-column column-idx "|"
(save-excursion
@@ -914,8 +897,7 @@ Assumes point is at (2).
(t '(4 5 6)))
charset char-width)
;; Render normal line.
- (setq column-start (valign--pixel-width-from-to
- (line-beginning-position) (point) t)
+ (setq column-start (valign--pixel-x (point))
column-idx 0)
(while (search-forward (valign-box-char 'v charset)
(line-end-position) t)
- [elpa] externals/valign updated (223407d -> 2035143), Stefan Monnier, 2021/03/16
- [elpa] externals/valign b000cca 02/15: Fix alignment for table.el tables, Stefan Monnier, 2021/03/16
- [elpa] externals/valign 6b0345e 03/15: Make at-table-p testing stricter, Stefan Monnier, 2021/03/16
- [elpa] externals/valign 49209b4 05/15: * README-CN.org: Touch up on phrasing., Stefan Monnier, 2021/03/16
- [elpa] externals/valign 2035143 15/15: * README-CN.org (自定义): Add descriptions for some variables., Stefan Monnier, 2021/03/16
- [elpa] externals/valign acdb551 01/15: Really really fix org-indent and line-number problem,
Stefan Monnier <=
- [elpa] externals/valign b6a0dcd 04/15: Add Chinese README, Stefan Monnier, 2021/03/16
- [elpa] externals/valign e8a5ce1 07/15: Remove note about org-indent-mode + line-numbers-mode, Stefan Monnier, 2021/03/16
- [elpa] externals/valign f5db1ef 06/15: ; * README.org: Change link to Chinese README., Stefan Monnier, 2021/03/16
- [elpa] externals/valign db5145a 14/15: * README.org (Customization): Add description for some variables., Stefan Monnier, 2021/03/16
- [elpa] externals/valign ccbcc1c 10/15: Fix alignment for Unicode tables, Stefan Monnier, 2021/03/16
- [elpa] externals/valign 16ff947 08/15: Patch an outline bug., Stefan Monnier, 2021/03/16
- [elpa] externals/valign bcfb414 13/15: Improve parse error report, Stefan Monnier, 2021/03/16
- [elpa] externals/valign 3fcb173 12/15: Fix 'valign--separator-line-p', Stefan Monnier, 2021/03/16
- [elpa] externals/valign ad8419e 11/15: ; * test.org: Add a test for Unicode tables., Stefan Monnier, 2021/03/16
- [elpa] externals/valign 745889d 09/15: * valign.el (valign--at-table-p): Don't pass "" to 'char-to-string'., Stefan Monnier, 2021/03/16