David Wolever
David Wolever

Reputation: 154664

How do I configure Emacs to autosave and backup to dotfiles?

I'd like to configure Emacs so that it autosaves and creates backups to a dotfile in the same directory as the file I'm editing (similar to Vim's .sw* files).

For example, when I'm editing foo.py, I'd like the autosave file to be .foo.py#, and the backup file to be .foo.py~.

How can I do that?

I've tried adding an item to auto-save-file-name-transforms: ("(.*/)?(.*)" ".\\2.swx" t), but that didn't seem to work (autosave files with the name #file# were still being created; nb: I added it using M-x customize-variable, so I don't think it was a syntax error or something trivial).

Upvotes: 0

Views: 133

Answers (1)

Ryan Fox
Ryan Fox

Reputation: 10269

The default behaviour for Emacs's regexes is to match parentheses as parentheses. You'll need to escape them to do group captures. Try this:

("\\(.*/\\)?\\(.*\\)" ".\\2.swx" t)

Upvotes: 1

Related Questions