emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Remove empty rows in a org-table


From: Florian Adamsky
Subject: [O] Remove empty rows in a org-table
Date: Sun, 27 Oct 2013 10:59:15 +0100
User-agent: mu4e 0.9.9.5; emacs 24.3.1

Dear org-mode hackers,

in a org-mode file I copy various information to a org-table. Sometimes
there are empty rows in that org-table which I don't like. Therefore I
wrote a little function that removes empty rows from a org-mode table.

Maybe this is of any for org-mode or for other people. I would like to
hear of any improvements or better ways to do this. Maybe this already
exists in org-mode somewhere? :-)

#+BEGIN_SRC emacs-lisp
(defun fa/org-table-remove-empty-rows ()
  "Removes empty rows in a org-mode table."
  (interactive)
  (save-excursion
    (unless (org-table-p)
      (error
       "You are not in an org-table."))
    (goto-char (org-table-begin))
    (let ((tbl-list (org-table-to-lisp)))
      (while
          (let ((row-list (car tbl-list)))
            (cond ((and
                    (listp row-list)
                    (equal row-list (make-list (length row-list)
                                               (string))))
                   (kill-line)
                   (kill-line))
                  (t (next-line)))
            (setq tbl-list (cdr tbl-list)))))))
#+END_SRC

This functions does the following:

|------+------+-----|        |------+------+-----|
| test |  foo | bar |        | test |  foo | bar |
|------+------+-----|        |------+------+-----|
|    1 |    2 |   3 |        |    1 |    2 |   3 |
|      |      |     |        |    4 |      |   6 |
|    4 |      |   6 |  -->   |      | test | bla |
|      |      |     |        |------+------+-----|
|      | test | bla |        |      |    2 |   4 |
|------+------+-----|        |------+------+-----|
|      |      |     |
|      |    2 |   4 |
|------+------+-----|

--
Florian Adamsky
http://florian.adamsky.it/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]