zwild / ob-ammonite

org-babel for scala evaluation in Ammonite
GNU General Public License v3.0
14 stars 2 forks source link

Get the last statement/eval only ? #4

Open reyman opened 4 years ago

reyman commented 4 years ago

Thanks for your work on ob-ammonite :) Is there a way to tune ob-ammonite to only get the last result evaluated using the :results value header given by org ?

For example this code :


#+begin_src amm :results value html :exports results
import $ivy.`org.scala-js::scalajs-library:0.6.31`
import $ivy.`com.lihaoyi::scalatags:0.8.2`, scalatags.Text.all._
val t =  div(
      p("This is my first paragraph"),
      p("This is my second paragraph")
    )
print(t.toString)
#+end_src

need return like this


#+RESULTS:
#+begin_export html
<div><p>This is my first paragraph</p><p>This is my second paragraph</p></div>import $ivy.$
#+end_export 
zwild commented 4 years ago

It seems that it's the return value by some specific libraries. Could you pull a request if you need that?

reyman commented 4 years ago

I'm don't know emacs lisp very well, but i could try to modify part of your code.

We could imagine a behavior similar to non system REPL like Python :

The two classical header options of org-mode "output" or "value" are both supported by ob-python, with behavior dependending on using "session" or "non-session" mode :

Also, in non-session mode, the python code block will be wrapped in a function, so to return a value (in :results value mode) you have to use a return statement. In session mode, the python code is evaluated directly by the interpreter, not in a function context, and the last statement's value will be automatically returned, so you must not use a return statement.

Perhaps i may be wrong on that, but we could imagine very close use case between ob-python and ob-ammonite