Home Download Buy Blog Forum Support

Running view.run_command against many files at once

Running view.run_command against many files at once

Postby alavers on Mon Mar 18, 2013 4:50 pm

I've inherited a javascript code base that has mixed space intentation widths. I've specified tab_size 4 and translate_tabs_to_spaces true in the project file, and I'd like to normalize everything to silence the linter, and do it all at once to avoid polluting the code history with whitespace changes.

For an individual file I have the following console commands that do the trick:

Code: Select all
view.run_command("unexpand_tabs");view.run_command("set_setting", {"setting": "tab_size", "value": 4} );view.run_command("expand_tabs")


I'd like to do this programmatically across many files, not just the one open in the buffer. Is there a simple way to do this?

EDIT: I suppose I can just import os to iterate over files in a directory, so my specific question is how to do something like the run_command() above upon a file path instead of the current view.
alavers
 
Posts: 1
Joined: Mon Mar 18, 2013 4:01 pm

Re: Running view.run_command against many files at once

Postby skuroda on Wed Mar 20, 2013 2:42 am

You would probably be better off just using a script to do this rather than trying to do it in Sublime Text. If you insist on doing it in ST, you can use a window.folders() to get paths in the current window. You can then use os.walk to open the file in sublime (thus creating a view), then run the command. Again though, this probably isn't the best way to do it.
skuroda
 
Posts: 673
Joined: Fri Oct 05, 2012 8:11 am


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 16 guests