Hi,
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 the equivalent of a KWrite function.
Basically, this is how it works: hen I press <Return> and a
new line is inserted, the previous line is stripped from its
trailing spaces.
Writing this is quite simple. I connect to the "key-press-event",
filter for the <Return> key and remove the spaces before the
cursor.
The problem is that it messes with the indentation (implemented
directly in GtkSourceView). Say the current line has 4 spaces only
(blank line). If I press <Return>, I want the line I was on
stripped from its spaces and have the following line already
indented with 4 spaces. Instead, this is what happens in order:
- my plugin will remove these four spaces
- GtkSourceView will insert the new line and indentation. Because
the plugin removed the spaces, GtkSourceView thinks there is no
indentation and don't reproduce it.
Another problem is that it messes with other indentation plugins. My
plugin doesn't interact with indentation and I'd like not to
conflict with other plugins. For example, the plugin
python_indentation uses the same signal and return True, which means
that the event is stopped from propagating.
The other issue deals with the code that handles the key-press-event
signal. In GtkSourceView (gtksourceview.c), there is a great care to
check for both GDK_RETURN and
GDK_KP_Enter
. The same
way, GtkSourceView makes sure that the enter key was not handled by
an input method by calling
gtk_text_view_im_context_filter_keypress
.
I don't know if plugins writers can deal with all of these details.
So, I wanted to know if there was a signal I could connect to that
signals a new line is inserted. If not, why not adding such a signal
to GtkSourceView after the new line is created with the correct
indentation? This wpould permit to have a cleaner way to write
indentation plugins as well.
Mildred
PS: Could you Cc me as I'm not on the list? Thanks.
--
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