在emacs中向前移动一个复合语句。

时间:2022-06-01 18:15:22

Is there an emacs command to move forward over a compound statement in C or C++ files?

在C或c++文件中,是否有emacs命令继续执行复合语句?

If I have the following code

如果我有以下代码

^ if (foo)
{
   doSomething();
}$

and the point is at the caret (^), I want to be able to do something like M-x forward-compound-statement RET and have the point move to the dollar sign.

重点是在插入符号(^),我希望能够做一些像m x forward-compound-statement RET,转向美元符号。

forward-sexp seems like it should be the right command, but that will only step over a single word, putting the point after the if. c-end-of-statement is also wrong, as it only goes to the first close parenthesis.

前面的sexp看起来应该是正确的命令,但是它只会跨过一个单词,把这个点放在if后面。c-end-of-statement也是错误的,因为它只指向第一个圆括号。

EDIT: In the case of an if-then-else-if-else block, I would ideally want it to go past all of the else blocks.

编辑:如果是if-then-else-if-else块,我希望它能通过所有else块。

I am also hoping to use this inside defuns that I write in the future, so key strokes are less of a concern than having one command to do it rather than repeating a command until I see that it gets to the right location.

我也希望在将来使用我在defuns中编写的这个功能,因此,比起使用一个命令而不是重复一个命令(直到我看到它到达正确的位置),关键的笔划并不那么重要。

1 个解决方案

#1


1  

Something like forward-compound-statement may very well exist for specific major-modes. I wouldn't bother learning them though.

对于特定的主要模式来说,像前向复合语句这样的语句很可能存在。但我不会去学习它们。

Instead, I recommend you get used to navigating with more composable commands like C-s. You can try something like jump-char to shorten the sequence by one key.

相反,我建议您习惯于使用更可组合的命令,比如C-s。你可以试着用一个键来缩短序列。

#1


1  

Something like forward-compound-statement may very well exist for specific major-modes. I wouldn't bother learning them though.

对于特定的主要模式来说,像前向复合语句这样的语句很可能存在。但我不会去学习它们。

Instead, I recommend you get used to navigating with more composable commands like C-s. You can try something like jump-char to shorten the sequence by one key.

相反,我建议您习惯于使用更可组合的命令,比如C-s。你可以试着用一个键来缩短序列。