The source code for the Mozilla Add-ons project tries to follow the PEAR Coding Standards. One of these standards is to use 4 spaces per level of indentation, and no tabs.

Over time, unfortunately, some files start to contain a significant amount of mixed-up indentation (both from badly set-up IDEs and third-party contributions that came with tab indentation but went un-noticed). That's both tedious and error-prone to fix by hand.

A similar problem poses trailing whitespace. While it's just annoying in general, especially in HTML template files, it also increases page size unnecessarily by leading to more bytes transmitted on the wire, with no benefit to neither the users nor the developers.

Luckily, there are two quick fixes for these problems in both the editor vim and my IDE of choice, Komodo:

To remove tabs and replace them with spaces...

  • in Komodo, select a code block, then click Code -> Untabify Region.
  • in vim, type :%s/\t/    /g (those are four spaces) -- or, as oremj points out in the comments, you could just to :retab .

And to wipe out trailing whitespace...

  • in Komodo, in Preferences -> Editor / Save Options, activate the option "Clean trailing whitespace and EOL markers". Then open your document of choice and just save it again. However, when writing patches, you might want to refrain from keeping this option on at all times: It might result in confusion if a lot of lines are touched that do not have anything to do with the current patch. I wish there was a one-time way to run this, instead of a config option.
  • in vim, type :%s/\s+$//g which the regex-savvy among you have quickly decyphered as: "in the entire document, replace all one or more whitespace characters that are followed by a line ending with the empty string".

Happy cleaning!

Was this helpful? Buy me a coffee with Bitcoin! (What is this?)

Updating Adobe Flash Without Restarting Firefox

No reason for a Flash upgrade to shut down your entire browser, even if it claims so.It's 2015, and the love-hate relationship of the Web...… Continue reading

Reddit's Fail-Alien (or "Fail-ien?")

Published on January 15, 2015