diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-29 02:37:30 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-29 02:37:30 +1200 |
commit | cd621073e171db746c6cba933a867a4f48329211 (patch) | |
tree | a25ab064d2f4fd9038e17176ecbea9c3de7a0fd4 | |
parent | First version (diff) | |
parent | Bump VERSION (diff) | |
download | vim-shebang-change-filetype-cd621073e171db746c6cba933a867a4f48329211.tar.gz vim-shebang-change-filetype-cd621073e171db746c6cba933a867a4f48329211.zip |
Merge branch 'release/v0.2.0'v0.2.0
* release/v0.2.0:
Condense and solidify documentation
Use :doautocmd to avoid redundancy
Correct indenting
Condense load guard
Split longish conditional
Remove unneeded function name
Replace unneeded regex check
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | autoload/shebang_change_filetype.vim | 5 | ||||
-rw-r--r-- | doc/shebang_change_filetype.txt | 11 | ||||
-rw-r--r-- | plugin/shebang_change_filetype.vim | 13 |
5 files changed, 16 insertions, 20 deletions
@@ -1,9 +1,8 @@ shebang\_change\_filetype.vim ============================= -This plugin watches the first line of a buffer for the presence of a "shebang", -beginning with the characters "#!". If such a line is added or modified, -filetype detection is re-run. +This plugin re-runs filetype detection if a shebang `#!` is added or changed in +the buffer. License ------- @@ -1 +1 @@ -0.1.0 +0.2.0 diff --git a/autoload/shebang_change_filetype.vim b/autoload/shebang_change_filetype.vim index 081eaf1..447ac2b 100644 --- a/autoload/shebang_change_filetype.vim +++ b/autoload/shebang_change_filetype.vim @@ -1,7 +1,8 @@ " Check whether the first line was changed and looks like a shebang, and if " so, re-run filetype detection -function! shebang_change_filetype#Check() abort - if line('''[') == 1 && getline(1) =~# '^#!' +function! shebang_change_filetype#() abort + if line("'[") == 1 + \ && strpart(getline(1), 0, 2) ==# '#!' doautocmd filetypedetect BufRead endif endfunction diff --git a/doc/shebang_change_filetype.txt b/doc/shebang_change_filetype.txt index 0d84d95..d26f02a 100644 --- a/doc/shebang_change_filetype.txt +++ b/doc/shebang_change_filetype.txt @@ -1,15 +1,14 @@ -*shebang_change_filetype.txt* For Vim version 7.0 Last change: 2019 May 20 +*shebang_change_filetype.txt* For Vim version 7.0 Last change: 2019 May 28 DESCRIPTION *shebang_change_filetype* -This plugin watches the first line of a buffer for the presence of a -"shebang", beginning with the characters "#!". If such a line is added or -modified, filetype detection is re-run. +This plugin re-runs |filetype| detection if a shebang `#!` is added or changed +in the buffer. REQUIREMENTS *shebang_change_filetype-requirements* -This plugin only loads if 'compatible' is not set, and requires the |+autocmd| -feature. It works best if the |TextChanged| event is also available. +This plugin only loads if 'compatible' is not set. It works best if the +|TextChanged| event is supported. AUTHOR *shebang_change_filetype-author* diff --git a/plugin/shebang_change_filetype.vim b/plugin/shebang_change_filetype.vim index ca6c183..03f5830 100644 --- a/plugin/shebang_change_filetype.vim +++ b/plugin/shebang_change_filetype.vim @@ -1,14 +1,11 @@ " -" shebang_change_filetype.vim: On leaving insert mode, check whether the first -" line was changed and looks like a shebang format. +" shebang_change_filetype.vim: Re-run filetype detection if a shebang #! is +" added or changed in the buffer. " " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself " -if exists('loaded_shebang_change_filetype') || &compatible - finish -endif -if !has('autocmd') || v:version < 700 +if exists('loaded_shebang_change_filetype') || &compatible || v:version < 700 finish endif let loaded_shebang_change_filetype = 1 @@ -17,9 +14,9 @@ let loaded_shebang_change_filetype = 1 augroup shebang_change_filetype autocmd! autocmd InsertLeave * - \ call shebang_change_filetype#Check() + \ call shebang_change_filetype#() if exists('##TextChanged') autocmd TextChanged * - \ call shebang_change_filetype#Check() + \ doautocmd InsertLeave endif augroup END |