Home Download Buy Blog Forum Support

V8 Engine for sublime text 2 - writing your plugin use JS

V8 Engine for sublime text 2 - writing your plugin use JS

Postby akira on Thu Jan 19, 2012 3:49 am

Hi

I compiled the Google V8 engine and PyV8 (https://github.com/okoye/PyV8) under the windows 32bit and the mac osx, build pyv8 as a plugin of sublime text 2.

Added a realtime syntax checking & jshint on js file
Added a javascript console like the python one
Wrote an example (test.js) shows how to writing your own plugin use JavaScript

You can download it here:

sublime-v8 for win32 - https://github.com/akira-cn/sublime-v8-win32
sublime-v8 for osx - https://github.com/akira-cn/sublime-v8-osx

enjoy~ :-)
akira
 
Posts: 7
Joined: Thu Jan 19, 2012 3:34 am

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby facelessuser on Thu Jan 19, 2012 4:11 am

Interesting idea.

Doesn't seem to work on mac.

Code: Select all
Traceback (most recent call last):
  File "./sublime_plugin.py", line 110, in create_window_commands
  File "./jshint.py", line 15, in __init__
IOError: [Errno 2] No such file or directory: 'jshint.js'


Also ctrl+alt+j does not bring up a console.
facelessuser
 
Posts: 1541
Joined: Tue Apr 05, 2011 7:38 pm

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby facelessuser on Thu Jan 19, 2012 4:35 am

I fixed the "no such file or directory" error.

in jshint.py
Code: Select all
   def __init__(self, window):
      self.panel = window.get_output_panel(JSHINT_VIEW_NAME)
      self.panel.set_name(JSHINT_VIEW_NAME)
      self.window = window
      ctx = PyV8.JSContext()
      ctx.enter()
      jshint_file = file(os.path.join(sublime.packages_path(),"sublime-v8-osx", "jshint.js"))
      source = jshint_file.read()
      self.jshint = ctx.eval(source)
      jshint_file.close()   


You need to run all of your python code through something like SublimeLinter. It would also be very helpful to be very consistant with tabs vs spaces. It is really hard to look at.

After I fixed this, it appears your plist for the console theme is borked as well.
facelessuser
 
Posts: 1541
Joined: Tue Apr 05, 2011 7:38 pm

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby akira on Thu Jan 19, 2012 4:47 am

Sorry, I set the wrong file path.

Now, the bug had been fixed.

https://github.com/akira-cn/sublime-v8-osx/commit/c1929851dda2b118cd55d7039c7bb3ca962dc2fb

thanks
akira
 
Posts: 7
Joined: Thu Jan 19, 2012 3:34 am

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby facelessuser on Thu Jan 19, 2012 4:51 am

Nice!

Seems to be working.

JS console is also now working. Not sure how I would use this yet, but I find it a pretty neat plugin.
facelessuser
 
Posts: 1541
Joined: Tue Apr 05, 2011 7:38 pm

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby tanepiper on Thu Jan 19, 2012 9:45 am

+1 for awesome! I might be able to make this a dependancy for my nodejs plugin to start doing some more debug features!

Thanks for the hard work
tanepiper
 
Posts: 68
Joined: Sun Nov 06, 2011 6:40 am

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby sublimator on Thu Jan 19, 2012 9:50 am

This sounds freaking awesome!
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 648
Joined: Thu Mar 20, 2008 5:41 am

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby tanepiper on Thu Jan 19, 2012 9:50 am

In the JS console I've noticed you don't output loops fully: http://screencast.com/t/fOrXQdO7iz

In a loop it's just outputting the last item (this is on MacOSX version, on 10.7.2 with the latest ST2 dev version)
tanepiper
 
Posts: 68
Joined: Sun Nov 06, 2011 6:40 am

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby sublimator on Thu Jan 19, 2012 10:42 am

facelessuser wrote:Not sure how I would use this yet, but I find it a pretty neat plugin.


V8 is just the javascript engine yeah? Anyway, another colour on the palette :)

Dunno if I'd ever use javascript for plugins but I reckon avoiding subprocess for javascript linting is worth the fuss.

For a console I'd prefer some sort of browser integration. Only real context I'd want to evaluate javascript in.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 648
Joined: Thu Mar 20, 2008 5:41 am

Re: V8 Engine for sublime text 2 - writing your plugin use JS

Postby akira on Thu Jan 19, 2012 11:01 am

I've fixed this bug in the windows version:
https://github.com/akira-cn/sublime-v8-win32/commit/4c2b8ec177cffa15cad67ca1314f55252133b0a6

I think it'll work fine at osx version as well
Since I cann't tested in my macbook just now. I'll update it later :-)

thanks~


tanepiper wrote:In the JS console I've noticed you don't output loops fully: http://screencast.com/t/fOrXQdO7iz

In a loop it's just outputting the last item (this is on MacOSX version, on 10.7.2 with the latest ST2 dev version)


updated

https://github.com/akira-cn/sublime-v8-osx/commit/3fc67de3a1e90be4f9675284630c83b55e47e6f9
akira
 
Posts: 7
Joined: Thu Jan 19, 2012 3:34 am

Next

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 11 guests