【问题标题】:Emacs semicolon presses indent to width of entire previous line, declaring private class variables. How to fix & stop? (c-electric-semi&comma?)Emacs 分号按整个前一行的宽度缩进,声明私有类变量。如何修复和停止? (c-electric-semi&comma?)
【发布时间】:2020-03-11 20:17:40
【问题描述】:

我的 .cpp 文件中的所有内容都正常缩进,直到我在以下几行中按下分号 ; --- 此时 emacs 一直缩进到最后一行的全长输入...

如果我删除访问修饰符并为任何类或结构声明 vars int x 和 int y,这很奇怪。

class Blah {
  private int x;
               private int y;
                            private int z;
};

如果我突出显示整个字段并按 ,Emacs 会将此视为该区域的正确缩进。除了indent customization 上的其他 qs 之外,似乎找不到与此相关的任何其他内容。


其他细节:

C-h k ;产生这个描述,所以它可能与这个特性有关——虽然我不明白,因为所描述的缩进似乎是指下一个换行符,而不是光标所在的当前行。

; runs the command c-electric-semi&comma (found in c++-mode-map),
  which is an interactive compiled Lisp function in ‘cc-cmds.el’.

It is bound to ,, ;.

(c-electric-semi&comma ARG)

Insert a comma or semicolon.

If ‘c-electric-flag’ is non-nil, point isn’t inside a literal and a
numeric ARG hasn’t been supplied, the command performs several electric
actions:

(a) When the auto-newline feature is turned on (indicated by "/la" on
the mode line) a newline might be inserted.  See the variable
‘c-hanging-semi&comma-criteria’ for how newline insertion is determined.

(b) Any auto-newlines are indented.  The original line is also
reindented unless ‘c-syntactic-indentation’ is nil.

(c) If auto-newline is turned on, a comma following a brace list or a
semicolon following a defun might be cleaned up, depending on the
settings of ‘c-cleanup-list’.

【问题讨论】:

标签: emacs emacs26


【解决方案1】:

; 是触发“更正这一行的缩进”命令的众多键之一。 ; 这里没有什么特别之处,只是 Emacs 通常会根据为文件定义的样式保持您的缩进正确。

正如 0x5453 在评论中所说,您的 C++ 文件在语法上无效,并且缩进器正在尽最大努力为这个不正确的文件提供合理的缩进。如果你修正你的代码是合法的,缩进也将被解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 2012-10-31
    • 2013-09-06
    • 1970-01-01
    • 2022-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多