[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/valign 9fc0c11 149/198: Use new function to calculate s
From: |
Stefan Monnier |
Subject: |
[elpa] externals/valign 9fc0c11 149/198: Use new function to calculate space and bar width |
Date: |
Tue, 1 Dec 2020 18:19:36 -0500 (EST) |
branch: externals/valign
commit 9fc0c113a3e1946dd338e296126f14245bd163a7
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Use new function to calculate space and bar width
* valign.el (valign--glyph-width-of): New function.
(valign--align-separator-row, valign-table-1): Use new function.
---
valign.el | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/valign.el b/valign.el
index 8b1714b..c3e4e0c 100644
--- a/valign.el
+++ b/valign.el
@@ -370,6 +370,12 @@ before event, ACTION is either 'entered or 'left."
(when (overlay-get ov 'valign)
(delete-overlay ov)))))
+(defun valign--glyph-width-of (string point)
+ "Return the pixel width of STRING with font at POINT."
+ (aref (aref (font-get-glyphs (font-at point) 0 (length string) string)
+ 0)
+ 4))
+
(cl-defmethod valign--align-separator-row
(type (style (eql single-column)) column-width-list)
"Align the separator row (|---+---|) as “|---------|”.
@@ -380,7 +386,7 @@ STYLE is 'single-column. COLUMN-WIDTH-LIST is returned from
(ignore type style)
(let* ((p (point))
(column-count (length column-width-list))
- (bar-width (valign--pixel-width-from-to (1- (point)) (point)))
+ (bar-width (valign--glyph-width-of "|" p))
;; Position of the right-most bar.
(total-width (+ (apply #'+ column-width-list)
(* bar-width (1+ column-count)))))
@@ -421,11 +427,8 @@ Assumes point is on the right bar or plus sign."
TYPE can be 'org-mode or 'markdown-mode, STYLE is 'multi-column.
COLUMN-WIDTH-LIST is returned from `valign--calculate-cell-width'."
(ignore type style)
- (let ((bar-width (valign--pixel-width-from-to (1- (point)) (point)))
- (space-width (save-excursion
- (search-forward " ")
- (valign--pixel-width-from-to
- (match-beginning 0) (match-end 0))))
+ (let ((bar-width (valign--glyph-width-of "|" (point)))
+ (space-width (valign--glyph-width-of " " (point)))
(column-start (point))
(col-idx 0)
(pos (valign--pixel-width-from-to
@@ -489,16 +492,8 @@ You need to restart valign mode for this setting to take
effect."
(defun valign-table-1 ()
"Visually align the table at point."
(valign--beginning-of-table)
- (let* ((space-width (save-excursion
- (or (search-forward " " nil t)
- (search-backward " " nil t))
- (valign--pixel-width-from-to
- (match-beginning 0) (match-end 0))))
- (bar-width (save-excursion
- (or (search-forward "|" nil t)
- (search-backward "|" nil t))
- (valign--pixel-width-from-to
- (match-beginning 0) (match-end 0))))
+ (let* ((space-width (valign--glyph-width-of " " (point)))
+ (bar-width (valign--glyph-width-of "|" (point)))
(table-beg (point))
(table-end (save-excursion (valign--end-of-table) (point)))
;; Very hacky, but..
- [elpa] externals/valign 316452b 163/198: Change fancy bar to use overlay, (continued)
- [elpa] externals/valign 316452b 163/198: Change fancy bar to use overlay, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 06d9e1a 192/198: Prepare for ELPA, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 5729733 178/198: * valign.el: Move user land code down below (re-layout)., Stefan Monnier, 2020/12/01
- [elpa] externals/valign b189102 194/198: ; * test.org: New test., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 44c747b 136/198: * valign.el (valign-table): Clean up table if error occurs., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 80cf682 121/198: Remove some internal variables, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 9daeab8 071/198: * valign.el (valign-table-quite): Really ignore errors., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 09e89aa 105/198: * valign.el (valign--at-table-p): Don’t align org blocks., Stefan Monnier, 2020/12/01
- [elpa] externals/valign e91abf2 112/198: Extract out boilerplate from valign-table, Stefan Monnier, 2020/12/01
- [elpa] externals/valign d799e31 181/198: ; * valign.el (valign--cell-content-config): Fix typo., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 9fc0c11 149/198: Use new function to calculate space and bar width,
Stefan Monnier <=
- [elpa] externals/valign d18aea8 183/198: Improve error handling, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 62766e7 184/198: Add custom group, Stefan Monnier, 2020/12/01
- [elpa] externals/valign bf68d39 171/198: Remove single-column style, Stefan Monnier, 2020/12/01
- [elpa] externals/valign ce1a53c 188/198: ; * test.org: Update., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 82be45d 198/198: Bug fix, Stefan Monnier, 2020/12/01
- [elpa] externals/valign cf3a794 099/198: Fix: cursor disappears on bars when fancy-bar is t, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 0e77a02 164/198: Add some commands that suppresses auto alignment, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 7afe578 182/198: Improve documentation, Stefan Monnier, 2020/12/01
- [elpa] externals/valign e0362c0 156/198: * valign.el (valign-region): Report to jit-lock the actual end of fontified region., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 841925f 189/198: Remove all advice when they are not needed, Stefan Monnier, 2020/12/01