1

The following happens fairly often to me:

  • I do emacs note-xyz in the terminal to create a new note
  • I write something in the note
  • I forget to save before logging out

Now I'm left with a file #note-xyz# in my directory, without corresponding note-xyz.

What's the fastest way to open #note-xyz# as note-xyz, so that from then on C+x C+s saves to the intended filename? Ideally I'm looking for a single command that I can put in an alias.

3
  • Not an answer to your question, but the fastest way handle this is to avoid the problem by simply answering the question correctly when Emacs asks you whether to save the buffer containing modifications when killing the application.... I've been using Emacs for about 7+ years now, and I've never forgotten to save a file.
    – lawlist
    Nov 23 '20 at 21:56
  • thanks, but i don't see this question if emacs is in a minimized terminal when ending the graphical session
    – user313032
    Nov 23 '20 at 21:59
  • 1
    You could open the backup normally and then save it with C-x C-w to a different name.
    – jue
    Nov 23 '20 at 22:10
0

Try recover-file for one specific file. If you call it with a filename it will prompt if the auto-save data exists e.g. (recover-file "note-xyz") otherwise, you could use recover-session if there are multiple files with unsaved changes.

You can also avoid the problem by adjusting the autosave settings to save more frequently. To save after every change for example (setq auto-save-interval 1) or (setq auto-save-timeout 1) to save whenever you stop typing for more than a second...

0

I believe M-x recover-session should be all you need.

However... I've just tested your scenario, and for some reason the session file is deleted if I kill emacs externally, which means that there is no record of what to recover.

This seems like a bug. Certainly it seems like undesirable default behaviour. Could you please M-x report-emacs-bug to follow this up?

I can reproduce the behaviour just by running emacs in the foreground in a terminal and then killing it with C-c once I've verified the presence of the session file listing the autosaved files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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