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?

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.