Is there a command for moving only the value 11 to the right column in the following column?
| Name | | | |------+----+---| | a | 11 | | | b | 10 | |
org-table-move-column but applying to a single cell only.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
Here is a naive function that I put together in few minutes. It uses interactive commands, so there must be a more correct way of doing the same thing.
Org table commands behave in quite surprising ways. See command documentation to understand better what is happening here.
This function does not delete the cell content in the next cell, but prepends to it. It should be easy to modify it to remove the next cell content first.
(defun org-table-prepend-cell-to-right () "Cut table cell content and prepend it to cell contects on its right." (interactive) (when (org-at-table-p 'any) (goto-char (1+ (point))) (call-interactively 'org-table-beginning-of-field) (let ((start (point)) (string)) (call-interactively 'org-table-end-of-field) (setq string (concat (delete-and-extract-region start (point)) " ")) (org-table-next-field) (insert string) (org-ctrl-c-ctrl-c))))
Following advice from @manandearth, I modified the
org-table-move-cell function from
org-table.el by commenting out a few lines:
(defun org-table-move-cell (&optional left) "Move the current cell 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) (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 cell further left")) (when (and (not left) (looking-at "[^|\n]*|[^|\n]*$")) (user-error "Cannot move cell further right")) (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) ;; ) ) (set-marker end nil) (org-table-goto-column colpos) (org-table-align) (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)))) (org-table-fix-formulas "$LR" (list (cons (number-to-string col) (number-to-string colpos)) (cons (number-to-string colpos) (number-to-string col)))) ) ) )
The commented lines would otherwise have the effect of going to the beginning of table and then processing every line until the end of table is reached. Now only the current line is processed and thus only two cells are transposed.