Home Web Development PHP Solution to: How do I reformat (beautify) my source code?

Get social!
There's a couple of caveats here:
  1. I'm programming (currently) in html/css/javascript/php.
  2. I'm using TextMate 2 as the text editor, along with it's remote editing capability.
When coding, I often "borrow" code snippets from various API samples (in this case the MapQuest Javascript API). Being a "pythonista" at heart, I adhere to strict formatting conventions in my coding (1 tab = 4 spaces). However, when using OPC (other people's code), the formatting can be different, or non-existent. Such was the case this time. Much of the borrowed code contained 2 or 3 spaces for each indented line. Generally offended (as I said, "pythonista"), I set to re-formatting the code. Of course, being a programmer, I wasn't going to do it by hand, I was going to find a program to do it for me. I probably should have just done it by hand.


After about 1 hour of trying online solutions (cutting and pasting a large file is a joke), command-line tools (tools like tidy didn't seem to do *anything*), and TextMate plugins, I was (almost) ready to give up. Then, just for the heck of it, I tried the "Indent Selection" menu item under "Text" in TextMate. To me, that command meant "indent all selected text 4 spaces". Wrong! Just like that all errant spaces and tabs disappeared, giving me my cherished 4-space indents throughout a file that contained html, css, javascript, and php. Nice!

Leave a Reply

Bad Behavior has blocked 58 access attempts in the last 7 days.