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/ftplugin | |
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/ftplugin')
-rw-r--r-- | vim/ftplugin/mail.vim | 9 | ||||
-rw-r--r-- | vim/ftplugin/markdown.vim | 9 | ||||
-rw-r--r-- | vim/ftplugin/sh.vim | 9 | ||||
-rw-r--r-- | vim/ftplugin/text.vim | 9 |
4 files changed, 8 insertions, 28 deletions
diff --git a/vim/ftplugin/mail.vim b/vim/ftplugin/mail.vim index 236f25ff..d4840bfd 100644 --- a/vim/ftplugin/mail.vim +++ b/vim/ftplugin/mail.vim @@ -1,9 +1,4 @@ " Use trailing whitespace to denote continued paragraph setlocal formatoptions+=w - -" Undo -if !exists('b:undo_ftplugin') - let b:undo_ftplugin = '' -endif -let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal formatoptions<' +let b:undo_user_ftplugin + \ = 'setlocal formatoptions<' diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim index 15333202..ab27c2f7 100644 --- a/vim/ftplugin/markdown.vim +++ b/vim/ftplugin/markdown.vim @@ -1,11 +1,6 @@ " Spellcheck documents by default if has('syntax') setlocal spell - - " Undo - if !exists('b:undo_ftplugin') - let b:undo_ftplugin = '' - endif - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal spell<' + let b:undo_user_ftplugin + \ = 'setlocal spell<' endif diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 85251aa1..21d494e3 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -23,6 +23,8 @@ endif " Use han(1df) as a man(1) wrapper for Bash files if available if exists('b:is_bash') && executable('han') setlocal keywordprg=han + let b:undo_user_indent + \ = 'setlocal keywordprg<' endif " Map checker based on shell family @@ -48,10 +50,3 @@ endif nnoremap <buffer> <silent> \ <LocalLeader>l \ :<C-U>execute b:lint<CR> - -" Undo -if !exists('b:undo_ftplugin') - let b:undo_ftplugin = '' -endif -let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal keywordprg<' diff --git a/vim/ftplugin/text.vim b/vim/ftplugin/text.vim index 15333202..ab27c2f7 100644 --- a/vim/ftplugin/text.vim +++ b/vim/ftplugin/text.vim @@ -1,11 +1,6 @@ " Spellcheck documents by default if has('syntax') setlocal spell - - " Undo - if !exists('b:undo_ftplugin') - let b:undo_ftplugin = '' - endif - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal spell<' + let b:undo_user_ftplugin + \ = 'setlocal spell<' endif |