[Geany-Users] new plugin for automatic alignment
Matthew Brush
mbrush at xxxxx
Thu Nov 19 03:01:07 UTC 2015
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
More information about the Users
mailing list