article 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From: "Eric H. Neilsen, Jr." <neilsen@fnal.gov>
  2. Subject: [Orgmode] A tool for creating source code files from example and src blocks in org files
  3. To: emacs-orgmode@gnu.org
  4. Date: Tue, 02 Jun 2009 13:50:58 -0500
  5. Hi,
  6. First, thank you Carsten and others, for putting this thing together;
  7. org-mode is the most useful tool I've run across in a long time.
  8. I recently put together a few commands to create source code files
  9. from SRC and EXAMPLE blocks in org-mode files. The original idea is to
  10. be able to compile examples in my notes without needing to merge them
  11. into a separate source file by hand. As I was writing it I realized
  12. this is exactly the same tool one needs to turn org-mode into a
  13. literate programming tool (see http://www.literateprogramming.com/ ),
  14. so I adopted some of the nomenclature. (I tried literate programming a
  15. few years ago, and gave up in frustration with the tools. I am tempted
  16. to try again with org-mode.)
  17. The two user level commands are org-tangle and org-untangle, best
  18. explained through example. Running org-tangle in a buffer that looks
  19. like this:
  20. ---------------------- begin /tmp/test.org ---------------------------
  21. * Some file
  22. Some text here
  23. #+CHUNK file1.sh 1
  24. #+BEGIN_SRC bash
  25. echo "line 1"
  26. echo "line 2"
  27. #+END_SRC
  28. more text
  29. ** Some subsection
  30. #+CHUNK file1.sh 2
  31. #+BEGIN_SRC bash
  32. echo "line 5"
  33. echo "line 6"
  34. #+END_SRC
  35. blah blah blah
  36. #+CHUNK README.txt 1
  37. #+BEGIN_EXAMPLE
  38. text line 1
  39. text line 2
  40. text line 3
  41. #+END_EXAMPLE
  42. foo foo bar baz
  43. #+CHUNK file1.sh 1.5
  44. #+BEGIN_SRC bash
  45. echo "line 3"
  46. echo "line 4"
  47. #+END_SRC
  48. -------------- end /tmp/test.org ----------------
  49. results in the creation of these two files, opened in emacs buffers:
  50. ------------- begin /tmp/file1.sh ----------------
  51. # ORGCHUNK /tmp/test.org 1
  52. echo "line 1"
  53. echo "line 2"
  54. # ORGCHUNK /tmp/test.org 1.5
  55. echo "line 3"
  56. echo "line 4"
  57. # ORGCHUNK /tmp/test.org 2
  58. echo "line 5"
  59. echo "line 6"
  60. ------------- end /tmp/file1.sh ---------------------
  61. and
  62. ------------ begin /tmp/README.txt -------------
  63. text line 1
  64. text line 2
  65. text line 3
  66. ------------ end /tmp/README.txt ---------------
  67. If you then edit file1.sh and run org-untangle in the buffer, changes
  68. to it will overwrite the literal blocks in the org-mode file from
  69. whence they came.
  70. Is there any interest in this? My organization's rules for releasing
  71. code to open source projects are being revised, but I am likely to be
  72. able to do so under a BSD-like license. If there is interest, I will
  73. push to try and figure out how to do this, and maybe even see if I can
  74. do the assignment of copyright stuff needed for it to get under the
  75. main umbrella (although I am not optimistic).
  76. (If anyone feels like rewriting it, that would be even better; aside
  77. from a fairly straightforward .emacs, this is my first ever lisp code,
  78. so it is likely to need cleaning and refactoring.)
  79. -Eric
  80. --
  81. Eric H. Neilsen, Jr.
  82. http://home.fnal.gov/~neilsen
  83. _______________________________________________
  84. Emacs-orgmode mailing list
  85. Remember: use `Reply All' to send replies to the list.
  86. Emacs-orgmode@gnu.org
  87. http://lists.gnu.org/mailman/listinfo/emacs-orgmode