forked from ehamiter/Sublime-Text-2-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleIt.py
33 lines (28 loc) · 1.25 KB
/
googleIt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sublime
import sublime_plugin
import webbrowser
class googleItCommand(sublime_plugin.TextCommand):
"""
This will search a word or a selection coupled with the file's
scope. Default binding recommendation: "ctrl + alt + forward_slash"
"""
def run(self, edit):
if len(self.view.file_name()) > 0:
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]
sublime.status_message('googleIt invoked-- ' + 'Scope: ' + scope + \
' Word: ' + word + ' Language: ' + language)
for region in self.view.sel():
phrase = self.view.substr(region)
search = 'http://google.com/search?q='
# Feeling lucky? Use 'http://google.com/search?btnI=1&q=' instead
if not region.empty():
webbrowser.open_new_tab(search + phrase + " " + language)
else:
webbrowser.open_new_tab(search + word + " " + language)
else:
pass
def is_enabled(self):
return self.view.file_name() and len(self.view.file_name()) > 0