gcv / julia-snail

An Emacs development environment for Julia
GNU General Public License v3.0
235 stars 23 forks source link

Executing blocks other than function ... end? #153

Closed wenzlawski closed 5 months ago

wenzlawski commented 5 months ago

How can one send begin ... end, if, or while blocks to the REPL? What about multiline function calls?

Sending a function to the repl with julia-snail-send-top-level or julia-snail-send-dwim works, but anything other block just terminates with No top-level form at point. Is this normal behaviour, or is something wrong with the way I'm using it?

The way I am currently using it is highlighting every block (except function), and executing with julia-snail-send-region. This works but its cumbersome.

gcv commented 5 months ago

You can select a region and use either julia-snail-send-region or julia-snail-send-dwim.

As for julia-snail-send-top-level, it currently detects these constructs: https://github.com/gcv/julia-snail/blob/a25ce847480a0c2bed24fad3f1ee62904c9c93a5/JuliaSnail.jl#L581-L587 — i.e., it detects a bunch of things as top-level forms, but there's probably room for improvement.

Sabancay commented 5 months ago

I recommend using expreg to select regions. It uses treesitter. Mark paragraph often gives a good selection candidate, when the code is strctured by new lines.

I use the following keys/commands to select:

:map julia-ts-mode-map ("C-c p" . mark-paragraph) ("C-c f" . mark-defun) ("C-+" . expreg-expand) ("C--" . expreg-contract)

and these to feed the REPL:

 :map julia-snail-mode-map
    ("S-<return>"   . julia-snail-send-dwim)
    ("C-<return>"   . julia-snail-send-region)
    ("M-<return>"   . julia-snail-send-line)
    ("C-S-<return>" . julia-snail-send-buffer-file)
wenzlawski commented 5 months ago

Expreg is just what I was looking for. Thank you!