Function: org-table-move-column

org-table-move-column is an autoloaded, interactive and byte-compiled function defined in org-table.el.gz.

Signature

(org-table-move-column &optional LEFT)

Documentation

Move the current column to the right. With arg LEFT, move to the left.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
;;;###autoload
(defun org-table-move-column (&optional left)
  "Move the current column to the right.  With arg LEFT, move to the left."
  (interactive "P")
  (unless (org-at-table-p) (user-error "Not at a table"))
  (org-table-find-dataline)
  (org-table-check-inside-data-field nil t)
  (let* ((col (org-table-current-column))
	 (col1 (if left (1- col) col))
	 (colpos (if left (1- col) (1+ col)))
	 (beg (org-table-begin))
	 (end (copy-marker (org-table-end))))
    (when (and left (= col 1))
      (user-error "Cannot move column further left"))
    (when (and (not left) (looking-at "[^|\n]*|[^|\n]*$"))
      (user-error "Cannot move column further right"))
    (let ((shrunk-columns (org-table--list-shrunk-columns)))
      (org-table-expand beg end)
      (org-table-save-field
       (goto-char beg)
       (while (< (point) end)
	 (unless (org-at-table-hline-p)
	   (org-table-goto-column col1 t)
	   (when (looking-at "|\\([^|\n]+\\)|\\([^|\n]+\\)|")
	     (transpose-regions
	      (match-beginning 1) (match-end 1)
	      (match-beginning 2) (match-end 2))))
	 (forward-line)))
      (org-table-goto-column colpos)
      (org-table-align)
      ;; Shift appropriately stored shrunk column numbers, then shrink
      ;; the columns again.
      (org-table--shrink-columns
       (mapcar (lambda (c)
		 (cond ((and (= col c) left) (1- c))
		       ((= col c) (1+ c))
		       ((and (= col (1+ c)) left) (1+ c))
		       ((and (= col (1- c)) (not left) (1- c)))
		       (t c)))
	       shrunk-columns)
       beg end)
      (set-marker end nil)
      ;; Fix TBLFM formulas, if desirable.
      (when (or (not org-table-fix-formulas-confirm)
		(funcall org-table-fix-formulas-confirm "Fix formulas? "))
	(org-table-fix-formulas
	 "$" (list (cons (number-to-string col) (number-to-string colpos))
		   (cons (number-to-string colpos) (number-to-string col))))))))