Orgmode Library of Babel implementation of sclang support in code blocks
Go to file

README.org

Why do I even?

Org-mode makes literate programming easy via Library of Babel. Il simply allows to mix text with executable code blocks which can also be extracted (tangled) into separate, executable files. The beauty of the Library of Babel implementation in org-mode lies in the fact that it supports many languages. I craved support for SuperCollider and craving became an itch when I needed to document a working pipeline alternating between executing sclang and shell scripts. I scratched an itch with this little module.

How to install?

First of all, you will need emacs (>=26) and SuperCollider (with emacs support) installed. Modern emacsen and Spacemacs come with bundled org-mode.

It can be installed as a package via Melpa or manually.

(use-package ob-sclang
   :config (org-babel-do-load-languages
            'org-babel-load-languages
            '((sclang . t))))

To install manually you can either drop file:ob-sclang.el somewhere in your Emacs' path or add its containing directory to load-path in .init file:

(add-to-list 'load-path "/path/to/ob-sclang/")

You will also have to add it to (org-babel-do-load-languages)

(require 'ob-sclang)
(org-babel-do-load-languages
    'org-babel-load-languages
    '((sclang . t)))

And then?

Well, then you type a block like this one:

#+BEGIN_SRC sclang
  "boo".postln;
#+END_SRC

And after you hit C-c C-c you should see the string appear in your SCLang:PostBuffer*

Note:, make sure you execute sclang-start prior to executing any sclang code blocks

Use of variables

You can also include variables to be passed to you sclang code:

#+BEGIN_SRC sclang :var boo="hoo" :var pi=3.14159 :var year=2000 :var buf='foo
  boo.postln;
  pi.postln;
  year.postln;
  buf.postln;
#+END_SRC

Will reformat your sclang body to:

"hoo".postln;
3.141590.postln;
2000.postln;
"foo".asSymbol.postln;

Before passing it on to the sclang process.

The use of sclang's own global variables is persistent between code blocks so ~boo

#+BEGIN_SRC sclang
  ~boo = "hoo";
#+END_SRC

is accessible here:

#+BEGIN_SRC sclang
  ~boo.postln;
#+END_SRC

Known issues

At this point, this plugin has a very crude functionality. It allows unidirectional control of SuperCollider process running inside Emacs. As such, here is a list of issues:

Of course feel free to open questions, suggestions, discussions and even pull requests.

Some tests

The code blocks beyond this point can be executed from an org buffer:

Post some string to SC's Post Buffer:

"boo".postln;

This python code does not need to be evaluated beforehand because it will be evaluated by sclang block below.

[1,2,3,4]
1 2 3 4

And we will use this table as input data

boo 5 9
good 7 xa

And here we execute some sclang that simply reads variables specified in code block's header. They include named python codeblock above and the table.

x.postln;
x.class.postln;
y.postln;
y.class.postln;
z.postln;
z.class.postln;
table.postln;
table.class.postln;
table[0].postln;
tb.postln;
tb.class.postln;

And this is the output to SC's Post Buffer.

10
Integer
11
Integer
1.1
Float
[ [ boo, 5, 9 ], [ good, 7, xa ] ]
Array
[ boo, 5, 9 ]
[ 1, 2, 3, 4 ]
Array

Michal Seta 2eb8101151
Merge pull request #5 from zzkt/main
melpa compatibility
2022-07-30 10:25:39 -04:00
.github/workflows melpa workflow 2022-07-30 12:36:01 +02:00
.gitignore melpa compatability 2022-07-30 12:18:39 +02:00
LICENSE the genesis 2018-07-25 15:53:33 -04:00
README.org melpa compatability 2022-07-30 12:18:39 +02:00
ob-sclang.el melpa compatability 2022-07-30 12:18:39 +02:00
tests.org an example/test orgmode file 2020-03-26 09:10:35 -04:00