6

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?

2

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 ()
 (interactive)
 (forward-comment (buffer-size)))

See the Elisp manual, node Motion via Parsing.

2
  • 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 Jun 20 '15 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 Jun 20 '15 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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