using findWordAt() while trying to capture floats and full strings (not words)

Hi, I am using CM and i’m looking to extract certain terms from the code, almost all terms work great, the rest is a bit challenging:

float numbers is an issue, i’m using findWordAt() that parses the terms so for example the number 1.23 would be parsed as either 1, or “.” or 23, but never as a float.
Since i’m using “mode” in Python mode, I’ve noticed that CM actually does find numbers and gives them the cm-number class, so my question is how or what method should I use to capture cm-number as a “whole float” returned?

I currently use a mousedown event in parallel with CM’s cursorActivity to capture the number as follows:

$('#element').on('mousedown', function (event) {
    try {
    }catch (e) {
        console.log(`error: ${e}`);

I would rather use CM for all these CM text operations since scaling up the project, I predict this will break or become a monstrosity.


I think you want the token-related function (getTokenAt or getLineTokens), since as you found, ‘words’ are defined rather simplistically.

Thanks marijn, I would like to also contribute in the near future, can you give me a link on what is expected from contributing devs?

There are small issues in python mode that I think needs some fixes, getTokenAt() doesn’t recognize <= (type is null, instead of operator) and from there i’ll be happy to contribute even more.


See the file.

1 Like