Просмотр исходного кода

library-of-babel: more control over exporting results to files

  #+source: table
  #+begin_src emacs-lisp
    (mapcar
     (lambda (el) (number-sequence el (+ el 3)))
     (number-sequence 0 4))
  #+end_src

  writes the results out as csv file
  #+call: write(data=table, file="~/Desktop/example.csv") :results silent

  writes the results out as tab separated file
  #+call: write(data=table, file="~/Desktop/example.tsv") :results silent

  write the results out as a normal org-mode file
  #+call: write(data=table, file="~/Desktop/example.org") :results silent

* contrib/babel/library-of-babel.org: more control over exporting
  results to files
Eric Schulte 14 лет назад
Родитель
Сommit
25ac9ea8dd
1 измененных файлов с 8 добавлено и 3 удалено
  1. 8 3
      contrib/babel/library-of-babel.org

+ 8 - 3
contrib/babel/library-of-babel.org

@@ -46,9 +46,14 @@ file as either a table or a string.
 Write =data= to a file at =file=.  If =data= is a list, then write it
 as a table in traditional Org-mode table syntax.
 #+srcname: write
-#+begin_src emacs-lisp :var data="" :var file=""
-  (with-temp-file file
-    (org-babel-insert-result data))
+#+begin_src emacs-lisp :var data="" :var file="" :var ext='()
+  (flet ((echo (r) (if (stringp r) r (format "%S" r))))
+    (with-temp-file file
+      (case (and (listp data)
+                 (or ext (intern (file-name-extension file))))
+        ('tsv (insert (orgtbl-to-tsv data '(:fmt echo))))
+        ('csv (insert (orgtbl-to-csv data '(:fmt echo))))
+        (t    (org-babel-insert-result data)))))
   nil
 #+end_src