master e84f48e5e40 1/2: markdown-ts-mode: Fix abutting table detection (bug#81199)

Sean Whitton <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit e84f48e5e405140fde91a57cbd9dbe2ccdd169e8
Author: Stéphane Marks <[email protected]>
Commit: Sean Whitton <[email protected]>

    markdown-ts-mode: Fix abutting table detection (bug#81199)
    
    Correct for navigating between empty table cells which should be
    respected rather than treated as blanks to skip.
    
    * lisp/textmodes/markdown-ts-mode.el (markdown-ts--table-abutting-pos):
    Fix to directly detect being in a table rather than inferring it.
---
 lisp/textmodes/markdown-ts-mode.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lisp/textmodes/markdown-ts-mode.el b/lisp/textmodes/markdown-ts-mode.el
index 0056d14f889..c44bc9161a3 100644
--- a/lisp/textmodes/markdown-ts-mode.el
+++ b/lisp/textmodes/markdown-ts-mode.el
@@ -3354,18 +3354,22 @@ With the prefix argument ARG, remain within the current code block."
 
 (defun markdown-ts--table-abutting-pos (pos)
   "Adjust POS to abut its closest text.
-Return pos adjusted to the position of the nearest non-blank character.
+If POS is already in a table, return POS.
+If not, adjust POS to the nearest non-blank character, looking first
+forward and then backward adjusting, if it is in a table, return the adjusted POS.
 Otherwise, return nil, for example, if the line is empty."
   (save-excursion
     (goto-char pos)
-    (skip-chars-forward "[[:blank:]]" (pos-eol))
-    (if (eq pos (pos-eol))
-        (progn
-          (goto-char pos)
-          (skip-chars-backward "[[:blank:]]" (pos-bol))
-          (unless (eq pos (pos-bol))
-            (max (point-min) (1- (point)))))
-      (min (point-max) (1+ (point))))))
+    (if (markdown-ts--table-node-row nil pos)
+        pos
+      (skip-chars-forward "[[:blank:]]" (pos-eol))
+      (if (markdown-ts--table-node-row)
+          (point)
+        (goto-char pos)
+        (skip-chars-backward "[[:blank:]]" (pos-bol))
+        (unless (eq (point) (pos-bol))
+          (if (markdown-ts--table-node-row nil (1- (point)))
+              (1- (point))))))))
 
 (defun markdown-ts--table-node-cell (&optional node pos abutting)
   "Compute table cell from named NODE at POS.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.