【问题标题】:Suppress c++ namespace indentation in emacs [duplicate]抑制emacs中的c ++命名空间缩进[重复]
【发布时间】:2012-12-11 17:16:51
【问题描述】:

可能重复:
Emacs - override indentation

我想要的是 emacs 不在命名空间内缩进代码

namespace a_namespace{

// no indentation
int namespace_global_variable;


// no indentation
class Class {
    // comment
    Class();
    //...
};

// and so on


}

当我尝试修改 innamespace 变量,或使用 C-c C-o 更改感兴趣点的缩进时,我没有得到想要的效果(实际上后者消除了函数内部的所有缩进) .

我的缩进配置如下所示(从 Google emacs 配置中复制):

(c-offsets-alist . ((arglist-intro vista-c-lineup-expression-plus-4)
                    (func-decl-cont . ++)
                    (member-init-intro . +)
                    (inher-intro . ++)
                    (comment-intro . 0)
                    (arglist-close . c-lineup-arglist)
                    (topmost-intro . 0)
                    (block-open . 0)
                    (inline-open . 0)
                    (substatement-open . 0)
                    (statement-cont
                     .
                     (,(when (fboundp 'c-no-indent-after-java-annotations)
                         'c-no-indent-after-java-annotations)
                      ,(when (fboundp 'c-lineup-assignments)
                         'c-lineup-assignments)
                      ++))
                    (label . /)
                    (case-label . +)
                    (statement-case-open . +)
                    (statement-case-intro . +) ; case w/o {
                    (access-label . /)
                    (innamespace . -))))

【问题讨论】:

  • 好像和here一样。
  • 该解决方案对我不起作用(虽然可能是用户错误)。
  • 这不是一个严格的重复,因为另一个问题要求 some 缩进,而这要求 none。 none 的解决方案可能比“一些金额设置为零”的解决方案更好。
  • 随便(c-set-offset 'innamespace '0)

标签: c++ emacs indentation


【解决方案1】:
(defconst my-cc-style
  '("cc-mode"
    (c-offsets-alist . ((innamespace . [0])))))

(c-add-style "my-cc-mode" my-cc-style)

来自Jason Zhang 的answer。在这里工作。

【讨论】:

  • 在我现有的c-offsets-alist 中简单地将- 替换为[0] 并不能解决问题。
  • 现在它似乎工作了——我不能 100% 确定 emacs 需要什么来重新读取它的 init 文件。
  • 不知何故这对我不起作用,即使在重新启动 Emacs 之后也是如此。 (c-set-offset 'innamespace 0) 有效(取自 brrian.tumblr.com/post/9018043954/…)
  • 请注意,这是从州复制的答案“然后使用 c-set-style 来使用您自己的样式。” 这里缺少重要的信息吗?跨度>
  • 这是旧的,但要让 emacs '重新读取它的 init 文件':-x eval-buffer(在访问 .emacs 或任何你命名的文件时)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-10
  • 2011-05-03
  • 2011-08-17
  • 2013-05-17
相关资源
最近更新 更多