aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-21 00:01:53 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-21 00:01:53 +1200
commit961e50bfc2128e04c7771ee0150d9024f5616987 (patch)
treef60cadba0b806a8671621ec45efead14ee57d54e
downloadvim-shebang-change-filetype-961e50bfc2128e04c7771ee0150d9024f5616987.tar.gz
vim-shebang-change-filetype-961e50bfc2128e04c7771ee0150d9024f5616987.zip
First versionv0.1.0
-rw-r--r--README.md14
-rw-r--r--VERSION1
-rw-r--r--autoload/shebang_change_filetype.vim7
-rw-r--r--doc/shebang_change_filetype.txt22
-rw-r--r--plugin/shebang_change_filetype.vim25
5 files changed, 69 insertions, 0 deletions
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 <tom@sanctum.geek.nz>.
+
+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 <tom@sanctum.geek.nz>
+" 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