user3408579
user3408579

Reputation: 11

Changing Emacs CC mode indent style

I'm an emacs newbie and I've been trying to set up my indent style for cc-mode. I like to write code like this:

if(true)
{
    foo();
    bar();
}

But the default indent style is more like:

if(true)
  {
    foo();
    bar();
  }

It seems the indent style I want is "bsd" while the default is "gnu". I put the following in my init.el file to change the settings:

(setq c-default-style "bsd")
(setq c-basic-indent 4)
(setq c-basic-offset 4)

This changed the offset and the default style, but when I typed some code out, it was still formatted like the gnu style. To clarify, I would type out if(true) [ENTER] { [ENTER] foo(); [ENTER] } and the result would be the gnu style code. I also tried putting this in my init.el, for the same results:

(defun my-c-mode-hook ()
(setq c-basic-offset 4
    c-indent-level 4
    c-default-style "bsd"))
(add-hook 'c-mode-common-hook 'my-c-mode-hook)

I could tell the settings were definitely changed because in the minibuffer I evaluated this expression (message "%s %s %d" c-default-style c-indentation-style c-basic-offset) to get this result: "bsd bsd 4"

I am using graphene. Is it possible that one of its included packages (smartparens or autocomplete maybe) could be interfering with my settings?

Upvotes: 1

Views: 687

Answers (0)

Related Questions