34 Commits

Author SHA1 Message Date
Israel Chauca Fuentes
22e6272b1a Migrate testing to tcltest + expect 2017-04-12 15:58:49 -04:00
Israel Chauca Fuentes
c4d51a21b3 Refactor pairs handling 2017-04-01 18:14:12 -04:00
Israel Chauca Fuentes
9ec998e87a Rewrite s:keys4right() 2017-03-20 22:49:37 -04:00
Israel Chauca Fuentes
0246f25de8 Some cleanup 2017-03-15 03:11:38 -04:00
Israel Chauca Fuentes
1eafd59b9c Quick fixes 2017-02-21 22:11:52 -05:00
Israel Chauca Fuentes
4eaeef01bf Fix problem with jumping over an existing closing delimiter. 2017-02-21 22:11:27 -05:00
Israel Chauca Fuentes
fb60f3cc9f Try to avoid breaking redo. 2017-02-21 22:09:40 -05:00
Israel Chauca Fuentes
e362f5a69d Add jump_over. Close #220. 2017-02-14 14:59:19 -05:00
Israel Chauca Fuentes
c97a824ed4 Do not jump over next delimiter when unbalanced pairs. Close #229. 2017-02-14 14:59:18 -05:00
Israel Chauca Fuentes
37122299b7 Add license. Close #247. 2017-02-14 14:59:17 -05:00
Israel Chauca Fuentes
d882e342f7 Add :DMDebug 2017-02-14 14:59:08 -05:00
Israel Chauca Fuentes
b1ff7f7942 Simplify expand_cr a bit and add some to do tests 2017-02-13 12:12:12 -05:00
Israel Chauca Fuentes
e48ea9f852 Allow jumping over quote on the right if in ignored syntax group 2017-02-12 23:48:13 -05:00
Israel Chauca Fuentes
cb6866f1c3 Improve smart rules 2017-02-11 22:38:51 -05:00
Israel Chauca Fuentes
8204ab4cb8 Better handling of syntax regions 2017-02-11 22:38:13 -05:00
Israel Chauca Fuentes
6f038350de Reorder some tests and add modelines everywhere 2017-02-11 20:07:40 -05:00
Israel Chauca Fuentes
0f6581c6f3 Add insert_eol_marker 2017-02-11 19:13:09 -05:00
Israel Chauca Fuentes
7752546515 Add jump_expansion 2017-02-11 17:55:03 -05:00
Israel Chauca Fuentes
7809c5e171 Add expand_cr 2017-02-11 11:11:17 -05:00
Israel Chauca Fuentes
b6cc751cc9 Rename some things. 2017-02-10 22:59:22 -05:00
Israel Chauca Fuentes
24cffe07b3 Consider that double quotes start comments in viml 2017-02-10 21:13:45 -05:00
Israel Chauca Fuentes
6fddbc5568 Add jump_expansion 2017-02-10 19:55:02 -05:00
Israel Chauca Fuentes
015e0efe53 Add expand_inside_quotes and fix a nesting problem. 2017-02-10 14:25:52 -05:00
Israel Chauca Fuentes
03a0e5d8b3 Simplify the format of the tests. 2017-02-10 00:32:17 -05:00
Israel Chauca Fuentes
d970ecc4ca Prevent recursive nesting of quotes in tests. 2017-02-10 00:30:23 -05:00
Israel Chauca Fuentes
353fb9a718 Sort things a bit. 2017-02-10 00:29:30 -05:00
Israel Chauca Fuentes
4d0060f22b Add support for quotes and a couple of other things. 2017-02-09 12:59:33 -05:00
Israel Chauca Fuentes
65016ebe37 Implement balance_pairs 2017-02-07 00:52:01 -05:00
Israel Chauca Fuentes
85d76972e6 Implement smart pairs. 2017-02-06 00:28:48 -05:00
Israel Chauca Fuentes
c4b5877958 Allow abbreviations to expand. 2017-02-06 00:25:44 -05:00
Israel Chauca Fuentes
2335c4ae27 Simplify makefiles. 2017-02-04 20:19:16 -05:00
Israel Chauca Fuentes
6f1a9d00af Implement autoclosingpairs. 2017-02-04 20:12:21 -05:00
Israel Chauca Fuentes
b99ecfa2e3 Simplify tests. 2017-01-23 20:40:55 -05:00
Israel Chauca Fuentes
50d97fd76e Simplify pattern 2015-09-11 09:18:12 -04:00
24 changed files with 1240 additions and 1594 deletions

