From: Jianing Yang <jianingy.yang@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [Babel] How to find out export format in a babel plugin
Date: Fri, 25 Mar 2011 11:09:46 +0800 [thread overview]
Message-ID: <AANLkTimZkxZMsrf7rAdhs2KWrAYLo0fy_JxwZ8XHMjZy@mail.gmail.com> (raw)
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
next reply other threads:[~2011-03-25 3:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-25 3:09 Jianing Yang [this message]
2011-03-25 4:17 ` [Babel] How to find out export format in a babel plugin Erik Iverson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTimZkxZMsrf7rAdhs2KWrAYLo0fy_JxwZ8XHMjZy@mail.gmail.com \
--to=jianingy.yang@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).