开发者

Change Emacs C style not working

开发者 https://www.devze.com 2023-04-04 09:18 出处:网络
For Emacs CC-mode, I am trying to use the \"bsd\" style, but make it so that all lines default to indentation in increments of 4 instead of 8. In my .emacs file, I have put:

For Emacs CC-mode, I am trying to use the "bsd" style, but make it so that all lines default to indentation in increments of 4 instead of 8. In my .emacs file, I have put:

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

But all lines still indent to 8 spaces. I can't really locate where the problem is. I'm running G开发者_如何学编程NU Emacs 23.3.1.


CC-mode settings are buffer-local which can cause problems. The best way to configure it is to put your customizations in a hook. That will ensure that, regardless of whether cc-mode has made c-basic-offset buffer local or not, the changes will be applied when the mode is started. I use something similar to this:

(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)


That looks right. Have you executed those lines in your .emacs file? Go to the end of them and do C-x C-e. If that doesn't work, close emacs and restart it (which forces it to re-read your .emacs file). If that doesn't work, go to your scratch buffer or something similar, and execute (message "%s %d %d" c-default-style c-basic-offset c-indent-level) to see what emacs thinks those values are (maybe you are including another file that overwrites those values?) Then load one of your CC files and check the mode to be sure you are in a C-type mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消