Extending org-mode Easy Templates

March 2, 2018

I frequently use org-mode Easy Templates and I noticed I often miss shortcut for comment block (BEGIN_COMMENT/END_COMMENT) which is very useful from time to time.

Let's add that feature.

(add-to-list 'org-structure-template-alist
             '("C" "#+BEGIN_COMMENT\n?\n#+END_COMMENT" ""))

C is character used to trigger completion by entering <C and pressing TAB - Emacs will then replace it with this block:

#+BEGIN_COMMENT

#+END_COMMENT

? is place where cursor will be set after expation.

Third argument in list I'm adding (empty string) is for Muse-like tags, which I'm not using at all.

Curious fact is that we are not limited to single character to trigger expansion - we can use words too:

(add-to-list 'org-structure-template-alist
             '("comment" "#+BEGIN_COMMENT\n?\n#+END_COMMENT" ""))

Entering <comment and pressing TAB will again expand it to above comment block.