Skip to content
This repository
Browse code

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

Close gh-36.
  • Loading branch information...
commit 68538334c144e966bc4e32fb7faaedc53c3f2a95 2 parents 89d39db + de77132
Kana Natsuno authored

Showing 2 changed files with 51 additions and 28 deletions. Show diff stats Hide diff stats

  1. +2 2 autoload/smartinput.vim
  2. +49 26 t/api.vim
4 autoload/smartinput.vim
@@ -77,7 +77,7 @@ function! smartinput#define_default_rules() "{{{2
77 77 \ {'at': '(\%#)', 'char': '<BS>', 'input': '<BS><Del>'},
78 78 \ {'at': '()\%#', 'char': '<BS>', 'input': '<BS><BS>'},
79 79 \ {'at': '\\\%#', 'char': '(', 'input': '('},
80   - \ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter>X<Enter>)<BS><Up><End><BS>'},
  80 + \ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter><Enter><Up><C-o>S'},
81 81 \ ])
82 82 call urules.add('[]', [
83 83 \ {'at': '\%#', 'char': '[', 'input': '[]<Left>'},
@@ -92,7 +92,7 @@ function! smartinput#define_default_rules() "{{{2
92 92 \ {'at': '{\%#}', 'char': '<BS>', 'input': '<BS><Del>'},
93 93 \ {'at': '{}\%#', 'char': '<BS>', 'input': '<BS><BS>'},
94 94 \ {'at': '\\\%#', 'char': '{', 'input': '{'},
95   - \ {'at': '{\%#}', 'char': '<Enter>', 'input': '<Enter>X<Enter><Up><End><C-t><BS>'},
  95 + \ {'at': '{\%#}', 'char': '<Enter>', 'input': '<Enter><Enter><Up><C-o>S'},
96 96 \ ])
97 97 call urules.add('''''', [
98 98 \ {'at': '\%#', 'char': '''', 'input': '''''<Left>'},
75 t/api.vim
@@ -877,16 +877,16 @@ describe 'The default configuration'
877 877 \ ],
878 878 \ '{} leave #4': [
879 879 \ ["{", ['{}'], 1, 2 - 1],
880   - \ ["\<Enter>x", ['{', "\tx", '}'], 2, 3 - 1],
881   - \ ["}", ['{', "\tx", '}'], 3, 2 - 1],
  880 + \ ["\<Enter> x", ['{', ' x', '}'], 2, 4 - 1],
  881 + \ ["}", ['{', ' x', '}'], 3, 2 - 1],
882 882 \ ],
883 883 \ '{} leave #5': [
884 884 \ ["{", ['{}'], 1, 2 - 1],
885   - \ ["\<Enter>", ['{', "\t", '}'], 2, 2 - 1],
886   - \ ["{", ['{', "\t{}", '}'], 2, 3 - 1],
887   - \ ["\<Enter>x", ['{', "\t{", "\t\tx", "\t}", '}'], 3, 4 - 1],
888   - \ ["}", ['{', "\t{", "\t\tx", "\t}", '}'], 4, 3 - 1],
889   - \ ["}", ['{', "\t{", "\t\tx", "\t}", '}'], 5, 2 - 1],
  885 + \ ["\<Enter> ", ['{', ' ', '}'], 2, 3 - 1],
  886 + \ ["{", ['{', ' {}', '}'], 2, 4 - 1],
  887 + \ ["\<Enter> x", ['{', ' {', ' x', ' }', '}'], 3, 6 - 1],
  888 + \ ["}", ['{', ' {', ' x', ' }', '}'], 4, 4 - 1],
  889 + \ ["}", ['{', ' {', ' x', ' }', '}'], 5, 2 - 1],
890 890 \ ],
891 891 \ '{} undo #1': [
892 892 \ ["{", ['{}'], 1, 2 - 1],
@@ -1054,27 +1054,50 @@ describe 'The default configuration'
1054 1054 Expect b:getSynNames(line('.'), col('.')) ==# ['Comment']
1055 1055 end
1056 1056
1057   - it 'should have rules to write C-like syntax source code'
1058   - setfiletype c
1059   - setlocal expandtab
1060   - Expect &l:filetype ==# 'c'
  1057 + it 'should have rules to expand a () block and a {} block'
  1058 + setfiletype ruby
  1059 + setlocal expandtab shiftwidth=2 softtabstop=2
1061 1060
1062   - for key in ["\<Enter>", "\<Return>", "\<CR>", "\<C-m>", "\<NL>", "\<C-j>"]
1063   - % delete _
1064   - execute 'normal' printf('ifoo(%sbar,%sbaz', key, key)
1065   - Expect getline(1, line('$')) ==# ['foo(',
1066   - \ ' bar,',
1067   - \ ' baz',
1068   - \ ' )']
1069   - Expect [line('.'), col('.')] ==# [3, 20 - 1]
  1061 + let keys = ["\<Enter>", "\<Return>", "\<CR>", "\<C-m>", "\<NL>", "\<C-j>"]
  1062 + for additional_indentkeys in ['', '*<Return>']
  1063 + " Some configurations for automatic indentation perform indentation
  1064 + " before breaking the current line, while the others do not so. For
  1065 + " example, $VIMRUNTIME/indent/php.vim performs such indentation. So
  1066 + " that we have to test both cases.
  1067 + setlocal indentkeys<
  1068 + let &l:indentkeys .= ',' . additional_indentkeys
1070 1069
1071   - % delete _
1072   - execute 'normal' printf('i{%sfoo();%sbar();', key, key)
1073   - Expect getline(1, line('$')) ==# ['{',
1074   - \ ' foo();',
1075   - \ ' bar();',
1076   - \ '}']
1077   - Expect [line('.'), col('.')] ==# [3, 15 - 1]
  1070 + for key in keys
  1071 + let note = [strtrans(key), additional_indentkeys]
  1072 +
  1073 + % delete _
  1074 + execute 'normal' printf('ifoo(%sbar,%sbaz', key, key)
  1075 + Expect [note, line('.'), col('.'), getline(1, line('$'))]
  1076 + \ ==# [
  1077 + \ note,
  1078 + \ 3, 6 - 1,
  1079 + \ [
  1080 + \ 'foo(',
  1081 + \ ' bar,',
  1082 + \ ' baz',
  1083 + \ ')',
  1084 + \ ],
  1085 + \ ]
  1086 +
  1087 + % delete _
  1088 + execute 'normal' printf('i{%sfoo()%sbar()', key, key)
  1089 + Expect [note, line('.'), col('.'), getline(1, line('$'))]
  1090 + \ ==# [
  1091 + \ note,
  1092 + \ 3, 8 - 1,
  1093 + \ [
  1094 + \ '{',
  1095 + \ ' foo()',
  1096 + \ ' bar()',
  1097 + \ '}',
  1098 + \ ],
  1099 + \ ]
  1100 + endfor
1078 1101 endfor
1079 1102 end
1080 1103

0 comments on commit 6853833

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