Remove `org<>' function
[org-mode/org-tableheadings.git] / lisp / ob-vala.el
blob96c37e3ad08f24de679e41b7b54995dc95b32b84
1 ;;; ob-vala.el --- Babel functions for Vala evaluation -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017-2018 Free Software Foundation, Inc.
5 ;; Author: Christian Garbs <mitch@cgarbs.de>
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: https://orgmode.org
9 ;;; License:
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
26 ;;; Commentary:
28 ;; ob-vala.el provides Babel support for the Vala language
29 ;; (see http://live.gnome.org/Vala for details)
31 ;;; Requirements:
33 ;; - Vala compiler binary (valac)
34 ;; - Vala development environment (Vala libraries etc.)
36 ;; vala-mode.el is nice to have for code formatting, but is not needed
37 ;; for ob-vala.el
39 ;;; Code:
41 (require 'ob)
43 (declare-function org-trim "org" (s &optional keep-lead))
45 ;; File extension.
46 (add-to-list 'org-babel-tangle-lang-exts '("vala" . "vala"))
48 ;; Header arguments empty by default.
49 (defvar org-babel-default-header-args:vala '())
51 (defcustom org-babel-vala-compiler "valac"
52 "Command used to compile a C source code file into an executable.
53 May be either a command in the path, like \"valac\"
54 or an absolute path name, like \"/usr/local/bin/valac\".
55 Parameters may be used like this: \"valac -v\""
56 :group 'org-babel
57 :version "26.1"
58 :package-version '(Org . "9.1")
59 :type 'string)
61 ;; This is the main function which is called to evaluate a code
62 ;; block.
64 ;; - run Vala compiler and create a binary in a temporary file
65 ;; - compiler/linker flags can be set via :flags header argument
66 ;; - if compilation succeeded, run the binary
67 ;; - commandline parameters to the binary can be set via :cmdline
68 ;; header argument
69 ;; - stdout will be parsed as RESULT (control via :result-params
70 ;; header argument)
72 ;; There is no session support because Vala is a compiled language.
74 ;; This function is heavily based on ob-C.el
75 (defun org-babel-execute:vala (body params)
76 "Execute a block of Vala code with Babel.
77 This function is called by `org-babel-execute-src-block'."
78 (message "executing Vala source code block")
79 (let* ((tmp-src-file (org-babel-temp-file
80 "vala-src-"
81 ".vala"))
82 (tmp-bin-file (org-babel-temp-file "vala-bin-" org-babel-exeext))
83 (cmdline (cdr (assq :cmdline params)))
84 (flags (cdr (assq :flags params))))
85 (with-temp-file tmp-src-file (insert body))
86 (org-babel-eval
87 (format "%s %s -o %s %s"
88 org-babel-vala-compiler
89 (mapconcat #'identity
90 (if (listp flags) flags (list flags)) " ")
91 (org-babel-process-file-name tmp-bin-file)
92 (org-babel-process-file-name tmp-src-file)) "")
93 (when (file-executable-p tmp-bin-file)
94 (let ((results
95 (org-trim
96 (org-babel-eval
97 (concat tmp-bin-file (if cmdline (concat " " cmdline) "")) ""))))
98 (org-babel-reassemble-table
99 (org-babel-result-cond (cdr (assq :result-params params))
100 (org-babel-read results)
101 (let ((tmp-file (org-babel-temp-file "vala-")))
102 (with-temp-file tmp-file (insert results))
103 (org-babel-import-elisp-from-file tmp-file)))
104 (org-babel-pick-name
105 (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
106 (org-babel-pick-name
107 (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
109 (defun org-babel-prep-session:vala (_session _params)
110 "Prepare a session.
111 This function does nothing as Vala is a compiled language with no
112 support for sessions."
113 (error "Vala is a compiled language -- no support for sessions"))
115 (provide 'ob-vala)
117 ;;; ob-vala.el ends here