Does anybody know of a way or a package that can recognize < and > when occuring in template contexts and automatically writes a > either right after the < or after the selected region when typing a <? (In other words, that behaves just as normal paren completion.)

I know that < and >are ambiguous if not evaluated in context and that this might therefore not be possible, that's why I am asking if anybody knows of a solution.

If however not all cases can be covered for technical reasons at least some would be possible, for example whenever < is typed right after template or when a block is selected that stands after template. And maybe some other cases.

2 Answers 2


Have a look at the package smartparens. It can be installed from melpa.

You can enable pairs of <> with:

(sp-with-modes '(c-mode c++-mode)
    (sp-local-pair "<" ">"))

after (require 'smartparens-config)

But be sure to finetune the rule. Have a look at the pair documentation and the complete documentation.

  • thanks, by default the completion for < seems to not use any heuristics and acts completely "dumb" and does not recognise when < actually is a comparison operator. Do you know if it says how to fix this anywhere in the documentation? When I glanced over it I did not see anything concerning this. Jul 13, 2017 at 18:30
  • 2
    Have a look here github.com/Fuco1/smartparens/wiki/Permissions and here github.com/Fuco1/smartparens/wiki/Wrapping. You can set up filters an triggers. I'm using the package, but I do not yet understand everything. For this rule local settings are to be used. Also have a look at :when and :unless.
    – jue
    Jul 13, 2017 at 18:35

syntactic-close as available from Melpa should close any known paired delimiter.


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.