【问题标题】:Emacs auto-indentation prevent double indentation on constructorsEmacs 自动缩进防止构造函数的双重缩进
【发布时间】:2014-09-20 17:50:07
【问题描述】:

我在 Windows 上使用 Emacs 24.3。我设置了自动缩进,但我希望 C++ 中的构造函数只缩进一层。我读过将 substatement-open 值设置为 0 可以解决此问题,但是,我仍然遇到此问题。

我目前看到的:

class A 
{  
public:
    A() 
        {
            // code
        }    
};

我想看什么:

class A 
{  
public:
    A() 
    {
        // code
    }    
};

谁能告诉我我的 .emacs 中有什么问题或缺少什么来纠正这个问题?

(setq c-default-style "stroustrup"
      c-basic-offset 4)

; no extra indentation on constructors
(defun my-cpp-mode-hook ()
  (setq c-basic-offset 4)
  (c-set-offset 'substatement-open 0))
(add-hook 'c++-mode-hook 'my-cpp-mode-hook)

; auto-indentation
(add-hook 'c-mode-common-hook (lambda () (c-toggle-auto-state 1)))

【问题讨论】:

    标签: emacs indentation


    【解决方案1】:

    尝试修改my-cpp-mode-hook,将inline-open也设置为0

    (defun my-cpp-mode-hook ()
      (setq c-basic-offset 4)
      (c-set-offset 'substatement-open 0)
      (c-set-offset 'inline-open 0))
    

    通常,您可以通过移动到有问题的行并使用c-show-syntactic-information(默认绑定到C-c C-s)来检查c-mode(和类似模式)中的缩进规则,在这种情况下会给出Syntactic analysis: ((inclass 10) (inline-open)) .

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-02
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多