[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] [Babel] How to find out export format in a babel plugin
From: |
Jianing Yang |
Subject: |
[O] [Babel] How to find out export format in a babel plugin |
Date: |
Fri, 25 Mar 2011 11:09:46 +0800 |
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
- [O] [Babel] How to find out export format in a babel plugin,
Jianing Yang <=