org-babel-lob.el 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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)
  26. (defun org-babel-execute:babel (body params)
  27. "Execute a library-of-babel block.
  28. These blocks do not have their own body. Instead they use a :srcname
  29. header argument to reference a different source block, whose body
  30. they use. Source blocks in the library of babel should use a
  31. standard naming scheme for the variable containing the input data
  32. for analysis / plotting. E.g. if that variable is always called
  33. __data__ then one of these bodyless babel blocks will call a library
  34. of babel block using :var __data__=<some reference>
  35. This function is called by `org-babel-execute-src-block'."
  36. (message "executing babel source code block...")
  37. (save-window-excursion
  38. (let ((srcname (cdr (assoc :srcname params))))
  39. ;; now locate the source block specified by srcname (it might be
  40. ;; in the library of babel), and construct a new source block
  41. ;; as follows:
  42. ;;
  43. ;; 1. The lang is the lang of the referenced source block
  44. ;; 2. The header args are those from the current #+begin_src babel block
  45. ;; 3. The body is from the reference source block
  46. ;; If using a library of babel function, then the
  47. ;; resposnsibility id on the caller to name the :var arg(s)
  48. ;; correctly. We could adopt a standard name such as __data__
  49. ;; for the input data for plotting / analysis. Thus in lob
  50. ;; source blocks the data variable would be referred to as
  51. ;; __data__ in the code, and the babel block would use :var
  52. ;; __data__=<some reference>
  53. ;; Now execute the constructed source block, ensuring that this
  54. ;; buffer receives the appropriate output, and only receives a
  55. ;; copy of the referenced source block if requested
  56. )))
  57. (provide 'org-babel-lob)