Fix load script order (#5)

* Move the function 'matched_filename' to ftdetect #4

* Move the variable 'g:requirements#detect_filename_pattern' to ftdetect #4

* Rename 'describe' in unittest

* Add dein.vim in section of installation

* Bump version to 1.3.0

Close #4
This commit is contained in:
raimon
2016-10-16 22:42:15 +09:00
committed by GitHub
parent a426efa00b
commit 0d1a7b1b5b
6 changed files with 46 additions and 41 deletions

View File

@@ -14,9 +14,15 @@ Installation
### Plugin manager (**recommended**) ### Plugin manager (**recommended**)
e.g.) [NeoBundle](https://github.com/Shougo/neobundle.vim), [Vundle](https://github.com/VundleVim/Vundle.vim), [vim-plug](https://github.com/junegunn/vim-plug) [and more](https://dotfiles.github.io/) e.g.) [dein.vim](https://github.com/Shougo/dein.vim)[NeoBundle](https://github.com/Shougo/neobundle.vim), [Vundle](https://github.com/VundleVim/Vundle.vim), [vim-plug](https://github.com/junegunn/vim-plug) [and more](https://dotfiles.github.io/)
```vim ```vim
" dein.vim
call dein#add('raimon49/requirements.txt.vim')
" dein.vim with lazy
call dein#add('raimon49/requirements.txt.vim', {'lazy': 1, 'on_ft': 'requirements'})
" NeoBundle " NeoBundle
NeoBundle 'raimon49/requirements.txt.vim' NeoBundle 'raimon49/requirements.txt.vim'

View File

@@ -1,33 +1,11 @@
" the Requirements File Format syntax support for Vim " the Requirements File Format syntax support for Vim
" Version: 1.2.0 " Version: 1.3.0
" Author: raimon <raimon49@hotmail.com> " Author: raimon <raimon49@hotmail.com>
" License: MIT LICENSE " License: MIT LICENSE
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
if !exists('g:requirements#detect_filename_pattern')
let g:requirements#detect_filename_pattern = ''
endif
function! requirements#matched_filename(filename)
if a:filename =~# '\v.*require(ment)?s\.(txt|in)$'
return 1
endif
if a:filename =~# '\vrequire(ment)?s/.*\.(txt|in)$'
return 1
endif
if len(g:requirements#detect_filename_pattern)
\ && a:filename =~# g:requirements#detect_filename_pattern
return 1
endif
return 0
endfunction
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo
" vim: et sw=4 ts=4 sts=4: " vim: et sw=4 ts=4 sts=4:

View File

@@ -1,12 +1,33 @@
" the Requirements File Format syntax support for Vim " the Requirements File Format syntax support for Vim
" Version: 1.2.0 " Version: 1.3.0
" Author: raimon <raimon49@hotmail.com> " Author: raimon <raimon49@hotmail.com>
" License: MIT LICENSE " License: MIT LICENSE
" "
if !exists('g:requirements#detect_filename_pattern')
let g:requirements#detect_filename_pattern = ''
endif
function! s:isRequirementsFile() function! s:isRequirementsFile()
let l:filename = expand("%:p") let l:filename = expand("%:p")
return requirements#matched_filename(l:filename) return Requirements_matched_filename(l:filename)
endfunction
function! Requirements_matched_filename(filename)
if a:filename =~# '\v.*require(ment)?s\.(txt|in)$'
return 1
endif
if a:filename =~# '\vrequire(ment)?s/.*\.(txt|in)$'
return 1
endif
if len(g:requirements#detect_filename_pattern)
\ && a:filename =~# g:requirements#detect_filename_pattern
return 1
endif
return 0
endfunction endfunction
au BufNewFile,BufRead *.{txt,in} if s:isRequirementsFile() | set ft=requirements au BufNewFile,BufRead *.{txt,in} if s:isRequirementsFile() | set ft=requirements

View File

@@ -1,5 +1,5 @@
" the Requirements File Format syntax support for Vim " the Requirements File Format syntax support for Vim
" Version: 1.2.0 " Version: 1.3.0
" Author: raimon <raimon49@hotmail.com> " Author: raimon <raimon49@hotmail.com>
" License: MIT LICENSE " License: MIT LICENSE

View File

@@ -1,5 +1,5 @@
" the Requirements File Format syntax support for Vim " the Requirements File Format syntax support for Vim
" Version: 1.2.0 " Version: 1.3.0
" Author: raimon <raimon49@hotmail.com> " Author: raimon <raimon49@hotmail.com>
" License: MIT LICENSE " License: MIT LICENSE

View File

@@ -1,42 +1,42 @@
filetype plugin on filetype plugin on
runtime! plugin/requirements.vim runtime! plugin/requirements.vim
describe 'enable: requirements#matched_filename()' describe 'enable: Requirements_matched_filename()'
it 'to enable file type detection: basic filename' it 'to enable file type detection: basic filename'
Expect requirements#matched_filename('requirements.txt') to_be_true Expect Requirements_matched_filename('requirements.txt') to_be_true
Expect requirements#matched_filename('requires.txt') to_be_true Expect Requirements_matched_filename('requires.txt') to_be_true
end end
it 'to enable file type detection: pip-tools filename' it 'to enable file type detection: pip-tools filename'
Expect requirements#matched_filename('requirements.in') to_be_true Expect Requirements_matched_filename('requirements.in') to_be_true
Expect requirements#matched_filename('requires.in') to_be_true Expect Requirements_matched_filename('requires.in') to_be_true
end end
it 'to enable file type detection: directory structure' it 'to enable file type detection: directory structure'
Expect requirements#matched_filename('requirements/dev.txt') to_be_true Expect Requirements_matched_filename('requirements/dev.txt') to_be_true
Expect requirements#matched_filename('requires/tests.in') to_be_true Expect Requirements_matched_filename('requires/tests.in') to_be_true
end end
end end
describe 'disable: requirements#matched_filename()' describe 'disable: Requirements_matched_filename()'
it 'to disable: file type detection: basic filename' it 'to disable: file type detection: basic filename'
Expect requirements#matched_filename('requirements.text') to_be_false Expect Requirements_matched_filename('requirements.text') to_be_false
end end
it 'to disable: file type detection: pip-tools filename' it 'to disable: file type detection: pip-tools filename'
Expect requirements#matched_filename('requirements.ini') to_be_false Expect Requirements_matched_filename('requirements.ini') to_be_false
end end
it 'to disable: file type detection: directory structure' it 'to disable: file type detection: directory structure'
Expect requirements#matched_filename('require/dev.txt') to_be_false Expect Requirements_matched_filename('require/dev.txt') to_be_false
end end
end end
describe 'g:requirements#detect_filename_pattern' describe 'g:requirements#detect_filename_pattern'
it 'use g:requirements#detect_filename_pattern' it 'use g:requirements#detect_filename_pattern'
Expect requirements#matched_filename('freeze.txt') to_be_false Expect Requirements_matched_filename('freeze.txt') to_be_false
let g:requirements#detect_filename_pattern = 'freeze' let g:requirements#detect_filename_pattern = 'freeze'
Expect requirements#matched_filename('freeze.txt') to_be_true Expect Requirements_matched_filename('freeze.txt') to_be_true
end end
end end