Possible to specify base value. Related issue #144

This commit is contained in:
mattn
2013-08-19 11:05:53 +09:00
parent 6016cf6bdd
commit b2561af319
5 changed files with 39 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" emmet.vim " emmet.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 13-Aug-2013. " Last Change: 19-Aug-2013.
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
@@ -130,6 +130,21 @@ function! emmet#mergeConfig(lhs, rhs)
endif endif
endfunction endfunction
function! emmet#newNode()
return { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'basevalue': 0, 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0, 'attrs_order': ['id', 'class'] }
endfunction
function! s:itemno(itemno, current)
let current = a:current
if current.basevalue == 0
return a:itemno
elseif current.basevalue > 0
return current.basevalue - 1 + a:itemno
elseif current.basevalue < 0
return current.multiplier - current.basevalue - 2 - a:itemno
endif
endfunction
function! emmet#toString(...) function! emmet#toString(...)
let current = a:1 let current = a:1
if a:0 > 1 if a:0 > 1
@@ -170,9 +185,9 @@ function! emmet#toString(...)
while itemno < current.multiplier while itemno < current.multiplier
if len(current.name) if len(current.name)
if current.multiplier == 1 if current.multiplier == 1
let inner = emmet#lang#{rtype}#toString(s:emmet_settings, current, type, inline, filters, group_itemno, indent) let inner = emmet#lang#{rtype}#toString(s:emmet_settings, current, type, inline, filters, s:itemno(group_itemno, current), indent)
else else
let inner = emmet#lang#{rtype}#toString(s:emmet_settings, current, type, inline, filters, itemno, indent) let inner = emmet#lang#{rtype}#toString(s:emmet_settings, current, type, inline, filters, s:itemno(itemno, current), indent)
endif endif
if current.multiplier > 1 if current.multiplier > 1
let inner = substitute(inner, '\$#', '$line'.(itemno+1).'$', 'g') let inner = substitute(inner, '\$#', '$line'.(itemno+1).'$', 'g')
@@ -189,8 +204,10 @@ function! emmet#toString(...)
if len(snippet) > 0 if len(snippet) > 0
let tmp = snippet let tmp = snippet
let tmp = substitute(tmp, '\${emmet_name}', current.name, 'g') let tmp = substitute(tmp, '\${emmet_name}', current.name, 'g')
let snippet_node = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 0, 'parent': {}, 'value': '{'.tmp.'}', 'pos': 0, 'important': current.important } let snippet_node = emmet#newNode()
let str = emmet#lang#{rtype}#toString(s:emmet_settings, snippet_node, type, inline, filters, group_itemno, indent) let snippet_node.value = '{'.tmp.'}'
let snippet_node.important = current.important
let str = emmet#lang#{rtype}#toString(s:emmet_settings, snippet_node, type, inline, filters, s:itemno(group_itemno, current), indent)
else else
if len(current.name) if len(current.name)
let str .= current.name let str .= current.name
@@ -214,7 +231,7 @@ function! emmet#toString(...)
if len(current.child) if len(current.child)
let render_type = emmet#getFileType(1) let render_type = emmet#getFileType(1)
for n in current.child for n in current.child
let inner .= emmet#toString(n, type, inline, filters, group_itemno, indent) let inner .= emmet#toString(n, type, inline, filters, s:itemno(group_itemno, n), indent)
endfor endfor
endif endif
let inner = substitute(inner, "\n", "\n" . indent, 'g') let inner = substitute(inner, "\n", "\n" . indent, 'g')

View File

@@ -14,7 +14,7 @@ function! emmet#lang#css#parseIntoTree(abbr, type)
let snippets = emmet#getResource(type, 'snippets', {}) let snippets = emmet#getResource(type, 'snippets', {})
let use_pipe_for_cursor = emmet#getResource(type, 'use_pipe_for_cursor', 1) let use_pipe_for_cursor = emmet#getResource(type, 'use_pipe_for_cursor', 1)
let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 } let root = emmet#newNode()
" emmet " emmet
let tokens = split(abbr, '+\ze[^+)!]') let tokens = split(abbr, '+\ze[^+)!]')
@@ -59,7 +59,8 @@ function! emmet#lang#css#parseIntoTree(abbr, type)
let important = 0 let important = 0
endif endif
" make default node " make default node
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': important } let current = emmet#newNode()
let current.important = important
let current.name = tag_name let current.name = tag_name
" aliases " aliases

View File

@@ -142,7 +142,7 @@ function! emmet#lang#haml#encodeImage()
endfunction endfunction
function! emmet#lang#haml#parseTag(tag) function! emmet#lang#haml#parseTag(tag)
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'attrs_order': [] } let current = emmet#newNode()
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)' let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
let match = matchstr(a:tag, mx) let match = matchstr(a:tag, mx)
let current.name = substitute(match, mx, '\1', 'i') let current.name = substitute(match, mx, '\1', 'i')

