0

I have a setup where I use EDE from CEDET for C projects development (among other things) and the real good flycheck on-the-fly syntax checking.

I have defined ede-cpp-root-project in my .emacs file for several projects where I have set project include-path variable to include the whole set of my project includes for each project. This works splendidly; auto-complete works and the all the includes are found by the semantic package for every project.

Now the question is how to set up this same include path for flycheck without heavy duplication?

Edit: I'm using gcc with flycheck, although I guess it doesn't make too much difference compare to clang.

0

Found an answer at: https://ogbe.net/emacsconfig.html

Copy-paste from the page:

Projects

In some projects, flycheck needs some information about the projects include path. Since we want to use EDE for C and C++ projects anyways, we can grab the include path from there.

(require 'ede)
(global-ede-mode t)
(require 'flycheck-cedet)

(defun dennis-flycheck-get-ede-includes ()
 (interactive)
 "Check if the current file is part of an EDE project.
  If yes, set up `flycheck-clang-include-path'"
 (make-variable-buffer-local 'flycheck-clang-include-path)
 (let* ((rel-includes
          (flycheck-cedet-get-cpp-includes "" (buffer-file-name)))
         (dirname (when rel-includes
                    (ede-cpp-root-project-root default-directory))))
    (when rel-includes
      (when (string-match "\\(.*\\)/$" dirname)
        (setq dirname (substring dirname (match-beginning 1) (match-end 1))))
      (setq incl-paths
            (mapcar '(lambda (arg) (concat dirname arg))
                    rel-includes))
      (setq flycheck-clang-include-path
            (append flycheck-clang-include-path incl-paths)))))

(add-hook 'c-mode-common-hook 'dennis-flycheck-get-ede-includes)

We can now list our current EDE projects. This is not being exported.

This one is referencing flycheck-cedet. It can be found here: https://github.com/dholm/flycheck-cedet

0

Other option is not to use EDE but to use projectile! See https://github.com/bbatsov/projectile . Add .projectile file to the project root to make it a projectile project and this to .emacs:

(require 'projectile)
(defun setup-flycheck-gcc-includes ()
  "Set gcc includes for flycheck using projectile."
  (let ((root (ignore-errors (projectile-project-root))))
    (when root
      (setq-local flycheck-gcc-include-path
                  (mapcar (lambda (dir-x)
                            (concat root dir-x)) (projectile-current-project-dirs))))))

(add-hook 'c-mode-common-hook 'setup-flycheck-gcc-includes)                  

I know that this adds every subdir that the projectile considers as project directory as a possible include directory. One might want to filter the list with some magic regex or something if one has better knowledge on which dirs are include dirs.

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.