Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo in the editor #636

Open
xiaq opened this issue Mar 14, 2018 · 3 comments
Open

Undo in the editor #636

xiaq opened this issue Mar 14, 2018 · 3 comments

Comments

@xiaq
Copy link
Member

xiaq commented Mar 14, 2018

Support undo in the editor.

@xiaq xiaq changed the title Undo Undo in the editor Mar 14, 2018
@xiaq xiaq added this to the 1.0 milestone Mar 16, 2018
@xiaq xiaq removed this from the 1.0 milestone Apr 6, 2019
@krader1961
Copy link
Contributor

Note that supporting undo also needs to handle abbreviation expansions. And the logic for how much work is undone is complex. I've never paid a lot of attention to how undo works in Vim but it clearly depends on transitions between insert and command mode to delineate how much work is undone. What does that mean for the Emacs editing mode? Also, if undo is supported that implies "redo" should be supported. Too, how much undo/redo state should be supported?

At the end of the day I am skeptical that this feature is sufficiently useful as to be justified. Even though I use it regularly in Vim. It seems to me that making it easier to drop into a real editor for non-trivial command edits is preferable. Something like the following that I now rely on in my ~/.elvish/rc.elv:

# Arrange for [alt-v] to edit the current command buffer using my prefered
# external editor.
fn external_edit_command {
  print $edit:current-command > /tmp/elvish-edit-command-$pid.elv
  $E:EDITOR /tmp/elvish-edit-command-$pid.elv </dev/tty >/dev/tty 2>&1
  edit:current-command = (cat /tmp/elvish-edit-command-$pid.elv | slurp)
}
edit:insert:binding[Alt-v] = $external_edit_command~

@xiaq
Copy link
Member Author

xiaq commented Apr 28, 2020

State mutations in the editor "widgets" are already guarded by mutexes, so a natural thing to do is to define each critical section as a unit of undo/redo.

@xiaq
Copy link
Member Author

xiaq commented Apr 28, 2020

Also, since code that mutates widget states already needs to be littered with m.Lock and defer m.Unlock() calls, those calls can be simply substituted with calls that also save the snapshot of the pre-mutation state. This lends itself easily to a history of states.

However, this history only operates on the widget level. It still needs some thoughts to connect all the states together into a global state. Conceptually it's easy, but how to implement this cleanly in Go can be an interesting exercise.

@xiaq xiaq removed the A:Editor label Oct 28, 2020
@xiaq xiaq moved this to Todo in All Elvish issues Feb 25, 2022
@xiaq xiaq moved this from ❓Triage to 🧭Recon in All Elvish issues Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🧭Recon
Development

No branches or pull requests

2 participants