Function: markdown-ts-table-next-cell

markdown-ts-table-next-cell is an interactive and byte-compiled function defined in markdown-ts-mode.el.gz.

Signature

(markdown-ts-table-next-cell &optional N)

Documentation

Move to the next cell in the table.

If N is negative, move to the previous cell. If not in a table, do nothing.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts-table-next-cell (&optional n)
  "Move to the next cell in the table.
If N is negative, move to the previous cell.
If not in a table, do nothing."
  (interactive)
  (markdown-ts--barf-if-not-mode 'markdown-ts-table-next-cell)
  (let ((backwards (and n (< n 0))))
    (when-let* ((at-table (markdown-ts-at-table-p nil t))
                (pos (car at-table))
                (table (cdr at-table))
                (node (treesit-node-at pos 'markdown 'named))
                (cell (markdown-ts--table-node-cell node))
                (cell-type (treesit-node-type node))
                (row (markdown-ts--table-node-row cell))
                (row-type (treesit-node-type row))
                (next-cell
                 (cond
                  ;; If in a pipe_table_delimiter_row and not the first
                  ;; or final cell in the row, stay within the row
                  ;; otherwise, the default condition should match.
                  ((and (equal row-type "pipe_table_delimiter_row")
                        (if backwards
                            (treesit-node-prev-sibling cell 'named)
                          (treesit-node-next-sibling cell 'named)))
                   (if backwards
                       (treesit-node-prev-sibling cell 'named)
                     (treesit-node-next-sibling cell 'named)))
                  ;; If on the first pipe_table_row's first cell moving
                  ;; backwards, move into the final
                  ;; pipe_table_delimiter_cell.
                  ((and (equal cell-type "pipe_table_cell")
                        (equal (treesit-node-type
                                (treesit-node-prev-sibling row 'named))
                               "pipe_table_delimiter_row")
                        (not (treesit-node-prev-sibling cell 'named))
                        backwards)
                   (treesit-search-forward
                    cell
                    "\\`pipe_table_delimiter_cell\\'" backwards))
                  ;; If on the first pipe_table_header's final cell
                  ;; moving forwards, move into the first
                  ;; pipe_table_delimiter_cell.
                  ((and (equal cell-type "pipe_table_cell")
                        (equal (treesit-node-type
                                (treesit-node-next-sibling row 'named))
                               "pipe_table_delimiter_row")
                        (not (treesit-node-next-sibling cell 'named))
                        (not backwards))
                   (treesit-search-forward
                    cell
                    "\\`pipe_table_delimiter_cell\\'" backwards))
                  (t
                   (treesit-search-forward
                    cell
                    "\\`pipe_table_cell\\'" backwards)))))
      ;; Keep point within the current table.
      (when (treesit-node-eq table (treesit-search-forward
                                    next-cell
                                    "\\`pipe_table\\'" 'backward))
        (goto-char (treesit-node-start next-cell)))
      (when (or (eq markdown-ts-table-auto-align t)
                (memq 'cell-navigation markdown-ts-table-auto-align))
        (markdown-ts-table-align-table)))))