Function: markdown-ts-table-move-column
markdown-ts-table-move-column is an interactive and byte-compiled
function defined in markdown-ts-mode.el.gz.
Signature
(markdown-ts-table-move-column &optional LEFT)
Documentation
Move the table column at point right or left.
If LEFT is non-nil and is not right, or with a prefix argument,
move the column to its left.
Do nothing if a row being moved is not within the columns of the header.
Do nothing if moving left and the current column is the first column of
the current row.
Do nothing if moving right and the current column is the final column of
the current row.
Point can be in the table header or body.
If point is not at a table, do nothing.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts-table-move-column (&optional left)
"Move the table column at point right or left.
If LEFT is non-nil and is not `right', or with a prefix argument,
move the column to its left.
Do nothing if a row being moved is not within the columns of the header.
Do nothing if moving left and the current column is the first column of
the current row.
Do nothing if moving right and the current column is the final column of
the current row.
Point can be in the table header or body.
If point is not at a table, do nothing."
(interactive)
(markdown-ts--barf-if-not-mode 'markdown-ts-table-move-column)
(setq left (cond ((eq left 'right) nil)
(left left)
(current-prefix-arg t)))
(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))
(row (markdown-ts--table-node-row node))
(header-row (treesit-search-subtree
table
"\\`pipe_table_header\\'"))
(nheaders (length (treesit-node-children header-row 'named)))
(cols (treesit-node-children row 'named))
(ncols (length cols)))
(let ((table-column (markdown-ts--table-compute-node-column row cell)))
(unless table-column
(error "Could not compute the table column"))
(if (>= table-column nheaders)
(message "Ragged/uneven column cannot be moved")
;; A B C D -> B A C D
;; Move A left: do nothing
;; Move D right: do nothing
;; Move current column left:
;; source column = t - 1
;; Move current column right:
;; clone t to t+1 if the final column, otherwise t+2
;; delete t
(cond ((and left (eq table-column 0))
(message "Leftmost column cannot be moved left")
nil)
((and (not left) (eq table-column (1- ncols)))
(message "Rightmost column cannot be moved right")
nil)
(t
(let ((source-column (if left
(1- table-column)
table-column))
(target-column (if left
table-column
(1+ table-column))))
(save-excursion
(markdown-ts-table--goto-column source-column)
(markdown-ts-table-insert-column
'right (list
target-column)))
(markdown-ts-table--goto-column source-column)
(markdown-ts-table-delete-column)
;; Empty cells can confuse the grammar, so no-error here.
(if left
(markdown-ts-table--goto-column
source-column 'no-error)
(markdown-ts-table--goto-column
target-column 'no-error)))))))))