2

Currently, I'm able to redirect Emacs backup files (those ending in '~' and those starting in '#') to a central location using the code below (it renames them nicely also, encoding the file path in the file name (e.g., ~/tmp/emacs_autosaves/#!home!cbalz!.bashrc#).

But how to preserve the functionality in that code, while also moving the files that Emacs makes that start with '.#' (those are often or always symlinks)?

Current working code - needs to be modified or augmented to work with files/symlinks starting with '.#' :

(defvar autosave-dir
 (concat "~/tmp/emacs_autosaves/" (user-login-name) "/"))
(make-directory autosave-dir t)
(setq auto-save-file-name-transforms `(("\\(?:[^/]*/\\)*\\(.*\\)" ,(concat
      autosave-dir "\\1") t))
christopherbalz
  • 722
  • 1
  • 8
  • 22

1 Answers1

4

The dot-hash-files are created by Emacs as a lock to avoid concurrent modification of a file. Unfortunately, the documentation does not mention the possibility of changing the default location of those files:

The file lock is really a file, a symbolic link with a special name, stored in the same directory as the file you are editing.

Thomas
  • 17,016
  • 4
  • 46
  • 70
  • 4
    It's not really "unfortunate" -- the mechanism *needs* to be user-agnostic. Any ability to relocate those locks would be counter-productive, unless you could guarantee that everyone was using the same configuration. – phils Apr 26 '12 at 03:25
  • 1
    @phils You're right of course, but it's in so far unfortunate that christopherbalz will not be able to achieve what he's after. – Thomas Apr 26 '12 at 06:03
  • How about telling Emacs to rollback any operations that are currently requiring the lock? – christopherbalz Apr 26 '12 at 17:27
  • 1
    Isn't the '.#' file specific to Emacs? If so, then what other concurrent access issues besides other Emacs instances would there be? For example, in my use case, I don't have other Emacs instances that I need to protect against modifying my locked file. But I do have Java programs that crash when they hit '.#' files. So it would be great to be able to put them off in a different location than the default. – christopherbalz Dec 22 '12 at 18:07
  • The use case would be multiple users accessing the same file (through Emacs) in a shared folder. If you're sure that this case does not apply to you, you might try putting the following in your .emacs file to prevent lock files to be written: `(fmakunbound 'lock-buffer)` – Thomas Dec 22 '12 at 22:35
  • It may be a nice feature, but it's annoying enough to make me consider not using emacs any more. And I'm a total aficionado-- all these years I thought it was because I was configuring it wrong. That fact that it's a "feature" kind of sucks. – mikermcneil Jan 04 '13 at 06:31
  • @Thomas tried `fmakunbound` with no luck unfortunately-- any ideas? – mikermcneil Jan 04 '13 at 06:33
  • 2
    See solution at http://stackoverflow.com/a/12974060/4869 for Emacs 24.3 : `(setq create-lockfiles nil)` – Swaroop C H Mar 05 '14 at 01:26