From 61d05839a42b56c0759264b493f98d5a516affc4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 13:38:10 +1300 Subject: 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. --- vim/indent/csv.vim | 9 ++------- vim/indent/tsv.vim | 9 ++------- vim/indent/vim.vim | 10 +++++----- 3 files changed, 9 insertions(+), 19 deletions(-) (limited to 'vim/indent') diff --git a/vim/indent/csv.vim b/vim/indent/csv.vim index 24ef53ce..682bc3a8 100644 --- a/vim/indent/csv.vim +++ b/vim/indent/csv.vim @@ -1,10 +1,5 @@ " Manual indenting and literal tabs for CSVs setlocal noautoindent setlocal noexpandtab - -" Undo -if !exists('b:undo_indent') - let b:undo_indent = '' -endif -let b:undo_indent = b:undo_indent - \ . '|setlocal autoindent< expandtab<' +let b:undo_user_indent + \ = 'setlocal autoindent< expandtab<' diff --git a/vim/indent/tsv.vim b/vim/indent/tsv.vim index 161fbbe3..951b3e60 100644 --- a/vim/indent/tsv.vim +++ b/vim/indent/tsv.vim @@ -1,10 +1,5 @@ " Manual indenting and literal tabs for TSVs setlocal noautoindent setlocal noexpandtab - -" Undo -if !exists('b:undo_indent') - let b:undo_indent = '' -endif -let b:undo_indent = b:undo_indent - \ . '|setlocal autoindent< expandtab<' +let b:undo_user_indent + \ = 'setlocal autoindent< expandtab<' diff --git a/vim/indent/vim.vim b/vim/indent/vim.vim index f9a8f211..047a353d 100644 --- a/vim/indent/vim.vim +++ b/vim/indent/vim.vim @@ -3,9 +3,9 @@ setlocal shiftwidth=2 setlocal softtabstop=2 setlocal tabstop=2 -" Undo -if !exists('b:undo_indent') - let b:undo_indent = '' +" Ancient Vim can't use the '<' suffix syntax for resetting local integer +" options +if v:version > 700 + let b:undo_user_indent + \ = 'setlocal shiftwidth< softtabstop< tabstop<' endif -let b:undo_indent = b:undo_indent - \ . '|setlocal shiftwidth< softtabstop< tabstop<' -- cgit v1.2.3