1

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

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

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

如果我突出显示整个字段并按 < TAB >,Emacs 会将其视为该区域的正确缩进。除了缩进自定义的其他问题之外,似乎找不到与此相关的任何其他内容


额外细节:

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

; 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’.

4

1 回答 1

0

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

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

于 2020-03-11T21:52:34.377 回答