From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Arne Babenhauserheide (IMK)" Subject: babel for ditaa-eps Date: Wed, 12 Sep 2012 16:00:36 +0200 Message-ID: <50509584.30704@kit.edu> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig80799085B1A02312579E055E" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TBnUo-0007OB-IA for emacs-orgmode@gnu.org; Wed, 12 Sep 2012 10:01:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TBnUh-0000Y5-UO for emacs-orgmode@gnu.org; Wed, 12 Sep 2012 10:00:50 -0400 Received: from mailout.scc.kit.edu ([129.13.185.202]:48339) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TBnUh-0000Xo-Hs for emacs-orgmode@gnu.org; Wed, 12 Sep 2012 10:00:43 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --------------enig80799085B1A02312579E055E Content-Type: multipart/mixed; boundary="------------030406090703000303020203" This is a multi-part message in MIME format. --------------030406090703000303020203 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Dear org hackers, I don=E2=80=99t know if there=E2=80=99s already a babel-ditaa-option for = using ditaa-eps, so I modified ob-ditaa.el to use ditaa-eps and convert the result using epstopdf. Feel free to use it. ;;; ob-ditaa-eps.el --- org-babel functions for ditaa evaluation ;; Copyright (C) 2009-2012 Free Software Foundation, Inc. ;; Author: Eric Schulte und Arne Babenhauserheide ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; This file is part of GNU Emacs. ;; GNU Emacs 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. ;; GNU Emacs 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 GNU Emacs. If not, see . ;;; Commentary: ;; Org-Babel support for evaluating ditaa source code as eps/pdf. ;; ;; Almost verbatim copy from ob-ditaa, but with ditaa-eps and epstopdf ;; as intermediate step. ;; ;; Ditaa differs from most standard languages in that ;; ;; 1) there is no such thing as a "session" in ditaa ;; ;; 2) we are generally only going to return results of type "file" ;; ;; 3) we are adding the "file" and "cmdline" header arguments ;; ;; 4) there are no variables (at least for now) ;;; Code: (require 'ob) (defvar org-babel-default-header-args:ditaa-eps '((:results . "file") (:exports . "results") (:java . "-Dfile.encoding=3DUTF-8")) "Default arguments for evaluating a ditaa source block.") (defcustom org-ditaa-eps-jar-path (expand-file-name "DitaaEps.jar" (file-name-as-directory (expand-file-name "scripts" (file-name-as-directory (expand-file-name "../contrib" (file-name-directory (find-library-name "org"))))))) "Path to the ditaa-eps jar executable." :group 'org-babel :type 'string) (defvar org-ditaa-eps-jar-path) (defun org-babel-execute:ditaa-eps (body params) "Execute a block of Ditaa code with org-babel. This function is called by `org-babel-execute-src-block'." (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) (out-file ((lambda (el) (or el (error "ditaa code block requires :file header argument"))) (cdr (assoc :file params)))) (cmdline (cdr (assoc :cmdline params))) (java (cdr (assoc :java params))) (in-file (org-babel-temp-file "ditaa-")) (cmd0 (concat "java " java " -jar " (shell-quote-argument (expand-file-name org-ditaa-eps-jar-path)) " " cmdline " " (org-babel-process-file-name in-file) " " (org-babel-process-file-name (concat in-file ".eps")))) (cmd1 (concat "epstopdf" " " (org-babel-process-file-name (concat in-file ".eps")) " -o=3D" (org-babel-process-file-name out-file)))) (unless (file-exists-p org-ditaa-eps-jar-path) (error "Could not find ditaa.jar at %s" org-ditaa-eps-jar-path)) (with-temp-file in-file (insert body)) (message cmd0) (shell-command cmd0) (message cmd1) (shell-command cmd1) nil)) ;; signal that output has already been written to file (defun org-babel-prep-session:ditaa-eps (session params) "Return an error because ditaa does not support sessions." (error "Ditaa does not support sessions")) (defun ditaa-eps-mode () (artist-mode)) (provide 'ob-ditaa-eps) ;;; ob-ditaa-eps.el ends here Best wishes, Arne --------------030406090703000303020203 Content-Type: text/x-emacs-lisp; name="ob-ditaa-eps.el" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ob-ditaa-eps.el" ;;; ob-ditaa-eps.el --- org-babel functions for ditaa evaluation ;; Copyright (C) 2009-2012 Free Software Foundation, Inc. ;; Author: Eric Schulte und Arne Babenhauserheide ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; This file is part of GNU Emacs. ;; GNU Emacs 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. ;; GNU Emacs 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 GNU Emacs. If not, see . ;;; Commentary: ;; Org-Babel support for evaluating ditaa source code as eps/pdf. ;;=20 ;; Almost verbatim copy from ob-ditaa, but with ditaa-eps and epstopdf ;; as intermediate step. ;; ;; Ditaa differs from most standard languages in that ;; ;; 1) there is no such thing as a "session" in ditaa ;; ;; 2) we are generally only going to return results of type "file" ;; ;; 3) we are adding the "file" and "cmdline" header arguments ;; ;; 4) there are no variables (at least for now) ;;; Code: (require 'ob) (defvar org-babel-default-header-args:ditaa-eps '((:results . "file") (:exports . "results") (:java . "-Dfile.encoding=3D= UTF-8")) "Default arguments for evaluating a ditaa source block.") (defcustom org-ditaa-eps-jar-path (expand-file-name "DitaaEps.jar" (file-name-as-directory (expand-file-name "scripts" (file-name-as-directory (expand-file-name "../contrib" (file-name-directory (find-library-name "org"))))))) "Path to the ditaa-eps jar executable." :group 'org-babel :type 'string) (defvar org-ditaa-eps-jar-path) (defun org-babel-execute:ditaa-eps (body params) "Execute a block of Ditaa code with org-babel. This function is called by `org-babel-execute-src-block'." (let* ((result-params (split-string (or (cdr (assoc :results params)) "= "))) (out-file ((lambda (el) (or el (error "ditaa code block requires :file header argument"))) (cdr (assoc :file params)))) (cmdline (cdr (assoc :cmdline params))) (java (cdr (assoc :java params))) (in-file (org-babel-temp-file "ditaa-")) (cmd0 (concat "java " java " -jar " (shell-quote-argument (expand-file-name org-ditaa-eps-jar-path)) " " cmdline " " (org-babel-process-file-name in-file) " " (org-babel-process-file-name (concat in-file ".eps")))) (cmd1 (concat "epstopdf" " " (org-babel-process-file-name (concat in-file ".eps")) " -o=3D" (org-babel-process-file-name out-file)))) (unless (file-exists-p org-ditaa-eps-jar-path) (error "Could not find ditaa.jar at %s" org-ditaa-eps-jar-path)) (with-temp-file in-file (insert body)) (message cmd0) (shell-command cmd0) (message cmd1) (shell-command cmd1) nil)) ;; signal that output has already been written to file (defun org-babel-prep-session:ditaa-eps (session params) "Return an error because ditaa does not support sessions." (error "Ditaa does not support sessions")) (defun ditaa-eps-mode () (artist-mode)) (provide 'ob-ditaa-eps) ;;; ob-ditaa-eps.el ends here --------------030406090703000303020203-- --------------enig80799085B1A02312579E055E Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJQUJWIAAoJEFyD82SnDaCegl4H/RUUdO174zFJqIGPJDKR4QjN l5U+LvH42wCkvIhvuIPKyLVFykFaLvkXHVTrp0o/Ss5s+A28RqnxMBYHplr9K8K9 zfXnDGWYPta6gcGUFPQka3gR/sDEYM0tUwU+XDRlURr/8HU3wfSYU2mqtjFonOQ7 lgFsuHvx0SMik9HdnO4OkypdDCZstLAlzsxX5S6E6bNVWSeWU8tPcWXcnO7b84t9 SmUSarKj10IDA5G5FcpdcTEgWWFuiN4gvkQkE3pSeFWUUi6S9C49YDy/nLmDGntf u+JztidlTnpYDiOcGGg356gyizQVL9A3gpn0qZCgWlWXAGd+lNKykVKtRYiEEtM= =4qV8 -----END PGP SIGNATURE----- --------------enig80799085B1A02312579E055E--