diff --git a/autoload/delimitMate.vim b/autoload/delimitMate.vim index 944d593..3be827c 100644 --- a/autoload/delimitMate.vim +++ b/autoload/delimitMate.vim @@ -181,35 +181,6 @@ function! delimitMate#CursorIdx() "{{{ return idx endfunction "delimitMate#CursorCol }}} -function! delimitMate#WriteBefore(str) "{{{ - let len = len(a:str) - let line = getline('.') - let col = delimitMate#CursorIdx() - 1 - 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 = 1 "len(a:str) - let line = split(getline('.'), '\zs') - let col = delimitMate#CursorIdx() - 1 - if (col + 1) < 0 || col('.') == 1 - let line = insert(line, a:str) - elseif col('.') == col('$') - let line = add(line, a:str) - else - let line1 = line[:(col)] - let line2 = line[(col+len):] - let line = line1 + [a:str] + line2 - endif - call setline('.', join(line, '')) - return '' -endfunction " }}} - function! delimitMate#GetSyntaxRegion(line, col) "{{{ return synIDattr(synIDtrans(synID(a:line, a:col, 1)), 'name') endfunction " }}} @@ -247,18 +218,6 @@ function! delimitMate#IsForbidden(char) "{{{ return index(s:g('excluded_regions_list'), region) >= 0 endfunction "}}} -function! delimitMate#FlushBuffer() " {{{ - call s:s('buffer', []) - return '' -endfunction " }}} - -function! delimitMate#AddToBuffer(str, ...) "{{{ - if a:0 && a:1 == 1 - return add(s:g('buffer'), a:str) - endif - return insert(s:g('buffer'), a:str) -endfunction "delimitMate#AddToBuffer }}} - function! delimitMate#BalancedParens(char) "{{{ " Returns: " = 0 => Parens balanced. @@ -296,13 +255,6 @@ function! delimitMate#BalancedParens(char) "{{{ return opening - closing endfunction "}}} -function! delimitMate#RmBuffer(num) " {{{ - if len(s:g('buffer')) > 0 - call remove(s:g('buffer'), 0, (a:num-1)) - endif - return "" -endfunction " }}} - function! delimitMate#IsSmartQuote(char) "{{{ if !s:g('smart_quotes') return 0 @@ -341,12 +293,10 @@ function! delimitMate#SkipDelim(char) "{{{ return a:char elseif cur == a:char " Exit pair - "return delimitMate#WriteBefore(a:char) - return a:char . delimitMate#Del() + return a:char . "\" elseif delimitMate#IsEmptyPair( pre . a:char ) " Add closing delimiter and jump back to the middle. - call delimitMate#AddToBuffer(a:char) - return delimitMate#WriteAfter(a:char) + return a:char . "\" else " Nothing special here, return the same character. return a:char @@ -374,9 +324,7 @@ function! delimitMate#ParenDelim(right) " {{{ return left "elseif (col) < 0 " call setline('.',a:right.line) - " call delimitMate#AddToBuffer(a:right) endif - call delimitMate#AddToBuffer(a:right . tail) return left . a:right . tail . repeat("\", len(split(tail, '\zs')) + 1) endfunction " }}} @@ -389,7 +337,7 @@ function! delimitMate#QuoteDelim(char) "{{{ if char_at == a:char && \ index(s:g('nesting_quotes'), a:char) < 0 " Get out of the string. - return a:char . delimitMate#Del() + return "\" elseif delimitMate#IsSmartQuote(a:char) " Seems like a smart quote, insert a single char. return a:char @@ -397,8 +345,6 @@ function! delimitMate#QuoteDelim(char) "{{{ \ && s:g('smart_quotes') " Seems like we have an unbalanced quote, insert one quotation " mark and jump to the middle. - call delimitMate#AddToBuffer(a:char) - "return delimitMate#WriteAfter(a:char) return a:char . "\" else " Insert a pair and jump to the middle. @@ -409,8 +355,6 @@ function! delimitMate#QuoteDelim(char) "{{{ let has_marker = marker == s:g('eol_marker') let sufix = !has_marker ? s:g('eol_marker') : '' endif - call delimitMate#AddToBuffer(a:char . sufix) - "call delimitMate#WriteAfter(a:char . sufix) return a:char . a:char . "\" endif endfunction "}}} @@ -421,11 +365,10 @@ function! delimitMate#JumpOut(char) "{{{ endif let jump = delimitMate#ShouldJump(a:char) if jump == 1 - return a:char . delimitMate#Del() + return "\" elseif jump == 3 - return ' '.a:char.delimitMate#Del().delimitMate#Del() + return "\\" elseif jump == 5 - call delimitMate#FlushBuffer() return "\\I\" else return a:char @@ -443,16 +386,12 @@ function! delimitMate#JumpAny(...) " {{{ let char = delimitMate#GetCharFromCursor(0) if char == " " " Space expansion. - return char . getline('.')[col('.')] . delimitMate#Del() . - \ delimitMate#Del() - "call delimitMate#RmBuffer(1) + return "\\" elseif char == "" " CR expansion. - call delimitMate#FlushBuffer() - return "\" . getline(line('.') + 1)[0] . delimitMate#Del() . "\" + return "\" . getline(line('.') + 1)[0] . "\\" else - "call delimitMate#RmBuffer(1) - return char . delimitMate#Del() + return "\" endif endfunction " delimitMate#JumpAny() }}} @@ -484,8 +423,6 @@ function! delimitMate#ExpandReturn() "{{{ endif if delimitMate#WithinEmptyPair() " Expand: - call delimitMate#FlushBuffer() - " Not sure why I used the previous combos, but I'm sure somebody will " tell me about it. " XXX zv prevents breaking expansion with syntax folding enabled by @@ -504,76 +441,30 @@ function! delimitMate#ExpandSpace() "{{{ \ && delimitMate#GetCharFromCursor(-2) == '\' if delimitMate#WithinEmptyPair() && !escaped " Expand: - call delimitMate#AddToBuffer('s') - return delimitMate#WriteAfter(' ') . "\" + return "\\\" else return "\" endif endfunction "}}} function! delimitMate#BS() " {{{ - let buffer_tail = get(s:g('buffer'), '-1', '') if delimitMate#IsForbidden("") let extra = '' - elseif &backspace !~ 'start\|2' && empty(s:g('buffer')) + elseif &bs !~ 'start\|2' let extra = '' elseif delimitMate#WithinEmptyPair() - let extra = delimitMate#Del() + let extra = "\" elseif delimitMate#IsSpaceExpansion() - let extra = delimitMate#Del() + let extra = "\" elseif delimitMate#IsCRExpansion() let extra = repeat("\", \ len(matchstr(getline(line('.') + 1), '^\s*\S'))) else let extra = '' endif - let tail_re = '\m\C\%(' - \ . join(s:g('right_delims')+s:g('quotes_list'), '\|') - \ . '\)' - \ . escape(s:g('eol_marker'), '\*.^$') - \ . '$' - if buffer_tail =~ tail_re && search('\%#'.tail_re, 'cWn') - let extra .= join(map(split(s:g('eol_marker'), '\zs'), - \ 'delimitMate#Del()'), '') - endif return "\" . extra endfunction " }}} delimitMate#BS() -function! delimitMate#Del() " {{{ - if len(s:g('buffer')) > 0 - call delimitMate#RmBuffer(1) - return "\" - else - return "\" - endif -endfunction " }}} - -function! delimitMate#Finish(move_back) " {{{ - let len = len(s:g('buffer')) - if len > 0 - let buffer = join(s:g('buffer'), '') - let len2 = len(buffer) - " Reset buffer: - call s:s('buffer', []) - let line = getline('.') - let col = col('.') -2 - if col < 0 - call setline('.', line[col+len2+1:]) - else - call setline('.', line[:col] . line[col+len2+1:]) - endif - let i = 1 - let lefts = "" - while i <= len && a:move_back - let lefts = lefts . "\" - let i += 1 - endwhile - let result = substitute(buffer, "s", "\", 'g') . lefts - return result - endif - return '' -endfunction " }}} - " }}} " Tools: {{{ @@ -596,18 +487,7 @@ function! delimitMate#TestMappings() "{{{ let imaps += \ s:g('quotes_list') + \ s:g('apostrophes_list') + - \ ['', '', '', '', ''] + - \ ['', '', '', '', '', - \ ''] + - \ ['', '', '', '', '', - \ '', 'g'] + - \ ['', '', ''] + - \ ['', '', - \ ''] + - \ ['', '', - \ ''] + - \ ['', '', - \ ''] + \ ['', '', '', '', 'g'] let imaps += ( s:g('expand_cr') ? [''] : [] ) let imaps += ( s:g('expand_space') ? [''] : [] ) diff --git a/plugin/delimitMate.vim b/plugin/delimitMate.vim index 8605890..b1b8087 100644 --- a/plugin/delimitMate.vim +++ b/plugin/delimitMate.vim @@ -252,24 +252,6 @@ function! s:DelimitMateSwitch() "{{{ endif endfunction "}}} -function! s:Finish() " {{{ - if exists('b:delimitMate_enabled') - return delimitMate#Finish(1) - endif - return '' -endfunction " }}} - -function! s:FlushBuffer() " {{{ - if exists('b:delimitMate_enabled') - return delimitMate#FlushBuffer() - endif - return '' -endfunction " }}} - -function! s:empty_buffer() - return empty(s:g('buffer')) -endfunction - "}}} " Mappers: {{{ @@ -327,18 +309,18 @@ function! s:ExtraMappings() "{{{ silent! imap delimitMateBS endif " If pair is empty, delete closing delimiter: - inoremap delimitMateS-BS delimitMate#WithinEmptyPair() ? "\=delimitMate#Del()\" : "\" + inoremap delimitMateS-BS delimitMate#WithinEmptyPair() ? "\" : "\" if !hasmapto('delimitMateS-BS','i') && maparg('', 'i') == '' silent! imap delimitMateS-BS endif " Expand return if inside an empty pair: inoremap delimitMateCR =delimitMate#ExpandReturn() - if s:g('expand_cr') != 0 && !hasmapto('delimitMateCR', 'i') && maparg('', 'i') == '' + if s:g('expand_cr') && !hasmapto('delimitMateCR', 'i') && maparg('', 'i') == '' silent! imap delimitMateCR endif " Expand space if inside an empty pair: inoremap delimitMateSpace =delimitMate#ExpandSpace() - if s:g('expand_space') != 0 && !hasmapto('delimitMateSpace', 'i') && maparg('', 'i') == '' + if s:g('expand_space') && !hasmapto('delimitMateSpace', 'i') && maparg('', 'i') == '' silent! imap delimitMateSpace endif " Jump over any delimiter: @@ -346,49 +328,8 @@ function! s:ExtraMappings() "{{{ if s:g('tab2exit') && !hasmapto('delimitMateS-Tab', 'i') && maparg('', 'i') == '' silent! imap delimitMateS-Tab endif - " Change char buffer on Del: - inoremap delimitMateDel =delimitMate#Del() - if !hasmapto('delimitMateDel', 'i') && maparg('', 'i') == '' - silent! imap delimitMateDel - endif - let keys = ['Left', 'Right', 'Home', 'End', 'C-Left', 'C-Right', - \ 'ScrollWheelUp', 'S-ScrollWheelUp', 'C-ScrollWheelUp', - \ 'ScrollWheelDown', 'S-ScrollWheelDown', 'C-ScrollWheelDown', - \ 'ScrollWheelLeft', 'S-ScrollWheelLeft', 'C-ScrollWheelLeft', - \ 'ScrollWheelRight', 'S-ScrollWheelRight', 'C-ScrollWheelRight'] - " Flush the char buffer on movement keystrokes: - for map in keys - exec 'inoremap delimitMate'.map.' !empty_buffer() ? "=delimitMate#Finish(1)<'.map.'>" : "<'.map.'>"' - if !hasmapto('delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == '' - exec 'silent! imap <'.map.'> delimitMate'.map - endif - endfor - " Also for default MacVim movements: - if has('gui_macvim') - for [key, map] in [['D-Left','Home'], ['D-Right','End'], ['M-Left','C-Left'], ['M-Right','C-Right']] - exec 'inoremap delimitMate'.key.' =Finish()<'.map.'>' - if mapcheck('<'.key.'>', 'i') == '<'.map.'>' - exec 'silent! imap <'.key.'> delimitMate'.key - endif - endfor - endif - " Except when pop-up menu is active: - for map in ['Up', 'Down', 'PageUp', 'PageDown', 'S-Down', 'S-Up'] - exec 'inoremap delimitMate'.map.' pumvisible() \|\| empty_buffer() ? "\<'.map.'>" : "\=\Finish()\\<'.map.'>"' - if !hasmapto('delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == '' - exec 'silent! imap <'.map.'> delimitMate'.map - endif - endfor - " Avoid ambiguous mappings: - for map in ['LeftMouse', 'RightMouse'] - exec 'inoremap delimitMateM'.map.' =delimitMate#Finish(1)<'.map.'>' - if !hasmapto('delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == '' - exec 'silent! imap <'.map.'> delimitMateM'.map - endif - endfor - " Jump over next delimiters - inoremap delimitMateJumpMany =len(delimitMate#Get('buffer')) ? delimitMate#Finish(0) : delimitMate#JumpMany() + inoremap delimitMateJumpMany =delimitMate#JumpMany() if !hasmapto('delimitMateJumpMany', 'i') && maparg("g", 'i') == '' imap g delimitMateJumpMany endif @@ -424,14 +365,6 @@ augroup delimitMate \ call DelimitMateDo() | \ let b:delimitMate_was_here = 1 | \ endif - - " Flush the char buffer: - autocmd InsertEnter * call FlushBuffer() - autocmd BufEnter * - \ if mode() == 'i' | - \ call FlushBuffer() | - \ endif - augroup END "}}}