I'm trying to activate flycheck-mode by default when opening any file in my project's directory. I'm a bit of an elisp newbie, my .dir-locals.el file looks like this:

((nil . (mode . flycheck-mode))
 ((cmake-ide-dir . "~/workspace/Samira3D"))
 ((cmake-ide-build-dir . "~/workspace/Samira3D/build/")))

And the error I'm getting is

Invalid function: (nil mode . flycheck-mode)

How would I go about solving this?

  • 1
    You don't call functions in .dir-locals.el. The file only contains a list that encodes how the variables are set. See the manual for details. The reason that you are getting this error I think is that flycheck mistreats the file as a usual el file. – xuhdev Apr 30 '16 at 9:01
  • 1
    I'd try whether the eval keyword is supported like with file-local variables. – wasamasa Apr 30 '16 at 9:24
  • I tried: ((nil . (cmake-ide-build-dir . "~/workspace/Samira3D/build"))) and it still gives me "Invalid function: (nil cmake-ide-build-dir . "~/workspace/Samira3D/build")" @xuhdev – Abdullah Al-Hatem Apr 30 '16 at 9:48
  • 1
    @xuhdev, of course, you can call functions in .dir-locals.el – RichieHH Feb 23 at 11:52
  1. Your list nesting is wrong.
  2. You need to use the eval pseudo-variable to evaluate expressions / call functions.
  3. Using mode to set a minor mode is deprecated. That's now for major modes only, and minor modes are enabled via eval.

I think you wanted this:

((nil . ((eval . (flycheck-mode 1))
         (cmake-ide-dir . "~/workspace/Samira3D")
         (cmake-ide-build-dir . "~/workspace/Samira3D/build/"))))

Also have a read of this:

C-hig (elisp) Dotted Pair Notation RET

Sometimes you'll see examples of .dir-locals.el files using fewer dots and parentheses, and the difference (or indeed equivalence) between the different ways of formatting them might be confusing, so that will hopefully clarify the matter.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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