emacs — C / C ++跳转到包含块的开头


10

在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模式有 fortran-beginning-of-block

程序模式有 promela-find-start-of-containing-block

Answers:


14

试试backward-up-list,默认绑定为C-M-u


1
和CMn(前移列表)跳到程序段的末尾
Francois

为了从头到尾一直在块内跳转,这并不能解决目的,因为当我尝试移动到块的末尾时,C-M-n会将我带到)函数调用的结尾。
dknight

1
有四个相关命令:CMn(下一个)和CMp(上一个),它们使您在整个括号块中来回移动; CMu(向上)和CMd(向下),使您向上或向下嵌套括号一级。(请参阅文档)因此,要转到当前块的末尾,您需要CMu CMn
rbennett485 '16
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.