Merge branch 'maint'
[org-mode.git] / contrib / lisp / ob-sclang.el
blobd2d1b71f3c62dabb85a423f34091845df5b63176
1 ;;; ob-sclang.el --- SCLang support for Org-mode Babel
2 ;;; -*- coding: utf-8 -*-
4 ;; Copyright (C) 2017 Free Software Foundation, Inc.
6 ;; Authors: stardiviner <numbchild@gmail.com>
7 ;; Package-Version: 0.1
8 ;; Keywords: babel sclang
10 ;; This file is not part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; `ob-sclang' requires `sclang-interp' from SuperCollider.
28 ;; Usually SuperCollider dependencies for Emacs are at /usr/share/emacs/site-lisp/SuperCollider/
29 ;; You can install SuperCollider following this article:
30 ;; https://github.com/supercollider/supercollider#building-the-source-code
32 ;; Usage:
34 ;; Support to evaluate sclang Org-mode src block with function `sclang-eval-string'.
36 ;; For example:
38 ;; #+BEGIN_SRC sclang :results none
39 ;; "Hello World".postln;
40 ;; #+END_SRC
42 ;; *NOTE* Temporary output to org-babel result output is not supported.
43 ;; Because `sclang-eval-string' will send output to Sclang Post Buffer.
44 ;; And command line `sclang' execute will not automatically stop after finished execution.
46 ;; #+BEGIN_SRC sclang :results none
47 ;; // modulate a sine frequency and a noise amplitude with another sine
48 ;; // whose frequency depends on the horizontal mouse pointer position
49 ;; {
50 ;; var x = SinOsc.ar(MouseX.kr(1, 100));
51 ;; SinOsc.ar(300 * x + 800, 0, 0.1)
52 ;; +
53 ;; PinkNoise.ar(0.1 * x + 0.1)
54 ;; }.play;
55 ;; #+END_SRC
58 ;;; Code:
59 ;;; ----------------------------------------------------------------------------
60 (require 'org)
61 (require 'ob)
63 (require 'sclang-interp)
65 (defgroup ob-sclang nil
66 "org-mode blocks for SuperCollider SCLang."
67 :group 'org)
69 ;;;###autoload
70 (defun org-babel-execute:sclang (body params)
71 "Org-mode Babel sclang hook for evaluate `BODY' with `PARAMS'."
72 (unless (or (equal (buffer-name) sclang-post-buffer)
73 (sclang-get-process))
74 (sclang-start))
75 (sclang-eval-string body t))
77 (defvar org-babel-default-header-args:sclang nil)
79 (setq org-babel-default-header-args:sclang
80 '((:session . "*SCLang:Workspace*")
81 ;; TODO: temporary can't find way to let sclang output to stdout for org-babel.
82 (:output . "none")))
84 (eval-after-load "org"
85 '(progn
86 (add-to-list 'org-src-lang-modes '("sclang" . sclang))))
88 ;;; ----------------------------------------------------------------------------
90 (provide 'ob-sclang)
92 ;;; ob-sclang.el ends here