diff options
| author | Bastien Guerry | 2011-07-28 17:13:49 +0200 |
|---|---|---|
| committer | Bastien Guerry | 2011-07-28 17:13:49 +0200 |
| commit | 3ab2c837b302b01fff610f7b83050ab7e703477c (patch) | |
| tree | efa67ed523bbda4d41488ae6b9ad2782941ddcf2 /lisp/org/ob-java.el | |
| parent | 44a8054f971837447e80d618b6e0c2a77778a2ee (diff) | |
| download | emacs-3ab2c837b302b01fff610f7b83050ab7e703477c.tar.gz emacs-3ab2c837b302b01fff610f7b83050ab7e703477c.zip | |
Merge changes from Org 7.4 to current Org 7.7.
Diffstat (limited to 'lisp/org/ob-java.el')
| -rw-r--r-- | lisp/org/ob-java.el | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lisp/org/ob-java.el b/lisp/org/ob-java.el new file mode 100644 index 00000000000..3f349fea271 --- /dev/null +++ b/lisp/org/ob-java.el | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | ;;; ob-java.el --- org-babel functions for java evaluation | ||
| 2 | |||
| 3 | ;; Copyright (C) 2011 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Eric Schulte | ||
| 6 | ;; Keywords: literate programming, reproducible research | ||
| 7 | ;; Homepage: http://orgmode.org | ||
| 8 | ;; Version: 7.7 | ||
| 9 | |||
| 10 | ;; This file is part of GNU Emacs. | ||
| 11 | |||
| 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 13 | ;; it under the terms of the GNU General Public License as published by | ||
| 14 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 15 | ;; (at your option) any later version. | ||
| 16 | |||
| 17 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | ;; GNU General Public License for more details. | ||
| 21 | |||
| 22 | ;; You should have received a copy of the GNU General Public License | ||
| 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 24 | |||
| 25 | ;;; Commentary: | ||
| 26 | |||
| 27 | ;; Currently this only supports the external compilation and execution | ||
| 28 | ;; of java code blocks (i.e., no session support). | ||
| 29 | |||
| 30 | ;;; Code: | ||
| 31 | (require 'ob) | ||
| 32 | (require 'ob-eval) | ||
| 33 | |||
| 34 | (defvar org-babel-tangle-lang-exts) | ||
| 35 | (add-to-list 'org-babel-tangle-lang-exts '("java" . "java")) | ||
| 36 | |||
| 37 | (defvar org-babel-java-command "java" | ||
| 38 | "Name of the java command.") | ||
| 39 | |||
| 40 | (defvar org-babel-java-compiler "javac" | ||
| 41 | "Name of the java compiler.") | ||
| 42 | |||
| 43 | (defun org-babel-execute:java (body params) | ||
| 44 | (let* ((classname (or (cdr (assoc :classname params)) | ||
| 45 | (error | ||
| 46 | "Can't compile a java block without a classname"))) | ||
| 47 | (packagename (file-name-directory classname)) | ||
| 48 | (src-file (concat classname ".java")) | ||
| 49 | (full-body (org-babel-expand-body:generic body params)) | ||
| 50 | (compile | ||
| 51 | (progn (with-temp-file src-file (insert full-body)) | ||
| 52 | (org-babel-eval | ||
| 53 | (concat org-babel-java-compiler " " src-file) "")))) | ||
| 54 | ;; created package-name directories if missing | ||
| 55 | (unless (or (not packagename) (file-exists-p packagename)) | ||
| 56 | (make-directory packagename 'parents)) | ||
| 57 | ((lambda (results) | ||
| 58 | (org-babel-reassemble-table | ||
| 59 | (if (member "vector" (cdr (assoc :result-params params))) | ||
| 60 | (let ((tmp-file (org-babel-temp-file "c-"))) | ||
| 61 | (with-temp-file tmp-file (insert results)) | ||
| 62 | (org-babel-import-elisp-from-file tmp-file)) | ||
| 63 | (org-babel-read results)) | ||
| 64 | (org-babel-pick-name | ||
| 65 | (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) | ||
| 66 | (org-babel-pick-name | ||
| 67 | (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))) | ||
| 68 | (org-babel-eval (concat org-babel-java-command " " classname) "")))) | ||
| 69 | |||
| 70 | (provide 'ob-java) | ||
| 71 | |||
| 72 | ;; arch-tag: dd1cfb00-7f76-4ecf-922c-f7031b68b85e | ||
| 73 | |||
| 74 | ;;; ob-java.el ends here | ||