Permalink
Browse files

Merge branch 'indent-correctly-after-expanding-blocks'

Close gh-36.
  • Loading branch information...
2 parents 89d39db + de77132 commit 68538334c144e966bc4e32fb7faaedc53c3f2a95 @kana committed Apr 3, 2012
Showing with 51 additions and 28 deletions.
  1. +2 −2 autoload/smartinput.vim
  2. +49 −26 t/api.vim
View
@@ -77,7 +77,7 @@ function! smartinput#define_default_rules() "{{{2
\ {'at': '(\%#)', 'char': '<BS>', 'input': '<BS><Del>'},
\ {'at': '()\%#', 'char': '<BS>', 'input': '<BS><BS>'},
\ {'at': '\\\%#', 'char': '(', 'input': '('},
- \ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter>X<Enter>)<BS><Up><End><BS>'},
+ \ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter><Enter><Up><C-o>S'},
\ ])
call urules.add('[]', [
\ {'at': '\%#', 'char': '[', 'input': '[]<Left>'},
@@ -92,7 +92,7 @@ function! smartinput#define_default_rules() "{{{2
\ {'at': '{\%#}', 'char': '<BS>', 'input': '<BS><Del>'},
\ {'at': '{}\%#', 'char': '<BS>', 'input': '<BS><BS>'},
\ {'at': '\\\%#', 'char': '{', 'input': '{'},
- \ {'at': '{\%#}', 'char': '<Enter>', 'input': '<Enter>X<Enter><Up><End><C-t><BS>'},
+ \ {'at': '{\%#}', 'char': '<Enter>', 'input': '<Enter><Enter><Up><C-o>S'},
\ ])
call urules.add('''''', [
\ {'at': '\%#', 'char': '''', 'input': '''''<Left>'},
View
@@ -877,16 +877,16 @@ describe 'The default configuration'
\ ],
\ '{} leave #4': [
\ ["{", ['{}'], 1, 2 - 1],
- \ ["\<Enter>x", ['{', "\tx", '}'], 2, 3 - 1],
- \ ["}", ['{', "\tx", '}'], 3, 2 - 1],
+ \ ["\<Enter> x", ['{', ' x', '}'], 2, 4 - 1],
+ \ ["}", ['{', ' x', '}'], 3, 2 - 1],
\ ],
\ '{} leave #5': [
\ ["{", ['{}'], 1, 2 - 1],
- \ ["\<Enter>", ['{', "\t", '}'], 2, 2 - 1],
- \ ["{", ['{', "\t{}", '}'], 2, 3 - 1],
- \ ["\<Enter>x", ['{', "\t{", "\t\tx", "\t}", '}'], 3, 4 - 1],
- \ ["}", ['{', "\t{", "\t\tx", "\t}", '}'], 4, 3 - 1],
- \ ["}", ['{', "\t{", "\t\tx", "\t}", '}'], 5, 2 - 1],
+ \ ["\<Enter> ", ['{', ' ', '}'], 2, 3 - 1],
+ \ ["{", ['{', ' {}', '}'], 2, 4 - 1],
+ \ ["\<Enter> x", ['{', ' {', ' x', ' }', '}'], 3, 6 - 1],
+ \ ["}", ['{', ' {', ' x', ' }', '}'], 4, 4 - 1],
+ \ ["}", ['{', ' {', ' x', ' }', '}'], 5, 2 - 1],
\ ],
\ '{} undo #1': [
\ ["{", ['{}'], 1, 2 - 1],
@@ -1054,27 +1054,50 @@ describe 'The default configuration'
Expect b:getSynNames(line('.'), col('.')) ==# ['Comment']
end
- it 'should have rules to write C-like syntax source code'
- setfiletype c
- setlocal expandtab
- Expect &l:filetype ==# 'c'
+ it 'should have rules to expand a () block and a {} block'
+ setfiletype ruby
+ setlocal expandtab shiftwidth=2 softtabstop=2
- for key in ["\<Enter>", "\<Return>", "\<CR>", "\<C-m>", "\<NL>", "\<C-j>"]
- % delete _
- execute 'normal' printf('ifoo(%sbar,%sbaz', key, key)
- Expect getline(1, line('$')) ==# ['foo(',
- \ ' bar,',
- \ ' baz',
- \ ' )']
- Expect [line('.'), col('.')] ==# [3, 20 - 1]
+ let keys = ["\<Enter>", "\<Return>", "\<CR>", "\<C-m>", "\<NL>", "\<C-j>"]
+ for additional_indentkeys in ['', '*<Return>']
+ " Some configurations for automatic indentation perform indentation
+ " before breaking the current line, while the others do not so. For
+ " example, $VIMRUNTIME/indent/php.vim performs such indentation. So
+ " that we have to test both cases.
+ setlocal indentkeys<
+ let &l:indentkeys .= ',' . additional_indentkeys
- % delete _
- execute 'normal' printf('i{%sfoo();%sbar();', key, key)
- Expect getline(1, line('$')) ==# ['{',
- \ ' foo();',
- \ ' bar();',
- \ '}']
- Expect [line('.'), col('.')] ==# [3, 15 - 1]
+ for key in keys
+ let note = [strtrans(key), additional_indentkeys]
+
+ % delete _
+ execute 'normal' printf('ifoo(%sbar,%sbaz', key, key)
+ Expect [note, line('.'), col('.'), getline(1, line('$'))]
+ \ ==# [
+ \ note,
+ \ 3, 6 - 1,
+ \ [
+ \ 'foo(',
+ \ ' bar,',
+ \ ' baz',
+ \ ')',
+ \ ],
+ \ ]
+
+ % delete _
+ execute 'normal' printf('i{%sfoo()%sbar()', key, key)
+ Expect [note, line('.'), col('.'), getline(1, line('$'))]
+ \ ==# [
+ \ note,
+ \ 3, 8 - 1,
+ \ [
+ \ '{',
+ \ ' foo()',
+ \ ' bar()',
+ \ '}',
+ \ ],
+ \ ]
+ endfor
endfor
end

0 comments on commit 6853833

Please sign in to comment.