1
0
Fork 0
mirror of synced 2024-06-03 07:51:09 -04:00
This commit is contained in:
epirus 2017-01-06 07:25:50 +00:00 committed by GitHub
commit c1b4210704
37 changed files with 10766 additions and 1 deletions

1
.gitignore vendored
View file

@ -4,6 +4,5 @@ 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

View file

@ -311,4 +311,6 @@ Vimscript mappings:
Do following:
* Remove `~/.vim_runtime`
* Remove any lines that refernce `.vim_runtime` in your `~/.vimrc`
## Stop Right Now
Because Vim 8 not stable~until to version 8.1

2
merge_upstream.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
git fetch upstream && git merge upstream/master

21
my_configs.vim Normal file
View file

@ -0,0 +1,21 @@
" personal themes
set background=dark
colorscheme solarized
" tabspace = 2
autocmd FileType * set tabstop=2|set shiftwidth=2
" tab switch
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<cr>

1
sources_forked/emmet-vim/.gitignore vendored Executable file
View file

@ -0,0 +1 @@
/doc/tags

4
sources_forked/emmet-vim/.gitmodules vendored Executable file
View file

@ -0,0 +1,4 @@
[submodule "docs"]
path = docs
url = https://github.com/mattn/emmet-vim
branch = gh-pages

View file

@ -0,0 +1,11 @@
all : emmet-vim.zip
remove-zip:
-rm doc/tags
-rm emmet-vim.zip
emmet-vim.zip: remove-zip
zip -r emmet-vim.zip autoload plugin doc
release: emmet-vim.zip
vimup update-script emmet.vim

View file

