From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Bach Subject: Import files to babel blocks Date: Sun, 21 Jul 2013 10:41:37 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V0pDG-0008Gd-Qv for emacs-orgmode@gnu.org; Sun, 21 Jul 2013 04:41:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V0pDF-0004Bg-S7 for emacs-orgmode@gnu.org; Sun, 21 Jul 2013 04:41:54 -0400 Received: from plane.gmane.org ([80.91.229.3]:44698) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V0pDF-0004BF-L3 for emacs-orgmode@gnu.org; Sun, 21 Jul 2013 04:41:53 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1V0pDE-0005tL-Kx for emacs-orgmode@gnu.org; Sun, 21 Jul 2013 10:41:52 +0200 Received: from 194.112.182.214 ([194.112.182.214]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Jul 2013 10:41:52 +0200 Received: from phaebz by 194.112.182.214 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Jul 2013 10:41:52 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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