Fix many bugs

When textmate was first open sourced, there's a pull request removed all its code and replaced with emacs's.