How to use indentLine? (Question about making changes.)

I’m trying to enforce indentation. I’ve got cursor control working, but when in comes to calling indentLine, I’ve obviously got something basically wrong. The editor gets corrupted. I’ve tried, for example:

function onRenderLine(cm, line, element) {

…which causes the whole system to break down. I assume this is because, to make changes, I need to be doing it in the correct context? I’ve tried some different events, but it’s never happy…and clearly there’s a deeper principle at work here that I don’t understand.

Thanks for your help! Ness

The documentation explicitly says not to use any state-changing methods on the editor from the renderLine event. That also doesn’t seem like a good place to do this anyway – you’re probably interested in changed lines, not rendered lines.

Sorry about that. I tried it also with onChange and onChanges – like I said, renderLine was only an example. I will try again with other events and see if I can get it to work this time. Thanks for your help.

Well, now it works in a bunch of events. I have no idea why I couldn’t get it work before – probably because it was 1 in the morning here. The only problem is that it’s failing to indent new lines sometimes…I’ll post a new thread if I can’t resolve that.

The trick with indenting new lines is just never to indent them. indentLine() removes all indentation on any line with no non-space value (including the current line).