Skip to content

Instantly share code, notes, and snippets.

@mitunya
Created March 1, 2023 23:03
Show Gist options
  • Save mitunya/46ae0c8e063dc8869e250640731459c9 to your computer and use it in GitHub Desktop.
Save mitunya/46ae0c8e063dc8869e250640731459c9 to your computer and use it in GitHub Desktop.
org-mode ob-dot
(defun org-babel-execute:dot (body params)
"Execute a block of Dot 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-"))
(script-file (org-babel-temp-file "dot-script-"))) ;;; when use script-file
(with-temp-file in-file
(insert (org-babel-expand-body:dot body params)))
;; org-babel-eval
(with-temp-file script-file
(insert (concat cmd
" " (org-babel-process-file-name in-file)
" " cmdline
" -o " (org-babel-process-file-name out-file))))
(set-file-modes script-file #o755)
(org-babel-eval script-file "")
;; ;; original
;; (org-babel-eval
;; (concat cmd
;; " " (org-babel-process-file-name in-file)
;; " " cmdline
;; " -o " (org-babel-process-file-name out-file)) "")
nil))
#+BEGIN_SRC dot :file o.svg :results file :exports both00
digraph {
A -> B;
}
#+END_SRC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment