The "gnu" style sets c-basic-offset
to 2, so that's where that's coming from.
As you have specific needs for a specific filename extension, I'd probably just define a derived mode to use with auto-mode-alist
:
(define-derived-mode cuda-mode c-mode "CUDA"
"CUDA mode."
(setq c-basic-offset 4))
(add-to-list 'auto-mode-alist '("\\.cu\\'" . cuda-mode))
You might alternatively call c-set-style
in the mode body, for some appropriate style, or even have an empty mode body and add an entry to c-default-style
for the new mode, depending on which approach you think will be the easiest to maintain.
Note also that c-basic-offset
is automatically buffer-local, so the following isn't doing anything useful for that variable:
(setq c-default-style "k&r"
c-basic-offset 4)
You could use (setq-default c-basic-offset 4)
if you want to, but it's probably sensible to leave the default value alone.
Lastly, ("c++" . "linux")
looks to me to be invalid as an entry in the c-default-style
alist. That list maps major mode symbols to style names, and "c++" is not a symbol (nor even the name of a major mode symbol). I doubt that entry is doing anything?