Sublime Forum

Stop Auto-Complete From Committing on 'Space'

#1

Is there any way to stop the Auto-Complete from committing when pressing ‘space’? I see the “auto_complete_commit_on_tab”: false option in the settings, but nothing to stop pressing the ‘space’ key from committing the selected entry.
Perhaps I can make use of some combination of the “auto_complete_selector” or “auto_complete_triggers” settings? Any help will be greatly appreciated.

1 Like

How to autocomplete inside a word?
#2

I have found that, if auto completion pops up automatically (from the auto_complete_selector and auto_complete_triggers preferences), it can only be completed by Tab/Enter as per the auto_complete_commit_on_tab preference. But, if you manually trigger auto completion, whether by the menu, a keybinding or a plugin calling view.run_command('auto_complete'), whatever you type/press next (if it is a word separator / non-word character) will commit the autocompletion and insert the character pressed. (Proven on ST3120 clean state on Windows and Linux.)

Is there a way to disable this, so that no matter how the auto completion is triggered, it will only ever complete on Tab/Enter as per the auto_complete_commit_on_tab preference? (without changing the word_separators preference, because that will affect double clicking etc.)


Example workflow to see this behavior:

  1. Open a new tab
  2. Set the syntax to Python (which has the source scope, which will by default trigger automatically as you type)
  3. type example1Enterexample2Enterexample3Enter
  4. type ex and press @. output is ex@
  5. press Backspace (or type ex and press Esc) and press Ctrl+Space. press @. output is example2@
  6. try with other non-word characters like Space or ( etc. same behavior as @. word characters like z insert a literal z and cancel the autocompletion.
  7. change the word_separators preference to an empty string and try again. behavior is the same as automatically triggered auto completion.
2 Likes

#3

You’re right, this was exactly the behavior I was seeing. I don’t have a proper solution, but have managed to find a hacky workaround.

It involves calling the hide_auto_complete command and returning from the completion function if the next character is a space.

pos = view_sel[0].end()
next_char = view.substr(sublime.Region(pos - 1, pos))

if next_char in (' ', '\n'):
    view.run_command('hide_auto_complete')
    return

This is a snippet from the Gherkin Auto-Complete Plus plugin I wrote. Take a look at the file gherkin_event_listener.py for more context.

3 Likes

#4

nice work @austincrft, thanks for sharing! - I especially like this bit:

where you pass arguments to the auto_complete command. Out of interest, where did you find out about the valid arguments? EDIT: I’ve just seen your SO question and understand that you took it from https://github.com/SublimeCodeIntel/SublimeCodeIntel/blob/c1b34873a90c3502de77dd983a93ec7bd5293d7e/SublimeCodeIntel.py#L210-L214 - how the author of that package knew about those arguments, I’d like to know!)

Using "disable_auto_insert": true does exactly what I want! :smiley: :heart:
(it also shows the pop-up when there is only one completion, so it seems to serve 2 functions at once)

2 Likes

#5



Seems the developer of SCI got Jon to add API methods especially for him :o Dev Build 2148 and the only documentation for them is in the release notes…

1 Like

#6

Oh, that’s interesting. I hadn’t realized it was added specifically for the SublimeCodeIntel package.

It took a lot of digging and experimenting to get that part working. I’m glad I can save someone else the trouble. :smiley:

2 Likes