Function: markdown-ts-table-align-column
markdown-ts-table-align-column is an interactive and byte-compiled
function defined in markdown-ts-mode.el.gz.
Signature
(markdown-ts-table-align-column &optional ALIGN)
Documentation
Alter the table column alignment at point.
Alter the column point is in.
Note: To compute the column, point must be within the column and cannot be on the leading or trailing whitespace or on a column delimiter.
ALIGN can be one of the symbols left, center, right or nil for
unspecified, or the characters l, c, or r.
If ALIGN is nil, assume unspecified. Make the alignment string a minimum of 5 characters to accommodate Markdown conventions.
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-align-column (&optional align)
"Alter the table column alignment at point.
Alter the column point is in.
Note: To compute the column, point must be within the column and cannot
be on the leading or trailing whitespace or on a column delimiter.
ALIGN can be one of the symbols `left', `center', `right' or nil for
unspecified, or the characters l, c, or r.
If ALIGN is nil, assume unspecified. Make the alignment string a
minimum of 5 characters to accommodate Markdown conventions.
If point is not at a table, do nothing."
(interactive
(list (car (read-multiple-choice
"Align column" '((?l "left")
(?c "center")
(?r "right")
(?u "unspecified"))))))
(markdown-ts--barf-if-not-mode 'markdown-ts-table-align-column)
(setq align (if (characterp align)
(pcase align (?l 'left) (?c 'center) (?r 'right))
align))
(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 cell))
(aligners (markdown-ts--table-aligners table)))
(let ((table-column (markdown-ts--table-compute-node-column row cell)))
(unless table-column
(error "Could not compute the table column"))
;; NOTE: GFM tables allow non-uniform table rows. The current row
;; could have a differing number of columns from the header. We
;; silently do nothing if we can't find a matching header column.
(when-let* ((aligner (nth table-column aligners))
(beg (plist-get aligner :beg))
(end (plist-get aligner :end))
(str (buffer-substring-no-properties beg end))
(strlen (max 5 (length str))))
(delete-region beg end)
(save-excursion
(goto-char beg)
(insert (markdown-ts--table-make-aligner strlen align)))))))