[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/valign 4c514ce 169/198: Use text properties for table.e
From: |
Stefan Monnier |
Subject: |
[elpa] externals/valign 4c514ce 169/198: Use text properties for table.el tables |
Date: |
Tue, 1 Dec 2020 18:19:41 -0500 (EST) |
branch: externals/valign
commit 4c514ce526cf794a9f97da7596414f7b58593d92
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Use text properties for table.el tables
* valign.el (valign--put-text-prop): New function.
(valign--clean-text-property): Remove text properties.
(valign--table-2, valign--align-separator-row-full): Change
'valign--put-overlay' to 'valign--put-text-prop'.
---
valign.el | 44 ++++++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/valign.el b/valign.el
index 648a6c1..b327ccd 100644
--- a/valign.el
+++ b/valign.el
@@ -434,6 +434,12 @@ PROPS contains properties and values."
(while props
(overlay-put ov (pop props) (pop props)))))
+(defun valign--put-text-prop (beg end &rest props)
+ "Put text property between BEG and END.
+PROPS contains properties and values."
+ (add-text-properties beg end props)
+ (put-text-property beg end 'valign t))
+
(defsubst valign--space (xpos)
"Return a display property that aligns to XPOS."
`(space :align-to (,xpos)))
@@ -481,10 +487,24 @@ before event, ACTION is either 'entered or 'left."
"Clean up the display text property between BEG and END."
(with-silent-modifications
(put-text-property beg end 'cursor-sensor-functions nil))
+ ;; Remove overlays.
(let ((ov-list (overlays-in beg end)))
(dolist (ov ov-list)
(when (overlay-get ov 'valign)
- (delete-overlay ov)))))
+ (delete-overlay ov))))
+ ;; Remove text properties.
+ (let ((p beg) tab-end last-p)
+ (while (not (eq p last-p))
+ (setq last-p p
+ p (next-single-char-property-change p 'valign nil end))
+ (when (plist-get (text-properties-at p) 'valign)
+ ;; We are at the beginning of a tab, now find the end.
+ (setq tab-end (next-single-char-property-change
+ p 'valign nil end))
+ ;; Remove text property.
+ (with-silent-modifications
+ (put-text-property p tab-end 'display nil)
+ (put-text-property p tab-end 'valign nil))))))
(defun valign--glyph-width-of (string point)
"Return the pixel width of STRING with font at POINT.
@@ -719,6 +739,9 @@ If FORCE non-nil, force align."
(defun valign--table-2 ()
"Visually align the table.el table at point."
+ ;; Instead of overlays, we use text proeprties in this function.
+ ;; Too many overlays degrades performance, and we add a whole bunch
+ ;; of them in this function, so better use text properties.
(valign--beginning-of-table)
(let* ((charset (valign--guess-charset))
(ucharset (alist-get 'unicode valign-box-charset-alist))
@@ -760,15 +783,16 @@ If FORCE non-nil, force align."
column-idx 0)
(while (search-forward (valign-box-char 'v charset)
(line-end-position) t)
- (valign--put-overlay (1- (point)) (point)
- 'display (valign-box-char 'v ucharset))
+ (valign--put-text-prop
+ (1- (point)) (point)
+ 'display (valign-box-char 'v ucharset))
(unless (looking-at "\n")
(pcase-let ((col-width (nth column-idx column-width-list))
(`(,cell-beg ,content-beg
,content-end ,cell-end)
(valign--cell-content-config
(valign-box-char 'v charset))))
- (valign--put-overlay
+ (valign--put-text-prop
content-end cell-end 'display
(valign--space (+ column-start col-width char-width)))
(cl-incf column-idx)
@@ -813,22 +837,22 @@ Assumes point before the first character."
(uh (valign-box-char 'h unicode-charset))
(eol (line-end-position))
(col-idx 0))
- (valign--put-overlay (point) (1+ (point)) 'display uleft)
+ (valign--put-text-prop (point) (1+ (point)) 'display uleft)
(goto-char (1+ (point)))
(while (re-search-forward (rx-to-string `(or ,middle ,right)) eol t)
;; Render joints.
(if (looking-at "\n")
- (valign--put-overlay (1- (point)) (point) 'display uright)
- (valign--put-overlay (1- (point)) (point) 'display umiddle))
+ (valign--put-text-prop (1- (point)) (point) 'display uright)
+ (valign--put-text-prop (1- (point)) (point) 'display umiddle))
;; Render horizontal lines.
(save-excursion
(let ((p (1- (point)))
(width (nth col-idx column-width-list)))
(goto-char p)
(skip-chars-backward (valign-box-char 'h charset))
- (valign--put-overlay (point) p 'display
- (make-string (/ width char-width)
- (aref uh 0)))))
+ (valign--put-text-prop (point) p 'display
+ (make-string (/ width char-width)
+ (aref uh 0)))))
(cl-incf col-idx))))
(defun valign--guess-charset ()
- [elpa] externals/valign 6e01d5b 172/198: Update README, (continued)
- [elpa] externals/valign 6e01d5b 172/198: Update README, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 7c67cf6 186/198: Update documentation, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 762b115 144/198: * valign.el (valign--separator-row-add-overlay): Change 'valign--glyph-width-at-point' to 'valign--pixel-width-from-to'., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 1858260 146/198: * valign.el: Bump version to 2.2.0, Stefan Monnier, 2020/12/01
- [elpa] externals/valign ac5bdad 154/198: Fix cell-width calculation, Stefan Monnier, 2020/12/01
- [elpa] externals/valign e94782a 180/198: Remove org-agenda-finalize-hook, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 5e70d9b 196/198: Fix beginning- and end-of-table functions, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 44f065d 131/198: * valign.el: Bump version to 2.1.0, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 693f086 135/198: * valign.el (valign-mode): Change tab-advice to :after., Stefan Monnier, 2020/12/01
- [elpa] externals/valign eaa5cb1 104/198: Enable autoload mechanism, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 4c514ce 169/198: Use text properties for table.el tables,
Stefan Monnier <=
- [elpa] externals/valign 8e598bf 170/198: ; * test.org: Add a test table., Stefan Monnier, 2020/12/01
- [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