emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Babel] How to find out export format in a babel plugin
@ 2011-03-25  3:09 Jianing Yang
  2011-03-25  4:17 ` Erik Iverson
  0 siblings, 1 reply; 2+ messages in thread
From: Jianing Yang @ 2011-03-25  3:09 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Babel] How to find out export format in a babel plugin
  2011-03-25  3:09 [Babel] How to find out export format in a babel plugin Jianing Yang
@ 2011-03-25  4:17 ` Erik Iverson
  0 siblings, 0 replies; 2+ messages in thread
From: Erik Iverson @ 2011-03-25  4:17 UTC (permalink / raw)
  To: Jianing Yang; +Cc: emacs-orgmode

On 03/24/2011 10:09 PM, Jianing Yang wrote:
> 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.

In git pulls from within the last few weeks, see the variable:
org-export-current-backend

Does your pygment idea have any overlap with:
http://comments.gmane.org/gmane.emacs.orgmode/28420

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-25  4:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-25  3:09 [Babel] How to find out export format in a babel plugin Jianing Yang
2011-03-25  4:17 ` Erik Iverson

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).