Home Download Buy Blog Forum Support

Trouble with EventListener

Trouble with EventListener

Postby NeQuissimus on Fri Mar 02, 2012 10:16 pm

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 :D)
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.
NeQuissimus
 
Posts: 2
Joined: Fri Mar 02, 2012 10:05 pm

Re: Trouble with EventListener

Postby C0D312 on Fri Mar 02, 2012 10:27 pm

So I'm not crazy... I cant figure this out either. I cheated by appending the default completions with:
Code: Select all
for x in view.find_all("(?<![$])\b[a-zA-Z]+"):
            completions.append(view.substr(x))
but I would like to know a fix.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Trouble with EventListener

Postby agibsonsw on Fri Mar 02, 2012 10:45 pm

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

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

But I like the above appending 8-). 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?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Trouble with EventListener

Postby agibsonsw on Fri Mar 02, 2012 11:11 pm

Perhaps it's possible to use a timeout or a simple counter variable, to only rebuild the default file-completion list every so often.. :?:
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Trouble with EventListener

Postby C0D312 on Fri Mar 02, 2012 11:20 pm

Or
Code: Select all
if(self.view.size() > 100000)
    return []
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Trouble with EventListener

Postby agibsonsw on Fri Mar 02, 2012 11:22 pm

C0D312 wrote:Or
Code: Select all
if(self.view.size() > 100000)
    return []


Sensible ;) But.. how do I cancel my EventListener ..?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Trouble with EventListener

Postby C0D312 on Fri Mar 02, 2012 11:24 pm

What do you mean? just say if(no_longer_applicable) return []
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Trouble with EventListener

Postby agibsonsw on Sat Mar 03, 2012 1:25 am

C0D312 wrote:What do you mean? just say if(no_longer_applicable) return []


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.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Trouble with EventListener

Postby NeQuissimus on Sat Mar 03, 2012 4:29 pm

@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)
NeQuissimus
 
Posts: 2
Joined: Fri Mar 02, 2012 10:05 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 25 guests