2

I tried running (forward-comment -1) by eval command, when the point is actually in the middle of a comment. Like forward-word (or) forward-line, i expected it move to the beginning of the comment & then to the previous comment etc...

But, the point is not moving at all..

Like, my javascript snippet looks like,

    /*  this is a dummy comment
   this is additional(^) comment
this is more additional  comment*/

My cursor is on the second line denoted by caret symbol and then i run, (forward-comment -1) and i expect the point to move to the comment's beginning. But (point) has not changed at all.

Note: This behavior is noticed in elisp mode as well with semicolon-ed comments.

2

Yes, that's the way forward-comment works (likewise forward-sexp).

To quote Stefan, from part of bug #8667:

The forward-THINGY functions all share the following property AFAIK: when called with a positive argument with point before some THINGIES, they will skip over that many THINGIES and when called with a negative argument with point after some THINGIES they will skip over that many THINGIES.

E.g. just like forward-comment, forward-sexp from within a sexp will not skip to the end of that sexp. And just like forward-sexp, forward-comment called in front of a nested comment will jump over that nested comment.

All calls with point elsewhere than before/after a THINGY behave in somewhat arbitrary ways which mostly depend on how the function is implemented and what kind of structure have (e.g. can they nest? Can we easily tell when we're in the middle of a THINGY ?).

0

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.