diff --git a/plugin/autoclose.vim b/plugin/autoclose.vim index 6b2366b..8b0d729 100644 --- a/plugin/autoclose.vim +++ b/plugin/autoclose.vim @@ -63,7 +63,7 @@ nmap ToggleAutoCloseMappings :call ToggleAutoCloseMappings() if (!hasmapto( 'ToggleAutoCloseMappings', 'n' )) nmap a ToggleAutoCloseMappings endif -fun ToggleAutoCloseMappings() " --- {{{2 +fun! ToggleAutoCloseMappings() " --- {{{2 if g:autoclose_on iunmap " iunmap ' @@ -75,28 +75,36 @@ fun ToggleAutoCloseMappings() " --- {{{2 iunmap } iunmap iunmap + iunmap iunmap + iunmap ` + iunmap < + iunmap > let g:autoclose_on = 0 echo "AutoClose Off" else inoremap " =QuoteDelim('"') + inoremap ` =QuoteDelim('`') inoremap ' =match(getline('.')[col('.') - 2],'\w') == 0 && getline('.')[col('.')-1] != "'" ? "'" : QuoteDelim("'") inoremap ( (=CloseStackPush(')') inoremap ) =CloseStackPop(')') inoremap [ [=CloseStackPush(']') inoremap ] =CloseStackPop(']') + inoremap < <=CloseStackPush('>') + inoremap > =CloseStackPop('>') "inoremap { {=CloseStackPush('}') inoremap { =OpenSpecial('{','}') inoremap } =CloseStackPop('}') - inoremap =OpenCloseBackspace() - inoremap =OpenCloseBackspace() + inoremap =OpenCloseBackspaceOrDel("BS") + inoremap =OpenCloseBackspaceOrDel("BS") + inoremap =OpenCloseBackspaceOrDel("Del") inoremap =CloseStackPop('') inoremap =CloseStackPop('') "the following simply creates an ambiguous mapping so vim fully "processes the escape sequence for terminal keys, see 'ttimeout' for a "rough explanation, this just forces it to work - if &term[:4] == "xterm" - inoremap OC + if &term[:4] == "xterm" || &term[:5] == 'screen' + inoremap OC endif let g:autoclose_on = 1 if a:0 == 0 @@ -108,7 +116,7 @@ endf let s:closeStack = [] " AutoClose Utilities -----------------------------------------{{{1 -function OpenSpecial(ochar,cchar) " ---{{{2 +function! OpenSpecial(ochar,cchar) " ---{{{2 let line = getline('.') let col = col('.') - 2 "echom string(col).':'.line[:(col)].'|'.line[(col+1):] @@ -122,7 +130,7 @@ function OpenSpecial(ochar,cchar) " ---{{{2 return a:ochar.CloseStackPush(a:cchar) endfunction -function CloseStackPush(char) " ---{{{2 +function! CloseStackPush(char) " ---{{{2 "echom "push" let line = getline('.') let col = col('.')-2 @@ -137,7 +145,7 @@ function CloseStackPush(char) " ---{{{2 return '' endf -function JumpOut(char) " ----------{{{2 +function! JumpOut(char) " ----------{{{2 let column = col('.') - 1 let line = getline('.') let mcol = match(line[column :], a:char) @@ -156,7 +164,7 @@ function JumpOut(char) " ----------{{{2 return a:char endif endf -function CloseStackPop(char) " ---{{{2 +function! CloseStackPop(char) " ---{{{2 "echom "pop" if(a:char == '') pclose @@ -186,7 +194,8 @@ function CloseStackPop(char) " ---{{{2 return popped endf -function QuoteDelim(char) " ---{{{2 +function! QuoteDelim(char) " ---{{{2 + " TODO: handle &commentstring at the beginning of a line (e.g. VIM mode) let line = getline('.') let col = col('.') if line[col - 2] == "\\" @@ -203,11 +212,11 @@ endf " The strings returned from QuoteDelim aren't in scope for , so I " have to fake it using this function (from the Vim help, but tweaked) -function s:SID() +function! s:SID() return matchstr(expand(''), '\d\+_\zeSID$') endfun -function OpenCloseBackspace() " ---{{{2 +function! OpenCloseBackspaceOrDel(map) " ---{{{2 "if pumvisible() " pclose " call StopOmni() @@ -215,20 +224,31 @@ function OpenCloseBackspace() " ---{{{2 "else let curline = getline('.') let curpos = col('.') + if a:map == 'Del' + let curpos -= 1 + end let curletter = curline[curpos-1] let prevletter = curline[curpos-2] if (prevletter == '"' && curletter == '"') || \ (prevletter == "'" && curletter == "'") || \ (prevletter == "(" && curletter == ")") || \ (prevletter == "{" && curletter == "}") || -\ (prevletter == "[" && curletter == "]") +\ (prevletter == "[" && curletter == "]") || +\ (prevletter == "`" && curletter == "`") || +\ (prevletter == "<" && curletter == ">") + if a:map == 'Del' + call insert(s:closeStack, curletter) + return "\" + end + " undo insert if len(s:closeStack) > 0 call remove(s:closeStack,0) endif - return "\\" - else - return "\" + return "\\" endif + + " return key as is (Del or BS) + if a:map == 'Del' | return "\" | else | return "\" | endif "endif endf