mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-06 20:54:31 +08:00
Now re-do-safe, except for <CR> expansion.
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,6 +1,10 @@
|
|||||||
PLUGIN=delimitMate
|
PLUGIN=delimitMate
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
install -m 755 -d ~/.vim
|
||||||
|
install -m 755 -d ~/.vim/plugin/
|
||||||
|
install -m 755 -d ~/.vim/autoload/
|
||||||
|
install -m 755 -d ~/.vim/doc/
|
||||||
cp -f doc/${PLUGIN}.txt ~/.vim/doc/${PLUGIN}.txt
|
cp -f doc/${PLUGIN}.txt ~/.vim/doc/${PLUGIN}.txt
|
||||||
cp -f plugin/${PLUGIN}.vim ~/.vim/plugin/${PLUGIN}.vim
|
cp -f plugin/${PLUGIN}.vim ~/.vim/plugin/${PLUGIN}.vim
|
||||||
cp -f autoload/${PLUGIN}.vim ~/.vim/autoload/${PLUGIN}.vim
|
cp -f autoload/${PLUGIN}.vim ~/.vim/autoload/${PLUGIN}.vim
|
||||||
|
|||||||
@@ -167,6 +167,11 @@ function! delimitMate#IsForbidden(char) "{{{
|
|||||||
"return result || region == 'Comment'
|
"return result || region == 'Comment'
|
||||||
return result
|
return result
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! delimitMate#FlushBuffer() " {{{
|
||||||
|
let b:delimitMate_buffer = []
|
||||||
|
return ''
|
||||||
|
endfunction " }}}
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Doers {{{
|
" Doers {{{
|
||||||
@@ -175,9 +180,11 @@ function! delimitMate#JumpIn(char) " {{{
|
|||||||
let col = col('.')-2
|
let col = col('.')-2
|
||||||
if (col) < 0
|
if (col) < 0
|
||||||
call setline('.',a:char.line)
|
call setline('.',a:char.line)
|
||||||
|
call insert(b:delimitMate_buffer, a:char)
|
||||||
else
|
else
|
||||||
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
||||||
call setline('.',line[:(col)].a:char.line[(col+1):])
|
call setline('.',line[:(col)].a:char.line[(col+1):])
|
||||||
|
call insert(b:delimitMate_buffer, a:char)
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
@@ -187,6 +194,7 @@ function! delimitMate#JumpOut(char) "{{{
|
|||||||
let col = col('.')-2
|
let col = col('.')-2
|
||||||
if line[col+1] == a:char
|
if line[col+1] == a:char
|
||||||
call setline('.',line[:(col)].line[(col+2):])
|
call setline('.',line[:(col)].line[(col+2):])
|
||||||
|
call delimitMate#RmBuffer(1)
|
||||||
endif
|
endif
|
||||||
return a:char
|
return a:char
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
@@ -197,10 +205,13 @@ function! delimitMate#JumpAny() " {{{
|
|||||||
if char == " "
|
if char == " "
|
||||||
" Space expansion.
|
" Space expansion.
|
||||||
let char = char . getline('.')[col('.')] . "\<Del>"
|
let char = char . getline('.')[col('.')] . "\<Del>"
|
||||||
|
call delimitMate#RmBuffer(2)
|
||||||
elseif char == ""
|
elseif char == ""
|
||||||
" CR expansion.
|
" CR expansion.
|
||||||
let char = "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
|
let char = "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
|
||||||
|
let b:delimitMate_buffer = []
|
||||||
endif
|
endif
|
||||||
|
call delimitMate#RmBuffer(1)
|
||||||
return char . "\<Del>"
|
return char . "\<Del>"
|
||||||
endfunction " delimitMate#JumpAny() }}}
|
endfunction " delimitMate#JumpAny() }}}
|
||||||
|
|
||||||
@@ -257,6 +268,7 @@ function! delimitMate#ExpandReturn() "{{{
|
|||||||
if delimitMate#WithinEmptyPair() &&
|
if delimitMate#WithinEmptyPair() &&
|
||||||
\ b:delimitMate_expand_cr
|
\ b:delimitMate_expand_cr
|
||||||
" Expand:
|
" Expand:
|
||||||
|
call delimitMate#FlushBuffer()
|
||||||
return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
|
return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
|
||||||
else
|
else
|
||||||
return "\<CR>"
|
return "\<CR>"
|
||||||
@@ -267,6 +279,7 @@ function! delimitMate#ExpandSpace() "{{{
|
|||||||
if delimitMate#WithinEmptyPair() &&
|
if delimitMate#WithinEmptyPair() &&
|
||||||
\ b:delimitMate_expand_space
|
\ b:delimitMate_expand_space
|
||||||
" Expand:
|
" Expand:
|
||||||
|
call insert(b:delimitMate_buffer, 's')
|
||||||
return delimitMate#WriteAfter(' ') . "\<Space>"
|
return delimitMate#WriteAfter(' ') . "\<Space>"
|
||||||
else
|
else
|
||||||
return "\<Space>"
|
return "\<Space>"
|
||||||
@@ -275,15 +288,44 @@ endfunction "}}}
|
|||||||
|
|
||||||
function! delimitMate#BS() " {{{
|
function! delimitMate#BS() " {{{
|
||||||
if delimitMate#WithinEmptyPair()
|
if delimitMate#WithinEmptyPair()
|
||||||
return "\<Right>\<BS>\<BS>"
|
call delimitMate#RmBuffer(1)
|
||||||
|
return "\<BS>\<Del>"
|
||||||
|
" return "\<Right>\<BS>\<BS>"
|
||||||
elseif b:delimitMate_expand_cr &&
|
elseif b:delimitMate_expand_cr &&
|
||||||
\ (delimitMate#IsCRExpansion() != 0 || delimitMate#IsSpaceExpansion())
|
\ (delimitMate#IsCRExpansion() != 0 || delimitMate#IsSpaceExpansion())
|
||||||
|
call delimitMate#RmBuffer(1)
|
||||||
return "\<BS>\<Del>"
|
return "\<BS>\<Del>"
|
||||||
else
|
else
|
||||||
return "\<BS>"
|
return "\<BS>"
|
||||||
endif
|
endif
|
||||||
endfunction " }}} delimitMate#BS()
|
endfunction " }}} delimitMate#BS()
|
||||||
|
|
||||||
|
function! delimitMate#Finish() " {{{
|
||||||
|
let len = len(b:delimitMate_buffer)
|
||||||
|
if len > 0
|
||||||
|
let buffer = join(b:delimitMate_buffer, '')
|
||||||
|
let line = getline('.')
|
||||||
|
let col = col('.') -2
|
||||||
|
echom 'col: ' . col . '-' . line[:col] . "|" . line[col+len+1:] . '%' . buffer
|
||||||
|
call setline('.', line[:col] . line[col+len+1:])
|
||||||
|
let i = 1
|
||||||
|
let lefts = ''
|
||||||
|
while i < len
|
||||||
|
let lefts = lefts . "\<Left>"
|
||||||
|
let i += 1
|
||||||
|
endwhile
|
||||||
|
return substitute(buffer, "s", "\<Space>", 'g') . lefts
|
||||||
|
endif
|
||||||
|
return ''
|
||||||
|
endfunction " }}}
|
||||||
|
|
||||||
|
function! delimitMate#RmBuffer(num) " {{{
|
||||||
|
if len(b:delimitMate_buffer) > 0
|
||||||
|
call remove(b:delimitMate_buffer, 0, (a:num-1))
|
||||||
|
endif
|
||||||
|
return ""
|
||||||
|
endfunction " }}}
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Mappers: {{{
|
" Mappers: {{{
|
||||||
@@ -302,7 +344,7 @@ function! delimitMate#AutoClose() "{{{
|
|||||||
let ld = b:delimitMate_left_delims[i]
|
let ld = b:delimitMate_left_delims[i]
|
||||||
let rd = b:delimitMate_right_delims[i]
|
let rd = b:delimitMate_right_delims[i]
|
||||||
exec 'inoremap <buffer> ' . ld . ' ' . ld . '<C-R>=delimitMate#JumpIn("' . rd . '")<CR>'
|
exec 'inoremap <buffer> ' . ld . ' ' . ld . '<C-R>=delimitMate#JumpIn("' . rd . '")<CR>'
|
||||||
"exec 'inoremap <buffer> ' . ld . ' ' '<C-R>=delimitMate#JumpIn("' . ld . '")<CR>'
|
"exec 'inoremap <buffer> ' . ld . ' <C-R>=delimitMate#JumpIn("' . ld . '")<CR>'
|
||||||
let i += 1
|
let i += 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
@@ -368,6 +410,20 @@ function! delimitMate#ExtraMappings() "{{{
|
|||||||
if b:delimitMate_tab2exit
|
if b:delimitMate_tab2exit
|
||||||
inoremap <buffer> <expr> <S-Tab> delimitMate#ShouldJump() ? delimitMate#JumpAny() : "\<S-Tab>"
|
inoremap <buffer> <expr> <S-Tab> delimitMate#ShouldJump() ? delimitMate#JumpAny() : "\<S-Tab>"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Fix the re-do feature:
|
||||||
|
inoremap <buffer> <Esc> <C-R>=delimitMate#Finish()<CR><Esc>
|
||||||
|
|
||||||
|
" Flush the char buffer on mouse click:
|
||||||
|
inoremap <buffer> <LeftMouse> <C-R>=delimitMate#FlushBuffer()<CR><LeftMouse>
|
||||||
|
inoremap <buffer> <RightMouse> <C-R>=delimitMate#FlushBuffer()<CR><RightMouse>
|
||||||
|
|
||||||
|
" Flush the char buffer on key movements:
|
||||||
|
inoremap <buffer> <Left> <C-R>=delimitMate#FlushBuffer()<CR><Left>
|
||||||
|
inoremap <buffer> <Right> <C-R>=delimitMate#FlushBuffer()<CR><Right>
|
||||||
|
inoremap <buffer> <Up> <C-R>=delimitMate#FlushBuffer()<CR><Up>
|
||||||
|
inoremap <buffer> <Down> <C-R>=delimitMate#FlushBuffer()<CR><Down>
|
||||||
|
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
@@ -423,6 +479,9 @@ function! delimitMate#TestMappings() "{{{
|
|||||||
exec "normal \<Esc>i"
|
exec "normal \<Esc>i"
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! delimitMate#Tests() " {{{
|
||||||
|
|
||||||
|
endfunction " }}}
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
" vim:foldmethod=marker:foldcolumn=4
|
" vim:foldmethod=marker:foldcolumn=4
|
||||||
|
|||||||
@@ -1,22 +1,9 @@
|
|||||||
" ============================================================================
|
" ============================================================================
|
||||||
" File: delimitMate.vim
|
" File: plugin/delimitMate.vim
|
||||||
" Version: 2.0
|
" Version: 2.1
|
||||||
" Description: This plugin tries to emulate the auto-completion of delimiters
|
" Description: This plugin provides auto-completion for quotes, parens, etc.
|
||||||
" that TextMate provides.
|
|
||||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||||
" Manual: Read ":help delimitMate".
|
" Manual: Read ":help delimitMate".
|
||||||
" Credits: Some of the code is modified or just copied from the following:
|
|
||||||
"
|
|
||||||
" - Ian McCracken
|
|
||||||
" Post titled: Vim, Part II: Matching Pairs:
|
|
||||||
" http://concisionandconcinnity.blogspot.com/
|
|
||||||
"
|
|
||||||
" - Aristotle Pagaltzis
|
|
||||||
" From the comments on the previous blog post and from:
|
|
||||||
" http://gist.github.com/144619
|
|
||||||
"
|
|
||||||
" - Vim Scripts:
|
|
||||||
" http://www.vim.org/scripts/
|
|
||||||
|
|
||||||
" Initialization: {{{
|
" Initialization: {{{
|
||||||
if exists("g:loaded_delimitMate") "{{{
|
if exists("g:loaded_delimitMate") "{{{
|
||||||
@@ -295,6 +282,12 @@ autocmd FileType * call <SID>DelimitMateDo()
|
|||||||
" Run on new buffers.
|
" Run on new buffers.
|
||||||
autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif
|
autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif
|
||||||
|
|
||||||
|
" Flush the char buffer:
|
||||||
|
autocmd InsertEnter * call delimitMate#FlushBuffer()
|
||||||
|
autocmd BufEnter * if mode() == 'i' | call delimitMate#FlushBuffer() | endif
|
||||||
|
|
||||||
|
"function! s:GetSynRegion () | echo synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') | endfunction
|
||||||
|
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
|
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
|
||||||
|
|||||||
Reference in New Issue
Block a user