|
| 1 | +;;; ob-csharp.el --- org-babel functions for csharp evaluation |
| 2 | + |
| 3 | +;; Copyright (C) 2011-2015 Free Software Foundation, Inc. |
| 4 | + |
| 5 | +;; Original Author: Eric Schulte (ob-java.el) |
| 6 | +;; Author: thomas "at" friendlyvillagers.com |
| 7 | +;; Keywords: literate programming, reproducible research |
| 8 | +;; Homepage: http://orgmode.org |
| 9 | + |
| 10 | +;; This file is NOT YET 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 csharp code blocks (i.e., no session support). |
| 29 | + |
| 30 | +;;; Code: |
| 31 | +(require 'ob) |
| 32 | + |
| 33 | +(defvar org-babel-tangle-lang-exts) |
| 34 | +(add-to-list 'org-babel-tangle-lang-exts '("csharp" . "cs")) |
| 35 | + |
| 36 | +(defcustom org-babel-csharp-command "mono" |
| 37 | + "Name of the csharp command. |
| 38 | +May be either a command in the path, like mono |
| 39 | +or an absolute path name, like /usr/local/bin/mono |
| 40 | +parameters may be used, like mono -verbose" |
| 41 | + :group 'org-babel |
| 42 | + :version "24.3" |
| 43 | + :type 'string) |
| 44 | + |
| 45 | +(defcustom org-babel-csharp-compiler "gmcs" |
| 46 | + "Name of the csharp compiler. |
| 47 | +May be either a command in the path, like mcs |
| 48 | +or an absolute path name, like /usr/local/bin/mcs |
| 49 | +parameters may be used, like mcs -warnaserror+" |
| 50 | + :group 'org-babel |
| 51 | + :version "24.3" |
| 52 | + :type 'string) |
| 53 | + |
| 54 | + |
| 55 | +(defun org-babel-execute:csharp (body params) |
| 56 | + (let* ((full-body (org-babel-expand-body:generic body params)) |
| 57 | + (cmpflag (or (cdr (assoc :cmpflag params)) "")) |
| 58 | + (cmdline (or (cdr (assoc :cmdline params)) "")) |
| 59 | + (src-file (org-babel-temp-file "csharp-src-" ".cs")) |
| 60 | + (exe-file (concat (file-name-sans-extension src-file) ".exe")) |
| 61 | + (compile |
| 62 | + (progn (with-temp-file src-file (insert full-body)) |
| 63 | + (org-babel-eval |
| 64 | + (concat org-babel-csharp-compiler " " cmpflag " " src-file) "")))) |
| 65 | + (let ((results (org-babel-eval (concat org-babel-csharp-command " " cmdline " " exe-file) ""))) |
| 66 | + (org-babel-reassemble-table |
| 67 | + (org-babel-result-cond (cdr (assoc :result-params params)) |
| 68 | + (org-babel-read results) |
| 69 | + (let ((tmp-file (org-babel-temp-file "c-"))) |
| 70 | + (with-temp-file tmp-file (insert results)) |
| 71 | + (org-babel-import-elisp-from-file tmp-file))) |
| 72 | + (org-babel-pick-name |
| 73 | + (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) |
| 74 | + (org-babel-pick-name |
| 75 | + (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))) |
| 76 | + |
| 77 | +(defun org-babel-prep-session:csharp (session params) |
| 78 | + "Return an error because csharp does not support sessions." |
| 79 | + (error "Sessions are not (yet) supported for CSharp")) |
| 80 | + |
| 81 | + |
| 82 | +(provide 'ob-csharp) |
| 83 | +;;; ob-csharp.el ends here |
0 commit comments