org-babel-lob.el 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. (defun org-babel-execute:babel (body params)
  28. "Execute a library-of-babel block.
  29. These blocks do not have their own body. Instead they use
  30. a :srcname header argument to reference a different source
  31. block, whose body they use. Source blocks in the library of
  32. babel should use a standard naming scheme for the variable
  33. containing the input data for analysis / plotting. E.g. if that
  34. variable is always called __data__ then one of these bodyless
  35. babel blocks will call a library of babel block using :var
  36. __data__=<some reference>. The header args from a babel block
  37. are appended to the header args from the target block.
  38. This function is called by `org-babel-execute-src-block'."
  39. (message "executing babel source code block...")
  40. (save-window-excursion
  41. (save-excursion
  42. (org-babel-goto-srcname (cdr (assoc :srcname params))))
  43. (forward-line 1)
  44. (insert (match-string 0))
  45. (org-babel-execute-src-block nil nil params)))
  46. (defun org-babel-lob-parse-buffer ()
  47. "Read all source-code blocks in buffer into memory."
  48. (save-excursion
  49. (goto-char (point-min))
  50. (let ((blocks (make-hash-table)))
  51. (while (re-search-forward
  52. org-babel-named-src-block-regexp nil t)
  53. (puthash (match-string-no-properties 1) ;; srcname
  54. (list (cons :lang (match-string-no-properties 2))
  55. (cons :body (match-string-no-properties 3))
  56. (cons :params (match-string-no-properties 4)))
  57. blocks))
  58. blocks)))
  59. (provide 'org-babel-lob)