Function: org-table--move-cell

org-table--move-cell is a byte-compiled function defined in org-table.el.gz.

Signature

(org-table--move-cell DIRECTION)

Documentation

Move the current cell in a cardinal direction.

DIRECTION is a symbol among up, down, left, and right. The contents the current cell are swapped with cell in the indicated direction. Raise an error if the move cannot be done.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
(defun org-table--move-cell (direction)
  "Move the current cell in a cardinal direction.
DIRECTION is a symbol among `up', `down', `left', and `right'.
The contents the current cell are swapped with cell in the
indicated direction.  Raise an error if the move cannot be done."
  (let ((row-shift (pcase direction (`up -1) (`down 1) (_ 0)))
	(column-shift (pcase direction (`left -1) (`right 1) (_ 0))))
    (when (and (= 0 row-shift) (= 0 column-shift))
      (error "Invalid direction: %S" direction))
    ;; Initialize `org-table-current-ncol' and `org-table-dlines'.
    (org-table-analyze)
    (let* ((row (org-table-current-line))
	   (column (org-table-current-column))
	   (target-row (+ row row-shift))
	   (target-column (+ column column-shift))
	   (org-table-current-nrow (1- (length org-table-dlines))))
      (when (or (< target-column 1)
		(< target-row 1)
		(> target-column org-table-current-ncol)
		(> target-row org-table-current-nrow))
	(user-error "Cannot move cell further"))
      (org-table--swap-cells row column target-row target-column)
      (org-table-goto-line target-row)
      (org-table-goto-column target-column))))