Cursor API and strings


I have a string first.second.third();, with the cursor after the d in third.

When I get the cursor using var cursor = editor.getCursor();, and call cursor.isInsideWord();, I get true. This seems weird to me because a “word” is only letters and dashes, and Atom’s Cursor API thinks the () are part of the word. So, I dug around and found that you can try to pass in a different regex to check against by doing cursor.isInsideWord({ wordRegex: /123/ });. That also returns true, which is impossible though…so I’m not getting how I can get cursor.isInsideWord() to work.


Atom’s definition of a “word” is not letters and dashes. Even the standard definition of a regular expression word character is much more inclusive than that:

Looking at the code:

There is no wordRegex parameter for cursor::isInsideWord or any parameter at all. The same goes for the Atom API documentation.

Also looking at the code above, it appears the heuristic that is being used is: When looking at the current row from the cursor location to the end of the buffer line, is there a match for the wordRegExp at the cursor location? The definition of cursor::wordRegExp is here:

Which is kinda complicated, probably very domain-specific and I could spend some time figuring it out, but I’m on vacation and about to take a nap :laughing:

Suffice it to say, I think you probably want to write your own logic around detecting whether or not you’re “inside a word” for whatever that means to you and your code.


Sorry, wrong method. I actually meant .getBeginningOfCurrentWordBufferPosition(). That one accepts a regex, but every time it returns true.


Are you sure? It is supposed to return a buffer position.


What are you trying to do, ultimately?