Auto insert of matching braces?

Is there a secret to auto insertion of matching braces?

I have implemented a `PairedBraceMatcher` (see below) which enabled matching **and** automatic insertion for `RBRACE` "}", RPAREN` ")" and `RBRACK` "]" but for the `begin`/`end` combo I am only getting matching and not auto-insert. What am I missing

The brace matcher correctly highlights the begin/end but doesn't auto insert the `end` keyword (which is what I want).

What am I missing?

Here's my code:

class MyBraceMatcher : PairedBraceMatcher {

override fun getPairs() = PAIRS

override fun isPairedBracesAllowedBeforeType(lbraceType: IElementType, next: IElementType?): Boolean = true

override fun getCodeConstructStart(file: PsiFile?, openingBraceOffset: Int): Int = openingBraceOffset

companion object {
private val PAIRS: Array<BracePair> = arrayOf(
BracePair(LBRACE, RBRACE, true),
BracePair(LPAREN, RPAREN, false),
BracePair(LBRACK, RBRACK, false)

I should clarify that :


But I don't think it has to do with multi-character tokens?


PairedBraceMatcher only works to insert a hard-coded set of potential braces if you debug the code that calls them.  Elixir doesn't have `begin` `end`, but it does have `do` `end` pair.  To get `end` to insert when you type `do` in, I declared a `TypedHandlerDelegate` ( that checked when I was typing the `do` token and inserted the `end` (  There is a slight bug in that PR in that didn't handle `do` could be used a as keyword key like `do:`, which is fixed by


**Thank you**


I noticed PairedBraceMatcher seemed hard-coded for potential braces.To bad!

I assumed that it would grab the text from the right pair and use that for insertion. Instead it auto-insert for some hard coded list of "common" items. This bug/feature can also be seen by changing the right-hand token (i.e try to match ( with }). The editor still auto-inserts ')'. Seems clumsy! A simple option would be to take text from right-hand token and use that or have the option to specify what text you want to auto insert 

The good thing is that your code seems straight forward, so I will go ahead and implement something like that in my code. Thank you!


Please sign in to leave a comment.