@ -0,0 +1,149 @@
# Emmet-vim
[emmet-vim](http://mattn.github.com/emmet-vim) is a vim plug-in
which provides support for expanding abbreviations similar to
[emmet](http://emmet.io/).
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mattn/emmet-vim/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
![](https://raw.githubusercontent.com/mattn/emmet-vim/master/doc/screenshot.gif)
## Installation
[Download zip file](http://www.vim.org/scripts/script.php?script_id=2981):
cd ~/.vim
unzip emmet-vim.zip
To install using pathogen.vim:
cd ~/.vim/bundle
git clone https://github.com/mattn/emmet-vim.git
To install using [Vundle](https://github.com/gmarik/vundle):
" add this line to your .vimrc file
Plugin 'mattn/emmet-vim'
To checkout the source from repository:
cd ~/.vim/bundle
git clone https://github.com/mattn/emmet-vim.git
or:
git clone https://github.com/mattn/emmet-vim.git
cd emmet-vim
cp plugin/emmet.vim ~/.vim/plugin/
cp autoload/emmet.vim ~/.vim/autoload/
cp -a autoload/emmet ~/.vim/autoload/
## Quick Tutorial
Open or create a New File:
vim index.html
Type ("\_" is the cursor position):
html:5_
Then type `<c-y>,` (<kbd>Ctrl</kbd><kbd>y</kbd><kbd>,</kbd>), and you should see:
```html
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
_
</body>
</html>
```
[More Tutorials](https://raw.github.com/mattn/emmet-vim/master/TUTORIAL)
## Enable in different mode
If you don't want to enable emmet in all modes,
you can use set these options in `vimrc`:
```vim
let g:user_emmet_mode='n' "only enable normal mode functions.
let g:user_emmet_mode='inv' "enable all functions, which is equal to
let g:user_emmet_mode='a' "enable all function in all mode.
```
## Enable just for html/css
```vim
let g:user_emmet_install_global = 0
autocmd FileType html,css EmmetInstall
```
## Redefine trigger key
To remap the default `<C-Y>` leader:
```vim
let g:user_emmet_leader_key='<C-Z>'
```
Note that the trailing `,` still needs to be entered, so the new keymap would be `<C-Z>,`.
## Adding custom snippets
If you have installed the [web-api](https://github.com/mattn/webapi-vim) for **emmet-vim** you can also add your own snippets using a custom **snippets.json** file.
Once you have installed the [web-api](https://github.com/mattn/webapi-vim) add this line to your **.vimrc**:
```
let g:user_emmet_settings = webapi#json#decode(join(readfile(expand('~/.snippets_custom.json')), "\n"))
```
You can change the **path** to your **snippets_custom.json** according to your preferences.
[Here](http://docs.emmet.io/customization/snippets/) you can find instructions about creating your customized **snippets.json** file.
## Project Authors
[Yasuhiro Matsumoto](http://mattn.kaoriya.net/)
## Links
### Emmet official site:
* <http://emmet.io/>
### zen-coding official site:
* <http://code.google.com/p/zen-coding/>
### emmet.vim:
* <http://mattn.github.com/emmet-vim>
### development repository:
* <https://github.com/mattn/emmet-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>
### A Chinese translation of the tutorial:
* <http://www.zfanw.com/blog/zencoding-vim-tutorial-chinese.html>

0
sources_forked/emmet-vim/TODO Executable file
View file

212
sources_forked/emmet-vim/TUTORIAL Executable file
View file

@ -0,0 +1,212 @@
Tutorial for Emmet.vim
mattn <mattn.jp@gmail.com>
1. Expand an Abbreviation
Type the 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 an Abbreviation
Write as below.
---------------------
test1
test2
test3
---------------------
Then do visual select(line wise) and type '<c-y>,'.
Once you get to the 'Tag:' prompt, type 'ul>li*'.
---------------------
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
</ul>
---------------------
If you type a tag, such as 'blockquote', then you'll see the following:
---------------------
<blockquote>
test1
test2
test3
</blockquote>
---------------------
3. Balance a Tag Inward
type '<c-y>d' in insert mode.
4. Balance a Tag Outward
type '<c-y>D' in insert mode.
5. Go to the Next Edit Point
type '<c-y>n' in insert mode.
6. Go to the Previous Edit Point
type '<c-y>N' in insert mode.
7. Update an <img>s Size
Move cursor to the 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, which include '<li>'
---------------------
<ul>
<li class="list1"></li>
<li class="list2"></li>
<li class="list3"></li>
</ul>
---------------------
and then type '<c-y>m'
---------------------
<ul>
<li class="list1"></li><li class="list2"></li><li class="list3"></li>
</ul>
---------------------
9. Remove a 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 the cursor inside block
---------------------
<div class="foo">
cursor is here
</div>
---------------------
Type '<c-y>j' in insert mode.
---------------------
<div class="foo"/>
---------------------
And then type '<c-y>j' in there again.
---------------------
<div class="foo">
</div>
---------------------
11. Toggle Comment
Move cursor inside the 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 an anchor from a URL
Move cursor to URL
---------------------
http://www.google.com/
---------------------
Type '<c-y>a'
---------------------
<a href="http://www.google.com/">Google</a>
---------------------
13. Make some quoted text from a URL
Move cursor to the 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 emmet.vim for the language you are using:
# cd ~/.vim
# unzip emmet-vim.zip
Or if you are using pathogen.vim:
# cd ~/.vim/bundle # or make directory
# unzip /path/to/emmet-vim.zip
Or if you get the sources from the repository:
# cd ~/.vim/bundle # or make directory
# git clone http://github.com/mattn/emmet-vim.git
15. Enable emmet.vim for the language you using.
You can customize the behavior of the languages you are using.
---------------------
# cat >> ~/.vimrc
let g:user_emmet_settings = {
\ 'php' : {
\ 'extends' : 'html',
\ 'filters' : 'c',
\ },
\ 'xml' : {
\ 'extends' : 'html',
\ },
\ 'haml' : {
\ 'extends' : 'html',
\ },
\}
---------------------

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
let s:exists = {}
function! emmet#lang#exists(type) abort
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/emmet/lang/'.a:type.'.vim')) > 0
return s:exists[a:type]
endfunction

View file

@ -0,0 +1,350 @@
function! emmet#lang#css#findTokens(str) abort
let tmp = substitute(substitute(a:str, '^.*[;{]\s*', '', ''), '}\s*$', '', '')
if tmp =~ '/' && tmp =~ '^[a-zA-Z0-9/_.]\+$'
" maybe path or something
return ''
endif
return substitute(substitute(a:str, '^.*[;{]\s*', '', ''), '}\s*$', '', '')
endfunction
function! emmet#lang#css#parseIntoTree(abbr, type) abort
let abbr = a:abbr
let type = a:type
let prefix = 0
let value = ''
let indent = emmet#getIndentation(type)
let aliases = emmet#getResource(type, 'aliases', {})
let snippets = emmet#getResource(type, 'snippets', {})
let use_pipe_for_cursor = emmet#getResource(type, 'use_pipe_for_cursor', 1)
let root = emmet#newNode()
" emmet
let tokens = split(abbr, '+\ze[^+)!]')
let block = emmet#util#searchRegion('{', '}')
if abbr !~# '^@' && emmet#getBaseType(type) ==# 'css' && type !=# 'sass' && block[0] ==# [0,0] && block[1] ==# [0,0]
let current = emmet#newNode()
let current.snippet = substitute(abbr, '\s\+$', '', '') . " {\n" . indent . "${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.-]\+\%(p\|e\|em\|re\|rem\|%\)\{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 =~# '%$'
let value .= v
elseif v =~# 'e$'
let value .= substitute(v, 'e$', 'em', '')
elseif v =~# 'em$'
let value .= v
elseif v =~# 're$'
let value .= substitute(v, 're$', 'rem', '')
elseif v =~# 'rem$'
let value .= v
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')
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')
if len(vv) == 0
let pat = '^' . join(split(tag_name, '\zs'), '[^:]\{-}')
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat')
if len(vv) == 0
let pat = '^' . join(split(tag_name, '\zs'), '.\{-}')
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat')
endif
endif
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
let current.pos = 0
let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$')
if len(lg) == 0
let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*)$')
if len(lg)
let [lg[1], lg[2], lg[3]] = ['linear', lg[1], lg[2]]
endif
endif
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 = '-o-' . snippet . "\n"
call add(root.child, deepcopy(current))
let current.snippet = '-ms-' . snippet . "\n"
call add(root.child, deepcopy(current))
let current.snippet = snippet
call add(root.child, current)
elseif token =~# '^c#\([0-9a-fA-F]\{3}\|[0-9a-fA-F]\{6}\)\(\.[0-9]\+\)\?'
let cs = split(token, '\.')
let current.name = ''
let [r,g,b] = [0,0,0]
if len(cs[0]) == 5
let rgb = matchlist(cs[0], 'c#\(.\)\(.\)\(.\)')
let r = eval('0x'.rgb[1].rgb[1])
let g = eval('0x'.rgb[2].rgb[2])
let b = eval('0x'.rgb[3].rgb[3])
elseif len(cs[0]) == 8
let rgb = matchlist(cs[0], 'c#\(..\)\(..\)\(..\)')
let r = eval('0x'.rgb[1])
let g = eval('0x'.rgb[2])
let b = eval('0x'.rgb[3])
endif
if len(cs) == 1
let current.snippet = printf('color:rgb(%d, %d, %d);', r, g, b)
else
let current.snippet = printf('color:rgb(%d, %d, %d, %s);', r, g, b, string(str2float('0.'.cs[1])))
endif
call add(root.child, current)
elseif token =~# '^c#'
let current.name = ''
let current.snippet = 'color:\${cursor};'
call add(root.child, current)
else
call add(root.child, current)
endif
endfor
endif
return root
endfunction
function! emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) abort
let current = a:current
let value = current.value[1:-2]
let tmp = substitute(value, '\${cursor}', '', 'g')
if tmp !~ '.*{[ \t\r\n]*}$'
if emmet#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
endif
return value
endfunction
function! emmet#lang#css#imageSize() abort
let img_region = emmet#util#searchRegion('{', '}')
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region)
return
endif
let content = emmet#util#getContent(img_region)
let fn = matchstr(content, '\<url(\zs[^)]\+\ze)')
let fn = substitute(fn, '[''" \t]', '', 'g')
if fn =~# '^\s*$'
return
elseif fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn)
endif
let [width, height] = emmet#util#getImageSize(fn)
if width == -1 && height == -1
return
endif
let indent = emmet#getIndentation('css')
if content =~# '.*\<width\s*:[^;]*;.*'
let content = substitute(content, '\<width\s*:[^;]*;', 'width: ' . width . 'px;', '')
else
let content = substitute(content, '}', indent . 'width: ' . width . "px;\n}", '')
endif
if content =~# '.*\<height\s*:[^;]*;.*'
let content = substitute(content, '\<height\s*:[^;]*;', 'height: ' . height . 'px;', '')
else
let content = substitute(content, '}', indent . 'height: ' . height . "px;\n}", '')
endif
call emmet#util#setContent(img_region, content)
endfunction
function! emmet#lang#css#encodeImage() abort
endfunction
function! emmet#lang#css#parseTag(tag) abort
return {}
endfunction
function! emmet#lang#css#toggleComment() abort
let line = getline('.')
let mx = '^\(\s*\)/\*\s*\(.*\)\s*\*/\s*$'
if line =~# '{\s*$'
let block = emmet#util#searchRegion('/\*', '\*/\zs')
if emmet#util#regionIsValid(block)
let content = emmet#util#getContent(block)
let content = substitute(content, '/\*\s\(.*\)\s\*/', '\1', '')
call emmet#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! emmet#lang#css#balanceTag(flag) range abort
if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0]
else
let curpos = emmet#util#getcurpos()
endif
let block = emmet#util#getVisualBlock()
if !emmet#util#regionIsValid(block)
if a:flag > 0
let block = emmet#util#searchRegion('^', ';')
if emmet#util#regionIsValid(block)
call emmet#util#selectRegion(block)
return
endif
endif
else
if a:flag > 0
let content = emmet#util#getContent(block)
if content !~# '^{.*}$'
let block = emmet#util#searchRegion('{', '}')
if emmet#util#regionIsValid(block)
call emmet#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 = emmet#util#searchRegion('^', ';')
if emmet#util#regionIsValid(block)
call emmet#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! emmet#lang#css#moveNextPrevItem(flag) abort
return emmet#lang#css#moveNextPrev(a:flag)
endfunction
function! emmet#lang#css#moveNextPrev(flag) abort
let pos = search('""\|()\|\(:\s*\zs$\)', a:flag ? 'Wbp' : 'Wp')
if pos == 2
startinsert!
else
silent! normal! l
startinsert
endif
endfunction
function! emmet#lang#css#splitJoinTag() abort
" nothing to do
endfunction
function! emmet#lang#css#removeTag() abort
" nothing to do
endfunction

View file

@ -0,0 +1,334 @@
function! emmet#lang#haml#findTokens(str) abort
return emmet#lang#html#findTokens(a:str)
endfunction
function! emmet#lang#haml#parseIntoTree(abbr, type) abort
return emmet#lang#html#parseIntoTree(a:abbr, a:type)
endfunction
function! emmet#lang#haml#toString(settings, current, type, inline, filters, itemno, indent) abort
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 = emmet#getIndentation(type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
let attribute_style = emmet#getResource('haml', 'attribute_style', 'hash')
let str = ''
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 emmet#util#unique(current.attrs_order + keys(current.attr))
if !has_key(current.attr, attr)
continue
endif
let Val = current.attr[attr]
if type(Val) == 2 && Val == function('emmet#types#true')
if attribute_style ==# 'hash'
let tmp .= ' :' . attr . ' => true'
elseif attribute_style ==# 'html'
let tmp .= attr . '=true'
end
else
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
if attribute_style ==# 'hash'
let tmp .= ','
elseif attribute_style ==# 'html'
let tmp .= ' '
endif
endif
if attribute_style ==# 'hash'
let tmp .= ' :' . attr . ' => "' . Val . '"'
elseif attribute_style ==# 'html'
let tmp .= attr . '="' . Val . '"'
end
endif
endif
endfor
if len(tmp)
if attribute_style ==# 'hash'
let str .= '{' . tmp . ' }'
elseif attribute_style ==# 'html'
let str .= '(' . tmp . ')'
end
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 .= emmet#toString(child, type, inline, filters, itemno, indent)
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! emmet#lang#haml#imageSize() abort
let line = getline('.')
let current = emmet#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] = emmet#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 = emmet#toString(current, 'haml', 1)
let haml = substitute(haml, '\${cursor}', '', '')
call setline('.', substitute(matchstr(line, '^\s*') . haml, "\n", '', 'g'))
endfunction
function! emmet#lang#haml#encodeImage() abort
endfunction
function! emmet#lang#haml#parseTag(tag) abort
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', '')
let attrs = substitute(match, mx, '\2', '')
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! emmet#lang#haml#toggleComment() abort
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! emmet#lang#haml#balanceTag(flag) range abort
let block = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0]
else
let curpos = emmet#util#getcurpos()
endif
let n = curpos[1]
let ml = len(matchstr(getline(n), '^\s*'))
if a:flag > 0
if a:flag == 1 || !emmet#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! emmet#lang#haml#moveNextPrevItem(flag) abort
return emmet#lang#haml#moveNextPrev(a:flag)
endfunction
function! emmet#lang#haml#moveNextPrev(flag) abort
let pos = search('""', a:flag ? 'Wb' : 'W')
if pos != 0
silent! normal! l
startinsert
endif
endfunction
function! emmet#lang#haml#splitJoinTag() abort
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 = emmet#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! emmet#lang#haml#removeTag() abort
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

View file

@ -0,0 +1,947 @@
let s:bx = '{\%("[^"]*"\|''[^'']*''\|\$#\|\${\w\+}\|\$\+\|{[^{]\+\|[^{}]\)\{-}}'
let s:mx = '\([+>]\|[<^]\+\)\{-}\s*'
\ .'\((*\)\{-}\s*'
\ .'\([@#.]\{-}[a-zA-Z_\!][a-zA-Z0-9:_\!\-$]*\|' . s:bx . '\|\[[^\]]\+\]\)'
\ .'\('
\ .'\%('
\ .'\%(#{[{}a-zA-Z0-9_\-\$]\+\|#[a-zA-Z0-9_\-\$]\+\)'
\ .'\|\%(\[\%("[^"]*"\|[^"\]]*\)\+\]\)'
\ .'\|\%(\.{[{}a-zA-Z0-9_\-\$]\+\|\.[a-zA-Z0-9_\-\$]\+\)'
\ .'\)*'
\ .'\)'
\ .'\%(\(' . s:bx . '\+\)\)\{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) abort
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
while 1
let tag = matchstr(str, '{%[^%]\{-}%}', 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
let str = a:str[last_pos :-1]
if str =~# '^\w\+="[^"]*$'
return ''
endif
return str
endfunction
function! emmet#lang#html#parseIntoTree(abbr, type) abort
let abbr = a:abbr
let type = a:type
let settings = emmet#getSettings()
if !has_key(settings, type)
let type = 'html'
endif
if len(type) == 0 | let type = 'html' | endif
let indent = emmet#getIndentation(type)
let pmap = {
\'p': 'span',
\'ul': 'li',
\'ol': 'li',
\'table': 'tr',
\'tr': 'td',
\'tbody': 'tr',
\'thead': 'tr',
\'tfoot': 'tr',
\'colgroup': 'col',
\'select': 'option',
\'optgroup': 'option',
\'audio': 'source',
\'video': 'source',
\'object': 'param',
\'map': 'area'
\}
let inlineLevel = split('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var',',')
let custom_expands = emmet#getResource(type, 'custom_expands', {})
if empty(custom_expands) && has_key(settings, 'custom_expands')
let custom_expands = settings['custom_expands']
endif
" try 'foo' to (foo-x)
let rabbr = emmet#getExpandos(type, abbr)
if rabbr == abbr
" try 'foo+(' to (foo-x)
let rabbr = substitute(abbr, '\%(+\|^\)\([a-zA-Z][a-zA-Z0-9+]\+\)+\([(){}>]\|$\)', '\="(".emmet#getExpandos(type, submatch(1)).")".submatch(2)', 'i')
endif
let abbr = rabbr
let root = emmet#newNode()
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 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 custom = ''
let important = 0
if len(str) == 0
break
endif
if tag_name =~# '^#'
let attributes = tag_name . attributes
let tag_name = ''
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 = ''
endif
if tag_name =~# '^\[.*\]$'
let attributes = tag_name . attributes
let tag_name = ''
endif
for k in keys(custom_expands)
if tag_name =~ k
let custom = tag_name
let tag_name = ''
break
endif
endfor
if empty(tag_name)
let pname = len(parent.child) > 0 ? parent.child[0].name : ''
if !empty(pname) && has_key(pmap, pname)
let tag_name = pmap[pname]
elseif !empty(pname) && index(inlineLevel, pname) > -1
let tag_name = 'span'
elseif len(parent.child) == 0 || len(custom) == 0
let tag_name = 'div'
else
let tag_name = custom
endif
endif
let basedirect = basevalue[1] ==# '-' ? -1 : 1
let basevalue = 0 + abs(basevalue[1:])
if multiplier <= 0 | let multiplier = 1 | endif
" make default node
let current = emmet#newNode()
let current.name = tag_name
let current.important = important
" aliases
let aliases = emmet#getResource(type, 'aliases', {})
if has_key(aliases, tag_name)
let current.name = aliases[tag_name]
endif
let use_pipe_for_cursor = emmet#getResource(type, 'use_pipe_for_cursor', 1)
" snippets
let snippets = emmet#getResource(type, 'snippets', {})
if !empty(snippets)
let snippet_name = tag_name
if has_key(snippets, snippet_name)
let snippet = snippet_name
while has_key(snippets, snippet)
let snippet = snippets[snippet]
endwhile
if use_pipe_for_cursor
let snippet = substitute(snippet, '|', '${cursor}', 'g')
endif
" just redirect to expanding
if type == 'html' && snippet !~ '^\s*[{\[<]'
return emmet#lang#html#parseIntoTree(snippet, a:type)
endif
let lines = split(snippet, "\n", 1)
call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")')
let current.snippet = join(lines, "\n")
let current.name = ''
endif
endif
for k in keys(custom_expands)
if tag_name =~# k
let current.snippet = '${' . (empty(custom) ? tag_name : custom) . '}'
let current.name = ''
break
elseif custom =~# k
let current.snippet = '${' . custom . '}'
let current.name = ''
break
endif
endfor
" default_attributes
let default_attributes = emmet#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 g:emmet_debug > 1
echomsg 'attr=' . item
endif
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]
if matchstr(atts, '^\s*\zs[0-9a-zA-Z_\-:]\+\(="[^"]*"\|=''[^'']*''\|=[^ ''"]\+\)') ==# ''
let ks = []
if has_key(default_attributes, current.name)
let dfa = default_attributes[current.name]
let ks = type(dfa) == 3 ? keys(dfa[0]) : keys(dfa)
endif
if len(ks) == 0 && has_key(default_attributes, current.name . ':src')
let ks = keys(default_attributes[current.name . ':src'])
endif
if len(ks) > 0
let current.attr[ks[0]] = atts
else
let current.attr[atts] = ''
endif
else
while len(atts)
let amat = matchstr(atts, '^\s*\zs\([0-9a-zA-Z-:]\+\%(="[^"]*"\|=''[^'']*''\|=[^ ''"]\+\|[^ ''"\]]*\)\{0,1}\)')
if len(amat) == 0
break
endif
let key = split(amat, '=')[0]
let Val = amat[len(key)+1:]
if key =~# '\.$' && Val ==# ''
let key = key[:-2]
unlet Val
let Val = function('emmet#types#true')
elseif Val =~# '^["'']'
let Val = Val[1:-2]
endif
let current.attr[key] = Val
if index(current.attrs_order, key) == -1
let current.attrs_order += [key]
endif
let atts = atts[stridx(atts, amat) + len(amat):]
unlet Val
endwhile
endif
endif
let attr = substitute(strpart(attr, len(item)), '^\s*', '', '')
endwhile
endif
" parse text
if tag_name =~# '^{.*}$'
let current.name = ''
let current.value = tag_name
else
let current.value = value
endif
let current.basedirect = basedirect
let current.basevalue = basevalue
let current.multiplier = multiplier
" parse step inside/outside
if !empty(last)
if operator =~# '>'
unlet! parent
let parent = last
let current.parent = last
let current.pos = last.pos + 1
else
let current.parent = parent
let current.pos = last.pos
endif
else
let current.parent = parent
let current.pos = 1
endif
if operator =~# '[<^]'
for c in range(len(operator))
let tmp = parent.parent
if empty(tmp)
break
endif
let parent = tmp
let current.parent = tmp
endfor
endif
call add(parent.child, current)
let last = current
" parse block
if block_start =~# '('
if operator =~# '>'
let last.pos += 1
endif
let last.block = 1
for n in range(len(block_start))
let pos += [last.pos]
endfor
endif
if block_end =~# ')'
for n in split(substitute(substitute(block_end, ' ', '', 'g'), ')', ',),', 'g'), ',')
if n ==# ')'
if len(pos) > 0 && last.pos >= pos[-1]
for c in range(last.pos - pos[-1])
let tmp = parent.parent
if !has_key(tmp, 'parent')
break
endif
let parent = tmp
endfor
if len(pos) > 0
call remove(pos, -1)
endif
let last = parent
let last.pos += 1
endif
elseif len(n)
let st = 0
for nc in range(len(last.child))
if last.child[nc].block
let st = nc
break
endif
endfor
let cl = last.child[st :]
let cls = []
for c in range(n[1:])
for cc in cl
if cc.multiplier > 1
let cc.basedirect = c + 1
else
let cc.basevalue = c + 1
endif
endfor
let cls += deepcopy(cl)
endfor
if st > 0
let last.child = last.child[:st-1] + cls
else
let last.child = cls
endif
endif
endfor
endif
let abbr = abbr[stridx(abbr, match) + len(match):]
if g:emmet_debug > 1
echomsg 'str='.str
echomsg 'block_start='.block_start
echomsg 'tag_name='.tag_name
echomsg 'operator='.operator
echomsg 'attributes='.attributes
echomsg 'value='.value
echomsg 'basevalue='.basevalue
echomsg 'multiplier='.multiplier
echomsg 'block_end='.block_end
echomsg 'abbr='.abbr
echomsg 'pos='.string(pos)
echomsg '---'
endif
endwhile
return root
endfunction
function! s:dollar_add(base,no) abort
if a:base > 0
return a:base + a:no - 1
elseif a:base < 0
return a:base - a:no + 1
else
return a:no
endif
endfunction
function! emmet#lang#html#toString(settings, current, type, inline, filters, itemno, indent) abort
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 = emmet#getResource(type, 'dollar_expr', 1)
let q = emmet#getResource(type, 'quote_char', '"')
let ct = emmet#getResource(type, 'comment_type', 'both')
let an = emmet#getResource(type, 'attribute_name', {})
if emmet#useFilter(filters, 'haml')
return emmet#lang#haml#toString(settings, current, type, inline, filters, itemno, indent)
endif
if emmet#useFilter(filters, 'slim')
return emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent)
endif
let comment = ''
let current_name = current.name
if dollar_expr
let current_name = substitute(current_name, '\$$', itemno+1, '')
endif
let str = ''
if len(current_name) == 0
let text = current.value[1:-2]
if dollar_expr
" TODO: regexp engine specified
let nr = itemno + 1
if exists('&regexpengine')
let text = substitute(text, '\%#=1\%(\\\)\@\<!\(\$\+\)\(@-\?[0-9]\+\)\{0,1}\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d",s:dollar_add(submatch(2)[1:],nr)).submatch(3)', 'g')
else
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\(@-\?[0-9]\+\)\{0,1}\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d",s:dollar_add(submatch(2)[1:],nr).submatch(3)', 'g')
endif
let text = substitute(text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g')
endif
return text
endif
if len(current_name) > 0
let str .= '<' . current_name
endif
for attr in emmet#util#unique(current.attrs_order + keys(current.attr))
if !has_key(current.attr, attr)
continue
endif
let Val = current.attr[attr]
if type(Val) == 2 && Val == function('emmet#types#true')
unlet Val
let Val = 'true'
if g:emmet_html5
let str .= ' ' . attr
else
let str .= ' ' . attr . '=' . q . attr . q
endif
if emmet#useFilter(filters, 'c')
if attr ==# 'id' | let comment .= '#' . Val | endif
if attr ==# 'class' | let comment .= '.' . Val | endif
endif
else
if dollar_expr
while Val =~# '\$\([^#{]\|$\)'
" TODO: regexp engine specified
if exists('&regexpengine')
let Val = substitute(Val, '\%#=1\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
else
let Val = substitute(Val, '\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endif
endwhile
let attr = substitute(attr, '\$$', itemno+1, '')
endif
if attr ==# 'class' && emmet#useFilter(filters, 'bem')
let vals = split(Val, '\s\+')
let Val = ''
let lead = ''
for _val in vals
if len(Val) > 0
let Val .= ' '
endif
if _val =~# '^_'
if has_key(current.parent.attr, 'class')
let lead = current.parent.attr["class"]
if _val =~# '^__'
let Val .= lead . _val
else
let Val .= lead . ' ' . lead . _val
endif
else
let lead = split(vals[0], '_')[0]
let Val .= lead . _val
endif
elseif _val =~# '^-'
for l in split(_val, '_')
if len(Val) > 0
let Val .= ' '
endif
let l = substitute(l, '^-', '__', '')
if len(lead) == 0
let pattr = current.parent.attr
if has_key(pattr, 'class')
let lead = split(pattr['class'], '\s\+')[0]
endif
endif
let Val .= lead . l
let lead .= l . '_'
endfor
else
let Val .= _val
endif
endfor
endif
if has_key(an, attr)
let attr = an[attr]
endif
if emmet#isExtends(type, 'jsx') && Val =~ '^{.*}$'
let str .= ' ' . attr . '=' . Val
else
let str .= ' ' . attr . '=' . q . Val . q
endif
if emmet#useFilter(filters, 'c')
if attr ==# 'id' | let comment .= '#' . Val | endif
if attr ==# 'class' | let comment .= '.' . Val | endif
endif
endif
unlet Val
endfor
if len(comment) > 0 && ct ==# 'both'
let str = '<!-- ' . comment . " -->\n" . str
endif
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1
let str .= settings.html.empty_element_suffix
else
let str .= '>'
let text = current.value[1:-2]
if dollar_expr
" TODO: regexp engine specified
let nr = itemno + 1
if exists('&regexpengine')
let text = substitute(text, '\%#=1\%(\\\)\@\<!\(\$\+\)\(@-\?[0-9]\+\)\{0,1}\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d",s:dollar_add(submatch(2)[1:],nr)).submatch(3)', 'g')
else
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\(@-\?[0-9]\+\)\{0,1}\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d",s:dollar_add(submatch(2)[1:],nr)).submatch(3)', 'g')
endif
let text = substitute(text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g')
if text != ''
let str = substitute(str, '\("\zs$#\ze"\|\s\zs\$#"\|"\$#\ze\s\)', text, 'g')
endif
endif
let str .= text
let nc = len(current.child)
let dr = 0
if nc > 0
for n in range(nc)
let child = current.child[n]
if child.multiplier > 1
let str .= "\n" . indent
let dr = 1
elseif len(current_name) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1
if nc > 1 || (len(child.name) > 0 && stridx(','.settings.html.inline_elements.',', ','.child.name.',') == -1)
let str .= "\n" . indent
let dr = 1
elseif current.multiplier == 1 && nc == 1 && len(child.name) == 0
let str .= "\n" . indent
let dr = 1
endif
endif
let inner = emmet#toString(child, type, 0, filters, itemno, indent)
let inner = substitute(inner, "^\n", '', 'g')
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
let str .= inner
endfor
else
if settings.html.indent_blockelement && len(current_name) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1
let str .= "\n" . indent . '${cursor}' . "\n"
else
let str .= '${cursor}'
endif
endif
if dr
let str .= "\n"
endif
let str .= '</' . current_name . '>'
endif
if len(comment) > 0
if ct ==# 'lastonly'
let str .= '<!-- ' . comment . ' -->'
else
let str .= "\n<!-- /" . comment . ' -->'
endif
endif
if len(current_name) > 0 && current.multiplier > 0 || stridx(','.settings.html.block_elements.',', ','.current_name.',') != -1
let str .= "\n"
endif
return str
endfunction
function! emmet#lang#html#imageSize() abort
let img_region = emmet#util#searchRegion('<img\s', '>')
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region)
return
endif
let content = emmet#util#getContent(img_region)
if content !~# '^<img[^><]\+>$'
return
endif
let current = emmet#lang#html#parseTag(content)
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] = emmet#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 html = substitute(emmet#toString(current, 'html', 1), '\n', '', '')
let html = substitute(html, '\${cursor}', '', '')
call emmet#util#setContent(img_region, html)
endfunction
function! emmet#lang#html#encodeImage() abort
let img_region = emmet#util#searchRegion('<img\s', '>')
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region)
return
endif
let content = emmet#util#getContent(img_region)
if content !~# '^<img[^><]\+>$'
return
endif
let current = emmet#lang#html#parseTag(content)
if empty(current) || !has_key(current.attr, 'src')
return
endif
let fn = current.attr.src
if fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn)
endif
let [width, height] = emmet#util#getImageSize(fn)
if width == -1 && height == -1
return
endif
let current.attr.width = width
let current.attr.height = height
let html = emmet#toString(current, 'html', 1)
call emmet#util#setContent(img_region, html)
endfunction
function! emmet#lang#html#parseTag(tag) abort
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')
let attrs = substitute(match, mx, '\2', 'i')
let mx = '\([a-zA-Z0-9]\+\)=\%(\([^"'' \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! emmet#lang#html#toggleComment() abort
let orgpos = getpos('.')
let curpos = getpos('.')
let mx = '<\%#[^>]*>'
while 1
let block = emmet#util#searchRegion('<!--', '-->')
if emmet#util#regionIsValid(block)
let block[1][1] += 2
let content = emmet#util#getContent(block)
let content = substitute(content, '^<!--\s\(.*\)\s-->$', '\1', '')
call emmet#util#setContent(block, content)
silent! call setpos('.', orgpos)
return
endif
let block = emmet#util#searchRegion('<[^>]', '>')
if !emmet#util#regionIsValid(block)
let pos1 = searchpos('<', 'bcW')
if pos1[0] == 0 && pos1[1] == 0
return
endif
let curpos = getpos('.')
continue
endif
let pos1 = block[0]
let pos2 = block[1]
let content = emmet#util#getContent(block)
let tag_name = matchstr(content, '^<\zs/\{0,1}[^ \r\n>]\+')
if tag_name[0] ==# '/'
call setpos('.', [0, pos1[0], pos1[1], 0])
let pos2 = searchpairpos('<'. tag_name[1:] . '\>[^>]*>', '', '</' . tag_name[1:] . '>', 'bnW')
let pos1 = searchpos('>', 'cneW')
let block = [pos2, pos1]
elseif tag_name =~# '/$'
if !emmet#util#pointInRegion(orgpos[1:2], block)
" it's broken tree
call setpos('.', orgpos)
let block = emmet#util#searchRegion('>', '<')
let content = '><!-- ' . emmet#util#getContent(block)[1:-2] . ' --><'
call emmet#util#setContent(block, content)
silent! call setpos('.', orgpos)
return
endif
else
call setpos('.', [0, pos2[0], pos2[1], 0])
let pos3 = searchpairpos('<'. tag_name . '\>[^>]*>', '', '</' . tag_name . '>', 'nW')
if pos3 == [0, 0]
let block = [pos1, pos2]
else
call setpos('.', [0, pos3[0], pos3[1], 0])
let pos2 = searchpos('>', 'neW')
let block = [pos1, pos2]
endif
endif
if !emmet#util#regionIsValid(block)
silent! call setpos('.', orgpos)
return
endif
if emmet#util#pointInRegion(curpos[1:2], block)
let content = '<!-- ' . emmet#util#getContent(block) . ' -->'
call emmet#util#setContent(block, content)
silent! call setpos('.', orgpos)
return
endif
endwhile
endfunction
function! emmet#lang#html#balanceTag(flag) range abort
let vblock = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0]
else
let curpos = emmet#util#getcurpos()
endif
let settings = emmet#getSettings()
if a:flag > 0
let mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*'
let last = curpos[1:2]
while 1
let pos1 = searchpos(mx, 'bW')
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
let tag_name = matchstr(content, '^<\zs[a-zA-Z0-9:_\-]*\ze')
if stridx(','.settings.html.empty_elements.',', ','.tag_name.',') != -1
let pos2 = searchpos('>', 'nW')
else
let pos2 = searchpairpos('<' . tag_name . '[^>]*>', '', '</'. tag_name . '\zs>', 'nW')
endif
let block = [pos1, pos2]
if pos1[0] == 0 && pos1[1] == 0
break
endif
if emmet#util#pointInRegion(last, block) && emmet#util#regionIsValid(block)
call emmet#util#selectRegion(block)
return
endif
if pos1 == last
break
endif
let last = pos1
endwhile
else
let mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
while 1
let pos1 = searchpos(mx, 'W')
if pos1 == curpos[1:2]
let pos1 = searchpos(mx . '\zs', 'W')
let pos2 = searchpos('.\ze<', 'W')
let block = [pos1, pos2]
if emmet#util#regionIsValid(block)
call emmet#util#selectRegion(block)
return
endif
endif
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
let tag_name = matchstr(content, '^<\zs[a-zA-Z0-9:_\-]*\ze')
if stridx(','.settings.html.empty_elements.',', ','.tag_name.',') != -1
let pos2 = searchpos('>', 'nW')
else
let pos2 = searchpairpos('<' . tag_name . '[^>]*>', '', '</'. tag_name . '\zs>', 'nW')
endif
let block = [pos1, pos2]
if pos1[0] == 0 && pos1[1] == 0
break
endif
if emmet#util#regionIsValid(block)
call emmet#util#selectRegion(block)
return
endif
endwhile
endif
if a:flag == -2 || a:flag == 2
silent! exe 'normal! gv'
else
call setpos('.', curpos)
endif
endfunction
function! emmet#lang#html#moveNextPrevItem(flag) abort
silent! exe "normal \<esc>"
let mx = '\%([0-9a-zA-Z-:]\+\%(="[^"]*"\|=''[^'']*''\|[^ ''">\]]*\)\{0,1}\)'
let pos = searchpos('\s'.mx.'\zs', '')
if pos != [0,0]
call feedkeys('v?\s\zs'.mx."\<cr>", '')
endif
endfunction
function! emmet#lang#html#moveNextPrev(flag) abort
let pos = search('\%(</\w\+\)\@<!\zs><\/\|\(""\)\|^\(\s*\)$', a:flag ? 'Wpb' : 'Wp')
if pos == 3
startinsert!
elseif pos != 0
silent! normal! l
startinsert
endif
endfunction
function! emmet#lang#html#splitJoinTag() abort
let curpos = emmet#util#getcurpos()
while 1
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
let pos1 = searchpos(mx, 'bcnW')
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\).*$', '\1', '')
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
if content[-2:] ==# '/>' && emmet#util#cursorInRegion(block)
let content = substitute(content[:-3], '\s*$', '', '') . '></' . tag_name . '>'
call emmet#util#setContent(block, content)
call setpos('.', [0, block[0][0], block[0][1], 0])
return
else
if tag_name[0] ==# '/'
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
call setpos('.', [0, pos1[0], pos1[1], 0])
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
else
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
endif
let block = [pos1, pos2]
let content = emmet#util#getContent(block)
if emmet#util#pointInRegion(curpos[1:2], block) && content[1:] !~# '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
let content = matchstr(content, mx)[:-2] . ' />'
call emmet#util#setContent(block, content)
call setpos('.', [0, block[0][0], block[0][1], 0])
return
else
if block[0][0] > 0
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
else
call setpos('.', curpos)
return
endif
endif
endif
endwhile
endfunction
function! emmet#lang#html#removeTag() abort
let curpos = emmet#util#getcurpos()
while 1
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*'
let pos1 = searchpos(mx, 'bcnW')
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
let tag_name = matchstr(content, '^<\zs/\{0,1}[a-zA-Z0-9:_\-]*')
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
if content[-2:] ==# '/>' && emmet#util#cursorInRegion(block)
call emmet#util#setContent(block, '')
call setpos('.', [0, block[0][0], block[0][1], 0])
return
else
if tag_name[0] ==# '/'
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
call setpos('.', [0, pos1[0], pos1[1], 0])
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
else
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
endif
let block = [pos1, pos2]
let content = emmet#util#getContent(block)
if emmet#util#pointInRegion(curpos[1:2], block) && content[1:] !~# '^<' . tag_name . '[^a-zA-Z0-9]'
call emmet#util#setContent(block, '')
call setpos('.', [0, block[0][0], block[0][1], 0])
return
else
if block[0][0] > 0
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
else
call setpos('.', curpos)
return
endif
endif
endif
endwhile
endfunction

View file

@ -0,0 +1,331 @@
function! emmet#lang#jade#findTokens(str) abort
return emmet#lang#html#findTokens(a:str)
endfunction
function! emmet#lang#jade#parseIntoTree(abbr, type) abort
return emmet#lang#html#parseIntoTree(a:abbr, a:type)
endfunction
function! emmet#lang#jade#toString(settings, current, type, inline, filters, itemno, indent) abort
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 = emmet#getIndentation(type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
let attribute_style = emmet#getResource('jade', 'attribute_style', 'hash')
let str = ''
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 emmet#util#unique(current.attrs_order + keys(current.attr))
if !has_key(current.attr, attr)
continue
endif
let Val = current.attr[attr]
if type(Val) == 2 && Val == function('emmet#types#true')
if attribute_style ==# 'hash'
let tmp .= ' ' . attr . ' = true'
elseif attribute_style ==# 'html'
let tmp .= attr . '=true'
end
else
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
if attribute_style ==# 'hash'
let tmp .= ', '
elseif attribute_style ==# 'html'
let tmp .= ' '
endif
endif
if attribute_style ==# 'hash'
let tmp .= '' . attr . '="' . Val . '"'
elseif attribute_style ==# 'html'
let tmp .= attr . '="' . Val . '"'
end
endif
endif
endfor
if len(tmp)
if attribute_style ==# 'hash'
let str .= '(' . tmp . ')'
elseif attribute_style ==# 'html'
let str .= '(' . tmp . ')'
end
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 .= emmet#toString(child, type, inline, filters, itemno, indent)
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! emmet#lang#jade#imageSize() abort
let line = getline('.')
let current = emmet#lang#jade#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] = emmet#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 jade = emmet#toString(current, 'jade', 1)
let jade = substitute(jade, '\${cursor}', '', '')
call setline('.', substitute(matchstr(line, '^\s*') . jade, "\n", '', 'g'))
endfunction
function! emmet#lang#jade#encodeImage() abort
endfunction
function! emmet#lang#jade#parseTag(tag) abort
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', '')
let attrs = substitute(match, mx, '\2', '')
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! emmet#lang#jade#toggleComment() abort
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! emmet#lang#jade#balanceTag(flag) range abort
let block = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0]
else
let curpos = emmet#util#getcurpos()
endif
let n = curpos[1]
let ml = len(matchstr(getline(n), '^\s*'))
if a:flag > 0
if a:flag == 1 || !emmet#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! emmet#lang#jade#moveNextPrevItem(flag) abort
return emmet#lang#jade#moveNextPrev(a:flag)
endfunction
function! emmet#lang#jade#moveNextPrev(flag) abort
let pos = search('""', a:flag ? 'Wb' : 'W')
if pos != 0
silent! normal! l
startinsert
endif
endfunction
function! emmet#lang#jade#splitJoinTag() abort
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 = emmet#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! emmet#lang#jade#removeTag() abort
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

