1
18
2011
0

Emacs中的K&R C风格设置

最近开始用emacs了,可是被这个问题困扰,就是我一般这样输入C代码

int foo(int x)
{
    int y, z;
    if( x < y )
        return y-x;
    else if ( x == y )
        return 0;
    else
        return x-y;
}

可是emacs就非得给我格式化成

int foo(int x)
    {
      int y, z;
      if( x < y )
        {
          return y-x;
        }
      else if ( x == y )
        {
          return 0;
        }
      else
        return x-y;
    }

后来一查,原来我一般用的就是K&R风格,而Emacs默认是GNU风格,在emacs的手册上找到了解决方法,自我发挥一下,就彻底解决这个问题了:

$ emacs ~/.emacs

追加如下代码:

;; c code indentation
(setq c-default-style
    '((c-mode . "k&r") (other . "gnu")))
(setq c-basic-offset 4)

现在就找回熟悉的自我了smiley

 

Category: 技术 | Tags: | Read Count: 4923

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Powered by Chito | Hosted at is-Programmer | Theme: Aeros 2.0 by TheBuckmaker.com