Re: [gedit-list] Plugin development question



Hiya,

Thanks for the hints. I managed to get it working with scroll_to_mark,
however it still ended up jumping around a bit which was annoying.

On your prompting I also tried to see if I could get it to be performant
using iterators. I was unsuccessful with this - it seemed to be pretty
slow on a large file even when simply iterating from one line to the
next (i.e. if I commented out the deletion part). No idea why.

What I have settled for now, is reading the file into a Python string
and using regexes to find where the deletion needs to happen, but then
using the Gtk API to properly delete from the buffer (rather than
writing a whole new string into the buffer). This is reasonably fast,
and has the advantage of being very fast on files which have no trailing
spaces, and it does away with the need to try to save the UI state and
then restore it. So I am pretty happy with this solution.

You can see the code here if interested:
https://github.com/jonleighton/gedit-trailsave/blob/a0fa9025dafd484c59f8e3fc4ea30a9c888c3426/trailsave.py#L62-86

Thanks!

Jon

On Sat, 2011-07-09 at 18:29 +0200, Jesse van den Kieboom wrote:
> Btw,
> 
> I would maybe look into the performance problem. For example, I see
> that you use get_iter_at_line with a line index, which could be
> potentially very slow. You could replace that by something that moves
> the iter to the next line each time, pseudo code would be something
> like this:
> 
> iter = buffer.get_start_iter()
> enditer = buffer.get_end_iter()
> 
> while not iter.equal(enditer):
>   if not iter.ends_line():
>     iter.forward_to_line_end()
> 
>   strip_spaces(iter)
>   iter.forward_line()
> 
> 
> Jesse
> 
> 2011/7/9 Jesse van den Kieboom <jesse icecrew nl>:
> > Hi Jon,
> >
> > See gtk_text_view_scroll_to_iter and gtk_text_view_scroll_to_mark:
> >
> > http://developer.gnome.org/gtk3/stable/GtkTextView.html#gtk-text-view-scroll-to-iter
> > http://developer.gnome.org/gtk3/stable/GtkTextView.html#gtk-text-view-scroll-to-mark
> >
> >
> > Jesse
> >
> > 2011/7/9 Jon Leighton <j jonathanleighton com>:
> >> Hi there,
> >>
> >> A few weeks ago I ported the trailsave plugin to Gedit 3
> >> (https://github.com/jonleighton/gedit-trailsave).
> >>
> >> It worked, but I found it to be pretty slow, particularly on large
> >> documents. So today I have been looking at a new strategy:
> >>
> >> * Get the contents of the buffer as a python string
> >> * Use regular expressions for the replacement
> >> * Save the result back to the buffer
> >>
> >> This seems to be much faster.
> >>
> >> One issue is preserving the state of the window to the user. I have
> >> managed to cook up some code which restores the cursor position.
> >>
> >> However, I am struggle to restore the scroll position of the view. I
> >> found that the Gedit.View implements the Gtk.Scrollable interface, so I
> >> have been trying to use set_vadjustment. However, it simply doesn't
> >> work.
> >>
> >> Any hints would be much appreciated. I am not really a python or a gtk
> >> programmer, so apologies in advance for any ignorance on my part :) The
> >> code in question is:
> >>
> >> https://github.com/jonleighton/gedit-trailsave/blob/master/trailsave.py#L87
> >>
> >> Many thanks,
> >>
> >> Jon Leighton
> >>
> >> --
> >> http://jonathanleighton.com/
> >>
> >> _______________________________________________
> >> gedit-list mailing list
> >> gedit-list gnome org
> >> http://mail.gnome.org/mailman/listinfo/gedit-list
> >>
> >>
> >

-- 
http://jonathanleighton.com/

Attachment: signature.asc
Description: This is a digitally signed message part



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