View file

@ -0,0 +1,47 @@
function! emmet#lang#less#findTokens(str) abort
return emmet#lang#html#findTokens(a:str)
endfunction
function! emmet#lang#less#parseIntoTree(abbr, type) abort
return emmet#lang#scss#parseIntoTree(a:abbr, a:type)
endfunction
function! emmet#lang#less#toString(settings, current, type, inline, filters, itemno, indent) abort
return emmet#lang#scss#toString(a:settings, a:current, a:type, a:inline, a:filters, a:itemno, a:indent)
endfunction
function! emmet#lang#less#imageSize() abort
call emmet#lang#css#imageSize()
endfunction
function! emmet#lang#less#encodeImage() abort
return emmet#lang#css#encodeImage()
endfunction
function! emmet#lang#less#parseTag(tag) abort
return emmet#lang#css#parseTag(a:tag)
endfunction
function! emmet#lang#less#toggleComment() abort
call emmet#lang#css#toggleComment()
endfunction
function! emmet#lang#less#balanceTag(flag) range abort
call emmet#lang#scss#balanceTag(a:flag)
endfunction
function! emmet#lang#less#moveNextPrevItem(flag) abort
return emmet#lang#less#moveNextPrev(a:flag)
endfunction
function! emmet#lang#less#moveNextPrev(flag) abort
call emmet#lang#scss#moveNextPrev(a:flag)
endfunction
function! emmet#lang#less#splitJoinTag() abort
call emmet#lang#css#splitJoinTag()
endfunction
function! emmet#lang#less#removeTag() abort
call emmet#lang#css#removeTag()
endfunction

