From 0d1a7b1b5bcc0548c1792a09364e4642d8727d2b Mon Sep 17 00:00:00 2001 From: raimon Date: Sun, 16 Oct 2016 22:42:15 +0900 Subject: [PATCH] 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 --- README.md | 8 +++++++- autoload/requirements.vim | 24 +----------------------- ftdetect/requirements.vim | 25 +++++++++++++++++++++++-- plugin/requirements.vim | 2 +- syntax/requirements.vim | 2 +- t/test_ftdetect.vim | 26 +++++++++++++------------- 6 files changed, 46 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index e8e7f23..497cbfd 100644 --- a/README.md +++ b/README.md @@ -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' diff --git a/autoload/requirements.vim b/autoload/requirements.vim index 1c3e858..51d5545 100644 --- a/autoload/requirements.vim +++ b/autoload/requirements.vim @@ -1,33 +1,11 @@ " the Requirements File Format syntax support for Vim -" Version: 1.2.0 +" Version: 1.3.0 " Author: raimon " 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: diff --git a/ftdetect/requirements.vim b/ftdetect/requirements.vim index 187e1fc..a5e21b6 100644 --- a/ftdetect/requirements.vim +++ b/ftdetect/requirements.vim @@ -1,12 +1,33 @@ " the Requirements File Format syntax support for Vim -" Version: 1.2.0 +" Version: 1.3.0 " Author: raimon " 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 diff --git a/plugin/requirements.vim b/plugin/requirements.vim index 7dc6906..153d178 100644 --- a/plugin/requirements.vim +++ b/plugin/requirements.vim @@ -1,5 +1,5 @@ " the Requirements File Format syntax support for Vim -" Version: 1.2.0 +" Version: 1.3.0 " Author: raimon " License: MIT LICENSE diff --git a/syntax/requirements.vim b/syntax/requirements.vim index 42954f3..a85e645 100644 --- a/syntax/requirements.vim +++ b/syntax/requirements.vim @@ -1,5 +1,5 @@ " the Requirements File Format syntax support for Vim -" Version: 1.2.0 +" Version: 1.3.0 " Author: raimon " License: MIT LICENSE diff --git a/t/test_ftdetect.vim b/t/test_ftdetect.vim index f988db6..ae819fa 100644 --- a/t/test_ftdetect.vim +++ b/t/test_ftdetect.vim @@ -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