Function: markdown-table-transpose

markdown-table-transpose is an interactive and byte-compiled function defined in markdown-mode.el.

Signature

(markdown-table-transpose)

Documentation

Transpose table at point.

Horizontal separator lines will be eliminated.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/markdown-mode-20260321.143/markdown-mode.el
(defun markdown-table-transpose ()
  "Transpose table at point.
Horizontal separator lines will be eliminated."
  (interactive)
  (unless (markdown-table-at-point-p)
    (user-error "Not at a table"))
  (let* ((table (buffer-substring-no-properties
                 (markdown-table-begin) (markdown-table-end)))
         ;; Convert table to Lisp structure
         (table (delq nil
                      (mapcar
                       (lambda (x)
                         (unless (string-match-p
                                  markdown-table-hline-regexp x)
                           (markdown--table-line-to-columns x)))
                       (markdown--split-string table "[ \t]*\n[ \t]*"))))
         (dline_old (markdown-table-get-dline))
         (col_old (markdown-table-get-column))
         (contents (mapcar (lambda (_)
                             (let ((tp table))
                               (mapcar
                                (lambda (_)
                                  (prog1
                                      (pop (car tp))
                                    (setq tp (cdr tp))))
                                table)))
                           (car table))))
    (goto-char (markdown-table-begin))
    (save-excursion
      (re-search-forward "|") (backward-char)
      (delete-region (point) (markdown-table-end))
      (insert (mapconcat
               (lambda(x)
                 (concat "| " (mapconcat 'identity x " | " ) " |\n"))
               contents "")))
    (markdown-table-goto-dline col_old)
    (markdown-table-goto-column dline_old))
  (when markdown-table-align-p
    (markdown-table-align)))