2

When the point is not at the beginning of a word/sexp, backward-word / backward-sexp places the cursor at the beginning of that word/sexp. If the point is already at the beginning of a word/sexp, this is of course not the case.

How to go to the beginning of the current word/sexp regardless of the point position?

Edit 1: By current sexp, I mean the smallest sexp containing the point, for example if the cursor is at o in the expression (end-of-line), the current sexp would be end-of-line. If the cursor is at (, the current sexp would be the whole (end-of-line).

Edit 2: Another reformulation of this question: how to detect if the point is at the beginning of the current word/sexp?

  • 1
    Do you mean if the point is already at the beginning of sexp it should stay where it is if you call backward-sexp? – clemera Aug 22 '15 at 21:54
  • @hatschipuh A function which puts the cursor at the beginning of the current word/sexp. Of course, backward-word/sexp itself cannot do this. – Name Aug 22 '15 at 22:11
  • Essentially, one would need to test for the various known conditions -- e.g., a space before the word or at line beginning. This can be done various ways -- e.g., regexp test; using a syntax test; testing for certain character codes; etc. Here is an example of a custom function that tests using syntax: stackoverflow.com/q/18675201/2112489 It is just an example, which is not custom tailored to answer this particular question. – lawlist Aug 22 '15 at 22:27

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.