ob-csharp.el (3104B)
1 ;;; ob-csharp.el --- org-babel functions for csharp evaluation 2 3 ;; Copyright (C) 2011-2021 Free Software Foundation, Inc. 4 5 ;; Author: thomas "at" friendlyvillagers.com based on ob-java.el by Eric Schulte 6 ;; Keywords: literate programming, reproducible research 7 ;; Homepage: https://git.sr.ht/~bzg/org-contrib 8 9 ;; This file is not part of GNU Emacs. 10 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. 15 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. 20 21 ;; You should have received a copy of the GNU General Public License 22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. 23 24 ;;; Commentary: 25 26 ;; Currently this only supports the external compilation and execution 27 ;; of csharp code blocks (i.e., no session support). 28 29 ;;; Code: 30 (require 'ob) 31 32 (defvar org-babel-tangle-lang-exts) 33 (add-to-list 'org-babel-tangle-lang-exts '("csharp" . "cs")) 34 35 (defcustom org-babel-csharp-command "mono" 36 "Name of the csharp command. 37 May be either a command in the path, like mono 38 or an absolute path name, like /usr/local/bin/mono 39 parameters may be used, like mono -verbose" 40 :group 'org-babel 41 :version "24.3" 42 :type 'string) 43 44 (defcustom org-babel-csharp-compiler "mcs" 45 "Name of the csharp compiler. 46 May be either a command in the path, like mcs 47 or an absolute path name, like /usr/local/bin/mcs 48 parameters may be used, like mcs -warnaserror+" 49 :group 'org-babel 50 :version "24.3" 51 :type 'string) 52 53 (defun org-babel-execute:csharp (body params) 54 (let* ((full-body (org-babel-expand-body:generic body params)) 55 (cmpflag (or (cdr (assq :cmpflag params)) "")) 56 (cmdline (or (cdr (assq :cmdline params)) "")) 57 (src-file (org-babel-temp-file "csharp-src-" ".cs")) 58 (exe-file (concat (file-name-sans-extension src-file) ".exe")) 59 (compile 60 (progn (with-temp-file src-file (insert full-body)) 61 (org-babel-eval 62 (concat org-babel-csharp-compiler " " cmpflag " " src-file) "")))) 63 (let ((results (org-babel-eval (concat org-babel-csharp-command " " cmdline " " exe-file) ""))) 64 (org-babel-reassemble-table 65 (org-babel-result-cond (cdr (assq :result-params params)) 66 (org-babel-read results) 67 (let ((tmp-file (org-babel-temp-file "c-"))) 68 (with-temp-file tmp-file (insert results)) 69 (org-babel-import-elisp-from-file tmp-file))) 70 (org-babel-pick-name 71 (cdr (assq :colname-names params)) (cdr (assq :colnames params))) 72 (org-babel-pick-name 73 (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))) 74 75 (defun org-babel-prep-session:csharp (session params) 76 "Return an error because csharp does not support sessions." 77 (error "Sessions are not supported for CSharp")) 78 79 (provide 'ob-csharp) 80 81 82 83 ;;; ob-csharp.el ends here