Home Download Buy Blog Forum Support

Paste Method

Paste Method

Postby C0D312 on Fri Nov 11, 2011 4:41 am

One of the things I missed about using an IDE is that I can easily see all the available functions to an Object. Then I discovered how powerful Goto Anything is... So I built my very first plugin which opens goto anything, filled with the class of whatever object you have selected. (Only works with Java at the moment)

example:
Code: Select all
MyClass obj;
obj|

press ctrl+r (super+r on OSX), goto anything opens with:
Code: Select all
MyClass@

This way, all my class methods are displayed...
So here's the question. Is there anyway to make a plugin that when I press enter, it copies the function name, escapes the overlap panel, and pastes function name in the window?

Thanks for any help.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Paste Method

Postby facelessuser on Fri Nov 11, 2011 5:48 am

Probably, what do you mean overlap panel? Do you have a clip of code where you invoke said overlap panel? I am not exactly sure what you mean. If you mean quick panel, then yes, you can give it a callback, and it will return the index of the item selected, since you populate it, you should also know the index.

I would really need more info, or see the code to be more help.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: Paste Method

Postby C0D312 on Fri Nov 11, 2011 12:37 pm

By overlap panel, I meant the Goto anything panel.

I was a bit reluctant to show my code because its my first plugin and its a pretty shitty attempt at python. BTW, I really suck at regex, so any help there is really appreciated. Thanks for your help.

Here's the plugin: https://github.com/BoundInCode/Function-Copier
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Paste Method

Postby spadgos on Fri Nov 11, 2011 1:02 pm

I've added some comments on your initial commit, I hope they're helpful!
spadgos
 
Posts: 121
Joined: Thu Oct 06, 2011 12:49 am

Re: Paste Method

Postby C0D312 on Fri Nov 11, 2011 1:34 pm

Thanks. I made those corrections.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Paste Method

Postby facelessuser on Fri Nov 11, 2011 3:04 pm

Don't feel bad. If I withheld my code every time I thought it was crappy, I would never let it out of my hands. :)

One suggestion, run SublimeLinter on your code.

Now, your question: The problem is, I don't think the "goto" panel has callbacks or any real way to access what it selects. It is designed with the purpose of "going to" ; I don't think it was designed to be used out of context.

I would personally ask jps if he could provide a method to retrieve goto anything results via the api without calling a goto panel, or ask if this already exists hidden somewhere. I just don't have enough experience with the api to tell you if it already exists, but I suspect it doesn't.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: Paste Method

Postby C0D312 on Sat Nov 12, 2011 1:23 am

So a decided that it might be more straightforward if I use the auto_complete api instead of the Goto anything.

So the plugin should:
1. find the object type (done)
2. Find all methods of that class (check for: entity.name.function)
3. Populate the auto_complete with all the methods. (?????)
4. Open auto_complete (view.run_command('auto_complete', {'disable_auto_insert': True}))

Before I embark, I have a question. How do I populate the auto_complete list? I've been scanning the codeintel plugin for clues but it's just a big puzzle...
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Paste Method

Postby ask on Sat Nov 12, 2011 2:12 am

C0D312 wrote:...
How do I populate the auto_complete list? ...


I believe, you can do it like this:
sublime_plugin.EventListener -> on_query_completions -> return [(x, x) for x in your_list]
ask
 
Posts: 26
Joined: Wed Sep 14, 2011 12:40 pm

Re: Paste Method

Postby facelessuser on Sat Nov 12, 2011 3:18 pm

Yeah, I think ask is on the right path. I haven't tried to do this specifically yet with the api, so my knowledge is limited on this topic, but I think this is the way you need to go from looking at CodeIntel.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm


Return to Plugin Development

Who is online

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