Skip to content

Commit

Permalink
Merge branch 'for-authoring-vim-script'
Browse files Browse the repository at this point in the history
Close gh-30.
  • Loading branch information
kana committed Mar 30, 2012
2 parents b29e05e + 79200c1 commit 5280b35
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions autoload/smartinput.vim
Expand Up @@ -141,6 +141,9 @@ function! smartinput#define_default_rules() "{{{2
\ {'at': '\%#', 'char': '''', 'input': '''''<Left>', \ {'at': '\%#', 'char': '''', 'input': '''''<Left>',
\ 'syntax': ['Constant']}, \ 'syntax': ['Constant']},
\ ]) \ ])
call urules.add('Vim script comment', [
\ {'at': '^\s*\%#', 'char': '"', 'input': '"'},
\ ])
"}}} "}}}


" ft_urule_sets_table... "{{{ " ft_urule_sets_table... "{{{
Expand All @@ -163,6 +166,9 @@ function! smartinput#define_default_rules() "{{{2
\ 'scheme': [ \ 'scheme': [
\ urules.table['Lisp quote'], \ urules.table['Lisp quote'],
\ ], \ ],
\ 'vim': [
\ urules.table['Vim script comment'],
\ ],
\ } \ }
"}}} "}}}


Expand Down
39 changes: 39 additions & 0 deletions t/api.vim
Expand Up @@ -992,4 +992,43 @@ describe 'The default configuration'
Expect [line('.'), col('.')] ==# [3, 15 - 1] Expect [line('.'), col('.')] ==# [3, 15 - 1]
endfor endfor
end end

it 'should have rules to input comments and strings easily in Vim script'
setfiletype vim

" `"` at the beginning of a line must be a comment sign.
% delete _
execute 'normal' 'i" This is a comment.'
Expect getline(1, line('$')) ==# ['" This is a comment.']
Expect [line('.'), col('.')] ==# [1, 21 - 1]

" The comment sign may be indented.
% delete _
execute 'normal' 'i " This is an indented comment.'
Expect getline(1, line('$')) ==# [' " This is an indented comment.']
Expect [line('.'), col('.')] ==# [1, 33 - 1]

" In a comment, `"` is usually inserted as a string literal or an ordinary
" English word. So that it should be completed.
% delete _
execute 'normal' 'i" This is a '
execute 'normal' 'a"'
execute 'normal' 'acomment'
Expect getline(1, line('$')) ==# ['" This is a "comment"']
Expect [line('.'), col('.')] ==# [1, 21 - 1]

" `"` after an operator is usually a string literal.
% delete _
execute 'normal' 'ilet foo = bar . "baz'
Expect getline(1, line('$')) ==# ['let foo = bar . "baz"']
Expect [line('.'), col('.')] ==# [1, 21 - 1]

" But it's hard to guess all cases. We assume only `"` at the beginning
" of a line is a comment sign. In other words, `"` after non-indent
" character is always treated as a string literal.
% delete _
execute 'normal' 'ilet foo = bar " baz'
Expect getline(1, line('$')) ==# ['let foo = bar " baz"']
Expect [line('.'), col('.')] ==# [1, 20 - 1]
end
end end

0 comments on commit 5280b35

Please sign in to comment.