[gedit-list] Plugins: signal handler when a new line is inserted



Hi,


First, if this is a duplicate, sorry, but I couldn't find the message on
the archives.


I want to write a plugin for Gedit that removes trailing spaces while
writing. But that won't remove trailing spaces where the file was not
modified. This is useful for example to avoid too many merge conflicts
when other people leave trailing spaces everywhere. It can also be
meaningful sometimes. In PHP, "?>\n" is not the same as "?> \n". In the
first form, the new line is removed.

This function exists in KWrite, but i'm trying to change to gedit...


How does this function works?
When I press <Return> and a new line is inserted, the previous line is
stripped from its trailing spaces.

How did I implement it?
I connected the signal key-press-event to get the <Return> key event,
and when this happens, I remove all the spaces that are before the
cursor. The signal continues its propagation and the default handler in
GtkSourceView inserts the new line.


Now, with this implementation, I have the following problems:

- I'm not sure I catch all the new line creations as i'm only listening
for the <Return> key. Indeed, while reading the source code of the
default handler in GtkSourceView, I noticed that <KP_Enter> had the same
effects

- There are other things i'm not duplicating. Again, while reading code,
I noticed that sometimes the event was discarded because it was only
relevant to the input method (call to
gtk_text_view_im_context_filter_keypress)

- It messes horribly with indentation. Basically, if I'm on an empty
line with only indentation spaces. The plugin foirst removes the
indentation before GtkSourceView creates the new line. Therefore,
GtkSourceView things there is no indentation. Instead, I'd like to keep
the same indentation level

- My plugin messes with other indentation plugins. For example, it seems
that the python_indentation plugin replaces completely the default
handler instead of adding to it. So, depending of the signal processing
order, the plugin might get executed or not


I wanted to know if there was a way to fix those issues. I was thinking
that GtkSourceView could be modified so it sends an event when a new
line is inserted. Both my plugin and the indentation plugin in effect
could then connect to this signal and modify the document as needed.
This method also keeps all the complicated stuff (key binding and input
method) in GtkSourceView, hidden away from plugin developers (so they
could not remove functionality by messing with it).

Am I imagining things, is there a better solution ?

Thanks.

Mildred
-- 
Mildred Ki'Lya
╭───────── mildred593@online.fr ──────────
│ Jabber, GoogleTalk: <mildred jabber fr>
│ Website: <http://ki.lya.online.fr>           GPG ID: 9A7D 2E2B
│ Fingerprint: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B

Attachment: 0x9A7D2E2B.asc
Description: application/pgp-keys

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]