Skip to content
Browse files

[vim] delimitMate update

  • Loading branch information...
1 parent af04f23 commit 233aca0a3e22245299a7e85a3265e2cc57cc5a16 @guns committed
View
124 etc/vim/bundle/delimitMate/Makefile
@@ -1,62 +1,82 @@
-PLUGIN=$(shell basename "$$PWD")
-SCRIPT=$(wildcard plugin/*.vim)
-#AUTOL=$(wildcard autoload/*.vim)
-AUTOL=autoload/$(PLUGIN).vim
-DOC=$(wildcard doc/*.txt)
-TESTS=$(wildcard autoload/*Tests.vim)
-VERSION=$(shell perl -ne 'if (/\*\sCurrent\srelease:/) {s/^\s+(\d+\.\S+)\s.*$$/\1/;print}' $(DOC))
-VIMFOLDER=~/.vim/
-VIM=/usr/bin/vim
+PLUGIN = $(wildcard plugin/*.vim)
+SOURCES = $(PLUGIN)
+LIB = $(wildcard autoload/*.vim)
+SOURCES += $(LIB)
+DOC = $(wildcard doc/*.txt)
+SOURCES += $(DOC)
+#NAME = $(shell basename "$$PWD")
+NAME = delimitMate
+VERSION = $(shell $(SED) -n -e '/Current \+release/{s/^ \+\([0-9.]\+\).*/\1/;p;}' $(firstword $(DOC)))
+FILENAME = $(NAME)-$(VERSION)
+DESTDIR = $(HOME)/.vim
+VIM = vim
+SED = gsed
+PERL = perl
+comma := ,
+empty :=
+space := $(empty) $(empty)
-.PHONY: $(PLUGIN).vba README
+.PHONY: version clean distclean undo release test install uninstall
-all: vimball README zip gzip
-
-vimball: $(PLUGIN).vba
+all: zip gzip
+dist: version all
+vimball: $(FILENAME).vmb
+zip: $(FILENAME).zip $(FILENAME).vmb.zip
+gzip: $(FILENAME).tar.gz $(FILENAME).vmb.gz
clean:
- @echo clean
- rm -f *.vba */*.orig *.~* .VimballRecord *.zip *.gz
+ rm -f */*.orig *.~* .VimballRecord *.zip *.gz *.vmb
-dist-clean: clean
+distclean: clean
+ -zsh -c 'setopt extendedglob; rm -f ^(README.md|Makefile)'
+ -zsh -c 'setopt extendedglob; rm -f .^(git|README.md|Makefile)*'
undo:
for i in */*.orig; do mv -f "$$i" "$${i%.*}"; done
-README:
- @echo README
- cp -f $(DOC) README
-
-$(PLUGIN).vba:
- @echo $(PLUGIN).vba
- rm -f $(PLUGIN)-$(VERSION).vba
- $(VIM) -N -c 'ru! vimballPlugin.vim' -c ':call append("0", [ "$(SCRIPT)", "$(AUTOL)", "$(DOC)"])' -c '$$d' -c ":%MkVimball $(PLUGIN)-$(VERSION) ." -c':q!'
- ln -f $(PLUGIN)-$(VERSION).vba $(PLUGIN).vba
-
-zip:
- @echo zip
- rm -f *.zip
- zip -r $(PLUGIN).zip doc plugin autoload
- zip $(PLUGIN).zip -d \*.sw\? || echo 1
- zip $(PLUGIN).zip -d \*.un\? || echo 1
- zip $(PLUGIN).zip -d \*.orig || echo 1
- zip $(PLUGIN).zip -d \*tags || echo 1
- zip $(PLUGIN).zip -d $(TESTS)
- ln -f $(PLUGIN).zip $(PLUGIN)-$(VERSION).zip
-
-gzip: vimball
- @echo vimball
- gzip -f $(PLUGIN).vba
-
-release: version all
-
version:
- @echo version: $(VERSION)
- perl -i.orig -pne 'if (/^"\sVersion:/) {s/(\d+\.\S+)/$(VERSION)/}' $(SCRIPT) $(AUTOL)
- perl -i.orig -pne 'if (/let\sdelimitMate_version/) {s/"(\d+\.\S+)"/"$(VERSION)"/}' $(SCRIPT)
- perl -i.orig -pne 'if (/beasts/) {s/(v\d+\.\S+)/v$(VERSION)/}' $(DOC)
- perl -i.orig -MPOSIX -pne 'if (/^"\sModified:/) {$$now_string = strftime "%F", localtime; s/(\d+-\d+-\d+)/$$now_string/e}' $(SCRIPT) $(AUTOL)
- perl -i.orig -MPOSIX -pne 'if (/^\s+$(VERSION)\s+\d+-\d+-\d+\s+\*/) {$$now_string = strftime "%F", localtime; s/(\d+-\d+-\d+)/$$now_string/}' $(DOC)
- @echo Version: $(VERSION)
-
-echo:
+ $(PERL) -i.orig -pne 'if (/^"\sVersion:/) {s/(\d+\.\S+)/$(VERSION)/}' $(PLUGIN) $(LIB)
+ $(PERL) -i.orig -pne \
+ 'if (/let\sdelimitMate_version/) {s/"(\d+\.\S+)"/"$(VERSION)"/}' $(PLUGIN)
+ $(PERL) -i.orig -pne 'if (/beasts/) {s/(v\d+\.\S+)/v$(VERSION)/}' $(DOC)
+ $(PERL) -i.orig -MPOSIX -pne \
+ 'if (/^"\sModified:/) {$$now_string = strftime "%F", localtime; s/(\d+-\d+-\d+)/$$now_string/e}' \
+ $(PLUGIN) $(LIB)
+ $(PERL) -i.orig -MPOSIX -pne \
+ 'if (/^\s+$(VERSION)\s+\d+-\d+-\d+\s+\*/) {$$now_string = strftime "%F", localtime; s/(\d+-\d+-\d+)/$$now_string/}' \
+ $(DOC)
+
+test:
+ runVimTests -0 test
+
+install: $(SOURCES)
+ for dir in $(^D);\
+ do install -d -m 0755 $(DESTDIR)$(PREFIX)/$$dir;\
+done;\
+for file in $^;\
+ do install -m 0644 $$file $(DESTDIR)$(PREFIX)/$$file;\
+done;
+
+uninstall:
+ for file in $(SOURCES);\
+ do rm -f $(DESTDIR)$(PREFIX)/$$file;\
+done;
+
+%.vmb: $(SOURCES)
+ $(VIM) -N -es -u NORC \
+ -c 'call setline(1,["$(subst $(space),"$(comma)",$^)"])'\
+ -c "%MkVimball! $(basename $@) ." -c 'q!'
+
+%.vmb.zip: vimball
+ zip $@ $(basename $@)
+
+%.zip: $(SOURCES)
+ zip $@ $^
+
+%.vmb.gz: vimball
+ gzip -f $(basename $@)
+
+%.tar.gz: $(SOURCES)
+ tar -cvzf $@ $^
+
+# vim:ts=2:sw=2
View
3 etc/vim/bundle/delimitMate/README
@@ -1,3 +0,0 @@
-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, like syntax awareness (will not insert the closing delimiter in comments and other configurable regions), <CR> and <Space> expansions (off by default), and some more.
-
-Most of the features can be modified or disabled permanently, using global variables, or on a FileType basis, using :autocmd. With a couple of exceptions and limitations, these features don't break undo, redo or history.
View
6 etc/vim/bundle/delimitMate/README.md
@@ -0,0 +1,6 @@
+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, like syntax awareness (will not insert the closing delimiter
+in comments and other configurable regions), <CR> and <Space> expansions (off by default), and some more.
+
+Most of the features can be modified or disabled permanently, using global variables, or on a FileType basis, using
+:autocmd.
View
532 etc/vim/bundle/delimitMate/autoload/delimitMate.vim
@@ -1,6 +1,6 @@
" File: autoload/delimitMate.vim
-" Version: 2.6
-" Modified: 2011-01-14
+" Version: 2.7
+" Modified: 2013-07-15
" Description: This plugin provides auto-completion for quotes, parens, etc.
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
" Manual: Read ":help delimitMate".
@@ -10,10 +10,57 @@
"let delimitMate_loaded = 1
+if !exists('s:options')
+ let s:options = {}
+endif
+function! s:s(name, value, ...) "{{{
+ let scope = a:0 ? a:1 : 's'
+ let bufnr = bufnr('%')
+ if !exists('s:options[bufnr]')
+ let s:options[bufnr] = {}
+ endif
+ if scope == 's'
+ let name = 'options.' . bufnr . '.' . a:name
+ else
+ let name = 'delimitMate_' . a:name
+ endif
+ exec 'let ' . scope . ':' . name . ' = a:value'
+endfunction "}}}
+
+function! s:g(name, ...) "{{{
+ let scope = a:0 ? a:1 : 's'
+ if scope == 's'
+ let bufnr = bufnr('%')
+ let name = 'options.' . bufnr . '.' . a:name
+ else
+ let name = 'delimitMate_' . a:name
+ endif
+ return eval(scope . ':' . name)
+endfunction "}}}
+
+function! s:exists(name, ...) "{{{
+ let scope = a:0 ? a:1 : 's'
+ if scope == 's'
+ let bufnr = bufnr('%')
+ let name = 'options.' . bufnr . '.' . a:name
+ else
+ let name = 'delimitMate_' . a:name
+ endif
+ return exists(scope . ':' . name)
+endfunction "}}}
+
+function! delimitMate#Set(...) "{{{
+ return call('s:s', a:000)
+endfunction "}}}
+
+function! delimitMate#Get(...) "{{{
+ return call('s:g', a:000)
+endfunction "}}}
+
function! delimitMate#ShouldJump(...) "{{{
" Returns 1 if the next character is a closing delimiter.
let char = delimitMate#GetCharFromCursor(0)
- let list = b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
+ let list = s:g('right_delims') + s:g('quotes_list')
" Closing delimiter on the right.
if (!a:0 && index(list, char) > -1)
@@ -23,24 +70,27 @@ function! delimitMate#ShouldJump(...) "{{{
" Closing delimiter with space expansion.
let nchar = delimitMate#GetCharFromCursor(1)
- if !a:0 && b:_l_delimitMate_expand_space && char == " "
+ if !a:0 && s:g('expand_space') && char == " "
if index(list, nchar) > -1
return 2
endif
- elseif a:0 && b:_l_delimitMate_expand_space && nchar == a:1
+ elseif a:0 && s:g('expand_space') && nchar == a:1 && char == ' '
return 3
endif
+ if !s:g('jump_expansion')
+ return 0
+ endif
+
" Closing delimiter with CR expansion.
let uchar = matchstr(getline(line('.') + 1), '^\s*\zs\S')
- if !a:0 && b:_l_delimitMate_expand_cr && char == ""
+ if !a:0 && s:g('expand_cr') && char == ""
if index(list, uchar) > -1
return 4
endif
- elseif a:0 && b:_l_delimitMate_expand_cr && uchar == a:1
+ elseif a:0 && s:g('expand_cr') && uchar == a:1
return 5
endif
-
return 0
endfunction "}}}
@@ -48,19 +98,35 @@ function! delimitMate#IsEmptyPair(str) "{{{
if strlen(substitute(a:str, ".", "x", "g")) != 2
return 0
endif
- let idx = index(b:_l_delimitMate_left_delims, matchstr(a:str, '^.'))
+ let idx = index(s:g('left_delims'), matchstr(a:str, '^.'))
if idx > -1 &&
- \ b:_l_delimitMate_right_delims[idx] == matchstr(a:str, '.$')
+ \ s:g('right_delims')[idx] == matchstr(a:str, '.$')
return 1
endif
- let idx = index(b:_l_delimitMate_quotes_list, matchstr(a:str, '^.'))
+ let idx = index(s:g('quotes_list'), matchstr(a:str, '^.'))
if idx > -1 &&
- \ b:_l_delimitMate_quotes_list[idx] == matchstr(a:str, '.$')
+ \ s:g('quotes_list')[idx] == matchstr(a:str, '.$')
return 1
endif
return 0
endfunction "}}}
+function! delimitMate#RightQ(char) "{{{
+ let i = 0
+ while delimitMate#GetCharFromCursor(i) ==# a:char
+ let i += 1
+ endwhile
+ return i
+endfunction "}}}
+
+function! delimitMate#LeftQ(char) "{{{
+ let i = 0
+ while delimitMate#GetCharFromCursor(i - 1) ==# a:char
+ let i -= 1
+ endwhile
+ return i * -1
+endfunction "}}}
+
function! delimitMate#GetCharFromCursor(...) "{{{
let idx = col('.') - 1
if !a:0 || (a:0 && a:1 >= 0)
@@ -79,12 +145,14 @@ function! delimitMate#IsCRExpansion(...) " {{{
let nchar = getline(line('.')-1)[-1:]
let schar = matchstr(getline(line('.')+1), '^\s*\zs\S')
let isEmpty = a:0 ? getline('.') =~ '^\s*$' : empty(getline('.'))
- if index(b:_l_delimitMate_left_delims, nchar) > -1
- \ && index(b:_l_delimitMate_left_delims, nchar) == index(b:_l_delimitMate_right_delims, schar)
+ if index(s:g('left_delims'), nchar) > -1
+ \ && index(s:g('left_delims'), nchar)
+ \ == index(s:g('right_delims'), schar)
\ && isEmpty
return 1
- elseif index(b:_l_delimitMate_quotes_list, nchar) > -1
- \ && index(b:_l_delimitMate_quotes_list, nchar) == index(b:_l_delimitMate_quotes_list, schar)
+ elseif index(s:g('quotes_list'), nchar) > -1
+ \ && index(s:g('quotes_list'), nchar)
+ \ == index(s:g('quotes_list'), schar)
\ && isEmpty
return 1
else
@@ -96,14 +164,19 @@ function! delimitMate#IsSpaceExpansion() " {{{
if col('.') > 2
let pchar = delimitMate#GetCharFromCursor(-2)
let nchar = delimitMate#GetCharFromCursor(1)
- let isSpaces = (delimitMate#GetCharFromCursor(-1) == delimitMate#GetCharFromCursor(0) && delimitMate#GetCharFromCursor(-1) == " ")
-
- if index(b:_l_delimitMate_left_delims, pchar) > -1 &&
- \ index(b:_l_delimitMate_left_delims, pchar) == index(b:_l_delimitMate_right_delims, nchar) &&
+ let isSpaces =
+ \ (delimitMate#GetCharFromCursor(-1)
+ \ == delimitMate#GetCharFromCursor(0)
+ \ && delimitMate#GetCharFromCursor(-1) == " ")
+
+ if index(s:g('left_delims'), pchar) > -1 &&
+ \ index(s:g('left_delims'), pchar)
+ \ == index(s:g('right_delims'), nchar) &&
\ isSpaces
return 1
- elseif index(b:_l_delimitMate_quotes_list, pchar) > -1 &&
- \ index(b:_l_delimitMate_quotes_list, pchar) == index(b:_l_delimitMate_quotes_list, nchar) &&
+ elseif index(s:g('quotes_list'), pchar) > -1 &&
+ \ index(s:g('quotes_list'), pchar)
+ \ == index(s:g('quotes_list'), nchar) &&
\ isSpaces
return 1
endif
@@ -124,35 +197,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
- 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 " }}}
@@ -168,7 +212,8 @@ 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)
+ let changed_line = strpart(origin_line, 0, col - 1) . a:char
+ \ . strpart(origin_line, col - 1)
call setline('.', changed_line)
let region = delimitMate#GetSyntaxRegion(line('.'), col)
call setline('.', origin_line)
@@ -176,28 +221,19 @@ function! delimitMate#GetCurrentSyntaxRegionIf(char) "{{{
endfunction "}}}
function! delimitMate#IsForbidden(char) "{{{
- if b:_l_delimitMate_excluded_regions_enabled == 0
+ if !s:g('excluded_regions_enabled')
return 0
endif
let region = delimitMate#GetCurrentSyntaxRegion()
- if index(b:_l_delimitMate_excluded_regions_list, region) >= 0
- "echom "Forbidden 1!"
- return 1
- endif
- let region = delimitMate#GetCurrentSyntaxRegionIf(a:char)
+ "if index(s:g('excluded_regions_list'), region) >= 0
+ " "echom "Forbidden 1!"
+ " return 1
+ "endif
+ "let region = delimitMate#GetCurrentSyntaxRegionIf(a:char)
"echom "Forbidden 2!"
- return index(b:_l_delimitMate_excluded_regions_list, region) >= 0
+ return index(s:g('excluded_regions_list'), region) >= 0
endfunction "}}}
-function! delimitMate#FlushBuffer() " {{{
- let b:_l_delimitMate_buffer = []
- return ''
-endfunction " }}}
-
-function! delimitMate#AddToBuffer(str) "{{{
- call insert(b:_l_delimitMate_buffer, a:str)
-endfunction "delimitMate#AddToBuffer }}}
-
function! delimitMate#BalancedParens(char) "{{{
" Returns:
" = 0 => Parens balanced.
@@ -208,7 +244,7 @@ function! delimitMate#BalancedParens(char) "{{{
let col = delimitMate#CursorIdx() - 1
let col = col >= 0 ? col : 0
let list = split(line, '\zs')
- let left = b:_l_delimitMate_left_delims[index(b:_l_delimitMate_right_delims, a:char)]
+ let left = s:g('left_delims')[index(s:g('right_delims'), a:char)]
let right = a:char
let opening = 0
let closing = 0
@@ -235,15 +271,8 @@ function! delimitMate#BalancedParens(char) "{{{
return opening - closing
endfunction "}}}
-function! delimitMate#RmBuffer(num) " {{{
- if len(b:_l_delimitMate_buffer) > 0
- call remove(b:_l_delimitMate_buffer, 0, (a:num-1))
- endif
- return ""
-endfunction " }}}
-
function! delimitMate#IsSmartQuote(char) "{{{
- if !b:_l_delimitMate_smart_quotes
+ if !s:g('smart_quotes')
return 0
endif
let char_at = delimitMate#GetCharFromCursor(0)
@@ -251,8 +280,11 @@ function! delimitMate#IsSmartQuote(char) "{{{
let valid_char_re = '\w\|[^[:punct:][:space:]]'
let word_before = char_before =~ valid_char_re
let word_at = char_at =~ valid_char_re
- let escaped = delimitMate#CursorIdx() >= 1 && delimitMate#GetCharFromCursor(-1) == '\'
- let result = word_before || escaped || word_at
+ let escaped = delimitMate#CursorIdx() >= 1
+ \ && delimitMate#GetCharFromCursor(-1) == '\'
+ let noescaped = substitute(getline('.'), '\\.', '', 'g')
+ let odd = (count(split(noescaped, '\zs'), a:char) % 2)
+ let result = word_before || escaped || word_at || odd
return result
endfunction "delimitMate#SmartQuote }}}
@@ -277,46 +309,39 @@ 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 . "\<Del>"
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 . "\<Left>"
else
" Nothing special here, return the same character.
return a:char
endif
endfunction "}}}
-function! delimitMate#ParenDelim(char) " {{{
- if delimitMate#IsForbidden(a:char)
- return ''
+function! delimitMate#ParenDelim(right) " {{{
+ let left = s:g('left_delims')[index(s:g('right_delims'),a:right)]
+ if delimitMate#IsForbidden(a:right)
+ return left
endif
" Try to balance matchpairs
- if b:_l_delimitMate_balance_matchpairs &&
- \ delimitMate#BalancedParens(a:char) <= 0
- return ''
+ if s:g('balance_matchpairs') &&
+ \ delimitMate#BalancedParens(a:right) < 0
+ return left
endif
let line = getline('.')
let col = col('.')-2
- let tail = len(line) == (col + 1) ? b:_l_delimitMate_eol_marker : ''
- let left = b:_l_delimitMate_left_delims[index(b:_l_delimitMate_right_delims,a:char)]
- let smart_matchpairs = substitute(b:_l_delimitMate_smart_matchpairs, '\\!', left, 'g')
- let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:char, 'g')
- "echom left.':'.smart_matchpairs . ':' . matchstr(line[col+1], smart_matchpairs)
- if b:_l_delimitMate_smart_matchpairs != '' &&
+ let tail = len(line) == (col + 1) ? s:g('eol_marker') : ''
+ let smart_matchpairs = substitute(s:g('smart_matchpairs'), '\\!', left, 'g')
+ let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:right, 'g')
+
+ if s:g('smart_matchpairs') != '' &&
\ line[col+1:] =~ smart_matchpairs
- return ''
- elseif (col) < 0
- call setline('.',a:char.line)
- call delimitMate#AddToBuffer(a:char)
- else
- "echom string(col).':'.line[:(col)].'|'.line[(col+1):]
- call setline('.',line[:(col)].a:char.tail.line[(col+1):])
- call delimitMate#AddToBuffer(a:char . tail)
+ return left
+ "elseif (col) < 0
+ " call setline('.',a:right.line)
endif
- return ''
+ return left . a:right . tail . repeat("\<Left>", len(split(tail, '\zs')) + 1)
endfunction " }}}
function! delimitMate#QuoteDelim(char) "{{{
@@ -325,22 +350,35 @@ function! delimitMate#QuoteDelim(char) "{{{
endif
let char_at = delimitMate#GetCharFromCursor(0)
let char_before = delimitMate#GetCharFromCursor(-1)
- if char_at == a:char &&
- \ index(b:_l_delimitMate_nesting_quotes, a:char) < 0
- " Get out of the string.
- return a:char . delimitMate#Del()
+ let nesting_on = index(s:g('nesting_quotes'), a:char) > -1
+ let left_q = nesting_on ? delimitMate#LeftQ(a:char) : 0
+ if nesting_on && left_q > 1
+ " Nesting quotes.
+ let right_q = delimitMate#RightQ(a:char)
+ let quotes = right_q > left_q + 1 ? 0 : left_q - right_q + 2
+ let lefts = quotes - 1
+ return repeat(a:char, quotes) . repeat("\<Left>", lefts)
+ elseif char_at == a:char
+ " Inside an empty pair, jump out
+ return a:char . "\<Del>"
elseif delimitMate#IsSmartQuote(a:char)
" Seems like a smart quote, insert a single char.
return a:char
- elseif (char_before == a:char && char_at != a:char) && b:_l_delimitMate_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)
+ elseif (char_before == a:char && char_at != a:char)
+ \ && s:g('smart_quotes')
+ " Seems like we have an unbalanced quote, insert one quotation
+ " mark and jump to the middle.
+ return a:char . "\<Left>"
else
" Insert a pair and jump to the middle.
- call delimitMate#AddToBuffer(a:char)
- call delimitMate#WriteAfter(a:char)
- return a:char
+ let sufix = ''
+ if !empty(s:g('eol_marker')) && col('.') - 1 == len(getline('.'))
+ let idx = len(s:g('eol_marker')) * -1
+ let marker = getline('.')[idx : ]
+ let has_marker = marker == s:g('eol_marker')
+ let sufix = !has_marker ? s:g('eol_marker') : ''
+ endif
+ return a:char . a:char . "\<Left>"
endif
endfunction "}}}
@@ -350,39 +388,33 @@ function! delimitMate#JumpOut(char) "{{{
endif
let jump = delimitMate#ShouldJump(a:char)
if jump == 1
- return a:char . delimitMate#Del()
+ return "\<Right>"
elseif jump == 3
- return ' '.a:char.delimitMate#Del().delimitMate#Del()
+ return "\<Right>\<Right>"
elseif jump == 5
- call delimitMate#FlushBuffer()
- return "\<C-O>:exec \"normal! \\<CR>a\"\<CR>"
+ return "\<Down>\<C-O>I\<Right>"
else
return a:char
endif
endfunction " }}}
-function! delimitMate#JumpAny(key) " {{{
+function! delimitMate#JumpAny(...) " {{{
if delimitMate#IsForbidden('')
- return a:key
+ return ''
endif
if !delimitMate#ShouldJump()
- return a:key
+ return ''
endif
" Let's get the character on the right.
let char = delimitMate#GetCharFromCursor(0)
if char == " "
" Space expansion.
- "let char = char . getline('.')[col('.')] . delimitMate#Del()
- return char . getline('.')[col('.')] . delimitMate#Del() . delimitMate#Del()
- "call delimitMate#RmBuffer(1)
+ return "\<Right>\<Right>"
elseif char == ""
" CR expansion.
- "let char = "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
- call delimitMate#FlushBuffer()
- return "\<CR>" . getline(line('.') + 1)[0] . delimitMate#Del() . "\<Del>"
+ return "\<CR>" . getline(line('.') + 1)[0] . "\<Del>\<Del>"
else
- "call delimitMate#RmBuffer(1)
- return char . delimitMate#Del()
+ return "\<Right>"
endif
endfunction " delimitMate#JumpAny() }}}
@@ -391,8 +423,8 @@ function! delimitMate#JumpMany() " {{{
let rights = ""
let found = 0
for char in line
- if index(b:_l_delimitMate_quotes_list, char) >= 0 ||
- \ index(b:_l_delimitMate_right_delims, char) >= 0
+ if index(s:g('quotes_list'), char) >= 0 ||
+ \ index(s:g('right_delims'), char) >= 0
let rights .= "\<Right>"
let found = 1
elseif found == 0
@@ -414,10 +446,8 @@ 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.
+ " 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
" InsertLeave.
return "\<Esc>a\<CR>\<Esc>zvO"
@@ -430,119 +460,59 @@ function! delimitMate#ExpandSpace() "{{{
if delimitMate#IsForbidden("\<Space>")
return "\<Space>"
endif
- let escaped = delimitMate#CursorIdx() >= 2 && delimitMate#GetCharFromCursor(-2) == '\'
+ let escaped = delimitMate#CursorIdx() >= 2
+ \ && delimitMate#GetCharFromCursor(-2) == '\'
if delimitMate#WithinEmptyPair() && !escaped
" Expand:
- call delimitMate#AddToBuffer('s')
- return delimitMate#WriteAfter(' ') . "\<Space>"
+ return "\<Space>\<Space>\<Left>"
else
return "\<Space>"
endif
endfunction "}}}
function! delimitMate#BS() " {{{
- let buffer_tail = get(b:_l_delimitMate_buffer, '-1', '')
if delimitMate#IsForbidden("")
let extra = ''
- elseif &backspace !~ 'start\|2' && empty(b:_l_delimitMate_buffer)
+ elseif &bs !~ 'start\|2'
let extra = ''
elseif delimitMate#WithinEmptyPair()
- let extra = delimitMate#Del()
+ let extra = "\<Del>"
elseif delimitMate#IsSpaceExpansion()
- let extra = delimitMate#Del()
+ let extra = "\<Del>"
elseif delimitMate#IsCRExpansion()
- let extra = repeat("\<Del>", len(matchstr(getline(line('.') + 1), '^\s*\S')))
+ let extra = repeat("\<Del>",
+ \ len(matchstr(getline(line('.') + 1), '^\s*\S')))
else
let extra = ''
endif
- let tail_re = '\m\C\%('
- \ . join(b:_l_delimitMate_right_delims, '\|')
- \ . '\)'
- \ . escape(b:_l_delimitMate_eol_marker, '\*.^$')
- \ . '$'
- if buffer_tail =~ tail_re && search('\%#'.tail_re, 'cWn')
- let extra .= join(map(split(b:_l_delimitMate_eol_marker, '\zs'),
- \ 'delimitMate#Del()'), '')
- endif
return "\<BS>" . extra
endfunction " }}} delimitMate#BS()
-function! delimitMate#Del() " {{{
- if len(b:_l_delimitMate_buffer) > 0
- call delimitMate#RmBuffer(1)
- return "\<Del>"
- else
- return "\<Del>"
- endif
-endfunction " }}}
-
-function! delimitMate#Finish(move_back) " {{{
- let len = len(b:_l_delimitMate_buffer)
- if len > 0
- let buffer = join(b:_l_delimitMate_buffer, '')
- let len2 = len(buffer)
- " Reset buffer:
- let b:_l_delimitMate_buffer = []
- let line = getline('.')
- let col = col('.') -2
- "echom 'col: ' . col . '-' . line[:col] . "|" . line[col+len+1:] . '%' . buffer
- 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 . "\<Left>"
- let i += 1
- endwhile
- let result = substitute(buffer, "s", "\<Space>", 'g') . lefts
- return result
- endif
- return ''
-endfunction " }}}
-
" }}}
" Tools: {{{
function! delimitMate#TestMappings() "{{{
- if &modified
- echohl WarningMsg
- let answer = input("Modified buffer, type \"yes\" to write and proceed with test: ") !~ '\c^yes$'
- echohl NONE
- if answer != '\c^yes$'
- return
- endif
- write
- endif
+ echom 1
+ %d
let options = sort(keys(delimitMate#OptionsList()))
- let optoutput = ['delimitMate Report', '==================', '', '* Options: ( ) default, (g) global, (b) buffer','']
+ let optoutput = ['delimitMate Report', '==================', '',
+ \ '* Options: ( ) default, (g) global, (b) buffer','']
for option in options
- exec 'call add(optoutput, ''('.(exists('b:delimitMate_'.option) ? 'b' : exists('g:delimitMate_'.option) ? 'g' : ' ').') delimitMate_''.option.'' = ''.string(b:_l_delimitMate_'.option.'))'
+ let scope = s:exists(option, 'b') ? 'b'
+ \ : s:exists(option, 'g') ? 'g' : ' '
+ call add(optoutput, '(' . scope . ')' . ' delimitMate_' . option . ' = ' . string(s:g(option)))
endfor
call append(line('$'), optoutput + ['--------------------',''])
" Check if mappings were set. {{{
- let imaps = b:_l_delimitMate_right_delims
- let imaps = imaps + ( b:_l_delimitMate_autoclose ? b:_l_delimitMate_left_delims : [] )
- let imaps = imaps +
- \ b:_l_delimitMate_quotes_list +
- \ b:_l_delimitMate_apostrophes_list +
- \ ['<BS>', '<S-BS>', '<Del>', '<S-Tab>', '<Esc>'] +
- \ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
- \ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>', '<C-G>g'] +
- \ ['<ScrollWheelUp>', '<S-ScrollWheelUp>', '<C-ScrollWheelUp>'] +
- \ ['<ScrollWheelDown>', '<S-ScrollWheelDown>', '<C-ScrollWheelDown>'] +
- \ ['<ScrollWheelLeft>', '<S-ScrollWheelLeft>', '<C-ScrollWheelLeft>'] +
- \ ['<ScrollWheelRight>', '<S-ScrollWheelRight>', '<C-ScrollWheelRight>']
- let imaps = imaps + ( b:_l_delimitMate_expand_cr ? ['<CR>'] : [] )
- let imaps = imaps + ( b:_l_delimitMate_expand_space ? ['<Space>'] : [] )
-
- let vmaps =
- \ b:_l_delimitMate_right_delims +
- \ b:_l_delimitMate_left_delims +
- \ b:_l_delimitMate_quotes_list
+ let imaps = s:g('right_delims')
+ let imaps += ( s:g('autoclose') ? s:g('left_delims') : [] )
+ let imaps +=
+ \ s:g('quotes_list') +
+ \ s:g('apostrophes_list') +
+ \ ['<BS>', '<S-BS>', '<S-Tab>', '<Esc>', '<C-G>g']
+ let imaps += ( s:g('expand_cr') ? ['<CR>'] : [] )
+ let imaps += ( s:g('expand_space') ? ['<Space>'] : [] )
let imappings = []
for map in imaps
@@ -551,71 +521,91 @@ function! delimitMate#TestMappings() "{{{
let map = '<Bar>'
endif
redir => output | execute "verbose imap ".map | redir END
- let imappings = imappings + split(output, '\n')
+ let imappings += split(output, '\n')
endfor
unlet! output
let output = ['* Mappings:', ''] + imappings + ['--------------------', '']
call append('$', output+['* Showcase:', ''])
" }}}
- if b:_l_delimitMate_autoclose
+ if s:g('autoclose')
" {{{
- for i in range(len(b:_l_delimitMate_left_delims))
- exec "normal Go0\<C-D>Open: " . b:_l_delimitMate_left_delims[i]. "|"
- exec "normal o0\<C-D>Delete: " . b:_l_delimitMate_left_delims[i] . "\<BS>|"
- exec "normal o0\<C-D>Exit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
- if b:_l_delimitMate_expand_space == 1
- exec "normal o0\<C-D>Space: " . b:_l_delimitMate_left_delims[i] . " |"
- exec "normal o0\<C-D>Delete space: " . b:_l_delimitMate_left_delims[i] . " \<BS>|"
+ for i in range(len(s:g('left_delims')))
+ exec "normal Go0\<C-D>Open: " . s:g('left_delims')[i]. "|"
+ exec "normal o0\<C-D>Delete: " . s:g('left_delims')[i] . "\<BS>|"
+ exec "normal o0\<C-D>Exit: " . s:g('left_delims')[i] . s:g('right_delims')[i] . "|"
+ if s:g('expand_space') == 1
+ exec "normal o0\<C-D>Space: " . s:g('left_delims')[i] . " |"
+ exec "normal o0\<C-D>Delete space: " . s:g('left_delims')[i]
+ \ . " \<BS>|"
endif
- if b:_l_delimitMate_expand_cr == 1
- exec "normal o0\<C-D>Car return: " . b:_l_delimitMate_left_delims[i] . "\<CR>|"
- exec "normal Go0\<C-D>Delete car return: " . b:_l_delimitMate_left_delims[i] . "\<CR>0\<C-D>\<BS>|"
+ if s:g('expand_cr') == 1
+ exec "normal o0\<C-D>Car return: " . s:g('left_delims')[i] .
+ \ "\<CR>|"
+ exec "normal Go0\<C-D>Delete car return: " . s:g('left_delims')[i]
+ \ . "\<CR>0\<C-D>\<BS>|"
endif
call append(line('$'), '')
endfor
- for i in range(len(b:_l_delimitMate_quotes_list))
- exec "normal Go0\<C-D>Open: " . b:_l_delimitMate_quotes_list[i] . "|"
- exec "normal o0\<C-D>Delete: " . b:_l_delimitMate_quotes_list[i] . "\<BS>|"
- exec "normal o0\<C-D>Exit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
- if b:_l_delimitMate_expand_space == 1
- exec "normal o0\<C-D>Space: " . b:_l_delimitMate_quotes_list[i] . " |"
- exec "normal o0\<C-D>Delete space: " . b:_l_delimitMate_quotes_list[i] . " \<BS>|"
+ for i in range(len(s:g('quotes_list')))
+ exec "normal Go0\<C-D>Open: " . s:g('quotes_list')[i] . "|"
+ exec "normal o0\<C-D>Delete: " . s:g('quotes_list')[i] . "\<BS>|"
+ exec "normal o0\<C-D>Exit: " . s:g('quotes_list')[i] . s:g('quotes_list')[i] . "|"
+ if s:g('expand_space') == 1
+ exec "normal o0\<C-D>Space: " . s:g('quotes_list')[i] . " |"
+ exec "normal o0\<C-D>Delete space: " . s:g('quotes_list')[i]
+ \ . " \<BS>|"
endif
- if b:_l_delimitMate_expand_cr == 1
- exec "normal o0\<C-D>Car return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
- exec "normal Go0\<C-D>Delete car return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|"
+ if s:g('expand_cr') == 1
+ exec "normal o0\<C-D>Car return: " . s:g('quotes_list')[i]
+ \ . "\<CR>|"
+ exec "normal Go0\<C-D>Delete car return: " . s:g('quotes_list')[i]
+ \ . "\<CR>\<BS>|"
endif
call append(line('$'), '')
endfor
"}}}
else
"{{{
- for i in range(len(b:_l_delimitMate_left_delims))
- exec "normal GoOpen & close: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
- exec "normal oDelete: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<BS>|"
- exec "normal oExit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
- if b:_l_delimitMate_expand_space == 1
- exec "normal oSpace: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " |"
- exec "normal oDelete space: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " \<BS>|"
+ for i in range(len(s:g('left_delims')))
+ exec "normal GoOpen & close: " . s:g('left_delims')[i]
+ \ . s:g('right_delims')[i] . "|"
+ exec "normal oDelete: " . s:g('left_delims')[i]
+ \ . s:g('right_delims')[i] . "\<BS>|"
+ exec "normal oExit: " . s:g('left_delims')[i] . s:g('right_delims')[i]
+ \ . s:g('right_delims')[i] . "|"
+ if s:g('expand_space') == 1
+ exec "normal oSpace: " . s:g('left_delims')[i]
+ \ . s:g('right_delims')[i] . " |"
+ exec "normal oDelete space: " . s:g('left_delims')[i]
+ \ . s:g('right_delims')[i] . " \<BS>|"
endif
- if b:_l_delimitMate_expand_cr == 1
- exec "normal oCar return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<CR>|"
- exec "normal GoDelete car return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<CR>\<BS>|"
+ if s:g('expand_cr') == 1
+ exec "normal oCar return: " . s:g('left_delims')[i]
+ \ . s:g('right_delims')[i] . "\<CR>|"
+ exec "normal GoDelete car return: " . s:g('left_delims')[i]
+ \ . s:g('right_delims')[i] . "\<CR>\<BS>|"
endif
call append(line('$'), '')
endfor
- for i in range(len(b:_l_delimitMate_quotes_list))
- exec "normal GoOpen & close: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
- exec "normal oDelete: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<BS>|"
- exec "normal oExit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
- if b:_l_delimitMate_expand_space == 1
- exec "normal oSpace: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " |"
- exec "normal oDelete space: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " \<BS>|"
+ for i in range(len(s:g('quotes_list')))
+ exec "normal GoOpen & close: " . s:g('quotes_list')[i]
+ \ . s:g('quotes_list')[i] . "|"
+ exec "normal oDelete: " . s:g('quotes_list')[i]
+ \ . s:g('quotes_list')[i] . "\<BS>|"
+ exec "normal oExit: " . s:g('quotes_list')[i] . s:g('quotes_list')[i]
+ \ . s:g('quotes_list')[i] . "|"
+ if s:g('expand_space') == 1
+ exec "normal oSpace: " . s:g('quotes_list')[i]
+ \ . s:g('quotes_list')[i] . " |"
+ exec "normal oDelete space: " . s:g('quotes_list')[i]
+ \ . s:g('quotes_list')[i] . " \<BS>|"
endif
- if b:_l_delimitMate_expand_cr == 1
- exec "normal oCar return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
- exec "normal GoDelete car return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|"
+ if s:g('expand_cr') == 1
+ exec "normal oCar return: " . s:g('quotes_list')[i]
+ \ . s:g('quotes_list')[i] . "\<CR>|"
+ exec "normal GoDelete car return: " . s:g('quotes_list')[i]
+ \ . s:g('quotes_list')[i] . "\<CR>\<BS>|"
endif
call append(line('$'), '')
endfor
@@ -624,11 +614,27 @@ function! delimitMate#TestMappings() "{{{
call append(line('$'), split(setoptions,"\n")
\ + ['--------------------'])
setlocal nowrap
+ call feedkeys("\<Esc>\<Esc>", 'n')
endfunction "}}}
function! delimitMate#OptionsList() "{{{
- return {'autoclose' : 1,'matchpairs': &matchpairs, 'quotes' : '" '' `', 'nesting_quotes' : [], 'expand_cr' : 0, 'expand_space' : 0, 'smart_quotes' : 1, 'smart_matchpairs' : '\w', 'balance_matchpairs' : 0, 'excluded_regions' : 'Comment', 'excluded_ft' : '', 'eol_marker': '', 'apostrophes' : ''}
+ return {
+ \ 'apostrophes' : '',
+ \ 'autoclose' : 1,
+ \ 'balance_matchpairs' : 0,
+ \ 'jump_expansion' : 0,
+ \ 'eol_marker' : '',
+ \ 'excluded_ft' : '',
+ \ 'excluded_regions' : 'Comment',
+ \ 'expand_cr' : 0,
+ \ 'expand_space' : 0,
+ \ 'matchpairs' : &matchpairs,
+ \ 'nesting_quotes' : [],
+ \ 'quotes' : '" '' `',
+ \ 'smart_matchpairs' : '\w',
+ \ 'smart_quotes' : 1,
+ \}
endfunction " delimitMate#OptionsList }}}
"}}}
-" vim:foldmethod=marker:foldcolumn=4
+" vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2
View
260 etc/vim/bundle/delimitMate/autoload/delimitMateTests.vim
@@ -1,260 +0,0 @@
-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
- elseif g:delimitMate_testing == "fork"
- !gvim -N -u NONE -U NONE -c "set runtimepath+=~/.vim/bundle/pathogen" -c "call pathogen\#runtime_append_all_bundles('bundle','symlinks')" -c "set backspace=eol,start" -c "set background=light" -c "syntax on" -c "let delimitMate_testing = 1" -c "ru autoload/delimitMate.vim" -c "ru autoload/delimitMateTests.vim" -c "ru plugin/delimitMate.vim" -c "call delimitMateTests\#Main()"
- return ""
- endif
- nmap <F1> :qall!<CR>
- let nomore = &more
- set nomore
- let b:test_results = {}
- let b:errors = 0
- let b:corrects = 0
- let b:ignores = 0
-
- function! SetOptions(list) " {{{
- let b:delimitMate_autoclose = 1
- let b:delimitMate_matchpairs = &matchpairs
- let b:delimitMate_quotes = "\" ' `"
- let b:delimitMate_excluded_regions = "Comment"
- 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
- "echom '1:'.str
- let op = strpart(str, 0, stridx(str,':'))
- "echom op
- let val = strpart(str, stridx(str, ':' ) + 1)
- "echom val
- exec "let b:delimitMate_" . op . " = " . val
- endfor
- DelimitMateReload
- endfunction " }}}
-
- function! Type(name, input, output, options, ...) " {{{
- if a:0 > 0
- let ignore = a:1
- else
- let ignore = 0
- endif
- if a:input != "\<Esc>."
- " Set default options:
- call SetOptions(a:options)
- let CapR = ""
- normal ggVG"_d
- exec "normal i" . a:input . "|\<Esc>"
- else
- let CapR = "_R"
- normal gg.
- endif
-
- exec "normal \<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 ignore == 1
- let label = "Ignored"
- let result = "?="
- let b:ignores += 1
- elseif result == 0
- let label = "Passed"
- let result = "=="
- let b:corrects += 1
- else
- let label = "Failed"
- let result = "!="
- let b:errors += 1
- endif
- exec "let b:test_results['" .
- \ substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . CapR . "'] = '" .
- \ label . ": ' . a:input . ' => ' . text . ' " .
- \ result . " ' . join(a:output, '<cr>')"
- endfunction " }}}
-
- function! RepeatLast(name, output, ...) " {{{
- if a:0 > 0
- let arg1 = a:1
- else
- let arg1 = ''
- endif
- call Type(a:name, "\<Esc>.", a:output, [], arg1)
- 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", ['(', '|', ')(', '|', ')'], 1)
-
- " BS with car return expansion
- call Type("BS with CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
- call RepeatLast("BS with CR expansion", ['(|)(|)'], 1)
-
- " Smart quotes
- call Type("Smart quote alphanumeric", "a\"4", ['a"4|'], [])
- call RepeatLast("Smart quote alphanumeric", ['a"4|a"4|'])
-
- " 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", ['(|)(|)'])
-
- " <Right-arrow> inserts text
- call Type("<Right-arrow> inserts text", "(he\<Right>\<Space>th\<Right>\<Right>", ['(he) th|'], [])
-
- " Backspace inside CR expansion
- call Type("Backspace inside CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
- call RepeatLast("Backspace inside CR expansion", ['(|)(|)'], 1)
-
- " FileType event
- let g:delimitMate_excluded_ft = "vim"
- set ft=vim
- call Type("FileType Autoclose parens", "(", ["(|"], [])
- unlet g:delimitMate_excluded_ft
- set ft=
-
- " Duplicated delimiter after CR
- call Type("Duplicated delimiter after CR", "(\<CR>", ['(', '|)'], [])
-
- " Deactivate on comments: The first call to a closing delimiter
- " will not work here as expected, but it does in real life tests.
- set ft=vim
- call Type("Deactivate on comments", "\"()``[]''\"\"", ["\"()``[]''\"\"|"], ["autoclose:0"], 1)
- set ft=
-
- " Deactivate parens on comments: The first call to a closing delimiter
- " will not work here as expected, but it does in real life tests.
- set ft=vim
- call Type("Deactivate parens on comments", "\"()[]", ["\"()[]|"], ["autoclose:0"], 1)
- set ft=
-
- " Deactivate quotes on comments: See previous note.
- set ft=vim
- call Type("Deactivate parens on comments", "\"(`", ["\"(``|"], [], 1)
- set ft=
-
- " Manual close at start of line
- call Type("Manual close at start of line", "m)\<Left>\<Left>)", [')|m)'], ["autoclose:0"])
-
- " Use | in quotes
- call Type("Use <Bar> in quotes", "\<Bar>bars", ['|bars|'], ["quotes:'|'"])
-
- " Use | in matchpairs
- call Type("Use <Bar> in matchpairs", "\<Bar>bars", ['|bars|$$'], ["matchpairs:'|:$'"])
-
- "}}}
-
- " Show results: {{{
- normal ggVG"_d
- call append(0, split(string(b:test_results)[1:-2], ', '))
- call append(0, "*TESTS REPORT: " . b:errors . " failed, " . b:corrects . " passed and " . b:ignores . " ignored.")
- normal "_ddgg
- let @/ = ".\\+Failed:.*!="
- 2,$sort /^.\+':/
- normal gg
- exec search('Ignored:','nW').",$sort! /^.\\+':/"
- set nohlsearch
- syn match lineIgnored ".*Ignored.*"
- syn match labelPassed "'\@<=.\+\(': 'Passed\)\@="
- syn match labelFailed "'\@<=.\+\(': 'Failed\)\@="
- syn match resultPassed "\('Passed: \)\@<=.\+\('$\)\@="
- syn match resultFailed "\('Failed: \)\@<=.\+\('$\)\@=" contains=resultInequal
- syn match resultIgnored "\('Ignored: \)\@<=.\+\('$\)\@="
- syn match resultInequal "!="
- syn match resultSummary "^\*.\+" contains=resultSummaryNumber
- syn match resultSummaryNumber "[1-9][0-9]* failed*" contained
-
- hi def link lineIgnored Ignore
- 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
- hi def link resultSummary SpecialComment
- hi def link resultSummaryNumber Error
- " }}}
-
- let &more = nomore
-endfunction
-" vim:foldmethod=marker:foldcolumn=4
-
View
84 etc/vim/bundle/delimitMate/doc/delimitMate.txt
@@ -1,4 +1,4 @@
-*delimitMate.txt* Trying to keep those beasts at bay! v2.6 *delimitMate*
+*delimitMate.txt* Trying to keep those beasts at bay! v2.7 *delimitMate*
@@ -47,16 +47,12 @@ etc.; besides some other related features that should make your time in insert
mode a little bit easier.
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 break undo, redo or history.
+variables, or on a FileType basis, using autocommands.
NOTE 1: If you have any trouble with this plugin, please run |:DelimitMateTest|
in a new buffer to see what is not working.
-NOTE 2: |'timeout'| needs to be set when working in the terminal, otherwise you
-might find weird behaviour with mappings including <Esc> or arrow keys.
-
-NOTE 3: Abbreiations set with |:iabbrev| will not be expanded by delimiters
+NOTE 2: Abbreviations set with |:iabbrev| will not be expanded by delimiters
used on delimitMate, you should use <C-]> (read |i_CTRL-]|) to expand them on
the go.
@@ -91,6 +87,8 @@ specific file types, see |delimitMateOptionDetails| for examples.
|'delimitMate_expand_space'| Turns on/off the expansion of <Space>.
+|'delimitMate_jump_expansion'| Turns on/off jumping over expansions.
+
|'delimitMate_smart_quotes'| Turns on/off the "smart quotes" feature.
|'delimitMate_smart_matchpairs'| Turns on/off the "smart matchpairs" feature.
@@ -121,7 +119,7 @@ autocmd to modify delimitMate's behavior for specific file types, read more in
|delimitMateFileType|.
Note: Use buffer variables only to set options for specific file types using
-:autocmd, use global variables to set options for every buffer. Read more in
+:autocmd, use global variables to set options for all buffers. Read more in
|g:var| and |b:var|.
------------------------------------------------------------------------------
@@ -184,8 +182,10 @@ e.g.: >
Values: A list of quotes. ~
Default: [] ~
-Quotes listed here will not be able to jump out of the empty pair, thus
-allowing the autoclosed quotes to be nested.
+When adding a third quote listed in this option is inserted, three quotes will
+be inserted to the right of the cursor and the cursor will stay in the middle.
+If more quotes are inserted the number of quotes on both sides of the cursor
+will stay balanced.
e.g.: >
let delimitMate_nesting_quotes = ['"','`']
au FileType python let b:delimitMate_nesting_quotes = ['"']
@@ -215,6 +215,17 @@ e.g.: >
au FileType tcl let b:delimitMate_expand_space = 1
<
------------------------------------------------------------------------------
+ *'delimitMate_jump_expansion'*
+ *'b:delimitMate_jump_expansion'*
+Values: 1 or 0 ~
+Default: 0 ~
+This option turns on/off the jumping over <CR> and <Space> expansions when
+inserting closing matchpairs. Read |delimitMateExpansion| for details.
+e.g.: >
+ let delimitMate_jump_expansion = 1
+ au FileType tcl let b:delimitMate_jump_expansion = 1
+<
+------------------------------------------------------------------------------
*'delimitMate_smart_quotes'*
*'b:delimitMate_smart_quotes'*
Values: 1 or 0 ~
@@ -278,9 +289,9 @@ e.g.: >
Values: String. ~
Default: Empty. ~
-The contents of this string will be inserted after the closing matchpair when
-the opening matchapair is inserted at the end of the line. This feature only
-works if the eol marker was inserted on the current insert session.
+The contents of this string will be inserted after the closing matchpair or
+quote when the respective opening matchapair or quote is inserted at the end
+of the line.
e.g.: >
au FileType c,perl let b:delimitMate_eol_marker = ";"
<
@@ -412,11 +423,11 @@ e.g. typing at the "|": >
------------------------------------------------------------------------------
3.4 SMART QUOTES *delimitMateSmartQuotes*
-Only one quote will be inserted following a quote, a "\" or, following or
-preceding a keyword character. This should cover closing quotes after a
-string, opening quotes before a string, escaped quotes and apostrophes. Except
-for apostrophes, this feature can be disabled setting the option
-|'delimitMate_smart_quotes'| to 0.
+Only one quote will be inserted following a quote, a "\", following or
+preceding a keyword character, or when the number of quotes in the current
+line is odd. This should cover closing quotes after a string, opening quotes
+before a string, escaped quotes and apostrophes. Except for apostrophes, this
+feature can be disabled setting the option |'delimitMate_smart_quotes'| to 0.
e.g. typing at the "|": >
@@ -589,26 +600,12 @@ In order to make custom mappings easier and prevent overwritting existing
ones, delimitMate uses the |<Plug>| + |hasmapto()| (|usr_41.txt|) construct
for its mappings.
-These are the default mappings:
+These are the default mappings for the extra features:
<BS> is mapped to <Plug>delimitMateBS
<S-BS> is mapped to <Plug>delimitMateS-BS
<S-Tab> is mapped to <Plug>delimitMateS-Tab
<C-G>g is mapped to <Plug>delimitMateJumpMany
-<Del> is mapped to <Plug>delimitMateDel
-<Esc> is mapped to <Plug>delimitMateEsc
-<Left> is mapped to <Plug>delimitMateLeft
-<Right> is mapped to <Plug>delimitMateRight
-<Home> is mapped to <Plug>delimitMateHome
-<End> is mapped to <Plug>delimitMateEnd
-<Up> is mapped to <Plug>delimitMateUp
-<Down> is mapped to <Plug>delimitMateDown
-<PageUp> is mapped to <Plug>delimitMatePageUp
-<PageDown> is mapped to <Plug>delimitMatePageDown
-<S-Down> is mapped to <Plug>delimitMateS-Down
-<S-Up> is mapped to <Plug>delimitMateS-Up
-<LeftMouse> is mapped to <Plug>delimitMateMLeftMouse
-<RightMouse> is mapped to <Plug>delimitMateMRightMouse
The rest of the mappings correspond to parens, quotes, CR, Space, etc. and they
depend on the values of the delimitMate options, they have the following form:
@@ -622,9 +619,9 @@ e.g.: for "(":
e.g.: If you have <CR> expansion enabled, you might want to skip it on pop-up
menus:
- imap <expr> <CR> pumvisible() ?
- \"\<c-y>" :
- \ "<Plug>delimitMateCR"
+ imap <expr> <CR> pumvisible()
+ \ ? "\<C-Y>"
+ \ : "<Plug>delimitMateCR"
==============================================================================
@@ -648,13 +645,13 @@ Returns 1 if there is a closing delimiter or a quote to the right of the
cursor, 0 otherwise.
------------------------------------------------------------------------------
-delimitMate#JumpAny(key) *delimitMate#JumpAny()*
+delimitMate#JumpAny() *delimitMate#JumpAny()*
This function returns a mapping that will make the cursor jump to the right
when delimitMate#ShouldJump() returns 1, returns the argument "key" otherwise.
e.g.: You can use this to create your own mapping to jump over any delimiter.
>
- inoremap <C-Tab> <C-R>=delimitMate#JumpAny("\<C-Tab>")<CR>
+ inoremap <C-Tab> <C-R>=delimitMate#JumpAny()<CR>
<
==============================================================================
@@ -713,8 +710,15 @@ This script was inspired by the auto-completion of delimiters on TextMate.
Version Date Release notes ~
|---------|------------|-----------------------------------------------------|
- 2.6 2011-01-14 * Current release:
- - Add smart_matchpairs feature.
+ 2.7 2013-07-15 * Current release:
+ - Lots of bug fixes.
+ - Add delimitMate_offByDefault.
+ - Add delimitMate_eol_marker.
+ - Reduce the number of mappings.
+ - Stop using setline().
+ - Better handling of nested quotes.
+|---------|------------|-----------------------------------------------------|
+ 2.6 2011-01-14 * - Add smart_matchpairs feature.
- Add mapping to jump over contiguous delimiters.
- Fix behaviour of b:loaded_delimitMate.
|---------|------------|-----------------------------------------------------|
View
2 etc/vim/bundle/delimitMate/doc/tags
@@ -2,6 +2,7 @@
'b:delimitMate_balance_matchpairs' delimitMate.txt /*'b:delimitMate_balance_matchpairs'*
'b:delimitMate_expand_cr' delimitMate.txt /*'b:delimitMate_expand_cr'*
'b:delimitMate_expand_space' delimitMate.txt /*'b:delimitMate_expand_space'*
+'b:delimitMate_jump_expansion' delimitMate.txt /*'b:delimitMate_jump_expansion'*
'b:delimitMate_matchpairs' delimitMate.txt /*'b:delimitMate_matchpairs'*
'b:delimitMate_nesting_quotes' delimitMate.txt /*'b:delimitMate_nesting_quotes'*
'b:delimitMate_quotes' delimitMate.txt /*'b:delimitMate_quotes'*
@@ -16,6 +17,7 @@
'delimitMate_excluded_regions' delimitMate.txt /*'delimitMate_excluded_regions'*
'delimitMate_expand_cr' delimitMate.txt /*'delimitMate_expand_cr'*
'delimitMate_expand_space' delimitMate.txt /*'delimitMate_expand_space'*
+'delimitMate_jump_expansion' delimitMate.txt /*'delimitMate_jump_expansion'*
'delimitMate_matchpairs' delimitMate.txt /*'delimitMate_matchpairs'*
'delimitMate_nesting_quotes' delimitMate.txt /*'delimitMate_nesting_quotes'*
'delimitMate_offByDefault' delimitMate.txt /*'delimitMate_offByDefault'*
View
192 etc/vim/bundle/delimitMate/plugin/delimitMate.vim
@@ -1,6 +1,6 @@
" File: plugin/delimitMate.vim
-" Version: 2.6
-" Modified: 2011-01-14
+" Version: 2.7
+" Modified: 2013-07-15
" Description: This plugin provides auto-completion for quotes, parens, etc.
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
" Manual: Read ":help delimitMate".
@@ -29,25 +29,20 @@ if v:version < 700
endif
let s:loaded_delimitMate = 1
-let delimitMate_version = "2.6"
+let delimitMate_version = "2.7"
function! s:option_init(name, default) "{{{
let b = exists("b:delimitMate_" . a:name)
let g = exists("g:delimitMate_" . a:name)
- let prefix = "_l_delimitMate_"
-
+ " Find value to use.
if !b && !g
- let sufix = a:default
- elseif !b && g
- exec "let sufix = g:delimitMate_" . a:name
+ let value = a:default
+ elseif b
+ exec "let value = b:delimitMate_" . a:name
else
- exec "let sufix = b:delimitMate_" . a:name
- endif
- if exists("b:" . prefix . a:name)
- exec "unlockvar! b:" . prefix . a:name
+ exec "let value = g:delimitMate_" . a:name
endif
- exec "let b:" . prefix . a:name . " = " . string(sufix)
- exec "lockvar! b:" . prefix . a:name
+ call s:s(a:name, value)
endfunction "}}}
function! s:init() "{{{
@@ -58,21 +53,21 @@ function! s:init() "{{{
" matchpairs
call s:option_init("matchpairs", string(&matchpairs)[1:-2])
- call s:option_init("matchpairs_list", map(split(b:_l_delimitMate_matchpairs, ','), 'split(v:val, '':'')'))
- call s:option_init("left_delims", map(copy(b:_l_delimitMate_matchpairs_list), 'v:val[0]'))
- call s:option_init("right_delims", map(copy(b:_l_delimitMate_matchpairs_list), 'v:val[1]'))
+ call s:option_init("matchpairs_list", map(split(s:g('matchpairs'), ','), 'split(v:val, '':'')'))
+ call s:option_init("left_delims", map(copy(s:g('matchpairs_list')), 'v:val[0]'))
+ call s:option_init("right_delims", map(copy(s:g('matchpairs_list')), 'v:val[1]'))
" quotes
call s:option_init("quotes", "\" ' `")
- call s:option_init("quotes_list", split(b:_l_delimitMate_quotes))
+ call s:option_init("quotes_list",split(s:g('quotes'), '\s\+'))
" nesting_quotes
call s:option_init("nesting_quotes", [])
" excluded_regions
call s:option_init("excluded_regions", "Comment")
- call s:option_init("excluded_regions_list", split(b:_l_delimitMate_excluded_regions, ',\s*'))
- let enabled = len(b:_l_delimitMate_excluded_regions_list) > 0
+ call s:option_init("excluded_regions_list", split(s:g('excluded_regions'), ',\s*'))
+ let enabled = len(s:g('excluded_regions_list')) > 0
call s:option_init("excluded_regions_enabled", enabled)
" excluded filetypes
@@ -113,6 +108,9 @@ function! s:init() "{{{
endif
call s:option_init("expand_cr", 0)
+ " jump_expansion
+ call s:option_init("jump_expansion", 0)
+
" smart_matchpairs
call s:option_init("smart_matchpairs", '^\%(\w\|\!\|£\|\$\|_\|["'']\s*\S\)')
@@ -121,7 +119,7 @@ function! s:init() "{{{
" apostrophes
call s:option_init("apostrophes", "")
- call s:option_init("apostrophes_list", split(b:_l_delimitMate_apostrophes, ":\s*"))
+ call s:option_init("apostrophes_list", split(s:g('apostrophes'), ":\s*"))
" tab2exit
call s:option_init("tab2exit", 1)
@@ -132,7 +130,7 @@ function! s:init() "{{{
" eol marker
call s:option_init("eol_marker", "")
- let b:_l_delimitMate_buffer = []
+ call s:s('buffer', [])
endfunction "}}} Init()
@@ -140,6 +138,14 @@ endfunction "}}} Init()
" Functions: {{{
+function! s:g(...) " {{{
+ return call('delimitMate#Get', a:000)
+endfunction " }}}
+
+function! s:s(...) " {{{
+ return call('delimitMate#Set', a:000)
+endfunction " }}}
+
function! s:Map() "{{{
" Set mappings:
try
@@ -149,7 +155,7 @@ function! s:Map() "{{{
let save_cpo = &cpo
set keymap=
set cpo&vim
- if b:_l_delimitMate_autoclose
+ if s:g('autoclose')
call s:AutoClose()
else
call s:NoAutoClose()
@@ -168,10 +174,10 @@ endfunction "}}} Map()
function! s:Unmap() " {{{
let imaps =
- \ b:_l_delimitMate_right_delims +
- \ b:_l_delimitMate_left_delims +
- \ b:_l_delimitMate_quotes_list +
- \ b:_l_delimitMate_apostrophes_list +
+ \ s:g('right_delims') +
+ \ s:g('left_delims') +
+ \ s:g('quotes_list') +
+ \ s:g('apostrophes_list') +
\ ['<BS>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
\ ['<C-Left>', '<C-Right>'] +
@@ -185,39 +191,20 @@ function! s:Unmap() " {{{
exec 'silent! iunmap <buffer> ' . map
endif
endfor
-
- if !has('gui_running')
- silent! iunmap <C-[>OC
- endif
-
let b:delimitMate_enabled = 0
endfunction " }}} s:Unmap()
function! s:TestMappingsDo() "{{{
- %d
- if !exists("g:delimitMate_testing")
- call delimitMate#TestMappings()
- else
- let temp_varsDM = [b:_l_delimitMate_expand_space, b:_l_delimitMate_expand_cr, b:_l_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 s:Unmap()
- call s:Map()
- call delimitMate#TestMappings()
- call append(line('$'),'')
- 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
+ if &modified
+ let confirm = input("Modified buffer, type \"yes\" to write and proceed "
+ \ . "with test: ") ==? 'yes'
+ if !confirm
+ return
+ endif
endif
- normal gg
+ call delimitMate#TestMappings()
g/\%^$/d
+ 0
endfunction "}}}
function! s:DelimitMateDo(...) "{{{
@@ -265,30 +252,12 @@ 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(b:_l_delimitMate_buffer)
-endfunction
-
"}}}
" Mappers: {{{
function! s:NoAutoClose() "{{{
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
- for delim in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
+ for delim in s:g('right_delims') + s:g('quotes_list')
if delim == '|'
let delim = '<Bar>'
endif
@@ -301,23 +270,23 @@ function! s:AutoClose() "{{{
" Add matching pair and jump to the midle:
" inoremap <silent> <buffer> ( ()<Left>
let i = 0
- while i < len(b:_l_delimitMate_matchpairs_list)
- let ld = b:_l_delimitMate_left_delims[i] == '|' ? '<bar>' : b:_l_delimitMate_left_delims[i]
- let rd = b:_l_delimitMate_right_delims[i] == '|' ? '<bar>' : b:_l_delimitMate_right_delims[i]
- exec 'inoremap <silent> <Plug>delimitMate' . ld . ' ' . ld . '<C-R>=delimitMate#ParenDelim("' . escape(rd, '|') . '")<CR>'
+ while i < len(s:g('matchpairs_list'))
+ let ld = s:g('left_delims')[i] == '|' ? '<bar>' : s:g('left_delims')[i]
+ let rd = s:g('right_delims')[i] == '|' ? '<bar>' : s:g('right_delims')[i]
+ exec 'inoremap <silent> <Plug>delimitMate' . ld . ' <C-R>=delimitMate#ParenDelim("' . escape(rd, '|') . '")<CR>'
exec 'silent! imap <unique> <buffer> '.ld.' <Plug>delimitMate'.ld
let i += 1
endwhile
" Exit from inside the matching pair:
- for delim in b:_l_delimitMate_right_delims
+ for delim in s:g('right_delims')
exec 'inoremap <silent> <Plug>delimitMate' . delim . ' <C-R>=delimitMate#JumpOut("\' . delim . '")<CR>'
exec 'silent! imap <unique> <buffer> ' . delim . ' <Plug>delimitMate'. delim
endfor
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
" inoremap <silent> <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
- for delim in b:_l_delimitMate_quotes_list
+ for delim in s:g('quotes_list')
if delim == '|'
let delim = '<Bar>'
endif
@@ -327,7 +296,7 @@ function! s:AutoClose() "{{{
" Try to fix the use of apostrophes (kept for backward compatibility):
" inoremap <silent> <buffer> n't n't
- for map in b:_l_delimitMate_apostrophes_list
+ for map in s:g('apostrophes_list')
exec "inoremap <silent> " . map . " " . map
exec 'silent! imap <unique> <buffer> ' . map . ' <Plug>delimitMate' . map
endfor
@@ -335,73 +304,32 @@ endfunction "}}}
function! s:ExtraMappings() "{{{
" If pair is empty, delete both delimiters:
- inoremap <silent><expr> <Plug>delimitMateBS delimitMate#WithinEmptyPair() ? "\<C-R>=delimitMate#BS()\<CR>" : "\<BS>"
+ inoremap <silent> <Plug>delimitMateBS <C-R>=delimitMate#BS()<CR>
if !hasmapto('<Plug>delimitMateBS','i') && maparg('<BS>'. 'i') == ''
silent! imap <unique> <buffer> <BS> <Plug>delimitMateBS
endif
" If pair is empty, delete closing delimiter:
- inoremap <silent> <expr> <Plug>delimitMateS-BS delimitMate#WithinEmptyPair() ? "\<C-R>=delimitMate#Del()\<CR>" : "\<S-BS>"
+ inoremap <silent> <expr> <Plug>delimitMateS-BS delimitMate#WithinEmptyPair() ? "\<Del>" : "\<S-BS>"
if !hasmapto('<Plug>delimitMateS-BS','i') && maparg('<S-BS>', 'i') == ''
silent! imap <unique> <buffer> <S-BS> <Plug>delimitMateS-BS
endif
" Expand return if inside an empty pair:
inoremap <silent> <Plug>delimitMateCR <C-R>=delimitMate#ExpandReturn()<CR>
- if b:_l_delimitMate_expand_cr != 0 && !hasmapto('<Plug>delimitMateCR', 'i') && maparg('<CR>', 'i') == ''
+ if s:g('expand_cr') && !hasmapto('<Plug>delimitMateCR', 'i') && maparg('<CR>', 'i') == ''
silent! imap <unique> <buffer> <CR> <Plug>delimitMateCR
endif
" Expand space if inside an empty pair:
inoremap <silent> <Plug>delimitMateSpace <C-R>=delimitMate#ExpandSpace()<CR>
- if b:_l_delimitMate_expand_space != 0 && !hasmapto('<Plug>delimitMateSpace', 'i') && maparg('<Space>', 'i') == ''
+ if s:g('expand_space') && !hasmapto('<Plug>delimitMateSpace', 'i') && maparg('<Space>', 'i') == ''
silent! imap <unique> <buffer> <Space> <Plug>delimitMateSpace
endif
" Jump over any delimiter:
- inoremap <silent> <Plug>delimitMateS-Tab <C-R>=delimitMate#JumpAny("\<S-Tab>")<CR>
- if b:_l_delimitMate_tab2exit && !hasmapto('<Plug>delimitMateS-Tab', 'i') && maparg('<S-Tab>', 'i') == ''
+ inoremap <silent> <Plug>delimitMateS-Tab <C-R>=delimitMate#JumpAny()<CR>
+ if s:g('tab2exit') && !hasmapto('<Plug>delimitMateS-Tab', 'i') && maparg('<S-Tab>', 'i') == ''
silent! imap <unique> <buffer> <S-Tab> <Plug>delimitMateS-Tab
endif
- " Change char buffer on Del:
- inoremap <silent> <Plug>delimitMateDel <C-R>=delimitMate#Del()<CR>
- if !hasmapto('<Plug>delimitMateDel', 'i') && maparg('<Del>', 'i') == ''
- silent! imap <unique> <buffer> <Del> <Plug>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 <silent><expr> <Plug>delimitMate'.map.' !<SID>empty_buffer() ? "<C-R>=delimitMate#Finish(1)<CR><'.map.'>" : "<'.map.'>"'
- if !hasmapto('<Plug>delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == ''
- exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>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 <silent> <Plug>delimitMate'.key.' <C-R>=<SID>Finish()<CR><'.map.'>'
- if mapcheck('<'.key.'>', 'i') == '<'.map.'>'
- exec 'silent! imap <buffer> <'.key.'> <Plug>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 <silent> <expr> <Plug>delimitMate'.map.' pumvisible() \|\| <SID>empty_buffer() ? "\<'.map.'>" : "\<C-R>=\<SID>Finish()\<CR>\<'.map.'>"'
- if !hasmapto('<Plug>delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == ''
- exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMate'.map
- endif
- endfor
- " Avoid ambiguous mappings:
- for map in ['LeftMouse', 'RightMouse']
- exec 'inoremap <silent> <Plug>delimitMateM'.map.' <C-R>=delimitMate#Finish(1)<CR><'.map.'>'
- if !hasmapto('<Plug>delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == ''
- exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMateM'.map
- endif
- endfor
-
" Jump over next delimiters
- inoremap <buffer> <Plug>delimitMateJumpMany <C-R>=len(b:_l_delimitMate_buffer) ? delimitMate#Finish(0) : delimitMate#JumpMany()<CR>
+ inoremap <buffer> <Plug>delimitMateJumpMany <C-R>=delimitMate#JumpMany()<CR>
if !hasmapto('<Plug>delimitMateJumpMany', 'i') && maparg("<C-G>g", 'i') == ''
imap <silent> <buffer> <C-G>g <Plug>delimitMateJumpMany
endif
@@ -437,14 +365,6 @@ augroup delimitMate
\ call <SID>DelimitMateDo() |
\ let b:delimitMate_was_here = 1 |
\ endif
-
- " Flush the char buffer:
- autocmd InsertEnter * call <SID>FlushBuffer()
- autocmd BufEnter *
- \ if mode() == 'i' |
- \ call <SID>FlushBuffer() |
- \ endif
-
augroup END
"}}}
View
1 etc/vim/bundle/delimitMate/test/_setup.vim
@@ -1,2 +1,3 @@
let &rtp = expand('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after'
+set bs=2
ru plugin/delimitMate.vim
View
5 etc/vim/bundle/delimitMate/test/autoclose_matchpairs.txt
@@ -24,6 +24,9 @@ let g:delimitMate_autoclose = 1
# Handle backspace gracefully.
set backspace=
"(\<Esc>a\<BS>x" "(x)"
+set bs=2
+# closing parens removes characters. #133
+"(a\<Esc>i)" "()a)"
# Add semicolon next to the closing paren. Issue #77.
new
@@ -31,4 +34,4 @@ let b:delimitMate_eol_marker = ';'
"abc(x" "abc(x);"
%d
# BS should behave accordingly.
-"abc(\<BS>" "abc"
+"abc(\<BS>" "abc;"
View
5 etc/vim/bundle/delimitMate/test/autoclose_matchpairs.vim
@@ -33,8 +33,9 @@ for item in lines
exec 'normal i'.eval(input2)."\<Esc>"
let line = getline('.')
let passed = line == eval(output2)
- call vimtap#Ok(passed, input2 . ' => ' . string(line) .
- \ (passed ? ' =' : ' !') . '= ' . string(eval(output2)))
+ call vimtap#Is(line, eval(output2), input2)
+ ", input2 . ' => ' . string(line) .
+ " \ (passed ? ' =' : ' !') . '= ' . string(eval(output2)))
let tcount += 1
endfor
endfor
View
12 etc/vim/bundle/delimitMate/test/autoclose_quotes.txt
@@ -30,9 +30,21 @@ let g:delimitMate_autoclose = 1
# Handle backspace gracefully.
set backspace=
"'\<Esc>a\<BS>x" "'x'"
+set backspace=2
set cpo=ces$
"'x" "'x'"
# Make sure smart quote works beyond first column.
" 'x" " 'x'"
# Make sure we jump over a quote on the right. #89.
"('test'x" "('test'x)"
+# Duplicate whole line when inserting quote at bol #105
+"}\<Home>'" "''}"
+"'\<Del>abc '" "'abc '"
+"''abc '" "''abc ''"
+# Nesting quotes:
+let g:delimitMate_nesting_quotes = split(g:delimitMate_quotes, '\s\+')
+"'''x" "'''x'''"
+"''''x" "''''x''''"
+"''x" "''x"
+"'x" "'x'"
+unlet g:delimitMate_nesting_quotes
View
6 etc/vim/bundle/delimitMate/test/expand_cr.txt
@@ -12,6 +12,8 @@ $(document).ready(function() {
--------------------------------------------------------------------------------
# Issue #95
new
+let b:delimitMate_jump_expansion = 1
+DelimitMateReload
exec "normal i(\<CR>test)x"
================================================================================
(
@@ -43,10 +45,10 @@ sub foo {
}
--------------------------------------------------------------------------------
%d
-call setline(1, "\"{bracketed}")
+call setline(1, '"{bracketed}')
normal A"x
================================================================================
-"{bracketed""x
+"{bracketed}"x
--------------------------------------------------------------------------------
# Syntax folding enabled by autocmd breaks expansion. But ti can't be tested
# with :normal
View
23 etc/vim/bundle/delimitMate/test/expand_cr.vim
@@ -7,6 +7,8 @@ call vimtap#Plan(testsnumber)
let tcount = 1
let expect = 0
let evaluate = 0
+let commands = []
+let header = ''
for item in lines
if item =~ '^=\{80}$'
let expect = 1
@@ -14,14 +16,20 @@ for item in lines
continue
endif
- if item =~ '^#\|^\s*$' && expect == 0
- " A comment or empty line.
+ if item =~ '^#' && expect == 0
+ " A comment.
+ let header = empty(header) ? item[1:] : 'Lines should match.'
+ continue
+ endif
+ if item =~ '^\s*$' && expect == 0
+ " An empty line.
continue
endif
if ! expect
" A command.
+ call add(commands, item)
exec item
- call vimtap#Diag(item)
+ "call vimtap#Diag(item)
continue
endif
if item =~ '^-\{80}$'
@@ -35,8 +43,13 @@ for item in lines
let passed = lines == expected
echom string(lines)
echom string(expected)
- call vimtap#Ok(passed, string(expected) .
- \ (passed ? ' =' : ' !') . '= ' . string(lines))
+ call vimtap#Is(lines, expected, header)
+ echom string(commands)
+ for cmd in commands
+ call vimtap#Diag(cmd)
+ endfor
+ let commands = []
+ let header = ''
let tcount += 1
endfor
call vimtest#Quit()
View
2 etc/vim/bundle/delimitMate/test/expand_space.txt
@@ -1,5 +1,7 @@
# Issue #95
new
+let b:delimitMate_jump_expansion = 1
+DelimitMateReload
exec "normal i( test)x"
================================================================================
( test )x

0 comments on commit 233aca0

Please sign in to comment.
Something went wrong with that request. Please try again.