From f8095a65ddae7b7d9f025e4a1837f340c1033705 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 25 Sep 2013 22:56:34 +0900 Subject: [PATCH] Expand paren --- autoload/emmet/lang/css.vim | 229 +++++++++++++++++++----------------- 1 file changed, 118 insertions(+), 111 deletions(-) diff --git a/autoload/emmet/lang/css.vim b/autoload/emmet/lang/css.vim index 61f315b..09442e9 100644 --- a/autoload/emmet/lang/css.vim +++ b/autoload/emmet/lang/css.vim @@ -18,123 +18,130 @@ function! emmet#lang#css#parseIntoTree(abbr, type) " emmet let tokens = split(abbr, '+\ze[^+)!]') - for n in range(len(tokens)) - let token = tokens[n] - let prop = matchlist(token, '^\(-\{0,1}[a-zA-Z]\+\|[a-zA-Z0-9]\++\{0,1}\|([a-zA-Z0-9]\++\{0,1})\)\(\%([0-9.-]\+[pe]\{0,1}-\{0,1}\|-auto\)*\)$') - if len(prop) - let token = substitute(prop[1], '^(\(.*\))', '\1', '') - if token =~ '^-' - let prefix = 1 - let token = token[1:] - endif - let value = '' - for v in split(prop[2], '\d\zs-') - if len(value) > 0 - let value .= ' ' - endif - if token =~ '^[z]' - " TODO - let value .= substitute(v, '[^0-9.]*$', '', '') - elseif v =~ 'p$' - let value .= substitute(v, 'p$', '%', '') - elseif v =~ 'e$' - let value .= substitute(v, 'e$', 'em', '') - elseif v =~ '\.' - let value .= v . 'em' - elseif v == 'auto' - let value .= v - elseif v == '0' - let value .= '0' - else - let value .= v . 'px' - endif - endfor - endif - - let tag_name = token - if tag_name =~ '.!$' - let tag_name = tag_name[:-2] - let important = 1 - else - let important = 0 - endif - " make default node + let block = emmet#util#searchRegion("{", "}") + if block[0] == [0,0] && block[1] == [0,0] let current = emmet#newNode() - let current.important = important - let current.name = tag_name - - " aliases - if has_key(aliases, tag_name) - let current.name = aliases[tag_name] - endif - - " snippets - if !empty(snippets) - let snippet_name = tag_name - if !has_key(snippets, snippet_name) - let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-\)') - let g:hoge = pat - let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') - if len(vv) > 0 - let snippet_name = vv[0] - else - let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-*\)') + let current.snippet = abbr . " {\n\t${cursor}\n}" + let current.name = '' + call add(root.child, deepcopy(current)) + else + for n in range(len(tokens)) + let token = tokens[n] + let prop = matchlist(token, '^\(-\{0,1}[a-zA-Z]\+\|[a-zA-Z0-9]\++\{0,1}\|([a-zA-Z0-9]\++\{0,1})\)\(\%([0-9.-]\+[pe]\{0,1}-\{0,1}\|-auto\)*\)$') + if len(prop) + let token = substitute(prop[1], '^(\(.*\))', '\1', '') + if token =~ '^-' + let prefix = 1 + let token = token[1:] + endif + let value = '' + for v in split(prop[2], '\d\zs-') + if len(value) > 0 + let value .= ' ' + endif + if token =~ '^[z]' + " TODO + let value .= substitute(v, '[^0-9.]*$', '', '') + elseif v =~ 'p$' + let value .= substitute(v, 'p$', '%', '') + elseif v =~ 'e$' + let value .= substitute(v, 'e$', 'em', '') + elseif v =~ '\.' + let value .= v . 'em' + elseif v == 'auto' + let value .= v + elseif v == '0' + let value .= '0' + else + let value .= v . 'px' + endif + endfor + endif + + let tag_name = token + if tag_name =~ '.!$' + let tag_name = tag_name[:-2] + let important = 1 + else + let important = 0 + endif + " make default node + let current = emmet#newNode() + let current.important = important + let current.name = tag_name + + " aliases + if has_key(aliases, tag_name) + let current.name = aliases[tag_name] + endif + + " snippets + if !empty(snippets) + let snippet_name = tag_name + if !has_key(snippets, snippet_name) + let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-\)') let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') - let minl = -1 - for vk in vv - let vvs = snippets[vk] - if minl == -1 || len(vvs) < minl - let snippet_name = vk - let minl = len(vvs) - endif - endfor + if len(vv) > 0 + let snippet_name = vv[0] + else + let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-*\)') + let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') + let minl = -1 + for vk in vv + let vvs = snippets[vk] + if minl == -1 || len(vvs) < minl + let snippet_name = vk + let minl = len(vvs) + endif + endfor + endif + endif + if has_key(snippets, snippet_name) + let snippet = snippets[snippet_name] + if use_pipe_for_cursor + let snippet = substitute(snippet, '|', '${cursor}', 'g') + endif + let lines = split(snippet, "\n") + call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")') + let current.snippet = join(lines, "\n") + let current.name = '' + let current.snippet = substitute(current.snippet, ';', value . ';', '') + if use_pipe_for_cursor && len(value) > 0 + let current.snippet = substitute(current.snippet, '\${cursor}', '', 'g') + endif + if n < len(tokens) - 1 + let current.snippet .= "\n" + endif endif endif - if has_key(snippets, snippet_name) - let snippet = snippets[snippet_name] - if use_pipe_for_cursor - let snippet = substitute(snippet, '|', '${cursor}', 'g') - endif - let lines = split(snippet, "\n") - call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")') - let current.snippet = join(lines, "\n") + + let current.pos = 0 + let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\w\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$') + if len(lg) let current.name = '' - let current.snippet = substitute(current.snippet, ';', value . ';', '') - if use_pipe_for_cursor && len(value) > 0 - let current.snippet = substitute(current.snippet, '\${cursor}', '', 'g') - endif - if n < len(tokens) - 1 - let current.snippet .= "\n" - endif + let current.snippet = printf("background-image:-webkit-gradient(%s, 0 0, 0 100%, from(%s), to(%s));\n", lg[1], lg[2], lg[3]) + call add(root.child, deepcopy(current)) + let current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", lg[2], lg[3]) + call add(root.child, deepcopy(current)) + let current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", lg[2], lg[3]) + call add(root.child, deepcopy(current)) + let current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", lg[2], lg[3]) + call add(root.child, deepcopy(current)) + let current.snippet = printf("background-image:linear-gradient(%s, %s);\n", lg[2], lg[3]) + call add(root.child, deepcopy(current)) + elseif prefix + let snippet = current.snippet + let current.snippet = '-webkit-' . snippet . "\n" + call add(root.child, deepcopy(current)) + let current.snippet = '-moz-' . snippet . "\n" + call add(root.child, deepcopy(current)) + let current.snippet = snippet + call add(root.child, current) + else + call add(root.child, current) endif - endif - - let current.pos = 0 - let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\w\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$') - if len(lg) - let current.name = '' - let current.snippet = printf("background-image:-webkit-gradient(%s, 0 0, 0 100%, from(%s), to(%s));\n", lg[1], lg[2], lg[3]) - call add(root.child, deepcopy(current)) - let current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", lg[2], lg[3]) - call add(root.child, deepcopy(current)) - let current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", lg[2], lg[3]) - call add(root.child, deepcopy(current)) - let current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", lg[2], lg[3]) - call add(root.child, deepcopy(current)) - let current.snippet = printf("background-image:linear-gradient(%s, %s);\n", lg[2], lg[3]) - call add(root.child, deepcopy(current)) - elseif prefix - let snippet = current.snippet - let current.snippet = '-webkit-' . snippet . "\n" - call add(root.child, deepcopy(current)) - let current.snippet = '-moz-' . snippet . "\n" - call add(root.child, deepcopy(current)) - let current.snippet = snippet - call add(root.child, current) - else - call add(root.child, current) - endif - endfor + endfor + endif return root endfunction