aboutsummaryrefslogtreecommitdiff
path: root/vim/plugin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-07 13:38:10 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-07 13:38:10 +1300
commit61d05839a42b56c0759264b493f98d5a516affc4 (patch)
treec550a3ad47412e4d97b711f8f8ba06fa6a091d1e /vim/plugin
parentUse b:undo variables correctly (diff)
downloaddotfiles-61d05839a42b56c0759264b493f98d5a516affc4.tar.gz
dotfiles-61d05839a42b56c0759264b493f98d5a516affc4.zip
Add user_ftplugin.vim and user_indent.vim plugins
This reverts commit 09b83b6 and replaces it with a working version. Because of the order in which the autocmd hooks run, the attempted method of adding unloading instructions for my custom ftplugin and indent rules to the b:undo_ftplugin and b:undo_indent doesn't actually work. This is because the custom rules for both groups from ~/.vim are sourced *first*, before their core versions, so the changes the custom rules made to b:undo_ftplugin and b:undo_indent are simply clobbered by the core version when it loads itself. Therefore we need to arrange for two things: 1. A custom variable needs to be checked and executed when the filetype changes to revert the changes for the custom ftplugin or indent rules. 2. That execution needs to take place *first* when the filetype changes. I wrote two simple plugins with very similar code that are designed to run as a user's custom ftplugin.vim and indent.vim implementations, running before their brethren in the Vim core, and setting up an autocmd hook to :execute b:undo_user_ftplugin and b:undo_user_indent plugin respectively. This seemed to work well, so I've implemented it. It involves adding a shim to ~/.vim/indent.vim and ~/.vim/ftplugin.vim to "preload" the plugin when the `filetype indent plugin on` call is made. I've added that to the relevant Makefile targets.
Diffstat (limited to 'vim/plugin')
-rw-r--r--vim/plugin/user_ftplugin.vim24
-rw-r--r--vim/plugin/user_indent.vim24
2 files changed, 48 insertions, 0 deletions
diff --git a/vim/plugin/user_ftplugin.vim b/vim/plugin/user_ftplugin.vim
new file mode 100644
index 00000000..d9739bda
--- /dev/null
+++ b/vim/plugin/user_ftplugin.vim
@@ -0,0 +1,24 @@
+"
+" user_ftplugin.vim: When switching filetypes, look for a b:undo_user_ftplugin
+" variable and use it in much the same way the core's ftplugin.vim does
+" b:undo_ftplugin in Vim >= 7.0. This allows you to undo your own ftplugin
+" files the same way you can the core ones.
+"
+if exists('g:loaded_user_ftplugin')
+ \ || !has('autocmd')
+ \ || &compatible
+ finish
+endif
+let g:loaded_user_ftplugin = 1
+
+function! s:LoadUserFtplugin()
+ if exists('b:undo_user_ftplugin')
+ execute b:undo_user_ftplugin
+ unlet b:undo_user_ftplugin
+ endif
+endfunction
+
+augroup user_ftplugin
+ autocmd!
+ autocmd FileType * call s:LoadUserFtplugin()
+augroup END
diff --git a/vim/plugin/user_indent.vim b/vim/plugin/user_indent.vim
new file mode 100644
index 00000000..01596bdb
--- /dev/null
+++ b/vim/plugin/user_indent.vim
@@ -0,0 +1,24 @@
+"
+" user_indent.vim: When switching filetypes, look for a b:undo_user_indent
+" variable and use it in much the same way the core's indent.vim does
+" b:undo_indent in Vim >= 7.0. This allows you to undo your own indent files
+" the same way you can the core ones.
+"
+if exists('g:loaded_user_indent')
+ \ || !has('autocmd')
+ \ || &compatible
+ finish
+endif
+let g:loaded_user_indent = 1
+
+function! s:LoadUserIndent()
+ if exists('b:undo_user_indent')
+ execute b:undo_user_indent
+ unlet b:undo_user_indent
+ endif
+endfunction
+
+augroup user_indent
+ autocmd!
+ autocmd FileType * call s:LoadUserIndent()
+augroup END