forked from FG42/FG42
86 lines
2.9 KiB
EmacsLisp
86 lines
2.9 KiB
EmacsLisp
;;; ob-gharphviz --- org-babel functions for gharphviz evaluation of FG42
|
|
;;
|
|
;; Copyright (c) 2010-2024 Sameer Rahmani & Contributors
|
|
;;
|
|
;; Author: Sameer Rahmani <lxsameer@gnu.org>
|
|
;; URL: https://devheroes.codes/FG42/FG42
|
|
;; Version: 4.0.0
|
|
;;
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
;;
|
|
;; This program is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
;;
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
;;
|
|
;;; Commentary:
|
|
|
|
;; This file location is important and can't be under `fg42/' dir even
|
|
;; though it is part of the FG42. That's due to the `org-babel' mechanism
|
|
;; to automatically load the language backend. SO DO NOT MOVE IT.
|
|
|
|
;;; Code:
|
|
(require 'ob)
|
|
(require 'ob-ref)
|
|
(require 'ob-comint)
|
|
(require 'ob-eval)
|
|
(require 'ob-dot)
|
|
|
|
|
|
(add-to-list 'org-babel-tangle-lang-exts '("graphviz-dot" . "dot"))
|
|
|
|
(defvar org-babel-default-header-args:graphviz-dot
|
|
'((:results . "file") (:exports . "results")))
|
|
|
|
(defun org-babel-expand-body:ghraphviz-dot (body params &optional processed-params)
|
|
"Expand BODY according to PARAMS, return the expanded body."
|
|
(let ((vars (org-babel--get-vars params)))
|
|
(mapc
|
|
(lambda (pair)
|
|
(let ((name (symbol-name (car pair)))
|
|
(value (cdr pair)))
|
|
(setq body
|
|
(replace-regexp-in-string
|
|
(concat "$" (regexp-quote name))
|
|
(if (stringp value) value (format "%S" value))
|
|
body
|
|
t
|
|
t))))
|
|
vars)
|
|
body))
|
|
|
|
(defun org-babel-execute:graphviz-dot (body params)
|
|
"Execute a block of Template code with org-babel.
|
|
This function is called by `org-babel-execute-src-block'"
|
|
(let* ((out-file (cdr (or (assq :file params)
|
|
(error "You need to specify a :file parameter"))))
|
|
(cmdline (or (cdr (assq :cmdline params))
|
|
(format "-T%s" (file-name-extension out-file))))
|
|
(cmd (or (cdr (assq :cmd params)) "dot"))
|
|
(coding-system-for-read 'utf-8) ;use utf-8 with sub-processes
|
|
(coding-system-for-write 'utf-8)
|
|
(in-file (org-babel-temp-file "dot-")))
|
|
(with-temp-file in-file
|
|
(insert (org-babel-expand-body:dot body params)))
|
|
(org-babel-eval
|
|
(concat cmd
|
|
" " (org-babel-process-file-name in-file)
|
|
" " cmdline
|
|
" -o " (org-babel-process-file-name out-file)) "")
|
|
;; signal that output has already been written to file
|
|
nil))
|
|
|
|
|
|
(defun org-babel-prep-session:graphviz-dot (session params)
|
|
"Prepare SESSION according to the header arguments specified in PARAMS."
|
|
(error "Dot does not support sessions"))
|
|
|
|
(provide 'ob-graphviz-dot)
|
|
;;; ob-graphviz-dot.el ends here
|