Home Download Buy Blog Forum Support

Getting view text diff between on_modified events

Getting view text diff between on_modified events

Postby Notfonk on Tue Dec 04, 2012 10:41 am

Hello there.

I'm making a plugin interfacing with a compiler, and i need a way to get text diffs between on_modified events.

The diff could take any form, that's not a problem, just a synthetic way to get all the changes that happened between now and the last time on_modified was called.

I'm pretty sure there is a way to do that, but i can't find it .. Anybody has an idea ?
Notfonk
 
Posts: 6
Joined: Tue Dec 04, 2012 10:37 am

Re: Getting view text diff between on_modified events

Postby agibsonsw on Tue Dec 04, 2012 11:13 am

Python has a difflib module but I haven't checked whether it is part of the ST Python-version. Test import difflib and check the Console for any error. Otherwise you would include it (or some alternative) as part of your plug-in.

on_modified happens constantly within a view so you would need to keep an eye on how much processing you do on each occasion. Python is very efficient, however, so this may not be too much of an issue.

Handling Undo and Redo correctly is likely to be a challenge.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Getting view text diff between on_modified events

Postby Notfonk on Tue Dec 04, 2012 11:20 am

Python has a difflib module but I haven't checked whether it is part of the ST Python-version


I thought about that, but i'd rather not reprocess the diff every time. Anyway, for the record, it is part of the ST python version.

modified happens constantly within a view so you would need to keep an eye on how much processing you do on each occasion


Well yes from what i gathered it seems to happen on *every* event. But that's not likely a big problem because i can always aggregate such events and do processing only every X events, or in an helper thread.

Handling Undo and Redo correctly is likely to be a challenge.


Why ? From what i've seen, on_modified events are also sent when an undo or a redo are done. I don't need to track wether they are undos/redos or not, just keep a consistent view of the file on the compiler's part.

Thanks for the input !
Notfonk
 
Posts: 6
Joined: Tue Dec 04, 2012 10:37 am

Re: Getting view text diff between on_modified events

Postby agibsonsw on Tue Dec 04, 2012 11:36 am

From what i've seen, on_modified events are also sent when an undo or a redo are done.


I, personally, cannot fully explain why Undo/Redo cause concerns, or precisely how they interact with on_modified. Perhaps someone else might offer some insight.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Getting view text diff between on_modified events

Postby adzenith on Tue Dec 04, 2012 5:11 pm

Undo/redo are a concern if an on_modified callback changes the buffer. If you change the buffer after an undo, it breaks the redo stack (and can also make undoing impossible, because the next undo undoes the callback modifications).
adzenith
 
Posts: 1214
Joined: Mon Oct 19, 2009 9:12 pm

Re: Getting view text diff between on_modified events

Postby agibsonsw on Tue Dec 04, 2012 7:26 pm

adzenith wrote:Undo/redo are a concern if an on_modified callback changes the buffer. If you change the buffer after an undo, it breaks the redo stack (and can also make undoing impossible, because the next undo undoes the callback modifications).


I was using on_modified to add_regions (and modify them): I didn't believe this changed the buffer(?). Regardless, I had to add a separate on_selection_modified to counter-balance the impact of Undo/Redo (or, at least, try to).

PS I am not trying to be discouraging :)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Getting view text diff between on_modified events

Postby Notfonk on Tue Dec 04, 2012 8:20 pm

Ok so this is clearly not a problem for my use case, since i'm not planning to modify the document in those callbacks.

So i guess the answer to my question is a "no there is no way of doing that" ?

That would be a definitive lack for an "on_modified" event IMO .
Notfonk
 
Posts: 6
Joined: Tue Dec 04, 2012 10:37 am

Re: Getting view text diff between on_modified events

Postby agibsonsw on Tue Dec 04, 2012 8:38 pm

The limit of my knowledge on this subject is to suggest that you could use on_selection_modified to store the current line-contents, having checked that they have moved to a different line, and then compare this to the line following on_modified. There is also the command_history() to explore, but I do not know how useful this may prove. Good luck.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Getting view text diff between on_modified events

Postby Notfonk on Tue Dec 04, 2012 8:42 pm

Ok. Thank you very much for your help !
Notfonk
 
Posts: 6
Joined: Tue Dec 04, 2012 10:37 am


Return to Plugin Development

Who is online

Users browsing this forum: Majestic-12 [Bot] and 5 guests