21
LICENSE.txt Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Israel Chauca
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,81 +1,15 @@
PLUGIN = $(wildcard plugin/*.vim) .DEFAULT: test
SOURCES = $(PLUGIN)
LIB = $(wildcard autoload/*.vim)
SOURCES += $(LIB)
DOC = $(wildcard doc/*.txt)
SOURCES += $(DOC)
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 = $(shell command -v gsed || command -v sed)
PERL = perl
comma := ,
empty :=
space := $(empty) $(empty)
.PHONY: version clean distclean undo release test install uninstall test_files := $(wildcard test/*.test)
short_targets := $(patsubst test/%,%,$(test_files))
all: zip gzip .PHONY: monitor test $(test_files) $(short_targets)
dist: version all
vimball: $(FILENAME).vmb
zip: $(FILENAME).zip $(FILENAME).vmb.zip
gzip: $(FILENAME).tar.gz $(FILENAME).vmb.gz
clean:
rm -f */*.orig *.~* .VimballRecord *.zip *.gz *.vmb
distclean: clean
-zsh -c 'setopt extendedglob; rm -f ^(README.md|Makefile|basic_vimrc)(.)'
-zsh -c 'setopt extendedglob; rm -f .^(git|README.md|Makefile|basic_vimrc)*'
undo:
for i in */*.orig; do mv -f "$$i" "$${i%.*}"; done
version:
$(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: test:
$(MAKE) -C test $(MAKE) -C test
install: $(SOURCES) monitor:
for dir in $(^D);\ $(MAKE) -C test monitor
do install -d -m 0755 $(DESTDIR)$(PREFIX)/$$dir;\
done;\
for file in $^;\
do install -m 0644 $$file $(DESTDIR)$(PREFIX)/$$file;\
done;
uninstall: $(test_files) $(short_targets):
for file in $(SOURCES);\ $(MAKE) -C test $(patsubst test/%,%,$@)
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

File diff suppressed because it is too large Load Diff

View File

@@ -1,402 +1,22 @@
" File: plugin/delimitMate.vim if exists("g:loaded_delimitMate") || &cp || !exists('##InsertCharPre')
" 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".
" ============================================================================
" Initialization: {{{
if exists("g:loaded_delimitMate") || &cp
" User doesn't want this plugin or compatible is set, let's get out!
finish finish
endif endif
let g:loaded_delimitMate = 1 let g:loaded_delimitMate = 1
let save_cpo = &cpo let save_cpo = &cpo
set cpo&vim set cpo&vim
if v:version < 700 command! -bar -bang DelimitMateSwitch call delimitMate#ex_cmd(<bang>0, 'switch' )
echoerr "delimitMate: this plugin requires vim >= 7!" command! -bar -bang DelimitMateOn call delimitMate#ex_cmd(<bang>0, 'enable' )
finish command! -bar -bang DelimitMateOff call delimitMate#ex_cmd(<bang>0, 'disable')
endif
let s:loaded_delimitMate = 1
let delimitMate_version = "2.8"
"}}}
" Functions: {{{
function! s:option_init(name, default) "{{{
let b = exists("b:delimitMate_" . a:name)
let g = exists("g:delimitMate_" . a:name)
" Find value to use.
if !b && !g
let value = a:default
elseif b
exec "let value = b:delimitMate_" . a:name
else
exec "let value = g:delimitMate_" . a:name
endif
call s:set(a:name, value)
endfunction "}}}
function! s:init() "{{{
" Initialize variables:
" autoclose
call s:option_init("autoclose", 1)
" matchpairs
call s:option_init("matchpairs", string(&matchpairs)[1:-2])
call s:option_init("matchpairs_list", map(split(s:get('matchpairs'), '.:.\zs,\ze.:.'), 'split(v:val, ''^.\zs:\ze.$'')'))
let pairs = s:get('matchpairs_list')
if len(filter(pairs, 'v:val[0] ==# v:val[1]'))
echohl ErrorMsg
echom 'delimitMate: each member of a pair in delimitMate_matchpairs must be different from each other.'
echom 'delimitMate: invalid pairs: ' . join(map(pairs, 'join(v:val, ":")'), ', ')
echohl Normal
return 0
endif
call s:option_init("left_delims", map(copy(s:get('matchpairs_list')), 'v:val[0]'))
call s:option_init("right_delims", map(copy(s:get('matchpairs_list')), 'v:val[1]'))
" quotes
call s:option_init("quotes", "\" ' `")
call s:option_init("quotes_list",split(s:get('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(s:get('excluded_regions'), ',\s*'))
let enabled = len(s:get('excluded_regions_list')) > 0
call s:option_init("excluded_regions_enabled", enabled)
" expand_space
if exists("b:delimitMate_expand_space") && type(b:delimitMate_expand_space) == type("")
echom "b:delimitMate_expand_space is '".b:delimitMate_expand_space."' but it must be either 1 or 0!"
echom "Read :help 'delimitMate_expand_space' for more details."
unlet b:delimitMate_expand_space
let b:delimitMate_expand_space = 1
endif
if exists("g:delimitMate_expand_space") && type(g:delimitMate_expand_space) == type("")
echom "delimitMate_expand_space is '".g:delimitMate_expand_space."' but it must be either 1 or 0!"
echom "Read :help 'delimitMate_expand_space' for more details."
unlet g:delimitMate_expand_space
let g:delimitMate_expand_space = 1
endif
call s:option_init("expand_space", 0)
" expand_cr
if exists("b:delimitMate_expand_cr") && type(b:delimitMate_expand_cr) == type("")
echom "b:delimitMate_expand_cr is '".b:delimitMate_expand_cr."' but it must be either 1 or 0!"
echom "Read :help 'delimitMate_expand_cr' for more details."
unlet b:delimitMate_expand_cr
let b:delimitMate_expand_cr = 1
endif
if exists("g:delimitMate_expand_cr") && type(g:delimitMate_expand_cr) == type("")
echom "delimitMate_expand_cr is '".g:delimitMate_expand_cr."' but it must be either 1 or 0!"
echom "Read :help 'delimitMate_expand_cr' for more details."
unlet g:delimitMate_expand_cr
let g:delimitMate_expand_cr = 1
endif
if ((&backspace !~ 'eol' || &backspace !~ 'start') && &backspace != 2) &&
\ ((exists('b:delimitMate_expand_cr') && b:delimitMate_expand_cr == 1) ||
\ (exists('g:delimitMate_expand_cr') && g:delimitMate_expand_cr == 1))
echom "delimitMate: There seems to be some incompatibility with your settings that may interfer with the expansion of <CR>. See :help 'delimitMate_expand_cr' for details."
endif
call s:option_init("expand_cr", 0)
" expand_in_quotes
call s:option_init('expand_inside_quotes', 0)
" jump_expansion
call s:option_init("jump_expansion", 0)
" smart_matchpairs
call s:option_init("smart_matchpairs", '^\%(\w\|\!\|[£$]\|[^[:punct:][:space:]]\)')
" smart_quotes
" XXX: backward compatibility. Ugly, should go the way of the dodo soon.
let quotes = escape(join(s:get('quotes_list'), ''), '\-^[]')
let default_smart_quotes = '\%(\w\|[^[:punct:][:space:]' . quotes . ']\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[^[:space:][:punct:]' . quotes . ']\)'
if exists('g:delimitMate_smart_quotes') && type(g:delimitMate_smart_quotes) == type(0)
if g:delimitMate_smart_quotes
unlet g:delimitMate_smart_quotes
else
unlet g:delimitMate_smart_quotes
let g:delimitMate_smart_quotes = ''
endif
endif
if exists('b:delimitMate_smart_quotes') && type(b:delimitMate_smart_quotes) == type(0)
if b:delimitMate_smart_quotes
unlet b:delimitMate_smart_quotes
if exists('g:delimitMate_smart_quotes') && type(g:delimitMate_smart_quotes) && g:delimitMate_smart_quotes
let b:delimitMate_smart_quotes = default_smart_quotes
endif
else
unlet b:delimitMate_smart_quotes
let b:delimitMate_smart_quotes = ''
endif
endif
call s:option_init("smart_quotes", default_smart_quotes)
" apostrophes
call s:option_init("apostrophes", "")
call s:option_init("apostrophes_list", split(s:get('apostrophes'), ":\s*"))
" tab2exit
call s:option_init("tab2exit", 1)
" balance_matchpairs
call s:option_init("balance_matchpairs", 0)
" eol marker
call s:option_init("insert_eol_marker", 1)
call s:option_init("eol_marker", "")
" Everything is fine.
return 1
endfunction "}}} Init()
function! s:get(...) " {{{
return call('delimitMate#Get', a:000)
endfunction " }}}
function! s:set(...) " {{{
return call('delimitMate#Set', a:000)
endfunction " }}}
function! s:Map() "{{{
" Set mappings:
try
let save_keymap = &keymap
let save_iminsert = &iminsert
let save_imsearch = &imsearch
let save_cpo = &cpo
set keymap=
set cpo&vim
silent! doautocmd <nomodeline> User delimitMate_map
if s:get('autoclose')
call s:AutoClose()
else
call s:NoAutoClose()
endif
call s:ExtraMappings()
finally
let &cpo = save_cpo
let &keymap = save_keymap
let &iminsert = save_iminsert
let &imsearch = save_imsearch
endtry
let b:delimitMate_enabled = 1
endfunction "}}} Map()
function! s:Unmap() " {{{
let imaps =
\ s:get('right_delims', []) +
\ s:get('left_delims', []) +
\ s:get('quotes_list', []) +
\ s:get('apostrophes_list', []) +
\ ['<BS>', '<C-h>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
\ ['<C-Left>', '<C-Right>'] +
\ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>', '<C-G>g']
for map in imaps
if maparg(map, "i") =~# '^<Plug>delimitMate'
if map == '|'
let map = '<Bar>'
endif
exec 'silent! iunmap <buffer> ' . map
endif
endfor
silent! doautocmd <nomodeline> User delimitMate_unmap
let b:delimitMate_enabled = 0
endfunction " }}} s:Unmap()
function! s:test() "{{{
if &modified
let confirm = input("Modified buffer, type \"yes\" to write and proceed "
\ . "with test: ") ==? 'yes'
if !confirm
return
endif
endif
call delimitMate#Test()
g/\%^$/d
0
endfunction "}}}
function! s:setup(...) "{{{
let swap = a:0 && a:1 == 2
let enable = a:0 && a:1
let disable = a:0 && !a:1
" First, remove all magic, if needed:
if get(b:, 'delimitMate_enabled', 0)
call s:Unmap()
" Switch
if swap
echo "delimitMate is disabled."
return
endif
endif
if disable
" Just disable the mappings.
return
endif
if !a:0
" Check if this file type is excluded:
if exists("g:delimitMate_excluded_ft") &&
\ index(split(g:delimitMate_excluded_ft, ','), &filetype, 0, 1) >= 0
" Finish here:
return 1
endif
" Check if user tried to disable using b:loaded_delimitMate
if exists("b:loaded_delimitMate")
return 1
endif
endif
" Initialize settings:
if ! s:init()
" Something went wrong.
return
endif
if enable || swap || !get(g:, 'delimitMate_offByDefault', 0)
" Now, add magic:
call s:Map()
if a:0
echo "delimitMate is enabled."
endif
endif
endfunction "}}}
function! s:TriggerAbb() "{{{
if v:version < 703
\ || ( v:version == 703 && !has('patch489') )
\ || pumvisible()
return ''
endif
return "\<C-]>"
endfunction "}}}
function! s:NoAutoClose() "{{{
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
for delim in s:get('right_delims') + s:get('quotes_list')
if delim == '|'
let delim = '<Bar>'
endif
exec 'inoremap <silent> <Plug>delimitMate' . delim . ' <C-R>=<SID>TriggerAbb().delimitMate#SkipDelim("' . escape(delim,'"') . '")<CR>'
exec 'silent! imap <unique> <buffer> '.delim.' <Plug>delimitMate'.delim
endfor
endfunction "}}}
function! s:AutoClose() "{{{
" Add matching pair and jump to the midle:
" inoremap <silent> <buffer> ( ()<Left>
let i = 0
while i < len(s:get('matchpairs_list'))
let ld = s:get('left_delims')[i] == '|' ? '<bar>' : s:get('left_delims')[i]
let rd = s:get('right_delims')[i] == '|' ? '<bar>' : s:get('right_delims')[i]
exec 'inoremap <expr><silent> <Plug>delimitMate' . ld
\. ' <SID>TriggerAbb().delimitMate#ParenDelim("' . escape(rd, '|') . '")'
exec 'silent! imap <unique> <buffer> '.ld
\.' <Plug>delimitMate'.ld
let i += 1
endwhile
" Exit from inside the matching pair:
for delim in s:get('right_delims')
let delim = delim == '|' ? '<bar>' : delim
exec 'inoremap <expr><silent> <Plug>delimitMate' . delim
\. ' <SID>TriggerAbb().delimitMate#JumpOut("\' . delim . '")'
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 s:get('quotes_list')
if delim == '|'
let delim = '<Bar>'
endif
exec 'inoremap <expr><silent> <Plug>delimitMate' . delim
\. ' <SID>TriggerAbb()."<C-R>=delimitMate#QuoteDelim(\"\\\' . delim . '\")<CR>"'
exec 'silent! imap <unique> <buffer> ' . delim
\. ' <Plug>delimitMate' . delim
endfor
" Try to fix the use of apostrophes (kept for backward compatibility):
" inoremap <silent> <buffer> n't n't
for map in s:get('apostrophes_list')
exec "inoremap <silent> " . map . " " . map
exec 'silent! imap <unique> <buffer> ' . map . ' <Plug>delimitMate' . map
endfor
endfunction "}}}
function! s:ExtraMappings() "{{{
" If pair is empty, delete both delimiters:
inoremap <silent> <Plug>delimitMateBS <C-R>=delimitMate#BS()<CR>
if !hasmapto('<Plug>delimitMateBS','i')
if empty(maparg('<BS>', 'i'))
silent! imap <unique> <buffer> <BS> <Plug>delimitMateBS
endif
if empty(maparg('<C-H>', 'i'))
silent! imap <unique> <buffer> <C-h> <Plug>delimitMateBS
endif
endif
" If pair is empty, delete closing delimiter:
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 <expr><silent> <Plug>delimitMateCR <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandReturn()\<CR>"
if s:get('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 <expr><silent> <Plug>delimitMateSpace <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandSpace()\<CR>"
if s:get('expand_space') && !hasmapto('<Plug>delimitMateSpace', 'i') && maparg('<Space>', 'i') == ''
silent! imap <unique> <buffer> <Space> <Plug>delimitMateSpace
endif
" Jump over any delimiter:
inoremap <expr><silent> <Plug>delimitMateS-Tab <SID>TriggerAbb()."\<C-R>=delimitMate#JumpAny()\<CR>"
if s:get('tab2exit') && !hasmapto('<Plug>delimitMateS-Tab', 'i') && maparg('<S-Tab>', 'i') == ''
silent! imap <unique> <buffer> <S-Tab> <Plug>delimitMateS-Tab
endif
" Jump over next delimiters
inoremap <expr><buffer> <Plug>delimitMateJumpMany <SID>TriggerAbb()."\<C-R>=delimitMate#JumpMany()\<CR>"
if !hasmapto('<Plug>delimitMateJumpMany', 'i') && maparg("<C-G>g", 'i') == ''
imap <silent> <buffer> <C-G>g <Plug>delimitMateJumpMany
endif
endfunction "}}}
"}}}
" Commands: {{{
" Let me refresh without re-loading the buffer:
command! -bar DelimitMateReload call s:setup(1)
" Quick test:
command! -bar DelimitMateTest call s:test()
" Switch On/Off:
command! -bar DelimitMateSwitch call s:setup(2)
" Enable mappings:
command! -bar DelimitMateOn call s:setup(1)
" Disable mappings:
command! -bar DelimitMateOff call s:setup(0)
"}}}
" Autocommands: {{{
augroup delimitMate augroup delimitMate
au! au!
" Run on file type change. au InsertCharPre * call delimitMate#InsertCharPre(v:char)
au FileType * call <SID>setup() au TextChangedI * call delimitMate#TextChangedI()
au InsertEnter * call delimitMate#InsertEnter()
" Run on new buffers. au CursorMovedI * call delimitMate#CursorMovedI()
au BufNewFile,BufRead,BufEnter *
\ if !exists('b:delimitMate_was_here') |
\ call <SID>setup() |
\ let b:delimitMate_was_here = 1 |
\ endif
augroup END augroup END
"}}}
" This is for the default buffer when it does not have a filetype.
call s:setup()
let &cpo = save_cpo let &cpo = save_cpo
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim " GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
" vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2 " vim: sw=2 et

View File

@@ -1,9 +1,14 @@
all: build/runVimTests test_files := $(wildcard *.test)
build/runVimTests/bin/runVimTests.sh -0 .
build/runVimTests: build/VimTAP .PHONY: all monitor $(test_files)
git clone https://github.com/inkarkat/runVimTests $@
# Use VimTAP as directory name, as used with runVimTestsSetup.vim. all:
build/VimTAP: time tclsh all.tcl
git clone https://github.com/inkarkat/vimtap $@
$(test_files):
time tclsh $@
printf "\a"
monitor:
fswatch -o ../autoload/*.vim ../plugin/*.vim *.test \
| xargs -n1 -I\{\} time tclsh all.tcl || printf "\a"

View File

@@ -1,12 +1,11 @@
let &rtp = expand('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after'
set bs=2 set bs=2
set hidden
set noshowmode
set whichwrap=[]
set noswapfile
let &hl = join(map(split(&hl, ','), 'substitute(v:val, '':.\+'', ''n'', ''g'')'), ',')
let &rtp = expand('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after'
let g:delimitMate_pairs = ['()','{}','[]','<>','¿?','¡!',',:']
let g:delimitMate_quotes = ['"', "'", '`', '«', '|']
ru plugin/delimitMate.vim ru plugin/delimitMate.vim
let runVimTests = expand('<sfile>:p:h').'/build/runVimTests' au VimEnter * echom 'Start test'
if isdirectory(runVimTests)
let &rtp = runVimTests . ',' . &rtp
endif
let vimTAP = expand('<sfile>:p:h').'/build/VimTAP'
if isdirectory(vimTAP)
let &rtp = vimTAP . ',' . &rtp
endif

18
test/all.tcl Normal file
View File

@@ -0,0 +1,18 @@
package require tcltest 2
namespace import -force ::tcltest::*
configure {*}$argv -testdir [file dir [info script]]
# Hook to determine if any of the tests failed. Then we can exit with
# proper exit code: 0=all passed, 1=one or more failed
proc tcltest::cleanupTestsHook {} {
variable numTests
upvar 2 testFileFailures crashed
set ::exitCode [expr {$numTests(Failed) > 0}]
if {[info exists crashed]} {
set ::exitCode [expr {$::exitCode || [llength $crashed]}]
}
}
runAllTests
puts "\a"
exit $exitCode

View File

@@ -1,51 +0,0 @@
let g:delimitMate_autoclose = 1
"(x" "(x)"
"(\<BS>x" "x"
"()x" "()x"
"((\<C-G>gx" "(())x"
"(x\<Esc>u" ""
"@(x" "@(x)"
"@#\<Left>(x" "@(x)#"
"(\<S-Tab>x" "()x"
let g:delimitMate_autoclose = 0
"(x" "(x"
"()x" "(x)"
"())x" "()x"
"()\<BS>x" "x"
"@()x" "@(x)"
"@#\<Left>()x" "@(x)#"
let g:delimitMate_expand_space = 1
let g:delimitMate_autoclose = 1
"(\<Space>x" "( x )"
"(\<Space>\<BS>x" "(x)"
let g:delimitMate_autoclose = 0
"()\<Space>\<BS>x" "(x)"
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
let b:delimitMate_eol_marker = ';'
"abc(x" "abc(x);"
%d
# BS should behave accordingly.
"abc(\<BS>" "abc;"
# Expand iabbreviations
unlet b:delimitMate_eol_marker
iabb def ghi
"def(" "ghi()"
iunabb def
"abc а\<Left>(" "abc (а"
"abc ñ\<Left>(" "abc (ñ"
"abc $\<Left>(" "abc ($"
"abc £\<Left>(" "abc (£"
"abc d\<Left>(" "abc (d"
"abc \<C-V>(\<Left>(" "abc (("
"abc .\<Left>(" "abc ()."
"abc \<Left>(" "abc () "

View File

@@ -1,42 +0,0 @@
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
let lines = readfile(expand('<sfile>:t:r').'.txt')
call vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^"'''))
let itemsnumber = len(split(g:delimitMate_matchpairs, '.:.\zs,\ze.:.'))
call vimtap#Plan(testsnumber * itemsnumber)
let tcount = 1
let reload = 1
for item in lines
if item =~ '^#\|^\s*$'
" A comment or empty line.
continue
endif
if item !~ '^"'
" A command.
exec item
call vimtap#Diag(item)
let reload = 1
continue
endif
if reload
DelimitMateReload
call vimtap#Diag('DelimitMateReload')
let reload = 0
endif
let [input, output] = split(item, '"\%(\\.\|[^\\"]\)*"\zs\s*\ze"\%(\\.\|[^\\"]\)*"')
for [s:l,s:r] in map(split(g:delimitMate_matchpairs, '.:.\zs,\ze.:.'), 'split(v:val, ''.\zs:\ze.'')')
let input2 = substitute(input, '(', s:l, 'g')
let input2 = substitute(input2, ')', s:r, 'g')
let output2 = substitute(output, '(', s:l, 'g')
let output2 = substitute(output2, ')', s:r, 'g')
%d
exec 'normal i'.eval(input2)."\<Esc>"
let line = getline('.')
let passed = line == eval(output2)
call vimtap#Is(line, eval(output2), input2)
", input2 . ' => ' . string(line) .
" \ (passed ? ' =' : ' !') . '= ' . string(eval(output2)))
let tcount += 1
endfor
endfor
call vimtest#Quit()

View File

@@ -1,73 +0,0 @@
let g:delimitMate_autoclose = 1
"'x" "'x'"
"'x\<Esc>u" ""
"''x" "''x"
"'\<BS>x" "x"
"'\<C-G>gx" "''x"
# This will fail for double quote.
"'\"x" "'\"x\"'"
"@'x" "@'x'"
"@#\<Left>'x" "@'x'#"
"'\<S-Tab>x" "''x"
"abc'" "abc'"
"abc\\'x" "abc\\'x"
"u'Привет'" "u'Привет'"
"u'string'" "u'string'"
let g:delimitMate_autoclose = 0
"'x" "'x"
"''x" "'x'"
"'''x" "''x"
"''\<BS>x" "x"
"@''x" "@'x'"
"@#\<Left>''x" "@'x'#"
let g:delimitMate_expand_space = 1
let g:delimitMate_autoclose = 1
"'\<Space>x" "' x'"
let g:delimitMate_expand_inside_quotes = 1
"'\<Space>x" "' x '"
"'\<Space>\<BS>x" "'x'"
"abc\\''\<Space>x" "abc\\' x'"
let g:delimitMate_autoclose = 0
"''\<Space>\<BS>x" "'x'"
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'"
# smart quote, check fo char on the right.
"a\<space>b\<left>'" "a 'b"
# 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
# expand iabbreviations
iabb def ghi
"def'" "ghi'"
let g:delimitMate_smart_quotes = '\w\%#\_.'
"xyz'x" "xyz'x"
"xyz 'x" "xyz 'x'"
let g:delimitMate_smart_quotes = '\s\%#\_.'
"abc'x" "abc'x'"
"abc 'x" "abc 'x"
# let's try the negated form
let g:delimitMate_smart_quotes = '!\w\%#\_.'
"cba'x" "cba'x'"
"cba 'x" "cba 'x"
let g:delimitMate_smart_quotes = '!\s\%#\_.'
"zyx'x" "zyx'x"
"zyx 'x" "zyx 'x'"
unlet g:delimitMate_smart_quotes
"'\<CR>\<BS>" "''"

View File

@@ -1,47 +0,0 @@
"let g:delimitMate_quotes = '" '' ` ” « |'
let g:delimitMate_quotes = '" '' ` « |'
let lines = readfile(expand('<sfile>:t:r').'.txt')
call vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^"'''))
let itemsnumber = len(split(g:delimitMate_quotes, ' '))
call vimtap#Plan(testsnumber * itemsnumber)
let reload = 1
let tcount = 1
let linenr = 0
for item in lines
let linenr += 1
if item =~ '^#\|^\s*$'
" A comment or empty line.
continue
endif
if item !~ '^"'
" A command.
exec item
call vimtap#Diag(item)
let reload = 1
continue
endif
if reload
DelimitMateReload
call vimtap#Diag('DelimitMateReload')
let reload = 0
endif
let quotes = split(g:delimitMate_quotes, '\s')
for quote in quotes
if vimtap#Skip(1, tcount != 26, "This test is invalid for double quote.")
let tcount += 1
continue
endif
let [input, output] = split(item, '"\%(\\.\|[^\\"]\)*"\zs\s*\ze"\%(\\.\|[^\\"]\)*"')
let input_q = substitute(input,"'" , escape(escape(quote, '"'), '\'), 'g')
let output_q = substitute(output,"'" , escape(escape(quote, '"'), '\'), 'g')
%d
exec 'normal i'.eval(input_q)."\<Esc>"
if quote == '”'
call vimtap#Todo(1)
endif
call vimtap#Is(getline('.'), eval(output_q), 'Line '.linenr.': '.eval(substitute(input_q, '\\<', '<','g')))
let tcount += 1
endfor
endfor
call vimtest#Quit()

49
test/eol_marker.test Normal file
View File

@@ -0,0 +1,49 @@
# singleTest name desc setup input result vimCmds? skipScript?
#
# - desc can be empty and input would be used.
# - vimCmds is a list of ex commands.
# - skipScript will be evaluated in the scope of the function "single" and it
# should return a keywowd such as toDo, badTest or other as listed in the
# docs for tcltest. e.g.:
# {expr "[string first {i'} \"${input}\"] > -1 ? {emptyTest} : {}"}
# see tcltest documentation for other values.
# Get some help:
source helper.tcl
set vimCmds [list {let g:delimitMate_expand_cr = 1}]
lappend vimCmds {let g:delimitMate_eol_marker = ';'}
lappend vimCmds {let g:delimitMate_insert_eol_marker = 0}
single ins_eol_marker_0-1 {} "" "i(" "()" ${vimCmds}
single ins_eol_marker_0-2 {} "" "i(\rx" "(\nx\n)" ${vimCmds}
set vimCmds [list {let g:delimitMate_expand_cr = 1}]
lappend vimCmds {let g:delimitMate_eol_marker = ';'}
lappend vimCmds {let g:delimitMate_insert_eol_marker = 1}
single ins_eol_marker_1-1 {} "" "i(" "();" ${vimCmds}
single ins_eol_marker_1-2 {} " a" "0i(" "() a" ${vimCmds}
single ins_eol_marker_1-3 {} "" "i(\rx" "(\nx\n);" ${vimCmds}
set vimCmds [list {let g:delimitMate_expand_cr = 1}]
lappend vimCmds {let g:delimitMate_eol_marker = ';'}
lappend vimCmds {let g:delimitMate_insert_eol_marker = 2}
single ins_eol_marker_2-1 {} "" "i(" "()" ${vimCmds}
single ins_eol_marker_2-2 {} "" "i(\rx" "(\nx\n);" ${vimCmds}
# Issue #195
single issue_195-1 {} "" "i{(\rx" "{(\nx\n)}" ${vimCmds}
# Issue #195
single issue_195-2 {} ";" "I{(\rx" "{(\nx\n)};" ${vimCmds}
################################################################
# This gives nice statistics and cleans up the mess left behind.
cleanupTests
# vim: set filetype=tcl et sw=2 sts=0 ts=8:

View File

@@ -1,44 +0,0 @@
let g:delimitMate_expand_cr = 1
let g:delimitMate_eol_marker = ';'
call vimtest#StartTap()
call vimtap#Plan(8)
" NOTE: Do not forget to update the plan ^
let g:delimitMate_insert_eol_marker = 0
DelimitMateReload
normal i(
call vimtap#Is(getline(1), '()', 'value = 1, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n)$', ' "normal i(\<CR>x", Value = 2, case 2')
let g:delimitMate_insert_eol_marker = 1
DelimitMateReload
%d _
normal i(
call vimtap#Is(getline(1), '();', '"normal i(", value = 1, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n);$', '"normal i(\<CR>x", Value = 2, case 2')
%d _
let g:delimitMate_insert_eol_marker = 2
DelimitMateReload
normal i(
call vimtap#Is(getline(1), '()', '"normal i(", Value = 2, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n);$', '"normal i(\<CR>x", Value = 2, case 2')
%d _
exec "normal i{(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^{(\n\s*x\n)};$', ' "normal i{(\<CR>x", Value = 2, case 3')
%d _
exec "normal i;\<Esc>I{(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^{(\n\s*x\n)};$', ' "normal i{(\<CR>x", Value = 2, case 4')
" End: quit vim.
call vimtest#Quit()

92
test/expand_cr.test Normal file
View File

@@ -0,0 +1,92 @@
# singleTest name desc setup input result vimCmds? skipScript?
#
# - desc can be empty and input would be used.
# - vimCmds is a list of ex commands.
# - skipScript will be evaluated in the scope of the function "single" and it
# should return a keywowd such as toDo, badTest or other as listed in the
# docs for tcltest. e.g.:
# {expr "[string first {i'} \"${input}\"] > -1 ? {emptyTest} : {}"}
# see tcltest documentation for other values.
# Get some help:
source helper.tcl
set vimCmds [list {let g:delimitMate_expand_cr = 1}]
#"let g:delimitMate_eol_marker = ';'
lappend vimCmds {filetype indent on}
lappend vimCmds {set bs=2 et sts=4 sw=4 ft=javascript}
single javascript-1 {} "\$(document).ready(function() {})" "f{a\rx" \
"\$(document).ready(function() {\n x\n})" ${vimCmds}
# Issue #95
set vimCmds [list {let g:delimitMate_expand_cr = 1}]
lappend vimCmds {let b:delimitMate_jump_expansion = 1}
set skipScript {string cat toDo}
single issue_95 {} "" "i(\rtest)x" "(\ntest\n)x" ${vimCmds} ${skipScript}
# Remove CR expansion on BS
set skipScript {string cat toDo}
single bs {} "" "i(\r\bx" "(x)" ${vimCmds} ${skipScript}
# Consider indentation with BS inside an empty CR expansion.
single bs_indentation {} "" "i( \r\b\bx" "(x)" ${vimCmds}
# Conflict with indentation settings (cindent). Issue #95
lappend vimCmds {se cindent}
single issue_95 {} "sub foo {\n while (1) {\n\n }\n}" "3Gi\bx" \
"sub foo {\n while (1) {x}\n}" ${vimCmds}
single nested_expansion-1 {} "sub foo {\n while (1) {\n bar\n }\n}" \
"3GA}x" "sub foo {\n while (1) {\n bar\n }x\n}" ${vimCmds}
single nested_expansion-2 {} "sub foo {\n while (1) {\n bar\n }\n}" \
"3GA{x" "sub foo {\n while (1) {\n bar{x}\n }\n}" ${vimCmds}
single bracketed {} "\"{bracketed}" "\033A\"x" "\"{bracketed}\"x" ${vimCmds}
# Syntax folding enabled by autocmd breaks expansion.
set vimCmds [list {let g:delimitMate_expand_cr = 1}]
lappend vimCmds {se cindent}
lappend vimCmds {set bs=2 et sts=4 sw=4}
lappend vimCmds {autocmd InsertEnter <buffer> let w:fdm=&foldmethod \
| setl foldmethod=manual}
lappend vimCmds {autocmd InsertLeave <buffer> let &foldmethod = w:fdm}
lappend vimCmds {set foldmethod=marker}
lappend vimCmds {set foldmarker={,}}
lappend vimCmds {set foldlevel=0}
lappend vimCmds {set backspace=2}
single folding {} "" "iabc {\rx" "abc {\n x\n}" ${vimCmds}
# expand_cr != 2}
set vimCmds [list {let g:delimitMate_expand_cr = 1}]
lappend vimCmds {se cindent}
lappend vimCmds {set bs=2 et sts=4 sw=4 ft=javascript}
lappend vimCmds {let b:delimitMate_jump_expansion = 1}
single axpand_cr_no_2 {} "abc(def)" "\$i\rx" "abc(def\n x)" ${vimCmds}
# expand_cr == 2
set vimCmds [list {let g:delimitMate_expand_cr = 2}]
lappend vimCmds {se cindent}
lappend vimCmds {set bs=2 et sts=4 sw=4 ft=javascript}
lappend vimCmds {let b:delimitMate_jump_expansion = 1}
single expand_cr_2 {} "abc(def)" "\$i\rx" "abc(def\n x\n )" ${vimCmds}
# Play nice with smartindent
set vimCmds [list {let g:delimitMate_expand_cr = 2}]
lappend vimCmds {let b:delimitMate_jump_expansion = 1}
lappend vimCmds {set smartindent}
single smartindent-1 {} "" "i{\rx" "{\n x\n}" ${vimCmds}
single quotes-1 {} "" "i\" x" {" x"} ${vimCmds}
single quotes-2 {} "" "i\"\rx" "\"\nx\"" ${vimCmds}
lappend vimCmds {let g:delimitMate_expand_inside_quotes = 1}
single quotes-3 {} "" "i\"\nx" "\"\nx\n\"" ${vimCmds}
################################################################
# This gives nice statistics and cleans up the mess left behind.
cleanupTests
# vim: set filetype=tcl et sw=2 sts=0 ts=8:

View File

@@ -1,96 +0,0 @@
#
%d
filetype indent on
set bs=2 et sts=4 sw=4 ft=javascript
call setline(1, '$(document).ready(function() {})')
DelimitMateReload
exec "normal 31|i\<CR>x\<Esc>"
================================================================================
$(document).ready(function() {
x
})
--------------------------------------------------------------------------------
# Issue #95
new
let b:delimitMate_jump_expansion = 1
DelimitMateReload
exec "normal i(\<CR>test)x"
================================================================================
(
test
)x
--------------------------------------------------------------------------------
# Remove CR expansion on BS
%d
exec "normal i(\<CR>\<BS>x"
================================================================================
(x)
--------------------------------------------------------------------------------
# Consider indentation with BS inside an empty CR expansion.
%d
exec "normal i( \<CR>\<BS>\<BS>x"
================================================================================
(x)
--------------------------------------------------------------------------------
# Conflict with indentation settings (cindent). Issue #95
se cindent
call setline(1, ['sub foo {',' while (1) {', ' ', ' }', '}'])
call cursor(3, 8)
normal a}x
================================================================================
sub foo {
while (1) {
}x
}
--------------------------------------------------------------------------------
%d
call setline(1, '"{bracketed}')
normal A"x
================================================================================
"{bracketed}"x
--------------------------------------------------------------------------------
# Syntax folding enabled by autocmd breaks expansion. But ti can't be tested
# with :normal
new
autocmd InsertEnter * let w:fdm=&foldmethod | setl foldmethod=manual
autocmd InsertLeave * let &foldmethod = w:fdm
set foldmethod=marker
set foldmarker={,}
set foldlevel=0
set backspace=2
exec "normal iabc {\<CR>x"
================================================================================
abc {
x
}
--------------------------------------------------------------------------------
# expand_cr != 2
%d_
call setline(1, 'abc(def)')
exec "normal $i\<CR>x"
================================================================================
abc(def
x)
--------------------------------------------------------------------------------
# expand_cr == 2
%d_
let delimitMate_expand_cr = 2
DelimitMateReload
call setline(1, 'abc(def)')
exec "normal $i\<CR>x"
================================================================================
abc(def
x
)
--------------------------------------------------------------------------------
# Play nice with smartindent
%d_
set all&
set smartindent
exec "normal $i{\<CR>x"
================================================================================
{
x
}
--------------------------------------------------------------------------------

View File

@@ -1,55 +0,0 @@
let g:delimitMate_expand_cr = 1
"DelimitMateReload
let lines = readfile(expand('<sfile>:t:r').'.txt')
call vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$'''))
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
let expected = []
continue
endif
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)
continue
endif
if item =~ '^-\{80}$'
let expect = 0
endif
if expect
call add(expected, item)
continue
endif
let lines = getline(1, line('$'))
let passed = lines == expected
echom string(lines)
echom string(expected)
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()

48
test/expand_space.test Normal file
View File

@@ -0,0 +1,48 @@
# singleTest name desc setup input result vimCmds? skipScript?
#
# - desc can be empty and input would be used.
# - vimCmds is a list of ex commands.
# - skipScript will be evaluated in the scope of the function "single" and it
# should return a keywowd such as toDo, badTest or other as listed in the
# docs for tcltest. e.g.:
# {expr "[string first {i'} \"${input}\"] > -1 ? {emptyTest} : {}"}
# see tcltest documentation for other values.
# Get some help:
source helper.tcl
set vimCmds [list {let g:delimitMate_expand_space = 1}]
lappend vimCmds {let g:delimitMate_autoclose = 1}
pairs pairs-1 {} "" "i( x" "( x )" ${vimCmds}
pairs pairs-2 {} "( )" "la\bx" "(x)" ${vimCmds}
pairs pairs-3 {} "" "iabc x" "abc x" ${vimCmds}
quotes quotes-1 {} "" "i' x" "' x'" ${vimCmds}
lappend vimCmds {let g:delimitMate_expand_inside_quotes = 1}
quotes quotes-2 {} "" "i' x" "' x '" ${vimCmds}
quotes quotes-3 {} "" "i' \bx" "'x'" ${vimCmds}
set skipScript {string cat quoteBug}
lappend vimCmds {let g:delimitMate_autoclose = 0}
quotes quotes-4 {} "abc\\" "A'' x" "abc\\'' x '" ${vimCmds} ${skipScript}
# Issue #95
lappend vimCmds {let b:delimitMate_jump_expansion = 1}
set skipScript {string cat toDo}
pairs issue_95 {} "" "i( test)x" "( test )x" ${vimCmds} ${skipScript}
pairs pairs-4 {} "" "i() \bx" "(x)" ${vimCmds}
quotes quotes-5 {} "" "i'' \bx" "'x'" ${vimCmds}
################################################################
# This gives nice statistics and cleans up the mess left behind.
cleanupTests
# vim: set filetype=tcl et sw=2 sts=0 ts=8:

View File

@@ -1,8 +0,0 @@
# Issue #95
new
let b:delimitMate_jump_expansion = 1
DelimitMateReload
exec "normal i( test)x"
================================================================================
( test )x
--------------------------------------------------------------------------------

View File

@@ -1,42 +0,0 @@
let g:delimitMate_expand_space = 1
"DelimitMateReload
let lines = readfile(expand('<sfile>:t:r').'.txt')
call vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$'''))
call vimtap#Plan(testsnumber)
let tcount = 1
let expect = 0
let evaluate = 0
for item in lines
if item =~ '^=\{80}$'
let expect = 1
let expected = []
continue
endif
if item =~ '^#\|^\s*$' && expect == 0
" A comment or empty line.
continue
endif
if ! expect
" A command.
exec item
call vimtap#Diag(item)
continue
endif
if item =~ '^-\{80}$'
let expect = 0
endif
if expect
call add(expected, item)
continue
endif
let lines = getline(1, line('$'))
let passed = lines == expected
echom string(lines)
echom string(expected)
call vimtap#Ok(passed, string(expected) .
\ (passed ? ' =' : ' !') . '= ' . string(lines))
let tcount += 1
endfor
call vimtest#Quit()

View File

@@ -1,8 +0,0 @@
let g:delimitMate_expand_cr = 1
let g:delimitMate_eol_marker = ';'
call vimtest#StartTap()
call vimtap#Plan(1)
call vimtap#Like(maparg('(', 'i'), '<Plug>delimitMate(', 'Mappings defined for the first buffer without filetype set.')
call vimtest#Quit()

125
test/helper.tcl Normal file
View File

@@ -0,0 +1,125 @@
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
namespace import -force ::tcltest::*
}
configure -verbose {body error skip}
#configure -verbose {start msec pass body error skip}
set charMap [list \
"\"" "\\\"" \
"\$" "\\$" \
"\[" "\\\[" \
"\]" "\\\]" \
"\\" "\\\\" \
"{" "\\{" \
"}" "\\}" \
]
# In order to skip a test pass a script that, when evaluated, returns emptyTest
# for tests that can not pass, or knownBug for ToDo features. e.g.:
# {expr "[string first {i'} \"${input}\"] > -1 ? {emptyTest} : {}"}
# see tcltest documentation for other values.
proc single {name desc setup input result \
{vimCmds {}} \
{constr {}} \
} {
set fnamePrefix "test_${name}"
global charMap
makeFile ${setup} "${fnamePrefix}.in"
makeFile {} "${fnamePrefix}.out"
makeFile [join ${vimCmds} "\n"] "${fnamePrefix}.vim"
set input [string map ${charMap} ${input}]
#puts [lindex ${vimCmds} 0]
set optCharMap [list {[} {\[} {]} {\]}]
set vimArgs [lmap option ${vimCmds} \
{string cat " -c \"[string map $charMap ${option}]\""}]
set body [string cat "
exec -- ./test.exp \"${fnamePrefix}\" \"${input}\"
return \[viewFile \"${fnamePrefix}.out\"\]
" ]
#puts ${body}
if {[string length ${desc}] eq 0} {
set desc ${input}
}
if {[string length ${constr}] ne 0} {
#puts ${constr}
set constr [eval ${constr}]
#puts ${constr}
}
set name "${name}: \"${setup}\", \"${desc}\" ->"
#puts $desc
#puts $name
test ${name} \
${desc} \
-body ${body} \
-constraints ${constr} \
-result ${result}
}
proc multi {items evalScript name desc setup input result \
{vimCmds {}} \
{constr {}} \
} {
global charMap
set minor 0
foreach item $items {
incr minor
eval ${evalScript}
foreach var {desc setup input result} {
set "the_${var}" [string map ${aCharMap} [expr "$${var}"]]
}
set the_name "${name}.${minor}"
single \
${the_name} \
${the_desc} \
${the_setup} \
${the_input} \
${the_result} \
${vimCmds} \
${constr} \
}
}
proc quotes {name desc setup input result \
{vimCmds {}} \
{constr {}} \
} {
set quotes [list {'} \" {`} {«} {|}]
set mapScript {set aCharMap [list "'" ${item}]}
multi \
${quotes} \
${mapScript} \
${name} \
${desc} \
${setup} \
${input} \
${result} \
${vimCmds} \
${constr} \
}
proc pairs {name desc setup input result \
{vimCmds {}} \
{constr {}} \
} {
set pairs [list () \{\} \[\] <> ¿? ¡! ,:]
set mapScript {
set left [string index ${item} 0]
set right [string index ${item} 1]
set aCharMap [list ( ${left} ) ${right}]
}
multi \
${pairs} \
${mapScript} \
${name} \
${desc} \
${setup} \
${input} \
${result} \
${vimCmds} \
${constr} \
}
# vim: set filetype=tcl et sw=2 sts=0 ts=8:

153
test/pairs.test Normal file
View File

@@ -0,0 +1,153 @@
# singleTest name desc setup input result vimCmds? skipScript?
#
# - desc can be empty and input would be used.
# - vimCmds is a list of ex commands.
# - skipScript will be evaluated in the scope of the function "single" and it
# should return a keywowd such as toDo, badTest or other as listed in the
# docs for tcltest. e.g.:
# {expr "[string first {i'} \"${input}\"] > -1 ? {emptyTest} : {}"}
# see tcltest documentation for other values.
# Get some help:
source helper.tcl
set vimCmds [list ]
pairs autoclose-1 {} {} "i(" "()"
pairs autoclose-2 {} {()} "a\b" ""
pairs autoclose-3 {} "()" "a)x" "()x"
set skipScript {string cat {toDo}}
single jump_all {} "" "((<magic>x" "(())x" {} ${skipScript}
pairs undo {} "" "i(x\033u" ""
pairs autoclose-4 {} "" "i@(x" "@(x)"
pairs autoclose-5 {} "@#" "a(x" "@(x)#"
pairs autoclose-6 {} "\\" "a(x" "\\(x"
pairs autoclose-7 {} "(\\)" "la)x" "(\\)x)"
pairs autoclose-8 {} {"abc"} "ifoo(" "foo(\"abc\""
set vimCmds [list {let g:delimitMate_autoclose = 0}]
pairs noautoclose-1 {} "" "i(x" "(x" ${vimCmds}
pairs noautoclose-2 {} "" "i()x" "(x)" ${vimCmds}
pairs noautoclose-3 {} "" "i())x" "()x" ${vimCmds}
pairs noautoclose-4 {} "" "i()\bx" "x" ${vimCmds}
pairs noautoclose-5 {} "" "i@()x" "@(x)" ${vimCmds}
pairs noautoclose-6 {} "@#" "a()x" "@(x)#" ${vimCmds}
#" Handle backspace gracefully.
set vimCmds [list {set backspace=}]
pairs bad_bs {} "" "i(\033a\bx" "(x)" ${vimCmds}
set vimCmds [list ]
# closing parens removes characters. #133
pairs autoclose-9 {} "(a)" "a)" "()a)" ${vimCmds}
# Expand iabbreviations
set vimCmds [list {iabb def ghi}]
# Not sure how to make it work on the test
pairs iabbr {} "" "idef(" "ghi()" ${vimCmds}
set vimCmds [list ]
pairs autoclose-10 {} {abc а} {$i(} {abc (а} ${vimCmds}
pairs autoclose-11 {} "abc ñ" "\$i(" "abc (ñ" ${vimCmds}
pairs autoclose-12 {} "abc \$" "\$i(" "abc (\$" ${vimCmds}
pairs autoclose-13 {} "abc £" "\$i(" "abc (£" ${vimCmds}
pairs autoclose-14 {} "abc d" "\$i(" "abc (d" ${vimCmds}
pairs autoclose-15 {} "abc ." "\$i(" "abc ()." ${vimCmds}
pairs autoclose-16 {} "abc " "\$i(" "abc () " ${vimCmds}
pairs autoclose-17 {} "abc (" "\$i(" "abc ((" ${vimCmds}
# Play nice with undo.
pairs undo {} "" "ia\007u(c)b\033u" "a" ${vimCmds}
# TODO: way to jump over one or several closing chars
set skipScript {string cat {toDo}}
single jump_to {} "()" "a\<magic>x" "()x" ${vimCmds} ${skipScript}
single jump_to {} "{()}" "la\\<magic>x" "{()}x" ${vimCmds} ${skipScript}
set vimCmds [list {let g:delimitMate_balance_pairs = 0}]
pairs no_balance_pairs-1 {} "ab cd)" "la(x" "ab(x) cd)" ${vimCmds}
# Issue #229
pairs issue_229-1 {} "((ab cd)" "\$i)x" "((ab cd)x" ${vimCmds}
set vimCmds [list ]
set vimCmds [list {let g:delimitMate_balance_pairs = 1}]
pairs issue_229-2 {} "ab cd)" "la(x" "ab(x cd)" ${vimCmds}
# Issue #229
pairs issue_229-3 {} "((ab cd)" "\$i)x" "((ab cd)x)" ${vimCmds}
# Issue #220
set vimCmds [list {let g:delimitMate_jump_next = 0}]
pairs issue_220-1 {} "()" "a)" "())" ${vimCmds}
# Issues #207 and #223
set vimCmds [list {let g:delimitMate_jump_long = 1}]
pairs jump_long-1 {} "{\[(foobar)\]}" "fbi)x" "{\[(foobar)x\]}" ${vimCmds}
# Issues #207 and #223
set skipScript {expr "[string first {[[foobar]]} \"${setup}\"] > -1 \
? {badTest} : {}"}
single jump_long-2 {} "{\[(foobar)\]}" "fbi\]x" "{\[(foobar)\]x}" ${vimCmds} ${skipScript}
# Issues #207 and #223
set skipScript {string cat {toDo}}
set vimCmds [list {let g:delimitMate_jump_all = 1}]
single issues_207_223 {} "{\[(foobar)\]}" "fbi<magic>x" "{\[(foobar)\]}x" \
${vimCmds} ${skipScript}
set vimCmds [list {let g:delimitMate_jump_back = 1}]
pairs jump_back {} "" "i()x" "()x" ${vimCmds}
# Disable on syntax groups
set vimCmds [list {syntax on}]
lappend vimCmds {set ft=vim}
lappend vimCmds {let g:delimitMate_excluded_regions = ['String']}
pairs ignore_syntax {} {echo " "} "f\"la(" {echo " ( "} ${vimCmds}
#" Issue #160
set vimCmds [list {filetype indent plugin on}]
lappend vimCmds {set ft=php}
set skipScript {string cat {toDo}}
single issue_160 {} "<?php incl" "A\x18\x0F\x19" "<?php include()" \
${vimCmds} ${skipScript}
set vimCmds [list ]
# Play nice with redo
pairs redo {} "abc " "Afoo(x\033." "abc foo(x)foo(x)" ${vimCmds}
pairs smart {} {""} "0a(x" {"(x"}
pairs smart {} {""} "0a()x" {"(x)"}
################################################################
# This gives nice statistics and cleans up the mess left behind.
cleanupTests
# vim: set filetype=tcl et sw=2 sts=0 ts=8:

107
test/quotes.test Normal file
View File

@@ -0,0 +1,107 @@
# singleTest name desc setup input result vimCmds? skipScript?
#
# - desc can be empty and input would be used.
# - vimCmds is a list of ex commands.
# - skipScript will be evaluated in the scope of the function "single" and it
# should return a keywowd such as toDo, badTest or other as listed in the
# docs for tcltest. e.g.:
# {expr "[string first {i'} \"${input}\"] > -1 ? {emptyTest} : {}"}
# see tcltest documentation for other values.
# Get some help:
source helper.tcl
quotes autoclose-1 {} {} "i'x" "'x'"
quotes autoclose-2 {} {} "i'x\033u" {}
quotes autoclose-3 {} {} {i''x} {''x}
quotes autoclose-4 {} {''} "a\bx" {x}
set skipScript {expr "[string first {i\"} \"${input}\"] > -1 ? {badTest} : {}"}
quotes autoclose-5 {} "" "i'x\"" "'x\"'" {} ${skipScript}
quotes autoclose-6 {} {} "i@'x" "@'x'"
quotes autoclose-7 {} {@#} "a'x" "@'x'#"
#quotes autoclose-8 {} {} "'\<S-Tab>x" "''x"
single autoclose-8 {} {abc'} "A'" "abc'" {} {string cat toDo}
quotes autoclose-9 {} "abc\\" "A'x" {abc\'x}
quotes autoclose-10 {} {} "au'Привет'" "u'Привет'"
quotes autoclose-11 {} {} "au'string'" "u'string'"
set vimCmds [list {let g:delimitMate_autoclose = 0}]
quotes noautoclose-1 {} {} "a'x" "'x" ${vimCmds}
quotes noautoclose-2 {} {} "a''x" "'x'" ${vimCmds}
quotes noautoclose-3 {} {} "a'''x" "''x" ${vimCmds}
quotes noautoclose-4 {} {} "a''\bx" "x" ${vimCmds}
quotes noautoclose-5 {} {} "a@''x" "@'x'" ${vimCmds}
quotes noautoclose-6 {} "@#" "a''x" "@'x'#" ${vimCmds}
set vimCmds [list {let g:delimitMate_autoclose = 1}]
# Handle backspace gracefully.
lappend vimCmds {set backspace=}
quotes badBS-1 {} {} "a'\033a\bx" "'x'" ${vimCmds}
set vimCmds [list {set cpo=ces$}]
quotes cpo {} {} "a'x" "'x'" ${vimCmds}
# Make sure smart quote works beyond first column.
quotes beyond_first_column {} { } "a'x" " 'x'"
# smart quote, check fo char on the right.
quotes smart_quote-1 {} "a b" "la'" "a 'b"
# Make sure we jump over a quote on the right. #89.
quotes autoclose-12 {} {} "a('test'x" "('test'x)"
# Duplicate whole line when inserting quote at bol #105
quotes autoclose-13 {} "}" "i'" "''}"
quotes autoclose-14 {} "'abc " "A'" "'abc '"
quotes autoclose-15 {} "''abc " "A'" "''abc ''"
# Nesting quotes:
set vimCmds [list {let g:delimitMate_nesting_quotes = delimitMate#option('quotes')}]
quotes nesting-1 {} "''" "A'x" "'''x'''" ${vimCmds}
quotes nesting-2 {} "'''" "A'x" "''''x''''" ${vimCmds}
quotes nesting-3 {} {} "i''x" "''x" ${vimCmds}
quotes nesting-4 {} {} "i'x" "'x'" ${vimCmds}
set vimCmds [list]
# expand iabbreviations
set vimCmds [list {iabb def ghi}]
single iabbr {} {} {idef"} {ghi"} ${vimCmds}
set vimCmds [list]
quotes autoclose-16 {} {} "i'\n\b" "''"
# Double quote starts a comment in viml
set vimCmds [list {set ft=vim}]
single vim_comment {} {} {i"} {"} ${vimCmds}
#" Allow quote to exit from string when disabled by syntax group.
set vimCmds [list {syntax on}]
quotes disabled_syntax {} "'abc'" "\$i'x" "'abc'x" ${vimCmds}
# --------
# This gives nice statistics and cleans up the mess left behind.
cleanupTests
# vim: set filetype=tcl et sw=2 sts=0 ts=8:

20
test/test.exp Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env expect -f
set testName [lindex $argv 0]
set filein "${testName}.in"
set fileout "${testName}.out"
set input [lindex $argv 1]
set timeout 2
spawn env TERM=dumb vim -N -i NONE -u _setup.vim -S "${testName}.vim" -- ${filein}
match_max 100000
expect -exact "Start test"
foreach char [split ${input} {}] {
send -- "${char}"
sleep .01
}
send -- " "
sleep .01
send -- ":w! ${fileout}\r"
send -- ":qa!\r"
expect eof