ob-csharp.el 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ;;; ob-csharp.el --- org-babel functions for csharp evaluation
  2. ;; Copyright (C) 2011-2018 Free Software Foundation, Inc.
  3. ;; Author: thomas "at" friendlyvillagers.com based on ob-java.el by Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: https://orgmode.org
  6. ;; This file is not part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Currently this only supports the external compilation and execution
  19. ;; of csharp code blocks (i.e., no session support).
  20. ;;; Code:
  21. (require 'ob)
  22. (defvar org-babel-tangle-lang-exts)
  23. (add-to-list 'org-babel-tangle-lang-exts '("csharp" . "cs"))
  24. (defcustom org-babel-csharp-command "mono"
  25. "Name of the csharp command.
  26. May be either a command in the path, like mono
  27. or an absolute path name, like /usr/local/bin/mono
  28. parameters may be used, like mono -verbose"
  29. :group 'org-babel
  30. :version "24.3"
  31. :type 'string)
  32. (defcustom org-babel-csharp-compiler "mcs"
  33. "Name of the csharp compiler.
  34. May be either a command in the path, like mcs
  35. or an absolute path name, like /usr/local/bin/mcs
  36. parameters may be used, like mcs -warnaserror+"
  37. :group 'org-babel
  38. :version "24.3"
  39. :type 'string)
  40. (defun org-babel-execute:csharp (body params)
  41. (let* ((full-body (org-babel-expand-body:generic body params))
  42. (cmpflag (or (cdr (assq :cmpflag params)) ""))
  43. (cmdline (or (cdr (assq :cmdline params)) ""))
  44. (src-file (org-babel-temp-file "csharp-src-" ".cs"))
  45. (exe-file (concat (file-name-sans-extension src-file) ".exe"))
  46. (compile
  47. (progn (with-temp-file src-file (insert full-body))
  48. (org-babel-eval
  49. (concat org-babel-csharp-compiler " " cmpflag " " src-file) ""))))
  50. (let ((results (org-babel-eval (concat org-babel-csharp-command " " cmdline " " exe-file) "")))
  51. (org-babel-reassemble-table
  52. (org-babel-result-cond (cdr (assq :result-params params))
  53. (org-babel-read results)
  54. (let ((tmp-file (org-babel-temp-file "c-")))
  55. (with-temp-file tmp-file (insert results))
  56. (org-babel-import-elisp-from-file tmp-file)))
  57. (org-babel-pick-name
  58. (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
  59. (org-babel-pick-name
  60. (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))))
  61. (defun org-babel-prep-session:csharp (session params)
  62. "Return an error because csharp does not support sessions."
  63. (error "Sessions are not supported for CSharp"))
  64. (provide 'ob-csharp)
  65. ;;; ob-csharp.el ends here