ob-fomus.el (3170B)
1 ;;; ob-fomus.el --- Org-babel functions for fomus evaluation 2 3 ;; Copyright (C) 2011-2014, 2021 Torsten Anders 4 5 ;; Author: Torsten Anders 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 ;; This program 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, or (at your option) 14 ;; any later version. 15 ;; 16 ;; This program 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; see the file COPYING. If not, write to the 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 ;; Boston, MA 02110-1301, USA. 25 26 ;;; Commentary: 27 28 ;; Org-Babel support for evaluating Fomus source code. 29 ;; For information on Fomus see http://fomus.sourceforge.net/ 30 ;; 31 ;; This differs from most standard languages in that 32 ;; 33 ;; 1) there is no such thing as a "session" in fomus 34 ;; 35 ;; 2) we are generally only going to return results of type "file" 36 ;; 37 ;; 3) we are adding the "file" and "cmdline" header arguments 38 ;; 39 ;; 4) there are no variables (at least for now) 40 41 ;;; Code: 42 (require 'ob) 43 (require 'ob-eval) 44 45 (defvar org-babel-default-header-args:fomus 46 '((:results . "file") (:exports . "results")) 47 "Default arguments to use when evaluating a fomus source block.") 48 49 (defun org-babel-expand-body:fomus (body params) 50 "Expand BODY according to PARAMS, return the expanded body." 51 (let ((vars (org-babel--get-vars params))) 52 (mapc 53 (lambda (pair) 54 (let ((name (symbol-name (car pair))) 55 (value (cdr pair))) 56 (setq body 57 (replace-regexp-in-string 58 (concat "\$" (regexp-quote name)) 59 (if (stringp value) value (format "%S" value)) 60 body)))) 61 vars) 62 body)) 63 64 (defun org-babel-execute:fomus (body params) 65 "Execute a block of Fomus code with org-babel. 66 This function is called by `org-babel-execute-src-block'." 67 (let* ((result-params (cdr (assq :result-params params))) 68 (out-file (cdr (assq :file params))) 69 (cmdline (cdr (assq :cmdline params))) 70 (cmd (or (cdr (assq :cmd params)) "fomus")) 71 (in-file (org-babel-temp-file "fomus-" ".fms"))) 72 (with-temp-file in-file 73 (insert (org-babel-expand-body:fomus body params))) 74 ;; TMP: testing 75 ;; (message (concat cmd 76 ;; " " (org-babel-process-file-name in-file) 77 ;; " " cmdline 78 ;; " -o " (org-babel-process-file-name out-file))) 79 (org-babel-eval 80 (concat cmd 81 " " (org-babel-process-file-name in-file) 82 " " cmdline 83 " -o " (org-babel-process-file-name out-file)) "") 84 nil)) ;; signal that output has already been written to file 85 86 (defun org-babel-prep-session:fomus (session params) 87 "Return an error because Fomus does not support sessions." 88 (error "Fomus does not support sessions")) 89 90 (provide 'ob-fomus) 91 92 ;;; ob-fomus.el ends here