0

I am using the following content to include headers to my project using .dir-locals.el

((c++-mode .
   ((flycheck-clang-language-standard . "c++14")
    (flycheck-clang-include-path
     "/Users/user/Documents/project_name/source"
     "/Users/user/Documents/project_name/source/library/include")
    )))

But, I do not want to explicit tell the path when it is located on my computer.

I was trying to use (concat (file-name-directory (or load-file-name buffer-file-name)) "library/include") for .../source/library/include and just (file-name-directory (or load-file-name buffer-file-name) for .../source. Since .dir-locals.el is located in /Users/user/Documents/project_name/source

However when I replace the part with its respective instructions I got

Error while checking syntax automatically: (error "Value (\"/Users/user/Documents/project_name/source" (eval concat (file-name-directory (or load-file-name buffer-file-name)) \"library/include\") of flycheck-clang-include-path for option \"-I\" is not a list of strings")

I tried to use it with eval but did not work, How can I accomplish my goal?

EDIT: I test using eval as db48x suggested as the following:

((c++-mode .
    ((flycheck-clang-language-standard . "c++14")
    (eval .
        (setq flycheck-clang-include-path
            '("/Users/user/Documents/project_name/source"
         "/Users/user/Documents/project_name/source/library/include"))
        )
    )
))

That worked fine, but when adding replacing the second path with (concat (file-name-directory (or load-file-name buffer-file-name)) "library/include") got that it is not a list of string.

0

In this context, eval isn't a function, it's just a symbol that tells it to evaluate a form rather than to set a variable. You need to do this instead:

((c++-mode .
   ((flycheck-clang-language-standard . "c++14")
    (eval .
     (setq flycheck-clang-include-path
           "/Users/user/Documents/project_name/source"
           (concat (file-name-directory (or load-file-name
                                            buffer-file-name))
                   "library/include")))))

Edit: Oops, you're right. In addition to leaving out a parenthesis, I left out something else that is important: I forgot to build a list of filenames. You almost fixed it correctly by putting the filenames in a quoted list, but the elements of a quoted list are not evaluated, so the quoted list just has the same non-filename stuff in it and gives you the same error. You can call the list function instead to build a list out of things that need to be evaluated. For example:

((c++-mode .
   ((flycheck-clang-language-standard . "c++14")
    (eval .
     (setq flycheck-clang-include-path
           (list "/Users/user/Documents/project_name/source"
                 (concat (file-name-directory (or load-file-name
                                                  buffer-file-name))
                         "library/include")))))))

I've actually tested it this time, so I know it works.

4
  • I got the same error saying the string paths are not a list of strings. Error while checking syntax automatically: (error "Value \"/Users/user/Documents/project_name/source" (quote (concat (file-name-directory (or load-file-name buffer-file-name)) "library/include"))) of flycheck-clang-include-path for option \"-I\" is not a list of strings")
    – Roger PA
    May 3 '20 at 16:17
  • You'll have to share the content of the file. I suspect you forgot to use eval. Also, the quote around the call to concat will prevent it from working.
    – db48x
    May 4 '20 at 20:38
  • Please check my update. I don't think the content of the file is the problem, what do you mean with the quote around concat, I had to add a ` to the list of paths to make it worked with raw strings. Without that quote as your suggestion, gives me the same error.
    – Roger PA
    May 8 '20 at 1:20
  • Yeah I was close, thank you for your help
    – Roger PA
    May 9 '20 at 21:59

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.