mirror of https://github.com/amix/vimrc.git
commit
170c9e69a5
@ -1,8 +1,9 @@ |
||||
temp_dirs/undodir* |
||||
temp_dirs/undodir/* |
||||
sources_non_forked/ack.vim/.netrwhist |
||||
temp_dirs/yankring_history_v2.txt |
||||
sources_forked/yankring/doc/tags |
||||
sources_non_forked/tlib/doc/tags |
||||
sources_non_forked/ctrlp.vim/doc/tags* |
||||
my_configs.vim |
||||
tags |
||||
.DS_Store |
||||
|
@ -0,0 +1,21 @@ |
||||
The MIT License (MIT) |
||||
|
||||
Copyright (c) 2016 Amir Salihefendic |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE. |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,4 +0,0 @@ |
||||
[submodule "docs"] |
||||
path = docs |
||||
url = git@github.com:mattn/zencoding-vim.git |
||||
branch = gh-pages |
@ -1,11 +0,0 @@ |
||||
all : zencoding-vim.zip |
||||
|
||||
remove-zip: |
||||
-rm doc/tags
|
||||
-rm zencoding-vim.zip
|
||||
|
||||
zencoding-vim.zip: remove-zip |
||||
zip -r zencoding-vim.zip autoload plugin doc
|
||||
|
||||
release: zencoding-vim.zip |
||||
vimup update-script zencoding.vim
|
@ -1,103 +0,0 @@ |
||||
# ZenCoding-vim |
||||
|
||||
[zencoding-vim](http://mattn.github.com/zencoding-vim) is vim script support for expanding abbreviation like zen-coding(emmet). |
||||
|
||||
## Installation |
||||
|
||||
[Download zip file](http://www.vim.org/scripts/script.php?script_id=2981): |
||||
|
||||
cd ~/.vim |
||||
unzip zencoding-vim.zip |
||||
|
||||
If you install pathogen.vim: |
||||
|
||||
cd ~/.vim/bundle # or make directory |
||||
unzip /path/to/zencoding-vim.zip |
||||
|
||||
If you get source from repository: |
||||
|
||||
cd ~/.vim/bundle # or make directory |
||||
git clone http://github.com/mattn/zencoding-vim.git |
||||
|
||||
or: |
||||
|
||||
git clone http://github.com/mattn/zencoding-vim.git |
||||
cd zencoding-vim |
||||
cp plugin/zencoding.vim ~/.vim/plugin/ |
||||
cp autoload/zencoding.vim ~/.vim/autoload/ |
||||
cp -a autoload/zencoding ~/.vim/autoload/ |
||||
|
||||
|
||||
## Quick Tutorial |
||||
|
||||
Open or create New File: |
||||
|
||||
vim index.html |
||||
|
||||
Type ("_" is the cursor position): |
||||
|
||||
html:5_ |
||||
|
||||
Then type "<c-y>," (Ctrl + y + ','), you should see: |
||||
|
||||
<!DOCTYPE HTML> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<title></title> |
||||
</head> |
||||
<body> |
||||
_ |
||||
</body> |
||||
</html> |
||||
|
||||
[More Tutorials](https://raw.github.com/mattn/zencoding-vim/master/TUTORIAL) |
||||
|
||||
|
||||
## Enable in different mode |
||||
|
||||
If you don't want enable zencoding in all mode, |
||||
you can use set a option in `vimrc`: |
||||
|
||||
let g:user_zen_mode='n' "only enable normal mode functions. |
||||
let g:user_zen_mode='inv' "enable all functions, which is equal to |
||||
let g:user_zen_mode='a' "enable all function in all mode. |
||||
|
||||
## Project Authors |
||||
|
||||
[Yasuhiro Matsumoto](http://mattn.kaoriya.net/) |
||||
|
||||
## Links |
||||
|
||||
### zen-coding official site: |
||||
|
||||
> <http://code.google.com/p/zen-coding/> |
||||
|
||||
### zencoding.vim: |
||||
|
||||
> <http://mattn.github.com/zencoding-vim> |
||||
|
||||
### development repository: |
||||
|
||||
> <https://github.com/mattn/zencoding-vim> |
||||
|
||||
### my blog posts about zencoding-vim: |
||||
|
||||
> <http://mattn.kaoriya.net/software/vim/20100222103327.htm> |
||||
|
||||
> <http://mattn.kaoriya.net/software/vim/20100306021632.htm> |
||||
|
||||
### japanese blog posts about zencoding-vim: |
||||
|
||||
> <http://d.hatena.ne.jp/idesaku/20100424/1272092255> |
||||
|
||||
> <http://d.hatena.ne.jp/griefworker/20110118/vim_zen_coding> |
||||
|
||||
> <http://d.hatena.ne.jp/sakurako_s/20110126/1295988873> |
||||
|
||||
> <http://looxu.blogspot.jp/2010/02/zencodingvimhtml.html> |
||||
|
||||
### tutorial traslated in chinese: |
||||
|
||||
> <http://www.zfanw.com/blog/zencoding-vim-tutorial-chinese.html> |
||||
|
@ -1,212 +0,0 @@ |
||||
Tutorial of zencoding.vim |
||||
|
||||
mattn <mattn.jp@gmail.com> |
||||
|
||||
1. Expand Abbreviation |
||||
|
||||
Type abbreviation as 'div>p#foo$*3>a' and type '<c-y>,'. |
||||
--------------------- |
||||
<div> |
||||
<p id="foo1"> |
||||
<a href=""></a> |
||||
</p> |
||||
<p id="foo2"> |
||||
<a href=""></a> |
||||
</p> |
||||
<p id="foo3"> |
||||
<a href=""></a> |
||||
</p> |
||||
</div> |
||||
--------------------- |
||||
|
||||
2. Wrap with Abbreviation |
||||
|
||||
Write as below. |
||||
--------------------- |
||||
test1 |
||||
test2 |
||||
test3 |
||||
--------------------- |
||||
Then do visual select(line wize) and type '<c-y>,'. |
||||
If you request 'Tag:', then type 'ul>li*'. |
||||
--------------------- |
||||
<ul> |
||||
<li>test1</li> |
||||
<li>test2</li> |
||||
<li>test3</li> |
||||
</ul> |
||||
--------------------- |
||||
|
||||
If you type tag as 'blockquote', then you'll see as following. |
||||
--------------------- |
||||
<blockquote> |
||||
test1 |
||||
test2 |
||||
test3 |
||||
</blockquote> |
||||
--------------------- |
||||
|
||||
3. Balance Tag Inward |
||||
|
||||
type '<c-y>d' in insert mode. |
||||
|
||||
4. Balance Tag Outward |
||||
|
||||
type '<c-y>D' in insert mode. |
||||
|
||||
5. Go to Next Edit Point |
||||
|
||||
type '<c-y>n' in insert mode. |
||||
|
||||
6. Go to Previous Edit Point |
||||
|
||||
type '<c-y>N' in insert mode. |
||||
|
||||
7. Update <img> Size |
||||
|
||||
Move cursor to img tag. |
||||
--------------------- |
||||
<img src="foo.png" /> |
||||
--------------------- |
||||
Type '<c-y>i' on img tag |
||||
--------------------- |
||||
<img src="foo.png" width="32" height="48" /> |
||||
--------------------- |
||||
|
||||
8. Merge Lines |
||||
|
||||
select the lines included '<li>' |
||||
--------------------- |
||||
<ul> |
||||
<li class="list1"></li> |
||||
<li class="list2"></li> |
||||
<li class="list3"></li> |
||||
</ul> |
||||
--------------------- |
||||
and type '<c-y>m' |
||||
--------------------- |
||||
<ul> |
||||
<li class="list1"></li><li class="list2"></li><li class="list3"></li> |
||||
</ul> |
||||
--------------------- |
||||
|
||||
9. Remove Tag |
||||
|
||||
Move cursor in block |
||||
--------------------- |
||||
<div class="foo"> |
||||
<a>cursor is here</a> |
||||
</div> |
||||
--------------------- |
||||
Type '<c-y>k' in insert mode. |
||||
--------------------- |
||||
<div class="foo"> |
||||
|
||||
</div> |
||||
--------------------- |
||||
|
||||
And type '<c-y>k' in there again. |
||||
--------------------- |
||||
|
||||
--------------------- |
||||
|
||||
10. Split/Join Tag |
||||
|
||||
Move cursor in block |
||||
--------------------- |
||||
<div class="foo"> |
||||
cursor is here |
||||
</div> |
||||
--------------------- |
||||
Type '<c-y>j' in insert mode. |
||||
--------------------- |
||||
<div class="foo"/> |
||||
--------------------- |
||||
|
||||
And type '<c-y>j' in there again. |
||||
--------------------- |
||||
<div class="foo"> |
||||
</div> |
||||
--------------------- |
||||
|
||||
11. Toggle Comment |
||||
|
||||
Move cursor to block |
||||
--------------------- |
||||
<div> |
||||
hello world |
||||
</div> |
||||
--------------------- |
||||
Type '<c-y>/' in insert mode. |
||||
--------------------- |
||||
<!-- <div> |
||||
hello world |
||||
</div> --> |
||||
--------------------- |
||||
Type '<c-y>/' in there again. |
||||
--------------------- |
||||
<div> |
||||
hello world |
||||
</div> |
||||
--------------------- |
||||
|
||||
12. Make anchor from URL |
||||
|
||||
Move cursor to URL |
||||
--------------------- |
||||
http://www.google.com/ |
||||
--------------------- |
||||
Type '<c-y>a' |
||||
--------------------- |
||||
<a href="http://www.google.com/">Google</a> |
||||
--------------------- |
||||
|
||||
13. Make quoted text from URL |
||||
|
||||
Move cursor to URL |
||||
--------------------- |
||||
http://github.com/ |
||||
--------------------- |
||||
Type '<c-y>A' |
||||
--------------------- |
||||
<blockquote class="quote"> |
||||
<a href="http://github.com/">Secure source code hosting and collaborative development - GitHub</a><br /> |
||||
<p>How does it work? Get up and running in seconds by forking a project, pushing an existing repository...</p> |
||||
<cite>http://github.com/</cite> |
||||
</blockquote> |
||||
--------------------- |
||||
|
||||
14. Installing zencoding.vim for language you using. |
||||
|
||||
# cd ~/.vim |
||||
# unzip zencoding-vim.zip |
||||
|
||||
or if you install pathogen.vim: |
||||
|
||||
# cd ~/.vim/bundle # or make directory |
||||
# unzip /path/to/zencoding-vim.zip |
||||
|
||||
if you get sources from repository: |
||||
|
||||
# cd ~/.vim/bundle # or make directory |
||||
# git clone http://github.com/mattn/zencoding-vim.git |
||||
|
||||
15. Enable zencoding.vim for language you using. |
||||
|
||||
You can customize the behavior of language you using. |
||||
|
||||
--------------------- |
||||
# cat >> ~/.vimrc |
||||
let g:user_zen_settings = { |
||||
\ 'php' : { |
||||
\ 'extends' : 'html', |
||||
\ 'filters' : 'c', |
||||
\ }, |
||||
\ 'xml' : { |
||||
\ 'extends' : 'html', |
||||
\ }, |
||||
\ 'haml' : { |
||||
\ 'extends' : 'html', |
||||
\ }, |
||||
\} |
||||
--------------------- |
File diff suppressed because it is too large
Load Diff
@ -1,11 +0,0 @@ |
||||
let s:exists = {} |
||||
function zencoding#lang#exists(type) |
||||
if len(a:type) == 0 |
||||
return 0 |
||||
elseif has_key(s:exists, a:type) |
||||
return s:exists[a:type] |
||||
endif |
||||
let s:exists[a:type] = len(globpath(&rtp, 'autoload/zencoding/lang/'.a:type.'.vim')) > 0 |
||||
return s:exists[a:type] |
||||
endfunction |
||||
|
@ -1,228 +0,0 @@ |
||||
function! zencoding#lang#css#findTokens(str) |
||||
return substitute(a:str, '^.*[;{]\s*', '', '') |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#parseIntoTree(abbr, type) |
||||
let abbr = a:abbr |
||||
let type = a:type |
||||
let prefix = 0 |
||||
let value = '' |
||||
|
||||
let settings = zencoding#getSettings() |
||||
let indent = zencoding#getIndentation(type) |
||||
|
||||
let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 } |
||||
|
||||
" 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 |
||||
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 = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': important } |
||||
let current.name = tag_name |
||||
|
||||
" aliases |
||||
let aliases = zencoding#getResource(type, 'aliases', {}) |
||||
if has_key(aliases, tag_name) |
||||
let current.name = aliases[tag_name] |
||||
endif |
||||
let use_pipe_for_cursor = zencoding#getResource(type, 'use_pipe_for_cursor', 1) |
||||
|
||||
" snippets |
||||
let snippets = zencoding#getResource(type, 'snippets', {}) |
||||
if !empty(snippets) && has_key(snippets, tag_name) |
||||
let snippet = snippets[tag_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 && stridx(value, '${cursor}') == -1 |
||||
let current.snippet = substitute(current.snippet, '${cursor}', '', 'g') . '${cursor}' |
||||
endif |
||||
if n < len(tokens) - 1 |
||||
let current.snippet .= "\n" |
||||
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 |
||||
return root |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#toString(settings, current, type, inline, filters, itemno, indent) |
||||
let current = a:current |
||||
let value = current.value[1:-2] |
||||
if zencoding#useFilter(a:filters, 'fc') |
||||
let value = substitute(value, '\([^:]\+\):\([^;]*;\)', '\1: \2', 'g') |
||||
else |
||||
let value = substitute(value, '\([^:]\+\):\([^;]*;\)', '\1:\2', 'g') |
||||
endif |
||||
if current.important |
||||
let value = substitute(value, ';', ' !important;', '') |
||||
endif |
||||
return value |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#imageSize() |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#encodeImage() |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#parseTag(tag) |
||||
return {} |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#toggleComment() |
||||
let line = getline('.') |
||||
let mx = '^\(\s*\)/\*\s*\(.*\)\s*\*/\s*$' |
||||
if line =~ '{\s*$' |
||||
let block = zencoding#util#searchRegion('/\*', '\*/\zs') |
||||
if zencoding#util#regionIsValid(block) |
||||
let content = zencoding#util#getContent(block) |
||||
let content = substitute(content, '/\*\s\(.*\)\s\*/', '\1', '') |
||||
call zencoding#util#setContent(block, content) |
||||
else |
||||
let node = expand('<cword>') |
||||
if len(node) |
||||
exe "normal ciw\<c-r>='/* '.node.' */'\<cr>" |
||||
endif |
||||
endif |
||||
else |
||||
if line =~ mx |
||||
let space = substitute(matchstr(line, mx), mx, '\1', '') |
||||
let line = substitute(matchstr(line, mx), mx, '\2', '') |
||||
let line = space . substitute(line, '^\s*\|\s*$', '\1', 'g') |
||||
else |
||||
let mx = '^\(\s*\)\(.*\)\s*$' |
||||
let line = substitute(line, mx, '\1/* \2 */', '') |
||||
endif |
||||
call setline('.', line) |
||||
endif |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#balanceTag(flag) range |
||||
if a:flag == -2 || a:flag == 2 |
||||
let curpos = [0, line("'<"), col("'<"), 0] |
||||
else |
||||
let curpos = getpos('.') |
||||
endif |
||||
let block = zencoding#util#getVisualBlock() |
||||
if !zencoding#util#regionIsValid(block) |
||||
if a:flag > 0 |
||||
let block = zencoding#util#searchRegion('^', ';') |
||||
if zencoding#util#regionIsValid(block) |
||||
call zencoding#util#selectRegion(block) |
||||
return |
||||
endif |
||||
endif |
||||
else |
||||
if a:flag > 0 |
||||
let content = zencoding#util#getContent(block) |
||||
if content !~ '^{.*}$' |
||||
let block = zencoding#util#searchRegion('{', '}') |
||||
if zencoding#util#regionIsValid(block) |
||||
call zencoding#util#selectRegion(block) |
||||
return |
||||
endif |
||||
endif |
||||
else |
||||
let pos = searchpos('.*;', 'nW') |
||||
if pos[0] != 0 |
||||
call setpos('.', [0, pos[0], pos[1], 0]) |
||||
let block = zencoding#util#searchRegion('^', ';') |
||||
if zencoding#util#regionIsValid(block) |
||||
call zencoding#util#selectRegion(block) |
||||
return |
||||
endif |
||||
endif |
||||
endif |
||||
endif |
||||
if a:flag == -2 || a:flag == 2 |
||||
silent! exe "normal! gv" |
||||
else |
||||
call setpos('.', curpos) |
||||
endif |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#moveNextPrev(flag) |
||||
let pos = search('""\|()\|\(:\s*\zs$\)', a:flag ? 'Wbp' : 'Wp') |
||||
if pos == 2 |
||||
startinsert! |
||||
else |
||||
silent! normal! l |
||||
startinsert |
||||
endif |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#splitJoinTag() |
||||
" nothing to do |
||||
endfunction |
||||
|
||||
function! zencoding#lang#css#removeTag() |
||||
" nothing to do |
||||
endfunction |
@ -1,310 +0,0 @@ |
||||
function! zencoding#lang#haml#findTokens(str) |
||||
return zencoding#lang#html#findTokens(a:str) |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#parseIntoTree(abbr, type) |
||||
return zencoding#lang#html#parseIntoTree(a:abbr, a:type) |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#toString(settings, current, type, inline, filters, itemno, indent) |
||||
let settings = a:settings |
||||
let current = a:current |
||||
let type = a:type |
||||
let inline = a:inline |
||||
let filters = a:filters |
||||
let itemno = a:itemno |
||||
let indent = a:indent |
||||
let dollar_expr = zencoding#getResource(type, 'dollar_expr', 1) |
||||
let str = "" |
||||
|
||||
let comment_indent = '' |
||||
let comment = '' |
||||
let current_name = current.name |
||||
if dollar_expr |
||||
let current_name = substitute(current.name, '\$$', itemno+1, '') |
||||
endif |
||||
if len(current.name) > 0 |
||||
let str .= '%' . current_name |
||||
let tmp = '' |
||||
for attr in current.attrs_order |
||||
if !has_key(current.attr, attr) |
||||
continue |
||||
endif |
||||
let val = current.attr[attr] |
||||
if dollar_expr |
||||
while val =~ '\$\([^#{]\|$\)' |
||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') |
||||
endwhile |
||||
let attr = substitute(attr, '\$$', itemno+1, '') |
||||
endif |
||||
let valtmp = substitute(val, '\${cursor}', '', '') |
||||
if attr == 'id' && len(valtmp) > 0 |
||||
let str .= '#' . val |
||||
elseif attr == 'class' && len(valtmp) > 0 |
||||
let str .= '.' . substitute(val, ' ', '.', 'g') |
||||
else |
||||
if len(tmp) > 0 | let tmp .= ',' | endif |
||||
let val = substitute(val, '\${cursor}', '', '') |
||||
let tmp .= ' :' . attr . ' => "' . val . '"' |
||||
endif |
||||
endfor |
||||
if len(tmp) |
||||
let str .= '{' . tmp . ' }' |
||||
endif |
||||
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 && len(current.value) == 0 |
||||
let str .= "/" |
||||
endif |
||||
|
||||
let inner = '' |
||||
if len(current.value) > 0 |
||||
let text = current.value[1:-2] |
||||
if dollar_expr |
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') |
||||
let text = substitute(text, '\${nr}', "\n", 'g') |
||||
let text = substitute(text, '\\\$', '$', 'g') |
||||
let str = substitute(str, '\$#', text, 'g') |
||||
endif |
||||
let lines = split(text, "\n") |
||||
if len(lines) == 1 |
||||
let str .= " " . text |
||||
else |
||||
for line in lines |
||||
let str .= "\n" . indent . line . " |" |
||||
endfor |
||||
endif |
||||
elseif len(current.child) == 0 |
||||
let str .= '${cursor}' |
||||
endif |
||||
if len(current.child) == 1 && len(current.child[0].name) == 0 |
||||
let text = current.child[0].value[1:-2] |
||||
if dollar_expr |
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') |
||||
let text = substitute(text, '\${nr}', "\n", 'g') |
||||
let text = substitute(text, '\\\$', '$', 'g') |
||||
endif |
||||
let lines = split(text, "\n") |
||||
if len(lines) == 1 |
||||
let str .= " " . text |
||||
else |
||||
for line in lines |
||||
let str .= "\n" . indent . line . " |" |
||||
endfor |
||||
endif |
||||
elseif len(current.child) > 0 |
||||
for child in current.child |
||||
let inner .= zencoding#toString(child, type, inline, filters, itemno) |
||||
endfor |
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') |
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g') |
||||
let str .= "\n" . indent . inner |
||||
endif |
||||
else |
||||
let str = current.value[1:-2] |
||||
if dollar_expr |
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') |
||||
let str = substitute(str, '\${nr}', "\n", 'g') |
||||
let str = substitute(str, '\\\$', '$', 'g') |
||||
endif |
||||
endif |
||||
let str .= "\n" |
||||
return str |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#imageSize() |
||||
let line = getline('.') |
||||
let current = zencoding#lang#haml#parseTag(line) |
||||
if empty(current) || !has_key(current.attr, 'src') |
||||
return |
||||
endif |
||||
let fn = current.attr.src |
||||
if fn =~ '^\s*$' |
||||
return |
||||
elseif fn !~ '^\(/\|http\)' |
||||
let fn = simplify(expand('%:h') . '/' . fn) |
||||
endif |
||||
|
||||
let [width, height] = zencoding#util#getImageSize(fn) |
||||
if width == -1 && height == -1 |
||||
return |
||||
endif |
||||
let current.attr.width = width |
||||
let current.attr.height = height |
||||
let current.attrs_order += ['width', 'height'] |
||||
let haml = zencoding#toString(current, 'haml', 1) |
||||
let haml = substitute(haml, '\${cursor}', '', '') |
||||
call setline('.', substitute(matchstr(line, '^\s*') . haml, "\n", "", "g")) |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#encodeImage() |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#parseTag(tag) |
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'attrs_order': [] } |
||||
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)' |
||||
let match = matchstr(a:tag, mx) |
||||
let current.name = substitute(match, mx, '\1', 'i') |
||||
let attrs = substitute(match, mx, '\2', 'i') |
||||
let mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' |
||||
while len(attrs) > 0 |
||||
let match = matchstr(attrs, mx) |
||||
if len(match) == 0 |
||||
break |
||||
endif |
||||
let attr_match = matchlist(match, mx) |
||||
let name = attr_match[1] |
||||
let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] |
||||
let current.attr[name] = value |
||||
let current.attrs_order += [name] |
||||
let attrs = attrs[stridx(attrs, match) + len(match):] |
||||
endwhile |
||||
return current |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#toggleComment() |
||||
let line = getline('.') |
||||
let space = matchstr(line, '^\s*') |
||||
if line =~ '^\s*-#' |
||||
call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*')) |
||||
elseif line =~ '^\s*%[a-z]' |
||||
call setline('.', space . '-# ' . line[len(space):]) |
||||
endif |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#balanceTag(flag) range |
||||
let block = zencoding#util#getVisualBlock() |
||||
if a:flag == -2 || a:flag == 2 |
||||
let curpos = [0, line("'<"), col("'<"), 0] |
||||
else |
||||
let curpos = getpos('.') |
||||
endif |
||||
let n = curpos[1] |
||||
let ml = len(matchstr(getline(n), '^\s*')) |
||||
|
||||
if a:flag > 0 |
||||
if a:flag == 1 || !zencoding#util#regionIsValid(block) |
||||
let n = line('.') |
||||
else |
||||
while n > 0 |
||||
let l = len(matchstr(getline(n), '^\s*\ze%[a-z]')) |
||||
if l > 0 && l < ml |
||||
let ml = l |
||||
break |
||||
endif |
||||
let n -= 1 |
||||
endwhile |
||||
endif |
||||
let sn = n |
||||
if n == 0 |
||||
let ml = 0 |
||||
endif |
||||
while n < line('$') |
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]')) |
||||
if l > 0 && l <= ml |
||||
let n -= 1 |
||||
break |
||||
endif |
||||
let n += 1 |
||||
endwhile |
||||
call setpos('.', [0, n, 1, 0]) |
||||
normal! V |
||||
call setpos('.', [0, sn, 1, 0]) |
||||
else |
||||
while n > 0 |
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) |
||||
if l > 0 && l > ml |
||||
let ml = l |
||||
break |
||||
endif |
||||
let n += 1 |
||||
endwhile |
||||
let sn = n |
||||
if n == 0 |
||||
let ml = 0 |
||||
endif |
||||
while n < line('$') |
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]')) |
||||
if l > 0 && l <= ml |
||||
let n -= 1 |
||||
break |
||||
endif |
||||
let n += 1 |
||||
endwhile |
||||
call setpos('.', [0, n, 1, 0]) |
||||
normal! V |
||||
call setpos('.', [0, sn, 1, 0]) |
||||
endif |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#moveNextPrev(flag) |
||||
let pos = search('""', a:flag ? 'Wb' : 'W') |
||||
if pos != 0 |
||||
silent! normal! l |
||||
startinsert |
||||
endif |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#splitJoinTag() |
||||
let n = line('.') |
||||
let sml = len(matchstr(getline(n), '^\s*%[a-z]')) |
||||
while n > 0 |
||||
if getline(n) =~ '^\s*\ze%[a-z]' |
||||
if len(matchstr(getline(n), '^\s*%[a-z]')) < sml |
||||
break |
||||
endif |
||||
let line = getline(n) |
||||
call setline(n, substitute(line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', '')) |
||||
let sn = n |
||||
let n += 1 |
||||
let ml = len(matchstr(getline(n), '^\s*%[a-z]')) |
||||
if len(matchstr(getline(n), '^\s*')) > ml |
||||
while n <= line('$') |
||||
let l = len(matchstr(getline(n), '^\s*')) |
||||
if l <= ml |
||||
break |
||||
endif |
||||
exe n "delete" |
||||
endwhile |
||||
call setpos('.', [0, sn, 1, 0]) |
||||
else |
||||
let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)') |
||||
let spaces = matchstr(getline(sn), '^\s*') |
||||
let settings = zencoding#getSettings() |
||||
if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1 |
||||
call append(sn, spaces . ' ') |
||||
call setpos('.', [0, sn+1, 1, 0]) |
||||
else |
||||
call setpos('.', [0, sn, 1, 0]) |
||||
endif |
||||
startinsert! |
||||
endif |
||||
break |
||||
endif |
||||
let n -= 1 |
||||
endwhile |
||||
endfunction |
||||
|
||||
function! zencoding#lang#haml#removeTag() |
||||
let n = line('.') |
||||
let ml = 0 |
||||
while n > 0 |
||||
if getline(n) =~ '^\s*\ze[a-z]' |
||||
let ml = len(matchstr(getline(n), '^\s*%[a-z]')) |
||||
break |
||||
endif |
||||
let n -= 1 |
||||
endwhile |
||||
let sn = n |
||||
while n < line('$') |
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]')) |
||||
if l > 0 && l <= ml |
||||
let n -= 1 |
||||
break |
||||
endif |
||||
let n += 1 |
||||
endwhile |
||||
if sn == n |
||||
exe "delete" |
||||
else |
||||
exe sn "," (n-1) "delete" |
||||
endif |
||||
endfunction |
@ -1,692 +0,0 @@ |
||||
let s:mx = '\([+>]\|[<^]\+\)\{-}\s*' |
||||
\ .'\((*\)\{-}\s*' |
||||
\ .'\([@#.]\{-}[a-zA-Z\!][a-zA-Z0-9:_\!\-$]*\|{\%([^$}]\+\|\$#\|\${\w\+}\|\$\+\)*}[ \t\r\n}]*\)' |
||||
\ .'\(' |
||||
\ .'\%(' |
||||
\ .'\%(#{[{}a-zA-Z0-9_\-\$]\+\|#[a-zA-Z0-9_\-\$]\+\)' |
||||
\ .'\|\%(\[[^\]]\+\]\)' |
||||
\ .'\|\%(\.{[{}a-zA-Z0-9_\-\$]\+\|\.[a-zA-Z0-9_\-\$]\+\)' |
||||
\ .'\)*' |
||||
\ .'\)' |
||||
\ .'\%(\({\%([^$}]\+\|\$#\|\${\w\+}\|\$\+\)*}\)\)\{0,1}' |
||||
\ .'\%(\*\([0-9]\+\)\)\{0,1}' |
||||
\ .'\(\%()\%(\*[0-9]\+\)\{0,1}\)*\)' |
||||
|
||||
function! zencoding#lang#html#findTokens(str) |
||||
let str = a:str |
||||
let [pos, last_pos] = [0, 0] |
||||
while 1 |
||||
let tag = matchstr(str, '<[a-zA-Z].\{-}>', pos) |
||||
if len(tag) == 0 |
||||
break |
||||
endif |
||||
let pos = stridx(str, tag, pos) + len(tag) |
||||
endwhile |
||||
let last_pos = pos |
||||
while len(str) > 0 |
||||
let token = matchstr(str, s:mx, pos) |
||||
if token == '' |
||||
break |
||||
endif |
||||
if token =~ '^\s' |
||||
let token = matchstr(token, '^\s*\zs.*') |
||||
let last_pos = stridx(str, token, pos) |
||||
endif |
||||
let pos = stridx(str, token, pos) + len(token) |
||||
endwhile |
||||
return a:str[last_pos :-1] |
||||
endfunction |
||||
|
||||
function! zencoding#lang#html#parseIntoTree(abbr, type) |
||||
let abbr = a:abbr |
||||
let type = a:type |
||||
|
||||
let settings = zencoding#getSettings() |
||||
if !has_key(settings, type) |
||||
let type = 'html' |
||||
endif |
||||
if len(type) == 0 | let type = 'html' | endif |
||||
|
||||
let settings = zencoding#getSettings() |
||||
let indent = zencoding#getIndentation(type) |
||||
|
||||
" try 'foo' to (foo-x) |
||||
let rabbr = zencoding#getExpandos(type, abbr) |
||||
if rabbr == abbr |
||||
" try 'foo+(' to (foo-x) |
||||
let rabbr = substitute(abbr, '\%(+\|^\)\([a-zA-Z][a-zA-Z0-9+]\+\)+\([(){}>]\|$\)', '\="(".zencoding#getExpandos(type, submatch(1)).")".submatch(2)', 'i') |
||||
endif |
||||
let abbr = rabbr |
||||
|
||||
let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0, 'attrs_order': ['id', 'class'] } |
||||
let parent = root |
||||
let last = root |
||||
let pos = [] |
||||
while len(abbr) |
||||
" parse line |
||||
let match = matchstr(abbr, s:mx) |
||||
let str = substitute(match, s:mx, '\0', 'ig') |
||||
let operator = substitute(match, s:mx, '\1', 'ig') |
||||
let block_start = substitute(match, s:mx, '\2', 'ig') |
||||
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 important = 0 |
||||
if len(str) == 0 |
||||
break |
||||
endif |
||||
if tag_name =~ '^#' |
||||
let attributes = tag_name . attributes |
||||
let tag_name = 'div' |
||||
endif |
||||
if tag_name =~ '.!$' |
||||
let tag_name = tag_name[:-2] |
||||
let important = 1 |
||||
endif |
||||
if tag_name =~ '^\.' |
||||
let attributes = tag_name . attributes |
||||
let tag_name = 'div' |
||||
endif |
||||
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.name = tag_name |
||||
|
||||
let current.important = important |
||||
|
||||
" aliases |
||||
let aliases = zencoding#getResource(type, 'aliases', {}) |
||||
if has_key(aliases, tag_name) |
||||
let current.name = aliases[tag_name] |
||||
endif |
||||
|
||||
let use_pipe_for_cursor = zencoding#getResource(type, 'use_pipe_for_cursor', 1) |
||||
|
||||
" snippets |
||||
let snippets = zencoding#getResource(type, 'snippets', {}) |
||||
if !empty(snippets) && has_key(snippets, tag_name) |
||||
let snippet = snippets[tag_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 = '' |
||||
endif |
||||
|
||||
" default_attributes |
||||
let default_attributes = zencoding#getResource(type, 'default_attributes', {}) |
||||
if !empty(default_attributes) |
||||
for pat in [current.name, tag_name] |
||||
if has_key(default_attributes, pat) |
||||
if type(default_attributes[pat]) == 4 |
||||
let a = default_attributes[pat] |
||||
let current.attrs_order += keys(a) |
||||
if use_pipe_for_cursor |
||||
for k in keys(a) |
||||
let current.attr[k] = len(a[k]) ? substitute(a[k], '|', '${cursor}', 'g') : '${cursor}' |
||||
endfor |
||||
else |
||||
for k in keys(a) |
||||
let current.attr[k] = a[k] |
||||
endfor |
||||
endif |
||||
else |
||||
for a in default_attributes[pat] |
||||
let current.attrs_order += keys(a) |
||||
if use_pipe_for_cursor |
||||
for k in keys(a) |
||||
let current.attr[k] = len(a[k]) ? substitute(a[k], '|', '${cursor}', 'g') : '${cursor}' |
||||
endfor |
||||
else |
||||
for k in keys(a) |
||||
let current.attr[k] = a[k] |
||||
endfor |
||||
endif |
||||
endfor |
||||
endif |
||||
if has_key(settings.html.default_attributes, current.name) |
||||
let current.name = substitute(current.name, ':.*$', '', '') |
||||
endif |
||||
break |
||||
endif |
||||
endfor |
||||
endif |
||||
|
||||
" parse attributes |
||||
if len(attributes) |
||||
let attr = attributes |
||||
while len(attr) |
||||
let item = matchstr(attr, '\(\%(\%(#[{}a-zA-Z0-9_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|\%(\.[{}a-zA-Z0-9_\-\$]\+\)*\)\)') |
||||
if len(item) == 0 |
||||
break |
||||
endif |
||||
if item[0] == '#' |
||||
let current.attr.id = item[1:] |
||||
endif |
||||
if item[0] == '.' |
||||
let current.attr.class = substitute(item[1:], '\.', ' ', 'g') |
||||
endif |
||||
if item[0] == '[' |
||||
let atts = item[1:-2] |
||||
while len(atts) |
||||
let amat = matchstr(atts, '\(\w\+\%(="[^"]*"\|=''[^'']*''\|[^ ''"\]]*\)\{0,1}\)') |
||||
if len(amat) == 0 |
||||
break |
||||
endif |
||||
let key = split(amat, '=')[0] |
||||
let val = amat[len(key)+1:] |
||||
if val =~ '^["'']' |
||||
let val = val[1:-2] |
||||
endif |
||||
let current.attr[key] = val |
||||
if index(current.attrs_order, key) == -1 |
||||
let current.attrs_order += [key] |