I’ve made a modified version of the GoogleIt plugin, allowing you to specify different search options for different language scopes (for example search PHP.net for PHP file). The original GoogleIt plugin is here: googleIt - a quick way to look up code reference
[code]
#Plugin inspired and modified from googleIt - a quick way to look up code reference
import sublime
import sublime_plugin
import webbrowser
class helpItCommand(sublime_plugin.TextCommand):
"""
This will search a word in a language's documenation or google it with it's scope otherwise
"""
def run(self, edit):
if len(self.view.file_name()) > 0:
settings = sublime.load_settings('HelpIt.sublime-settings');
item = None
word = self.view.substr(self.view.word(self.view.sel()[0].begin()))
scope = self.view.scope_name(self.view.sel()[0].begin()).strip()
getlang = scope.split('.')
language = getlang-1]
if language == 'basic':
language = getlang-2]
if language == 'html': #HTML shows up A LOT for internal CSS, PHP and JS
if 'php' in getlang:
language = 'php'
elif 'js' in getlang:
language = 'js'
elif 'css' in getlang:
language = 'css'
#Map languages if needed. For example: Map .less files to .css searches
if settings.has(language):
item = settings.get(language)
if item != None and 'map' in item:
language = item'map']
sublime.status_message('helpIt invoked-- ' + 'Scope: ' + scope + \
' Word: ' + word + ' Language: ' + language)
for region in self.view.sel():
phrase = self.view.substr(region)
search = 'http://google.com/search?q='
custom = False
if item != None:
if type(item) == unicode:
search = item
custom = True
elif 'url' in item:
search = item'url']
custom = True
if not region.empty():
webbrowser.open_new_tab(search + phrase + "" if custom else " " + language)
else:
webbrowser.open_new_tab(search + word + "" if custom else " " + language)
else:
pass
def is_enabled(self):
return self.view.file_name() and len(self.view.file_name()) > 0[/code]
And the HelpIt.sublime-settings file looks like this at the moment:
{
"php" : {
"url" : "http://php.net/"
},
"less" : {
"map" : "css"
}
}
The map property allows you to make a language use the url of another or use it’s scope name in the googleIt search (I have lesscss.tmLanguage package so I’ve set it to use css in the google search). Hope this is helpful to someone (this is my first attempt at a plugin and any real python, so please excuse any stupid mistakes). Oh my key binding is Alt+F1 (from Notepad++):
{ "keys": "alt+f1"], "command": "help_it" }
Edit: Forgot to mention. If you just supply a string for a language in the options file rather than an object, it’ll use that string as the search url. A good one for HTML that I like is "“http://www.google.com/search?btnI=1&q=site:w3schools.com/html5+tag+” to search any tag within the html5 spec.