0

I've seen in some Emacs videos, the author would type

#+BEGIN_SRC

in their buffer, and emacs auto inserts #+END_SRC.

Is this a feature I can "turn on" in vanilla Emacs? If not, which package can I use?

Basil
  • 12,019
  • 43
  • 69
american-ninja-warrior
  • 3,773
  • 2
  • 21
  • 40
  • Another question related to easy template with more info: https://emacs.stackexchange.com/questions/12841/quickly-insert-source-blocks-in-org-mode – Jules Feb 09 '18 at 00:27
  • 3
    Thanks @Jules, I've flagged the question: Possible duplicate of [Quickly insert source blocks in org mode](https://emacs.stackexchange.com/questions/12841/quickly-insert-source-blocks-in-org-mode). – Basil Feb 09 '18 at 00:30

2 Answers2

3

In Org, you're looking for (org) Easy Templates; try typing <sTAB:

With just a few keystrokes, Org’s easy templates inserts empty pairs of
structural elements, such as ‘#+BEGIN_SRC’ and ‘#+END_SRC’.  Easy
templates use an expansion mechanism, which is native to Org, in a
process similar to ‘yasnippet’ and other Emacs template expansion
packages.

   ‘<’ ‘s’ ‘<TAB>’ expands to a ‘src’ code block.

   ‘<’ ‘l’ ‘<TAB>’ expands to:

   #+BEGIN_EXPORT latex

   #+END_EXPORT

   Org comes with these pre-defined easy templates:

‘s’     ‘#+BEGIN_SRC ... #+END_SRC’
‘e’     ‘#+BEGIN_EXAMPLE ... #+END_EXAMPLE’
‘q’     ‘#+BEGIN_QUOTE ... #+END_QUOTE’
‘v’     ‘#+BEGIN_VERSE ... #+END_VERSE’
‘c’     ‘#+BEGIN_CENTER ... #+END_CENTER’
‘C’     ‘#+BEGIN_COMMENT ... #+END_COMMENT’
‘l’     ‘#+BEGIN_EXPORT latex ... #+END_EXPORT’
‘L’     ‘#+LATEX:’
‘h’     ‘#+BEGIN_EXPORT html ... #+END_EXPORT’
‘H’     ‘#+HTML:’
‘a’     ‘#+BEGIN_EXPORT ascii ... #+END_EXPORT’
‘A’     ‘#+ASCII:’
‘i’     ‘#+INDEX:’ line
‘I’     ‘#+INCLUDE:’ line

   More templates can added by customizing the variable
‘org-structure-template-alist’, whose docstring has additional details.

Outside Org, there are many template expansion packages. I don't use any, but the one I hear about most frequently which is (very) actively maintained is the aforementioned Yasnippet.

See also (emacs) Abbrevs.

Basil
  • 12,019
  • 43
  • 69
1

Melpa delivers a package syntactic-close. The command of this name should do it. Development is at https://github.com/emacs-berlin/syntactic-close

Andreas Röhler
  • 1,894
  • 10
  • 10