Commit | Line | Data |
---|---|---|
86fbb8ca CD |
1 | ;;; ob-dot.el --- org-babel functions for dot evaluation |
2 | ||
ab422c4d | 3 | ;; Copyright (C) 2009-2013 Free Software Foundation, Inc. |
86fbb8ca CD |
4 | |
5 | ;; Author: Eric Schulte | |
6 | ;; Keywords: literate programming, reproducible research | |
7 | ;; Homepage: http://orgmode.org | |
86fbb8ca CD |
8 | |
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation, either version 3 of the License, or | |
14 | ;; (at your option) any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 | ||
24 | ;;; Commentary: | |
25 | ||
26 | ;; Org-Babel support for evaluating dot source code. | |
27 | ;; | |
28 | ;; For information on dot see http://www.graphviz.org/ | |
29 | ;; | |
30 | ;; This differs from most standard languages in that | |
31 | ;; | |
32 | ;; 1) there is no such thing as a "session" in dot | |
33 | ;; | |
34 | ;; 2) we are generally only going to return results of type "file" | |
35 | ;; | |
36 | ;; 3) we are adding the "file" and "cmdline" header arguments | |
37 | ;; | |
38 | ;; 4) there are no variables (at least for now) | |
39 | ||
40 | ;;; Code: | |
41 | (require 'ob) | |
42 | (require 'ob-eval) | |
43 | ||
44 | (defvar org-babel-default-header-args:dot | |
45 | '((:results . "file") (:exports . "results")) | |
46 | "Default arguments to use when evaluating a dot source block.") | |
47 | ||
afe98dfa | 48 | (defun org-babel-expand-body:dot (body params) |
86fbb8ca | 49 | "Expand BODY according to PARAMS, return the expanded body." |
afe98dfa | 50 | (let ((vars (mapcar #'cdr (org-babel-get-header params :var)))) |
86fbb8ca CD |
51 | (mapc |
52 | (lambda (pair) | |
53 | (let ((name (symbol-name (car pair))) | |
54 | (value (cdr pair))) | |
55 | (setq body | |
56 | (replace-regexp-in-string | |
57 | (concat "\$" (regexp-quote name)) | |
58 | (if (stringp value) value (format "%S" value)) | |
59 | body)))) | |
60 | vars) | |
61 | body)) | |
62 | ||
63 | (defun org-babel-execute:dot (body params) | |
64 | "Execute a block of Dot code with org-babel. | |
65 | This function is called by `org-babel-execute-src-block'." | |
afe98dfa | 66 | (let* ((result-params (cdr (assoc :result-params params))) |
8223b1d2 BG |
67 | (out-file (cdr (or (assoc :file params) |
68 | (error "You need to specify a :file parameter")))) | |
afe98dfa CD |
69 | (cmdline (or (cdr (assoc :cmdline params)) |
70 | (format "-T%s" (file-name-extension out-file)))) | |
71 | (cmd (or (cdr (assoc :cmd params)) "dot")) | |
72 | (in-file (org-babel-temp-file "dot-"))) | |
86fbb8ca | 73 | (with-temp-file in-file |
afe98dfa CD |
74 | (insert (org-babel-expand-body:dot body params))) |
75 | (org-babel-eval | |
76 | (concat cmd | |
77 | " " (org-babel-process-file-name in-file) | |
78 | " " cmdline | |
79 | " -o " (org-babel-process-file-name out-file)) "") | |
3ab2c837 | 80 | nil)) ;; signal that output has already been written to file |
86fbb8ca CD |
81 | |
82 | (defun org-babel-prep-session:dot (session params) | |
83 | "Return an error because Dot does not support sessions." | |
84 | (error "Dot does not support sessions")) | |
85 | ||
86 | (provide 'ob-dot) | |
87 | ||
5b409b39 | 88 | |
86fbb8ca CD |
89 | |
90 | ;;; ob-dot.el ends here |