Skip to content

Instantly share code, notes, and snippets.

@kaz-yos
Last active May 24, 2018 15:02
Show Gist options
  • Save kaz-yos/e36141a5fd53bf75c15512954bac56aa to your computer and use it in GitHub Desktop.
Save kaz-yos/e36141a5fd53bf75c15512954bac56aa to your computer and use it in GitHub Desktop.
Mathematically sane org-table-create by advising it
;; Swap dimension specification
(defun my-reverse-org-table-dimension (size)
(let* ((split (org-split-string size " *x *"))
(pos1 (nth 1 split))
(pos0 (car split)))
(concat pos1 "x" pos0)))
;; Wrapper to fix the dimension
(defun org-table-create-reverse-table-dimension (old-fun &optional size)
"Query for a size and insert a table skeleton.
SIZE is a string Rows x Columns like for example \"2x3\".
When calling non-interactively SIZE should be a string Columns x Rows
to conform the org-mode convention."
(interactive "P")
(unless size
(setq size (my-reverse-org-table-dimension
(read-string
(concat "Table size Rows x Columns [e.g. "
(my-reverse-org-table-dimension org-table-default-size) "]: ")
"" nil (my-reverse-org-table-dimension org-table-default-size)))))
(funcall old-fun size))
;; Advice org-table-create
(advice-add 'org-table-create
:around #'org-table-create-reverse-table-dimension)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment