From 950f883d89ca0fa7e80cca8f9a0d8cfbade8ebc3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 9 Jul 2018 01:15:22 +1200 Subject: Overhaul ftplugin check, lint, tidy - Set 'equalprg' for HTML and Perl - Discard filter#Stable() - Set default :compiler for all applicable filetypes - Change local leader mappings for Perl and shell script merely to set :compiler, rather than running it - Bind global leader mapping for running :lmake! - Bind global leader mappings for applying 'equalprg' and 'formatprg' to the whole buffer, using a new autoloaded helper function vimrc#Anchor() to avoid the cursor jumping around --- vim/after/ftplugin/gitcommit.vim | 10 +++------- vim/after/ftplugin/html.vim | 24 ++++++++++++++---------- vim/after/ftplugin/perl.vim | 17 +++++++++++------ vim/after/ftplugin/php.vim | 12 ++++++------ vim/after/ftplugin/sh.vim | 21 ++++++++++++--------- vim/after/ftplugin/vim.vim | 12 ++++++------ vim/after/ftplugin/zsh.vim | 13 ++++--------- 7 files changed, 56 insertions(+), 53 deletions(-) (limited to 'vim/after/ftplugin') diff --git a/vim/after/ftplugin/gitcommit.vim b/vim/after/ftplugin/gitcommit.vim index 035b835c..e55ebff7 100644 --- a/vim/after/ftplugin/gitcommit.vim +++ b/vim/after/ftplugin/gitcommit.vim @@ -6,10 +6,6 @@ endif " Make angle brackets behave like mail quotes setlocal comments+=n:> setlocal formatoptions+=coqr - -" Add to undo script -if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal comments<' - \ . '|setlocal formatoptions<' -endif +let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal comments<' + \ . '|setlocal formatoptions<' diff --git a/vim/after/ftplugin/html.vim b/vim/after/ftplugin/html.vim index 545076b1..3a08d110 100644 --- a/vim/after/ftplugin/html.vim +++ b/vim/after/ftplugin/html.vim @@ -3,11 +3,21 @@ if &filetype != 'html' || &compatible || v:version < 700 finish endif +" Use tidy(1) for checking and program formatting +compiler tidy +setlocal equalprg=tidy\ -quiet +let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal equalprg<' + \ . '|setlocal errorformat<' + \ . '|setlocal makeprg<' + " Set up hooks for timestamp updating -autocmd html_timestamp BufWritePre - \ if exists('b:html_timestamp_check') - \| call html#TimestampUpdate() - \|endif +augroup html_timestamp + autocmd BufWritePre + \ if exists('b:html_timestamp_check') + \| call html#TimestampUpdate() + \|endif +augroup END let b:undo_ftplugin = b:undo_ftplugin \ . '|autocmd! html_timestamp BufWritePre ' @@ -17,13 +27,7 @@ if exists('g:no_plugin_maps') || exists('g:no_html_maps') endif " Set mappings -nnoremap l - \ :call compiler#Make('tidy') nnoremap r \ :call html#UrlLink() -nnoremap t - \ :call filter#Stable('tidy -quiet') let b:undo_ftplugin = b:undo_ftplugin - \ . '|nunmap l' \ . '|nunmap r' - \ . '|nunmap t' diff --git a/vim/after/ftplugin/perl.vim b/vim/after/ftplugin/perl.vim index 8887b56a..564653d2 100644 --- a/vim/after/ftplugin/perl.vim +++ b/vim/after/ftplugin/perl.vim @@ -3,22 +3,27 @@ if &filetype != 'perl' || &compatible || v:version < 700 finish endif +" Use Perl itself for checking and Perl::Tidy for tidying +compiler perl +setlocal equalprg=perltidy +let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal equalprg<' + \ . '|setlocal errorformat<' + \ . '|setlocal makeprg<' + " Stop here if the user doesn't want ftplugin mappings if exists('g:no_plugin_maps') || exists('g:no_perl_maps') finish endif -" Set mappings +" Mappings to choose compiler nnoremap c - \ :call compiler#Make('perl') + \ :compiler perl nnoremap l - \ :call compiler#Make('perlcritic') -nnoremap t - \ :call filter#Stable('perltidy') + \ :compiler perlcritic let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap c' \ . '|nunmap l' - \ . '|nunmap t' " Bump version numbers nmap v diff --git a/vim/after/ftplugin/php.vim b/vim/after/ftplugin/php.vim index 35849ac5..1f40aba7 100644 --- a/vim/after/ftplugin/php.vim +++ b/vim/after/ftplugin/php.vim @@ -3,6 +3,12 @@ if &filetype != 'php' || &compatible || v:version < 700 finish endif +" Use PHP itself for syntax checking +compiler php +let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal errorformat<' + \ . '|setlocal makeprg<' + " Set comment formats setlocal comments=s1:/*,m:*,ex:*/,://,:# setlocal formatoptions+=or @@ -15,12 +21,6 @@ if exists('g:no_plugin_maps') || exists('g:no_php_maps') finish endif -" Set mappings -nnoremap c - \ :call compiler#Make('php') -let b:undo_ftplugin = b:undo_ftplugin - \ . '|nunmap c' - " Get rid of the core ftplugin's square-bracket maps on unload let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap [[' diff --git a/vim/after/ftplugin/sh.vim b/vim/after/ftplugin/sh.vim index 086e23d5..01505a88 100644 --- a/vim/after/ftplugin/sh.vim +++ b/vim/after/ftplugin/sh.vim @@ -17,11 +17,6 @@ if exists('b:is_bash') \ . '|setlocal keywordprg<' endif -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_sh_maps') - finish -endif - " Choose check compiler based on file subtype if exists('b:is_bash') let b:sh_check_compiler = 'bash' @@ -30,14 +25,22 @@ elseif exists('b:is_kornshell') else let b:sh_check_compiler = 'sh' endif +execute 'compiler '.b:sh_check_compiler let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:sh_check_compiler' + \ . '|setlocal errorformat<' + \ . '|setlocal makeprg<' + +" Stop here if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_sh_maps') + finish +endif -" Set mappings -nnoremap c - \ :call compiler#Make(b:sh_check_compiler) +" Mappings to choose compiler +nnoremap c + \ ':compiler '.b:sh_check_compiler.'' nnoremap l - \ :call compiler#Make('shellcheck') + \ :compiler shellcheck let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap c' \ . '|nunmap l' diff --git a/vim/after/ftplugin/vim.vim b/vim/after/ftplugin/vim.vim index e01e2050..bd0a83ce 100644 --- a/vim/after/ftplugin/vim.vim +++ b/vim/after/ftplugin/vim.vim @@ -3,17 +3,17 @@ if &filetype != 'vim' || &compatible || v:version < 700 finish endif +" Use Vint as a syntax checker +compiler vint +let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal errorformat<' + \ . '|setlocal makeprg<' + " Stop here if the user doesn't want ftplugin mappings if exists('g:no_plugin_maps') || exists('g:no_vim_maps') finish endif -" Set mappings -nnoremap l - \ :call compiler#Make('vint') -let b:undo_ftplugin = b:undo_ftplugin - \ . '|nunmap l' - " Get rid of the core ftplugin's square-bracket maps on unload let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap [[' diff --git a/vim/after/ftplugin/zsh.vim b/vim/after/ftplugin/zsh.vim index 79f3c638..d5852e53 100644 --- a/vim/after/ftplugin/zsh.vim +++ b/vim/after/ftplugin/zsh.vim @@ -3,13 +3,8 @@ if &filetype != 'zsh' || &compatible || v:version < 700 finish endif -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_zsh_maps') - finish -endif - -" Set mappings -nnoremap c - \ :call compiler#Make('zsh') +" Use Z shell itself as a syntax checker +compiler zsh let b:undo_ftplugin = b:undo_ftplugin - \ . '|nunmap c' + \ . '|setlocal errorformat<' + \ . '|setlocal makeprg<' -- cgit v1.2.3