server.mk: implement ELPA
[org-mode/org-tableheadings.git] / lisp / ob-scala.el
blobd4b87beca0145a7173466e9e371fb349abcea8db
1 ;;; ob-scala.el --- org-babel functions for Scala evaluation
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
5 ;; Author: Andrzej Lichnerowicz
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:
25 ;; Currently only supports the external execution. No session support yet.
27 ;;; Requirements:
28 ;; - Scala language :: http://www.scala-lang.org/
29 ;; - Scala major mode :: Can be installed from Scala sources
30 ;; https://github.com/scala/scala-dist/blob/master/tool-support/src/emacs/scala-mode.el
32 ;;; Code:
33 (require 'ob)
34 (require 'ob-ref)
35 (require 'ob-comint)
36 (require 'ob-eval)
37 (eval-when-compile (require 'cl))
39 (add-to-list 'org-babel-tangle-lang-exts '("scala" . "scala"))
40 (defvar org-babel-default-header-args:scala '())
41 (defvar org-babel-scala-command "scala"
42 "Name of the command to use for executing Scala code.")
45 (defun org-babel-execute:scala (body params)
46 "Execute a block of Scala code with org-babel. This function is
47 called by `org-babel-execute-src-block'"
48 (message "executing Scala source code block")
49 (let* ((processed-params (org-babel-process-params params))
50 (session (org-babel-scala-initiate-session (nth 0 processed-params)))
51 (vars (nth 1 processed-params))
52 (result-params (nth 2 processed-params))
53 (result-type (cdr (assoc :result-type params)))
54 (full-body (org-babel-expand-body:generic
55 body params))
56 (result (org-babel-scala-evaluate
57 session full-body result-type result-params)))
59 (org-babel-reassemble-table
60 result
61 (org-babel-pick-name
62 (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
63 (org-babel-pick-name
64 (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
67 (defun org-babel-scala-table-or-string (results)
68 "Convert RESULTS into an appropriate elisp value.
69 If RESULTS look like a table, then convert them into an
70 Emacs-lisp table, otherwise return the results as a string."
71 (org-babel-script-escape results))
74 (defvar org-babel-scala-wrapper-method
77 ) asString print
81 (defun org-babel-scala-evaluate
82 (session body &optional result-type result-params)
83 "Evaluate BODY in external Scala process.
84 If RESULT-TYPE equals 'output then return standard output as a string.
85 If RESULT-TYPE equals 'value then return the value of the last statement
86 in BODY as elisp."
87 (when session (error "Sessions are not supported for Scala. Yet."))
88 (case result-type
89 (output
90 (let ((src-file (org-babel-temp-file "scala-")))
91 (progn (with-temp-file src-file (insert body))
92 (org-babel-eval
93 (concat org-babel-scala-command " " src-file) ""))))
94 (value
95 (let* ((src-file (org-babel-temp-file "scala-"))
96 (wrapper (format org-babel-scala-wrapper-method body)))
97 (with-temp-file src-file (insert wrapper))
98 ((lambda (raw)
99 (if (member "code" result-params)
101 (org-babel-scala-table-or-string raw)))
102 (org-babel-eval
103 (concat org-babel-scala-command " " src-file) ""))))))
106 (defun org-babel-prep-session:scala (session params)
107 "Prepare SESSION according to the header arguments specified in PARAMS."
108 (error "Sessions are not supported for Scala. Yet."))
110 (defun org-babel-scala-initiate-session (&optional session)
111 "If there is not a current inferior-process-buffer in SESSION
112 then create. Return the initialized session. Sessions are not
113 supported in Scala."
114 nil)
116 (provide 'ob-scala)
120 ;;; ob-scala.el ends here