Setting flycheck-clang-include-path in .dir-locals using projectile
Asked Answered
P

1

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
Pekin answered 4/6, 2017 at 19:0 Comment(0)
C
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")))))))
Camass answered 4/6, 2017 at 19:25 Comment(8)
Thanks. I get this error: File local-variables error: (void-function projectile-project-root)Pekin
@Pekin make sure you have enabled projectile-mode. Or autoload that function in your init since it isn;t autoloaded from projectile.Camass
could you please advice on how to do that in code? I am new to lisp.Pekin
I moved projectile initialization in the init file all the way to the top and now it works...Thanks.Pekin
@Pekin 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-pathCamass
jenesaisquoi, it is suggested to use (locate-dominating-file) in place of projectile like in emacs.stackexchange.com/questions/12940/… how to apply that in your code?Pekin
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 exposureCamass
I did replace projectile-project-root with (locate-dominating-file default-directory ".dir-locals.el") but that did not work.Pekin

© 2022 - 2024 — McMap. All rights reserved.