Unexpected completion with TAB in presence of underscore


#1

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?


#2

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.


#3

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


#4

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.


#5

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.


#6

@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?


#7

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.

"*":
  autocomplete:
    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.


#8

Any idea when 1.24 will be released?


#9

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.


#10

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?


#11

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


#12

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


#13

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


#14

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