Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The Mathematica Front End's built-in Undo command can only undo a single editing step.

Has anyone implemented or seen implemented an efficient and comfortable multiple undo?

I have in mind ideas such as, CellEventActions that keeps a stack in the cell context pushing the cell state every time a key among a list (brackets, @, operators) is pressed. Some other shortcut to recover older states (or a palette, or perhaps tweaking the front end's .tr files??)

I am not familiar at all with typical text based implementations and their issues. I guess it wouldn't be a practical problem to lose the undo state between sessions, would it?

So, has this been done, or is it doable or practical? What are your thoughts?

share|improve this question
+1, I also proposed something like this in the mathgroup post linked here: groups.google.com/group/comp.soft-sys.math.mathematica/… – Jens Feb 18 '12 at 8:03
5  
This certainly seems possible at least for the "Program" - style cells, and I have plans to integrate this as a feature in the next versions of the syntax highlighter, which you are probably familiar with. Since my highlighting engine is grabbing the cell's contents on every trigered event, this should be a relatively simple matter to do. One problem I face here is that I don't know how to trigger the CTRL key (or its equivalent on other platforms) yet. – Leonid Shifrin Feb 18 '12 at 21:41
1  
@LeonidShifrin I would happily write Undo[] multiple times, don't let Ctrl get in your way. – David Mar 6 '12 at 7:35
12  
I can't undertand. Why Mathematica is missing this? This action is extremly needed and useful. And missing until latest Mathematica versions. Lol. Why? Maybe someone should contact Mathematica and show this question for them. – GarouDan Jun 26 '12 at 19:03
3  
I feel shame when I'm teaching Mathematica to someone and people discover the "One time CTRL Z" limitation. It's too basic. – Murta Oct 6 '12 at 14:24
show 13 more comments

1 Answer

I made a simple version control and undo function. (Since it uses system commands right now it is only tested for Linux. Windows support is added but not tested. MacOS is not tested either.)

Here is the link to undo.m or the github

Would be great to have some feedback with ideas how to improve it, also I didn't test this a lot but it seems to be working fine. It is probably not the most efficient way but I think it is a good start.

From the readme:


This package adds a poor mans version control and undo functionality to Mathematica. For a previously saved notebook 'notebook.nb' a version info file 'notebook.nb.undo.mx' is created and every time changes are committed a backup file 'notebook.nb[version].bak' is created. System menu entries in insert are created.


Keyboard Shortcuts

Alt+z : Undo

Alt+x : Redo

Alt+s : Commit

Alt+d : Opens CommitInfo Dialog


Usage: Evaluate the following commands

ManualCommit (Default) - Only do commits manually.

AutoCommit - Turn on automatic commits. Every time a cell is evaluated a new commit is made. (This can lead to a lot of files)

CronCommit[n] - makes a new commit every n minutes.

CommitNow - Making a commit CommitInfo - Show a list of all Versions CommitClean - Remove all commited files

Undo - Undo to the previous commit Redo - Undo to the next commit GotoCommit[n] - Go to the n-th version


NOTICE

When altering not the latest version, the changes (when running undo or redo) are not saved, only when running 'commit' these changes are changed (with a new highest version number). Only changes to the version with the highest version number are changed upon 'undo'

Whether a commit needs to be made when running undo is checked with a system variable that can be altered by manually saving the document. Leading to possible loss of changes. For best results do not save the notebook manually and turn auto save off - just use commit to save the work.

share|improve this answer
thanks to Chris Degnen for helping with the keyboard shortcuts. mathematica.stackexchange.com/questions/16165/… – jenson Dec 12 '12 at 16:04
from looking at the code, it should work under OS X (the default shell is bash) – acl Dec 12 '12 at 22:48

protected by rm -rf Feb 6 at 4:52

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.