From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric H. Neilsen, Jr." Subject: A tool for creating source code files from example and src blocks in org files Date: Tue, 02 Jun 2009 13:50:58 -0500 Message-ID: <4A257492.5030300@fnal.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7BIT Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MBZ4i-0007X4-Ux for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 14:51:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MBZ4e-0007QQ-9I for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 14:51:04 -0400 Received: from [199.232.76.173] (port=35159 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBZ4d-0007Q8-PM for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 14:50:59 -0400 Received: from mailgw1.fnal.gov ([131.225.111.11]:41338) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MBZ4d-0002PR-8w for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 14:50:59 -0400 Received: from mailav1.fnal.gov (mailav1.fnal.gov [131.225.111.18]) by mailgw1.fnal.gov (iPlanet Messaging Server 5.2 HotFix 2.06 (built Mar 28 2005)) with SMTP id <0KKM004V6KCUFY@mailgw1.fnal.gov> for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 13:50:58 -0500 (CDT) Received: from mailgw1.fnal.gov ([131.225.111.11]) by mailav1.fnal.gov (SAVSMTP 3.1.7.47) with SMTP id M2009060213505813933 for ; Tue, 02 Jun 2009 13:50:58 -0500 Received: from conversion-daemon.mailgw1.fnal.gov by mailgw1.fnal.gov (iPlanet Messaging Server 5.2 HotFix 2.06 (built Mar 28 2005)) id <0KKM00J01KB8LR@mailgw1.fnal.gov> (original mail from neilsen@fnal.gov) for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 13:50:58 -0500 (CDT) Received: from sdsslnx33.fnal.gov (sdsslnx33.fnal.gov [131.225.7.7]) by mailgw1.fnal.gov (iPlanet Messaging Server 5.2 HotFix 2.06 (built Mar 28 2005)) with ESMTPSA id <0KKM00ESQKCY6L@mailgw1.fnal.gov> for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 13:50:58 -0500 (CDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi, First, thank you Carsten and others, for putting this thing together; org-mode is the most useful tool I've run across in a long time. I recently put together a few commands to create source code files from SRC and EXAMPLE blocks in org-mode files. The original idea is to be able to compile examples in my notes without needing to merge them into a separate source file by hand. As I was writing it I realized this is exactly the same tool one needs to turn org-mode into a literate programming tool (see http://www.literateprogramming.com/ ), so I adopted some of the nomenclature. (I tried literate programming a few years ago, and gave up in frustration with the tools. I am tempted to try again with org-mode.) The two user level commands are org-tangle and org-untangle, best explained through example. Running org-tangle in a buffer that looks like this: ---------------------- begin /tmp/test.org --------------------------- * Some file Some text here #+CHUNK file1.sh 1 #+BEGIN_SRC bash echo "line 1" echo "line 2" #+END_SRC more text ** Some subsection #+CHUNK file1.sh 2 #+BEGIN_SRC bash echo "line 5" echo "line 6" #+END_SRC blah blah blah #+CHUNK README.txt 1 #+BEGIN_EXAMPLE text line 1 text line 2 text line 3 #+END_EXAMPLE foo foo bar baz #+CHUNK file1.sh 1.5 #+BEGIN_SRC bash echo "line 3" echo "line 4" #+END_SRC -------------- end /tmp/test.org ---------------- results in the creation of these two files, opened in emacs buffers: ------------- begin /tmp/file1.sh ---------------- # ORGCHUNK /tmp/test.org 1 echo "line 1" echo "line 2" # ORGCHUNK /tmp/test.org 1.5 echo "line 3" echo "line 4" # ORGCHUNK /tmp/test.org 2 echo "line 5" echo "line 6" ------------- end /tmp/file1.sh --------------------- and ------------ begin /tmp/README.txt ------------- text line 1 text line 2 text line 3 ------------ end /tmp/README.txt --------------- If you then edit file1.sh and run org-untangle in the buffer, changes to it will overwrite the literal blocks in the org-mode file from whence they came. Is there any interest in this? My organization's rules for releasing code to open source projects are being revised, but I am likely to be able to do so under a BSD-like license. If there is interest, I will push to try and figure out how to do this, and maybe even see if I can do the assignment of copyright stuff needed for it to get under the main umbrella (although I am not optimistic). (If anyone feels like rewriting it, that would be even better; aside from a fairly straightforward .emacs, this is my first ever lisp code, so it is likely to need cleaning and refactoring.) -Eric -- Eric H. Neilsen, Jr. http://home.fnal.gov/~neilsen