0

I have these functions defined in my early-init.el. I'm trying to change the location of where my backups are saved and keep getting a Wrong type argument stringp (djm/emacs-cache "backups/").

early-init.el

(Defconst user-emacs-cache "~/.cache/emacs/")

(eval-and-compile
  (defun djm/emacs-path (path)
    (expand-file-name path user-emacs-directory)))

(eval-and-compile
    (defun djm/emacs-cache (path)
           (expand-file-name path user-emacs-cache)))

init.el

(Use-package files
  :ensure nil
  :custom
  (auto-save-file-name-transforms '((".*" (djm/emacs-cache "backups/") t)))
  (backup-directory-alist '(("." . (djm/emacs-cache "backups/")))))

I change the place of a lot of files in my init file. How can I make something like this work without hardcoding it?

dylanjm
  • 303
  • 2
  • 10

1 Answers1

1

I ended up finding a suitable solution on another SO answer found here:

How to evaluate the variables before adding them to a list?

(quote ARG)

Return the argument, without evaluating it. (quote x) yields x. Warning: quote does not construct its return value, but just returns the value that was pre-constructed by the Lisp reader...

Hence, you either need to backquote or use a function that evaluates the arguments.

Thus, I was able to fix the error by doing:


(Use-package files
  :ensure nil
  :custom
  (auto-save-file-name-transforms `((".*" ,(djm/emacs-cache "backups/") t)))
  (backup-directory-alist `(("." . ,(djm/emacs-cache "backups/")))))

I'm still interested in learning best practices or a more idiomatic away to achieve this. I will accept an answer showing this.

dylanjm
  • 303
  • 2
  • 10
  • I think that what you've done is fairly idiomatic. The backquote/unquote combination is a very standard way to achieve such things. – phils Nov 25 '19 at 01:03