Cleaner implementation of org-babel-execute:babel.
[org-mode.git] / lisp / org-babel-lob.el
blob9be2404650929645007aa266311b46b28fa90eb1
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
8 ;; Version: 0.01
10 ;;; License:
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)
15 ;; any later version.
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.
27 ;;; Commentary:
29 ;; See org-babel.org in the parent directory for more information
31 ;;; Code:
32 (require 'org-babel)
34 (org-babel-add-interpreter "babel")
36 (setq org-babel-library-of-babel
37 (progn (set-buffer
38 (find-file-noselect "../library-of-babel.org"))
39 (org-babel-get-all-src-block-infos)))
41 (defun org-babel-execute:babel (body params)
42 "Execute a library-of-babel block.
44 These blocks do not have their own body. Instead they use
45 a :srcname header argument to reference a different source
46 block, whose body they use. Source blocks in the library of
47 babel should use a standard naming scheme for the variable
48 containing the input data for analysis / plotting. E.g. if that
49 variable is always called __data__ then one of these bodyless
50 babel blocks will call a library of babel block using :var
51 __data__=<some reference>. The header args from a babel block
52 are appended to the header args from the target block.
54 This function is called by `org-babel-execute-src-block'."
55 (message "executing babel source code block...")
56 (save-window-excursion
57 (let* ((srcname (cdr (assoc :srcname params)))
58 (info (or (save-excursion
59 (goto-char (org-babel-find-named-block srcname))
60 (org-babel-get-src-block-info))
61 (gethash srcname org-babel-library-of-babel))))
62 (org-babel-execute-src-block nil info params))))
64 (provide 'org-babel-lob)