<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>> To: users@lists.geany.org<br><div>> From: kugel@rockbox.org<br>> Date: Fri, 13 Nov 2015 13:56:47 +0100<br>> Subject: Re: [Geany-Users] new plugin for automatic alignment<br>> <br>> Am 13.11.2015 um 12:37 schrieb Max Voss:<br>> > Hello everyone!<br>> ><br>> > I wrote a plugin that automatically aligns your "=" like this:<br>> > |fooooo=1 bar=1|<br>> > becomes<br>> > |fooooo = 1 bar = 1|<br>> > See the geanpy readme ( https://github.com/codebrainz/geanypy ) for <br>> > info on how to install python plugins.<br>> ><br>> > You can get the plugin itself from my github:<br>> ><br>> > https://github.com/BMaxV/Geany-Autoalign<br>> ><br>> > It's functional but there is a lot room for improvement, so I'd very <br>> > much like to hear your critique, suggestions, feature requests, etc.<br>> <br>> <br>> Awesome, I've always wanted a way to do that!<br>> <br>> Can you describe the algorithm briefly?<br>> <br>> As Lex mentioned, be aware that geanypy is under rework currently. From <br>> a quick look at your plugin you won't have to adapt your code. However, <br>> python plugin will be expected in a different location after the rework <br>> (directly under ~/.config/geany/plugins or /usr/lib/geany/plugins <br>> respectively). You will then be able to make use of keybindings.<br>> <br>> Best regards.<br>> _______________________________________________<br>> Users mailing list<br>> Users@lists.geany.org<br>> https://lists.geany.org/cgi-bin/mailman/listinfo/users<br><br>Hello again,<br><br>Sure, I can describe the algorithm:<br><br>First it checks for the editor signal (although atm it just takes <i>any</i> "editor-notify" not just text change).<br><br>Then it gets the line and checks if there is a symbol that has to be aligned.<br><br>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:<br><br>a=1<br>while a==1:<br>    ...<br><br>Then it splits the line into variables and arguments at the location of the "=" , so left, right basically.<br><br>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.<br><br>The newlines get created with " indentation + variable + = + value "<br><br>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.<br><br>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.<br><br>I don't need to worry about changes in locations, it's all contained.<br><br>cheers<br><br>Max<br><br><br><br></div>                                      </div></body>
</html>