if ( 'prettyPrint' in window ) {} else {
    document.write( '<script type="text/javascript" src="http://gist-it.appspot.com/assets/prettify/prettify.js"></script>' );
}
document.write( '<link rel="stylesheet" href="http://gist-it.appspot.com/assets/embed.css"/>' );
document.write( '<link rel="stylesheet" href="http://gist-it.appspot.com/assets/prettify/prettify.css"/>' );
document.write( '<div class="gister-gist">\n<div class="gist-file">\n    <div class="gist-data">\n        <pre class="prettyprint">import os\nimport sublime\nimport sublime_plugin\n\n\nclass WhitespaceListener(sublime_plugin.EventListener):\n    """Event listener to manage whitespace on save"""\n    def on_pre_save(self, view):\n        if view.settings().get(\'expand_tabs_on_save\') == True:\n            view.run_command(\'expand_tabs\')\n        if view.settings().get(\'trim_trailing_whitespace_on_save\') == True:\n            view.run_command(\'trim_trailing_whitespace\')\n        if view.settings().get(\'ensure_newline_at_eof_on_save\') == True:\n            view.run_command(\'ensure_newline_at_eof\')\n\n\nclass TrimTrailingWhitespace(sublime_plugin.TextCommand):\n    """Trims trailing whitespace."""\n    def run(self, *args):\n        trailing_white_space = self.view.find_all("[\\t ]+$")\n        edit = self.view.begin_edit()\n        for match in trailing_white_space:\n            self.view.erase(edit, match)\n        self.view.end_edit(edit)\n\n\nclass EnsureNewlineAtEof(sublime_plugin.TextCommand):\n    """Ensures the desired number of trailing new lines.\n\n    Set \'max_newline_removals\' to the number of newlines to be removed (\'\n    a performance/sanity check.\')\n\n    Set \'trailing_newlines\' to the number of desired newlines at the end of\n    the file.\n    """\n    def run(self, *args):\n        # Remove up to *max_newline_removals* trailing new lines.\n        max_removals = self.view.settings().get(\'max_newline_removals\', 20)\n        edit = self.view.begin_edit()\n        for i in range(max_removals):\n            size = self.view.size()\n            last_line = self.view.full_line(size - 1)\n            if size &gt; 0 and self.view.substr(last_line) == \'\\n\':\n                self.view.erase(edit, last_line)\n\n        # Add desired trailing newlines\n        trailing_newlines = self.view.settings().get(\'trailing_newlines\', 1)\n        for i in range(trailing_newlines):\n            if not self.view.substr(last_line).endswith(\'\\n\'):\n                self.view.insert(edit, self.view.size(), \'\\n\')\n        self.view.end_edit(edit)\n</pre>\n    </div>\n    <div class="gist-meta">\n        <span><a href="https://github.com/nstielau/Sublime-Text-2-Plugins/blob/master/whitespace.py">This Gist</a> by <a href="http://gist-it.appspot.com">gist-it</a></span>\n        <span style="float: right; color: #369;"><a href="https://github.com/nstielau/Sublime-Text-2-Plugins/raw/master/whitespace.py">view raw</a></span>\n        <span style="float: right; margin-right: 8px;">\n            <a style="color: rgb(102, 102, 102);" href="https://github.com/nstielau/Sublime-Text-2-Plugins/blob/master/whitespace.py">whitespace.py</a></span>\n            <!-- Generated by: http://gist-it.appspot.com -->\n    </div>\n</div>\n</div>' );
document.write( '<script type="text/javascript">prettyPrint();</script>' );
