Closed oakmac closed 4 years ago
I can't seem to find any documentation about this. Need to ask the forum, but it seems to be down at the moment.
this seems relevant: https://www.sublimetext.com/forum/viewtopic.php?f=6&t=1584&p=7332
also this: https://www.sublimetext.com/forum/viewtopic.php?f=3&t=1645&p=8034&hilit=undo#p8034
Undo/redo inside of an edit is something that's fundamentally not supported: if you were running a debug build, you'd hit an assert.
To be able to modify the buffer from within on_modified, and have it considered as part of the original edit, is going to require more API support. One option would be to add an on_pre_modified(view, edit) callback, where you'd have a chance to make any last minute changes before the action is committed. This would still be limited though, as you still wouldn't know exactly what's changed.
This is important functionality and probably the highest priority issue for this plugin right now.
@JoakimLofgren - any thoughts? :)
I might take a stab at it this weekend :)
I was looking for an existing plugin that would require something like this. Couldn't find any.
I figured Sublime's auto-match plugin would use such a feature, because it auto-inserts a close-paren after you type an open-paren. But this is instead a native feature of Sublime, not a plugin. So I looked at how Sublime's paredit plugin achieves this, but it just binds (
to a command which insert both at the same time.
I think the only way to accomplish this is to intercept the edit before it is made, and then commit the corrected edit after Parinfer processes it.
https://www.sublimetext.com/docs/3/api_reference.html#sublime.Edit :
Edit objects have no functions, they exist to group buffer modifications. Edit objects are passed to TextCommands, and are not user createable. Using an invalid Edit object, or an Edit object from a different view, will cause the functions that require them to fail.
Since the on_modified
callback only gives you the view... it isn't really possible from what I see.
Unless you somehow changed the edit_token to the value of the user change edit token?
Just talked to @den1k about this, and he says that we just need to undo twice whenever the user triggers an undo.
@shaunlebron @oakmac and add a flag for parinfer not to run if the last change was an undo (and I assume same for redo)
Thanks for looking into this everyone. And a big +1 for the plugin, I'm finding it really useful whilst getting to grips with lisp :)
I think I found a fix for this with v0.6.0. "Works on my machine" :)
Can anyone confirm?
Yehaa!
I tried in both Sublime 2 and 3. It works until you add/delete/move a paren. looking at it
Great work! Sent a PR that fixes it on mac, using Cmd instead of Ctrl
I'd like to close this issue, but just wanted to make sure this feature was working for everyone.
@JoakimLofgren, @heeton - can you confirm?
Seems to work, although.. what about redo? :)
Every text change made by the plugin is being added to the undo stack. Parinfer changes should not be added to the undo stack.