TextMate doesn’t follow the PEP8 (Python Code Guidelines) when editing. Most of the time, it will leave spaces following the previous line indentation when the line is empty.
To solve this, you can do this:
Create a Save File Command:
- Go to “Bundles”, “Bundle Editor”, “Edit Commands”;
- Add a new command (Click on the “+” sign in the left pane);
- Change “Save” to “Current File”;
- “Input” should be “None”;
- “Output” is “Discard” (so the “Commands” doesn’t matter);
- Change the name of the Command to something meaningful.
Create a Macro:
- Go to “Bundles”, “Macros”, “Start Recording”;
- “Bundles”, “Text”, “Convert/Stripping”, “Remove Trailing Spaces in Document”;
- “Bundles”, “<Your Name> Bundle”, “<The name you chose for the previous command”;
- “Bundles”, “Macros”, “Stop Recording”;
- “Bundles”, “Macros”, “Save Last Recording”;
- Select a name for the macro;
- On the “Activation”, leave it to “Key Equivalent” and, after clicking in the empty field right next to it, Press “Command S”.
This way, when saving a file with “Command S”, it will run the “Remove Trailing Spaces Document” macro (thus removing such spaces) and save the document using the custom command (unfortunately, it doesn’t seem to work if you use the normal save command and that’s why you need to create a custom command.)