Sublime Forum

Running view.run_command against many files at once

#1

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:

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.

0 Likes

#2

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.

0 Likes