babel: updating ob-dot.el and ob-mscgen.el to use ob-eval

This commit is contained in:
Eric Schulte 2010-07-05 19:03:25 -07:00
parent 07b8908903
commit 2538e687da
2 changed files with 17 additions and 18 deletions

View File

@ -40,8 +40,10 @@
;;; Code:
(require 'ob)
(require 'ob-eval)
(defvar org-babel-default-header-args:dot '((:results . "file") (:exports . "results"))
(defvar org-babel-default-header-args:dot
'((:results . "file") (:exports . "results"))
"Default arguments to use when evaluating a dot source block.")
(defun org-babel-expand-body:dot (body params &optional processed-params)
@ -57,8 +59,7 @@ called by `org-babel-execute-src-block'."
(cmd (or (cdr (assoc :cmd params)) "dot"))
(in-file (make-temp-file "org-babel-dot")))
(with-temp-file in-file (insert body))
(message (concat cmd " " in-file " " cmdline " -o " out-file))
(shell-command (concat cmd " " in-file " " cmdline " -o " out-file))
(org-babel-eval (concat cmd " " in-file " " cmdline " -o " out-file) "")
out-file))
(defun org-babel-prep-session:dot (session params)

View File

@ -28,7 +28,8 @@
;; sequence charts. The mscgen utility is used for processing the
;; sequence definition, and must therefore be installed in the system.
;;
;; Mscgen is available and documented at http://www.mcternan.me.uk/mscgen/index.html
;; Mscgen is available and documented at
;; http://www.mcternan.me.uk/mscgen/index.html
;;
;; This code is directly inspired by Eric Schulte's ob-dot.el
;;
@ -55,6 +56,7 @@
;;; Code:
(require 'ob)
(require 'ob-eval)
(defvar org-babel-default-header-args:mscgen
'((:results . "file") (:exports . "results"))
@ -64,22 +66,18 @@
"Expand BODY according to PARAMS, return the expanded body." body)
(defun org-babel-execute:mscgen (body params)
"Execute a block of Mscgen code with org-babel. This function is
called by `org-babel-execute-src-block'.
Default filetype is png. Modify by setting :filetype parameter to mscgen supported formats."
"Execute a block of Mscgen code with org-babel. This function
is called by `org-babel-execute-src-block'. Default filetype is
png. Modify by setting :filetype parameter to mscgen supported
formats."
(message "executing Mscgen source code block")
(let* ((out-file (or (cdr (assoc :file params)) "output.png" ))
exit-code
(filetype (or (cdr (assoc :filetype params)) "png" ))
(stderr
(with-temp-buffer
(insert body)
(setq exit-code (org-babel-shell-command-on-region
(point-min) (point-max) (concat "mscgen -T " filetype " -o " out-file)
nil 'replace (current-buffer)))
(buffer-string))))
(unless (cdr (assoc :file params)) (setq stderr (concat stderr "\nERROR: no output file specified. Add \":file some_name.png\" to the src header" )) (error stderr))
(if (> exit-code 0) (org-babel-error-notify exit-code stderr))
(filetype (or (cdr (assoc :filetype params)) "png" )))
(unless (cdr (assoc :file params))
(error (concat
"\nERROR: no output file specified. "
"Add \":file some_name.png\" to the src header")))
(org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body)
out-file))
(defun org-babel-prep-session:mscgen (session params)