* Babel support for Vala @ 2017-07-09 20:09 Christian Garbs 2017-07-10 9:03 ` Nicolas Goaziou 0 siblings, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-07-09 20:09 UTC (permalink / raw) To: emacs-orgmode Hi there, I have written a minimal Babel mode supporting the Vala[1][2] language based on both ob-template.el and ob-C.el. I would like to contribute it to lisp/contrib if you deem it useful. ob-vala.el is available here: https://github.com/mmitch/babel-vala so long Mitch [1] https://wiki.gnome.org/Projects/Vala [2] https://wiki.gnome.org/Projects/Vala/About PS: I'm neither fluent in Vala, Lisp or Orgmode - I stumbled across Vala and wanted to document how I write a simple Vala example, decided to try doing that Literate Programming style with Orgmode and then found out I had to write a Babel mode first ;-) -- ....Christian.Garbs....................................https://www.cgarbs.de Experience varies directly with equipment ruined. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Babel support for Vala 2017-07-09 20:09 Babel support for Vala Christian Garbs @ 2017-07-10 9:03 ` Nicolas Goaziou 2017-07-10 17:54 ` Christian Garbs 0 siblings, 1 reply; 20+ messages in thread From: Nicolas Goaziou @ 2017-07-10 9:03 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@cgarbs.de> writes: > I have written a minimal Babel mode supporting the Vala[1][2] language > based on both ob-template.el and ob-C.el. > > I would like to contribute it to lisp/contrib if you deem it useful. Thank you. Would you want to add it to Org core base? If so, you need to sign FSF papers if you haven't. See <http://orgmode.org/worg/org-contribute.html> for details. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Babel support for Vala 2017-07-10 9:03 ` Nicolas Goaziou @ 2017-07-10 17:54 ` Christian Garbs 2017-07-11 8:10 ` Nicolas Goaziou 0 siblings, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-07-10 17:54 UTC (permalink / raw) To: emacs-orgmode Am 10.07.2017 um 11:03 schrieb Nicolas Goaziou: > Christian Garbs <mitch@cgarbs.de> writes: > >> I have written a minimal Babel mode supporting the Vala[1][2] language >> based on both ob-template.el and ob-C.el. >> >> I would like to contribute it to lisp/contrib if you deem it useful. > Would you want to add it to Org core base? If so, you need to sign FSF > papers if you haven't. See <http://orgmode.org/worg/org-contribute.html> > for details. Originally I only wanted to contribute to lisp/contrib without the FSF papers ("too much of a hassle"), but your question made me reconsider :-) I'll send the mail to assign@gnu.org and while waiting for the process, I'll write some documentation based on ob-doc-template.org so long, Mitch -- ....Christian.Garbs....................................https://www.cgarbs.de "Riko?" "Hmm?" "Did I ever tell you how beautiful you are?" She smiled. "You tried once, but gave up." (Hammer Time, Book One by Martin Rose) ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Babel support for Vala 2017-07-10 17:54 ` Christian Garbs @ 2017-07-11 8:10 ` Nicolas Goaziou 2017-07-13 21:42 ` Christian Garbs 0 siblings, 1 reply; 20+ messages in thread From: Nicolas Goaziou @ 2017-07-11 8:10 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@mitch.h.shuttle.de> writes: > I'll send the mail to assign@gnu.org and while waiting for the > process, I'll write some documentation based on ob-doc-template.org Great! Thank you. In the meantime, would you want to sent your library as a patch so that we can review it? Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Babel support for Vala 2017-07-11 8:10 ` Nicolas Goaziou @ 2017-07-13 21:42 ` Christian Garbs 2017-07-14 8:30 ` Nicolas Goaziou 0 siblings, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-07-13 21:42 UTC (permalink / raw) To: emacs-orgmode Hi, Am 11.07.2017 um 10:10 schrieb Nicolas Goaziou: > In the meantime, would you want to sent your library as a patch so that > we can review it? The patch is prepared but I have one question regarding the copyright situation: Looking at the other files[1], I think I should now list the FSF as copyright holder. Can I already do that before the paperwork has been completed or do I have to hold the patch back until that time? And should I send the patch as a reply into this thread or start a new one? so long Mitch [1] `grep Copyright lisp/*.el' shows the FSF as copyright holder for all files except `lisp/org-duration.el'. Is that a bug or intentional? ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Babel support for Vala 2017-07-13 21:42 ` Christian Garbs @ 2017-07-14 8:30 ` Nicolas Goaziou 2017-07-14 19:43 ` [PATCH] ob-vala.el: Add Vala support to Babel Christian Garbs 0 siblings, 1 reply; 20+ messages in thread From: Nicolas Goaziou @ 2017-07-14 8:30 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@mitch.h.shuttle.de> writes: > The patch is prepared but I have one question regarding the copyright > situation: Looking at the other files[1], I think I should now list > the FSF as copyright holder. Can I already do that before the > paperwork has been completed or do I have to hold the patch back until > that time? Please do. > And should I send the patch as a reply into this thread or start a new > one? Replying to this thread is fine. > [1] `grep Copyright lisp/*.el' shows the FSF as copyright holder for > all files except `lisp/org-duration.el'. Is that a bug or > intentional? It was a bug. I fixed it. Thank you. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH] ob-vala.el: Add Vala support to Babel 2017-07-14 8:30 ` Nicolas Goaziou @ 2017-07-14 19:43 ` Christian Garbs 2017-07-23 9:05 ` Nicolas Goaziou 0 siblings, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-07-14 19:43 UTC (permalink / raw) To: emacs-orgmode; +Cc: Christian Garbs * ob-vala.el: Add support for the Vala language to Babel. --- lisp/ob-vala.el | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 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..9b5407f --- /dev/null +++ b/lisp/ob-vala.el @@ -0,0 +1,129 @@ +;;; ob-vala.el --- org-babel functions for Vala evaluation + +;; Copyright (C) 2017 Free Software Foundation, Inc. + +;; Author: Christian Garbs <mitch@cgarbs.de> +;; 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 <http://www.gnu.org/licenses/>. + +;;; 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 '()) + +(defvar org-babel-vala-compiler "valac" + "Command used to compile a Vala source code file into an +executable.") + +(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 org-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 (assoc :cmdline params))) + (flags (cdr (assoc :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)) ""))) + ) + (if (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 (assoc :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 (assoc :colname-names params)) (cdr (assoc :colnames params))) + (org-babel-pick-name + (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))) + )) + ))) + +(defun org-babel-prep-session:vala (session params) + "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")) + +(defun org-babel-vala-var-to-vala (var) + "Convert an elisp var into a string of vala source code +specifying a var of the same value." + (format "%S" var)) + +(defun org-babel-vala-table-or-string (results) + "If the results look like a table, then convert them into an +Emacs-lisp table, otherwise return the results as a string." + ) + +(provide 'ob-vala) + +;;; ob-vala.el ends here -- 2.7.4 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-07-14 19:43 ` [PATCH] ob-vala.el: Add Vala support to Babel Christian Garbs @ 2017-07-23 9:05 ` Nicolas Goaziou 2017-07-31 22:04 ` [PATCH v2] " Christian Garbs 2017-08-01 21:20 ` [PATCH] " Christian Garbs 0 siblings, 2 replies; 20+ messages in thread From: Nicolas Goaziou @ 2017-07-23 9:05 UTC (permalink / raw) To: Christian Garbs; +Cc: Christian Garbs, emacs-orgmode Hello, Christian Garbs <mitch@mitch.h.shuttle.de> writes: > * ob-vala.el: Add support for the Vala language to Babel. Thank you. Comments follow. > +;; file extension ;; File extension. > +;; header arguments empty by default ;; Header argument empty by default. > +(defvar org-babel-vala-compiler "valac" > + "Command used to compile a Vala source code file into an > +executable.") The first line of a docstring should be a full sentence. Also, shouldn't this be a defcustom? > +(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 org-babel. "org-babel" -> "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 (assoc :cmdline params))) > + (flags (cdr (assoc :flags params))) `assoc' -> `assq' > + (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 'identity -> #'identity > + (if (listp flags) flags (list flags)) " ") > + (org-babel-process-file-name tmp-bin-file) > + (org-babel-process-file-name tmp-src-file)) ""))) > + ) There should be no dangling parenthesis. Please move it at the end of the line above. > + (if (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 (assoc :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 (assoc :colname-names params)) (cdr (assoc :colnames params))) > + (org-babel-pick-name > + (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))) > + )) > + ))) See above. Also, it looks like you are using a one-armed `if'. In this case, I suggest using (when ...) instead. > +(defun org-babel-prep-session:vala (session params) > + "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")) See remark about first line in a docstirng. > +(defun org-babel-vala-var-to-vala (var) > + "Convert an elisp var into a string of vala source code > +specifying a var of the same value." > + (format "%S" var)) Ditto. > +(defun org-babel-vala-table-or-string (results) > + "If the results look like a table, then convert them into an > +Emacs-lisp table, otherwise return the results as a string." > + ) The body of the function is missing. Could you send an updated patch? Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2] ob-vala.el: Add Vala support to Babel 2017-07-23 9:05 ` Nicolas Goaziou @ 2017-07-31 22:04 ` Christian Garbs 2017-08-01 21:59 ` Nicolas Goaziou 2017-08-01 21:20 ` [PATCH] " Christian Garbs 1 sibling, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-07-31 22:04 UTC (permalink / raw) To: emacs-orgmode * 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 <mitch@cgarbs.de> +;; 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 <http://www.gnu.org/licenses/>. + +;;; 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 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH v2] ob-vala.el: Add Vala support to Babel 2017-07-31 22:04 ` [PATCH v2] " Christian Garbs @ 2017-08-01 21:59 ` Nicolas Goaziou 2017-07-31 22:04 ` [PATCH v3] " Christian Garbs 0 siblings, 1 reply; 20+ messages in thread From: Nicolas Goaziou @ 2017-08-01 21:59 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@cgarbs.de> writes: > * 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 Babel functions for Vala evaluation Also, could you use lexical binding, i.e., add "-*- lexical-binding: t; -*-" on the first line of the file and check byte-compilation doesn't complain. > +(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' like \"valac\" > +or an absolute path name, like `/usr/local/bin/valac'. an absolute file name, like \"/usr/local/bin/valac\". > +Parameters may be used like this: `valac -v'" like this: \"valac -c\"" > + :group 'org-babel > + :version "24.3" > + :type 'string) Some keywords are missing: :version "26.1" :package-version '(Org . "9.1") Barring the suggestions above, your patch looks good. I think we can apply it as soon as the FSF process is complete. Thank you! Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v3] ob-vala.el: Add Vala support to Babel 2017-08-01 21:59 ` Nicolas Goaziou @ 2017-07-31 22:04 ` Christian Garbs 2017-08-07 9:41 ` Nicolas Goaziou 0 siblings, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-07-31 22:04 UTC (permalink / raw) To: emacs-orgmode * lisp/ob-vala.el: Add support for the Vala language to Babel. * testing/lisp/test-ob-vala.el: Add tests for ob-vala.el. * doc/org.texi (Working with source code): Add Vala to the list of supported languages. --- doc/org.texi | 1 + etc/ORG-NEWS | 13 +++++ lisp/ob-vala.el | 115 +++++++++++++++++++++++++++++++++++++++++++ testing/lisp/test-ob-vala.el | 104 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 lisp/ob-vala.el create mode 100644 testing/lisp/test-ob-vala.el diff --git a/doc/org.texi b/doc/org.texi index db28bfee..3493ebb5 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -15535,6 +15535,7 @@ Org supports the following languages for the @samp{src} code blocks: @item Scheme @tab scheme @tab GNU Screen @tab screen @item Sed @tab sed @tab shell @tab sh @item SQL @tab sql @tab SQLite @tab sqlite +@item Vala @tab vala @end multitable Additional documentation for some languages are at diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 5fb763c6..6192dbed 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -233,6 +233,19 @@ using ~:namespaces~: ,#+END_SRC #+end_example +**** Support for Vala language + +[[https://wiki.gnome.org/Projects/Vala][Vala]] language blocks support two special header arguments: + +- ~:flags~ passes arguments to the compiler +- ~:cmdline~ passes commandline arguments to the generated executable + +Support for [[http://orgmode.org/manual/var.html#var][~:var~]] does not exist yet, also there is no [[http://orgmode.org/manual/session.html#session][~:session~]] +support because Vala is a compiled language. + +The Vala compiler binary can be changed via the ~defcustom~ +~org-babel-vala-compiler~. + *** New ~function~ scope argument for the Clock Table Added a nullary function that returns a list of files as a possible argument for the scope of the clock table. diff --git a/lisp/ob-vala.el b/lisp/ob-vala.el new file mode 100644 index 00000000..1282e162 --- /dev/null +++ b/lisp/ob-vala.el @@ -0,0 +1,115 @@ +;;; ob-vala.el --- Babel functions for Vala evaluation -*- lexical-binding: t; -*- + +;; Copyright (C) 2017 Free Software Foundation, Inc. + +;; Author: Christian Garbs <mitch@cgarbs.de> +;; 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 <http://www.gnu.org/licenses/>. + +;;; 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 "26.1" + :package-version '(Org . "9.1") + :type 'string) + +;; 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)))) + (with-temp-file tmp-src-file (insert 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 (assq :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 diff --git a/testing/lisp/test-ob-vala.el b/testing/lisp/test-ob-vala.el new file mode 100644 index 00000000..92032222 --- /dev/null +++ b/testing/lisp/test-ob-vala.el @@ -0,0 +1,104 @@ +;;; test-ob-vala.el --- tests for ob-vala.el + +;; Copyright (C) 2017 Christian Garbs +;; Authors: Christian Garbs + +;; This file is not part of GNU Emacs. + +;; This program 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. + +;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Code: +(unless (featurep 'ob-vala) + (signal 'missing-test-dependency "Support for Vala code blocks")) + +(org-test-for-executable org-babel-vala-compiler) + +(ert-deftest ob-vala/assert () + (should t)) + +(ert-deftest ob-vala/static-output () + "Parse static output to variable." + (should (= 42 + (org-test-with-temp-text + " +#+begin_src vala + class Demo.HelloWorld : GLib.Object { + public static int main(string[] args) { + stdout.printf(\"42\n\"); + return 0; + } + } +#+end_src" + (org-babel-next-src-block) + (org-babel-execute-src-block))))) + +(ert-deftest ob-vala/return-numerics () + "Return multiple numeric values." + (should (equal '((0) (1) (2)) + (org-test-with-temp-text + " +#+begin_src vala + class Demo.HelloWorld : GLib.Object { + public static int main(string[] args) { + for (int i=0; i<3; i++) { + stdout.printf(\"%d\n\", i); + } + return 0; + } + } +#+end_src" + (org-babel-next-src-block) + (org-babel-execute-src-block))))) + +(ert-deftest ob-vala/compiler-args () + "Pass compiler arguments." + (should (string= "Foo" + (org-test-with-temp-text + " +#+begin_src vala :flags -D FOO + class Demo.HelloWorld : GLib.Object { + public static int main(string[] args) { +#if FOO + stdout.printf(\"Foo\n\"); +#else + stdout.printf(\"No foo\n\"); +#endif + return 0; + } + } +#+end_src" + (org-babel-next-src-block) + (org-babel-execute-src-block))))) + +(ert-deftest ob-vala/comdline-args () + "Pass commandline arguments." + (should (equal '(("foo") ("bar")) + (org-test-with-temp-text + " +#+begin_src vala :cmdline foo bar + class Demo.HelloWorld : GLib.Object { + public static int main(string[] args) { + // skip args[0], it is the binary name + for (int i=1; i < args.length; i++) { + stdout.printf(\"%s\n\" , args[i]); + } + return 0; + } + } +#+end_src" + (org-babel-next-src-block) + (org-babel-execute-src-block))))) + + +;;; test-ob-vala.el ends here -- 2.11.0 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH v3] ob-vala.el: Add Vala support to Babel 2017-07-31 22:04 ` [PATCH v3] " Christian Garbs @ 2017-08-07 9:41 ` Nicolas Goaziou 0 siblings, 0 replies; 20+ messages in thread From: Nicolas Goaziou @ 2017-08-07 9:41 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@cgarbs.de> writes: > * lisp/ob-vala.el: Add support for the Vala language to Babel. > > * testing/lisp/test-ob-vala.el: Add tests for ob-vala.el. > > * doc/org.texi (Working with source code): Add Vala to the list of > supported languages. Applied. Thank you. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-07-23 9:05 ` Nicolas Goaziou 2017-07-31 22:04 ` [PATCH v2] " Christian Garbs @ 2017-08-01 21:20 ` Christian Garbs 2017-08-01 22:03 ` Nicolas Goaziou 1 sibling, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-08-01 21:20 UTC (permalink / raw) To: emacs-orgmode Hello and sorry for the wait! On Sun, Jul 23, 2017 at 11:05:02AM +0200, Nicolas Goaziou wrote: > Christian Garbs <mitch@mitch.h.shuttle.de> writes: > > > * ob-vala.el: Add support for the Vala language to Babel. > > +(defvar org-babel-vala-compiler "valac" > > + "Command used to compile a Vala source code file into an > > +executable.") > > The first line of a docstring should be a full sentence. > > Also, shouldn't this be a defcustom? Yes, it should. Looking at the other defcustoms, is the current wording ok? Or should it still be full a sentence? > > +(defun org-babel-vala-table-or-string (results) > > + "If the results look like a table, then convert them into an > > +Emacs-lisp table, otherwise return the results as a string." > > + ) > > The body of the function is missing. Not only is the body missing, the function is also not used at all, so I have removed it altogether. Same for org-babel-vala-var-to-vala. > Could you send an updated patch? Incoming :-) Some of your proposed changes apply to ob-C.el as well. I could prepare a different patch for that (under which topic?), but I am not confident that I could test the changes appropriately. I don't have proper C/C++/D org files handy that would cover all cases (eg. header arguments). Regards Christian PS: My FSF paperwork is complete. -- ....Christian.Garbs....................................https://www.cgarbs.de Wie packt man Styroporkügelchen ein, wenn man sie verschickt? ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-08-01 21:20 ` [PATCH] " Christian Garbs @ 2017-08-01 22:03 ` Nicolas Goaziou 2017-08-02 20:24 ` Christian Garbs 0 siblings, 1 reply; 20+ messages in thread From: Nicolas Goaziou @ 2017-08-01 22:03 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@cgarbs.de> writes: > Hello and sorry for the wait! No problem. > Looking at the other defcustoms, is the current wording ok? It is. > Some of your proposed changes apply to ob-C.el as well. I could > prepare a different patch for that (under which topic?), Depending on the size of the changes, it could be "Tiny changes", "Small refactoring"... > but I am not confident that I could test the changes appropriately. > I don't have proper C/C++/D org files handy that would cover all cases > (eg. header arguments). ob-C.el has a couple of tests (BTW, would you want to write some for "ob-vala.el"?). > PS: My FSF paperwork is complete. I overlooked this information. These are great news. I'll push your patch once updated (see my other mail). Could you provide an ORG-NEWS entry about the new file? Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-08-01 22:03 ` Nicolas Goaziou @ 2017-08-02 20:24 ` Christian Garbs 2017-08-03 10:49 ` Nicolas Goaziou 0 siblings, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-08-02 20:24 UTC (permalink / raw) To: emacs-orgmode Hi, On Wed, Aug 02, 2017 at 12:03:50AM +0200, Nicolas Goaziou wrote: > Christian Garbs <mitch@cgarbs.de> writes: > > Some of your proposed changes apply to ob-C.el as well. I could > > prepare a different patch for that (under which topic?), > > Depending on the size of the changes, it could be "Tiny changes", "Small > refactoring"... I'll have a look at it if time permits. I should probably write some documentation for ob-vala first. > (BTW, would you want to write some for "ob-vala.el"?). Oooh, I like testing! After having I short look at the ob-C tests I think I should be able to come up with some similar test cases. > Could you provide an ORG-NEWS entry about the new file? Yes, I'll try that, too. The next iteration of the patch should include ob-vala.el itself, some tests and an ORG-NEWS entry. Regarding the lexical-binding: How can I check if byte-compiling is successful? Regards, Christian -- ....Christian.Garbs....................................https://www.cgarbs.de Murphy's Laws of Combat: 21. Friendly fire isn't. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-08-02 20:24 ` Christian Garbs @ 2017-08-03 10:49 ` Nicolas Goaziou 2017-08-05 19:53 ` Christian Garbs 0 siblings, 1 reply; 20+ messages in thread From: Nicolas Goaziou @ 2017-08-03 10:49 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@cgarbs.de> writes: > The next iteration of the patch should include ob-vala.el itself, some > tests and an ORG-NEWS entry. Great! Thank you. > Regarding the lexical-binding: How can I check if byte-compiling is > successful? M-x emacs-lisp-byte-compile Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-08-03 10:49 ` Nicolas Goaziou @ 2017-08-05 19:53 ` Christian Garbs 2017-08-06 0:22 ` Nicolas Goaziou 0 siblings, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-08-05 19:53 UTC (permalink / raw) To: emacs-orgmode Hi! On Thu, Aug 03, 2017 at 12:49:44PM +0200, Nicolas Goaziou wrote: > Christian Garbs <mitch@cgarbs.de> writes: > > Regarding the lexical-binding: How can I check if byte-compiling is > > successful? > > M-x emacs-lisp-byte-compile Byte-compiling works and gave me 5 warnings about unused variables and arguments which I could fix in different ways. Currently I run into a problem with the test case: I have created an org file containing some Vala code and an .el file with some tests, but the dependency check at the top of the test always fails: | (unless (featurep 'ob-vala) | (signal 'missing-test-dependency "Support for Vala code blocks")) Removing the test results in errors. When I replace those two lines with | (require 'ob-vala) the tests run as expected, eg. they fail when I deliberately provoke an error and succeed otherwise. I think this is a dependency or build problem, but I don't know what exactly goes wrong or how to fix it. I have searched the whole source for 'ob-C and 'ob-fortran to see how those tests and modules differ from 'ob-vala, but this yielded no result. My guess: It is something totally basic and trivial. Any ideas? Regards Christian -- ....Christian.Garbs....................................https://www.cgarbs.de To iterate is human, to recurse divine. (L. Peter Deutsch) ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-08-05 19:53 ` Christian Garbs @ 2017-08-06 0:22 ` Nicolas Goaziou 2017-08-06 10:06 ` Christian Garbs 0 siblings, 1 reply; 20+ messages in thread From: Nicolas Goaziou @ 2017-08-06 0:22 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@cgarbs.de> writes: > Byte-compiling works and gave me 5 warnings about unused variables and > arguments which I could fix in different ways. Note that the usual solution to get rid of unused arguments is to prefix their name with "_". > Currently I run into a problem with the test case: I have created an > org file containing some Vala code and an .el file with some tests, It would be better to have all tests and data self contained in the same ".el" file, IMO. > but the dependency check at the top of the test always fails: > > | (unless (featurep 'ob-vala) > | (signal 'missing-test-dependency "Support for Vala code blocks")) > > Removing the test results in errors. > > When I replace those two lines with > > | (require 'ob-vala) > > the tests run as expected, eg. they fail when I deliberately provoke > an error and succeed otherwise. > > I think this is a dependency or build problem, but I don't know what > exactly goes wrong or how to fix it. I have searched the whole source > for 'ob-C and 'ob-fortran to see how those tests and modules differ > from 'ob-vala, but this yielded no result. > > My guess: It is something totally basic and trivial. > Any ideas? I don't see any problem. The tests are meant to run if user has loaded "ob-vala", but the test suite shouldn't load that library on user's behalf. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-08-06 0:22 ` Nicolas Goaziou @ 2017-08-06 10:06 ` Christian Garbs 2017-08-07 9:52 ` Nicolas Goaziou 0 siblings, 1 reply; 20+ messages in thread From: Christian Garbs @ 2017-08-06 10:06 UTC (permalink / raw) To: emacs-orgmode Hello On Sun, Aug 06, 2017 at 02:22:31AM +0200, Nicolas Goaziou wrote: > Christian Garbs <mitch@cgarbs.de> writes: > > Currently I run into a problem with the test case: I have created an > > org file containing some Vala code and an .el file with some tests, > > It would be better to have all tests and data self contained in the same > ".el" file, IMO. It seems I have studied the wrong tests and thought all tests were built that way :-) > I don't see any problem. The tests are meant to run if user has loaded > "ob-vala", but the test suite shouldn't load that library on user's > behalf. I just found BTEST_OB_LANGUAGES in local.mk. When I add "vala" there, "make test" will run my tests - problem solved. (I don't have (require 'ob-vala) in my .emacs as I rarely ever need it. If I need it, I put "# eval: (require 'ob-vala)" in the corresponding org file.) I fear that I am the only one who will ever run the vala tests ;-) - Are there any build hosts that automatically run the tests with all languages enabled? - Or could the BTEST_OB_LANGUAGES default in mk/default.mk be expanded to include vala? (99% of the users will simply skip the vala test because they don't have the compiler binary, so it should have no ill effacts) Regards Christian -- ....Christian.Garbs....................................https://www.cgarbs.de "We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true" ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] ob-vala.el: Add Vala support to Babel 2017-08-06 10:06 ` Christian Garbs @ 2017-08-07 9:52 ` Nicolas Goaziou 0 siblings, 0 replies; 20+ messages in thread From: Nicolas Goaziou @ 2017-08-07 9:52 UTC (permalink / raw) To: Christian Garbs; +Cc: emacs-orgmode Hello, Christian Garbs <mitch@cgarbs.de> writes: > I fear that I am the only one who will ever run the vala tests ;-) > > - Are there any build hosts that automatically run the tests with all > languages enabled? I don't think so. > - Or could the BTEST_OB_LANGUAGES default in mk/default.mk be expanded > to include vala? (99% of the users will simply skip the vala test > because they don't have the compiler binary, so it should have no > ill effacts) Done. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2017-08-07 9:52 UTC | newest] Thread overview: 20+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-07-09 20:09 Babel support for Vala Christian Garbs 2017-07-10 9:03 ` Nicolas Goaziou 2017-07-10 17:54 ` Christian Garbs 2017-07-11 8:10 ` Nicolas Goaziou 2017-07-13 21:42 ` Christian Garbs 2017-07-14 8:30 ` Nicolas Goaziou 2017-07-14 19:43 ` [PATCH] ob-vala.el: Add Vala support to Babel Christian Garbs 2017-07-23 9:05 ` Nicolas Goaziou 2017-07-31 22:04 ` [PATCH v2] " Christian Garbs 2017-08-01 21:59 ` Nicolas Goaziou 2017-07-31 22:04 ` [PATCH v3] " Christian Garbs 2017-08-07 9:41 ` Nicolas Goaziou 2017-08-01 21:20 ` [PATCH] " Christian Garbs 2017-08-01 22:03 ` Nicolas Goaziou 2017-08-02 20:24 ` Christian Garbs 2017-08-03 10:49 ` Nicolas Goaziou 2017-08-05 19:53 ` Christian Garbs 2017-08-06 0:22 ` Nicolas Goaziou 2017-08-06 10:06 ` Christian Garbs 2017-08-07 9:52 ` Nicolas Goaziou
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).