Home Download Buy Blog Forum Support

Highlight method arguments in Python

Highlight method arguments in Python

Postby OstrichPolicy on Wed Dec 26, 2012 12:24 am

Hello,
I was used to editing Python with Netbeans, because it was the only editor I knew that could edit Python and even added a little support.

Some time ago, I found that Sublime Text 2 suits my needs better, so I made the step.

However, there is one thing in Netbeans that is really handy, which is the highlighting of the arguments of the method.

Image

How to change the theme of Sublime Text 2 so, that 'self', 'playerId', 'text', 'channel' and 'flags' are highlighted as well?

Regards,
Aart
P.S. I sure hope this is the right section..
OstrichPolicy
 
Posts: 3
Joined: Wed Dec 26, 2012 12:22 am

Re: Highlight method arguments in Python

Postby agibsonsw on Wed Dec 26, 2012 1:13 am

If you click into one of the parameters and press Ctrl-Alt-Shift-P you can read the scope in the status-bar. Alternatively, the ScopeHunter package is very useful.

Code: Select all
      <dict>
         <key>name</key>
         <string>Function params (Python)</string>
         <key>scope</key>
         <string>variable.parameter.function.python</string>
         <key>settings</key>
         <dict>
            <key>fontStyle</key>
            <string></string>
            <key>foreground</key>
            <string>#0AC800</string>
         </dict>
      </dict>
"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: Highlight method arguments in Python

Postby OstrichPolicy on Wed Dec 26, 2012 11:36 am

Thanks, but that's not really what I meant.

I would like it to highlight the arguments of the method INSIDE the method, so I can see what variables are given when you call the method.

So if you would call this particular method, you could do something like this:
Code: Select all
self.onChatMessage(1, "text", 5, 6)

Then, def onChatMessage would do something with that, but I would like to see which variables are given when the method is called: "self, playerId, text, channel, flags", like so:

def onChatMessage(self, playerId, text, channel, flags):
.........command, parameter = self.core.decodeChatMessage(text)
.........text = ["@" + command.lower()]
.........if parameter: text.append(parameter)
.........self.core.coreChatMessage(playerId, " ".join(text), channel, flags)

This is not only for Python, by the way, but also very handy in Java, PHP and so on.
OstrichPolicy
 
Posts: 3
Joined: Wed Dec 26, 2012 12:22 am

Re: Highlight method arguments in Python

Postby FichteFoll on Sat Dec 29, 2012 2:44 am

Should be possible but would require a Python plugin because you can't figure out which identifiers have been used in the function definition (at least not with an undefined number) using only regular expressions.

You just have to analyze the Python code (probably using the already defined scopes) and then highlight the variables manually using view.add_regions.
FichteFoll
 
Posts: 383
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: Highlight method arguments in Python

Postby OstrichPolicy on Sat Jan 05, 2013 12:28 am

Oh boy... Could you give an example?
OstrichPolicy
 
Posts: 3
Joined: Wed Dec 26, 2012 12:22 am

Re: Highlight method arguments in Python

Postby FichteFoll on Sun Jan 06, 2013 6:51 pm

Giving an example would be hard because I can either tell you which methods can be used or I can just write the whole thing. I'll try the first because that requires less time:

Thankfully, ST2 provides some nice parsing using the syntax definition from Python. You can adapt to this essentially using `view.find_by_selector`. For examples with add_region, see "BracketHighlighter" or "SublimeLinter" plugins. The code could be quite complex but their usage is really exemplary.
FichteFoll
 
Posts: 383
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany


Return to Technical Support

Who is online

Users browsing this forum: Alexa [Bot], Exabot [Bot], Google [Bot], Yahoo [Bot] and 26 guests