gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 07:32:28 27 4
gpt4 key购买 nike

我正在使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com