4

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 | 

1 Answer 1

3

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
  • 2
    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))) Commented May 17, 2021 at 9:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.