Add ERT for table alignment within Org buffer
[org-mode.git] / contrib / babel / langs / ob-eukleides.el
blob6696e2f38c2f2d06f9244cfc90db3df49db93ca6
1 ;;; ob-eukleides.el --- org-babel functions for eukleides evaluation
3 ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
5 ;; Author: Luis Anaya
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
26 ;; Org-Babel support for evaluating eukleides script.
28 ;; Inspired by Ian Yang's org-export-blocks-format-eukleides
29 ;; http://www.emacswiki.org/emacs/org-export-blocks-format-eukleides.el
31 ;;; Requirements:
33 ;; eukleides | http://eukleides.org
34 ;; eukleides | `org-eukleides-path' should point to the eukleides executablexs
36 ;;; Code:
37 (require 'ob)
38 (require 'ob-eval)
40 (defvar org-babel-default-header-args:eukleides
41 '((:results . "file") (:exports . "results"))
42 "Default arguments for evaluating a eukleides source block.")
44 (defcustom org-eukleides-path nil
45 "Path to the eukleides executable file."
46 :group 'org-babel
47 :version "24.1"
48 :type 'string)
51 (defcustom org-eukleides-eps-to-raster nil
52 "Command used to convert EPS to raster. Nil for no conversion."
53 :group 'org-babel
54 :type '(choice
55 (repeat :tag "Shell Command Sequence" (string :tag "Shell Command"))
56 (const :tag "sam2p" "a=%s;b=%s;sam2p ${a} ${b}" )
57 (const :tag "NetPNM" "a=%s;b=%s;pstopnm -stdout ${a} | pnmtopng > ${b}" )
58 (const :tag "None" nil)))
61 (defun org-babel-execute:eukleides (body params)
62 "Execute a block of eukleides code with org-babel.
63 This function is called by `org-babel-execute-src-block'."
64 (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
65 (out-file (or (cdr (assoc :file params))
66 (error "Eukleides requires a \":file\" header argument")))
67 (cmdline (cdr (assoc :cmdline params)))
68 (in-file (org-babel-temp-file "eukleides-"))
69 (java (or (cdr (assoc :java params)) ""))
70 (cmd (if (not org-eukleides-path)
71 (error "`org-eukleides-path' is not set")
72 (concat (expand-file-name org-eukleides-path)
73 " -b --output="
74 (org-babel-process-file-name
75 (concat
76 (file-name-sans-extension out-file) ".eps"))
77 " "
78 (org-babel-process-file-name in-file)))))
79 (unless (file-exists-p org-eukleides-path)
80 (error "Could not find eukleides at %s" org-eukleides-path))
82 (if (string= (file-name-extension out-file) "png")
83 (if org-eukleides-eps-to-raster
84 (shell-command (format org-eukleides-eps-to-raster
85 (concat (file-name-sans-extension out-file) ".eps")
86 (concat (file-name-sans-extension out-file) ".png")))
87 (error "Conversion to PNG not supported. use a file with an EPS name")))
89 (with-temp-file in-file (insert body))
90 (message "%s" cmd) (org-babel-eval cmd "")
91 nil)) ;; signal that output has already been written to file
93 (defun org-babel-prep-session:eukleides (session params)
94 "Return an error because eukleides does not support sessions."
95 (error "Eukleides does not support sessions"))
97 (provide 'ob-eukleides)
101 ;;; ob-eukleides.el ends here