[Geany-Devel] Some Auto-Indentation Ideas

Lex Trotman elextr at xxxxx
Thu Mar 14 08:13:58 UTC 2013


Hi Braden,

Indentation, sigh.  Search the developer mailing list archives and IRC
archives for indentation, that should give you enough reading for a
while, so I can get on with a little top-posted rant :).  More
specific comments below.

There have been at least two attempted improvements of the indentation
system that I know of.  This lead me to survey other editors
capabilities and the idioms used in various languages.

My conclusion is that Geany devs are no different to most, they like
and use a limited range of languages and indentation styles.
Therefore the techniques they propose usually provide some benefit for
their preferred language/style, but these techniques also often
provide negative benefits for other use-cases.  And there are always
more use-cases that are *not* the particular developers personal
favourite :)

When I looked at other editors I realisedt that most indentation
schemes are *not* local syntax based, even if at first glance they
seem to be.  In actual fact they are based on the language grammar.
The editors that did a good job of indentation were those that
evaluated the language grammar, for example Eclipse, Netbeans and
lately Emacs.

This means that no scheme is going to handle many languages, and
simple schemes based on the indentation/contents of the previous line
and the current line will not work much of the time, since the grammar
production that actually controls the indentation is not on those
lines.

In my opinion, implementing such schemes is a waste of developer time
since they won't work fully, and so some way of working around them is
needed.  Why waste time doing something that won't work much of the
time and then providing a way for someone else to waste their time
correcting it?

Instead all Geany should do is provide a way for language specific
plugins to provide indentation services.  This interface should be as
general as possible, because the Geany developers do *not* understand
the schemes and idioms of languages and styles other than their
favourites.

The only indentation schemes built-in to Geany should be the very
simple language independent ones such as "manual" or "same as last
line".

</rant>

On 14 March 2013 15:42, Braden Walters <meoblast at aol.com> wrote:
> I had some ideas for some keybindings or settings that could help with some
> indentation issues. I'm willing to implement them myself, but I wanted to
> see what the other developers think first. First, the reason why I want to
> even write these.
>
> I work on multiple projects, some of which have multiple developers and some
> where whitespace has been left all around some files. I generally use manual
> indentation (no auto-indent at all), and I can't help but think there's
> something better I could do. I could use the current character indent, but
> then I'll have trailing whitespace everywhere, or I'll have to backspace

I am not sure why you will have trailing whitespace when you use
current character?  That would only occur on blank lines, and can be
removed by the "strip trailing whitespace on save" option or
<ctrl>+<shift>+backspace (see below).

> that out manually (sort of defeats the purpose). I could turn on "Strip
> trailing whitespace", but that's going to modify a lot of lines I never
> really changed.

It will give you lots of VCS noise the first time you do it, yes, but
from then on it should be ok.  Just do one commit just to strip the
trailing whitespace, and then go on with your changes in whitespace
free bliss :)

>
> Here are some solutions I've thought up:
> - Keybindings for everything approach: Improve the "smart indent" key
> binding to just use the global (or project if available) settings for
> auto-indentation upon striking the key combination. Then, create a key
> binding that removes all contents from a line, but does not delete the line
> itself.

It currently takes two keystrokes I admit

<ctrl>+<shift>+backspace <ctrl>+<shift>+delete

but if you know you are at the end only the first is required.

> - Strip on return approach: Create a global/project settings option to strip
> whitespace from the current line upon striking return.
>

menu->preferences->editor->features->Newline strips trailing spaces

> Both of these approaches introduce a problem though. If I remove whitespace
> from a line, I return back to a column position of zero. The auto-indent
> modes I've used will therefore make the following line 0 columns indented.
> One solution to this could be to auto-indent up to the last indented line,
> if available. I'm sure there are other solutions to this though.

If you remove *leading* whitespace then yes it will go to position
zero, but why would you do that?  If the indentation is wrong, no
current mechanism in Geany will correct it, corrections are totally
manual.  You need to use a styler like astyle or uncrustify for that.
You might be able to arrange a custom command to do that with the
selection (<ctrl>+a for all:) but don't try and use astyle for that it
doesn't work.

>
> So I propose three questions in this email. First: Is this something I
> should even be making for an upstream core feature, or should it be in a
> plugin?

Well, as my <rant> says I think it should be a plugin, but at the
moment Geany does not have an interface for an indentation plugin, you
would have to process every character, and that is maybe a bit
inefficient.

> Second: Which of my two approaches seems more reasonable?

TBH I'm not sure what you actually proposed to change?


> Third: Are
> there any other solutions anyone has to the final problem I mentioned, or
> will the solution I proposed suffice?
>

As said above, not sure why you would do that?


> Sorry for the length of this e-mail, everyone.

No problem, as you can gather its engaged many of us in many
discussion and proposals.

Cheers
Lex

>
> --
> Sincerely,
> Braden Walters
>
> _______________________________________________
> Devel mailing list
> Devel at lists.geany.org
> https://lists.geany.org/cgi-bin/mailman/listinfo/devel


More information about the Devel mailing list