[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/valign 53be5d7 089/198: Add fancy bar
From: |
Stefan Monnier |
Subject: |
[elpa] externals/valign 53be5d7 089/198: Add fancy bar |
Date: |
Tue, 1 Dec 2020 18:19:23 -0500 (EST) |
branch: externals/valign
commit 53be5d759e56e545d2830f7cf43093555d3bbde6
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Add fancy bar
Basically a full-height line.
* valign.el (valign--maybe-render-bar, valign--render-bar): New
functions.
(valign--align-separator-row, valign--separator-row-add-overlay): Add
fancy bar for each separator cell.
(valign-fancy-bar): New custom option.
(valign-table): Add fancy bar for each cell.
(valign-reset-buffer): Add code to remove fancy bar property.
---
valign.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 48 insertions(+), 7 deletions(-)
diff --git a/valign.el b/valign.el
index 65f2a32..4c56205 100644
--- a/valign.el
+++ b/valign.el
@@ -327,6 +327,23 @@ white space stretching to XPOS, a pixel x position."
beg end 'display
`(space :align-to (,xpos)))))
+(defvar valign-fancy-bar)
+(defun valign--maybe-render-bar (point)
+ "Make the character at POINT a full hegiht bar.
+But only if `valign-fancy-bar' is non-nil."
+ (when valign-fancy-bar
+ (valign--render-bar point)))
+
+(defun valign--render-bar (point)
+ "Make the character at POINT a full hegiht bar."
+ (with-silent-modifications
+ (put-text-property
+ point (1+ point) 'display '(space :width (1)))
+ (put-text-property
+ point (1+ point) 'face '(:inverse-video t))
+ (put-text-property
+ point (1+ point) 'font-lock-face '(:inverse-video t))))
+
(defun valign--clean-text-property (beg end)
"Clean up the display text property between BEG and END."
;; TODO ‘text-property-search-forward’ is Emacs 27 feature.
@@ -372,7 +389,9 @@ right bar’s position."
(total-width (car (last pos-list))))
(when (search-forward "|" nil t)
(with-silent-modifications
- (valign--put-text-property p (1- (point)) total-width))
+ (valign--put-text-property p (1- (point)) total-width)
+ ;; Render the right bar.
+ (valign--maybe-render-bar (1- (point))))
;; Why do we have to add an overlay? Because text property
;; doens’t work. First, font-lock overwrites what ever face
;; property you add; second, even if you are sneaky and added a
@@ -391,9 +410,12 @@ Cell ranges from BEG to END, the pixel position RIGHT-POS
marks
the position for the right bar (“|”).
Assumes point is on the right bar or plus sign."
;; Make “+” look like “|”
- (when (eq (char-after end) ?+)
- (with-silent-modifications
- (put-text-property end (1+ end) 'display "|")))
+ (if valign-fancy-bar
+ ;; Render the right bar.
+ (valign--render-bar end)
+ (when (eq (char-after end) ?+)
+ (with-silent-modifications
+ (put-text-property end (1+ end) 'display "|"))))
;; Markdown row
(when (eq (char-after beg) ?:)
(setq beg (1+ beg)))
@@ -429,7 +451,7 @@ POS-LIST is a list of positions for each column’s right
bar."
(<= col-idx max-col)
(re-search-forward "[+|]" (line-end-position) t))
;; Separator rows that has empty cells (|----| |----|)
- ;; is also possible.
+ ;; is also possible. `seperator-p' is t only for |----|.
(if seperator-p
(valign--separator-row-add-overlay
p (1- (point)) (nth col-idx pos-list))
@@ -463,6 +485,15 @@ for the former, and 'multi-column for the latter."
(const :tag "A single column" single-column))
:group 'valign)
+(defcustom valign-fancy-bar nil
+ "Non-nil means to render bar as a full-height line.
+You need to restart valign mode or realign tables for this
+setting to take effect."
+ :type '(choice
+ (const :tag "Enable fancy bar" t)
+ (const :tag "Disable fancy bar" nil))
+ :group 'valign)
+
(defun valign-table ()
"Visually align the table at point."
(interactive)
@@ -472,7 +503,7 @@ for the former, and 'multi-column for the latter."
(save-excursion
(let (end column-width-list column-idx pos ssw bar-width
separator-row-point-list rev-list
- column-alignment-list info at-sep-row)
+ column-alignment-list info at-sep-row right-bar-pos)
;; ‘separator-row-point-list’ marks the point for each
;; separator-row, so we can later come back and align them.
;; ‘rev-list’ is the reverse list of right positions of each
@@ -493,7 +524,11 @@ for the former, and 'multi-column for the latter."
(save-excursion
;; Check there is a right bar.
(when (save-excursion
- (search-forward "|" (line-end-position) t))
+ (search-forward "|" (line-end-position) t)
+ (setq right-bar-pos (match-beginning 0)))
+ ;; Can’t put this in the save-excursion, donno why.
+ ;; Render the right bar of each cell.
+ (valign--maybe-render-bar right-bar-pos)
;; We are after the left bar (“|”).
;; Start aligning this cell.
;; Pixel width of the column
@@ -513,6 +548,8 @@ for the former, and 'multi-column for the latter."
(when (eq column-idx 0)
(when (valign--separator-p)
(push (point) separator-row-point-list))
+ ;; Render the first bar of the line.
+ (valign--maybe-render-bar (1- (point)))
(unless (valign--separator-p)
(setq rev-list nil))
(setq at-sep-row (if (valign--separator-p) t nil))
@@ -639,6 +676,10 @@ FLAG is the same as in ‘org-flag-region’."
(when (and (consp display)
(eq (car display) 'space))
(put-text-property pp p 'display nil))))
+ ;; Remove fancy bars.
+ (put-text-property (point-min) (point-max) 'face nil)
+ (put-text-property (point-min) (point-max) 'font-lock-face nil)
+ (jit-lock-refontify)
;; Remove overlays.
(dolist (ov (overlays-in (point-min) (point-max)))
(when (overlay-get ov 'valign)
- [elpa] externals/valign ed8dd50 118/198: Remove obsolete functions, (continued)
- [elpa] externals/valign ed8dd50 118/198: Remove obsolete functions, Stefan Monnier, 2020/12/01
- [elpa] externals/valign ced2f6a 132/198: * valign.el (valign-table-1): Fix search term., Stefan Monnier, 2020/12/01
- [elpa] externals/valign c70c64e 125/198: * valign.el (valign--clean-text-property): Remove code using 'text-property-search-forward'., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 645260f 076/198: * valign.el (valign-table): Allow edebug., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 82566b3 080/198: Fix tab calculation, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 6578fe4 081/198: * valign.el (valign-table): Don’t message errors., Stefan Monnier, 2020/12/01
- [elpa] externals/valign e2a2a85 085/198: Rework hooks, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 44651e9 086/198: * valign.el (valign-mode): Change text-scale hooks., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 8b6ce8c 084/198: * valign.el (valign--cell-width): Minor change., Stefan Monnier, 2020/12/01
- [elpa] externals/valign dcf6bd8 088/198: Add force align, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 53be5d7 089/198: Add fancy bar,
Stefan Monnier <=
- [elpa] externals/valign 98eae8d 090/198: * valign.el (valign-table): Remove setter for custom option., Stefan Monnier, 2020/12/01
- [elpa] externals/valign 159ae0f 102/198: Fix typo, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 1a614d2 101/198: Add missing with-silent-modifications form, Stefan Monnier, 2020/12/01
- [elpa] externals/valign ba7a72b 110/198: * valign.el (valign-table): Tuck in some long lines., Stefan Monnier, 2020/12/01
- [elpa] externals/valign ea71f38 126/198: * valign.el (valign-fancy-bar): Fix typo., Stefan Monnier, 2020/12/01
- [elpa] externals/valign cb95dc1 119/198: Separate valign--do-table, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 237293b 140/198: Change signal-catch to if-else, Stefan Monnier, 2020/12/01
- [elpa] externals/valign 9554e4b 123/198: Clean up valign-table-1, Stefan Monnier, 2020/12/01
- [elpa] externals/valign a8d93c5 145/198: Fix markdown table alignment, Stefan Monnier, 2020/12/01
- [elpa] externals/valign a68750a 114/198: * valign.el (valign-table): Add missing docstring., Stefan Monnier, 2020/12/01