Hello everyone!
I wrote a plugin that automatically aligns your "=" like this: fooooo=1 bar=1becomes fooooo = 1 bar = 1See 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.
Cheers!
Max
On 13 November 2015 at 21:37, Max Voss maxivoss@hotmail.de wrote:
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.
Cheers!
Max
Hi,
Havn't looked at your plugin yet, but just a heads up to you about https://github.com/geany/geany-plugins/commit/cef52c503658e5ff726db296cd2ec1... which should be visible on the Geany-Plugins website after the 1.26 release.
Cheers Lex
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
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.
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
Am 16.11.2015 um 11:36 schrieb Max Voss:
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.
Is this plugin specific to python source code? Or can it auto-align (for example) C code as well?
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.
Setting replacing the entire text has a serious drawback. The undo action that is recorded by scintilla will be large in memory, basically the size of the document. It seems auto-aligning is a frequent thing so this sounds troublesome.
Best regards
Hi,
As a general comment, Thomas is right, catching every notify and re-styling all the text is going to be too expensive.
For example Asciidoc is 6000+ lines of Python, I would suspect that is too long to use this approach.
You should detect the char added notify and just do the line that the character is added to, and maybe only when = or end of line is typed? Don't even look at the previous or next lines.
Cheers Lex
On 16 November 2015 at 20:45, Thomas Martitz kugel@rockbox.org wrote:
Am 16.11.2015 um 11:36 schrieb Max Voss:
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.
Is this plugin specific to python source code? Or can it auto-align (for example) C code as well?
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.
Setting replacing the entire text has a serious drawback. The undo action that is recorded by scintilla will be large in memory, basically the size of the document. It seems auto-aligning is a frequent thing so this sounds troublesome.
Best regards
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
On Mon, Nov 16, 2015 at 7:24 AM, Lex Trotman elextr@gmail.com wrote:
As a general comment, Thomas is right, catching every notify and re-styling all the text is going to be too expensive.
It didn't sound to me like the algorithm styles *all* the text, just nearby text. If your code is in one monolithic block, then yes, it's all the text. But it doesn't seem like a common case. And your code wouldn't consist mostly of assignment statements, would it?
You should detect the char added notify and just do the line that the character is added to, and maybe only when = or end of line is typed? Don't even look at the previous or next lines.
How can you *align* the current line if not by checking previous or next lines? And if it turns out the line you've currently typed does have the longest variable name so far, what's the point of the plug-in if it doesn't go back and fix the previous lines to this one?
John Y.
Hey again,
More info and some answers
The most important thing first:
It should be able to align pretty much anything, I just started with "=", but the code really just looks for any symbol you or I specify. Also I am only experienced with python so I don't know what kind of alignment would be useful besides the "=" signs for other languages. I'm taking requests. :)
I also know the following:
Listening to all editor notify notifications is bad, but I the python documentation doesn't really cover further filtering. I'm sure it's in the C++ docs, but I don't know how many and what parts made it from C++ to python. If you know how to do this filtering in python please do tell.
I'm going to revisit the setting of the text first.
I put the plugin out anyway to get feedback from more people than whoever is hanging out on IRC and so far that's working, thank you!
cheers
Max
On 2015-11-18 2:32 PM, Max Voss wrote:
I also know the following:
Listening to all editor notify notifications is bad, but I the python documentation doesn't really cover further filtering. I'm sure it's in the C++ docs, but I don't know how many and what parts made it from C++ to python. If you know how to do this filtering in python please do tell.
As you guessed, it's similar-ish to the C code, which is based on how Scintilla and GObject works (actually two different "styles" of async notifications; Win32 API messaging adapted to GObject signals-based API).
In your "main()" method (customarily called something similar to the signal name, like "on_editor_notify"), you need to change the signature to something like:
class AlignPlugin(geany.Plugin): ... def main(self, editor, notification): " Responds to signals from the Editor " # see 'help(geany.scintilla)' for codes if notification.nmhdr.code == geany.scintilla.ONE_OF_THE_CODES: # do stuff only when that message/signal is sent ...
For this plugin you probably want something like "geany.scintilla.MODIFIED" code. You can further filter it for only when text was added or removed, by checking the "modification_type" property on the "notification" argument as show above. It's a bitfield/flags for the kinds of changes that happened (see "help(geany.scintilla)" for listing as well). It might be useful to check whether the "MOD_INSERT_TEXT" or "MOD_DELETE_TEXT" bits are set. Depending on your algorithm, you might also check that the character typed was a newline (ex. using the "lines_added" property of the notification) or that the char was '=', or whatever suits the algorithm. The part in Geany that handles this signal, albeit in C, is here[0], it might give some ideas at least.
Sorry the docs suck. This part is fairly well documented generically by the Scintilla documentation[1], but adapting it to GeanyPy isn't exactly straightforward without digging around looking at the exposed objects (or reading its C source, ugh), and adapting from the C docs. It would be great to add more example plugins into GeanyPy showing (with loads of comments) how this kind of non-Python stuff works.
Feel free to ask any specific questions in devel list or on IRC or whatever.
Cheers, Matthew Brush
[0]: https://github.com/geany/geany/blob/1.26.0/src/editor.c#L1014 [1]: http://www.scintilla.org/ScintillaDoc.html#Notifications