Home Download Buy Blog Forum Support

Java Script formatting plugin, need your help

Java Script formatting plugin, need your help

Postby select on Thu Mar 07, 2013 6:22 pm

Hey there,
since I am going to work alot with Java Script now I wanted a plugin for Java Script text auto formatting, similar to auto pep8. The plugins I found were a old and not configurable so I used what was there and improved it.
Here is the result: https://github.com/select/sublime-text-jsbeautifier
But wait I still have some issues to solve before I can submit it to the plugin manager

1) When I re-format just one line jsbeautifier takes away the original indentation. I guess this is because it was meant for formating whole files. Any hints on how to get back the leading tabs/spaces?

2) I am not sure how to parse user preferences or if I even have to. Any hints?
select
 
Posts: 5
Joined: Thu Mar 07, 2013 6:09 pm

Re: Java Script formatting plugin, need your help

Postby select on Thu Mar 07, 2013 6:25 pm

Oh and another issue is that this plugin so far executes on all files not just java script files. Another issue I could need some hints on how to restrict it to js files only.
select
 
Posts: 5
Joined: Thu Mar 07, 2013 6:09 pm

Re: Java Script formatting plugin, need your help

Postby skuroda on Thu Mar 07, 2013 7:06 pm

Haven't looked at the code so the following is just speculation.

1. You would have to modify the command to handle single line inputs before formatting.

2. You would do something like sublime.load_settings("JsFormat.sublime-settings"). This will return a settings object.

3. You can use something like view.settings().get("syntax") to find out what syntax is being used. You can also view.file_name() to get the name of the file and check for the .js extension.

4. Welly ou don't have a fourth point but wanted to ask this. Have you looked at JsFormat? I believe it uses the same library, and is actively maintained. It may already have some of the features you are looking for.
skuroda
 
Posts: 688
Joined: Fri Oct 05, 2012 8:11 am

Re: Java Script formatting plugin, need your help

Postby select on Thu Mar 07, 2013 7:46 pm

ha should have asked before starting to work
but I just could not find JsFormat :(
select
 
Posts: 5
Joined: Thu Mar 07, 2013 6:09 pm

Re: Java Script formatting plugin, need your help

Postby select on Thu Mar 07, 2013 7:57 pm

anyway thanks alot for the help and I learned quite a bit on how easy it is to write sublime plugins :)
select
 
Posts: 5
Joined: Thu Mar 07, 2013 6:09 pm

Re: Java Script formatting plugin, need your help

Postby Varemenos on Sat Mar 09, 2013 11:50 pm

Why don't you include css-beautifier and html-beautifier from the same jsbeatifier's project as well? (they are included and function almost the same)
Varemenos
 
Posts: 5
Joined: Sat Mar 17, 2012 3:37 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests