From 961e50bfc2128e04c7771ee0150d9024f5616987 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 21 May 2019 00:01:53 +1200 Subject: First version --- README.md | 14 ++++++++++++++ VERSION | 1 + autoload/shebang_change_filetype.vim | 7 +++++++ doc/shebang_change_filetype.txt | 22 ++++++++++++++++++++++ plugin/shebang_change_filetype.vim | 25 +++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 README.md create mode 100644 VERSION create mode 100644 autoload/shebang_change_filetype.vim create mode 100644 doc/shebang_change_filetype.txt create mode 100644 plugin/shebang_change_filetype.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..3f6524a --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +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. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/autoload/shebang_change_filetype.vim b/autoload/shebang_change_filetype.vim new file mode 100644 index 0000000..081eaf1 --- /dev/null +++ b/autoload/shebang_change_filetype.vim @@ -0,0 +1,7 @@ +" 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) =~# '^#!' + doautocmd filetypedetect BufRead + endif +endfunction diff --git a/doc/shebang_change_filetype.txt b/doc/shebang_change_filetype.txt new file mode 100644 index 0000000..0d84d95 --- /dev/null +++ b/doc/shebang_change_filetype.txt @@ -0,0 +1,22 @@ +*shebang_change_filetype.txt* For Vim version 7.0 Last change: 2019 May 20 + +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. + +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. + +AUTHOR *shebang_change_filetype-author* + +Written and maintained by Tom Ryder . + +LICENSE *shebang_change_filetype-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/shebang_change_filetype.vim b/plugin/shebang_change_filetype.vim new file mode 100644 index 0000000..ca6c183 --- /dev/null +++ b/plugin/shebang_change_filetype.vim @@ -0,0 +1,25 @@ +" +" shebang_change_filetype.vim: On leaving insert mode, check whether the first +" line was changed and looks like a shebang format. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if exists('loaded_shebang_change_filetype') || &compatible + finish +endif +if !has('autocmd') || v:version < 700 + finish +endif +let loaded_shebang_change_filetype = 1 + +" Set up hook for before writes to check the buffer for new shebangs +augroup shebang_change_filetype + autocmd! + autocmd InsertLeave * + \ call shebang_change_filetype#Check() + if exists('##TextChanged') + autocmd TextChanged * + \ call shebang_change_filetype#Check() + endif +augroup END -- cgit v1.2.3