Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I run scala code blocks in org-mode? #148

Open
ag91 opened this issue Apr 13, 2018 · 11 comments
Open

How do I run scala code blocks in org-mode? #148

ag91 opened this issue Apr 13, 2018 · 11 comments

Comments

@ag91
Copy link

ag91 commented Apr 13, 2018

Thanks for the great software guys.
I am a heavy user of org mode and I would like to evaluate scala blocks.
Is there an explanation somewhere on how to do it?

I would like to be able to C-c C-c on a block such this:

#+BEGIN_SRC scala :results output
println("hi")
#+END_SRC

And get something like:

#+RESULT:
hi

However if I try, I get Not connected. M-x ensime to connect.
Now I understand I need an Ensime session running, but after setting up one for a sample project (build.sbt and running sbt ensimeConfig), it still does not work.

Am I missing something? Is there any tutorial/docs on how to do this?

Ideally I would like to run the previous source block just with the Scala binary,
and I would like to have the option to run the great Ensime with something like:

#+BEGIN_SRC scala :ensime-project /someDir :session someSession
import superCoolDependency;

println(superCoolDependency.superCoolPrintout())
#+END_SRC

And using the session to refer to the Ensime connection in future blocks.

Thanks again!

@khayyamsaleem
Copy link

You need to run an Ensime session inside the editor. Try M-x ensime

@hb9
Copy link

hb9 commented May 31, 2018

Dirty workaround that works for me: replace ob-scala.el (located in your elpa-folder/scala-mode) with https://raw.githubusercontent.com/tkf/org-mode/master/lisp/ob-scala.el

You can then use :results output without ensime.

(It will break as soon you update or reinstall scala-mode)

@ag91
Copy link
Author

ag91 commented Jun 1, 2018

@hb9 that is helpful indeed!
I knew about a previous ob-scala that was actually meeting this use case scenario,
but I think the current one should still satisfy it (otherwise why replace it at all?).

@khayyamsaleem I have actually tried and is not working: maybe I am doing something wrong. If it is working for you, could you list the steps you are following?

@hb9
Copy link

hb9 commented Jun 1, 2018

I have actually tried and is not working: maybe I am doing something wrong. If it is working for you, could you list the steps you are following?

You need to run M-x ensime in a buffer that is somehow connected to a .ensime config-file. E.g. in a buffer that belongs to a scala-project with a working ensime configuration. Then you need to also set the directory of the org-code-block via :dir your/scala_project/with/ensime_config to that project folder. Those steps are at least working for me. It gives me the output of the scala-repl for that code-block.

I still think that my org-files should not depend on .ensime config-files. I would also appreciate it if the old functionality would be restored.

@eikek
Copy link

eikek commented Jun 15, 2018

I also have problems with this new implementation. My scala snippets are not working anymore, because it wants me to start ensime now. Is it now required to have a working and running ensime to execute scala source blocks in org files?

@ag91
Copy link
Author

ag91 commented Jun 28, 2018

By the way, I have automated the setup to use org and ensime together. Maybe you could find it useful as well: https://github.com/ag91/EasyOrgEnsime
I welcome feedback :)

@eikek
Copy link

eikek commented Jun 29, 2018

@ag91 that looks nice, thanks! I now copied the old ob-scala.el to my .emacs dir and load it after org. I'm using ammonite for the scala snippets and can work with dependencies that way. I would still like to not be required having a ensime process running to evaluate some snippets.

@ant-t
Copy link

ant-t commented Jul 8, 2018

Is there any progress on this? I just need a few throwaway lines in scala as part of a org-mode notebook being passed around.

It seems counterproductive for org-mode to offload their ob-scala.el to a third party which is not tied to their release schedule.

@ccarlile
Copy link

@eikek How did you get scala snippets working with ammonite?

@eikek
Copy link

eikek commented Dec 12, 2018

@ccarlile I think this is the relevant part in my config:

(setq org-babel-scala-command "amm")
(setq org-babel-scala-wrapper-method "%s")
;; load “old” ob-scala  
(load-file (concat user-emacs-directory "lisp/ob-scala.el"))

The downside is that it only works with stdout output… It could be improved I guess

@dmg46664
Copy link

dmg46664 commented Jun 3, 2019

It's a great pity that this is not accommodated out the box. Orgmode is a big part of the reason I use Emacs, and I end up using other languages (js, python, elisp), specifically not Scala, for org blocks in order to achieve things.

eikek added a commit to eikek/init.el that referenced this issue Nov 6, 2019
- new ob-scala requires a running ensime session (which is a bad idea
  imho)

- see hvesalai/emacs-scala-mode#148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants