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