previous article
Compounding Confoundment: arbitrary interpreters for Babel // Bodacious Blog

Automate the process of changing the babel block wrapper

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(defun org-babel-raise ()
  "Move the interior of a babel to the outside: remove the babel block chrome and keep only the source code."
  (interactive)
  (evil-with-single-undo
    ;; put a line after the block
    (call-interactively 'org-mark-element)
    (ekm "C-x C-x")
    (insert "\n")
    (ekm "<up>")
    (ekm "C-x C-x")

    (ekm "C-c '")
    (ekm "C-x h")
    (ekm "C-x h")
    (ekm "M-w")
    (ekm "C-c '")
    (call-interactively 'org-babel-mark-block)
    (ekm "<up>")
    (ekm "C-x C-x")
    (ekm "<down>")
    (ekm "C-y")
    (ekm "C-x C-x")))

(defun org-babel-change-block-type ()
  (interactive)
  (if (org-in-src-block-p)
      (progn
        (call-interactively 'org-babel-raise)
        (call-interactively 'hydra-org-template/body))
    (self-insert-command 1)))

(define-key org-mode-map (kbd ">") 'org-babel-change-block-type)

I have accidentally made this into the wrong type of babel (i.e. sh).

1
2
3
4
#+BEGIN_SRC sh -n :async :results verbatim drawer
  # This is a command to grep my emacs config directory for some bindings
  cd $EMACSD/config; ead "define-key.*M-l"
#+END_SRC

I can turn it into a different one by pressing >.

1
2
3
4
#+BEGIN_SRC sh -n :interpreter "spv bash" :async :results none
  # This is a command to grep my emacs config directory for some bindings
  cd $EMACSD/config; ead "define-key.*M-l"
#+END_SRC

I just turned it into an “spv bash” babel!

asciinema recording