3

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.

lo tolmencre
  • 169
  • 6

2 Answers2

3

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.

jue
  • 4,476
  • 8
  • 20
  • 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. – lo tolmencre Jul 13 '17 at 18:30
  • 2
    Have a look here https://github.com/Fuco1/smartparens/wiki/Permissions and here https://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 '17 at 18:35
0

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

https://github.com/emacs-berlin/syntactic-close

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