Persistent undo buffer for scripts and text files
Today I did what I was planning to do for some time. I added persistent undo buffer for my build scripts.
This is second side effect of naracea usage I didn’t expected when I started the development. When I moved my dev notes to naracea, I was kind of afraid of data loss. The file format was still not fixed and there were some bugs in file saving at that time. While I keep my documents in version control system (as everybody should), I was thinking I should have a backup plan for the case when something goes really wrong and document gets corrupted while being saved. So I added two phase save (first rename the existing document, then save the new version and only when the save is successful remove the previous file) and as a last resort I implemented automatic export of the document’s content to the text file.
I never needed the feature, since I never experienced the problem so bad that it would corrupt the document file, but it was there, and I was thinking how it can be useful. And then I realized that adding possibility to set the autoexport filename would allow me to use naracea as an undo buffer for normal text files.
Here is how it works: in my project folder I created subfolder named “_undo”. I created new naracea document called “scripts”. In the document I renamed the branch to “rakefile”, put content of my rake script into it and set its autoexport filename to “..\rakefile.rb”. Now, when I want to edit my rakefile, I open “scripts.ncd” naracea document and when it is saved, the rakefile branch is automatically exported to the actual “rakefile.rb” file in document’s parent folder.
Sounds complicated, but it really isn’t (see forum post which describes it in more detail).
So now, if I edit my rakefile in naracea, I have all changes made to the script persisted, and I can move back and forth in the script’s history without being scared that I won’t be able to undo changes after I close the text editor (which is exactly what happens when I use other text editors).
Sure, naracea is not programmer’s text editor, and it doesn’t support syntax highlighting etc., but still: the feature seems neat to me.