Created
July 21, 2010 07:01
-
-
Save hotoo/484171 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| --- C:/Documents and Settings/wb-tianliang/My Documents/下载/csspretty.vim Wed Jul 21 14:25:29 2010 | |
| +++ D:/Vim/vimfiles/ftplugin/css/csspretty.vim Wed Jul 21 14:59:04 2010 | |
| @@ -30,7 +30,7 @@ | |
| " generates whitespace | |
| function! Whitespace(indent) | |
| - let tabstop = 3 | |
| + let tabstop = &ts | |
| return repeat(' ', a:indent * tabstop) | |
| endfunction | |
| @@ -99,8 +99,11 @@ | |
| let declarations = [] | |
| for o in split(contents, ';') | |
| - let property = Trim(split(o, ':')[0]) | |
| - let value = Trim(split(o, ':')[1]) | |
| + " let property = Trim(split(o, ':')[0]) | |
| + " let value = Trim(split(o, ':')[1]) | |
| + let colonIndex = stridx(o, ':') | |
| + let property = Trim(strpart(o, 0, colonIndex)) | |
| + let value = Trim(strpart(o, colonIndex+1)) | |
| call add(declarations, {'property': property, 'value': value}) | |
| endfor | |
| @@ -118,8 +121,13 @@ | |
| for x in range(len(matches)) | |
| let match = matches[x] | |
| - call add(lines, match['selector']) | |
| - call add(lines, '{') | |
| + if g:CssPrettyLeftBraceAtNewLine | |
| + call add(lines, match['selector']) | |
| + call add(lines, '{') | |
| + else | |
| + call add(lines, match['selector'].'{') | |
| + endif | |
| + | |
| for declaration in match['declarations'] | |
| call add(lines, Whitespace(1) . declaration['property'] . ": " . declaration['value'] . ';') | |
| endfor | |
| @@ -140,7 +148,7 @@ | |
| endfor | |
| call cursor(lastline, 1) | |
| for x in range(lastline - firstline + 1) | |
| - exe 'normal ' . "a\b\e" | |
| + exe 'normal ' . "a\b\e" | |
| endfor | |
| " and appending into the buffer | |
| @@ -151,3 +159,6 @@ | |
| endfor | |
| endfunction | |
| + | |
| +let g:CssPrettyLeftBraceAtNewLine=0 | |
| +nmap <F1> :call CssPretty()<cr> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
解析为 background:#fff url(http;
的bug,丢掉了第 2 个冒号及其之后的内容。