I like to use the forward- and back-paragraph methods to jump around my source code. I would like it to behave slightly differently though. Consider the following comment block:

// comment line one.
// comment line two.

I'd like to jump over the entire comment block, and not land in-between line and and two -- in other words, I'd like it to consider a contiguous comment block as a single paragraph.

Anyone know how to do this?

1 Answer 1


If what you want to do is skip forward over all of a set of contiguous comments then M-: (forward-comment (buffer-size)) should do more or less what you request.

You can of course wrap that sexp to define a command:

(defun my-fwd-comment ()
 (forward-comment (buffer-size)))

See the Elisp manual, node Motion via Parsing.

  • 1
    Thanks, this is interesting info, but it's not quite what I'm looking for. My use case is I'm using a fwd-pgph and back-pgph to navigate through code, and I get annoyed that I get hung up in a multi-paragraph comment... it's a fairly minor point, but if I could could use the same key combo to get fwd-paragaph in code and fwd-comment over comments, that would be slick.
    – Spacemoose
    Commented Jun 20, 2015 at 19:45
  • 1
    You can do that by defining a command that calls one or the other, depending on whether it is looking at or is inside a comment. See, for instance, syntax-ppss, including (nth 4 (syntax-ppss)).
    – Drew
    Commented Jun 20, 2015 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.