Sublime Forum

Auto Complete within Snippets Failure, followed by Sporadic Auto Complete Failure

#1

Auto complete has stopped working within a snippet. I haven’t changed ST3 in anyway (or any snippetts since this behaviour).
Also I’ve not put into effect any of the changes that were suggested in my last couple of posts.
I get the same behaviour in freshly installed state as well as rebooting, restarting both program and machine.

Auto complete works outside of a snippet sometimes, but if I use a snippet auto complete will work in one snippet and then cease to work at all. Things that have been working for four months or so, have just stopped working.

In summary, when ST3 starts up I can use auto-complete 1 time in a snippett, then not at all until reboot etc. Sometimes (and this appears to be random) auto complete doesn’t work outside of a snippet either.
(Auto complete doesn’t work in both user defined snippets and the default ones that came with ST3)

I’ve been using ST3 for about 9 months (ha) and this is a new behaviour and as far as I understand it is not expected. Really annoying to have this functionality just disappear. Crumbs !

(sorry to be a bit grumpy, it’s just 40 mins or so down the pan, checking when and where it does and doesn’t work so I can write this post. These things always happen at a bad time…)

Can anyone help me please ?

Lozminda

0 Likes

#2

I had a flash of inspiration, though once again it’s a kind of work around, and I’m kinda still back at square one…

"auto_complete_commit_on_tab": true,

I’ve commented out the above setting, I now have auto-complete working in snippets. However the behaviour I want is

a) “auto_complete_commit_on_tab”: true

b) auto complete to work in a snippet

c) then I’d like to swap what return and tab do in auto complete, so that within auto-complete, when I press Enter I select the auto-complete option, and when I press Tab I get a new line. Having both do the same means that it’s a pain to have a newline if that’s what you want rather than an auto-completion.

Any help much appreciated (as always) as I’m currently back to square 1

Lozminda

Ps I tried

	{ "keys": ["tab"], "command": "noop", "context":
  [
  	{ "key": "auto_complete_visible" },
  	{ "key": "setting.auto_complete_commit_on_tab" }
  ]

},

But that doesn’t work…

0 Likes

#3

I’d like to swap what return and tab do in auto complete, so that within auto-complete, when I press Enter I select the auto-complete option, and when I press Tab I get a new line. Having both do the same means that it’s a pain to have a newline if that’s what you want rather than an auto-completion.

Any help much appreciated (as always) as I’m currently back to square 1

Lozminda

Ps I can’t have "auto_complete_commit_on_tab": true, because that seems to cause more auto-complete not to work in snippets. Also I tried

{ "keys": ["tab"], "command": "noop", "context":
  [
  	{ "key": "auto_complete_visible" },
  	{ "key": "setting.auto_complete_commit_on_tab" }
  ]
}

But that doesn’t work…
0 Likes

#4

If you want Tab to insert a newline while the autocomplete panel is open, you need to bind it to the insert command with an argument that tells it to insert a newline:

    { "keys": ["tab"], "command": "insert", "args": {"characters": "\n"} ,
      "context": [
        { "key": "auto_complete_visible" },
       ],
    },

I don’t think you need the second part of the context; that would only make the key apply when auto_complete_commit_on_tab is turned on, which would have the effect of blocking being able to choose any item at all.

If anything, you could use an additional context like this one, to reverse the state of the check so that the binding only applies when the option it turned off (such that if the option is turned on, the binding no longer applies and Tab will commit the completion for you).

{ "key": "setting.auto_complete_commit_on_tab", "operator": "equal", "operand": false },
1 Like

#5

I’ll get back to this one, I’m off to the pub for last orders. I’ll have for you !

Drat, pub closed early due to covid… However this means I can get back to ST3.

  { "keys": ["tab"], "command": "insert", "args": {"characters": "\n"} ,
      "context": [
        { "key": "auto_complete_visible" },
       ],
    },

seems to work perfectly. Just to be crystal clear for other noobs (like me):

do you mean

    { "keys": ["tab"], "command": "insert", "args": {"characters": "\n"} ,
      "context": [
       { "key": "setting.auto_complete_commit_on_tab", "operator": "equal", "operand": false },
       ],
    },

or having a double key ?

0 Likes

#6

You’d want two contexts here if you want to include this one as well. When a key binding contains context entries, all of them have to evaluate out to a “True” result for the binding to be considered. If any contexts don’t apply, that binding is skipped and Sublime looks for another one on the same key that applies better.

So, in this case you always want to at least have the context for auto_complete_visible, otherwise the Tab key will insert a Newline when you don’t want it to.

The second one is a sanity filter that would disable the binding if you ever turned off the setting.

I have a video that discusses key contexts, how they’re set up and how Sublime uses them as well (also this week’s video was about creating your own from scratch in a plugin):

0 Likes

#7

Awesome ! Awesome ! (must be at least 10 chars) :yum:

0 Likes