mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-07 13:14:35 +08:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
422420c494 | ||
|
|
2c8b586679 | ||
|
|
e748b461b6 | ||
|
|
17a061a1fa | ||
|
|
29d42e0771 | ||
|
|
e818c05e33 | ||
|
|
29cb16c42e | ||
|
|
d478e75178 | ||
|
|
eb03c7058e | ||
|
|
1e7a5c7f6e | ||
|
|
b9bd9e3229 | ||
|
|
b25906e610 | ||
|
|
5ca0eee4cd | ||
|
|
a751498fbc | ||
|
|
9292c9294a | ||
|
|
4083c581d6 | ||
|
|
86ff123318 | ||
|
|
a8cbf2e429 | ||
|
|
96d53eaa31 | ||
|
|
b5292f7c58 | ||
|
|
6b80cfefb6 | ||
|
|
7540b37e8f |
14
Makefile
14
Makefile
@@ -1,19 +1,27 @@
|
||||
PLUGIN=delimitMate
|
||||
|
||||
install:
|
||||
cp -f doc/* ~/.vim/doc/${PLUGIN}.txt
|
||||
cp -f plugin/* ~/.vim/plugin/${PLUGIN}.vim
|
||||
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 plugin/${PLUGIN}.vim ~/.vim/plugin/${PLUGIN}.vim
|
||||
cp -f autoload/${PLUGIN}.vim ~/.vim/autoload/${PLUGIN}.vim
|
||||
cp -f autoload/${PLUGIN}Tests.vim ~/.vim/autoload/${PLUGIN}Tests.vim
|
||||
|
||||
doc_update: install
|
||||
/usr/bin/vim -u NONE -c ':helptags ~/.vim/doc' -c ':q'
|
||||
|
||||
zip:
|
||||
zip -r ${PLUGIN}.zip doc plugin
|
||||
zip -r ${PLUGIN}.zip doc plugin autoload
|
||||
zip ${PLUGIN}.zip -d \*.sw\?
|
||||
zip ${PLUGIN}.zip -d autoload/${PLUGIN}Tests.vim
|
||||
|
||||
vimball: install
|
||||
echo doc/${PLUGIN}.txt > vimball.txt
|
||||
echo plugin/${PLUGIN}.vim >> vimball.txt
|
||||
echo autoload/${PLUGIN}.vim >> vimball.txt
|
||||
/usr/bin/vim -c 'e vimball.txt' -c '%MkVimball! ${PLUGIN}' -c 'q'
|
||||
|
||||
gzip: vimball
|
||||
|
||||
577
autoload/delimitMate.vim
Normal file
577
autoload/delimitMate.vim
Normal file
@@ -0,0 +1,577 @@
|
||||
" ============================================================================
|
||||
" File: autoload/delimitMate.vim
|
||||
" Version: 2.1
|
||||
" Description: This plugin provides auto-completion for quotes, parens, etc.
|
||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||
" Manual: Read ":help delimitMate".
|
||||
|
||||
" Utilities {{{
|
||||
function! delimitMate#ShouldJump() "{{{
|
||||
let col = col('.')
|
||||
let lcol = col('$')
|
||||
let char = getline('.')[col - 1]
|
||||
let nchar = getline('.')[col]
|
||||
let uchar = getline(line('.') + 1)[0]
|
||||
|
||||
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
if char == cdel
|
||||
" Closing delimiter on the right.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
if b:delimitMate_expand_space && char == " "
|
||||
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
if nchar == cdel
|
||||
" Closing delimiter with space expansion.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if b:delimitMate_expand_cr && char == ""
|
||||
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
if uchar == cdel
|
||||
" Closing delimiter with CR expansion.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#IsBlockVisual() " {{{
|
||||
if mode() == "\<C-V>"
|
||||
return 1
|
||||
endif
|
||||
" Store unnamed register values for later use in delimitMate#RestoreRegister().
|
||||
let b:save_reg = getreg('"')
|
||||
let b:save_reg_mode = getregtype('"')
|
||||
|
||||
if len(getline('.')) == 0
|
||||
" This for proper wrap of empty lines.
|
||||
let @" = "\n"
|
||||
endif
|
||||
return 0
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#Visual(del) " {{{
|
||||
let mode = mode()
|
||||
if mode == "\<C-V>"
|
||||
redraw
|
||||
echom "delimitMate: delimitMate is disabled on blockwise visual mode."
|
||||
return ""
|
||||
endif
|
||||
" Store unnamed register values for later use in delimitMate#RestoreRegister().
|
||||
let b:save_reg = getreg('"')
|
||||
let b:save_reg_mode = getregtype('"')
|
||||
|
||||
if len(getline('.')) == 0
|
||||
" This for proper wrap of empty lines.
|
||||
let @" = "\n"
|
||||
endif
|
||||
|
||||
if mode ==# "V"
|
||||
let dchar = "\<BS>"
|
||||
else
|
||||
let dchar = ""
|
||||
endif
|
||||
|
||||
let index = index(b:delimitMate_left_delims, a:del)
|
||||
if index >= 0
|
||||
let ld = a:del
|
||||
let rd = b:delimitMate_right_delims[index]
|
||||
endif
|
||||
|
||||
let index = index(b:delimitMate_right_delims, a:del)
|
||||
if index >= 0
|
||||
let ld = b:delimitMate_left_delims[index]
|
||||
let rd = a:del
|
||||
endif
|
||||
|
||||
let index = index(b:delimitMate_quotes_list, a:del)
|
||||
if index >= 0
|
||||
let ld = a:del
|
||||
let rd = ld
|
||||
endif
|
||||
|
||||
return "s" . ld . "\<C-R>\"" . dchar . rd . "\<Esc>:call delimitMate#RestoreRegister()\<CR>"
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#IsEmptyPair(str) "{{{
|
||||
for pair in b:delimitMate_matchpairs_list
|
||||
if a:str == join( split( pair, ':' ),'' )
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
for quote in b:delimitMate_quotes_list
|
||||
if a:str == quote . quote
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#IsCRExpansion() " {{{
|
||||
let nchar = getline(line('.')-1)[-1:]
|
||||
let schar = getline(line('.')+1)[:0]
|
||||
let isEmpty = getline('.') == ""
|
||||
if index(b:delimitMate_left_delims, nchar) > -1 &&
|
||||
\ index(b:delimitMate_left_delims, nchar) == index(b:delimitMate_right_delims, schar) &&
|
||||
\ isEmpty
|
||||
return 1
|
||||
elseif index(b:delimitMate_quotes_list, nchar) > -1 &&
|
||||
\ index(b:delimitMate_quotes_list, nchar) == index(b:delimitMate_quotes_list, schar) &&
|
||||
\ isEmpty
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction " }}} delimitMate#IsCRExpansion()
|
||||
|
||||
function! delimitMate#IsSpaceExpansion() " {{{
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if col > 0
|
||||
let pchar = line[col - 1]
|
||||
let nchar = line[col + 2]
|
||||
let isSpaces = (line[col] == line[col+1] && line[col] == " ")
|
||||
|
||||
if index(b:delimitMate_left_delims, pchar) > -1 &&
|
||||
\ index(b:delimitMate_left_delims, pchar) == index(b:delimitMate_right_delims, nchar) &&
|
||||
\ isSpaces
|
||||
return 1
|
||||
elseif index(b:delimitMate_quotes_list, pchar) > -1 &&
|
||||
\ index(b:delimitMate_quotes_list, pchar) == index(b:delimitMate_quotes_list, nchar) &&
|
||||
\ isSpaces
|
||||
return 1
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endfunction " }}} IsSpaceExpansion()
|
||||
|
||||
function! delimitMate#WithinEmptyPair() "{{{
|
||||
let cur = strpart( getline('.'), col('.')-2, 2 )
|
||||
return delimitMate#IsEmptyPair( cur )
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#WriteBefore(str) "{{{
|
||||
let len = len(a:str)
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if col < 0
|
||||
call setline('.',line[(col+len+1):])
|
||||
else
|
||||
call setline('.',line[:(col)].line[(col+len+1):])
|
||||
endif
|
||||
return a:str
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#WriteAfter(str) "{{{
|
||||
let len = len(a:str)
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
call setline('.',a:str.line)
|
||||
else
|
||||
call setline('.',line[:(col)].a:str.line[(col+len):])
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#RestoreRegister() " {{{
|
||||
" Restore unnamed register values store in delimitMate#IsBlockVisual().
|
||||
call setreg('"', b:save_reg, b:save_reg_mode)
|
||||
echo ""
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#GetCurrentSyntaxRegion() "{{{
|
||||
return synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#GetCurrentSyntaxRegionIf(char) "{{{
|
||||
let col = col('.')
|
||||
let origin_line = getline('.')
|
||||
let changed_line = strpart(origin_line, 0, col - 1) . a:char . strpart(origin_line, col - 1)
|
||||
call setline('.', changed_line)
|
||||
let region = synIDattr(synIDtrans(synID(line('.'), col, 1)), 'name')
|
||||
call setline('.', origin_line)
|
||||
return region
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#IsForbidden(char) "{{{
|
||||
if b:delimitMate_excluded_regions_enabled = 0
|
||||
return 0
|
||||
endif
|
||||
let result = index(b:delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0
|
||||
if result >= 0
|
||||
return result + 1
|
||||
endif
|
||||
let region = delimitMate#GetCurrentSyntaxRegionIf(a:char)
|
||||
let result = index(b:delimitMate_excluded_regions_list, region) >= 0
|
||||
"return result || region == 'Comment'
|
||||
return result + 1
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#FlushBuffer() " {{{
|
||||
let b:delimitMate_buffer = []
|
||||
return ''
|
||||
endfunction " }}}
|
||||
" }}}
|
||||
|
||||
" Doers {{{
|
||||
function! delimitMate#JumpIn(char) " {{{
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
call setline('.',a:char.line)
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
else
|
||||
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
||||
call setline('.',line[:(col)].a:char.line[(col+1):])
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#JumpOut(char) "{{{
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if line[col+1] == a:char
|
||||
return a:char . delimitMate#Del()
|
||||
else
|
||||
return a:char
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#JumpAny() " {{{
|
||||
" Let's get the character on the right.
|
||||
let char = getline('.')[col('.')-1]
|
||||
if char == " "
|
||||
" Space expansion.
|
||||
"let char = char . getline('.')[col('.')] . delimitMate#Del()
|
||||
return char . getline('.')[col('.')] . delimitMate#Del() . delimitMate#Del()
|
||||
"call delimitMate#RmBuffer(1)
|
||||
elseif char == ""
|
||||
" CR expansion.
|
||||
"let char = "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
|
||||
let b:delimitMate_buffer = []
|
||||
return "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
|
||||
else
|
||||
"call delimitMate#RmBuffer(1)
|
||||
return char . delimitMate#Del()
|
||||
endif
|
||||
endfunction " delimitMate#JumpAny() }}}
|
||||
|
||||
function! delimitMate#SkipDelim(char) "{{{
|
||||
let cur = strpart( getline('.'), col('.')-2, 3 )
|
||||
if cur[0] == "\\"
|
||||
" Escaped character
|
||||
return a:char
|
||||
elseif cur[1] == a:char
|
||||
" Exit pair
|
||||
"return delimitMate#WriteBefore(a:char)
|
||||
return a:char . delimitMate#Del()
|
||||
"elseif cur[1] == ' ' && cur[2] == a:char
|
||||
"" I'm leaving this in case someone likes it. Jump an space and delimiter.
|
||||
"return "\<Right>\<Right>"
|
||||
elseif delimitMate#IsEmptyPair( cur[0] . a:char )
|
||||
" Add closing delimiter and jump back to the middle.
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
return delimitMate#WriteAfter(a:char)
|
||||
else
|
||||
" Nothing special here, return the same character.
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#QuoteDelim(char) "{{{
|
||||
let line = getline('.')
|
||||
let col = col('.') - 2
|
||||
if line[col] == "\\"
|
||||
" Seems like a escaped character, insert one quotation mark.
|
||||
return a:char
|
||||
elseif line[col + 1] == a:char
|
||||
" Get out of the string.
|
||||
"return delimitMate#WriteBefore(a:char)
|
||||
return a:char . delimitMate#Del()
|
||||
elseif (line[col] =~ '[a-zA-Z0-9]' && a:char == "'") ||
|
||||
\(line[col] =~ '[a-zA-Z0-9]' && b:delimitMate_smart_quotes)
|
||||
" Seems like an apostrophe or a closing, insert a single quote.
|
||||
return a:char
|
||||
elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:delimitMate_smart_quotes
|
||||
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
return delimitMate#WriteAfter(a:char)
|
||||
else
|
||||
" Insert a pair and jump to the middle.
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
call delimitMate#WriteAfter(a:char)
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#MapMsg(msg) "{{{
|
||||
redraw
|
||||
echomsg a:msg
|
||||
return ""
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#ExpandReturn() "{{{
|
||||
if delimitMate#WithinEmptyPair() &&
|
||||
\ b:delimitMate_expand_cr
|
||||
" Expand:
|
||||
call delimitMate#FlushBuffer()
|
||||
return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
|
||||
else
|
||||
return "\<CR>"
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#ExpandSpace() "{{{
|
||||
if delimitMate#WithinEmptyPair() &&
|
||||
\ b:delimitMate_expand_space
|
||||
" Expand:
|
||||
call insert(b:delimitMate_buffer, 's')
|
||||
return delimitMate#WriteAfter(' ') . "\<Space>"
|
||||
else
|
||||
return "\<Space>"
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#BS() " {{{
|
||||
if delimitMate#WithinEmptyPair()
|
||||
"call delimitMate#RmBuffer(1)
|
||||
return "\<BS>" . delimitMate#Del()
|
||||
" return "\<Right>\<BS>\<BS>"
|
||||
elseif b:delimitMate_expand_space &&
|
||||
\ delimitMate#IsSpaceExpansion()
|
||||
"call delimitMate#RmBuffer(1)
|
||||
return "\<BS>" . delimitMate#Del()
|
||||
elseif b:delimitMate_expand_cr &&
|
||||
\ delimitMate#IsCRExpansion()
|
||||
return "\<BS>\<Del>"
|
||||
else
|
||||
return "\<BS>"
|
||||
endif
|
||||
endfunction " }}} delimitMate#BS()
|
||||
|
||||
function! delimitMate#Del() " {{{
|
||||
if len(b:delimitMate_buffer) > 0
|
||||
let line = getline('.')
|
||||
let col = col('.') - 2
|
||||
call delimitMate#RmBuffer(1)
|
||||
call setline('.', line[:col] . line[col+2:])
|
||||
return ''
|
||||
else
|
||||
return "\<Del>"
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
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: {{{
|
||||
function! delimitMate#NoAutoClose() "{{{
|
||||
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
|
||||
for delim in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#SkipDelim("' . escape(delim,'"') . '")<CR>'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#AutoClose() "{{{
|
||||
" Add matching pair and jump to the midle:
|
||||
" inoremap <buffer> ( ()<Left>
|
||||
let i = 0
|
||||
while i < len(b:delimitMate_matchpairs_list)
|
||||
let ld = b:delimitMate_left_delims[i]
|
||||
let rd = b:delimitMate_right_delims[i]
|
||||
exec 'inoremap <buffer> ' . ld . ' ' . ld . '<C-R>=delimitMate#JumpIn("' . rd . '")<CR>'
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
" Exit from inside the matching pair:
|
||||
for delim in b:delimitMate_right_delims
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#JumpOut("\' . delim . '")<CR>'
|
||||
endfor
|
||||
|
||||
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
||||
" inoremap <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
|
||||
for delim in b:delimitMate_quotes_list
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#QuoteDelim("\' . delim . '")<CR>'
|
||||
endfor
|
||||
|
||||
" Try to fix the use of apostrophes (de-activated by default):
|
||||
" inoremap <buffer> n't n't
|
||||
for map in b:delimitMate_apostrophes_list
|
||||
exec "inoremap <buffer> " . map . " " . map
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#VisualMaps() " {{{
|
||||
let VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
|
||||
let vleader = b:delimitMate_visual_leader
|
||||
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
|
||||
for del in b:delimitMate_right_delims + b:delimitMate_left_delims + b:delimitMate_quotes_list
|
||||
exec "vnoremap <buffer> <expr> " . vleader . del . ' delimitMate#Visual("' . escape(del, '")') . '")'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#ExtraMappings() "{{{
|
||||
" If pair is empty, delete both delimiters:
|
||||
inoremap <buffer> <BS> <C-R>=delimitMate#BS()<CR>
|
||||
|
||||
" If pair is empty, delete closing delimiter:
|
||||
inoremap <buffer> <expr> <S-BS> delimitMate#WithinEmptyPair() ? "\<Del>" : "\<S-BS>"
|
||||
|
||||
" Expand return if inside an empty pair:
|
||||
if b:delimitMate_expand_cr != 0
|
||||
inoremap <buffer> <expr> <CR> delimitMate#WithinEmptyPair() ? "\<C-R>=delimitMate#ExpandReturn()\<CR>" : "\<CR>"
|
||||
endif
|
||||
|
||||
" Expand space if inside an empty pair:
|
||||
if b:delimitMate_expand_space != 0
|
||||
inoremap <buffer> <expr> <Space> delimitMate#WithinEmptyPair() ? "\<C-R>=delimitMate#ExpandSpace()\<CR>" : "\<Space>"
|
||||
endif
|
||||
|
||||
" Jump out ot any empty pair:
|
||||
if b:delimitMate_tab2exit
|
||||
inoremap <buffer> <expr> <S-Tab> delimitMate#ShouldJump() ? "\<C-R>=delimitMate#JumpAny()\<CR>" : "\<S-Tab>"
|
||||
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#Finish()<CR><LeftMouse>
|
||||
inoremap <buffer> <RightMouse> <C-R>=delimitMate#Finish()<CR><RightMouse>
|
||||
|
||||
" Flush the char buffer on key movements:
|
||||
inoremap <buffer> <Left> <C-R>=delimitMate#Finish()<CR><Left>
|
||||
inoremap <buffer> <Right> <C-R>=delimitMate#Finish()<CR><Right>
|
||||
inoremap <buffer> <Up> <C-R>=delimitMate#Finish()<CR><Up>
|
||||
inoremap <buffer> <Down> <C-R>=delimitMate#Finish()<CR><Down>
|
||||
|
||||
inoremap <buffer> <Del> <C-R>=delimitMate#Del()<CR>
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#UnMap() " {{{
|
||||
let imaps =
|
||||
\ b:delimitMate_right_delims +
|
||||
\ b:delimitMate_left_delims +
|
||||
\ b:delimitMate_quotes_list +
|
||||
\ b:delimitMate_apostrophes_list +
|
||||
\ ['<BS>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
|
||||
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>']
|
||||
|
||||
let vmaps =
|
||||
\ b:delimitMate_right_delims +
|
||||
\ b:delimitMate_left_delims +
|
||||
\ b:delimitMate_quotes_list
|
||||
|
||||
for map in imaps
|
||||
if maparg(map, "i") =~? 'delimitMate'
|
||||
exec 'silent! iunmap <buffer> ' . map
|
||||
endif
|
||||
endfor
|
||||
|
||||
if !exists("b:delimitMate_visual_leader")
|
||||
let vleader = ""
|
||||
else
|
||||
let vleader = b:delimitMate_visual_leader
|
||||
endif
|
||||
for map in vmaps
|
||||
if maparg(vleader . map, "v") =~? "delimitMate"
|
||||
exec 'silent! vunmap <buffer> ' . vleader . map
|
||||
endif
|
||||
endfor
|
||||
endfunction " }}} delimitMate#UnMap()
|
||||
|
||||
"}}}
|
||||
|
||||
" Tools: {{{
|
||||
function! delimitMate#TestMappings() "{{{
|
||||
exec "normal i*b:delimitMate_autoclose = " . b:delimitMate_autoclose . "\<CR>"
|
||||
exec "normal i*b:delimitMate_expand_space = " . b:delimitMate_expand_space . "\<CR>"
|
||||
exec "normal i*b:delimitMate_expand_cr = " . b:delimitMate_expand_cr . "\<CR>\<CR>"
|
||||
|
||||
if b:delimitMate_autoclose
|
||||
for i in range(len(b:delimitMate_left_delims))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i]. "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . " |"
|
||||
exec "normal A\<CR>Delete space: " . b:delimitMate_left_delims[i] . " \<BS>|"
|
||||
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
|
||||
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . "\<CR>|"
|
||||
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_left_delims[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
for i in range(len(b:delimitMate_quotes_list))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Delete: "
|
||||
exec "normal A". b:delimitMate_quotes_list[i]
|
||||
exec "normal a\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . " |"
|
||||
exec "normal A\<CR>Delete space: " . b:delimitMate_quotes_list[i] . " \<BS>|"
|
||||
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . "\<CR>|"
|
||||
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
else
|
||||
for i in range(len(b:delimitMate_left_delims))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . " |"
|
||||
exec "normal A\<CR>Delete space: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . " \<BS>|"
|
||||
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
|
||||
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<CR>|"
|
||||
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
for i in range(len(b:delimitMate_quotes_list))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . " |"
|
||||
exec "normal A\<CR>Delete space: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . " \<BS>|"
|
||||
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<CR>|"
|
||||
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
endif
|
||||
exec "normal \<Esc>i"
|
||||
endfunction "}}}
|
||||
|
||||
"}}}
|
||||
|
||||
" vim:foldmethod=marker:foldcolumn=4
|
||||
225
autoload/delimitMateTests.vim
Normal file
225
autoload/delimitMateTests.vim
Normal file
@@ -0,0 +1,225 @@
|
||||
function! delimitMateTests#Main() " {{{
|
||||
if !exists("g:delimitMate_testing")
|
||||
echoerr "delimitMateTests#Main(): If you really want to use me, you must set delimitMate_testing to any value."
|
||||
return
|
||||
endif
|
||||
nmap <F1> :qall!<CR>
|
||||
let b:test_results = {}
|
||||
|
||||
function! SetOptions(list) " {{{
|
||||
let b:delimitMate_autoclose = 1
|
||||
let b:delimitMate_matchpairs = &matchpairs
|
||||
let b:delimitMate_quotes = "\" ' `"
|
||||
let b:delimitMate_excluded_regions = "Comment"
|
||||
silent! unlet b:delimitMate_visual_leader
|
||||
let b:delimitMate_expand_space = 0
|
||||
let b:delimitMate_expand_cr = 0
|
||||
let b:delimitMate_smart_quotes = 1
|
||||
let b:delimitMate_apostrophes = ""
|
||||
let b:delimitMate_tab2exit = 1
|
||||
" Set current test options:
|
||||
for str in a:list
|
||||
let pair = split(str, ':')
|
||||
exec "let b:delimitMate_" . pair[0] . " = " . pair[1]
|
||||
endfor
|
||||
DelimitMateReload
|
||||
endfunction " }}}
|
||||
|
||||
function! Type(name, input, output, options) " {{{
|
||||
" Set default options:
|
||||
call SetOptions(a:options)
|
||||
normal ggVG"_d
|
||||
exec "normal i" . a:input . "|\<Esc>"
|
||||
call setpos('.', [0, 1, 1, 0])
|
||||
let result = len(a:output) != line('$')
|
||||
for line in a:output
|
||||
if getline('.') != line || result == 1
|
||||
let result = 1
|
||||
break
|
||||
endif
|
||||
call setpos('.', [0, line('.') + 1, 1, 0])
|
||||
endfor
|
||||
let text = getline('.')
|
||||
let i = 2
|
||||
while i <= line('$')
|
||||
let text = text . "<cr>" . getline(i)
|
||||
let i += 1
|
||||
endwhile
|
||||
if result == 0
|
||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Passed: ' . text . ' == ' . join(a:output, '<cr>')"
|
||||
else
|
||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Failed: ' . text . ' != ' . join(a:output, '<cr>')"
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
function! RepeatLast(name, output) " {{{
|
||||
normal gg.
|
||||
call setpos('.', [0, 1, 1, 0])
|
||||
let result = len(a:output) != line('$')
|
||||
for line in a:output
|
||||
if getline('.') != line || result == 1
|
||||
let result = 1
|
||||
break
|
||||
endif
|
||||
call setpos('.', [0, line('.') + 1, 1, 0])
|
||||
endfor
|
||||
let text = getline('1')
|
||||
let i = 2
|
||||
while i <= line('$')
|
||||
let text = text . "<cr>" . getline(i)
|
||||
let i += 1
|
||||
endwhile
|
||||
if result == 0
|
||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "_R'] = 'Passed: ' . text . ' == ' . join(a:output, '<cr>')"
|
||||
else
|
||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "_R'] = 'Failed: ' . text . ' != ' . join(a:output, '<cr>')"
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
" Test's test {{{
|
||||
call Type("Test 1", "123", ["123|"], [])
|
||||
call RepeatLast("Test 1", ["123|123|"])
|
||||
|
||||
" Auto-closing parens
|
||||
call Type("Autoclose parens", "(", ["(|)"], [])
|
||||
call RepeatLast("Autoclose_parens", ["(|)(|)"])
|
||||
|
||||
" Auto-closing quotes
|
||||
call Type("Autoclose quotes", '"', ['"|"'], [])
|
||||
call RepeatLast("Autoclose_quotes", ['"|""|"'])
|
||||
|
||||
" Deleting parens
|
||||
call Type("Delete empty parens", "(\<BS>", ["|"], [])
|
||||
call RepeatLast("Delete empty parens", ["||"])
|
||||
|
||||
" Deleting quotes
|
||||
call Type("Delete emtpy quotes", "\"\<BS>", ['|'], [])
|
||||
call RepeatLast("Delete empty quotes", ["||"])
|
||||
|
||||
" Manual closing parens
|
||||
call Type("Manual closing parens", "()", ["(|)"], ["autoclose:0"])
|
||||
call RepeatLast("Manual closing parens", ["(|)(|)"])
|
||||
|
||||
" Manual closing quotes
|
||||
call Type("Manual closing quotes", "\"\"", ['"|"'], ["autoclose:0"])
|
||||
call RepeatLast("Manual closing quotes", ['"|""|"'])
|
||||
|
||||
" Jump over paren
|
||||
call Type("Jump over paren", "()", ['()|'], [])
|
||||
call RepeatLast("Jump over paren", ['()|()|'])
|
||||
|
||||
" Jump over quote
|
||||
call Type("Jump over quote", "\"\"", ['""|'], [])
|
||||
call RepeatLast("Jump over quote", ['""|""|'])
|
||||
|
||||
" Apostrophe
|
||||
call Type("Apostrophe", "test'", ["test'|"], [])
|
||||
call RepeatLast("Apostrophe", ["test'|test'|"])
|
||||
|
||||
" Close quote
|
||||
call Type("Close quote", "'\<Del>\<Esc>a'", ["'|'"], [])
|
||||
|
||||
" Closing paren
|
||||
call Type("Closing paren", "abcd)", ["abcd)|"], [])
|
||||
|
||||
" <S-Tab>
|
||||
call Type("S Tab", "(\<S-Tab>", ["()|"], [])
|
||||
call RepeatLast("S Tab", ["()|()|"])
|
||||
|
||||
" Space expansion
|
||||
call Type("Space expansion", "(\<Space>\<BS>", ['(|)'], ['expand_space:1'])
|
||||
call RepeatLast("BS with space expansion", ['(|)(|)'])
|
||||
|
||||
" BS with space expansion
|
||||
call Type("BS with space expansion", "(\<Space>", ['( | )'], ['expand_space:1'])
|
||||
call RepeatLast("Space expansion", ['( | )( | )'])
|
||||
|
||||
" Car return expansion
|
||||
call Type("CR expansion", "(\<CR>", ['(', '|', ')'], ['expand_cr:1'])
|
||||
call RepeatLast("CR expansion", ['(', '|', ')(', '|', ')'])
|
||||
|
||||
" BS with car return expansion
|
||||
call Type("BS with CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
|
||||
call RepeatLast("BS with CR expansion", ['(|)(|)'])
|
||||
|
||||
" Visual wrapping
|
||||
call Type("Visual wrapping left paren", "1234\<Esc>v,(", ['123(4)'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual wrapping left paren", ['(1)23(4)'])
|
||||
|
||||
" Visual line wrapping
|
||||
call Type("Visual line wrapping left paren", "1234\<Esc>V,(", ['(1234)'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual line wrapping left paren", ['((1234))'])
|
||||
|
||||
" Visual wrapping
|
||||
call Type("Visual wrapping right paren", "1234\<Esc>v,)", ['123(4)'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual wrapping right paren", ['(1)23(4)'])
|
||||
|
||||
" Visual line wrapping
|
||||
call Type("Visual line wrapping right paren", "1234\<Esc>V,)", ['(1234)'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual line wrapping right paren", ['((1234))'])
|
||||
|
||||
" Visual wrapping
|
||||
call Type("Visual wrapping quote", "1234\<Esc>v,\"", ['123"4"'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual wrapping quote", ['"1"23"4"'])
|
||||
|
||||
" Visual line wrapping
|
||||
call Type("Visual line wrapping quote", "1234\<Esc>V,\"", ['"1234"'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual line wrapping quote", ['""1234""'])
|
||||
|
||||
" Visual line wrapping empty line
|
||||
call Type("Visual line wrapping paren empty line", "\<Esc>V,(", ['()'], ['visual_leader:","'])
|
||||
|
||||
" Visual line wrapping empty line
|
||||
call Type("Visual line wrapping quote empty line", "\<Esc>V,\"", ['""'], ['visual_leader:","'])
|
||||
|
||||
" Smart quotes
|
||||
call Type("Smart quote alphanumeric", "alpha\"numeric", ['alpha"numeric|'], [])
|
||||
call RepeatLast("Smart quote alphanumeric", ['alpha"numeric|alpha"numeric|'])
|
||||
|
||||
" Smart quotes
|
||||
call Type("Smart quote escaped", "esc\\\"", ['esc\"|'], [])
|
||||
call RepeatLast("Smart quote escaped", ['esc\"|esc\"|'])
|
||||
|
||||
" Smart quotes
|
||||
call Type("Smart quote apostrophe", "I'm", ["I'm|"], ['smart_quotes:0'])
|
||||
call RepeatLast("Smart quote escaped", ["I'm|I'm|"])
|
||||
|
||||
" Backspace inside space expansion
|
||||
call Type("Backspace inside space expansion", "(\<Space>\<BS>", ['(|)'], ['expand_space:1'])
|
||||
call RepeatLast("Backspace inside space expansion", ['(|)(|)'])
|
||||
|
||||
" Backspace inside CR expansion
|
||||
call Type("Backspace inside CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
|
||||
call RepeatLast("Backspace inside CR expansion", ['(|)(|)'])
|
||||
|
||||
" FileType event
|
||||
let g:delimitMate_excluded_ft = "vim"
|
||||
set ft=vim
|
||||
call Type("FileType Autoclose parens", "(", ["(|"], [])
|
||||
unlet g:delimitMate_excluded_ft
|
||||
set ft=
|
||||
|
||||
"}}}
|
||||
|
||||
" Show results: {{{
|
||||
normal ggVG"_d
|
||||
call append(0, split(string(b:test_results)[1:-2], ', '))
|
||||
normal "_ddgg
|
||||
let @/ = ".\\+Failed:.*!="
|
||||
set nohlsearch
|
||||
"syntax match failedLine "^.*Failed.*$" contains=ALL
|
||||
"syn match passedLine ".*Passed.*"
|
||||
syn match labelPassed "'\@<=.\+\(': 'Passed\)\@="
|
||||
syn match labelFailed "'\@<=.\+\(': 'Failed\)\@="
|
||||
syn match resultPassed "\('Passed: \)\@<=.\+\('$\)\@="
|
||||
syn match resultFailed "\('Failed: \)\@<=.\+\('$\)\@=" contains=resultInequal
|
||||
syn match resultInequal "!="
|
||||
|
||||
hi def link labelPassed Comment
|
||||
hi def link labelFailed Special
|
||||
hi def link resultPassed Ignore
|
||||
hi def link resultFailed Boolean
|
||||
hi def link resultInequal Error
|
||||
" }}}
|
||||
endfunction " }}}
|
||||
" vim:foldmethod=marker:foldcolumn=4
|
||||
@@ -1,4 +1,4 @@
|
||||
*delimitMate* Trying to keep those beasts at bay! v.2.0 *delimitMate.txt*
|
||||
*delimitMate* Trying to keep those beasts at bay! v.2.1 *delimitMate.txt*
|
||||
|
||||
========================================================================= ~
|
||||
==== ========= ========================== ===== ===================== ~
|
||||
@@ -37,23 +37,13 @@
|
||||
==============================================================================
|
||||
1.- INTRODUCTION *delimitMateIntro*
|
||||
|
||||
The delimitMate plugin tries to provide some not so dumb help in the work with
|
||||
delimiters (brackets, quotes, etc.), with some optional auto-completions and
|
||||
expansions.
|
||||
This plug-in provides automatic closing of quotes, parenthesis, brackets,
|
||||
etc., besides some other related features that should make your time in insert
|
||||
mode a little bit easier.
|
||||
|
||||
When automatic closing is enabled, if an opening delimiter is inserted
|
||||
delimitMate inserts the closing pair and places the cursor between them. When
|
||||
automatic closing is disabled, no closing delimiters is inserted by
|
||||
delimitMate, but if a pair of delimiters is typed, the cursor is placed in the
|
||||
middle. Also, to get out of a pair of delimiters just type shift+tab or the
|
||||
right delimiter and the cursor will jump to the right.
|
||||
|
||||
If the cursor is inside an empty pair of delimiters, typing <Space> will
|
||||
insert two spaces and the cursor will be placed in the middle; typing <CR>
|
||||
will insert to car retunrs and place the cursor in the middle line, between
|
||||
the delimiters.
|
||||
|
||||
All of the operations are undo/redo-wise safe.
|
||||
Most of the features can be modified or disabled permanently, using global
|
||||
variables, or on a FileType basis, using autocommands. With a couple of
|
||||
exceptions and limitations, this features don't brake undo, redo or history.
|
||||
|
||||
==============================================================================
|
||||
2. FUNCTIONALITY *delimitMateFunctionality*
|
||||
@@ -118,6 +108,8 @@ Expand <CR> to: >
|
||||
| )
|
||||
<
|
||||
|
||||
NOTE that the expansion of <CR> will brake the redo command.
|
||||
|
||||
Since <Space> and <CR> are used everywhere, I have made the functions involved
|
||||
in expansions global, so they can be used to make custom mappings. Read
|
||||
|delimitMateFunctions| for more details.
|
||||
@@ -125,8 +117,11 @@ in expansions global, so they can be used to make custom mappings. Read
|
||||
------------------------------------------------------------------------------
|
||||
2.3 BACKSPACE *delimitMateBackspace*
|
||||
|
||||
If you press backspace inside an empty pair, both delimiters are deleted. If
|
||||
you type shift + backspace instead, only the closing delimiter will be
|
||||
If you press backspace inside an empty pair, both delimiters are deleted. When
|
||||
expansions are enabled, <BS> will also delete the expansions. NOTE that
|
||||
deleting <CR> expansions will brake the redo command.
|
||||
|
||||
If you type shift + backspace instead, only the closing delimiter will be
|
||||
deleted.
|
||||
|
||||
e.g. typing at the "|": >
|
||||
@@ -134,7 +129,13 @@ e.g. typing at the "|": >
|
||||
What | Before | After
|
||||
==============================================
|
||||
<BS> | call expand(|) | call expand|
|
||||
---------|------------------|-----------------
|
||||
---------|-------------------|-----------------
|
||||
<BS> | call expand( | ) | call expand(|)
|
||||
---------|-------------------|-----------------
|
||||
<BS> | call expand( | call expand(|)
|
||||
| | |
|
||||
| ) |
|
||||
---------|-------------------|-----------------
|
||||
<S-BS> | call expand(|) | call expand(|
|
||||
<
|
||||
|
||||
@@ -144,8 +145,8 @@ e.g. typing at the "|": >
|
||||
When visual mode is active this script allows for the selection to be enclosed
|
||||
with delimiters. But, since brackets have special meaning in visual mode, a
|
||||
leader (the value of 'mapleader' by default) should precede the delimiter.
|
||||
This feature doesn't currently work on blockwise visual mode, any suggestions
|
||||
will be welcome.
|
||||
NOTE that this feature brakes the redo command and doesn't currently work on
|
||||
blockwise visual mode, any suggestions will be welcome.
|
||||
|
||||
e.g. (selection represented between square brackets): >
|
||||
|
||||
@@ -487,7 +488,12 @@ This script was inspired by the auto-completion of delimiters of TextMate.
|
||||
|
||||
Version Date Release notes ~
|
||||
|---------|------------|-----------------------------------------------------|
|
||||
2.0 2010-04-01 * New features:
|
||||
2.1 2010-05-10 - Most of the functions have been moved to an
|
||||
autoload script to avoid loading unnecessary ones.
|
||||
- Fixed a problem with the redo command.
|
||||
- Many small fixes.
|
||||
|---------|------------|-----------------------------------------------------|
|
||||
2.0 2010-04-01 New features:
|
||||
- All features are redo/undo-wise safe.
|
||||
- A single quote typed after an alphanumeric
|
||||
character is considered an apostrophe and one
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
" ============================================================================
|
||||
" File: delimitMate.vim
|
||||
" Version: 2.0
|
||||
" Description: This plugin tries to emulate the auto-completion of delimiters
|
||||
" that TextMate provides.
|
||||
" File: plugin/delimitMate.vim
|
||||
" Version: 2.1
|
||||
" Description: This plugin provides auto-completion for quotes, parens, etc.
|
||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||
" 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: {{{
|
||||
if exists("g:loaded_delimitMate") "{{{
|
||||
@@ -38,8 +25,11 @@ if v:version < 700
|
||||
endif
|
||||
|
||||
let s:loaded_delimitMate = 1 " }}}
|
||||
let delimitMate_version = '2.0'
|
||||
let delimitMate_version = '2.1'
|
||||
|
||||
"}}}
|
||||
|
||||
" Tools: {{{
|
||||
function! s:Init() "{{{
|
||||
|
||||
let b:loaded_delimitMate = 1
|
||||
@@ -55,59 +45,34 @@ function! s:Init() "{{{
|
||||
|
||||
" delimitMate_matchpairs {{{
|
||||
if !exists("b:delimitMate_matchpairs") && !exists("g:delimitMate_matchpairs")
|
||||
if s:ValidMatchpairs(&matchpairs) == 1
|
||||
let s:matchpairs_temp = &matchpairs
|
||||
else
|
||||
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
||||
finish
|
||||
endif
|
||||
elseif exists("b:delimitMate_matchpairs")
|
||||
if s:ValidMatchpairs(b:delimitMate_matchpairs) || b:delimitMate_matchpairs == ""
|
||||
let s:matchpairs_temp = b:delimitMate_matchpairs
|
||||
else
|
||||
echoerr "delimitMate: Invalid format in 'b:delimitMate_matchpairs', falling back to matchpairs. Fix the error and use the command :DelimitMateReload to try again."
|
||||
if s:ValidMatchpairs(&matchpairs) == 1
|
||||
let s:matchpairs_temp = &matchpairs
|
||||
else
|
||||
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
||||
let s:matchpairs_temp = ""
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if s:ValidMatchpairs(g:delimitMate_matchpairs) || g:delimitMate_matchpairs == ""
|
||||
let s:matchpairs_temp = g:delimitMate_matchpairs
|
||||
else
|
||||
echoerr "delimitMate: Invalid format in 'g:delimitMate_matchpairs', falling back to matchpairs. Fix the error and use the command :DelimitMateReload to try again."
|
||||
if s:ValidMatchpairs(&matchpairs) == 1
|
||||
let s:matchpairs_temp = &matchpairs
|
||||
else
|
||||
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
||||
let s:matchpairs_temp = ""
|
||||
endif
|
||||
endif
|
||||
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_quotes {{{
|
||||
if exists("b:delimitMate_quotes")
|
||||
if b:delimitMate_quotes =~ '^\(\S\)\(\s\S\)*$' || b:delimitMate_quotes == ""
|
||||
let s:quotes = split(b:delimitMate_quotes)
|
||||
else
|
||||
let s:quotes = split("\" ' `")
|
||||
echoerr "delimitMate: There is a problem with the format of 'b:delimitMate_quotes', it should be a string of single characters separated by spaces. Falling back to default values."
|
||||
endif
|
||||
elseif exists("g:delimitMate_quotes")
|
||||
if g:delimitMate_quotes =~ '^\(\S\)\(\s\S\)*$' || g:delimitMate_quotes == ""
|
||||
let s:quotes = split(g:delimitMate_quotes)
|
||||
else
|
||||
let s:quotes = split("\" ' `")
|
||||
echoerr "delimitMate: There is a problem with the format of 'g:delimitMate_quotes', it should be a string of single characters separated by spaces. Falling back to default values."
|
||||
endif
|
||||
else
|
||||
let s:quotes = split("\" ' `")
|
||||
endif
|
||||
let b:delimitMate_quotes_list = s:quotes " }}}
|
||||
|
||||
" delimitMate_excluded_regions {{{
|
||||
if exists("b:delimitMate_excluded_regions")
|
||||
let s:excluded_regions = b:delimitMate_excluded_regions
|
||||
elseif exists("g:delimitMate_excluded_regions")
|
||||
let s:excluded_regions = g:delimitMate_excluded_regions
|
||||
else
|
||||
let s:excluded_regions = "Comment"
|
||||
endif
|
||||
let b:delimitMate_excluded_regions_list = split(s:excluded_regions, ',\s*')
|
||||
let b:delimitMate_excluded_regions_enabled = len(b:delimitMate_excluded_regions_list) " }}}
|
||||
|
||||
" delimitMate_visual_leader {{{
|
||||
if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader")
|
||||
let b:delimitMate_visual_leader = exists('b:maplocalleader') ? b:maplocalleader :
|
||||
@@ -121,7 +86,7 @@ function! s:Init() "{{{
|
||||
" delimitMate_expand_space {{{
|
||||
if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space")
|
||||
let b:delimitMate_expand_space = 0
|
||||
elseif !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space")
|
||||
elseif !exists("b:delimitMate_expand_space") && exists("g:delimitMate_expand_space")
|
||||
let b:delimitMate_expand_space = g:delimitMate_expand_space
|
||||
else
|
||||
" Nothing to do.
|
||||
@@ -168,423 +133,41 @@ function! s:Init() "{{{
|
||||
let b:delimitMate_matchpairs_list = split(s:matchpairs_temp, ',')
|
||||
let b:delimitMate_left_delims = split(s:matchpairs_temp, ':.,\=')
|
||||
let b:delimitMate_right_delims = split(s:matchpairs_temp, ',\=.:')
|
||||
let s:VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
|
||||
|
||||
call s:UnMap()
|
||||
let b:delimitMate_buffer = []
|
||||
|
||||
call delimitMate#UnMap()
|
||||
if b:delimitMate_autoclose
|
||||
call s:AutoClose()
|
||||
call delimitMate#AutoClose()
|
||||
else
|
||||
call s:NoAutoClose()
|
||||
call delimitMate#NoAutoClose()
|
||||
endif
|
||||
call s:VisualMaps()
|
||||
call s:ExtraMappings()
|
||||
call delimitMate#VisualMaps()
|
||||
call delimitMate#ExtraMappings()
|
||||
|
||||
endfunction "}}} Init()
|
||||
"}}}
|
||||
|
||||
" Utilities: {{{
|
||||
function! s:ValidMatchpairs(str) "{{{
|
||||
if a:str !~ '^.:.\(,.:.\)*$'
|
||||
return 0
|
||||
endif
|
||||
for pair in split(a:str,',')
|
||||
if strpart(pair, 0, 1) == strpart(pair, 2, 1) || strlen(pair) != 3
|
||||
return 0
|
||||
endif
|
||||
endfor
|
||||
return 1
|
||||
endfunction "}}}
|
||||
|
||||
function! DelimitMate_ShouldJump() "{{{
|
||||
let char = getline('.')[col('.') - 1]
|
||||
for pair in b:delimitMate_matchpairs_list
|
||||
if char == split( pair, ':' )[1]
|
||||
" Same character on the rigth, jump over it.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
for quote in b:delimitMate_quotes_list
|
||||
if char == quote
|
||||
" Same character on the rigth, jump over it.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! s:IsBlockVisual() " {{{
|
||||
if visualmode() == "<C-V>"
|
||||
return 1
|
||||
endif
|
||||
" Store unnamed register values for later use in s:RestoreRegister().
|
||||
let s:save_reg = getreg('"')
|
||||
let s:save_reg_mode = getregtype('"')
|
||||
|
||||
if len(getline('.')) == 0
|
||||
" This for proper wrap of empty lines.
|
||||
let @" = "\n"
|
||||
endif
|
||||
return 0
|
||||
endfunction " }}}
|
||||
|
||||
function! s:IsEmptyPair(str) "{{{
|
||||
for pair in b:delimitMate_matchpairs_list
|
||||
if a:str == join( split( pair, ':' ),'' )
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
for quote in b:delimitMate_quotes_list
|
||||
if a:str == quote . quote
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! DelimitMate_WithinEmptyPair() "{{{
|
||||
let cur = strpart( getline('.'), col('.')-2, 2 )
|
||||
return s:IsEmptyPair( cur )
|
||||
endfunction "}}}
|
||||
|
||||
function! s:WriteBefore(str) "{{{
|
||||
let len = len(a:str)
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if col < 0
|
||||
call setline('.',line[(col+len+1):])
|
||||
else
|
||||
call setline('.',line[:(col)].line[(col+len+1):])
|
||||
endif
|
||||
return a:str
|
||||
endfunction " }}}
|
||||
|
||||
function! s:WriteAfter(str) "{{{
|
||||
let len = len(a:str)
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
call setline('.',a:str.line)
|
||||
else
|
||||
call setline('.',line[:(col)].a:str.line[(col+len):])
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! s:RestoreRegister() " {{{
|
||||
" Restore unnamed register values store in s:IsBlockVisual().
|
||||
call setreg('"', s:save_reg, s:save_reg_mode)
|
||||
echo ""
|
||||
endfunction " }}}
|
||||
" }}}
|
||||
|
||||
" Doers: {{{
|
||||
function! s:JumpIn(char) " {{{
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
call setline('.',a:char.line)
|
||||
else
|
||||
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
||||
call setline('.',line[:(col)].a:char.line[(col+1):])
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! s:JumpOut(char) "{{{
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if line[col+1] == a:char
|
||||
call setline('.',line[:(col)].line[(col+2):])
|
||||
endif
|
||||
return a:char
|
||||
endfunction " }}}
|
||||
|
||||
function! DelimitMate_JumpAny() " {{{
|
||||
let nchar = getline('.')[col('.')-1]
|
||||
return nchar . "\<Del>"
|
||||
endfunction " DelimitMate_JumpAny() }}}
|
||||
|
||||
function! s:SkipDelim(char) "{{{
|
||||
let cur = strpart( getline('.'), col('.')-2, 3 )
|
||||
if cur[0] == "\\"
|
||||
" Escaped character
|
||||
return a:char
|
||||
elseif cur[1] == a:char
|
||||
" Exit pair
|
||||
return s:WriteBefore(a:char)
|
||||
"elseif cur[1] == ' ' && cur[2] == a:char
|
||||
"" I'm leaving this in case someone likes it. Jump an space and delimiter.
|
||||
"return "\<Right>\<Right>"
|
||||
elseif s:IsEmptyPair( cur[0] . a:char )
|
||||
" Add closing delimiter and jump back to the middle.
|
||||
return s:WriteAfter(a:char)
|
||||
else
|
||||
" Nothing special here, return the same character.
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:QuoteDelim(char) "{{{
|
||||
let line = getline('.')
|
||||
let col = col('.') - 2
|
||||
if line[col] == "\\"
|
||||
" Seems like a escaped character, insert one quotation mark.
|
||||
return a:char
|
||||
elseif line[col + 1] == a:char
|
||||
" Get out of the string.
|
||||
return s:WriteBefore(a:char)
|
||||
elseif (line[col] =~ '[a-zA-Z0-9]' && a:char == "'") ||
|
||||
\(line[col] =~ '[a-zA-Z0-9]' && b:delimitMate_smart_quotes)
|
||||
" Seems like an apostrophe or a closing, insert a single quote.
|
||||
return a:char
|
||||
elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:delimitMate_smart_quotes
|
||||
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
|
||||
return s:WriteAfter(a:char)
|
||||
else
|
||||
" Insert a pair and jump to the middle.
|
||||
call s:WriteAfter(a:char)
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:MapMsg(msg) "{{{
|
||||
redraw
|
||||
echomsg a:msg
|
||||
return ""
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Mappings: {{{
|
||||
function! s:NoAutoClose() "{{{
|
||||
" inoremap <buffer> ) <C-R>=<SID>SkipDelim('\)')<CR>
|
||||
for delim in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>SkipDelim("' . escape(delim,'"') . '")<CR>'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! s:AutoClose() "{{{
|
||||
" Add matching pair and jump to the midle:
|
||||
" inoremap <buffer> ( ()<Left>
|
||||
let i = 0
|
||||
while i < len(b:delimitMate_matchpairs_list)
|
||||
let ld = b:delimitMate_left_delims[i]
|
||||
let rd = b:delimitMate_right_delims[i]
|
||||
exec 'inoremap <buffer> ' . ld . ' ' . ld . '<C-R>=<SID>JumpIn("' . rd . '")<CR>'
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
||||
" inoremap <buffer> " <C-R>=<SID>QuoteDelim("\"")<CR>
|
||||
for delim in b:delimitMate_quotes_list
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>QuoteDelim("\' . delim . '")<CR>'
|
||||
endfor
|
||||
|
||||
" Exit from inside the matching pair:
|
||||
for delim in b:delimitMate_right_delims
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>JumpOut("\' . delim . '")<CR>'
|
||||
endfor
|
||||
|
||||
" Try to fix the use of apostrophes (de-activated by default):
|
||||
" inoremap <buffer> n't n't
|
||||
for map in b:delimitMate_apostrophes_list
|
||||
exec "inoremap <buffer> " . map . " " . map
|
||||
endfor
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! s:VisualMaps() " {{{
|
||||
let vleader = b:delimitMate_visual_leader
|
||||
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
|
||||
let i = 0
|
||||
while i < len(b:delimitMate_matchpairs_list)
|
||||
" Map left delimiter:
|
||||
let ld = b:delimitMate_left_delims[i]
|
||||
let rd = b:delimitMate_right_delims[i]
|
||||
exec 'vnoremap <buffer> <expr> ' . vleader . ld . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . ld . '\<C-R>\"' . rd . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||
|
||||
" Map right delimiter:
|
||||
exec 'vnoremap <buffer> <expr> ' . vleader . rd . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . ld . '\<C-R>\"' . rd . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
" Wrap the selection with matching quotes, but do nothing if blockwise visual mode is active:
|
||||
for quote in b:delimitMate_quotes_list
|
||||
" vnoremap <buffer> <expr> \' <SID>IsBlockVisual() ? <SID>MapMsg("Message") : "s'\<C-R>\"'\<Esc>:call <SID>RestoreRegister()<CR>"
|
||||
exec 'vnoremap <buffer> <expr> ' . vleader . quote . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') .'\<C-R>\"' . escape(quote,'"') . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! DelimitMate_ExpandReturn() "{{{
|
||||
" Expand:
|
||||
return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
|
||||
endfunction "}}}
|
||||
|
||||
function! DelimitMate_ExpandSpace() "{{{
|
||||
" Expand:
|
||||
return s:WriteAfter(' ') . "\<Space>"
|
||||
endfunction "}}}
|
||||
|
||||
function! s:ExtraMappings() "{{{
|
||||
" If pair is empty, delete both delimiters:
|
||||
inoremap <buffer> <expr> <BS> DelimitMate_WithinEmptyPair() ? "\<Right>\<BS>\<BS>" : "\<BS>"
|
||||
|
||||
" If pair is empty, delete closing delimiter:
|
||||
inoremap <buffer> <expr> <S-BS> DelimitMate_WithinEmptyPair() ? "\<Del>" : "\<S-BS>"
|
||||
|
||||
" Expand return if inside an empty pair:
|
||||
if b:delimitMate_expand_cr != 0
|
||||
inoremap <buffer> <expr> <CR> DelimitMate_WithinEmptyPair() ?
|
||||
\ DelimitMate_ExpandReturn() : "\<CR>"
|
||||
endif
|
||||
|
||||
" Expand space if inside an empty pair:
|
||||
if b:delimitMate_expand_space != 0
|
||||
inoremap <buffer> <expr> <Space> DelimitMate_WithinEmptyPair() ?
|
||||
\ DelimitMate_ExpandSpace() : "\<Space>"
|
||||
endif
|
||||
|
||||
" Jump out ot any empty pair:
|
||||
if b:delimitMate_tab2exit
|
||||
inoremap <buffer> <expr> <S-Tab> DelimitMate_ShouldJump() ? DelimitMate_JumpAny() : "\<S-Tab>"
|
||||
endif
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Tools: {{{
|
||||
function! s:TestMappings() "{{{
|
||||
if b:delimitMate_autoclose
|
||||
exec "normal i* AUTOCLOSE:\<CR>"
|
||||
for i in range(len(b:delimitMate_left_delims))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i]. "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . " |"
|
||||
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
|
||||
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
for i in range(len(b:delimitMate_quotes_list))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Delete: "
|
||||
exec "normal A". b:delimitMate_quotes_list[i]
|
||||
exec "normal a\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . " |"
|
||||
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
else
|
||||
exec "normal i* NO AUTOCLOSE:\<CR>"
|
||||
for i in range(len(b:delimitMate_left_delims))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . " |"
|
||||
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
|
||||
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
for i in range(len(b:delimitMate_quotes_list))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . " |"
|
||||
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
endif
|
||||
exec "normal \<Esc>i"
|
||||
endfunction "}}}
|
||||
|
||||
function! s:SwitchAutoclose() "{{{
|
||||
if !exists("g:delimitMate_autoclose")
|
||||
let g:delimitMate_autoclose = 1
|
||||
elseif g:delimitMate_autoclose == 1
|
||||
let g:delimitMate_autoclose = 0
|
||||
else
|
||||
let g:delimitMate_autoclose = 1
|
||||
endif
|
||||
DelimitMateReload
|
||||
endfunction "}}}
|
||||
|
||||
function! s:UnMap() " {{{
|
||||
" No Autoclose Mappings:
|
||||
for char in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
if maparg(char,"i") =~? 'SkipDelim'
|
||||
exec 'silent! iunmap <buffer> ' . char
|
||||
"echomsg 'iunmap <buffer> ' . char
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Autoclose Mappings:
|
||||
let i = 0
|
||||
let l = len(b:delimitMate_matchpairs_list)
|
||||
while i < l
|
||||
if maparg(b:delimitMate_left_delims[i],"i") =~? 'JumpIn'
|
||||
exec 'silent! iunmap <buffer> ' . b:delimitMate_left_delims[i]
|
||||
"echomsg 'iunmap <buffer> ' . b:delimitMate_left_delims[i]
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
for char in b:delimitMate_quotes_list
|
||||
if maparg(char, "i") =~? 'QuoteDelim'
|
||||
exec 'silent! iunmap <buffer> ' . char
|
||||
"echomsg 'iunmap <buffer> ' . char
|
||||
endif
|
||||
endfor
|
||||
for char in b:delimitMate_right_delims
|
||||
if maparg(char, "i") =~? 'JumpOut'
|
||||
exec 'silent! iunmap <buffer> ' . char
|
||||
"echomsg 'iunmap <buffer> ' . char
|
||||
endif
|
||||
endfor
|
||||
for map in b:delimitMate_apostrophes_list
|
||||
exec "silent! iunmap <buffer> " . map
|
||||
endfor
|
||||
|
||||
" Visual Mappings:
|
||||
for char in b:delimitMate_right_delims + b:delimitMate_left_delims + b:delimitMate_quotes_list
|
||||
if maparg(b:delimitMate_visual_leader . char,"v") =~? 'IsBlock'
|
||||
exec 'silent! vunmap <buffer> ' . b:delimitMate_visual_leader . char
|
||||
"echomsg 'vunmap <buffer> ' . b:delimitMate_visual_leader . char
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Expansion Mappings:
|
||||
if maparg('<BS>', "i") =~? 'WithinEmptyPair'
|
||||
silent! iunmap <buffer> <BS>
|
||||
"echomsg "silent! iunmap <buffer> <BS>"
|
||||
endif
|
||||
if maparg('<S-BS>', "i") =~? 'WithinEmptyPair'
|
||||
silent! iunmap <buffer> <BS>
|
||||
"echomsg "silent! iunmap <buffer> <BS>"
|
||||
endif
|
||||
if maparg('<CR>',"i") =~? 'DelimitMate_ExpandReturn'
|
||||
silent! iunmap <buffer> <CR>
|
||||
"echomsg "silent! iunmap <buffer> <CR>"
|
||||
endif
|
||||
if maparg('<Space>',"i") =~? 'DelimitMate_ExpandSpace'
|
||||
silent! iunmap <buffer> <Space>
|
||||
"echomsg "silent! iunmap <buffer> <Space>"
|
||||
endif
|
||||
if maparg('<S-Tab>', "i") =~? 'ShouldJump'
|
||||
silent! iunmap <buffer> <S-Tab>
|
||||
"echomsg "silent! iunmap <buffer> <S-Tab>"
|
||||
endif
|
||||
endfunction " }}} s:ExtraMappings()
|
||||
|
||||
function! s:TestMappingsDo() "{{{
|
||||
"DelimitMateReload
|
||||
if !exists("g:delimitMate_testing")
|
||||
"call s:DelimitMateDo()
|
||||
call s:TestMappings()
|
||||
silent call delimitMate#TestMappings()
|
||||
else
|
||||
call s:SwitchAutoclose()
|
||||
call s:TestMappings()
|
||||
let temp_varsDM = [b:delimitMate_expand_space, b:delimitMate_expand_cr, b:delimitMate_autoclose]
|
||||
for i in [0,1]
|
||||
let b:delimitMate_expand_space = i
|
||||
let b:delimitMate_expand_cr = i
|
||||
for a in [0,1]
|
||||
let b:delimitMate_autoclose = a
|
||||
call s:Init()
|
||||
call delimitMate#TestMappings()
|
||||
exec "normal i\<CR>"
|
||||
call s:SwitchAutoclose()
|
||||
call s:TestMappings()
|
||||
endfor
|
||||
endfor
|
||||
let b:delimitMate_expand_space = temp_varsDM[0]
|
||||
let b:delimitMate_expand_cr = temp_varsDM[1]
|
||||
let b:delimitMate_autoclose = temp_varsDM[2]
|
||||
unlet temp_varsDM
|
||||
endif
|
||||
normal gg
|
||||
endfunction "}}}
|
||||
|
||||
function! s:DelimitMateDo() "{{{
|
||||
@@ -592,11 +175,8 @@ function! s:DelimitMateDo() "{{{
|
||||
" Check if this file type is excluded:
|
||||
for ft in split(g:delimitMate_excluded_ft,',')
|
||||
if ft ==? &filetype
|
||||
if !exists("b:delimitMate_quotes_list")
|
||||
return 1
|
||||
endif
|
||||
"echomsg "excluded"
|
||||
call s:UnMap()
|
||||
call delimitMate#UnMap()
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
@@ -604,10 +184,13 @@ function! s:DelimitMateDo() "{{{
|
||||
try
|
||||
"echomsg "included"
|
||||
let save_cpo = &cpo
|
||||
let save_keymap = &keymap
|
||||
set keymap=
|
||||
set cpo&vim
|
||||
call s:Init()
|
||||
finally
|
||||
let &cpo = save_cpo
|
||||
let &keymap = save_keymap
|
||||
endtry
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
@@ -621,6 +204,9 @@ command! DelimitMateReload call s:DelimitMateDo()
|
||||
" Quick test:
|
||||
command! DelimitMateTest call s:TestMappingsDo()
|
||||
|
||||
"command! DelimitMateRegions echo s:excluded_regions
|
||||
" Turn
|
||||
|
||||
" Run on file type events.
|
||||
"autocmd VimEnter * autocmd FileType * call <SID>DelimitMateDo()
|
||||
autocmd FileType * call <SID>DelimitMateDo()
|
||||
@@ -628,7 +214,12 @@ autocmd FileType * call <SID>DelimitMateDo()
|
||||
" Run on new buffers.
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user