[Geany] Re: Couple of small patches

Catalin Marinas catalin.marinas at xxxxx
Mon Dec 17 15:27:17 UTC 2007


On 14/12/2007, Catalin Marinas <catalin.marinas at gmail.com> wrote:
> On 14/12/2007, Enrico Tröger <enrico.troeger at uvena.de> wrote:
> > On Thu, 13 Dec 2007 11:43:53 +0000, "Catalin Marinas"
> > <catalin.marinas at gmail.com> wrote:
> >
> > > snip
> > > The indentation is done with spaces rather than a combination of
> > > spaces and tabs. I find this more useful since it doesn't break the
> > I like this feature and I think we should add it. But before, please
> > change the code so that it respects the document->use_tabs setting.
> > Inserting only spaces is a no go, I prefer to use tabs for indentation.
> > You (and many other people) like to indent only with spaces, therefore
> > there is an option to choose whether to use tabs or not. Your code
> > should take care of this. When not using tabs, simply add only spaces,
> > a mix of tabs and spaces if the user has chosen to use tabs.
> > I didn't have a look at it but get_whitespace() might be useful.
>
> My comment was probably a bit misleading, I use tabs indentation myself as well.
>
> The patch uses tabs for the first part of the line indentation (it
> actually copies the previous one). If there is an additional
> indentation for an open bracket, it uses spaces for the rest of the
> line.
>
> For example (using dots instead of spaces below and spaces for the
> corresponding tab), with 4-spaces per tab:
>
> void some_func(void)
> {
>     if (a == 10 &&
>     ....b == 20)
>     {
>
>     }
> }
>
> viewing the code in an editor set to 8 spaces per tab, the "if"
> conditions are still aligned (I view geany code with 8 spaces per tab
> and the ifs don't look at nice :-)):
>
> void some_func(void)
> {
>         if (a == 10 &&
>         ....b == 20)
>         {
>
>         }
> }

Just ignore this patch for now, it needs a bit more thinking. In the
case above, if the brace is at the same line with "if", it indents
like below:

void some_func(void)
{
        if (a == 10 &&
        ....b == 20) {
        ....    some code;
        }
}

Using tabs wouldn't help either as in the case above (8 spaces/tab) it
would use spaces anyway.

A solution would be to detect when the block finished but this would
mean parsing more than one previous line for the start of the block at
every new line inserted (is this an expensive operation in geany?).

It might be better to have a more generic solution to always parse to
the beginning of the block, including blocks delimited by braces for
some languages.

-- 
Catalin



More information about the Users mailing list