The source block behavior changed in Org 9.2. The abbreviation <s
no longer works by default. Instead, you use C-c C-,
which calls org-insert-structure-template
.
Pressing C-c C-,
brings up a dialog. Press TAB
and then enter src R
. This inserts a source block and puts your cursor at the start of the second line (let |
be point):
#+begin_src R
|#+end_src
To then edit inside the block, press C-o
to open a new line.
You can save a template by adding an entry to the org-structure-template-alist
. Put the following somewhere in your init.el
or run it using C-x C-e
:
(add-to-list 'org-structure-template-alist '("r" . "src R"))
Now when you do C-c C-,
you will see an entry for r
in the list. You can follow the same approach for other languages, such as Python, Ruby, etc. Simply replace the cdr in the dotted pair above (the "src R" part).
Additionally, to insert a line between the source block delimiters, you can insert a newline character using C-q C-j
. That is, type src
R
C-q C-j
in the cdr of the dotted pair above. The result will look like:
(add-to-list 'org-structure-template-alist '("R" . "src R
"))
Now when you press R
, Emacs will insert the source block and put your cursor between them on a new line (let |
be point):
#+begin_src R
|
#+end_src