Given that the point is right in front of a comment, how do I move it to the end of the comment, but before the comment end markers?

For example:

  • for a C++ // xxx comment, I would like to move the point to the end of the line
  • for C-style /* xxx */ comments I would like to move the point to right before the second *.

To complicate matters, I would like this to be mode independent. Also, I would like the solution to be based on the syntax table, as there are major modes that don't set up the comment-related regex variables properly.

Starting points:

  • The function forward-comment can move the point the after the comment end marker, but I want it to stop before the comment end marker
  • The syntax table can define three kinds of comments at the same time (where the b and c flags indicate that character is part of alternative comment kinds). When the point is inside a comment, the function syntax-ppss can tell which kind of comment it is.

Your Answer

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

Browse other questions tagged or ask your own question.