Quarto is a literate programming framework. It allows you to combine in a single file code (in various programming languages) and text (in markdown).*
When a Quarto document is rendered, the output from the code is combined with the text into a single document (e.g. pdf or html).
I have installed Quarto-emacs
, which does a great job of rendering and live-previewing quarto files. Among other things, I have also installed Polymode
, which associates different code and text blocks with their respective major-modes in a single buffer. Now I can write, code, and preview the results on the fly. Thanks, Emacs!
However, whenever I change some python code block, I have to re-render the whole document (by running markdown-preview
or markdown-compile
). This can take a while. Moreover, I can't run the code block and then continue to experiment in the interpreter (REPL).
So what I want is to run only a selected python code block or the selected and all previous code blocks (like in a Jupyter notebook) in the interpreter (REPL). This works quite well in RStudio, but I would rather stick to Emacs, which in general has great support for Python and R.
It sort of works with R code blocks in Emacs. When I hit C-c b
(ess-eval-buffer
) on an R code block, a buffer with an R console is opened and the block is executed there. I don't know how to evaluate all previous code blocks, however.
But when I hit C-c c
(elpy-shell-send-buffer
), the whole buffer is evaluated instead of just the present code block. Of course, this results in a syntax error. When I try C-c C-y w
elpy-shell-send-codecell
, I get "Not in a codecell".
I also tried several polymode
functions:
polymode-eval-region-or-chunk
producesUndefined ‘polymode-eval-region-function’ in buffer test.qmd[python]
on python blocks but works on R blocks.polymode-eval-buffer
,polymode-eval-buffer-from-beg-to-point
, andpolymode-eval-buffer-from-point-to-end
only run the R blocks, not the Python blocks.
Is there any way to make this work as seamlessly as in RStudio?
*This is a generalization of R Markdown and similar to both org-mode
with org-babel
and Juypter notebooks, which Emacs can display and run using ein
.
markdown-preview
? According to the Quarto documentation you should only have to save the file to update the 'preview'.Quarto-emacs
doesn't preview on file save. See here: github.com/quarto-dev/quarto-emacs/issues/5ess-eval-buffer
works from the .qmd file buffer? Here it does open an R console, but it sends the whole buffer contents instead of the only code block.