emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/valign f6d60d2 078/198: Merge two implementations for v


From: Stefan Monnier
Subject: [elpa] externals/valign f6d60d2 078/198: Merge two implementations for valign--align-separator-row
Date: Tue, 1 Dec 2020 18:19:20 -0500 (EST)

branch: externals/valign
commit f6d60d2701b65bd56e5308d0e1919c764120fea8
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Merge two implementations for valign--align-separator-row
    
    * valign.el (valign--align-separator-row): merge org and markdown.
---
 valign.el | 45 ++++++++++++++++-----------------------------
 1 file changed, 16 insertions(+), 29 deletions(-)

diff --git a/valign.el b/valign.el
index 5184a4b..e72089a 100644
--- a/valign.el
+++ b/valign.el
@@ -458,41 +458,28 @@ Assumes point is on the right bar or plus sign."
     (overlay-put ov 'valign t)))
 
 (cl-defmethod valign--align-separator-row
-  ((type (eql org)) (style (eql multi-column)) pos-list)
+  (type (style (eql multi-column)) pos-list)
   "Align the separator row in multi column style.
-TYPE must be 'org-mode, STYLE is 'multi-column.
+TYPE can be 'org-mode or 'markdown-mode, STYLE is 'multi-column.
 POS-LIST is a list of positions for each column’s right bar."
   (ignore type style)
   (let ((p (point))
-        (col-idx 0))
+        (col-idx 0)
+        (max-col (1- (length pos-list)))
+        (seperator-p (valign--separator-p)))
     (while (and (< (point) (point-max))
-                (search-forward "+" (line-end-position) t))
-      (valign--separator-row-add-overlay
-       p (1- (point))
-       (or (nth col-idx pos-list) 0))
+                (<= col-idx max-col)
+                (re-search-forward "[+|]" (line-end-position) t))
+      ;; Separator rows that has empty cells (|----|    |----|)
+      ;; is also possible.
+      (if seperator-p
+          (valign--separator-row-add-overlay
+           p (1- (point)) (nth col-idx pos-list))
+        (valign--put-text-property
+         p (1- (point)) (nth col-idx pos-list)))
       (cl-incf col-idx)
-      (setq p (point)))
-    ;; Last column
-    (when (search-forward "|" (line-end-position) t)
-      (valign--separator-row-add-overlay
-       p (1- (point))
-       (or (nth col-idx pos-list) 0)))))
-
-(cl-defmethod valign--align-separator-row
-  ((type (eql markdown)) (style (eql multi-column)) pos-list)
-  "Align the separator row in multi column style.
-TYPE must be 'markdown-mode, STYLE is 'multi-column.
-POS-LIST is a list of positions for each column’s right bar."
-  (ignore type style)
-  (let ((p (point))
-        (col-idx 0))
-    (while (and (< (point) (point-max))
-                (search-forward "|" (line-end-position) t))
-      (valign--separator-row-add-overlay
-       p (1- (point))
-       (or (nth col-idx pos-list) 0))
-      (cl-incf col-idx)
-      (setq p (point)))))
+      (setq p (point))
+      (setq seperator-p (valign--separator-p)))))
 
 (defun valign--guess-table-type ()
   "Return either 'org or 'markdown."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]