I realize there are a number of questions surrounding this topic, but I'm trying use a global function that I've written inside a project .dir-locals.el.

Specifically, I wrote a function to add a series of include paths to the company-clang-arguments variable. I simply want to call this function (which returns a list of strings), and add it to company-clang-arguments.

This is what I am attempting to do:

((nil . ((company-clang-arguments . (eval (company-clang-header-paths "/path/to/compile_commands.json"))))))

I know that company-clang-header-paths correctly returns a list ("-I/path/one -I/path/two") when I evaluate it in another buffer.

I also know that I am able to use dir-locals.el manually like so:

((nil . ((company-clang-arguments . ("-I/a/b" "-I/c/d")))))

I realize this may be a newbie question, but I'm struggling to understand the evaluation context. The . operator cons the list together, but I'm a bit lost on how to evaluate this function and return the list.

I keep running into errors that tell me I'm providing the wrong type:

Wrong type argument: stringp, eval

Obviously, I've tried playing around, but I always get Wrong type argument: stringp, <something>, where <something> is the thing I tried.

If anyone could help me out, I'd appreciate it. Thanks.

  • Try this ((nil . ((eval . (setq company-clang-arguments (company-clang-header-paths "/path/to/compile_commands.json")))))), as eval is one of the special variables.
    – whatacold
    Dec 22, 2018 at 3:25

1 Answer 1


Bearing in mind that .dir-locals.el contains data, and forms are not evaluated unless you explicitly say to do so...

((nil . ((company-clang-arguments . (eval (company-clang-header-paths "/path/to/compile_commands.json"))))))

Sets the buffer-local value of company-clang-arguments to the list (eval (company-clang-header-paths "/path/to/compile_commands.json"))

Just as if you had used:

(setq-local company-clang-arguments '(eval (company-clang-header-paths "/path/to/compile_commands.json"))

I presume that company-clang-arguments needs to be a list of strings, and therefore the symbol eval as the first list item triggers the error you're seeing. (The second value of that list wouldn't fare any better, but it doesn't get that far.)

To evaluate an expression when the .dir-locals.el file is processed, you need to use the eval pseudo-variable. e.g.:

((nil . ((eval . (setq-local company-clang-arguments (company-clang-header-paths "/path/to/compile_commands.json"))))))

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.