[ESS] Integration of pandoc using polymode+knitr
Mathieu Basille
basille.web at ase-research.org
Tue Mar 11 02:59:19 CET 2014
Le 03/10/2014 09:16 PM, Ed Kademan a écrit :
>
> [...]
>
> When you define a function you need to include an argument list. Your code
> should probably start out looking something like this
>
> (defun ess-swv-pandoc ()
> (interactive)
> "Run Pandoc on the associated .md file."
>
Ah, that's perfect! Just what I was missing. Well, this shows how bad I am
regarding Lisp! Thanks Ed!
Here is my working function, definitely not a clean approach, and totally
dependent on my system, but it should get those people interested started,
and it's working at least for me:
(defun ess-swv-pandoc ()
"Run Pandoc on the associated .md file."
(interactive)
(let* ((rmd-buf (current-buffer)))
(save-excursion
(let* ((sprocess (ess-get-process ess-current-process-name))
(sbuffer (process-buffer sprocess))
(md-filename (file-name-sans-extension (buffer-file-name)))
(buf-coding (symbol-name buffer-file-coding-system))
(pandoc-cmd
(format "require(knitr); pandoc(\"%s.md\", format =
\"html\", config =
\"/home/mathieu/.emacs.d/config/config.pandoc\")"
md-filename)))
(message "Running pandoc on %s.md" md-filename)
(ess-execute pandoc-cmd 'buffer nil nil)
(switch-to-buffer rmd-buf)
(ess-show-buffer (buffer-name sbuffer) nil)))))
(define-key polymode-mode-map [(control f5)] 'ess-swv-pandoc)
Since I associated (f5) to 'ess-swv-weave, I can first weave the .Rmd file
using knitr (f5) and then render as HTML the resulting file using the
knitr::pandoc (C-f5). All Pandoc options are then tuned in
/home/mathieu/.emacs.d/config/config.pandoc, see [1] for more details.
Now, this does exactly what I wanted, thanks a lot!
Mathieu.
[1] http://yihui.name/knitr/demo/pandoc/
--
~$ whoami
Mathieu Basille, PhD
~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille
~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
-- Paul Éluard
More information about the ESS-help
mailing list