2

Trying to set flycheck-clang-include-path without the need to include the full path of the project include directories using projectile, but I get errors... So this works:

((nil . (
     (company-clang-arguments . (
                     "/home/user/Downloads/project/headers"
                     "/home/user/Downloads/project/source/mon"
                     ))
         (flycheck-clang-include-path . (
                     "/home/user/Downloads/project/headers"
                     "/home/user/Downloads/project/source/mon"
                     ))
     )))

But this does not:

((nil . (
     (company-clang-arguments . (
                     (concat "-I" (projectile-project-root) "headers")
                     (concat "-I" (projectile-project-root) "source/mon")
                     ))
         (flycheck-clang-include-path . (
                     (concat (projectile-project-root) "headers")
                     (concat (projectile-project-root) "source/mon")
                     ))
     )))

The error that is reported:

flycheck-substitute-argument: Value ((concat (projectile-project-root) "headers")) of flycheck-clang-include-path for option "-I" is not a list of strings
SFbay007
  • 1,917
  • 1
  • 20
  • 39

1 Answers1

3

One possibility is using an eval to evaluate the quoted forms in your dir-locals. This may be considered unsafe since anything could be evaluated in such a form.

((nil 
  (eval . (let ((root (projectile-project-root)))
            (setq-local company-clang-arguments
                        (list (concat "-I" root "headers")
                              (concat "-I" root "source/mon")))
            (setq-local flycheck-clang-include-path
                        (list (concat root "headers")
                              (concat root "source/mon")))))))
Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • Thanks. I get this error: File local-variables error: (void-function projectile-project-root) – SFbay007 Jun 04 '17 at 21:36
  • @SFbay007 make sure you have enabled `projectile-mode`. Or autoload that function in your init since it isn;t autoloaded from projectile. – Rorschach Jun 04 '17 at 21:38
  • could you please advice on how to do that in code? I am new to lisp. – SFbay007 Jun 04 '17 at 21:55
  • I moved projectile initialization in the init file all the way to the top and now it works...Thanks. – SFbay007 Jun 04 '17 at 23:17
  • @SFbay007 if you want to autoload a function you can do it via `(autoload 'projectile-project-root "projectile")` assuming that `projectile.el` is on your `load-path` – Rorschach Jun 04 '17 at 23:26
  • jenesaisquoi, it is suggested to use (locate-dominating-file) in place of projectile like in https://emacs.stackexchange.com/questions/12940/variable-project-root-folder-in-dir-locals-el how to apply that in your code? – SFbay007 Jun 05 '17 at 15:59
  • you can replace `projectile-project-root` above with whatever you want to use. If you have a new question you should start a new thread to get more exposure – Rorschach Jun 05 '17 at 16:10
  • I did replace projectile-project-root with (locate-dominating-file default-directory ".dir-locals.el") but that did not work. – SFbay007 Jun 05 '17 at 17:56