Automatically dedent a line via indentNodeProp

Hi, I have written some code to automatically dedent “else” clauses if the indentation is higher than the corresponding “if” statement by using an updateListener and determining if the line is an “else”. However I was wondering if it could be achieve via an IndentNodeProp as the language I am supporting is multilingual and hence with the updateListener approach I have to look for all possible translations of the word “else”. However, as we add more languages I have to edit the code to include their translation of the word “else”.

If I could do it with an indentNodeProp I would just have to attach the code to the ElseClause node and it would work for all languages added in the future. I tried to do it but couldn’t figure how how to dispatch the transaction when I attempted it from the IndentNodeProp as I don’t have access to the view.

Note, I am not able to match an else until the line has already been entered.

You can use a combination of syntax-based indentation (via indentNodeProp) and indentOnInput with "indentOnInput" language data holding a regular expression matching lines that start with an else. The Python mode does this for else: (see this example­–if you type a colon at the end, it’ll reindent immediately).

If I used the IndentOnInput with a regex won’t I still have to list all the language translations of ‘else’ in the regex? I was trying to use the Node so I wouldn’t have to modify the indent logic as we add additional languages. If it’s not possible that’s fine I just wanted to ensure I wasn’t missing something.

Oh, now I see what you mean by translations. Yes, that’s a simple regexp matched against the line, so it’d need to match all the words used.