[Geany-devel] Indentation using regex (was [PATCH 14/19] Rewrite tab switching queue)

Nathan Broadbent nathan.f77 at xxxxx
Tue Dec 6 07:27:35 UTC 2011


> 1. calculate the indent each change, and then ripple that through the file
> 2. calculate the indent each change and only apply it to this line
> 3. calculate and apply the indent to lines N and N-1 only on new line
> or user command
> 4. calculate and apply the indent on user command
>
> Option 1 is rejected because it is expensive and it will destroy
> manually adjusted indentation when editing an existing line and
> because indentation can change as you type causing distracting effects
> (happens with some Emacs indentation styles)
>
> Option 2 is rejected for the same reasons
>
> Option 4 is rejected because auto new line indent is really the
> minimum required to be called "auto" indentation
>
> So that leaves option 3.  The upside is that new lines get a sensible
> indentation automatically, the downside is that lines that should be
> unindented won't be until enter or user command.  I have used another
> editor that worked this way and after a while I became used to it.
> Note that editing an existing line won't destroy manual indentation
> unless you tell it to or create a new line after.

Hello,

Good auto-indentation is one of the last things I'm missing after my
switch from Gedit to Geany. It was something that was handled really
well by the 'Smart Indent' plugin. I would like to share a short video
(1:24) of the indentation behavior that I grew accustomed to:

http://vimeo.com/1890098


This style of auto-indentation requires Option 1 or 2 (calculate for
each change), because it unindents the 'end', 'elsif' and 'else'
keywords as soon as their last characters are pressed.
I did find this behavior very useful, even though I admit that it
would sometimes destroy my manual indentation.


You might also find it interesting to browse the code of this plugin here:

https://github.com/gmate/gmate/blob/master/plugins/gedit2/smart_indent/smart_indent/__init__.py

At least, it contains some good indent regexs for different languages.


I might disagree that Options 1 & 2 are expensive. The gedit plugin
even defines a very limited set of 'unindent_keystrokes', so the
'unindent' regex is only executed when one of these keys are pressed.
For C, it's just ":", and for Ruby, it's "edfn".
I also disagree that it's distracting, because I grew accustomed to it
very quickly.

So if it could be written in a way that supports the behavior in the
video above, I would be really grateful.
But no problem if not -- like you say, I can get used to any behavior
after using it for a while.


Thanks very much for your time!
Nathan B



More information about the Devel mailing list