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

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

[elpa] externals/valign 3fcb173 12/15: Fix 'valign--separator-line-p'


From: Stefan Monnier
Subject: [elpa] externals/valign 3fcb173 12/15: Fix 'valign--separator-line-p'
Date: Tue, 16 Mar 2021 00:01:35 -0400 (EDT)

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

    Fix 'valign--separator-line-p'
    
    * valign.el (valign--separator-p): Add optional argument POINT.
    (valign--separator-line-p): Separate logic for table.el tables and org
    tables.
    (valign--calculate-cell-width): Don't give a default value to CHARSET.
---
 valign.el | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/valign.el b/valign.el
index c2ad270..6f4fe57 100644
--- a/valign.el
+++ b/valign.el
@@ -324,11 +324,11 @@ properties must be cleaned before using this."
   (- (car (window-text-pixel-size nil (line-beginning-position) point))
      (line-number-display-width 'pixel)))
 
-(defun valign--separator-p ()
+(defun valign--separator-p (&optional point)
   "If the current cell is actually a separator.
-Assume point is after the left bar (“|”)."
-  (or (eq (char-after) ?:) ;; Markdown tables.
-      (eq (char-after) ?-)))
+POINT should be after the left bar (“|”), default to current point."
+  (or (eq (char-after point) ?:) ;; Markdown tables.
+      (eq (char-after point) ?-)))
 
 (defun valign--alignment-from-seperator ()
   "Return the alignment of this column.
@@ -394,22 +394,27 @@ Return t if the dimension is correct, nil if not."
 (defun valign--separator-line-p (&optional charset)
   "Return t if this line is a separator line.
 If the table is a table.el table, you need to specify CHARSET.
+If the table is not a table.el table, DON’T specify CHARSET.
 Assumes the point is at the beginning of the line."
-  (if charset
-      (let ((charset (or charset (cdar valign-box-charset-alist))))
-        (member (char-to-string (char-after))
-                (list (valign-box-char 1 charset)
-                      (valign-box-char 4 charset)
-                      (valign-box-char 7 charset))))
-    (valign--separator-p)))
+  (save-excursion
+    (skip-chars-forward " \t")
+    (if charset
+        ;; Check for table.el tables.
+        (let ((charset (or charset (cdar valign-box-charset-alist))))
+          (member (char-to-string (char-after))
+                  (list (valign-box-char 1 charset)
+                        (valign-box-char 4 charset)
+                        (valign-box-char 7 charset))))
+      ;; Check for org/markdown tables.
+      (and (eq (char-after) ?|)
+           (valign--separator-p (1+ (point)))))))
 
 (defun valign--calculate-cell-width (limit &optional charset)
   "Return a list of column widths.
 Each column width is the largest cell width of the column.  Start
 from point, stop at LIMIT.  If the table is a table.el table, you
 need to specify CHARSET."
-  (let* ((charset (or charset (cdar valign-box-charset-alist)))
-         (bar-char (valign-box-char 'v charset))
+  (let* ((bar-char (if charset (valign-box-char 'v charset) "|"))
          row-idx column-idx matrix row)
     (ignore row-idx)
     (save-excursion



reply via email to

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