Created
February 21, 2012 00:03
-
-
Save brendanjerwin/1872435 to your computer and use it in GitHub Desktop.
Source this in your .vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! CoffeeClean() | |
let save_cursor = getpos(".") | |
"general puncuation spacing cleanup | |
" | |
"Missing spaces | |
silent! %s/\v','/', '/g | |
silent! %s/\v","/", "/g | |
silent! %s/\v:(\w)(['"].*)@<!/: \1/g | |
silent! %s/\v:\@(['"].*)@<!/: @/g | |
"ensure space after = | |
silent! %s/\v\=(\S)/= \1/g | |
"Extra spaces | |
silent! %s/\v\s+\=\s+/ = /g | |
silent! %s/\v(\w)\s+,/\1,/g | |
"use single quotes for 'normal' strings, leave double quotes for | |
"interpolated strings | |
" silent! %s/"\([^#"']\+\)"/'\1'/g | |
silent! %s/""/''/g | |
"remove extra spaces around braces | |
silent! %s/ ]/]/g | |
silent! %s/\[ /[/g | |
silent! %s/( /(/g | |
silent! %s/\v(\S)\s+\)/\1)/g | |
silent! %s/\(\w\) )/\1)/g | |
"lambdas | |
" | |
"always remove a space before the rocket | |
silent! %s/) ->/)->/g | |
silent! %s/) =>/)=>/g | |
"cleanup lambdas as contained in parens. ensure a space to make it stand | |
"out | |
silent! %s/\v\(\((\w+)\)-\>/( (\1)->/g | |
silent! %s/\v\(\((\w+)\)=\>/( (\1)=>/g | |
"a parameterless lambda should always have a space in front | |
silent! %s/\v:-\>/: ->/g | |
silent! %s/\v:\=\>/: =>/g | |
"simple cleanups for common stuff | |
silent! %s/'use strict';/'use strict'/g | |
silent! %s/@$/this/ | |
call setpos('.', save_cursor) | |
endfunction | |
autocmd BufWritePre *.coffee call CoffeeClean() |
JamesMaroney
commented
Feb 21, 2012
via email
ok, I'm back at the computer now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment