1 ;;; org-babel-lob.el --- The Library of Babel: off-the-shelf functions for data analysis and plotting using org-babel
3 ;; Copyright (C) 2009 Dan Davison, Eric Schulte
5 ;; Author: Dan Davison, Eric Schulte
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; See org-babel.org in the parent directory for more information
34 (org-babel-add-interpreter "babel")
36 (defun org-babel-execute:babel
(body params
)
37 "Execute a library-of-babel block.
39 These blocks do not have their own body. Instead they use
40 a :srcname header argument to reference a different source
41 block, whose body they use. Source blocks in the library of
42 babel should use a standard naming scheme for the variable
43 containing the input data for analysis / plotting. E.g. if that
44 variable is always called __data__ then one of these bodyless
45 babel blocks will call a library of babel block using :var
46 __data__=<some reference>. The header args from a babel block
47 are appended to the header args from the target block.
49 This function is called by `org-babel-execute-src-block'."
50 (message "executing babel source code block...")
51 (save-window-excursion
53 (org-babel-goto-srcname (cdr (assoc :srcname params
))))
55 (insert (match-string 0))
56 (org-babel-execute-src-block nil nil params
)))
58 (defun org-babel-lob-parse-buffer ()
59 "Read all source-code blocks in buffer into memory."
61 (goto-char (point-min))
62 (let ((blocks (make-hash-table)))
63 (while (re-search-forward
64 org-babel-named-src-block-regexp nil t
)
65 (puthash (match-string-no-properties 1) ;; srcname
66 (list (cons :lang
(match-string-no-properties 2))
67 (cons :body
(match-string-no-properties 3))
68 (cons :params
(match-string-no-properties 4)))
72 (provide 'org-babel-lob
)