Unexpected completion with TAB in presence of underscore


This is a follow up on the following issue

In particular, it seems like once _ is added to the list of “Non Word Characters” then autocomplete-python breaks when trying to auto-complete something like pa_bar.

Do you have any idea for a workaround? Has anyone else experienced this problem?


autocomplete-python looks at the word currently under the cursor to see what it should suggest, and you have deliberately defined that _ is a non-word character, breaking pa_bar into two words.


So there’s no nice way to enjoy both worlds?


You could rewrite the next-word command to jump to the next word or _.

The API has support for most things like this, but in this case it’s lacking (there’s no editor.moveToNextCharacter('_')). So what would have to happen is that the package or init.coffee script would define a new command that checks the cursor position and then pulls that row. The column in the cursor position is the index in the resulting string, and you can perform a normal search from the index to the end for underscores. Use editor.moveToBeginningOfNextWord(), return (doing nothing) if the cursor row has changed, then record the cursor column and compare it to the index of the first underscore. If the first underscore comes first, set the cursor position accordingly.


There’s a new setting autocomplete.extraWordCharacters that you can set which is separate from editor.nonWordCharacters.
https://github.com/atom/language-css/blob/d57ce703cd5afa8fe44b72877558c8e0a53a372f/settings/language-css.cson#L7 as an example.

EDIT: Might only be in Atom 1.24-beta and above.


@DamnedScholar You mean I should redefine the function and remove _ from the non-words list?

@Wliu How can I add _ globally to this setting? How can I know whether it is already available for 1.23?


That would allow you to maintain your workflow while fixing the autocomplete behavior, yes. However, with what @Wliu said, you might just want to grab the Atom beta.

How can I add _ globally to this setting?

You see how it’s specified in language-css.cson? Do exactly the same thing in your config.cson, but with a global scope.

    extraWordCharacters: "_-"

How can I know whether it is already available for 1.23?

It’s not. The feature was added on January 11, and 1.23 came out on January 9.


Any idea when 1.24 will be released?


We don’t advertise planned release dates. Check the blog (https://blog.atom.io) every few days to see if there’s been an update.


I had the chance to auto update to 1.24 and I still have an issue. In particular _ is added both to Non Words Characters in Settings -> Editor and to extraWordCharacters in config.cson. But the problem I have is still there.

Am I doing something wrong?


@Wliu? Can you please try and reproduce the issue?


Sorry, missed your last reply. I’ll see if I have time.


Thanks! I’ll be happy to provide further debugging data.


Update: I’ve been really busy recently; I’ll try to take a look this coming week.