> To: users@lists.geany.org
> From: kugel@rockbox.org
> Date: Fri, 13 Nov 2015 13:56:47 +0100
> Subject: Re: [Geany-Users] new plugin for automatic alignment
>
> Am 13.11.2015 um 12:37 schrieb Max Voss:
> > Hello everyone!
> >
> > I wrote a plugin that automatically aligns your "=" like this:
> > |fooooo=1 bar=1|
> > becomes
> > |fooooo = 1 bar = 1|
> > See the geanpy readme ( https://github.com/codebrainz/geanypy ) for
> > info on how to install python plugins.
> >
> > You can get the plugin itself from my github:
> >
> > https://github.com/BMaxV/Geany-Autoalign
> >
> > It's functional but there is a lot room for improvement, so I'd very
> > much like to hear your critique, suggestions, feature requests, etc.
>
>
> Awesome, I've always wanted a way to do that!
>
> Can you describe the algorithm briefly?
>
> As Lex mentioned, be aware that geanypy is under rework currently. From
> a quick look at your plugin you won't have to adapt your code. However,
> python plugin will be expected in a different location after the rework
> (directly under ~/.config/geany/plugins or /usr/lib/geany/plugins
> respectively). You will then be able to make use of keybindings.
>
> Best regards.
> _______________________________________________
> Users mailing list
> Users@lists.geany.org
> https://lists.geany.org/cgi-bin/mailman/listinfo/users

Hello again,

Sure, I can describe the algorithm:

First it checks for the editor signal (although atm it just takes any "editor-notify" not just text change).

Then it gets the line and checks if there is a symbol that has to be aligned.

Then it gets the adjecent lines and checks those too, for misaligned symbols, indentation, and stop conditions like if there is a ":" in that line, for example I don't want to align:

a=1
while a==1:
    ...

Then it splits the line into variables and arguments at the location of the "=" , so left, right basically.

Then it strips the indentation white space and newline characters and gets the max. length of a variable. All variable names that are shorter than that get buffered with spaces until they're equal in length.

The newlines get created with " indentation + variable + = + value "

All the old lines and new lines get compiled into a block each, I search the document for the entire old block, do some string slicing and plug the new block into the old blocks place.

Then all text gets set to the text with the plugged new block and the cursor position gets set to the end of the new block.

I don't need to worry about changes in locations, it's all contained.

cheers

Max