oakmac / sublime-text-parinfer

Parinfer plugin for Sublime Text
ISC License
57 stars 8 forks source link

skip undo stack #20

Closed oakmac closed 4 years ago

oakmac commented 8 years ago

Every text change made by the plugin is being added to the undo stack. Parinfer changes should not be added to the undo stack.

oakmac commented 8 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.

oakmac commented 8 years ago

this seems relevant: https://www.sublimetext.com/forum/viewtopic.php?f=6&t=1584&p=7332

oakmac commented 8 years ago

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.

oakmac commented 8 years ago

This is important functionality and probably the highest priority issue for this plugin right now.

@JoakimLofgren - any thoughts? :)

JoakimLofgren commented 8 years ago

I might take a stab at it this weekend :)

shaunlebron commented 8 years ago

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.

JoakimLofgren commented 8 years ago

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?

shaunlebron commented 8 years ago

Just talked to @den1k about this, and he says that we just need to undo twice whenever the user triggers an undo.

den1k commented 8 years ago

@shaunlebron @oakmac and add a flag for parinfer not to run if the last change was an undo (and I assume same for redo)

alexslade commented 8 years ago

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 :)

oakmac commented 8 years ago

I think I found a fix for this with v0.6.0. "Works on my machine" :)

Can anyone confirm?

den1k commented 8 years ago

Yehaa!

shaunlebron commented 8 years ago

I tried in both Sublime 2 and 3. It works until you add/delete/move a paren. looking at it

shaunlebron commented 8 years ago

Great work! Sent a PR that fixes it on mac, using Cmd instead of Ctrl

oakmac commented 8 years ago

I'd like to close this issue, but just wanted to make sure this feature was working for everyone.

@JoakimLofgren, @heeton - can you confirm?

JoakimLofgren commented 8 years ago

Seems to work, although.. what about redo? :)