View File

@@ -9,8 +9,8 @@ let s:mx = '\([+>]\|[<^]\+\)\{-}\s*'
\ .'\)*' \ .'\)*'
\ .'\)' \ .'\)'
\ .'\%(\({\%([^$}]\+\|\$#\|\${\w\+}\|\$\+\)*}\)\)\{0,1}' \ .'\%(\({\%([^$}]\+\|\$#\|\${\w\+}\|\$\+\)*}\)\)\{0,1}'
\ .'\%(\*\([0-9]\+\)\)\{0,1}' \ .'\%(\(@-\{0,1}[0-9]\+\)\{0,1}\*\([0-9]\+\)\)\{0,1}'
\ .'\(\%()\%(\*[0-9]\+\)\{0,1}\)*\)' \ .'\(\%()\%(\(@-\{0,1}[0-9]\+\)\{0,1}\*[0-9]\+\)\{0,1}\)*\)'
function! emmet#lang#html#findTokens(str) function! emmet#lang#html#findTokens(str)
let str = a:str let str = a:str
@@ -58,7 +58,7 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
endif endif
let abbr = rabbr let abbr = rabbr
let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0, 'attrs_order': ['id', 'class'] } let root = emmet#newNode()
let parent = root let parent = root
let last = root let last = root
let pos = [] let pos = []
@@ -71,8 +71,9 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
let tag_name = substitute(match, s:mx, '\3', 'ig') let tag_name = substitute(match, s:mx, '\3', 'ig')
let attributes = substitute(match, s:mx, '\4', 'ig') let attributes = substitute(match, s:mx, '\4', 'ig')
let value = substitute(match, s:mx, '\5', 'ig') let value = substitute(match, s:mx, '\5', 'ig')
let multiplier = 0 + substitute(match, s:mx, '\6', 'ig') let basevalue = substitute(match, s:mx, '\6', 'ig')
let block_end = substitute(match, s:mx, '\7', 'ig') let multiplier = 0 + substitute(match, s:mx, '\7', 'ig')
let block_end = substitute(match, s:mx, '\8', 'ig')
let important = 0 let important = 0
if len(str) == 0 if len(str) == 0
break break
@@ -89,10 +90,11 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
let attributes = tag_name . attributes let attributes = tag_name . attributes
let tag_name = 'div' let tag_name = 'div'
endif endif
let basevalue = 0 + basevalue[1:]
if multiplier <= 0 | let multiplier = 1 | endif if multiplier <= 0 | let multiplier = 1 | endif
" make default node " make default node
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0, 'attrs_order': ['id', 'class'] } let current = emmet#newNode()
let current.name = tag_name let current.name = tag_name
let current.important = important let current.important = important
@@ -216,6 +218,7 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
else else
let current.value = value let current.value = value
endif endif
let current.basevalue = basevalue
let current.multiplier = multiplier let current.multiplier = multiplier
" parse step inside/outside " parse step inside/outside
@@ -292,6 +295,7 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
echomsg "operator=".operator echomsg "operator=".operator
echomsg "attributes=".attributes echomsg "attributes=".attributes
echomsg "value=".value echomsg "value=".value
echomsg "basevalue=".basevalue
echomsg "multiplier=".multiplier echomsg "multiplier=".multiplier
echomsg "block_end=".block_end echomsg "block_end=".block_end
echomsg "abbr=".abbr echomsg "abbr=".abbr
@@ -488,7 +492,7 @@ function! emmet#lang#html#encodeImage()
endfunction endfunction
function! emmet#lang#html#parseTag(tag) function! emmet#lang#html#parseTag(tag)
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'attrs_order': [] } let current = emmet#newNode()
let mx = '<\([a-zA-Z][a-zA-Z0-9]*\)\(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\(/\{0,1}\)>' let mx = '<\([a-zA-Z][a-zA-Z0-9]*\)\(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\(/\{0,1}\)>'
let match = matchstr(a:tag, mx) let match = matchstr(a:tag, mx)
let current.name = substitute(match, mx, '\1', 'i') let current.name = substitute(match, mx, '\1', 'i')

View File

@@ -120,7 +120,7 @@ function! emmet#lang#slim#encodeImage()
endfunction endfunction
function! emmet#lang#slim#parseTag(tag) function! emmet#lang#slim#parseTag(tag)
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'attrs_order': [] } let current = emmet#newNode()
let mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)' let mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)'
let match = matchstr(a:tag, mx) let match = matchstr(a:tag, mx)
let current.name = substitute(match, mx, '\1', 'i') let current.name = substitute(match, mx, '\1', 'i')