How to automatically handle (insertion, reformatting) of keyword pairs?

I have a bunch of multi-character keyword pairs in my language (for example "BEGIN" and "END" or "CLASS" and "ENDCLASS") that I would like to function like `{` and `}` does in IntelliJ. What's the best way to accomplish that?

Here is what I'm looking for (in order of priority):

1. In IntelliJ when the user types `{` it automatically inserts `}`. I believe a typedHandler does this, but I'm worried about performance as I would have to do a string compare every time the user typed 'n', 's' or several other letters. Is there another way to do this? Can I react when keyword or elements gets created?

2. If the user manually types `}` on an empty indented line to close a pair then IntelliJ automatically de-indents the line. I have the same concerns as in questions one about performance. Note! I have formatting working so if a user manually calls reformat then it reindents correctly. I would like to do this automatically.

3. If the user stands between `{` and `}` and hits enter the result is a smartly formatted into three lines with the cursor correctly indented. How is this done?

/Robert

0

Please sign in to leave a comment.