Sublime Forum

Trouble with EventListener

#1

Hi,

I have written two Plugins (.py files) which seem to work just fine.
Both inherit from EventListener, and therefore show up as auto-completions.
The trouble is that as long as I keep those plugins, the word matching functionality is not working anymore.
I would expect the completions from the plugins to be added to the list of possible completions.
But somehow they seem to replace the usual list of completions (I no longer have suggestions for variables, methods, types etc.)

The .py files can be found here: (I don’t want to spam the entire code into this forum post :smiley:)
https://github.com/NeQuissimus/Sublime/blob/master/packages/NeQuissimus/mit.py
https://github.com/NeQuissimus/Sublime/blob/master/packages/NeQuissimus/package.py

Am I doing something wrong or is this the regular behaviour?
Is it either plugins or word matching?

Thank you very much.

0 Likes

#2

So I’m not crazy… I cant figure this out either. I cheated by appending the default completions with: for x in view.find_all("(?<!$])\b[a-zA-Z]+"): completions.append(view.substr(x)) but I would like to know a fix.

0 Likes

#3

[quote=“C0D312”]So I’m not crazy… I cant figure this out either. I cheated by appending the default completions with: for x in view.find_all("(?<!$])\b[a-zA-Z]+"): completions.append(view.substr(x)) but I would like to know a fix.[/quote]

This is the way I read on_query_completions to behave - we are taking responsibility for all completions.

But I like the above appending :sunglasses:. Although, I can imagine it might slow things down a bit for a large file(?). Wonder if there is a way around this…

Related question please: how do we detach an EventListener?

0 Likes

#4

Perhaps it’s possible to use a timeout or a simple counter variable, to only rebuild the default file-completion list every so often… :question:

0 Likes

#5

Or if(self.view.size() > 100000) return ]

0 Likes

#6

[quote=“C0D312”]Or if(self.view.size() > 100000) return ][/quote]

Sensible :wink: But… how do I cancel my EventListener …?

0 Likes

#7

What do you mean? just say if(no_longer_applicable) return ]

0 Likes

#8

Thank you. But I’m looking to entirely disable/detach my event-listener. My intention/hope is to dynamically attach and remove a listener.

Andy.

0 Likes

#9

@C0D312: Your solution has quite the impact on performance I would think. I do not know whether I would want to do that…
Here is how I activated/deactivated my plugins while developing them:
I have my custom package in a separate folder outside of the Sublime folder structure.
I wrote a small bash script that would create a symlink into Sublime Text/Packages when I wanted my scripts active and removed the symlink when I did not need them. But you need to reload plugins in Sublime still, for me it turned out to be the quickest to just include a kill and restart command in my bash script.
But this is far from optimal and I suppose if you are using Windows, you would have to copy your plugins around every time. I do not believe that Windows has symlinks.

But back to my question:
So it seems to be by design that a plugin replaces all suggestions? The API documentation does indeed read that way.
I am not a Python programmer but maybe it would be possible to return something like super.on_query_completions + “my completion”, “insert this”], so that we can simply append to the list? (Or add to the top of it if the statement was reversed)

0 Likes