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() |
Author
brendanjerwin
commented
Feb 21, 2012
via email
:) here too
…On Feb 20, 2012, at 7:36 PM, JamesMaroney wrote:
In a bit. Starting bedtime routine now.
On Feb 20, 2012 7:34 PM, "Brendan Erwin" <
***@***.***>
wrote:
> Yeah, I'm hacking on it right now.
>
> have time to play with it with me?
>
> On Feb 20, 2012, at 7:33 PM, JamesMaroney wrote:
>
> > We should note the intent of each of these in some comments.
> > Are we sure that line 8 is working?
> > ---
> >
> > Reply to this email directly or view it on GitHub:
> > https://gist.github.com/1872435
> ---
>
> Reply to this email directly or view it on GitHub:
> https://gist.github.com/1872435
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1872435
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