【问题标题】:Change count of tabs in 'case' keyword on emacs in c++ mode在 c++ 模式下更改 emacs 上的“case”关键字中的选项卡数
【发布时间】:2014-03-08 18:29:55
【问题描述】:

我在 emacs 上将编码样式更改为 BSD,现在看起来像这样:

switch(a)
{
 case TYPEvar:
    return x(node);
}

我想在case之前添加一个标签,像这样:

switch(node->type)
{
  case TYPEvar:
       return walk(node);
}

我需要在 .emacs 中进行哪些更改?我试过(我不做emacs lisp)更改tab-width in:

(setq-default c-basic-offset 2
          tab-width 2
          indent-tabs-mode t)

但它什么也没改变。

【问题讨论】:

    标签: c++ emacs coding-style


    【解决方案1】:

    如果只对当前缓冲区执行此操作,请转到包含 case 的行并执行 C-cC-o,它会提示您输入要缩进的语法符号更改输入/选择case-label(默认选中)。然后输入缩进的值,输入你想要的缩进。

    上面设置了当前缓冲区的缩进。要为所有缓冲区设置缩进,您可以使用c-mode-common-hook,如下所示

    (add-hook 'c-mode-common-hook (lambda ()
                                    (add-to-list 'c-offsets-alist '(case-label . 2))))
    

    【讨论】:

    • 很奇怪。谢谢!另外,我可以将此更改应用于尚未使用此新样式缩进的自动缩进文件吗?
    • 你可以写一些elisp代码。就像(setq files '("~/test.c")) (dolist (file files) (with-current-buffer (find-file file) (mark-whole-buffer) (indent-for-tab-command) (save-buffer) (kill-buffer))) 应该完成files 是您要缩进的文件列表的工作。虽然我没有测试过,但要小心!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 2019-03-17
    相关资源
    最近更新 更多