Skip to content

Instantly share code, notes, and snippets.

@mrc
Created April 30, 2013 07:51
Show Gist options
  • Save mrc/5487238 to your computer and use it in GitHub Desktop.
Save mrc/5487238 to your computer and use it in GitHub Desktop.
Kill a column in an org-mode table (clipboard driven development at it's finest; a renovator's dream)
(defun org-table-kill-column (margin-width)
"Kill a column from the table.
Cut in on each side by MARGIN-WIDTH; use 0 to keep the column delimiters."
(interactive "p")
(if (not (org-at-table-p))
(error "Not at a table"))
(org-table-find-dataline)
(org-table-check-inside-data-field)
(kill-new "")
(let* ((col (org-table-current-column))
(beg (org-table-begin))
(end (org-table-end))
;; Current cursor position
(linepos (org-current-line))
(colpos col))
(goto-char beg)
(while (< (point) end)
(if (org-at-table-hline-p)
nil
(org-table-goto-column col t)
(when (looking-at "|[^|\n]+|")
(let ((cell (filter-buffer-substring
(+ (match-beginning 0) margin-width)
(- (match-end 0) margin-width))))
(kill-append (concat cell "\n") nil))
(replace-match "|")))
(beginning-of-line 2))
(move-marker end nil)
(org-goto-line linepos)
(org-table-goto-column colpos)
(org-table-align)
(org-table-fix-formulas "$" (list (cons (number-to-string col) "INVALID"))
col -1 col)
(org-table-fix-formulas "$LR" (list (cons (number-to-string col) "INVALID"))
col -1 col)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment