1 ;;; ob-vala.el --- Babel functions for Vala evaluation -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017 Free Software Foundation, Inc.
5 ;; Author: Christian Garbs <mitch@cgarbs.de>
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
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/>.
26 ;; ob-vala.el provides Babel support for the Vala language
27 ;; (see http://live.gnome.org/Vala for details)
31 ;; - Vala compiler binary (valac)
32 ;; - Vala development environment (Vala libraries etc.)
34 ;; vala-mode.el is nice to have for code formatting, but is not needed
41 (declare-function org-trim
"org" (s &optional keep-lead
))
44 (add-to-list 'org-babel-tangle-lang-exts
'("vala" .
"vala"))
46 ;; Header arguments empty by default.
47 (defvar org-babel-default-header-args
:vala
'())
49 (defcustom org-babel-vala-compiler
"valac"
50 "Command used to compile a C source code file into an executable.
51 May be either a command in the path, like \"valac\"
52 or an absolute path name, like \"/usr/local/bin/valac\".
53 Parameters may be used like this: \"valac -v\""
56 :package-version
'(Org .
"9.1")
59 ;; This is the main function which is called to evaluate a code
62 ;; - run Vala compiler and create a binary in a temporary file
63 ;; - compiler/linker flags can be set via :flags header argument
64 ;; - if compilation succeeded, run the binary
65 ;; - commandline parameters to the binary can be set via :cmdline
67 ;; - stdout will be parsed as RESULT (control via :result-params
70 ;; There is no session support because Vala is a compiled language.
72 ;; This function is heavily based on ob-C.el
73 (defun org-babel-execute:vala
(body params
)
74 "Execute a block of Vala code with Babel.
75 This function is called by `org-babel-execute-src-block'."
76 (message "executing Vala source code block")
77 (let* ((tmp-src-file (org-babel-temp-file
80 (tmp-bin-file (org-babel-temp-file "vala-bin-" org-babel-exeext
))
81 (cmdline (cdr (assq :cmdline params
)))
82 (flags (cdr (assq :flags params
))))
83 (with-temp-file tmp-src-file
(insert body
))
85 (format "%s %s -o %s %s"
86 org-babel-vala-compiler
88 (if (listp flags
) flags
(list flags
)) " ")
89 (org-babel-process-file-name tmp-bin-file
)
90 (org-babel-process-file-name tmp-src-file
)) "")
91 (when (file-executable-p tmp-bin-file
)
95 (concat tmp-bin-file
(if cmdline
(concat " " cmdline
) "")) ""))))
96 (org-babel-reassemble-table
97 (org-babel-result-cond (cdr (assq :result-params params
))
98 (org-babel-read results
)
99 (let ((tmp-file (org-babel-temp-file "vala-")))
100 (with-temp-file tmp-file
(insert results
))
101 (org-babel-import-elisp-from-file tmp-file
)))
103 (cdr (assq :colname-names params
)) (cdr (assq :colnames params
)))
105 (cdr (assq :rowname-names params
)) (cdr (assq :rownames params
))))))))
107 (defun org-babel-prep-session:vala
(_session _params
)
109 This function does nothing as Vala is a compiled language with no
110 support for sessions."
111 (error "Vala is a compiled language -- no support for sessions"))
115 ;;; ob-vala.el ends here