From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jianing Yang Subject: [Babel] How to find out export format in a babel plugin Date: Fri, 25 Mar 2011 11:09:46 +0800 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from [140.186.70.92] (port=41474 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2xPI-0005Pc-6o for emacs-orgmode@gnu.org; Thu, 24 Mar 2011 23:09:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2xPH-0004rz-8w for emacs-orgmode@gnu.org; Thu, 24 Mar 2011 23:09:48 -0400 Received: from mail-gx0-f169.google.com ([209.85.161.169]:61425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q2xPH-0004qw-54 for emacs-orgmode@gnu.org; Thu, 24 Mar 2011 23:09:47 -0400 Received: by mail-gx0-f169.google.com with SMTP id 23so352227gxk.0 for ; Thu, 24 Mar 2011 20:09:46 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi, all I've recently written a babel plugin which does syntax highlighting using pygment. However, I have to specify a '-f html' option every time I use it. It looks like #+begin_src pygment :cmdline -l bash -O linenos -f html exec 3<&0 # copies STDIN, it prevents 'read' stealing STDIN from '$command' while read FN; do test -e "$FN" || rm -iv "$FN" <&3 done < <(find . $level -type l) #+end_src Therefore, my question is that is there a way that a babel plugin can be aware about the export format? If there is, not only I can omit the '-f html' but it could also support for other export format, like latex, transparently. The following is my code: (require 'ob) (require 'ob-eval) (defvar org-babel-default-header-args:pygment '((:results . "html") (:exports . "results")) "Default arguments to use when evaluating a pygment source block.") (defun org-babel-execute:pygment (body params) "Execute a block of Dot 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 (cdr (assoc :file params))) (cmdline (cdr (assoc :cmdline params))) (in-file (org-babel-temp-file "pygment-")) (cmd (concat org-pygment-path " " cmdline " " (org-babel-process-file-name in-file) ))) (unless (file-exists-p org-pygment-path) (error "Could not find pygment at %s" org-pygment-path)) (message (concat "Running Pygment: " cmd)) (with-temp-file in-file (insert body)) (org-babel-eval cmd "") )) (defun org-babel-prep-session:pygment (session params) "Return an error because Dot does not support sessions." (error "Dot does not support sessions")) (provide 'ob-pygment) Thanks very much Regards, Jianing Yang