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?

  • Show the complete error message, which in this case should say what type of arg was expected (versus received). – Drew Oct 25 at 15:01
  • @Drew I answered my own question below where I reference that question. – dylanjm Oct 25 at 17:20
  • Yes, I saw that. – Drew Oct 25 at 17:27
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.

  • 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 at 1:03

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