I am trying to fine-tune the setup for emacs with emacs prelude included.
I want to have as the default checker cppcheck
for flycheck and activate ggtags by default for GNU Global. I am coding mainly c++. It used to work before for ggtags-mode
variable but now it seems not to work anymore.
(load "/home/user/.emacs.d/init.el")
(defun my-c-mode-common-hook ()
"Hook for all c derived modes."
(c-add-style "my-style"
'("stroustrup"
(c-offsets-alist
(innamespace . [0])
(inline-open . 0)
(inher-cont . c-lineup-multi-inher)
(arglist-cont-nonempty . +)
(template-args-cont . +))))
(setq c-default-style "my-style")
(when (derived-mode-p 'c-mode 'c++-mode)
(ggtags-mode 1)
(flycheck-select-checker "c/c++-cppcheck"))
)
(add-hook 'c-mode-common-hook
(my-c-mode-common-hook))
I have a warning that says the following functions are not known to be defined: ggtags-mode, flycheck-select-checker
. But when loading the .emacs file is loaded, there are no errors.
Can anyone help me with the right way to make these 2 minor modes work correctly configured? For me it seems the right way to do it, but obviously I am missing something.
You use add-hook
wrongly: It takes a function as 2nd argument but you call your function there and so pass the value of (flycheck-select-checker ..)
as the function. You will likely see an error in a C (C/Java/C++/AWK/...) mode.
What you need to do is (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
.
Also this code will never be executed:
(when (derived-mode-p 'c-mode 'c++-mode)
(ggtags-mode 1)
(flycheck-select-checker "c/c++-cppcheck"))
because 'c-mode
is not derived of 'c++-mode
, I guess you want to check if the current major-mode is derived of c++-mode
:
(when (derived-mode-p major-mode 'c++-mode)
(ggtags-mode 1)
(flycheck-select-checker "c/c++-cppcheck"))