Org-babel-js

Table of Contents

hello, world demo

console.log("Hello, World!");
Hello, World!

Configuration

(require 'ob-js)

(add-to-list 'org-babel-load-languages '(js . t))
(org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)
(add-to-list 'org-babel-tangle-lang-exts '("js" . "js"))

Use JavaScript libraries

console.log() is supported by default.

var util = require("util");
console.log("this is a Node.js test program!");
this is a Node.js test program!

Support session for many Emacs packages

The header argument :session value of packages REPL buffer names are default.

And they all support for auto initiate session with ob-core.el built-in function org-babel-initiate-session, which is used by commands like org-babel-switch-to-session / ([C-c C-v C-z]).

Indium

console.log("stardiviner")

skewer-mode

console.log("stardiviner")

js-comint

console.log("stardiviner")

helper command to insert session header argument

I write an helper command to insert session header argument easily:

(defun ob-js-insert-session-header-arg (session)
  "Insert ob-js `SESSION' header argument.
- `js-comint'
- `skewer-mode'
- `Indium'
"
  (interactive (list (completing-read "ob-js session: "
                                      '("js-comint" "skewer-mode" "indium"))))
  (org-babel-insert-header-arg
   "session"
   (pcase session
     ("js-comint" "\"*Javascript REPL*\"")
     ("skewer-mode" "\"*skewer-repl*\"")
     ("indium" "\"*JS REPL*\""))))

(define-key org-babel-map (kbd "J") 'ob-js-insert-session-header-arg)

Documentation from the orgmode.org/worg/ website (either in its HTML format or in its Org format) is licensed under the GNU Free Documentation License version 1.3 or later. The code examples and css stylesheets are licensed under the GNU General Public License v3 or later.