Home Download Buy Blog Forum Support

Sublime Text 2 Open in Browser

Re: Sublime Text 2 Open in Browser

Postby neotoxic on Wed Jul 20, 2011 2:08 pm

Ah that worked, thank you.

So the code posted by jbrooksuk is not needed?
neotoxic
 
Posts: 6
Joined: Sat Dec 26, 2009 10:56 am

Re: Sublime Text 2 Open in Browser

Postby bizoo on Wed Jul 20, 2011 2:19 pm

neotoxic wrote:Ah that worked, thank you.

So the code posted by jbrooksuk is not needed?

Yes it is.
open_browser is not an internal command so you need the plugin for it.
bizoo
 
Posts: 886
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Sublime Text 2 Open in Browser

Postby neotoxic on Wed Jul 20, 2011 4:06 pm

Ah cool, I was trying to understand how the plugin was working. I can understand that the console command that is being run buy this code is called 'open_browser'

Code: Select all
view.run_command('open_browser')

But I was expecting to see the name of that command name 'open_browser' in the plugin code somewhere.

Code: Select all
import sublime, sublime_plugin
import webbrowser

class OpenBrowserCommand(sublime_plugin.TextCommand):
   def run(self,edit):
      url = self.view.file_name()
      webbrowser.open_new(self.view.file_name())

How dose open_browser relate to the plugin class OpenBrowserCommand
neotoxic
 
Posts: 6
Joined: Sat Dec 26, 2009 10:56 am

Re: Sublime Text 2 Open in Browser

Postby guillermooo on Wed Jul 20, 2011 4:28 pm

guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Sublime Text 2 Open in Browser

Postby neotoxic on Thu Jul 21, 2011 8:30 pm

That's great, thank you for taking the time to post this link, I shall have a read.
neotoxic
 
Posts: 6
Joined: Sat Dec 26, 2009 10:56 am

Re: Sublime Text 2 Open in Browser

Postby krungthepmaha on Thu Sep 08, 2011 3:40 pm

I have pretty good luck using the below. Note: I use this on windows. This will open all files in sublime into firefox or you can change out your preferred browser.

Code: Select all
import sublime, sublime_plugin
import subprocess

class OpenBrowserCommand(sublime_plugin.TextCommand):
   def run(self,edit):
      subprocess.call([r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe', '-new-tab', self.view.file_name()])
krungthepmaha
 
Posts: 1
Joined: Thu Sep 08, 2011 3:38 pm

Re: Sublime Text 2 Open in Browser

Postby nicktheandroid on Sun Oct 23, 2011 12:41 am

I apologize, i'm a super noob, to create this plugin in ST2 I would go to Tools > New Plugin, then I would select all and paste this code:

Code: Select all
import sublime, sublime_plugin
import webbrowser

class OpenBrowserCommand(sublime_plugin.TextCommand):
   def run(self,edit):
      url = self.view.file_name()
      webbrowser.open_new(self.view.file_name())


Then I would save it under the default User folder it opens when I press ctrl-S.
After that, how would I launch it with a keyboard shortcut, again, i apologize for my noobness.
nicktheandroid
 
Posts: 16
Joined: Tue Feb 08, 2011 5:33 pm

Re: Sublime Text 2 Open in Browser

Postby C0D312 on Sun Oct 23, 2011 1:40 am

@nicktheandroid,

To assign any action to a key binding, look in your "Preferences > Default Key Bindings" or "Preferences > User Key Bindings." This is where all of your key bindings are. For open in browser, add this to your "user key bindings":
Code: Select all
{ "keys": ["super+shift+b"], "command": "open_browser" }


btw: you can very quickly get to your key binding files using the command palette
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Sublime Text 2 Open in Browser

Postby jeremyScott on Fri Mar 16, 2012 2:17 pm

C0D312 wrote:
Code: Select all
{ "keys": ["super+shift+b"], "command": "open_browser" }


Trying to get this to work. I've added other keybindings but this one isn't opening a browser.
Is there some other setting I'm missing? I'm using ST2 2181
jeremyScott
 
Posts: 6
Joined: Thu Feb 23, 2012 5:08 pm

Re: Sublime Text 2 Open in Browser

Postby Varemenos on Sat Mar 17, 2012 3:39 pm

Code: Select all
import sublime, sublime_plugin
import subprocess

class OpenBrowserCommand(sublime_plugin.TextCommand):
   def run(self,edit):
      subprocess.call([r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe', '-new-tab', self.view.file_name()])


Im using this code mentioned previous, but it will open the file in the browser with file:/// is there a way to change it to http://localhost/?
Varemenos
 
Posts: 5
Joined: Sat Mar 17, 2012 3:37 pm

PreviousNext

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], movax and 30 guests