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
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 13-Aug-2013.
" Last Change: 19-Aug-2013.
let s:save_cpo = &cpo
set cpo&vim
@@ -130,6 +130,21 @@ function! emmet#mergeConfig(lhs, rhs)
endif
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(...)
let current = a:1
if a:0 > 1
@@ -170,9 +185,9 @@ function! emmet#toString(...)
while itemno < current.multiplier
if len(current.name)
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
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
if current.multiplier > 1
let inner = substitute(inner, '\$#', '$line'.(itemno+1).'$', 'g')
@@ -189,8 +204,10 @@ function! emmet#toString(...)
if len(snippet) > 0
let tmp = snippet
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 str = emmet#lang#{rtype}#toString(s:emmet_settings, snippet_node, type, inline, filters, group_itemno, indent)
let snippet_node = emmet#newNode()
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
if len(current.name)
let str .= current.name
@@ -214,7 +231,7 @@ function! emmet#toString(...)
if len(current.child)
let render_type = emmet#getFileType(1)
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
endif
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 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
let tokens = split(abbr, '+\ze[^+)!]')
@@ -59,7 +59,8 @@ function! emmet#lang#css#parseIntoTree(abbr, type)
let important = 0
endif
" 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
" aliases

View File

@@ -142,7 +142,7 @@ function! emmet#lang#haml#encodeImage()
endfunction
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 match = matchstr(a:tag, mx)
let current.name = substitute(match, mx, '\1', 'i')

View File

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

View File

@@ -120,7 +120,7 @@ function! emmet#lang#slim#encodeImage()
endfunction
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 match = matchstr(a:tag, mx)
let current.name = substitute(match, mx, '\1', 'i')