emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] simple script to convert txt tables to Org-mode tables on the co


From: Achim Gratz
Subject: Re: [O] simple script to convert txt tables to Org-mode tables on the command line
Date: Mon, 07 Jan 2013 21:33:39 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.91 (gnu/linux)

Bastien writes:
> In the same vein, the next release of Clojure (1.5) includes
> a way to export to Org mode tables:

While we are talking about exporting tables to/from Org: Start a session
from sudoku.el and use this org file to easily import Sudoku from a
paper or book into sudoku.el and maybe keep track of what you did.  Not
the most elegant code for dealing with the lists structures, but it gets
the job done.

--8<---------------cut here---------------start------------->8---
#+NAME: export-sudoku
#+BEGIN_SRC emacs-lisp :var table=() :hlines no :results output silent
  (setq custom-puzzles 
        (list
         (mapcar
          (lambda (row)
            (mapcar
             (lambda (entry)
               (if (stringp entry) 0 entry))
             row))
          (remove 'hline table))))
#+END_SRC
#+NAME: import-sudoku
#+BEGIN_SRC emacs-lisp :results value :hlines yes
  (let (board
        (index 0))
  (setq board (mapcar
               (lambda (row)
                 (mapcar
                  (lambda (entry)
                    (if (zerop entry) "" entry))
                  row))
               current-board))
  (list
   (nth 0 board) (nth 1 board) (nth 2 board)
   'hline
   (nth 3 board) (nth 4 board) (nth 5 board)
   'hline
   (nth 6 board) (nth 7 board) (nth 8 board)))
#+END_SRC

#+TBLNAME: Test
| 3 |   | 2 |   |   |   | 5 |   | 8 |
|   | 9 |   | 3 |   | 5 |   | 6 |   |
| 6 |   |   |   | 7 |   |   |   | 4 |
|---+---+---+---+---+---+---+---+---|
|   | 8 |   | 1 |   | 4 |   | 2 |   |
|   |   | 9 |   |   |   | 8 |   |   |
|   | 2 |   | 6 |   | 9 |   | 5 |   |
|---+---+---+---+---+---+---+---+---|
| 8 |   |   |   | 9 |   |   |   | 5 |
|   | 1 |   | 4 |   | 3 |   | 8 |   |
| 2 |   | 4 |   |   |   | 1 |   | 9 |
#+CALL: export-sudoku(table=Test) :results output silent
#+CALL: import-sudoku() :hlines yes
--8<---------------cut here---------------end--------------->8---

One noteworthy thing: even though I say ":hlines no" (I can also do this
on the call line with the same result), the table still gets exported to
elisp _with_ hlines and I need to filter them out myself.  I'm not sure
if that is intended, but it feels a bit awkward.  If anything, this
exception should be noted in the documentation if it is intentional.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds




reply via email to

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