ThibautVerron / ob-magma

Support for magma in org-babel
1 stars 1 forks source link

-- ##: (visual-line-mode 1); ##: (visual-fill-column-mode 1); --

This package is by no means ready for production use. I have stopped working on it in the spring of 2015, so I may not be able to provide support. But please, if you test it and encounter issues, feel free to post them here for reference.

If someone is wishing to pursue developing this package, I will be glad to help to my best capacity.

This package provides support for magma evaluation with org-babel. Evaluation is made in a unique magma session, explicit naming of sessions is possible.

Results type can be either 'output or 'value, in which case magma tries to determine whether the output is a table or not. If your output is a sequence and you do not wish to format it as a table, use 'output for this code block.

Tne parameter =:magma-eval t= causes the block to be enclosed in an =eval= form. The output value is given by the =return= statement. At the moment, nothing is done to suppress other forms of output. This evaluation method corresponds to ='value= for most other modes, but due to limits with magma =eval= (for example, no side effect is possible), making it the default would be counter-intuitive.

This package is intended to be used with the =magma-mode= available [[https://github.com/ThibautVerron/magma-mode][here]], but in theory, it could work with any =magma-mode= providing a function =magma-run (&optional session)= creating a magma interactive buffer and returning it. The function may disregard the =session= argument, in which case the =:session= parameter of org will have no effect.

** Examples

(Please see the [[https://raw.githubusercontent.com/ThibautVerron/ob-magma/master/README.org][readme in raw org form]] for the results of the examples)

Results are handled as string by default:

+begin_src magma :var x=5

print(3+3); print(x+3);

+end_src

+RESULTS:

: 6 : 8

If the result is a sequence, it is returned as a =org= table.

+begin_src magma

print([[1,2,3],[4,5,6],[7,8,9]]);

+end_src

+RESULTS:

| 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 |

If this is unwanted, use the =:results output= parameter.

+begin_src magma :results output

print([[1,2,3],[4,5,6],[7,8,9]]);

+end_src

+RESULTS:

: [ : [ 1, 2, 3 ], : [ 4, 5, 6 ], : [ 7, 8, 9 ] : ]

A special evaluation method is given by the =:eval= parameter. In this setting, all code is wrapped in an =eval= form, and evaluated. The code block should have a return statement and avoid printing overall (this will be fixed in the future).

+begin_src magma :eval t

x := 3; y := 4; return x + y;

+end_src

+RESULTS:

: 7

Finally, session-based evaluation is also supported:

+begin_src magma :session "ses1"

x := 3; print x;

+end_src

+RESULTS:

: 3

+begin_src magma :session "ses2"

x := 4; print x;

+end_src

+RESULTS:

: 4

+begin_src magma :session "ses1"

print x;

+end_src

+RESULTS:

: 3