TextMate 2 bundle: Strips trailing whitespace from current document when saving. Works nicely with my Save On Focus Lost bundle. If you need whitespace highlighting, check the superb Whitespace bundle by Mads Hartmann. If you happen to need new lines at EOF, then check Mike Szyndel's Ensure New Line at the EOF bundle, which is based on mine.
- Clone the git repo to
- Relaunch TextMate 2
If you want the bundle to affect some filetypes only, it's easy.
Say you want to avoid stripping white space on CSV files.
Just open the bundle editor (Bundles menu › Edit Bundles... or pressing Ctrl + Alt + Command + B) and add
-text.tabular.csv in the Scope Selector field of the command (see attached screenshot : )
If you need to exclude multiple file types, just add
(space)-scope.namespace. For example, if you want to exclude CSV and YAML, you'd write:
If you want the bundle to work only on specific file types, use the namespace only, without the minus sign (i.e: if you want to strip CSV files only, you'd write
text.tabular.csv). If you need to include multiple file types just add them separated by comma (i.e:
text.tabular.csv, source.yaml, text.html.markdown).
If you want to know which scope corresponds to each language, just hit Ctrl + Shift + P ('Show Scope' command) on a document of that type, and you'll get a nice tooltip with the scope namespaces that apply at the current cursor's position.
You need to be using at least TextMate version 2.0.0-alpha.9317. Open Preferences » Software Update and ALT-click the "Check Now" button to get the most recent nightly build (this will grab a latest version than the one you get by just clicking the button).