View file

@ -0,0 +1,160 @@
function! emmet#lang#sass#findTokens(str) abort
return emmet#lang#css#findTokens(a:str)
endfunction
function! emmet#lang#sass#parseIntoTree(abbr, type) abort
return emmet#lang#html#parseIntoTree(a:abbr, a:type)
endfunction
function! emmet#lang#sass#toString(settings, current, type, inline, filters, itemno, indent) abort
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 str = ''
let current_name = current.name
let current_name = substitute(current.name, '\$$', itemno+1, '')
if len(current.name) > 0
let str .= current_name
let tmp = ''
for attr in keys(current.attr)
let val = current.attr[attr]
while val =~# '\$\([^#{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile
let attr = substitute(attr, '\$$', itemno+1, '')
if attr ==# 'id'
let str .= '#' . val
elseif attr ==# 'class'
let str .= '.' . val
else
let tmp .= attr . ': ' . val
endif
endfor
if len(tmp) > 0
let str .= "\n"
for line in split(tmp, "\n")
let str .= indent . line . "\n"
endfor
else
let str .= "\n"
endif
let inner = ''
for child in current.child
let tmp = emmet#toString(child, type, inline, filters, itemno, indent)
let tmp = substitute(tmp, "\n", "\n" . escape(indent, '\'), 'g')
let tmp = substitute(tmp, "\n" . escape(indent, '\') . '$', '${cursor}\n', 'g')
let inner .= tmp
endfor
if len(inner) > 0
let str .= indent . inner
endif
else
let text = emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
let text = substitute(text, '\s*;\ze\(\${[^}]\+}\)\?\(\n\|$\)', '', 'g')
return text
endif
return str
endfunction
function! emmet#lang#sass#imageSize() abort
endfunction
function! emmet#lang#sass#encodeImage() abort
endfunction
function! emmet#lang#sass#parseTag(tag) abort
endfunction
function! emmet#lang#sass#toggleComment() abort
endfunction
function! emmet#lang#sass#balanceTag(flag) range abort
let block = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0]
else
let curpos = emmet#util#getcurpos()
endif
let n = curpos[1]
let ml = len(matchstr(getline(n), '^\s*'))
if a:flag > 0
if a:flag == 1 || !emmet#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! emmet#lang#sass#moveNextPrevItem(flag) abort
return emmet#lang#sass#moveNextPrev(a:flag)
endfunction
function! emmet#lang#sass#moveNextPrev(flag) abort
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
if pos == 2
startinsert!
elseif pos != 0
silent! normal! l
startinsert
endif
endfunction
function! emmet#lang#sass#splitJoinTag() abort
endfunction
function! emmet#lang#sass#removeTag() abort
endfunction

View file

@ -0,0 +1,125 @@
function! emmet#lang#scss#findTokens(str) abort
return emmet#lang#css#findTokens(a:str)
endfunction
function! emmet#lang#scss#parseIntoTree(abbr, type) abort
if a:abbr =~# '>'
return emmet#lang#html#parseIntoTree(a:abbr, a:type)
else
return emmet#lang#css#parseIntoTree(a:abbr, a:type)
endif
endfunction
function! emmet#lang#scss#toString(settings, current, type, inline, filters, itemno, indent) abort
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 str = ''
let current_name = substitute(current.name, '\$$', itemno+1, '')
if len(current.name) > 0
let str .= current_name
let tmp = ''
for attr in keys(current.attr)
let val = current.attr[attr]
while val =~# '\$\([^#{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile
let attr = substitute(attr, '\$$', itemno+1, '')
if attr ==# 'id'
let str .= '#' . val
elseif attr ==# 'class'
let str .= '.' . val
else
let tmp .= attr . ': ' . val . ';'
endif
endfor
if len(tmp) > 0
let str .= " {\n"
for line in split(tmp, "\n")
let str .= indent . line . "\n"
endfor
else
let str .= " {\n"
endif
let inner = ''
for child in current.child
let inner .= emmet#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 .= indent . inner . "${cursor}\n}\n"
else
return emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
endif
return str
endfunction
function! emmet#lang#scss#imageSize() abort
call emmet#lang#css#imageSize()
endfunction
function! emmet#lang#scss#encodeImage() abort
return emmet#lang#css#encodeImage()
endfunction
function! emmet#lang#scss#parseTag(tag) abort
return emmet#lang#css#parseTag(a:tag)
endfunction
function! emmet#lang#scss#toggleComment() abort
call emmet#lang#css#toggleComment()
endfunction
function! emmet#lang#scss#balanceTag(flag) range abort
if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0]
call setpos('.', curpos)
else
let curpos = emmet#util#getcurpos()
endif
if a:flag < 0
let ret = searchpair('}', '', '.\zs{')
else
let ret = searchpair('{', '', '}', 'bW')
endif
if ret > 0
let pos1 = emmet#util#getcurpos()[1:2]
if a:flag < 0
let pos2 = searchpairpos('{', '', '}')
else
let pos2 = searchpairpos('{', '', '}')
endif
let block = [pos1, pos2]
if emmet#util#regionIsValid(block)
call emmet#util#selectRegion(block)
return
endif
endif
if a:flag == -2 || a:flag == 2
silent! exe 'normal! gv'
else
call setpos('.', curpos)
endif
endfunction
function! emmet#lang#scss#moveNextPrevItem(flag) abort
return emmet#lang#scss#moveNextPrev(a:flag)
endfunction
function! emmet#lang#scss#moveNextPrev(flag) abort
call emmet#lang#css#moveNextPrev(a:flag)
endfunction
function! emmet#lang#scss#splitJoinTag() abort
call emmet#lang#css#splitJoinTag()
endfunction
function! emmet#lang#scss#removeTag() abort
call emmet#lang#css#removeTag()
endfunction

View file

@ -0,0 +1,281 @@
function! emmet#lang#slim#findTokens(str) abort
return emmet#lang#html#findTokens(a:str)
endfunction
function! emmet#lang#slim#parseIntoTree(abbr, type) abort
return emmet#lang#html#parseIntoTree(a:abbr, a:type)
endfunction
function! emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) abort
let current = a:current
let type = a:type
let inline = a:inline
let filters = a:filters
let itemno = a:itemno
let indent = emmet#getIndentation(type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
let str = ''
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
for attr in emmet#util#unique(current.attrs_order + keys(current.attr))
if !has_key(current.attr, attr)
continue
endif
let Val = current.attr[attr]
if type(Val) == 2 && Val == function('emmet#types#true')
let str .= ' ' . attr . '=true'
else
if dollar_expr
while Val =~# '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile
endif
let attr = substitute(attr, '\$$', itemno+1, '')
let str .= ' ' . attr . '="' . Val . '"'
endif
endfor
let inner = ''
if len(current.value) > 0
let str .= "\n"
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
for line in split(text, "\n")
let str .= indent . '| ' . line . "\n"
endfor
elseif len(current.child) == 0
let str .= '${cursor}'
endif
if len(current.child) == 1 && len(current.child[0].name) == 0
let str .= "\n"
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
for line in split(text, "\n")
let str .= indent . '| ' . line . "\n"
endfor
elseif len(current.child) > 0
for child in current.child
let inner .= emmet#toString(child, type, inline, filters, itemno, indent)
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
if str !~# "\n$"
let str .= "\n"
endif
return str
endfunction
function! emmet#lang#slim#imageSize() abort
let line = getline('.')
let current = emmet#lang#slim#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] = emmet#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 slim = emmet#toString(current, 'slim', 1)
let slim = substitute(slim, '\${cursor}', '', '')
call setline('.', substitute(matchstr(line, '^\s*') . slim, "\n", '', 'g'))
endfunction
function! emmet#lang#slim#encodeImage() abort
endfunction
function! emmet#lang#slim#parseTag(tag) abort
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', '')
let attrs = substitute(match, mx, '\2', '')
let mx = '\([a-zA-Z0-9]\+\)=\%(\([^"'' \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! emmet#lang#slim#toggleComment() abort
let line = getline('.')
let space = matchstr(line, '^\s*')
if line =~# '^\s*/'
call setline('.', space . line[len(space)+1:])
elseif line =~# '^\s*[a-z]'
call setline('.', space . '/' . line[len(space):])
endif
endfunction
function! emmet#lang#slim#balanceTag(flag) range abort
let block = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0]
else
let curpos = emmet#util#getcurpos()
endif
let n = curpos[1]
let ml = len(matchstr(getline(n), '^\s*'))
if a:flag > 0
if a:flag == 1 || !emmet#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! emmet#lang#slim#moveNextPrevItem(flag) abort
return emmet#lang#slim#moveNextPrev(a:flag)
endfunction
function! emmet#lang#slim#moveNextPrev(flag) abort
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
if pos == 2
startinsert!
elseif pos != 0
silent! normal! l
startinsert
endif
endfunction
function! emmet#lang#slim#splitJoinTag() abort
let n = line('.')
while n > 0
if getline(n) =~# '^\s*\ze[a-z]'
let sn = n
let n += 1
if getline(n) =~# '^\s*|'
while n <= line('$')
if getline(n) !~# '^\s*|'
break
endif
exe n 'delete'
endwhile
call setpos('.', [0, sn, 1, 0])
else
let spaces = matchstr(getline(sn), '^\s*')
call append(sn, spaces . ' | ')
call setpos('.', [0, sn+1, 1, 0])
startinsert!
endif
break
endif
let n -= 1
endwhile
endfunction
function! emmet#lang#slim#removeTag() abort
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

View file

