ob-io.el 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ;;; ob-io.el --- Babel Functions for Io -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2012-2015 Free Software Foundation, Inc.
  3. ;; Author: Andrzej Lichnerowicz
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; This file is 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 only supports the external execution. No session support yet.
  19. ;; :results output -- runs in scripting mode
  20. ;; :results output repl -- runs in repl mode
  21. ;;; Requirements:
  22. ;; - Io language :: http://iolanguage.org/
  23. ;; - Io major mode :: Can be installed from Io sources
  24. ;; https://github.com/stevedekorte/io/blob/master/extras/SyntaxHighlighters/Emacs/io-mode.el
  25. ;;; Code:
  26. (require 'ob)
  27. (eval-when-compile (require 'cl))
  28. (defvar org-babel-tangle-lang-exts) ;; Autoloaded
  29. (add-to-list 'org-babel-tangle-lang-exts '("io" . "io"))
  30. (defvar org-babel-default-header-args:io '())
  31. (defvar org-babel-io-command "io"
  32. "Name of the command to use for executing Io code.")
  33. (defun org-babel-execute:io (body params)
  34. "Execute a block of Io code with org-babel. This function is
  35. called by `org-babel-execute-src-block'"
  36. (message "executing Io source code block")
  37. (let* ((processed-params (org-babel-process-params params))
  38. (session (org-babel-io-initiate-session (nth 0 processed-params)))
  39. (result-params (nth 2 processed-params))
  40. (result-type (cdr (assoc :result-type params)))
  41. (full-body (org-babel-expand-body:generic
  42. body params))
  43. (result (org-babel-io-evaluate
  44. session full-body result-type result-params)))
  45. (org-babel-reassemble-table
  46. result
  47. (org-babel-pick-name
  48. (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
  49. (org-babel-pick-name
  50. (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
  51. (defvar org-babel-io-wrapper-method
  52. "(
  53. %s
  54. ) asString print
  55. ")
  56. (defun org-babel-io-evaluate (session body &optional result-type result-params)
  57. "Evaluate BODY in external Io process.
  58. If RESULT-TYPE equals `output' then return standard output as a string.
  59. If RESULT-TYPE equals `value' then return the value of the last statement
  60. in BODY as elisp."
  61. (when session (error "Sessions are not (yet) supported for Io"))
  62. (case result-type
  63. (output
  64. (if (member "repl" result-params)
  65. (org-babel-eval org-babel-io-command body)
  66. (let ((src-file (org-babel-temp-file "io-")))
  67. (progn (with-temp-file src-file (insert body))
  68. (org-babel-eval
  69. (concat org-babel-io-command " " src-file) "")))))
  70. (value (let* ((src-file (org-babel-temp-file "io-"))
  71. (wrapper (format org-babel-io-wrapper-method body)))
  72. (with-temp-file src-file (insert wrapper))
  73. (let ((raw (org-babel-eval
  74. (concat org-babel-io-command " " src-file) "")))
  75. (org-babel-result-cond result-params
  76. raw
  77. (org-babel-script-escape raw)))))))
  78. (defun org-babel-prep-session:io (_session _params)
  79. "Prepare SESSION according to the header arguments specified in PARAMS."
  80. (error "Sessions are not (yet) supported for Io"))
  81. (defun org-babel-io-initiate-session (&optional _session)
  82. "If there is not a current inferior-process-buffer in SESSION
  83. then create. Return the initialized session. Sessions are not
  84. supported in Io."
  85. nil)
  86. (provide 'ob-io)
  87. ;;; ob-io.el ends here