![emacs — C/C++ 跳转到包含块的开头](https://linux22.com/image/1269590/emacs%20%E2%80%94%20C%2FC%2B%2B%20%E8%B7%B3%E8%BD%AC%E5%88%B0%E5%8C%85%E5%90%AB%E5%9D%97%E7%9A%84%E5%BC%80%E5%A4%B4.png)
在 emacs 中编辑 C 或 C++ 文件时,我希望能够转到包含代码块。我原本希望找到一个 c-beginning-of-block 函数,但遗憾的是,没有这样的函数(据我所知)。例如,我可能正在编辑以下丑陋的 C 代码:
void myFunction()
{
if (something) { //<--- I want to jump to this brace!
// do lots of stuff
if (stuff) {
// stuff
}
// more stuff
// ...
// I want to put my cursor somewhere on this line <---
// (anywhere just outside the following if) and call c-beginning-of-block
// and jump to the brace marked above (skipping "sibling" statements)
if (pizza_is_good) {
// do something
// wait, where am I?
}
// way more stuff
// ...
if (i_love_pizza) {
// eat pizza
}
}
}
如果这还不是 emacs 的一部分,我会感到非常惊讶,我只是在任何地方都找不到它......
fortran-mode 有fortran-beginning-of-block
promela-mode 有promela-find-start-of-containing-block
答案1
尝试backward-up-list
,默认绑定到C-M-u。