Sublime Forum

Auto-completion triggered by space character

#1

I use StataEditor, a package for Stata code. After the ST 4 update, space triggers auto-completion, which is really annoying because it prevents me from seeing the variable names that are in the lines below. I was hoping update 4143 would fix that, but it has not. Any advice on how to prevent space from triggering auto-completion? Any thoughts are appreciated.

Screenshot%202022-11-22%20144852

0 Likes

#2

I use the following plugin to prevent autocompletions after space:

import sublime
import sublime_plugin

class CompletionListener(sublime_plugin.ViewEventListener):

    def on_query_completions(self, prefix, locations):
        # suppress auto complete when typing whitespace
        if not prefix:
            return [], sublime.INHIBIT_WORD_COMPLETIONS | sublime.DYNAMIC_COMPLETIONS
1 Like

#3

Hi @jwortmann, thank you for your reply. I saved the plugin to my User folder. Unfortunately, I see no change in the behavior. space keeps triggering auto-completion.

0 Likes

#4

Ah, I see now from your screenshot that the completions are from a plugin (because they have the “Command” or “Function” annotation). The code that I posted above can only suppress Sublime’s built-in word completions from the buffer when you type a space.

Afaik there is no setting or other built-in way to prevent the autocompletion popup after whitespace in general. My only idea left for your specific problem would be to create an override for the completion plugin from the package you use, and adjust it to return no items if the “prefix” is empty/whitespace (i.e. it should work to just copy the two lines from the code above into the on_query_completions method from that plugin).

I took a quick look into the linked package and this adjustment would need to be done for each of the on_query_completions methods in https://github.com/mattiasnordin/StataEditor/blob/master/CompletionsPlugin.py.
Perhaps an enhancement request to implement such a configuration option in the package would be a better approach here.

Or if you find another solution, I’d be happy to know, because I also don’t like Sublimes autocomplete popup after space.

1 Like

#5

Hi @jwortmann, thank you for taking the time to look at the package. Unfortunately it has not been maintained since 2020. I tried to substitue every line containing return complist with the following code:

if not prefix:
	return ([], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_REORDER)
else:
	return complist

Still, auto-completion is triggered by space. I even put a print command before each return and the code reaches the print commands correctly. Could this be driven by the difference between ViewEventListener and EventListener, whatever it is? My Python skills are very limited.

0 Likes

#6

Out of curiosity, what are auto_complete_selector and auto_complete_triggers set to in files where this happens? (they can be be syntax and view specific, so view.settings().get("auto_complete_selector") and such will show you what’s in effect in files).

Off the top of my head, this can happen:

  • if a plugin makes it happen unexpectedly
  • auto_complete_selector is set such that places where you don’t want autocomplete are matched, making Sublime think that you want the popup when you don’t
  • auto_complete_triggers has been set such that it tries to trigger when you don’t expect it to.
0 Likes

#7

Here are two possible reasons why it would still not work even with your adjustments:

  1. When you deal with (View)EventListeners in a plugin, you probably need to restart Sublime Text after you have made an adjustment to the file. When saving the file, the plugin will be reloaded, but (I think) the old EventListener is still kept in memory or so and is still operating.

  2. You saved the file into the Packages/User/ folder, which means that it will not replace the file from the package. In order to actually override the package file, you need to put it into Packages/StataEditor/.

    By the way, this is a good opportunity for another recommendation (and probably receive another :heart: reaction for it :smile:) of the excellent OverrideAudit package from the user who has just answered above of this post. That package immensely helps when dealing with such overrides for package ressources, and it can notify you if the file from the original package gets updated and your override would be outdated.

1 Like

#8

Hi @OdatNurd, please see below. They look exactly as I set them in the global preferences. If I comment out both auto_complete_selector and auto_complete_triggers in the global preferences, I still have the issue.

>>> view.settings().get("auto_complete_selector")
'meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double - string.quoted.single - string.unquoted.heredoc'
>>> view.settings().get("auto_complete_triggers")
[{'characters': '<', 'selector': 'text.html, text.xml'}, {'rhs_empty': True, 'selector': 'punctuation.accessor'}, {'characters': '\\', 'selector': 'text.tex.latex'}]
0 Likes

#9

Hi @jwortmann, thank you for bringing this up.

Yes, I have also tried to restart Sublime, but there was no change in behavior.

Well, the first attempt I put the plugin in the User folder. However, in the second attempt in which I edited CompletionsPlugin.py, I put it in the StataEditor folder.

0 Likes

#10

This gave me the hint that I actually copied CompletionsPlugin.py to my User folder in the past, kept the file under a different name, and included the names of several functions and commands that are not originally in the package. If I modify this file as well, it works! Thank you so much, @jwortmann. I really appreciate it!

1 Like