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

Jiří Techet techet at xxxxx
Fri Sep 17 08:28:37 UTC 2010


On Fri, Sep 17, 2010 at 01:23, Lex Trotman <elextr at gmail.com> wrote:
> On 17 September 2010 06:17, Jiří Techet <techet at gmail.com> wrote:
>> On Thu, Sep 16, 2010 at 19:27, Thomas Martitz
>> <thomas.martitz at student.htw-berlin.de> wrote:
>>>  On 16.09.2010 02:23, Lex Trotman wrote:
>>>>
>>>> Hi Jiri,
>>>>
>>>> I couldn't get this to work at all, it printed "calling indent this
>>>> line" all the time but didn't indent :-(
>>>>
>>>> I only had half an hour so I couldn't investigate much.
>>>>
>>>
>>> I have the same experience. Auto-indentation doesn't seem to work anymore
>>> (e.g. when hitting enter after on a line that ends with {, or when typing
>>> }).
>>
>> I have just re-tested it again and it works on my machine (I have
>> forgotten one trace in the code - that's what you see in the console).
>> A quick question: have you read the commit log?
>>
>>    This patch makes it possible to specify several regex patterns for every
>>    filetype which determine under what condition the indentation is performed.
>>    The pattern variables are specified under the [settings] section of the
>>    given filetype and their value is the regex to be used. The variables are
>>    as follows:
>>
>>    * indent_this_line_regex - the match is performed after every keystroke
>>      and if the regex matches, the indentation is performed on the current
>>      line
>>    * indent_next_line_regex - the match is performed only when enter is
>>      pressed. The indentation is applied on the next line
>>    * unindent_this_line_regex - like indent_this_line_regex but
>> unindents instead
>>    * unindent_next_line_regex - like indent_next_line_regex but indents instead
>>
>>    Comments and strings are detected from the lexer so these can be ignored
>>    inside the patterns. For instance these are very basic rules for GNU
>>    indent style:
>>
>>    indent_next_line_regex=^.*\\{[[:blank:]]*$
>>    unindent_this_line_regex=^[[:blank:]]*\\}$
>>    indent_this_line_regex=^[[:blank:]]+\\{$
>>    unindent_next_line_regex=^[[:blank:]]*\\}[[:blank:]]*$
>
> Yes, I read the instructions (rare I admit) and I copied these regexen.
>
> I'll see if I get time to look at it some more today or tomorrow.
>
> Note that unless you are going to add the regexes to all filetypes
> then Geany still needs to behave as it currently does when there is no
> filetype regex(es).

Currently geany only indents languages with braces (C, C++, Java,
Perl, ...) and Python, so these are the only languages whose patterns
have to be set. I think it is really best to set the patterns
per-langauge - there may be slight differences between C and Perl for
example. But it should be no problem to copy the patterns to the
filetype settings files that go under /usr/local/share/geany.

What I'd like to see and what I'm not sure about how to do it in a
nice way is the possibility to switch between different indent styles
for different projects/files. For instance I maintain a project that
uses the GNU indent style while geany uses the ANSI style. Suggestions
are welcome.

Cheers,

Jiri

>
> Cheers
> Lex
>
>>



More information about the Devel mailing list