org-babel-lob.el 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;;; org-babel-lob.el --- The Library of Babel: off-the-shelf functions for data analysis and plotting using org-babel
  2. ;; Copyright (C) 2009 Dan Davison, Eric Schulte
  3. ;; Author: Dan Davison, Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; See org-babel.org in the parent directory for more information
  24. ;;; Code:
  25. (require 'org-babel)
  26. (org-babel-add-interpreter "babel")
  27. (setq org-babel-library-of-babel
  28. (progn (set-buffer
  29. (find-file-noselect "../library-of-babel.org"))
  30. (org-babel-get-all-src-block-infos)))
  31. (defun org-babel-execute:babel (body params)
  32. "Execute a library-of-babel block.
  33. These blocks do not have their own body. Instead they use
  34. a :srcname header argument to reference a different source
  35. block, whose body they use. Source blocks in the library of
  36. babel should use a standard naming scheme for the variable
  37. containing the input data for analysis / plotting. E.g. if that
  38. variable is always called __data__ then one of these bodyless
  39. babel blocks will call a library of babel block using :var
  40. __data__=<some reference>. The header args from a babel block
  41. are appended to the header args from the target block.
  42. This function is called by `org-babel-execute-src-block'."
  43. (message "executing babel source code block...")
  44. (save-window-excursion
  45. (let* ((srcname (cdr (assoc :srcname params)))
  46. (info (or (save-excursion
  47. (goto-char (org-babel-find-named-block srcname))
  48. (org-babel-get-src-block-info))
  49. (gethash srcname org-babel-library-of-babel))))
  50. (org-babel-execute-src-block nil info params))))
  51. (provide 'org-babel-lob)