Take the 2-minute tour ×
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
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
15  
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
2  
undo-for-mathematica.alaifari.com –  Tyilo Aug 24 '13 at 22:45
1  
@JacobAkkerboom I believe you and the sentence I cited explains why such a significant statement was removed ("non-disclosure agreement"). But may be there is a video of this conference with that statement? In any case, thank you for citing, it is wonderful news. –  Alexey Popkov Jan 8 at 10:55
show 18 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 if you just want to try it (and trust me enough to run the code without checking) run

Get["https://raw.github.com/jensbob/mathematica_undo/master/undo.m"]

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.

EDIT: This version also has problems with individual context for each notebook, so just be warned. :)

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
add comment

protected by rm -rf Feb 6 '13 at 4:52

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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