c++ - 自定义 google-c-style.el

标签 c++ emacs indentation

我正在使用 google-c-style.el缩进我的 C++ 程序。类中的函数将缩进如下: enter image description here

这不是我想要的,我想要这个:

enter image description here

这是我在 .emacs 中的设置:

(setq c-default-style "linux")

(setq c-basic-offset 4)

(require 'cc-mode)

(require 'google-c-style)

(add-hook 'c-mode-common-hook 'google-make-newline-indent)

最佳答案

看起来你还需要:

(add-hook 'c-mode-common-hook 'google-set-c-style)

目前,即使您需要 google-c-style,它也不会添加样式,直到上面的 defun 被调用。文档字符串说它也应该被添加到钩子(Hook)中。


更一般地说,对于缩进问题,您需要了解 c-offsets-alist

它允许您自定义缩进在不同句法元素上的执行方式。 找出您需要修改哪个元素的简单方法是转到该位置(例如,在您的示例中打开 fun())并点击 C-c C-s for c-显示句法信息

我个人不会使用这个 google 风格的脚本,而是从它或其他 c 风格派生并覆盖值以满足我的口味。

例如,我注意到您期望 c-basic-offset 为 4,但 google-style 使用的 c-basic-offset 为 2,因此您可以派生并覆盖 Google 样式以替换 c-basic-offset .

checkout :How to make Emacs put access level modifiers in their own indentation level in my C++ code?举个例子。

关于c++ - 自定义 google-c-style.el,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17391095/

相关文章:

emacs - 如何告诉 Emacs find-file 不要折叠 '//' 的路径

emacs - 如何像自动完成一样显示弹出符号文档?

python - emacs 根据文件中已有的内容使用不同的缩进

windows - f#中的缩进问题(vs2010 beta1)

python - 列表列表,我似乎无法正确缩进

C++ 如何将任何类(自定义)对象转换为 vector <unsigned char>

c++ - 有没有办法 decltype 不可调用函数的结果?

macos - 在Emacs.app中使用Cask

c++ - 调用重写函数并使用基类中的重载变量

C++调用子类的虚方法而不是基类