views:

761

answers:

2

I would like to do something like this Textmate tip, so that trailing whitespace are always highlighted in some way when I code something in Python - it makes it easier to correct it immediately and other editors such as Emacs can do it.

Unfortunately the discussion after that post seems to suggest it's difficult to do. For me the invalid.trailing-whitespace scope selector is not even visible in the preferences after following this tip. Has anyone else had any success with this?

+3  A: 

I don't know how to highlight the trailing space but you can remove it by going to

Bundles -> Text -> Converting/Stripping -> Remove trailing spaces in document

Also, because textmate has emacs bindings, you may be able to do it the same way you would do it in emacs.

jimiyash
Works great! I assigned that bundle action to ^S, and changed the save action from "Nothing" to "Current File". So now if I hit ^S, whitespaces are stripped before the file is saved to disk.
pojo
+4  A: 

This code works (but not with comment) :

{   scopeName = 'source.whitespace';
    patterns = (
        {  name = 'source.invalid.trailing-whitespace';
            match = '(\s+)$';
            captures = { 1 = { name = 'invalid.trailing-whitespace'; }; };
         },
    );
}

PS: I have changed "source" to "source.whitespace"

For comment change in Python grammar :

{  name = 'comment.line.number-sign.python';
   match = '(#).*$\n?';
   captures = { 1 = { name = 'punctuation.definition.comment.python'; }; };
},

In:

{  name = 'comment.line.number-sign.python';
   match = '(#).*(\s+)$\n?';
   captures = { 
     1 = { name = 'punctuation.definition.comment.python'; }; 
     2 = { name = 'invalid.trailing-whitespace';  }; 
   };
},
ppierre
Thank you! This worked great.
pojo
You can also use :http://github.com/ppierre/python-pep8-tmbundle
ppierre