【发布时间】:2013-02-05 19:48:26
【问题描述】:
我正在尝试在 emacs 中实现以下缩进:
class A
{
// I ALWAYS use access labels in classes
public: // access-label
int member; // inclass
};
struct B
{
// I NEVER use access labels in structs
int member; // inclass
};
但是用下面的配置文件...
(defun my-cpp-mode ()
"My C++ mode"
(c++-mode)
(c-set-style "K&R")
(setq c-basic-offset 4)
(c-set-offset 'access-label '-)
(c-set-offset 'inclass '++)
;; ...
(setq mode-name "My C++")
)
(add-to-list 'auto-mode-alist '("\\.[ch]p?p?\\'" . my-cpp-mode))
...我只实现:
class A
{
public: // access-label
int member; // inclass
};
struct B
{
// this indentation is too long
int member; // inclass
};
当然是因为:
- 对于缩进,“class”和“struct”显然没有区别(都是“inclass”),
- “inclass”内容的缩进不取决于访问标签的存在与否。
知道如何根据类/结构或访问标签的存在来使 inclass 内容的缩进吗?
【问题讨论】:
-
我想你只希望 public: 和 private: 不添加缩进级别。
-
谢谢,但如果你的意思是“{”和“public:”在同一列上,那不是我想要的。
-
我可以理解您的愿望,并且只要进行足够的调整,它应该是可能的。另一方面,这很可能不容易实现,因为类和结构之间的无区别在 C++ 中非常深入:您甚至可以对结构使用访问说明符。不过,由于这种用途很少见,我会为这个问题 +1,并有兴趣看看是否有任何解决方案出现。
标签: c++ emacs indentation