ob-dot.el 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ;;; ob-dot.el --- org-babel functions for dot evaluation
  2. ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs 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 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; Org-Babel support for evaluating dot source code.
  20. ;;
  21. ;; For information on dot see http://www.graphviz.org/
  22. ;;
  23. ;; This differs from most standard languages in that
  24. ;;
  25. ;; 1) there is no such thing as a "session" in dot
  26. ;;
  27. ;; 2) we are generally only going to return results of type "file"
  28. ;;
  29. ;; 3) we are adding the "file" and "cmdline" header arguments
  30. ;;
  31. ;; 4) there are no variables (at least for now)
  32. ;;; Code:
  33. (require 'ob)
  34. (require 'ob-eval)
  35. (defvar org-babel-default-header-args:dot
  36. '((:results . "file") (:exports . "results"))
  37. "Default arguments to use when evaluating a dot source block.")
  38. (defun org-babel-expand-body:dot (body params &optional processed-params)
  39. "Expand BODY according to PARAMS, return the expanded body." body)
  40. (defun org-babel-execute:dot (body params)
  41. "Execute a block of Dot code with org-babel.
  42. This function is called by `org-babel-execute-src-block'."
  43. (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
  44. (out-file (cdr (assoc :file params)))
  45. (cmdline (cdr (assoc :cmdline params)))
  46. (cmd (or (cdr (assoc :cmd params)) "dot"))
  47. (in-file (make-temp-file "org-babel-dot")))
  48. (with-temp-file in-file (insert body))
  49. (org-babel-eval (concat cmd " " in-file " " cmdline " -o " out-file) "")
  50. out-file))
  51. (defun org-babel-prep-session:dot (session params)
  52. "Return an error because Dot does not support sessions."
  53. (error "Dot does not support sessions"))
  54. (provide 'ob-dot)
  55. ;; arch-tag: 817d0516-7b47-4f77-a8b2-2aadd8e4d0e2
  56. ;;; ob-dot.el ends here