emacs-orgmode
[Top][All Lists]
Advanced

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

[O] Import files to babel blocks


From: Michael Bach
Subject: [O] Import files to babel blocks
Date: Sun, 21 Jul 2013 10:41:37 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7

Dear org-mode Users and Developers,

I am trying to write a simple function for importing files to org-mode
babel code blocks.

My naive approach was

--8<---------------cut here---------------start------------->8---
(defun import-to-org-from-files (path pattern progmode)
  (mapcar #'(lambda (filepath)
              (progn
                (insert (format
                         "\n#+name: %s\n" (file-name-nondirectory
                                           (file-name-sans-extension
                                            filepath))))
                (insert (format "#+begin_src: %s :eval no\n" progmode))
                (insert-file-contents filepath)
                (insert "\n#+end_src\n"))
              )
          (directory-files path t pattern)))
--8<---------------cut here---------------end--------------->8---

to be called e.g. like this

--8<---------------cut here---------------start------------->8---
(import-to-org-from-files "/path/to/scripts/" ".*\.sh$" "sh")
--8<---------------cut here---------------end--------------->8---


This leads to all babel code blocks being inserted empty and all file
content inserted afterwards, i.e. the `insert-file-contents' is somehow
delayed until all `insert's have happened.

Maybe this is just related to my misunderstanding of the involved elisp,
but I am posting it here since I am sure someone must have thought about
this import. Or is there even an org-mode builtin that can be used?

Best Regards,
Michael





reply via email to

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