DISQUS

Blogo Baggins: Waging War on Whitespace (using TextMate)

  • nsmgr8 · 7 months ago
    Wow!

    Is it that simple?

    I was searching for a way to do this forever. You made my day. Thank you very much!
  • chmurph2 · 7 months ago
    Glad it helped!
  • Martijn Lafeber · 3 months ago
    Thank you, this blogpost should be a compulsory read for all developers.
  • chmurph2 · 3 months ago
    Martijn,

    Couldn't agree more.

    -Chris
  • mxcl · 1 month ago
    Some stuff, like Markdown, has special meaning for trailing space. So really I'd rather have a pre-commit hook that rejects lines that just have trailing white space.

    Even better would be a pre-commit hook that removed lines from staging that are only changes in trailing whitespace.
  • chmurph2 · 1 month ago
    Agreed. I don't think TextMate offers hooks ala vm and emacs, though.
    Perhaps in version 2.
  • mxcl · 1 month ago
    Well Git itself has pre-commit hooks, although thorough integration with git into TextMate would be pretty neat. Then you could specify lines to unstage like you can with GitX.
  • chmurph2 · 1 month ago
    Right, makes sense. I like the idea of my editor handling it outside of
    source control*, though I acknowledge my solution is flawed with languages
    like Markdown. One day that'll burn me and I'll fix it in some fashion.

    -Chris

    * There is a reason why it's called "source control" though. :)
  • atmos · 1 month ago
    We call this one 'quality spec' http://gist.github.com/227332 :)
  • chmurph2 · 1 month ago
    Good idea. I may have to use something like that.
  • Steve Heffernan · 1 month ago
    In markdown, 2 trailing spaces is a line break. Any way to account for this exception?
  • chmurph2 · 1 month ago
    Off the top of my head you might consider leveraging scope selectors.

    http://manual.macromates.com/en/scope_selectors

    -Chris
  • Geoffrey Grosenbach · 1 month ago
    Emacs also has the cleanup-buffer command that not only deletes trailing whitespace but also formats your code nicely, including enforcing tabs or spaces (according to your configuration).

    Or, try whitespace-mode to see trailing whitespace displayed in ugly colors.
  • Ben Dunlap · 1 month ago
    I reflexively use the '-w' switch (ignore horizontal whitespace) when I run GNU diff from the command line. This avoids diff cruft and also avoids munging legitimate trailing whitespace. Do other diff tools typically lack this kind of an option?
  • Matt Powell · 1 month ago
    A heads-up: in TextMate, this will also unfold all your foldings if, like me, you use text-folding to stay sane when dealing with large files.
  • chmurph2 · 1 month ago
    Matt, yeah, I know.

    See my 4th footnote. :)
  • Bradley Grzesiak · 1 month ago
    Living the "leave the campsite cleaner than when you found it" motto, I manually strip whitespace (well, with a bundle command... not *actually* manually) any file when I find it. Rather than feeling like an automated process, it feels like an accomplishment.

    "ahh, *I* made this file better."
  • Moz Morris · 1 month ago
    Great post - my fellow 'Zend using' developers will be happy.
  • chmurph2 · 1 month ago
    Thanks, Moz.
  • Pierre Lemieux · 2 weeks ago
    Barebones BBEdit has a preference built-in for that.