For my current project I have been trying to configure it so I don't need to explicitly type compile and debug commands each time I start a new emacs session.

In my .dir-locals.el file I have:

((nil . ((eval . (set (make-local-variable 'project-path) (locate-dominating-file default-directory ".dir-locals.el")))))
(c++-mode . ((compile-command . (concat project-path "rest of my compile command"))
(gud-gdb-command-name . (concat project-path "rest of my debug command)))))

This works until I do m-x gdb where I get the message: Wrong type argument: characterp, concat however compiling gives the correct command.

Replacing (concat project-path "rest of my debug command) with the full command resolves this issue but will break if I change my folder structure.

I don't have a huge amount of experience in lisp, and don't understand why concat is producing the wrong type when I run gdb.

1 Answer 1


The general format for .dir-locals.el is described here:

The file is data rather than code, so nothing is evaluated by default. To evaluate code, you must use the special pseudo variable name eval, as described at:

You've already done this in one place:

(eval . (set (make-local-variable 'project-path) (locate-dominating-file default-directory ".dir-locals.el")))

which you could simplify to:

(eval . (setq-local project-path (locate-dominating-file default-directory ".dir-locals.el")))

but you didn't use eval here:

(compile-command . (concat project-path "rest of my compile command"))

And so this is setting the buffer-local value of compile-command to a list value (a list with the symbol concat as its first element, resulting in your error "Wrong type argument: characterp, concat").

Instead, do this like your first case:

(eval . (setq-local compile-command (concat project-path "rest of my compile command")))

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.