diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-07 13:38:10 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-07 13:38:10 +1300 |
commit | 61d05839a42b56c0759264b493f98d5a516affc4 (patch) | |
tree | c550a3ad47412e4d97b711f8f8ba06fa6a091d1e /vim/doc/user_indent.txt | |
parent | Use b:undo variables correctly (diff) | |
download | dotfiles-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/doc/user_indent.txt')
-rw-r--r-- | vim/doc/user_indent.txt | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/vim/doc/user_indent.txt b/vim/doc/user_indent.txt new file mode 100644 index 00000000..ff71d575 --- /dev/null +++ b/vim/doc/user_indent.txt @@ -0,0 +1,27 @@ +*user_indent.txt* "Undo" for local indent files + +Author: Tom Ryder <tom@sanctum.geek.nz> +License: Same terms as Vim itself (see |license|) + +This plugin adds an |autocmd| hook to |FileType| to run before the one that the +core indent.vim sets, to allow setting a b:undo_user_indent variable with +code to |:execute| when the filetype is next changed, in much the same way that +the core files in Vim >= 7.0x support a b:|undo_indent| variable. + +This will only work if it's loaded *before* indent.vim so that the autocmd +hooks run in the right order. There are a couple of ways to do this: + +1. Create your own ~/.vim/indent.vim with the following contents: + + silent! runtime plugin/user_indent.vim + + This will then be sourced before the core indent.vim runs. This is the + suggested method. + +2. Run the same line in your ~/.vimrc before your `filetype indent on` line. + +See also: user_ftplugin.vim. + +This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun +off into a separate distribution as it solidifies and this documentation +improves. |