tpapp / julia-repl

Run an inferior Julia REPL in a terminal inside Emacs
Other
170 stars 35 forks source link

Send code in cells #60

Open nbrantut opened 5 years ago

nbrantut commented 5 years ago

Would it be possible to evaluate (i.e., send code to repl) code as cells (like juno, or matlab-style), for instance whatever is between ## or equivalent?

This might be linked to implementing issues reported in #19 (optionnally together with #18), but there might be an additional job for regexp tracking the cell separation symbols (maybe even highlight cells, ideally...)

I was looking to implement this myself, but my elisp is not good at all. I'll give it a go but this might look horrible.

tpapp commented 5 years ago

I think Jupyter notebook interfaces already handle this kind of workflow very well and there doesn't seem to be a lot of payoff from duplicating this. You may find eg

https://github.com/millejoh/emacs-ipython-notebook

useful.

nbrantut commented 5 years ago

Thanks for the answer; I have used the notebooks in emacs using the package you point to, but found it unecessarily cumbersome, especially for short codes. I was just thinking of doing a extremely stripped down version of cells by having a simple syntax marker that lets me evaluate a bunch of lines without having to mark the region by moving the cursor around.

But yes if that's not something you think is of interest fair enough!

recri commented 4 years ago

You might look at the literate programming support in emacs org-mode, it lists a contributed julia package already. https://orgmode.org/manual/Working-with-source-code.html

untoreh commented 3 years ago

the ob-julia module in org-mode depends on ess, the EIN or emacs-jupyter packages require...a jupyter server, there is a ob-julia-vterm package but it is synchronous and now julia-repl has vterm support anyway.. this is what I am using currently, to execute code blocks in the repl, same as https://github.com/diadochos/org-babel-eval-in-repl

(defun org-babel-execute:julia (body params)
    (interactive)
    (setq
     julia-repl-inferior-buffer-name-suffix
     (intern (rest (assoc :session params))))
    (julia-repl--send-string
     (org-babel-expand-body:julia body params)))

However I have also to redefine julia-repl--inferior-buffer-name otherwise the session isn't picked up...not sure why

jonasseglare commented 2 years ago

There is a library for Emacs that does this for Python source code: https://github.com/thisch/python-cell.el

I actually took this code and modified it to work for Clojure instead. And it would probably also be easy to adapt it for Julia.

Edit: I got it working for Julia with just very few changes :-)

juliacell

This is what I did:

  1. Downloaded python-cell.py and to the file ~/.emacs.d/julia-cell/julia-cell.el
  2. Replaced line (require 'python) by (require 'julia-repl) in that file.
  3. Replaced line (python-shell-send-region start end) by (julia-repl--send-string (buffer-substring-no-properties start end)).
  4. Did search/replace from python to julia in that file.
  5. Added the necessary commands to load the julia-cell.el code in my init.el file:
    (add-to-list 'load-path "~/.emacs.d/julia-cell")
    (require 'julia-cell)
    (add-hook 'julia-mode-hook 'julia-cell-mode)

I think it would be cool to have this kind of functionality being part of julia-repl. Another option would be to extend the python-cell repo to generalize for Julia, not sure what is best.