Auto-indentation, type ahead

gabor on 2008-11-12T07:12:03

I was trying to improve the auto-indentation of Padre.

  1. First it had no auto-indentation at all.
  2. Then it would copy the indentation from the previous line every time you press ENTER.
  3. Then people asked that it will add another level of indentation if there is an opening brace { on the line where the ENTER was pressed.
So far it is working and you can pick one of the 3 options. Though I just remembered I still have to allow the user to decide if the indentation is TAB or N spaces and what is N.

Anyway, I did not really like option 3 as I am used to type the closing brace } quickly after the ENTER which reminded me that some people like that - what's its name, type-ahead? - feature where their editor guesses what they want to write and adds that part too. For example if I type { it will add two newlines and a } on the second one indented to the level where it should be. Moving the cursor to the line between the two where you should start typing the content of the block.

I wonder, is the auto-indentation just a special case of this type-ahead feature?

In addition, looking at vi I noticed it has this feature of dealing with indentation when you type the closing brace yourself. If you do that on the beginning of a line it can auto indent it to where it should be.

Of course there might be several answers to the question where should the opening and closing braces be? and probably every developer has her own preference of exactly what she wants to be typed ahead.

I guess I need to look at how other editors and IDEs provide this feature and listen to the potential users. That's you.

As a side note I am going to talk about Padre and wxPerl development in Haifa next week.


How vim ai works

Aristotle on 2008-11-12T09:35:29

In vim, when you enter a new line, the cursor is positioned according to the indentation level it should be, but no characters are actually entered. That is, if you use the cursor keys to leave the line and then come back to it, you will find that the line is empty. Only as soon as you type your first character do the indentation characters materialise.