From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Garbs Subject: [PATCH v2] ob-vala.el: Add Vala support to Babel Date: Tue, 1 Aug 2017 00:04:34 +0200 Message-ID: <20170801212016.7264C2DB@fluttershy.mitch.h.shuttle.de> References: <87379no75t.fsf@nicolasgoaziou.fr> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dceae-0004qu-Gs for emacs-orgmode@gnu.org; Tue, 01 Aug 2017 17:20:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dceab-0008Qx-B9 for emacs-orgmode@gnu.org; Tue, 01 Aug 2017 17:20:32 -0400 Received: from mail.shuttle.de ([194.95.249.4]:46474) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dceaa-0008Mv-Vf for emacs-orgmode@gnu.org; Tue, 01 Aug 2017 17:20:29 -0400 Received: from yggdrasil.mitch.h.shuttle.de (p2E5B4CF4.dip0.t-ipconnect.de [46.91.76.244]) by mspool3.srv.dfn.de (Postfix) with ESMTPSA id C20371244 for ; Tue, 1 Aug 2017 23:20:17 +0200 (CEST) Received: from fluttershy.mitch.h.shuttle.de ([192.168.0.132]) by yggdrasil.mitch.h.shuttle.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1dceaO-0007Z8-Ge for emacs-orgmode@gnu.org; Tue, 01 Aug 2017 23:20:16 +0200 In-Reply-To: <87379no75t.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org * ob-vala.el: Add support for the Vala language to Babel. --- lisp/ob-vala.el | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 lisp/ob-vala.el diff --git a/lisp/ob-vala.el b/lisp/ob-vala.el new file mode 100644 index 0000000..0375265 --- /dev/null +++ b/lisp/ob-vala.el @@ -0,0 +1,122 @@ +;;; ob-vala.el --- org-babel functions for Vala evaluation + +;; Copyright (C) 2017 Free Software Foundation, Inc. + +;; Author: Christian Garbs +;; Keywords: literate programming, reproducible research +;; Homepage: http://orgmode.org + +;;; License: + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;; ob-vala.el provides Babel support for the Vala language +;; (see http://live.gnome.org/Vala for details) + +;;; Requirements: + +;; - Vala compiler binary (valac) +;; - Vala development environment (Vala libraries etc.) +;; +;; vala-mode.el is nice to have for code formatting, but is not needed +;; for ob-vala.el + +;;; Code: + +(require 'ob) + +(declare-function org-trim "org" (s &optional keep-lead)) + +;; File extension. +(add-to-list 'org-babel-tangle-lang-exts '("vala" . "vala")) + +;; Header arguments empty by default. +(defvar org-babel-default-header-args:vala '()) + +(defcustom org-babel-vala-compiler "valac" + "Command used to compile a C source code file into an executable. +May be either a command in the path, like `valac' +or an absolute path name, like `/usr/local/bin/valac'. +Parameters may be used like this: `valac -v'" + :group 'org-babel + :version "24.3" + :type 'string) + +(defun org-babel-expand-body:vala (body params &optional processed-params) + "Expand BODY: does nothing, returns original BODY while ignoring PARAMS." + body ;; TODO: expand params? + ) + +;; This is the main function which is called to evaluate a code +;; block. +;; +;; - run Vala compiler and create a binary in a temporary file +;; - compiler/linker flags can be set via :flags header argument +;; - if compilation succeeded, run the binary +;; - commandline parameters to the binary can be set via :cmdline +;; header argument +;; - stdout will be parsed as RESULT (control via :result-params +;; header argument) +;; +;; There is no session support because Vala is a compiled language. +;; +;; This function is heavily based on ob-C.el +(defun org-babel-execute:vala (body params) + "Execute a block of Vala code with Babel. +This function is called by `org-babel-execute-src-block'." + (message "executing Vala source code block") + (let* ((tmp-src-file (org-babel-temp-file + "vala-src-" + ".vala")) + (tmp-bin-file (org-babel-temp-file "vala-bin-" org-babel-exeext)) + (cmdline (cdr (assq :cmdline params))) + (flags (cdr (assq :flags params))) + (full-body (org-babel-expand-body:vala body params)) + (compile + (progn + (with-temp-file tmp-src-file (insert full-body)) + (org-babel-eval + (format "%s %s -o %s %s" + org-babel-vala-compiler + (mapconcat #'identity + (if (listp flags) flags (list flags)) " ") + (org-babel-process-file-name tmp-bin-file) + (org-babel-process-file-name tmp-src-file)) "")))) + (when (file-executable-p tmp-bin-file) + (let ((results + (org-trim + (org-babel-eval + (concat tmp-bin-file (if cmdline (concat " " cmdline) "")) "")))) + (org-babel-reassemble-table + (org-babel-result-cond (cdr (assq :result-params params)) + (org-babel-read results) + (let ((tmp-file (org-babel-temp-file "vala-"))) + (with-temp-file tmp-file (insert results)) + (org-babel-import-elisp-from-file tmp-file))) + (org-babel-pick-name + (cdr (assq :colname-names params)) (cdr (assq :colnames params))) + (org-babel-pick-name + (cdr (assq :rowname-names params)) (cdr (assoc :rownames params)))))))) + +(defun org-babel-prep-session:vala (session params) + "Prepare a session. +This function does nothing as Vala is a compiled language with no +support for sessions." + (error "Vala is a compiled language -- no support for sessions")) + +(provide 'ob-vala) + +;;; ob-vala.el ends here -- 2.7.4