Function: org-babel-execute:ditaa

org-babel-execute:ditaa is a byte-compiled function defined in ob-ditaa.el.gz.

Signature

(org-babel-execute:ditaa BODY PARAMS)

Documentation

Execute BODY of ditaa code with org-babel according to PARAMS.

This function is called by org-babel-execute-src-block.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-ditaa.el.gz
(defun org-babel-execute:ditaa (body params)
  "Execute BODY of ditaa code with org-babel according to PARAMS.
This function is called by `org-babel-execute-src-block'."
  (let* ((out-file (org-babel-graphical-output-file params))
         (out-file-suffix (file-name-extension out-file))
         ;; backwards-compatibility of :eps and :pdf header arguments
         ;; notice that these take precedence over file type (suffix)
         (legacy-eps (cdr (assq :eps params)))
         (legacy-pdf (cdr (assq :pdf params))))
    (when (and legacy-eps legacy-pdf)
      (error "(ob-ditaa) Both :eps and :pdf legacy output types specified"))
    (let* ((legacy-output-type (or legacy-eps legacy-pdf))
           (eps (or legacy-eps (string= out-file-suffix "eps")))
           (pdf (or legacy-pdf (string= out-file-suffix "pdf")))
           (svg (and (not legacy-output-type) (string= out-file-suffix "svg")))
           (png (and (not legacy-output-type)
                     (or (string= out-file-suffix "png")
                         (not (or svg pdf eps))))) ;; default output type is png
           (ditaa-options (cdr (assq :cmdline params)))
	   (java-options (cdr (assq :java params)))
           (use-eps-jar (or eps pdf))
           (exec-form (if (or (equal org-ditaa-default-exec-mode 'jar) use-eps-jar)
                          (concat org-ditaa-java-exec
                                  (when java-options (concat " " java-options))
                                  " "
                                  ;; use obsolete variable instead of default param if defined
                                  (if (boundp 'org-ditaa-jar-option) org-ditaa-jar-option "-jar")
                                  " "
                                  (shell-quote-argument
                                   (ob-ditaa--ensure-jar-file (if use-eps-jar org-ditaa-eps-jar-path
                                                                org-ditaa-jar-path))))
                        org-ditaa-exec))
	   (in-file (org-babel-temp-file "ditaa-"))
           (ditaa-out-file (org-babel-process-file-name (if pdf (concat in-file ".eps") out-file)))
           (ditaa-coding-system 'utf-8)
	   (cmd (concat exec-form
                        (when ditaa-options (concat " " ditaa-options))
                        (when svg (concat " " "--svg"))
                        " " "-e" " " (symbol-name ditaa-coding-system)
                        " " in-file " " ditaa-out-file)))
      ;; verify that output file type is specified - note that this
      ;; error should in fact never happen, since default png type is
      ;; set above if no other supported type is specified
      (unless (or eps pdf svg png)
        (error (concat "(ob-ditaa) Unknown output file extension: " out-file-suffix)))
      (with-temp-file in-file
        (set-buffer-file-coding-system ditaa-coding-system)
        (insert body))
      (shell-command cmd)
      (when pdf
        (shell-command (concat "epstopdf" " " ditaa-out-file " "
                               "-o=" (org-babel-process-file-name out-file))))
      nil))) ;; signal that output has already been written to file