From a3759e52632618635992ba2ccdabac6c1e210ddb Mon Sep 17 00:00:00 2001 From: Thiago Alves Date: Fri, 5 Sep 2008 21:44:37 -0300 Subject: [PATCH] Fix a problem when use AutoClose on Visual Mode Blockwise. Unfortunatelly Backspace will not work as expected on this mode due Vim behavior. E.g.: Select a column of text and press than keys. You'll see that only the first line will be changed. --- plugin/autoclose.vim | 51 +++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/plugin/autoclose.vim b/plugin/autoclose.vim index 07dfd99..72b4019 100644 --- a/plugin/autoclose.vim +++ b/plugin/autoclose.vim @@ -1,11 +1,11 @@ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " AutoClose.vim - Automatically close pair of characters: ( with ), [ with ], { with }, etc. -" Version: 1.3 +" Version: 1.4 " Author: Thiago Alves " Maintainer: Thiago Alves " URL: http://thiagoalves.org " Licence: This script is released under the Vim License. -" Last modified: 08/26/2008 +" Last modified: 09/05/2008 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let s:debug = 0 @@ -69,20 +69,30 @@ function! s:IsForbidden(char) endfunction function! s:InsertPair(char) + let l:save_ve = &ve + set ve=all + let l:next = s:GetNextChar() let l:result = a:char if s:running && !s:IsForbidden(a:char) && (l:next == "\0" || l:next !~ '\w') let l:result .= s:charsToClose[a:char] . "\" endif + + exec "set ve=" . l:save_ve return l:result endfunction function! s:ClosePair(char) + let l:save_ve = &ve + set ve=all + if s:running && s:GetNextChar() == a:char let l:result = "\" else let l:result = a:char endif + + exec "set ve=" . l:save_ve return l:result endfunction @@ -110,10 +120,16 @@ function! s:CheckPair(char) endfunction function! s:Backspace() + let l:save_ve = &ve + set ve=all + + let l:result = "\" if s:running && s:IsEmptyPair() - return "\\" + let l:result .= "\" endif - return "\" + + exec "set ve=" . l:save_ve + return l:result endfunction function! s:ToggleAutoClose() @@ -128,10 +144,6 @@ endfunction """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Configuration """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" variables that represents the turn on and turn off of virtualedition -let s:turn_ve_on= ":let save_ve = &ve:set ve=all" -let s:turn_ve_off = ":let &ve = save_ve" - " let user define which character he/she wants to autocomplete if exists("g:AutoClosePairs") && type(g:AutoClosePairs) == type({}) let s:charsToClose = g:AutoClosePairs @@ -158,31 +170,16 @@ endif " create appropriate maps to defined open/close characters for key in keys(s:charsToClose) - if key == '"' - let open_func_arg = '"\""' - let close_func_arg = '"\""' - else - let open_func_arg = '"' . key . '"' - let close_func_arg = '"' . s:charsToClose[key] . '"' - endif if key == s:charsToClose[key] - exec "inoremap " . key . " " . s:turn_ve_on . "=CheckPair(" . open_func_arg . ")" . s:turn_ve_off + exec "inoremap " . key . " =CheckPair(\"" . (key == '"' ? '\"' : key) . "\")" else - exec "inoremap " . s:charsToClose[key] . " " . s:turn_ve_on . "=ClosePair(" . close_func_arg . ")" . s:turn_ve_off - exec "inoremap " . key . " " . s:turn_ve_on . "=InsertPair(" . open_func_arg . ")" . s:turn_ve_off + exec "inoremap " . key . " =InsertPair(\"" . key . "\")" + exec "inoremap " . s:charsToClose[key] . " =ClosePair(\"" . s:charsToClose[key] . "\")" endif endfor -exec "inoremap " . s:turn_ve_on . "=Backspace()" . s:turn_ve_off +exec "inoremap =Backspace()" " Define convenient commands command! AutoCloseOn :let s:running = 1 command! AutoCloseOff :let s:running = 0 command! AutoCloseToggle :call s:ToggleAutoClose() - -" return to the users own compatible-mode settings -let &cpo = s:global_cpo - -" Clean up -unlet s:global_cpo -unlet s:turn_ve_on -unlet s:turn_ve_off