branch: elpa/markdown-mode
commit c765b73b370f0fcaaa3cee28b2be69652e2d2c39
Merge: 0f7eae8113 00f13a98d1
Author: Shohei YOSHIDA <syo...@gmail.com>
Commit: GitHub <nore...@github.com>

    Merge pull request #748 from jrblevin/issue-747
    
    Improve checking if the line is delimiter row
---
 CHANGES.md             |  2 ++
 markdown-mode.el       | 12 +++++++++---
 tests/markdown-test.el | 10 ++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index d2fd6426a3..23cf98d88c 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -23,6 +23,7 @@
     - Don't override table faces by link faces [GH-716][]
     - Fix invalid italic fontification after bold markups[GH-731][]
     - Fix `markdown-live-preview-mode` fails when `eww-auto-rename-buffer` is 
non-nil[GH-737][]
+    - Fix to mistake to handle the line as delimiter row[GH-747][]
 
   [gh-572]: https://github.com/jrblevin/markdown-mode/issues/572
   [gh-705]: https://github.com/jrblevin/markdown-mode/issues/705
@@ -30,6 +31,7 @@
   [gh-731]: https://github.com/jrblevin/markdown-mode/issues/731
   [gh-737]: https://github.com/jrblevin/markdown-mode/issues/737
   [gh-739]: https://github.com/jrblevin/markdown-mode/issues/739
+  [gh-747]: https://github.com/jrblevin/markdown-mode/issues/747
 
 
 # Markdown Mode 2.5
diff --git a/markdown-mode.el b/markdown-mode.el
index 7774a343c6..d50303c49c 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -9202,6 +9202,11 @@ This function assumes point is on a table."
         (push (buffer-substring-no-properties cur (point-max)) ret))
       (nreverse ret))))
 
+(defsubst markdown--is-delimiter-row (line)
+  (and (string-match-p "\\`[ \t]*|[ \t]*[-:]" line)
+       (cl-loop for c across line
+                always (member c '(?| ?- ?: ?\t ? )))))
+
 (defun markdown-table-align ()
   "Align table at point.
 This function assumes point is on a table."
@@ -9214,9 +9219,10 @@ This function assumes point is on a table."
             ;; Store table indent
             (indent (progn (looking-at "[ \t]*") (match-string 0)))
             ;; Split table in lines and save column format specifier
-            (lines (mapcar (lambda (l)
-                             (if (string-match-p "\\`[ \t]*|[ \t]*[-:]" l)
-                                 (progn (setq fmtspec (or fmtspec l)) nil) l))
+            (lines (mapcar (lambda (line)
+                             (if (markdown--is-delimiter-row line)
+                                 (progn (setq fmtspec (or fmtspec line)) nil)
+                               line))
                            (markdown--split-string (buffer-substring begin 
end) "\n")))
             ;; Split lines in cells
             (cells (mapcar (lambda (l) (markdown--table-line-to-columns l))
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index 03883cc113..fdceb31342 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -7270,6 +7270,16 @@ https://github.com/jrblevin/markdown-mode/issues/640";
       (should (string= (buffer-substring-no-properties (point-min) (point-max))
                        "| 1 | 2 | 3 |\n| 4 | 5 | 6 |\n")))))
 
+(ert-deftest test-markdown-table/decide-delimiter-line ()
+  "Test `markdown-table-aligh' for the line which starts with dash.
+Detail: https://github.com/jrblevin/markdown-mode/issues/747";
+  (let ((markdown-table-align-p t))
+    (markdown-test-string "| -c | some text |\n"
+      (search-forward "some")
+      (call-interactively 'markdown-table-next-row)
+      (should (string= (buffer-substring-no-properties (point-min) (point-max))
+                       "| -c | some text |\n|    |           |\n")))))
+
 (provide 'markdown-test)
 
 ;;; markdown-test.el ends here

Reply via email to