【发布时间】:2011-10-20 02:19:07
【问题描述】:
据我所知,在 emacs 中,没有办法自定义 C++ 中模板列表的结束“>”字符的缩进级别。目前我的emacs缩进方案是这样做的:
template <
typename T1,
typename T2,
typename T3
>
class X;
我想要的是这样的:
template <
typename T1,
typename T2,
typename T3
>
class X;
将缩进变量 template-args-cont 设置为零将正确缩进 '>' 字符,但代价是取消缩进模板参数列表的实际正文。
emacs 专家有什么建议吗?
编辑:
我通过以下 hack 得到了一些帮助:
(defun indent-templates (elem)
(c-langelem-col elem t)
(let ((current-line
(buffer-substring-no-properties
(point-at-bol) (point-at-eol))))
(if (string-match-p "^\\s-*>" current-line)
0
'+)))
然后在我的自定义主题中将 template-args-cont 设置为 indent-templates,ala:
(c-add-style "my-style"
'("stroustrup"
;; ... Other stuff ...
(template-args-cont . indent-templates))))
但它仍然很麻烦。它在大多数情况下都有效,但有时 emacs 会因为认为模板列表是 arglist 而感到困惑,然后就会产生欢闹。
【问题讨论】:
-
我不确定是否可行,但如果可行,您可以在此页面上找到信息:gnu.org/software/emacs/manual/html_mono/…
-
其实我觉得如果你自己写一个排队函数是可以的。我之前评论中的文档提供了更多信息。
-
请注意,Emacs c++-mode 通常会定期对模板参数感到困惑,因此它实际上可能不是您的代码的问题... [公平地说,实际上很难正确, 因为 C++ 中
<和>的多重含义(有时作为平衡分隔符,有时作为运算符),除非你进行比 c++-mode 更多的实际解析...]