ob-dot.el 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: 7.01trans
  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."
  40. (let ((vars (nth 1 (or processed-params
  41. (org-babel-process-params params)))))
  42. (mapc
  43. (lambda (pair)
  44. (let ((name (symbol-name (car pair)))
  45. (value (cdr pair)))
  46. (setq body
  47. (replace-regexp-in-string
  48. (concat "\$" (regexp-quote name))
  49. (if (stringp value) value (format "%S" value))
  50. body))))
  51. vars)
  52. body))
  53. (defun org-babel-execute:dot (body params)
  54. "Execute a block of Dot code with org-babel.
  55. This function is called by `org-babel-execute-src-block'."
  56. (let ((processed-params (org-babel-process-params params))
  57. (result-params (split-string (or (cdr (assoc :results params)) "")))
  58. (out-file (cdr (assoc :file params)))
  59. (cmdline (cdr (assoc :cmdline params)))
  60. (cmd (or (cdr (assoc :cmd params)) "dot"))
  61. (in-file (make-temp-file "org-babel-dot")))
  62. (with-temp-file in-file
  63. (insert (org-babel-expand-body:dot body params processed-params)))
  64. (org-babel-eval (concat cmd " " in-file " " cmdline " -o " out-file) "")
  65. out-file))
  66. (defun org-babel-prep-session:dot (session params)
  67. "Return an error because Dot does not support sessions."
  68. (error "Dot does not support sessions"))
  69. (provide 'ob-dot)
  70. ;; arch-tag: 817d0516-7b47-4f77-a8b2-2aadd8e4d0e2
  71. ;;; ob-dot.el ends here