1

How do I configure a dedicated location for lock files and auto-save files that works on MS-Windows, GNU/Linux, and macOS? I'm using GNU Emacs 28.2

The following works on GNU/Linux but not on MS-Windows for me:

(setq lock-file-name-transforms
      '(("\\`/.*/\\([^/]+\\)\\'" "~/.emacs.d/backup/\\1" t))
      auto-save-file-name-transforms
      '(("\\`/.*/\\([^/]+\\)\\'" "~/.emacs.d/backup/\\1" t)))

However, my backup directory setting does work for both GNU/Linux and MS-Windows:

(setq backup-directory-alist '((".*" . "~/.emacs.d/backup/")))

1 Answer 1

1

The following works on GNU/Linux but not on MS-Windows for me:

(setq lock-file-name-transforms
      '(("\\`/.*/\\([^/]+\\)\\'" "~/.emacs.d/backup/\\1" t))
      auto-save-file-name-transforms
      '(("\\`/.*/\\([^/]+\\)\\'" "~/.emacs.d/backup/\\1" t)))

This is obviously because a pathname on MS-Windows doesn't begin with / -- but you wrote "\\`/...". You might want to correct it to "\\`[[:alpha:]]:/...".

3
  • use system-type to determine whether Emacs is running on MS-Windows
    – shynur
    Aug 22, 2023 at 16:54
  • Some MS-Windows pathnames do begin with /, like //wsl.localhost/Ubuntu/...
    – Victor L
    Aug 23, 2023 at 21:31
  • @VictorLyuboslavsky: I see no need to mention //wsl here if you don't say you use WSL in your question -- if you want to take WSL into consideration, what about FTP, SSH? ||| If you use WSL, say it in your question. If not, please let me know whether my answer solves your problem.
    – shynur
    Aug 24, 2023 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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