2021-08-30 How I avoid deleting large parts of Org buffers accidentally

For today, I have a kind of obvious trick, but one that saved me a lot of trouble at least once.

As many Emacs users, I am a heavy Org-mode user. However, one of the strengths of Org-mode is also one of its weaknesses. By default, it hides a lot of stuff from the user, in the sense of rendering them invisible (property drawers, folded parts of the tree etc.). This means that if I e.g. clock in and then accidentally call undo (effectively deleting my clock entry), it’s possible that I won’t notice that something is missing. Another thing I happen to press accidentally is C-c ;, which toggles the COMMENT keyword of the current entry – when I’m editing a long section of my book on Elisp, for instance, pressing C-c ; instead of C-c , (which is used to e.g. edit a source block) is pretty easy.

Almost a year ago I decided to do something about it, and I came up with a primitive but working solution. I commit my changes to all my Org files to Git once per day (more or less – well, sometimes a bit less, since the average is about 0.8 times per day, which I have set as a Beeminder goal to keep it that way), and I actually review the changes (diffs) before I do. I don’t get fancy with my commit messages – it is just “Update” every day – but when there are substantial changes (and due to how diff works, e.g. moving subtrees results in a fairly big diff), I usually add something like “big change of order”, “major shuffling” etc. This way I know that if – at some point in the future – it turns out that I’ve actually deleted something accidentally, I can use that to track the offending commit faster. (Of course, there’s also git log -G in case I need it.)

Of course, this process is kind of tedious, but experience shows that most of the time it doesn’t take more than a minute or two per day (usually most changes are either green, meaning I added something, or come in pairs of green/red lines, meaning I changed something, and Magit highlights the added/deleted words by default then, so I can catch any significant deletions at the first glance). And I have a feeling that the peace of mind is worth 1–2 minutes of very light work per day. (Just in case you are wondering, yes, I also perform regular backups of all my files, but recovering from a Git repo is way easier than from backups – they are more like a nuclear option.)

There are also automated and semi-automated solutions like this (see answers to this SO question, for instance – git-wip is probably the best-known), but I like my manual version because when I visually skim the diff, I can spot issues right away (well, in the evening) instead of, say, a week (or a month, or a year…) later.

That’s it for today, hope it helps!

CategoryEnglish, CategoryBlog, CategoryEmacs