Open In Browser 只能使用默认浏览器打开,你可以看看它的代码:
Packages/Default/open_in_browser.py:
import sublime, sublime_plugin
import webbrowser
class OpenInBrowserCommand(sublime_plugin.TextCommand):
def run(self, edit):
if self.view.file_name():
webbrowser.open_new_tab("file://" + self.view.file_name())
def is_visible(self):
return self.view.file_name() and (self.view.file_name()[-5:] == ".html" or
self.view.file_name()[-5:] == ".HTML" or
self.view.file_name()[-4:] == ".htm" or
self.view.file_name()[-4:] == ".HTM")
你可以另外写个插件提供相应功能。
要右键菜单,需要加个 Context.sublime-menu。
查考 Packages/Default/Context.sublime-menu 的实现。
关键代码供你参考(从我某个插件抠出来的,不完整):
# 在OSX下使用Firefox打开浏览器
# browser_command = ["open", "-a", "firefox", "{url}"]
# url = "blahblahblah"
browser_command = [
os.path.expandvars(arg).format(url=url)
for arg in setting.browser_command
]
if os.name == 'nt':
# unicode arguments broken under windows
encoding = locale.getpreferredencoding()
browser_command = [arg.encode(encoding) for arg in browser_command]
subprocess.Popen(browser_command)