emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Remove empty rows in a org-table
@ 2013-10-27  9:59 Florian Adamsky
  0 siblings, 0 replies; only message in thread
From: Florian Adamsky @ 2013-10-27  9:59 UTC (permalink / raw)
  To: emacs-orgmode

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/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-10-27  9:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-27  9:59 Remove empty rows in a org-table Florian Adamsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).