Release 7.01
[org-mode.git] / lisp / ob-dot.el
blob4657fb80ba0330f81bf2cae53941382732c49465
1 ;;; ob-dot.el --- org-babel functions for dot evaluation
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5 ;; Author: Eric Schulte
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
8 ;; Version: 7.01
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Org-Babel support for evaluating dot source code.
29 ;; For information on dot see http://www.graphviz.org/
31 ;; This differs from most standard languages in that
33 ;; 1) there is no such thing as a "session" in dot
35 ;; 2) we are generally only going to return results of type "file"
37 ;; 3) we are adding the "file" and "cmdline" header arguments
39 ;; 4) there are no variables (at least for now)
41 ;;; Code:
42 (require 'ob)
43 (require 'ob-eval)
45 (defvar org-babel-default-header-args:dot
46 '((:results . "file") (:exports . "results"))
47 "Default arguments to use when evaluating a dot source block.")
49 (defun org-babel-expand-body:dot (body params &optional processed-params)
50 "Expand BODY according to PARAMS, return the expanded body."
51 (let ((vars (nth 1 (or processed-params
52 (org-babel-process-params params)))))
53 (mapc
54 (lambda (pair)
55 (let ((name (symbol-name (car pair)))
56 (value (cdr pair)))
57 (setq body
58 (replace-regexp-in-string
59 (concat "\$" (regexp-quote name))
60 (if (stringp value) value (format "%S" value))
61 body))))
62 vars)
63 body))
65 (defun org-babel-execute:dot (body params)
66 "Execute a block of Dot code with org-babel.
67 This function is called by `org-babel-execute-src-block'."
68 (let ((processed-params (org-babel-process-params params))
69 (result-params (split-string (or (cdr (assoc :results params)) "")))
70 (out-file (cdr (assoc :file params)))
71 (cmdline (cdr (assoc :cmdline params)))
72 (cmd (or (cdr (assoc :cmd params)) "dot"))
73 (in-file (make-temp-file "org-babel-dot")))
74 (with-temp-file in-file
75 (insert (org-babel-expand-body:dot body params processed-params)))
76 (org-babel-eval (concat cmd " " in-file " " cmdline " -o " out-file) "")
77 out-file))
79 (defun org-babel-prep-session:dot (session params)
80 "Return an error because Dot does not support sessions."
81 (error "Dot does not support sessions"))
83 (provide 'ob-dot)
85 ;; arch-tag: 817d0516-7b47-4f77-a8b2-2aadd8e4d0e2
87 ;;; ob-dot.el ends here