1 #+OPTIONS: H:3 num:nil toc:2 \n:nil ::t |:t ^:{} -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc
2 #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate hideblocks
3 #+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
4 #+TAGS: Write(w) Update(u) Fix(f) Check(c) noexport(n)
7 #+EMAIL: numbchild at gmail dot com
9 #+HTML_LINK_UP: index.html
10 #+HTML_LINK_HOME: https://orgmode.org/worg/
15 console.log("Hello, World!");
23 #+begin_src emacs-lisp
26 (add-to-list 'org-babel-load-languages '(js . t))
27 (org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)
28 (add-to-list 'org-babel-tangle-lang-exts '("js" . "js"))
32 * Use JavaScript libraries
34 src_js{console.log()} is supported by default.
37 var util = require("util");
38 console.log("this is a Node.js test program!");
42 : this is a Node.js test program!
44 * Support session for many Emacs packages
46 The header argument :session value of packages REPL buffer names are default.
48 And they all support for auto initiate session with ob-core.el
49 built-in function ~org-babel-initiate-session~, which is used by
50 commands like ~org-babel-switch-to-session~ / ([C-c C-v C-z]).
54 #+begin_src js :session "*JS REPL*"
55 console.log("stardiviner")
60 #+begin_src js :session "*skewer-repl*"
61 console.log("stardiviner")
66 #+begin_src js :session "*Javascript REPL*"
67 console.log("stardiviner")
70 ** helper command to insert session header argument
72 I write an helper command to insert session header argument easily:
74 #+begin_src emacs-lisp
75 (defun ob-js-insert-session-header-arg (session)
76 "Insert ob-js `SESSION' header argument.
81 (interactive (list (completing-read "ob-js session: "
82 '("js-comint" "skewer-mode" "indium"))))
83 (org-babel-insert-header-arg
86 ("js-comint" "\"*Javascript REPL*\"")
87 ("skewer-mode" "\"*skewer-repl*\"")
88 ("indium" "\"*JS REPL*\""))))
90 (define-key org-babel-map (kbd "J") 'ob-js-insert-session-header-arg)