this post was submitted on 12 Oct 2023
1 points (100.0% liked)

Emacs

311 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

Hi all,

I recently did "something" in an emacs buffer and lost a bunch of text in different places, and I was unable to undo the deletions. I tried to use ediff (I guess I should have used ediff-backup?) to recover the lost text but not being competent I mixed up buffers "A" and "B" and ended up copying the deletions to the backup file and couldn't recover from there .... :-).

Now I am curious if there are recent 'best practices' to

  1. Avoid doing 'something' that causes text to disappear
  2. Have a more robust, for a beginner like me, set of autosave and associated settings.

I found/checked the following sources:

https://www.gnu.org/software/emacs/manual/html_mono/ediff.html#Major-Entry-Points

https://www.reddit.com/r/emacs/comments/5h7k1r/undo_lost_hours_of_work/

https://www.gnu.org/software/emacs/manual/html_node/elisp/Auto_002dSaving.html

https://www.reddit.com/r/emacs/comments/3sqtig/important_block_of_text_disappeared_from_my_notes/

https://www.gnu.org/software/emacs/manual/html_node/emacs/Version-Control.html

However, regarding the manuals, I think I could benefit from some guidance on how to set up the most robust system (I rather have a lot of littering but with a robust ability to recover files vs a no-littering approach). And regarding users that experienced the same issue, the posts and replies are several years old so maybe obsolete with current emacs version (and package ecosystem).

I am looking for some recommendation to either disabling certain key bindings (e.g., linked to commands that can select/delete a lot of text), or perhaps change certain default settings (e.g., like the one for org-mode that prevents deleting text in folded sections). Or anything that works for you :-).

If the answer is outside of emacs, ie use git with some auto-commit script running in the background, I'd be interested in recommendations as well. I use emacs on my personal MacBook Air and on my company Windows laptop. I don't need to share my files with anyone, I just want to be able to recover from stupid user errors on my side :-).

(I backup to external drives as well, but my scenario is more 'OMG I pressed some key chord when I was doing something else and thought another application was focused but it wasn't. Worst part is I typically don't notice immediately, but only after a while, I may have even been adding a lot of text before realizing I somehow lost a whole bunch of other text somewhere else in a file - I think I read about a setting that asked for confirmation before a large amount of text is killed, but I couldn't find it back. And I also make such mistaken on smaller pieces of text, like a TODO heading in org-mode.)

Thank you for help,

Paul

top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 1 year ago

magit-wip saved me a couple of times. And I'm doing magit-snapshots each time when my project compiled successfully.

[–] [email protected] 1 points 1 year ago (1 children)

Git project, magit and magit-wip mode which creates intermediate commits automatically. In general file editing, emacs file backups are pretty good; learn to work with them.

[–] [email protected] 1 points 1 year ago

magit-wip saved me a couple of times. And I'm doing magit-snapshots each time when my project compiled successfully.

[–] [email protected] 1 points 1 year ago

Should I worry that the utf-8 file I start editing becomes a text-raw-unix file on save and git commit over tramp/scp as indicated by the initial character on the modeline changing from U to t?

The messages buffer mentions tramp encoding/decoding using

Saving file /scp:s:/ftp/pub/users/x/index.gmi... Tramp: Encoding local file ‘/tmp/tramp.x.gmi’ using ‘(lambda (beg end) (let ((coding-system-for-write 'binary) (coding-system-for-read 'binary)) (apply #'tramp-call-process-region '(tramp-file-name scp nil nil s nil /ftp/pub/users/x/index.gmi nil) beg end (car (split-string env GZIP= gzip)) t t nil (cdr (split-string env GZIP= gzip)))) (base64-encode-region (point-min) (point-max)))’...done Tramp: Decoding remote file ‘/scp:s:/ftp/pub/users/x/index.gmi’ using ‘(base64 -d -i | env GZIP= gzip -d >%s)’...done Wrote /scp:s:/ftp/pub/users/x/index.gmi

[–] [email protected] 1 points 1 year ago

At first I thought this was going to be about the very useful and delightful topic of "Best practices for avoiding work."

My inner Maynard G. Krebs jumped up to say "Work?!".

[–] [email protected] 1 points 1 year ago

To the OP, use M-x customize-group RET backup

There you'll find options for keeping number of backups and where they store.

git is the tool to rely on for version tracking at any granularity you decide, keep committing and logging your changes and you can go back to any point with the builtin vc tool, for example, C-x v l, for logs, C-x v =, for changes, C-x v v, for next step, see the manual f1-r

[–] [email protected] 1 points 1 year ago

Version control. That is all.