Open In Browser 只能使用默認(rèn)瀏覽器打開,你可以看看它的代碼:
Packages/Default/open_in_browser.py:
import sublime, sublime_plugin
import webbrowserclass 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")
你可以另外寫個(gè)插件提供相應(yīng)功能。
要右鍵菜單,需要加個(gè) Context.sublime-menu。
查考 Packages/Default/Context.sublime-menu 的實(shí)現(xiàn)。
關(guān)鍵代碼供你參考(從我某個(gè)插件摳出來(lái)的,不完整):
# 在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)