Whitespace rework to produce consistent layout using 4-space indentation. Copy of #132

This is a duplicate of pull-request #132, except being against the dev branch.


Note: The real changes are +108 -68 if you ignore whitespace (and compare against my [other](https://github.com/emoncms/emoncms/pull/133) pull request. (and that's mostly minor format tweaking, a few additional comments (TODO, etc...) and a few cases where github's diff isn't working properly), or +840  −167 if you don't include my other pull request.

Apparently you can add `?w=1` to the end of a github pull request or comparison to get only the non-whitespace changes. [Whitespace ignoring diff](https://github.com/emoncms/emoncms/pull/134?w=1)