mirror of
https://github.com/raimon49/requirements.txt.vim.git
synced 2025-12-06 18:14:26 +08:00
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:
@@ -14,9 +14,15 @@ Installation
|
||||
|
||||
### 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
|
||||
" 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 'raimon49/requirements.txt.vim'
|
||||
|
||||
|
||||
@@ -1,33 +1,11 @@
|
||||
" the Requirements File Format syntax support for Vim
|
||||
" Version: 1.2.0
|
||||
" Version: 1.3.0
|
||||
" Author: raimon <raimon49@hotmail.com>
|
||||
" License: MIT LICENSE
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
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
|
||||
unlet s:save_cpo
|
||||
" vim: et sw=4 ts=4 sts=4:
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
" the Requirements File Format syntax support for Vim
|
||||
" Version: 1.2.0
|
||||
" Version: 1.3.0
|
||||
" Author: raimon <raimon49@hotmail.com>
|
||||
" License: MIT LICENSE
|
||||
"
|
||||
if !exists('g:requirements#detect_filename_pattern')
|
||||
let g:requirements#detect_filename_pattern = ''
|
||||
endif
|
||||
|
||||
function! s:isRequirementsFile()
|
||||
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
|
||||
|
||||
au BufNewFile,BufRead *.{txt,in} if s:isRequirementsFile() | set ft=requirements
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
" the Requirements File Format syntax support for Vim
|
||||
" Version: 1.2.0
|
||||
" Version: 1.3.0
|
||||
" Author: raimon <raimon49@hotmail.com>
|
||||
" License: MIT LICENSE
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
" the Requirements File Format syntax support for Vim
|
||||
" Version: 1.2.0
|
||||
" Version: 1.3.0
|
||||
" Author: raimon <raimon49@hotmail.com>
|
||||
" License: MIT LICENSE
|
||||
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
filetype plugin on
|
||||
runtime! plugin/requirements.vim
|
||||
|
||||
describe 'enable: requirements#matched_filename()'
|
||||
describe 'enable: Requirements_matched_filename()'
|
||||
it 'to enable file type detection: basic filename'
|
||||
Expect requirements#matched_filename('requirements.txt') to_be_true
|
||||
Expect requirements#matched_filename('requires.txt') to_be_true
|
||||
Expect Requirements_matched_filename('requirements.txt') to_be_true
|
||||
Expect Requirements_matched_filename('requires.txt') to_be_true
|
||||
end
|
||||
|
||||
it 'to enable file type detection: pip-tools filename'
|
||||
Expect requirements#matched_filename('requirements.in') to_be_true
|
||||
Expect requirements#matched_filename('requires.in') to_be_true
|
||||
Expect Requirements_matched_filename('requirements.in') to_be_true
|
||||
Expect Requirements_matched_filename('requires.in') to_be_true
|
||||
end
|
||||
|
||||
it 'to enable file type detection: directory structure'
|
||||
Expect requirements#matched_filename('requirements/dev.txt') to_be_true
|
||||
Expect requirements#matched_filename('requires/tests.in') to_be_true
|
||||
Expect Requirements_matched_filename('requirements/dev.txt') to_be_true
|
||||
Expect Requirements_matched_filename('requires/tests.in') to_be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'disable: requirements#matched_filename()'
|
||||
describe 'disable: Requirements_matched_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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
describe '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'
|
||||
Expect requirements#matched_filename('freeze.txt') to_be_true
|
||||
Expect Requirements_matched_filename('freeze.txt') to_be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user