@ -0,0 +1,65 @@
function! emmet#lorem#en#expand(command) abort
let wcount = matchstr(a:command, '\(\d*\)$')
let wcount = wcount > 0 ? wcount : 30
let common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit']
let words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet',
\ 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi',
\ 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi',
\ 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos',
\ 'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum',
\ 'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus',
\ 'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus',
\ 'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum',
\ 'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem',
\ 'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus',
\ 'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente',
\ 'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet',
\ 'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta',
\ 'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima',
\ 'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim',
\ 'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores',
\ 'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias',
\ 'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea',
\ 'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt',
\ 'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate',
\ 'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius',
\ 'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos',
\ 'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore',
\ 'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo',
\ 'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi',
\ 'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam',
\ 'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique',
\ 'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere',
\ 'maxime', 'corrupti']
let ret = []
let sentence = 0
for i in range(wcount)
let arr = common
if sentence > 0
let arr += words
endif
let r = emmet#util#rand()
let word = arr[r % len(arr)]
if sentence == 0
let word = substitute(word, '^.', '\U&', '')
endif
let sentence += 1
call add(ret, word)
if (sentence > 5 && emmet#util#rand() < 10000) || i == wcount - 1
if i == wcount - 1
let endc = '?!...'[emmet#util#rand() % 5]
call add(ret, endc)
else
let endc = '?!,...'[emmet#util#rand() % 6]
call add(ret, endc . ' ')
endif
if endc !=# ','
let sentence = 0
endif
else
call add(ret, ' ')
endif
endfor
return join(ret, '')
endfunction

View file

@ -0,0 +1,27 @@
scriptencoding utf-8
function! emmet#lorem#ja#expand(command) abort
let wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '')
let wcount = wcount > 0 ? wcount : 30
let url = "http://www.aozora.gr.jp/cards/000081/files/470_15407.html"
let content = emmet#util#cache(url)
if len(content) == 0
let content = emmet#util#getContentFromURL(url)
let content = matchstr(content, '<div[^>]*>\zs.\{-}</div>')
let content = substitute(content, '[ \r]', '', 'g')
let content = substitute(content, '<br[^>]*>', "\n", 'g')
let content = substitute(content, '<[^>]\+>', '', 'g')
let content = join(filter(split(content, "\n"), 'len(v:val)>0'), "\n")
call emmet#util#cache(url, content)
endif
let content = substitute(content, "、\n", "、", "g")
let clines = split(content, '\n')
let lines = filter(clines, 'len(substitute(v:val,".",".","g"))<=wcount')
if len(lines) == 0
let lines = clines
endif
let r = emmet#util#rand()
return lines[r % len(lines)]
endfunction

View file

@ -0,0 +1,349 @@
"==============================================================================
" region utils
"==============================================================================
" deleteContent : delete content in region
" if region make from between '<foo>' and '</foo>'
" --------------------
" begin:<foo>
" </foo>:end
" --------------------
" this function make the content as following
" --------------------
" begin::end
" --------------------
function! emmet#util#deleteContent(region) abort
let lines = getline(a:region[0][0], a:region[1][0])
call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
silent! exe 'delete '.(a:region[1][0] - a:region[0][0])
call setline(line('.'), lines[0][:a:region[0][1]-2] . lines[-1][a:region[1][1]])
endfunction
" change_content : change content in region
" if region make from between '<foo>' and '</foo>'
" --------------------
" begin:<foo>
" </foo>:end
" --------------------
" and content is
" --------------------
" foo
" bar
" baz
" --------------------
" this function make the content as following
" --------------------
" begin:foo
" bar
" baz:end
" --------------------
function! emmet#util#setContent(region, content) abort
let newlines = split(a:content, '\n', 1)
let oldlines = getline(a:region[0][0], a:region[1][0])
call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
silent! exe 'delete '.(a:region[1][0] - a:region[0][0])
if len(newlines) == 0
let tmp = ''
if a:region[0][1] > 1
let tmp = oldlines[0][:a:region[0][1]-2]
endif
if a:region[1][1] >= 1
let tmp .= oldlines[-1][a:region[1][1]:]
endif
call setline(line('.'), tmp)
elseif len(newlines) == 1
if a:region[0][1] > 1
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0]
endif
if a:region[1][1] >= 1
let newlines[0] .= oldlines[-1][a:region[1][1]:]
endif
call setline(line('.'), newlines[0])
else
if a:region[0][1] > 1
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0]
endif
if a:region[1][1] >= 1
let newlines[-1] .= oldlines[-1][a:region[1][1]:]
endif
call setline(line('.'), newlines[0])
call append(line('.'), newlines[1:])
endif
endfunction
" select_region : select region
" this function make a selection of region
function! emmet#util#selectRegion(region) abort
call setpos('.', [0, a:region[1][0], a:region[1][1], 0])
normal! v
call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
endfunction
" point_in_region : check point is in the region
" this function return 0 or 1
function! emmet#util#pointInRegion(point, region) abort
if !emmet#util#regionIsValid(a:region) | return 0 | endif
if a:region[0][0] > a:point[0] | return 0 | endif
if a:region[1][0] < a:point[0] | return 0 | endif
if a:region[0][0] == a:point[0] && a:region[0][1] > a:point[1] | return 0 | endif
if a:region[1][0] == a:point[0] && a:region[1][1] < a:point[1] | return 0 | endif
return 1
endfunction
" cursor_in_region : check cursor is in the region
" this function return 0 or 1
function! emmet#util#cursorInRegion(region) abort
if !emmet#util#regionIsValid(a:region) | return 0 | endif
let cur = emmet#util#getcurpos()[1:2]
return emmet#util#pointInRegion(cur, a:region)
endfunction
" region_is_valid : check region is valid
" this function return 0 or 1
function! emmet#util#regionIsValid(region) abort
if a:region[0][0] == 0 || a:region[1][0] == 0 | return 0 | endif
return 1
endfunction
" search_region : make region from pattern which is composing start/end
" this function return array of position
function! emmet#util#searchRegion(start, end) abort
let b = searchpairpos(a:start, '', a:end, 'bcnW')
if b == [0, 0]
return [searchpairpos(a:start, '', a:end, 'bnW'), searchpairpos(a:start, '\%#', a:end, 'nW')]
else
return [b, searchpairpos(a:start, '', a:end. '', 'nW')]
endif
endfunction
" get_content : get content in region
" this function return string in region
function! emmet#util#getContent(region) abort
if !emmet#util#regionIsValid(a:region)
return ''
endif
let lines = getline(a:region[0][0], a:region[1][0])
if a:region[0][0] == a:region[1][0]
let lines[0] = lines[0][a:region[0][1]-1:a:region[1][1]-1]
else
let lines[0] = lines[0][a:region[0][1]-1:]
let lines[-1] = lines[-1][:a:region[1][1]-1]
endif
return join(lines, "\n")
endfunction
" region_in_region : check region is in the region
" this function return 0 or 1
function! emmet#util#regionInRegion(outer, inner) abort
if !emmet#util#regionIsValid(a:inner) || !emmet#util#regionIsValid(a:outer)
return 0
endif
return emmet#util#pointInRegion(a:inner[0], a:outer) && emmet#util#pointInRegion(a:inner[1], a:outer)
endfunction
" get_visualblock : get region of visual block
" this function return region of visual block
function! emmet#util#getVisualBlock() abort
return [[line("'<"), col("'<")], [line("'>"), col("'>")]]
endfunction
"==============================================================================
" html utils
"==============================================================================
function! emmet#util#getContentFromURL(url) abort
let res = system(printf('%s -i %s', g:emmet_curl_command, shellescape(substitute(a:url, '#.*', '', ''))))
while res =~# '^HTTP/1.\d 3' || res =~# '^HTTP/1\.\d 200 Connection established' || res =~# '^HTTP/1\.\d 100 Continue'
let pos = stridx(res, "\r\n\r\n")
if pos != -1
let res = strpart(res, pos+4)
else
let pos = stridx(res, "\n\n")
let res = strpart(res, pos+2)
endif
endwhile
let pos = stridx(res, "\r\n\r\n")
if pos != -1
let content = strpart(res, pos+4)
else
let pos = stridx(res, "\n\n")
let content = strpart(res, pos+2)
endif
let header = res[:pos-1]
let charset = matchstr(content, '<meta[^>]\+content=["''][^;"'']\+;\s*charset=\zs[^;"'']\+\ze["''][^>]*>')
if len(charset) == 0
let charset = matchstr(content, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]*>')
endif
if len(charset) == 0
let charset = matchstr(header, '\nContent-Type:.* charset=[''"]\?\zs[^''";\n]\+\ze')
endif
if len(charset) == 0
let s1 = len(split(content, '?'))
let utf8 = iconv(content, 'utf-8', &encoding)
let s2 = len(split(utf8, '?'))
return (s2 == s1 || s2 >= s1 * 2) ? utf8 : content
endif
return iconv(content, charset, &encoding)
endfunction
function! emmet#util#getTextFromHTML(buf) abort
let threshold_len = 100
let threshold_per = 0.1
let buf = a:buf
let buf = strpart(buf, stridx(buf, '</head>'))
let buf = substitute(buf, '<style[^>]*>.\{-}</style>', '', 'g')
let buf = substitute(buf, '<script[^>]*>.\{-}</script>', '', 'g')
let res = ''
let max = 0
let mx = '\(<td[^>]\{-}>\)\|\(<\/td>\)\|\(<div[^>]\{-}>\)\|\(<\/div>\)'
let m = split(buf, mx)
for str in m
let c = split(str, '<[^>]*?>')
let str = substitute(str, '<[^>]\{-}>', ' ', 'g')
let str = substitute(str, '&gt;', '>', 'g')
let str = substitute(str, '&lt;', '<', 'g')
let str = substitute(str, '&quot;', '"', 'g')
let str = substitute(str, '&apos;', '''', 'g')
let str = substitute(str, '&nbsp;', ' ', 'g')
let str = substitute(str, '&yen;', '\&#65509;', 'g')
let str = substitute(str, '&amp;', '\&', 'g')
let str = substitute(str, '^\s*\(.*\)\s*$', '\1', '')
let str = substitute(str, '\s\+', ' ', 'g')
let l = len(str)
if l > threshold_len
let per = (l+0.0) / len(c)
if max < l && per > threshold_per
let max = l
let res = str
endif
endif
endfor
let res = substitute(res, '^\s*\(.*\)\s*$', '\1', 'g')
return res
endfunction
function! emmet#util#getImageSize(fn) abort
let fn = a:fn
if emmet#util#isImageMagickInstalled()
return emmet#util#imageSizeWithImageMagick(fn)
endif
if filereadable(fn)
let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g')
else
if fn !~# '^\w\+://'
let path = fnamemodify(expand('%'), ':p:gs?\\?/?')
if has('win32') || has('win64') |
let path = tolower(path)
endif
for k in keys(g:emmet_docroot)
let root = fnamemodify(k, ':p:gs?\\?/?')
if has('win32') || has('win64') |
let root = tolower(root)
endif
if stridx(path, root) == 0
let v = g:emmet_docroot[k]
let fn = (len(v) == 0 ? k : v) . fn
break
endif
endfor
endif
let hex = substitute(system(g:emmet_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g')
endif
let [width, height] = [-1, -1]
if hex =~# '^89504e470d0a1a0a'
let width = eval('0x'.hex[32:39])
let height = eval('0x'.hex[40:47])
endif
if hex =~# '^ffd8'
let pos = 4
while pos < len(hex)
let bs = hex[pos+0:pos+3]
let pos += 4
if bs ==# 'ffc0' || bs ==# 'ffc2'
let pos += 6
let height = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])
let pos += 4
let width = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])
break
elseif bs =~# 'ffd[9a]'
break
elseif bs =~# 'ff\(e[0-9a-e]\|fe\|db\|dd\|c4\)'
let pos += (eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])) * 2
endif
endwhile
endif
if hex =~# '^47494638'
let width = eval('0x'.hex[14:15].hex[12:13])
let height = eval('0x'.hex[18:19].hex[16:17])
endif
return [width, height]
endfunction
function! emmet#util#imageSizeWithImageMagick(fn) abort
let img_info = system('identify -format "%wx%h" "'.a:fn.'"')
let img_size = split(substitute(img_info, '\n', '', ''), 'x')
if len(img_size) != 2
return [-1, -1]
endif
return img_size
endfunction
function! emmet#util#isImageMagickInstalled() abort
if !get(g:, 'emmet_use_identify', 1)
return 0
endif
return executable('identify')
endfunction
function! emmet#util#unique(arr) abort
let m = {}
let r = []
for i in a:arr
if !has_key(m, i)
let m[i] = 1
call add(r, i)
endif
endfor
return r
endfunction
let s:seed = localtime()
function! emmet#util#srand(seed) abort
let s:seed = a:seed
endfunction
function! emmet#util#rand() abort
let s:seed = s:seed * 214013 + 2531011
return (s:seed < 0 ? s:seed - 0x80000000 : s:seed) / 0x10000 % 0x8000
endfunction
function! emmet#util#cache(name, ...) abort
let content = get(a:000, 0, '')
let dir = expand('~/.emmet/cache')
if !isdirectory(dir)
call mkdir(dir, 'p', 0700)
endif
let file = dir . '/' . substitute(a:name, '\W', '_', 'g')
if len(content) == 0
if !filereadable(file)
return ''
endif
return join(readfile(file), "\n")
endif
call writefile(split(content, "\n"), file)
endfunction
function! emmet#util#getcurpos() abort
let pos = getpos('.')
if mode(0) ==# 'i' && pos[2] > 0
let pos[2] -=1
endif
return pos
endfunction
function! emmet#util#closePopup() abort
return pumvisible() ? "\<c-e>" : ''
endfunction

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -0,0 +1,277 @@
script_name: Emmet.vim
script_id: '2981'
script_type: utility
script_package: emmet-vim.zip
script_version: '0.86'
required_vim_version: '7.0'
summary: vim plugins for HTML and CSS hi-speed coding.
detailed_description: |
This is vim script support expanding abbreviation like emmet.
ref: http://emmet.io/
There is a movie using emmet.vim
ref: http://mattn.github.com/emmet-vim
Source Repository.
ref: http://github.com/mattn/emmet-vim
Type abbreviation
+-------------------------------------
| html:5_
+-------------------------------------
"_" is a cursor position. and type "<c-y>," (Ctrl + y and Comma)
NOTE: Don't worry about key map. you can change it easily.
+-------------------------------------
| <!DOCTYPE HTML>
| <html lang="en">
| <head>
| <title></title>
| <meta charset="UTF-8">
| </head>
| <body>
| _
| </body>
| </html>
+-------------------------------------
Type following
+-------------------------------------
| div#foo$*2>div.bar
+-------------------------------------
And type "<c-y>,"
+-------------------------------------
|<div id="foo1">
| <div class="bar">_</div>
|</div>
|<div id="foo2">
| <div class="bar"></div>
|</div>
| _
+-------------------------------------
Tutorial:
http://github.com/mattn/emmet-vim/raw/master/TUTORIAL
How work this:
http://mattn.github.com/emmet-vim
Tips:
You can customize behavior of expanding with overriding config.
This configuration will be merged at loading plugin.
let g:user_emmet_settings = {
\ 'indentation' : ' ',
\ 'perl' : {
\ 'aliases' : {
\ 'req' : 'require '
\ },
\ 'snippets' : {
\ 'use' : "use strict\nuse warnings\n\n",
\ 'warn' : "warn \"|\";",
\ }
\ }
\}
let g:user_emmet_expandabbr_key = '<c-e>'
let g:use_emmet_complete_tag = 1
You can set language attribute in html using emmet_settings['lang'].
install_details: |
# cd ~/.vim
# unzip emmet-vim.zip
or if you install pathogen.vim:
# cd ~/.vim/bundle # or make directory
# unzip /path/to/emmet-vim.zip
if you get sources from repository:
# cd ~/.vim/bundle # or make directory
# git clone http://github.com/mattn/emmet-vim.git
versions:
- '0.86': |
This is an upgrade for Emmet.vim: lot of bug fixes.
- '0.85': |
This is an upgrade for Emmet.vim: lot of bug fixes.
- '0.84': |
This is an upgrade for Emmet.vim: lot of bug fixes. fix bug that interpose insert completion plugins.
- '0.83': |
This is an upgrade for Emmet.vim: lot of bug fixes.
- '0.82': |
This is an upgrade for Emmet.vim: many bug fixes.
- '0.81': |
Release of Emmet.vim: renamed from ZenCoding.vim.
- '0.80': |
This is an upgrade for ZenCoding.vim: add emmet features.
- '0.74': |
This is an upgrade for ZenCoding.vim: many bug fixes.
- '0.73': |
This is an upgrade for ZenCoding.vim: many bug fixes. and support slim format (experimental).
- '0.72': |
This is an upgrade for ZenCoding.vim:
[fix] fix finding tokens.
- '0.71': |
This is an upgrade for ZenCoding.vim:
[fix] fix finding begin of tokens.
- '0.70': |
This is an upgrade for ZenCoding.vim:
[mod] Changed behavior of expanding. "div div>a|" should keep first div element.
[add] Supported slim formatter.
- '0.60': |
This is an upgrade for ZenCoding.vim:
[fix] fixed expanding {{}}.
- '0.59': |
This is an upgrade for ZenCoding.vim:
[fix] fixed toggleComment and mny bugs.
- '0.58': |
This is an upgrade for ZenCoding.vim:
[fix] fixed 'foo+' style expandos.
- '0.57': |
This is an upgrade for ZenCoding.vim:
[fix] fixed expandos that don't work 'choose' in xsl.
- '0.56': |
This is an upgrade for ZenCoding.vim:
[fix] fixed contents parser.
- '0.55': |
uploaded again: sorry, files was old.
- '0.54': |
[add] support sass, xsd.
[fix] expanding with html tag.
uploaded again: sorry, fileformat was DOS.
- '0.53': |
[fix] gif width/height was swapped.
- '0.52': |
[fix] broken wrap expanding.
- '0.51': |
This is an upgrade for ZenCoding.vim:
[fix] wrap expanding with '&'.
[fix] expand .content to class="content".
[fix] haml expanding.
[fix] bg+ snippet
- '0.50': |
This is an upgrade for ZenCoding.vim:
[fix] fixed parsing '#{{foo}}' and '.{{bar}}'.
- '0.49': |
This is an upgrade for ZenCoding.vim:
[doc] add help manual.
- '0.48': |
This is an upgrade for ZenCoding.vim:
[fix] install mappings to global.
- '0.47': |
This is an upgrade for ZenCoding.vim:
[drastic changes] enable autoload. you should whole replace older files.
package was empty. upload again.
- '0.46': |
This is an upgrade for ZenCoding.vim:
[drastic changes] enable autoload. you should whole replace older files.
- '0.45': |
This is an upgrade for ZenCoding.vim:
fixed attribute parsing like: a[href="hello', world" rel].
- '0.44': |
This is an upgrade for ZenCoding.vim:
fixed checking whether have mapping using maparg() / hasmapto().
- '0.43': |
This is an upgrade for ZenCoding.vim:
fixed behavior for nested block. like "html:5>#page>(header#globalHeader>(hgroup>h1+h2)+(nav>ul>li*3>a)+(form>p.siteSearch>input+input[type=button]))+(#contents>(#main>(section>h2+p*5)+p.pagetop>a[href=#page])+(#sub>p+(nav>ul>li>a)))+(footer#globalFoooter>(ul>li>a)+(p.copyright>small))"
- '0.42': |
This is an upgrade for ZenCoding.vim:
fixed select/option indent.
- '0.41': |
This is an upgrade for ZenCoding.vim:
fixed default filter. when using 'e' filter, output become empty.
- '0.40': |
This is an upgrade for ZenCoding.vim:
add the pure vimscript code for 'get image size'. you can use it without perl interface just now.
change key assign of ZenCodingExpandWord from ',' to ';'. it don't effect to most users.
- '0.39': |
This is an upgrade for ZenCoding.vim: fixed problem about 'selection'. see http://github.com/mattn/zencoding-vim/issues/#issue/2
- '0.38': |
This is an upgrade for ZenCoding.vim: use v7h"_s instead of v7hs for backspace.
- '0.37': |
This is an upgrade for ZenCoding.vim: fixed problem that won't working with some 'backspace' options.
- '0.36': |
This is an upgrade for ZenCoding.vim: fixed problem that filter does not work.
- '0.35': |
This is an upgrade for ZenCoding.vim: enable zencoding for other languages. (meaning php also)
- '0.34': |
This is an upgrade for ZenCoding.vim: enable zencoding for xsl. (you should add ~/.vim/ftplugin/xslt/zencoding.vim)
- '0.33': |
This is an upgrade for ZenCoding.vim: fixed problem breaking multibyte when cursor is in a part of line. enabled zencoding for javascript in html.
- '0.32': |
This is an upgrade for ZenCoding.vim: fixed indentation. supported extends so that you can enable zencoding for php/xhtml/haml other's section 14 in http://github.com/mattn/zencoding-vim/raw/master/TUTORIAL
- '0.31': |
This is an upgrade for ZenCoding.vim: fixed indentation and $$$ problem. fixed about missing support multiple classes.
- '0.30': |
This is an upgrade for ZenCoding.vim: Fixed key assign.
- '0.29': |
This is an upgrade for ZenCoding.vim: Changed leading key to '<c-y>' from '<c-z>'.
- '0.28': |
This is an upgrade for ZenCoding.vim: supported 'Balance Tag Inward/Outward', 'Go to Next/Previous Edit Point', 'Update <img> Size', 'Remove Tag', 'Split/Join Tag', 'Toggle Comment'
- '0.27': |
This is an upgrade for ZenCoding.vim: fixed problem that can't work on the part of multibyte characters. fixed inline elements behavior.
- '0.26': |
This is an upgrade for ZenCoding.vim: The count of '(((a#foo + a#bar)*2)*3)' should be 12.
- '0.25': |
This is an upgrade for ZenCoding.vim: store undo before working. good luck about 'table>(tr>td*3)*4'.
- '0.24': |
This is an upgrade for ZenCoding.vim: fixed behavior of parsing area of visual selection.
- '0.23': |
This is an upgrade for ZenCoding.vim: pre-expand '#header>li<#content' to 'div#header>li<div#content'. support () expression.
- '0.22': |
This is an upgrade for ZenCoding.vim: expand 'ul+' to 'ul>li'. fix undo ring. support visual selection. when type trigger key on visual select, it request you leader like 'ul>li'. if you give 'ul>li*' as leader, you'll get each separate 'ul>li' tags. and when you give 'blockquote' as leader, you'll get blocked text.
- '0.21': |
This is an upgrade for ZenCoding.vim: treat xhtml as html.
- '0.20': |
This is an upgrade for ZenCoding.vim: add option use_zen_complete_tag for complete abbr.
- '0.19': |
This is an upgrade for ZenCoding.vim: fixed problem that couldn't expand 'link:css' correctly.
- '0.18': |
This is an upgrade for ZenCoding.vim: ignore duplicate key map.
- '0.17': |
This is an upgrade for ZenCoding.vim: fixed key map.
- '0.16': |
This is an upgrade for ZenCoding.vim: fixed problem 'endless loop'.
- '0.15': |
This is an upgrade for ZenCoding.vim: set default filetype to 'html'.
- '0.14': |
This is an upgrade for ZenCoding.vim: fixed tag name like 'fs:n' in 'css'.
- '0.14': |
This is an upgrade for ZenCoding.vim: indentation for each languages.
- '0.13': |
This is an upgrade for ZenCoding.vim: user key map.
- '0.12': |
This is an upgrade for ZenCoding.vim: few extensive notation.
- '0.11': |
This is an upgrade for ZenCoding.vim: fixed indent.
- '0.10': |
This is an upgrade for ZenCoding.vim: fixed behavior of '+' operator
- '0.9': |
This is an upgrade for ZenCoding.vim: fixed single line behavior
- '0.8': |
This is an upgrade for ZenCoding.vim: support 'a[href=http://www.google.com]{Google}'
- '0.7': |
This is an upgrade for ZenCoding.vim: fixed behavior in 'a+b'.
- '0.6': |
This is an upgrade for ZenCoding.vim: fixed strange behavior about '<a href="">b_</a>'.
- '0.5': |
This is an upgrade for ZenCoding.vim: recover rest part in line.
- '0.4': |
This is an upgrade for ZenCoding.vim: fixed cursor position. fixed ${lang} replacement.
- '0.3': |
This is an upgrade for ZenCoding.vim: fixed line expanding.
- '0.2': |
This is an upgrade for ZenCoding.vim: fixed problem that moving cursor with expanding.
- '0.1': |
Initial upload
# __END__
# vim: filetype=yaml

View file

@ -0,0 +1,177 @@
"=============================================================================
" File: emmet.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 26-Jul-2015.
" Version: 0.86
" WebPage: http://github.com/mattn/emmet-vim
" Description: vim plugins for HTML and CSS hi-speed coding.
" SeeAlso: http://emmet.io/
" Usage:
"
" This is vim script support expanding abbreviation like emmet.
" ref: http://emmet.io/
"
" Type abbreviation
" +-------------------------------------
" | html:5_
" +-------------------------------------
" "_" is a cursor position. and type "<c-y>," (Ctrl+y and Comma)
" NOTE: Don't worry about key map. you can change it easily.
" +-------------------------------------
" | <!DOCTYPE HTML>
" | <html lang="en">
" | <head>
" | <title></title>
" | <meta charset="UTF-8">
" | </head>
" | <body>
" | _
" | </body>
" | </html>
" +-------------------------------------
" Type following
" +-------------------------------------
" | div#foo$*2>div.bar
" +-------------------------------------
" And type "<c-y>,"
" +-------------------------------------
" |<div id="foo1">
" | <div class="bar">_</div>
" |</div>
" |<div id="foo2">
" | <div class="bar"></div>
" |</div>
" +-------------------------------------
"
" Tips:
"
" You can customize behavior of expanding with overriding config.
" This configuration will be marged at loading plugin.
"
" let g:user_emmet_settings = {
" \ 'indentation' : ' ',
" \ 'perl' : {
" \ 'aliases' : {
" \ 'req' : 'require '
" \ },
" \ 'snippets' : {
" \ 'use' : "use strict\nuse warnings\n\n",
" \ 'warn' : "warn \"|\";",
" \ }
" \ }
" \}
"
" You can set language attribute in html using 'emmet_settings.lang'.
"
" GetLatestVimScripts: 2981 1 :AutoInstall: emmet.vim
" script type: plugin
if &compatible || v:version < 702 || (exists('g:loaded_emmet_vim') && g:loaded_emmet_vim)
finish
endif
let g:loaded_emmet_vim = 1
let s:save_cpo = &cpoptions
set cpoptions&vim
if !exists('g:emmet_html5')
let g:emmet_html5 = 1
endif
if !exists('g:emmet_docroot')
let g:emmet_docroot = {}
endif
if !exists('g:emmet_debug')
let g:emmet_debug = 0
endif
if !exists('g:emmet_curl_command')
let g:emmet_curl_command = 'curl -s -L -A Mozilla/5.0'
endif
if !exists('g:user_emmet_leader_key')
let g:user_emmet_leader_key = '<c-y>'
endif
function! s:install_plugin(mode, buffer)
let buffer = a:buffer ? '<buffer>' : ''
let items = [
\ {'mode': 'i', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#expandAbbr(0,"")<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': ':call emmet#expandAbbr(3,"")<cr>'},
\ {'mode': 'v', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': ':call emmet#expandAbbr(2,"")<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_expandword_key', 'key': ';', 'plug': 'emmet-expand-word', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#expandAbbr(1,"")<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_expandword_key', 'key': ';', 'plug': 'emmet-expand-word', 'func': ':call emmet#expandAbbr(1,"")<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_update_tag', 'key': 'u', 'plug': 'emmet-update-tag', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#updateTag()<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_update_tag', 'key': 'u', 'plug': 'emmet-update-tag', 'func': ':call emmet#updateTag()<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': '<esc>:call emmet#balanceTag(1)<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': ':call emmet#balanceTag(1)<cr>'},
\ {'mode': 'v', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': ':call emmet#balanceTag(2)<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_balancetagoutward_key', 'key': 'D', 'plug': 'emmet-balance-tag-outword', 'func': '<esc>:call emmet#balanceTag(-1)<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_balancetagoutward_key', 'key': 'D', 'plug': 'emmet-balance-tag-outword', 'func': ':call emmet#balanceTag(-1)<cr>'},
\ {'mode': 'v', 'var': 'user_emmet_balancetagoutward_key', 'key': 'D', 'plug': 'emmet-balance-tag-outword', 'func': ':call emmet#balanceTag(-2)<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_next_key', 'key': 'n', 'plug': 'emmet-move-next', 'func': '<esc>:call emmet#moveNextPrev(0)<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_next_key', 'key': 'n', 'plug': 'emmet-move-next', 'func': ':call emmet#moveNextPrev(0)<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_prev_key', 'key': 'N', 'plug': 'emmet-move-prev', 'func': '<esc>:call emmet#moveNextPrev(1)<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_prev_key', 'key': 'N', 'plug': 'emmet-move-prev', 'func': ':call emmet#moveNextPrev(1)<cr>'},
\ {'mode': 'i', 'var': '', 'key': '', 'plug': 'emmet-move-next-item', 'func': '<esc>:call emmet#moveNextPrevItem(0)<cr>'},
\ {'mode': 'n', 'var': '', 'key': '', 'plug': 'emmet-move-next-item', 'func': ':call emmet#moveNextPrevItem(0)<cr>'},
\ {'mode': 'i', 'var': '', 'key': '', 'plug': 'emmet-move-prev-item', 'func': '<esc>:call emmet#moveNextPrevItem(1)<cr>'},
\ {'mode': 'n', 'var': '', 'key': '', 'plug': 'emmet-move-prev-item', 'func': ':call emmet#moveNextPrevItem(1)<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_imagesize_key', 'key': 'i', 'plug': 'emmet-image-size', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#imageSize()<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_imagesize_key', 'key': 'i', 'plug': 'emmet-image-size', 'func': ':call emmet#imageSize()<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_togglecomment_key', 'key': '/', 'plug': 'emmet-toggle-comment', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#toggleComment()<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_togglecomment_key', 'key': '/', 'plug': 'emmet-toggle-comment', 'func': ':call emmet#toggleComment()<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_splitjointag_key', 'key': 'j', 'plug': 'emmet-split-join-tag', 'func': '<esc>:call emmet#splitJoinTag()<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_splitjointag_key', 'key': 'j', 'plug': 'emmet-split-join-tag', 'func': ':call emmet#splitJoinTag()<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_removetag_key', 'key': 'k', 'plug': 'emmet-remove-tag', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#removeTag()<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_removetag_key', 'key': 'k', 'plug': 'emmet-remove-tag', 'func': ':call emmet#removeTag()<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_anchorizeurl_key', 'key': 'a', 'plug': 'emmet-anchorize-url', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#anchorizeURL(0)<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_anchorizeurl_key', 'key': 'a', 'plug': 'emmet-anchorize-url', 'func': ':call emmet#anchorizeURL(0)<cr>'},
\ {'mode': 'i', 'var': 'user_emmet_anchorizesummary_key', 'key': 'A', 'plug': 'emmet-anchorize-summary', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#anchorizeURL(1)<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_anchorizesummary_key', 'key': 'A', 'plug': 'emmet-anchorize-summary', 'func': ':call emmet#anchorizeURL(1)<cr>'},
\ {'mode': 'v', 'var': 'user_emmet_mergelines_key', 'key': 'm', 'plug': 'emmet-merge-lines', 'func': ':call emmet#mergeLines()<cr>'},
\ {'mode': 'v', 'var': 'user_emmet_codepretty_key', 'key': 'c', 'plug': 'emmet-code-pretty', 'func': ':call emmet#codePretty()<cr>'},
\]
let only_plug = get(g:, 'emmet_install_only_plug', 0)
for item in items
if a:mode !=# 'a' && stridx(a:mode, item.mode) == -1
continue
endif
exe item.mode . 'noremap '. buffer .' <plug>(' . item.plug . ') ' . item.func
if item.var != '' && !only_plug
if exists('g:' . item.var)
let key = eval('g:' . item.var)
else
let key = g:user_emmet_leader_key . item.key
endif
if !hasmapto('<plug>(' . item.plug . ')', item.mode) && !len(maparg(key, item.mode))
exe item.mode . 'map ' . buffer . ' <unique> ' . key . ' <plug>(' . item.plug . ')'
endif
endif
endfor
if exists('g:user_emmet_complete_tag') && g:user_emmet_complete_tag
if get(g:, 'user_emmet_install_global', 1)
set omnifunc=emmet#completeTag
else
setlocal omnifunc=emmet#completeTag
endif
endif
endfunction
command! -nargs=0 -bar EmmetInstall call <SID>install_plugin(get(g:, 'user_emmet_mode', 'a'), 1)
if get(g:, 'user_emmet_install_global', 1)
call s:install_plugin(get(g:, 'user_emmet_mode', 'a'), 0)
endif
if get(g:, 'user_emmet_install_command', 1)
command! -nargs=1 Emmet call emmet#expandAbbr(4, <q-args>)
endif
let &cpoptions = s:save_cpo
unlet s:save_cpo
" vim:set et:

File diff suppressed because it is too large Load diff

4
sources_forked/supertab/.gitignore vendored Executable file
View file

@ -0,0 +1,4 @@
*.swp
*.vmb
doc/tags
/README.html

View file

@ -0,0 +1,17 @@
SHELL=/bin/bash
all: dist
dist:
@rm supertab.vmb 2> /dev/null || true
@vim -c 'r! git ls-files doc plugin' \
-c '$$,$$d _' -c '%MkVimball supertab .' -c 'q!'
clean:
@rm -R build 2> /dev/null || true
install: supertab.vmb
vim $< -c 'so %' -c 'q'
uninstall:
vim -c 'RmVimball supertab.vmb' -c 'q'

View file

@ -0,0 +1,172 @@
.. Copyright (c) 2012 - 2014, Eric Van Dewoestine
All rights reserved.
Redistribution and use of this software in source and binary forms, with
or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of Eric Van Dewoestine nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission of
Eric Van Dewoestine.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.. _overview:
==================
Overview
==================
Supertab is a vim plugin which allows you to use <Tab> for all your insert
completion needs (:help ins-completion).
Features
--------
- Configurable to suit you needs:
- Default completion type to use.
- Prevent <Tab> from completing after/before defined patterns.
- Close vim's completion preview window when code completion is finished.
- When using other completion types, you can configure how long to 'remember'
the current completion type before returning to the default.
- Don't like using <Tab>? You can also configure a different pair of keys to
scroll forwards and backwards through completion results.
- Optional improved 'longest' completion support (after typing some characters,
hitting <Tab> will highlight the next longest match).
- Built in 'context' completion option which chooses the appropriate completion
type based on the text preceding the cursor.
- You can also plug in your own functions to determine which completion type
to use.
- Support for simple completion chaining (falling back to a different
completion type, keyword completion for example, if omni or user completion
returns no results).
Installation
------------
You have a few options when it comes to installing supertab:
1. Use your linux package manager:
Some linux distributions include a supertab package so you don't have to
manage the install/upgrade of supertab separately from other software on your
system.
2. Use a vim plugin manager:
There are several plugin managers for vim, which will either allow you to
manually clone vim plugin repositories, or will do so for you. Probably the
two most popular ones currently are `pathogen
<https://github.com/tpope/vim-pathogen>`_ and `vundle
<https://github.com/gmarik/Vundle.vim>`_. Please refer to their docs for
instructions on how to install plugins.
3. And lastly you can use the vimball (.vmb) file found on
`vim.org <http://www.vim.org/scripts/script.php?script_id=1643>`_:
Vimball files are installed by simply opening them in vim and then sourcing
the file:
::
$ vim supertab.vmb
:source %
Frequently Asked Questions
--------------------------
- **Why isn't supertab honoring my configured settings (attempts to complete at the
start of a line, always performs keyword completion instead of my configured
default, etc.)?**
Chances are that you have a very old version of `snipmate
<https://github.com/msanders/snipmate.vim>`_ installed, or something similar,
which will issue a `<c-n>` when no snippet is found. Supertab use to map to
`<c-n>`, so this behavior would act as a fallback to supertab, but current
versions of supertab no longer do so, resulting in snipmate bypassing supertab
entirely.
You can check if this is the case by running the following in vim to see what
is mapped to `<tab>`:
::
:verbose imap <tab>
To resolve the issue you can either:
#. Install my `fork <https://github.com/ervandew/snipmate.vim>`_ or
#. Upgrade to a more recent snipmate fork, like `garbas/vim-snipmate
<https://github.com/garbas/vim-snipmate>`_
See `#74 <https://github.com/ervandew/supertab/issues/74>`_ for additional
details.
- **Why does <tab> navigate the completion menu from bottom to top?**
First, if after reading the explanation below (or if you don't want to bother
reading it), you still want the default to scroll down the list then you can
use:
::
let g:SuperTabDefaultCompletionType = "<c-n>"
or if your default completion type is currently `context` then you can use
this instead:
::
let g:SuperTabContextDefaultCompletionType = "<c-n>"
Now on to the reasoning behind this. When using `<c-p>` or `<c-n>` to start
insert completion, both populate the completion popup with the same list of
words in the same order, the only difference is that `<c-p>` highlights the
nearest matching word located above the current cursor position, which is the
result at the bottom of the completion popup. Without supertab installed,
continuing to hit `<c-p>` will walk up the list to next nearest word above the
cursor.
I think Bram chose to display the results like this so that
#. the completion logic is the same for `<c-n>` and `<c-p>`, only the first
entry to highlight differs
#. so that the behavior of `<c-p>` mode is consistent, always moving up the
list and
#. when starting `<c-p>` mode you don't have to switch over to
using `<c-n>` to get the next nearest entry, just continue to hit `<c-p>`.
So, with supertab I wanted to preserve the same behavior. If `<c-p>` is your
default completion method (supertab defaults to this being the case), then
`<tab>` will start it and additional uses of `<tab>` will move up the list
instead of down so that you don't have to suddenly switch to using `<s-tab>`
to get the next nearest result.
Why is `<c-p>` the supertab default? The original supertab author found (and I
agree with his finding) that while coding, the keyword match you want is
typically the closer of the matches above the cursor, which `<c-p>` naturally
provides.

View file

@ -0,0 +1,473 @@
*supertab.txt*
Author: Eric Van Dewoestine <ervandew@gmail.com>
Original concept and versions up to 0.32 written by
Gergely Kontra <kgergely@mcl.hu>
This plugin is licensed under the terms of the BSD License. Please see
supertab.vim for the license in its entirety.
==============================================================================
Supertab *supertab*
1. Introduction |supertab-intro|
2. Supertab Usage |supertab-usage|
3. Supertab Options |supertab-options|
Default completion type |supertab-defaultcompletion|
Secondary default completion type |supertab-contextdefault|
Completion contexts |supertab-completioncontexts|
Context text |supertab-contexttext|
Context Discover |supertab-contextdiscover|
Example |supertab-contextexample|
Completion Duration |supertab-duration|
Preventing Completion After/Before... |supertab-preventcomplete|
Changing default mapping |supertab-forwardbackward|
Inserting true tabs |supertab-mappingtabliteral|
Enhanced longest match support |supertab-longestenhanced|
Preselecting the first entry |supertab-longesthighlight|
Mapping <cr> to end completion |supertab-crmapping|
Auto close the preview window |supertab-closepreviewonpopupclose|
Keyword completion ignore/match case |supertab-completecase|
Completion Chaining |supertab-completionchaining|
==============================================================================
1. Introduction *supertab-intro*
Supertab is a plugin which allows you to perform all your insert completion
(|ins-completion|) using the tab key.
Supertab requires Vim version 7.0 or above.
==============================================================================
2. Supertab usage *supertab-usage*
Using Supertab is as easy as hitting <Tab> or <S-Tab> (shift+tab) while in
insert mode, with at least one non whitespace character before the cursor, to
start the completion and then <Tab> or <S-Tab> again to cycle forwards or
backwards through the available completions.
Example ('|' denotes the cursor location):
bar
baz
b|<Tab> Hitting <Tab> here will start the completion, allowing you to
then cycle through the suggested words ('bar' and 'baz').
==============================================================================
3. Supertab Options *supertab-options*
Supertab is configured via several global variables that you can set in your
|vimrc| file according to your needs. Below is a comprehensive list of
the variables available.
Default Completion Type *supertab-defaultcompletion*
*g:SuperTabDefaultCompletionType*
g:SuperTabDefaultCompletionType (default value: "<c-p>")
Used to set the default completion type. There is no need to escape this
value as that will be done for you when the type is set.
Example: setting the default completion to 'user' completion:
>
let g:SuperTabDefaultCompletionType = "<c-x><c-u>"
<
Note: a special value of 'context' is supported which will result in
super tab attempting to use the text preceding the cursor to decide which
type of completion to attempt. Currently supertab can recognize method calls
or attribute references via '.', '::' or '->', and file path references
containing '/'. If the language you are using doesn't use any of the member
reference characters listed above, or you'd like to add additional patterns,
you can write a custom context function also described in the next section
(Completion context).
Example: setting the default completion to supertab's 'context' completion:
>
let g:SuperTabDefaultCompletionType = "context"
<
/usr/l<tab> # will use filename completion
myvar.t<tab> # will use user completion if completefunc set,
# or omni completion if omnifunc set.
myvar-><tab> # same as above
When using context completion, super tab will fall back to a secondary default
completion type set by |g:SuperTabContextDefaultCompletionType|.
Note: once the buffer has been initialized, changing the value of this setting
will not change the default complete type used. If you want to change the
default completion type for the current buffer after it has been set, perhaps
in an ftplugin, you'll need to call *SuperTabSetDefaultCompletionType* like so,
supplying the completion type you wish to switch to:
>
call SuperTabSetDefaultCompletionType("<c-x><c-u>")
<
Secondary default completion type *supertab-contextdefault*
*g:SuperTabContextDefaultCompletionType*
g:SuperTabContextDefaultCompletionType (default value: "<c-p>")
Sets the default completion type used when g:SuperTabDefaultCompletionType is
set to 'context' and no completion type is returned by any of the configured
contexts.
Note: supertab also supports the b:SuperTabContextDefaultCompletionType
variable allowing you to set the default type separately for the current
buffer, like from an ftplugin for example.
Completion contexts *supertab-completioncontexts*
*g:SuperTabCompletionContexts*
g:SuperTabCompletionContexts (default value: ['s:ContextText'])
Sets the list of contexts used for context completion. This value should
be a list of function names which provide the context implementation.
When supertab starts context completion, each of these contexts will be
consulted, in the order they were supplied, to determine the completion type
to use. If a context returns a completion type, that type will be used,
otherwise the next context in the list will be consulted. If after executing
all the context functions, no completion type has been determined, then the
value of |g:SuperTabContextDefaultCompletionType| will be used.
Note: supertab also supports the b:SuperTabCompletionContexts variable
allowing you to set the list of contexts separately for the current buffer,
like from an ftplugin for example.
Built in completion contexts:
s:ContextText *supertab-contexttext*
The text context will examine the text near the cursor to decide which type
of completion to attempt. Currently the text context can recognize method
calls or attribute references via '.', '::' or '->', and file path
references containing '/'.
/usr/l<tab> # will use filename completion
myvar.t<tab> # will use user completion if completefunc set, or
# omni completion if omnifunc set.
myvar-><tab> # same as above
Supported configuration attributes:
*g:SuperTabContextTextFileTypeExclusions*
List of file types for which the text context will be skipped.
*g:SuperTabContextTextOmniPrecedence* (default: ['&completefunc', '&omnifunc'])
*b:SuperTabContextTextOmniPrecedence*
List of omni completion option names in the order of precedence that they
should be used if available. By default, user completion will be given
precedence over omni completion, but you can use this variable to give
omni completion higher precedence by placing it first in the list.
*g:SuperTabContextTextMemberPatterns* (default: ['\.', '>\?::', '->'])
*b:SuperTabContextTextMemberPatterns*
List of patterns used to determine when omni/user completion should be
used. The default list consists of the most common patterns used to access
module/class/object members.
Note: For html and xml based files, the buffer local version of the above
two settings are set to trigger omni completion first when encountering a
potential end tag pattern of '</'.
s:ContextDiscover *supertab-contextdiscover*
This context will use the 'g:SuperTabContextDiscoverDiscovery' variable to
determine the completion type to use. It will evaluate each value, in the
order they were defined, until a variable evaluates to a non-zero or
non-empty value, then the associated completion type is used.
Supported configuration properties:
g:SuperTabContextDiscoverDiscovery
List of variable:completionType mappings.
Example context configuration: *supertab-contextexample*
>
let g:SuperTabCompletionContexts = ['s:ContextText', 's:ContextDiscover']
let g:SuperTabContextTextOmniPrecedence = ['&omnifunc', '&completefunc']
let g:SuperTabContextDiscoverDiscovery =
\ ["&completefunc:<c-x><c-u>", "&omnifunc:<c-x><c-o>"]
<
In addition to the default completion contexts, you can plug in your own
implementation by creating a globally accessible function that returns
the completion type to use (eg. "\<c-x>\<c-u>").
>
function MyTagContext()
if filereadable(expand('%:p:h') . '/tags')
return "\<c-x>\<c-]>"
endif
" no return will result in the evaluation of the next
" configured context
endfunction
let g:SuperTabCompletionContexts =
\ ['MyTagContext', 's:ContextText', 's:ContextDiscover']
<
Here is another example that could be used to add context support for
clojure, and perhaps other lisp variants:
>
let b:SuperTabCompletionContexts =
\ ['ClojureContext'] + g:SuperTabCompletionContexts
function! ClojureContext()
let curline = getline('.')
let cnum = col('.')
let synname = synIDattr(synID(line('.'), cnum - 1, 1), 'name')
if curline =~ '(\S\+\%' . cnum . 'c' && synname !~ '\(String\|Comment\)'
return "\<c-x>\<c-o>"
endif
endfunction
<
Completion Duration *supertab-duration*
*g:SuperTabRetainCompletionDuration*
g:SuperTabRetainCompletionDuration (default value: 'insert')
Determines if, and for how long, the current completion type is retained.
The possible values include:
'completion' - The current completion type is only retained for the
current completion. Once you have chosen a completion
result or exited the completion mode, the default
completion type is restored.
'insert' - The current completion type is saved until you exit insert
mode (via ESC). Once you exit insert mode the default
completion type is restored. (supertab default)
'session' - The current completion type is saved for the duration of
your vim session or until you enter a different completion
mode.
Preventing completion after... *supertab-preventcomplete*
*g:SuperTabNoCompleteBefore*
*g:SuperTabNoCompleteAfter*
g:SuperTabNoCompleteBefore (default value: [])
g:SuperTabNoCompleteAfter (default value: ['^', '\s'])
These two variables are used to control when supertab will attempt completion
or instead fall back to inserting a literal <tab>. There are two possible ways
to define these variables:
1) by specifying a list of patterns which are tested against the text before
and after the current cursor position that when matched, prevent completion.
So if you don't want supertab to start completion at the start of a line,
after a comma, or after a space, you can set g:SuperTabNoCompleteAfter
to ['^', ',', '\s'].
2) by specifying a funcref to a global accessible function which expects
as parameter the text to be inspected (before or after) and, based on that (or
other factors), it returns 1 if completion must be prevented, 0 otherwise.
Note: That a buffer local version of these variables
(b:SuperTabNoCompleteBefore, b:SuperTabNoCompleteAfter) are also supported
should you wish to have different values depending on the file type for
instance.
Changing the default mapping *supertab-forwardbackward*
*g:SuperTabMappingForward*
*g:SuperTabMappingBackward*
g:SuperTabMappingForward (default value: '<tab>')
g:SuperTabMappingBackward (default value: '<s-tab>')
These two variables allow you to set the keys used to kick off the current
completion. By default this is <tab> and <s-tab>. To change to something
like <c-space> and <s-c-space>, you can add the following to your |vimrc|.
>
let g:SuperTabMappingForward = '<c-space>'
let g:SuperTabMappingBackward = '<s-c-space>'
>
Note: if the above does not have the desired effect (which may happen in
console version of vim), you can try the following mappings. Although the
backwards mapping still doesn't seem to work in the console for me, your
milage may vary.
>
let g:SuperTabMappingForward = '<nul>'
let g:SuperTabMappingBackward = '<s-nul>'
<
Inserting true tabs *supertab-mappingtabliteral*
*g:SuperTabMappingTabLiteral*
g:SuperTabMappingTabLiteral (default value: '<c-tab>')
Sets the key mapping used to insert a literal tab where supertab would
otherwise attempt to kick off insert completion. The default is '<c-tab>'
(ctrl-tab) which unfortunately might not work at the console. So if you are
using a console vim and want this functionality, you may have to change it to
something that is supported. Alternatively, you can escape the <tab> with
<c-v> (see |i_CTRL-V| for more infos).
See also |supertab-preventcomplete|.
Enhanced longest match support *supertab-longestenhanced*
*g:SuperTabLongestEnhanced*
g:SuperTabLongestEnhanced (default value: 0)
When enabled and 'longest' is in your |completeopt| setting, supertab will
provide an enhanced longest match support where typing one or more letters and
hitting tab again while in a completion mode will complete the longest common
match using the new text in the buffer.
For example, say you have a buffer with the following contents:
FooBarFoo
FooBar
Foo
FooBarBaz
And you then type F<tab>. Vim's builtin longest support will complete the
longest common text 'Foo' and offer 'FooBarFoo', 'FooBar', 'Foo', and
'FooBarBaz' as possible completions. With supertab's longest match
enhancement disabled, typing B<tab> while still in the completion mode will
end up completing 'FooBarBaz' or 'FooBarFoo' depending your settings, instead
of the next longest common match of 'FooBar'. With supertab's enhanced
longest match feature enabled, the typing of B<tab> will result in the next
longest text being completed.
Preselecting the first entry *supertab-longesthighlight*
*g:SuperTabLongestHighlight*
g:SuperTabLongestHighlight (default value: 0)
Sets whether or not to pre-highlight the first match when completeopt has the
popup menu enabled and the 'longest' option as well. When enabled, <tab> will
kick off completion and pre-select the first entry in the popup menu, allowing
you to simply hit <enter> to use it.
Mapping <cr> to end completion *supertab-crmapping*
*g:SuperTabCrMapping*
g:SuperTabCrMapping (default value: 0)
When enabled, <cr> will cancel completion mode preserving the current text.
Compatibility with other plugins:
- endwise: compatible
- delimitMate: not compatible (disabled if the delimitMate <cr> mapping is
detected.)
Note: if you have an insert expression mapping with a <cr> in it or an insert
abbreviation containing a <cr>, then supertab will not create a <cr> mapping
which could potentially cause problems with those.
Auto close the preview window *supertab-closepreviewonpopupclose*
*g:SuperTabClosePreviewOnPopupClose*
g:SuperTabClosePreviewOnPopupClose (default value: 0)
When enabled, supertab will attempt to close vim's completion preview window
when the completion popup closes (completion is finished or canceled).
Completion ignore/match case *supertab-completecase*
*g:SuperTabCompleteCase*
g:SuperTabCompleteCase (default value: 'inherit')
When issuing completions (keyword and potentially others), the value of your
|'ignorecase'| setting will determine what results are returned based on
whether or not you've chosen to ignore case or not. However, you may have
|'ignorecase'| set or unset for other reasons and don't want that value
considered when using insert completion. SuperTab allows you temporarily
override |'ignorecase'| by setting g:SuperTabCompleteCase to either 'ignore'
or 'match' depending on whether you want to always ignore or match case when
using insert completion.
Note: third party omni/user completion plugins may or may not honor
|'ignorecase'|. If they do not, then you can probably contact them to add that
support.
Completion Chaining *supertab-completionchaining*
SuperTab provides the ability to chain one of the completion functions
(|completefunc| or |omnifunc|) together with one of the default vim
completion key sequences (|ins-completion|), giving you the ability to attempt
completion with the first, and upon no results, fall back to the second.
To utilize this feature you need to call the *SuperTabChain* function where
the first argument is the name of a vim compatible |complete-function| and the
second is one of vim's insert completion (|ins-completion|) key bindings
(<c-p>, <c-n>, <c-x><c-]>, etc). Calling this function will set the current
buffer's |completefunc| option to a supertab provided implementation which
utilizes the supplied arguments to perform the completion.
Here is an example that can be added to your .vimrc which will setup the
supertab chaining for any filetype that has a provided |omnifunc| to first
try that, then fall back to supertab's default, <c-p>, completion:
>
autocmd FileType *
\ if &omnifunc != '' |
\ call SuperTabChain(&omnifunc, "<c-p>") |
\ endif
<
You can also specify whether or not the 'context' completion method will
be used as part of your completion chaining. If you've already set your
default completion type to 'context', then no further action is needed. If
however you haven't set that or don't want to use 'context' completion in this
case, then you can supply a third argument to SuperTabChain which is a boolean
(1 or 0) indicationg whether you want to use 'context' completion (1) or not
(0).
Here is an example where 'context' is the global default and completion
chaining is enabled for file types that have omni completion support:
>
let g:SuperTabDefaultCompletionType = 'context'
autocmd FileType *
\ if &omnifunc != '' |
\ call SuperTabChain(&omnifunc, "<c-p>") |
\ endif
<
This configuration will result in a completion flow like so:
if text before the cursor looks like a file path:
use file completion
elif text before the cursor looks like an attempt to access a member
(method, field, etc):
use user completion
where user completion is currently set to supertab's
completion chaining, resulting in:
if omni completion has results:
use omni completion
else:
use keyword completion
else:
use keyword completion
Note: Completion chaining only supports chaining 1 completion function (omni
or user) with 1 regular completion keybinding. All other combinations of
completions (2 or more completion functions, 2 or more key bindings, etc.) are
not supported due to limitations imposed by vim's code completion
implementation.
Note: If the |completefunc| or |omnifunc| use vim's |complete_add()| instead
of returning completion results as a list, then Supertab's completion chaining
won't work properly with it since Supertab uses the function result to
determine if it should fallback to the next completion type.
vim:tw=78:ts=8:ft=help:norl:

View file

@ -0,0 +1,61 @@
" Author: Eric Van Dewoestine <ervandew@gmail.com>
"
" License: {{{
" Copyright (c) 2014
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * Redistributions in binary form must reproduce the above
" copyright notice, this list of conditions and the
" following disclaimer in the documentation and/or other
" materials provided with the distribution.
"
" * Neither the name of Gergely Kontra or Eric Van Dewoestine nor the names
" of its contributors may be used to endorse or promote products derived
" from this software without specific prior written permission of Gergely
" Kontra or Eric Van Dewoestine.
"
" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
" IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
" THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
" }}}
if !exists('b:SuperTabContextTextMemberPatterns')
let b:SuperTabContextTextMemberPatterns = ['</']
endif
if !exists('b:SuperTabContextTextOmniPrecedence')
let set_precedence = 1
" don't set omni precedence when user is using eclim + php
if &ft == 'php'
try
let project = eclim#project#util#GetCurrentProjectName()
if project != ''
let natures = eclim#project#util#GetProjectNatureAliases(project)
let set_precedence = !eclim#util#ListContains(natures, 'php')
endif
catch /E117/
endtry
endif
if set_precedence
let b:SuperTabContextTextOmniPrecedence = ['&omnifunc', '&completefunc']
endif
endif
" vim:ft=vim:fdm=marker

View file

@ -0,0 +1,45 @@
" Author: Eric Van Dewoestine <ervandew@gmail.com>
"
" License: {{{
" Copyright (c) 2014
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * Redistributions in binary form must reproduce the above
" copyright notice, this list of conditions and the
" following disclaimer in the documentation and/or other
" materials provided with the distribution.
"
" * Neither the name of Gergely Kontra or Eric Van Dewoestine nor the names
" of its contributors may be used to endorse or promote products derived
" from this software without specific prior written permission of Gergely
" Kontra or Eric Van Dewoestine.
"
" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
" IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
" THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
" }}}
if !exists('b:SuperTabContextTextMemberPatterns')
let b:SuperTabContextTextMemberPatterns = ['</']
endif
if !exists('b:SuperTabContextTextOmniPrecedence')
let b:SuperTabContextTextOmniPrecedence = ['&omnifunc', '&completefunc']
endif
" vim:ft=vim:fdm=marker

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,66 @@
System Copy
===========
System copy provides vim mappings for copying / pasting text to the os specific
clipboard. Most people will be happy just setting their Vim clipboard to the
system clipboard, but I find that doing so pollutes my clipboard history.
Instead, this plugin creates a unique mapping that explicitly pulls content
from Vim into the system clipboard.
Usage
-----
System copy provides a mapping to copy to the system clipboard using a motion
or visual selection. It also provides a mapping for pasting from the system
clipboard.
The default mapping is `cp`, and can be followed by any motion or text
object. For instance:
- `cpiw` => copy word into system clipboard
- `cpi'` => copy inside single quotes to system clipboard
In addition, `cP` is mapped to copy the current line directly.
The sequence `cv` is mapped to paste the content of system clipboard to the
next line.
Clipboard Utilities
-------------------
- OSX - `pbcopy` and `pbpaste`
- Windows - `clip` and `paste`
- Linux - `xsel`
Options
-------
`system-copy` uses default copy and paste command based on your OS, but
you can override either of these commands if you have more specific needs.
To declare custom copy command use following example:
``` vim
let g:system_copy#copy_command='xclip -sel clipboard'
```
And to declare custom paste command use:
``` vim
let g:system_copy#paste_command='xclip -sel clipboard -o'
```
Installation
------------
If you don't have a preferred installation method, I recommend using [Vundle](https://github.com/VundleVim/Vundle.vim).
Assuming you have Vundle installed and configured, the following steps will
install the plugin:
Add the following line to your `~/.vimrc` and then run `:PluginInstall` from
within Vim:
``` vim
call vundle#begin()
" ...
Plugin 'christoomey/vim-system-copy'
" ...
call vundle#end()
```

View file

@ -0,0 +1,111 @@
if exists('g:loaded_system_copy') || v:version < 700
finish
endif
let g:loaded_system_copy = 1
let s:blockwise = 'blockwise visual'
let s:visual = 'visual'
let s:motion = 'motion'
let s:linewise = 'linewise'
let s:mac = 'mac'
let s:windows = 'windows'
let s:linux = 'linux'
function! s:system_copy(type, ...) abort
let mode = <SID>resolve_mode(a:type, a:0)
if mode == s:linewise
let lines = { 'start': line("'["), 'end': line("']") }
silent exe lines.start . "," . lines.end . "y"
elseif mode == s:visual || mode == s:blockwise
silent exe "normal! `<" . a:type . "`>y"
else
silent exe "normal! `[v`]y"
endif
let command = s:CopyCommandForCurrentOS()
silent call system(command, getreg('@'))
echohl String | echon 'Copied to clipboard using: ' . command | echohl None
endfunction
function! s:system_paste() abort
let command = <SID>PasteCommandForCurrentOS()
put =system(command)
echohl String | echon 'Pasted to vim using: ' . command | echohl None
endfunction
function! s:resolve_mode(type, arg)
let visual_mode = a:arg != 0
if visual_mode
return (a:type == '') ? s:blockwise : s:visual
elseif a:type == 'line'
return s:linewise
else
return s:motion
endif
endfunction
function! s:currentOS()
let os = substitute(system('uname'), '\n', '', '')
let known_os = 'unknown'
if has("gui_mac") || os ==? 'Darwin'
let known_os = s:mac
elseif has("gui_win32")
let known_os = s:windows
elseif os ==? 'Linux'
let known_os = s:linux
else
exe "normal \<Esc>"
throw "unknown OS: " . os
endif
return known_os
endfunction
function! s:CopyCommandForCurrentOS()
if exists('g:system_copy#copy_command')
return g:system_copy#copy_command
endif
let os = <SID>currentOS()
if os == s:mac
return 'pbcopy'
elseif os == s:windows
return 'clip'
elseif os == s:linux
return 'xsel --clipboard --input'
endif
endfunction
function! s:PasteCommandForCurrentOS()
if exists('g:system_copy#paste_command')
return g:system_copy#paste_command
endif
let os = <SID>currentOS()
if os == s:mac
return 'pbpaste'
elseif os == s:windows
return 'paste'
elseif os == s:linux
return 'xsel --clipboard --output'
endif
endfunction
xnoremap <silent> <Plug>SystemCopy :<C-U>call <SID>system_copy(visualmode(),visualmode() ==# 'V' ? 1 : 0)<CR>
nnoremap <silent> <Plug>SystemCopy :<C-U>set opfunc=<SID>system_copy<CR>g@
nnoremap <silent> <Plug>SystemCopyLine :<C-U>set opfunc=<SID>system_copy<Bar>exe 'norm! 'v:count1.'g@_'<CR>
nnoremap <silent> <Plug>SystemPaste :<C-U>call <SID>system_paste()<CR>
if !hasmapto('<Plug>SystemCopy', 'n') || maparg('cp', 'n') ==# ''
nmap cp <Plug>SystemCopy
endif
if !hasmapto('<Plug>SystemCopy', 'v') || maparg('cp', 'v') ==# ''
xmap cp <Plug>SystemCopy
endif
if !hasmapto('<Plug>SystemCopyLine', 'n') || maparg('cP', 'n') ==# ''
nmap cP <Plug>SystemCopyLine
endif
if !hasmapto('<Plug>SystemPaste', 'n') || maparg('cv', 'n') ==# ''
nmap cv <Plug>SystemPaste
endif
" vim:ts=2:sw=2:sts=2