2

In Excel etc it is possible to delete a cell in a column and have the cells below it "shift up" without affecting the content of the other columns. I haven't found a command for this in org-mode, is there one?

Example: In the following table I want to delete the cell Banana.

| Cars  | Fruits |
|-------+--------|
| Volvo | Apple  |
| Saab  | Banana |
| Ford  | Pear   |

This should be the result:

| Cars  | Fruits |
|-------+--------|
| Volvo | Apple  |
| Saab  | Pear   |
| Ford  |        |

Now ideally if I were to additionally delete Volvo the table would look like this:

| Cars | Fruits |
|------+--------|
| Saab | Apple  |
| Ford | Pear   |
2

Here's a function I wrote,

(defun org-table-collapse-cell ()
  (interactive)
  (save-excursion ;; Save point
    (org-table-blank-field) ;; Blank the cell
    (while (progn ;; Swap blank cell with a cell under it until the blank is at the bottom.
         (org-table--move-cell 'down)
         (org-table-align)
         (org-table-check-inside-data-field))))
  (org-table-next-field))

It's very rough and calling it on Volvo and Banana yields

| Cars | Fruits |
|------+--------|
| Saab | Apple  |
| Ford | Pear   |
|      |        |

Which, I think should be enough you can delete the empty row yourself.

1
  • 1
    Rolling your own seems like a good solution. I made a small change which handles the error from org-table--move-cell and also restores the point a bit better than save-excursion. (defun org-table-collapse-cell () (interactive) (let ((pt (point))) (org-table-blank-field) (condition-case nil (while (org-table-check-inside-data-field) (org-table--move-cell 'down) (org-table-align)) (user-error nil)) (goto-char pt))) May 17 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.