Skip to content

Commit 5bf2e4e

Browse files
Ryan P. C. McQuenfarcaller
Ryan P. C. McQuen
authored andcommitted
Factor out Dash opening code so that searching is cross platform. (#67)
1 parent a5be185 commit 5bf2e4e

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

DashDoc.py

+39-18
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,42 @@ def docset_keys(view, syntax_docset_map):
2525
return []
2626

2727

28+
def open_dash(query, keys, run_in_background)
29+
# background
30+
background_string = '&prevent_activation=true' if run_in_background else ''
31+
32+
if platform.system() == 'Windows':
33+
# sending keys=<nothing> confuses some Windows doc viewers
34+
if keys:
35+
# ampersand must be escaped and ^ is the Windows shell escape char
36+
url = 'dash-plugin://keys=%s^&query=%s%s' % (','.join(keys), quote(query), background_string)
37+
else:
38+
url = 'dash-plugin://query=%s%s' % (quote(query), background_string)
39+
subprocess.call(['start', url], shell=True)
40+
elif platform.system() == 'Linux':
41+
if keys:
42+
subprocess.call([
43+
'/usr/bin/xdg-open',
44+
'dash-plugin:keys=%s&query=%s%s' % (','.join(keys), quote(query), background_string)
45+
])
46+
else:
47+
subprocess.call([
48+
'/usr/bin/xdg-open',
49+
'dash-plugin:query=%s%s' % (quote(query), background_string)
50+
])
51+
else:
52+
if keys:
53+
subprocess.call([
54+
'/usr/bin/open', '-g',
55+
'dash-plugin://keys=%s&query=%s%s' % (','.join(keys), quote(query), background_string)
56+
])
57+
else:
58+
subprocess.call([
59+
'/usr/bin/open', '-g',
60+
'dash-plugin://query=%s%s' % (quote(query), background_string)
61+
])
62+
63+
2864
class DashDocCommand(sublime_plugin.TextCommand):
2965
def run(self, edit, flip_syntax_sensitive=False, run_in_background=False):
3066
# read global and (project-specific) local settings
@@ -51,23 +87,8 @@ def run(self, edit, flip_syntax_sensitive=False, run_in_background=False):
5187
syntax_sensitive = flip_syntax_sensitive ^ syntax_sensitive_as_default
5288
keys = docset_keys(self.view, syntax_docset_map) if syntax_sensitive else []
5389

54-
# background
55-
background_string = '&prevent_activation=true' if run_in_background else ''
56-
57-
if platform.system() == 'Windows':
58-
# sending keys=<nothing> confuses some Windows doc viewers
59-
if keys:
60-
# ampersand must be escaped and ^ is the Windows shell escape char
61-
url = 'dash-plugin://keys=%s^&query=%s%s' % (','.join(keys), quote(query), background_string)
62-
else:
63-
url = 'dash-plugin://query=%s%s' % (quote(query), background_string)
64-
subprocess.call(['start', url], shell=True)
65-
elif platform.system() == 'Linux':
66-
subprocess.call(['/usr/bin/xdg-open',
67-
'dash-plugin:keys=%s&query=%s%s' % (','.join(keys), quote(query), background_string)])
68-
else:
69-
subprocess.call(['/usr/bin/open', '-g',
70-
'dash-plugin://keys=%s&query=%s%s' % (','.join(keys), quote(query), background_string)])
90+
open_dash(query, keys, run_in_background)
91+
7192

7293
class DashDocSearchCommand(sublime_plugin.WindowCommand):
7394
def run(self):
@@ -80,4 +101,4 @@ def on_cancel(self, name):
80101
pass
81102

82103
def on_done(self, topic):
83-
subprocess.call(["open", "dash-plugin://query=" + quote(topic)])
104+
open_dash(topic, [], False)

0 commit comments

Comments
 (0)