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-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
Undefined ‘polymode-eval-region-function’ in buffer test.qmd[python]on python blocks but works on R blocks.
polymode-eval-buffer-from-point-to-endonly run the R blocks, not the Python blocks.
Is there any way to make this work as seamlessly as in RStudio?