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

Lex Trotman elextr at xxxxx
Tue Sep 21 00:41:24 UTC 2010


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:]]*$
>
>    By commenting-out the last two lines you get ANSI indentation style.
>    If you replace \\{ and \\} with begin and end, respectively, you
>    get analogous rules for pascal. Notice the double-escaping of { and } -
>    the first escape sequence is for the keyfile ini format (so for the
>    regex itself \\ becomes \).
>
> This means that in order to make it work e.g. for C, you have to edit
>
> ~/.config/geany/filedefs/filetypes.c
>
> (or the corresponding file under /usr/local/share/geany) and add
>
> indent_next_line_regex=^.*\\{[[:blank:]]*$
> unindent_this_line_regex=^[[:blank:]]*\\}$
> indent_this_line_regex=^[[:blank:]]+\\{$
> unindent_next_line_regex=^[[:blank:]]*\\}[[:blank:]]*$
>
> under the [settings] section (+ restart geany). Please let me know if
> it works (but also in the opposite case ;-).
>
> Jiri
>

Hi Jiri,

Got it working, I'd put the regexes in the filetypes in the wrong
prefix, my mistake :-D

But it doesn't seem to be working as expected.

Using only the first two of your regexes the following gets:

class foo {
    struct bar {
        int i;
    };
    }

fair enough, the } regex doesn't expect anything after it so I added
.* after the } but now I get

class foo {
    struct bar {
        int i;
};
}

The }; line undents two levels??

Cheers
Lex



>>
>> Best regards.
>> _______________________________________________
>> Geany-devel mailing list
>> Geany-devel at uvena.de
>> http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
>>
> _______________________________________________
> Geany-devel mailing list
> Geany-devel at uvena.de
> http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
>



More information about the Devel mailing list