From 670c735799879ae066b9a5249356a4d872514951 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 17 Jun 2018 11:53:31 +1200 Subject: Use autoload function for temp-makeprg :lmake --- vim/after/ftplugin/html/lint.vim | 25 ++++++------------------- vim/after/ftplugin/perl/check.vim | 25 ++++++------------------- vim/after/ftplugin/perl/lint.vim | 25 ++++++------------------- vim/after/ftplugin/php/check.vim | 34 ++++++---------------------------- vim/after/ftplugin/sh/check.vim | 36 +++++++++++++----------------------- vim/after/ftplugin/sh/lint.vim | 25 ++++++------------------- vim/after/ftplugin/vim/lint.vim | 25 ++++++------------------- vim/after/ftplugin/zsh/check.vim | 25 ++++++------------------- vim/autoload/compiler.vim | 11 +++++++++++ 9 files changed, 66 insertions(+), 165 deletions(-) create mode 100644 vim/autoload/compiler.vim (limited to 'vim') diff --git a/vim/after/ftplugin/html/lint.vim b/vim/after/ftplugin/html/lint.vim index a3776d60..0b56e73c 100644 --- a/vim/after/ftplugin/html/lint.vim +++ b/vim/after/ftplugin/html/lint.vim @@ -15,33 +15,20 @@ if &filetype !=# 'html' finish endif +" Don't load if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_html_maps') + finish +endif + " Flag as loaded let b:did_ftplugin_html_lint = 1 let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_html_lint' -" Build function for linter -function! s:HtmlLint() - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - endif - compiler tidy - lmake! - lwindow - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - endif -endfunction - -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_html_maps') - finish -endif - " Define a mapping target nnoremap \ HtmlLint - \ :call HtmlLint() + \ :call compiler#Make('tidy') let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap HtmlLint' diff --git a/vim/after/ftplugin/perl/check.vim b/vim/after/ftplugin/perl/check.vim index e115b37f..f6f99f08 100644 --- a/vim/after/ftplugin/perl/check.vim +++ b/vim/after/ftplugin/perl/check.vim @@ -10,33 +10,20 @@ if exists('b:did_ftplugin_perl_check') finish endif +" Don't load if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_perl_maps') + finish +endif + " Flag as loaded let b:did_ftplugin_perl_check = 1 let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_perl_check' -" Build function for checker -function! s:PerlCheck() - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - endif - compiler perl - lmake! - lwindow - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - endif -endfunction - -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_perl_maps') - finish -endif - " Define a mapping target nnoremap \ PerlCheck - \ :call PerlCheck() + \ :call compiler#Make('perl') let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap PerlCheck' diff --git a/vim/after/ftplugin/perl/lint.vim b/vim/after/ftplugin/perl/lint.vim index 3e73ac9a..eaa6684c 100644 --- a/vim/after/ftplugin/perl/lint.vim +++ b/vim/after/ftplugin/perl/lint.vim @@ -10,33 +10,20 @@ if exists('b:did_ftplugin_perl_lint') finish endif +" Don't load if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_html_maps') + finish +endif + " Flag as loaded let b:did_ftplugin_perl_lint = 1 let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_perl_lint' -" Build function for linter -function! s:PerlLint() - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - endif - compiler perlcritic - lmake! - lwindow - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - endif -endfunction - -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_perl_maps') - finish -endif - " Define a mapping target nnoremap \ PerlLint - \ :call PerlLint() + \ :call compiler#Make('perlcritic') let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap PerlLint' diff --git a/vim/after/ftplugin/php/check.vim b/vim/after/ftplugin/php/check.vim index f211a642..9dc4c6a8 100644 --- a/vim/after/ftplugin/php/check.vim +++ b/vim/after/ftplugin/php/check.vim @@ -10,42 +10,20 @@ if exists('b:did_ftplugin_php_check') finish endif +" Don't load if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_php_maps') + finish +endif + " Flag as loaded let b:did_ftplugin_php_check = 1 let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_php_check' -" Build function for checker -function! s:PhpCheck() - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - endif - compiler php - - " The PHP compiler is unusual: it gets us to provide the filename argument - " ourselves. 7.4.191 is the earliest version with the :S file name modifier, - " which we really should use if we can - if v:version >= 704 || v:version == 704 && has('patch191') - lmake! %:S - else - lmake! % - endif - lwindow - - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - endif -endfunction - -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_php_maps') - finish -endif - " Define a mapping target nnoremap \ PhpCheck - \ :call PhpCheck() + \ :call compiler#Make('php') let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap PhpCheck' diff --git a/vim/after/ftplugin/sh/check.vim b/vim/after/ftplugin/sh/check.vim index e92409cf..499926f3 100644 --- a/vim/after/ftplugin/sh/check.vim +++ b/vim/after/ftplugin/sh/check.vim @@ -10,39 +10,29 @@ if exists('b:did_ftplugin_sh_check') finish endif +" Stop here if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_sh_maps') + finish +endif + " Flag as loaded let b:did_ftplugin_sh_check = 1 let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_sh_check' -" Build function for checker -function! s:ShCheck() - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - endif - if exists('b:is_bash') - compiler bash - elseif exists('b:is_kornshell') - compiler ksh - else - compiler sh - endif - lmake! - lwindow - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - endif -endfunction - -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_sh_maps') - finish +" Choose compiler based on file subtype +if exists('b:is_bash') + let b:sh_check_compiler = 'bash' +elseif exists('b:is_kornshell') + let b:sh_check_compiler = 'ksh' +else + let b:sh_check_compiler = 'sh' endif " Define a mapping target nnoremap \ ShCheck - \ :call ShCheck() + \ :call compiler#Make(b:sh_check_compiler) let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap ShCheck' diff --git a/vim/after/ftplugin/sh/lint.vim b/vim/after/ftplugin/sh/lint.vim index 87f1c07e..65fe003d 100644 --- a/vim/after/ftplugin/sh/lint.vim +++ b/vim/after/ftplugin/sh/lint.vim @@ -10,33 +10,20 @@ if exists('b:did_ftplugin_sh_lint') finish endif +" Don't load if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_sh_maps') + finish +endif + " Flag as loaded let b:did_ftplugin_sh_lint = 1 let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_sh_lint' -" Build function for linter -function! s:ShLint() - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - endif - compiler shellcheck - lmake! - lwindow - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - endif -endfunction - -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_sh_maps') - finish -endif - " Define a mapping target nnoremap \ ShLint - \ :call ShLint() + \ :call compiler#Make('shellcheck') let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap ShLint' diff --git a/vim/after/ftplugin/vim/lint.vim b/vim/after/ftplugin/vim/lint.vim index 1e4f7d39..bd8c1da4 100644 --- a/vim/after/ftplugin/vim/lint.vim +++ b/vim/after/ftplugin/vim/lint.vim @@ -10,33 +10,20 @@ if exists('b:did_ftplugin_vim_lint') finish endif +" Don't load if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_vim_maps') + finish +endif + " Flag as loaded let b:did_ftplugin_vim_lint = 1 let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_vim_lint' -" Build function for linter -function! s:VimLint() - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - endif - compiler vint - lmake! - lwindow - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - endif -endfunction - -" Stop here if the user doesn't want ftplugin mappings -if exists('g:no_plugin_maps') || exists('g:no_vim_maps') - finish -endif - " Define a mapping target nnoremap \ VimLint - \ :call VimLint() + \ :call compiler#Make('vint') let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap VimLint' diff --git a/vim/after/ftplugin/zsh/check.vim b/vim/after/ftplugin/zsh/check.vim index 1d327a62..3e5ad7c6 100644 --- a/vim/after/ftplugin/zsh/check.vim +++ b/vim/after/ftplugin/zsh/check.vim @@ -10,33 +10,20 @@ if exists('b:did_ftplugin_zsh_check') finish endif +" Don't load if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_zsh_maps') + finish +endif + " Flag as loaded let b:did_ftplugin_zsh_check = 1 let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_zsh_check' -" Build function for checker -function! s:ZshCheck() - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - endif - compiler zsh - lmake! - lwindow - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - endif -endfunction - -" Set up a mapping for the checker, if we're allowed -if exists('g:no_plugin_maps') || exists('g:no_zsh_maps') - finish -endif - " Define a mapping target nnoremap \ ZshCheck - \ :call ZshCheck() + \ :call compiler#Make('zsh') let b:undo_ftplugin = b:undo_ftplugin \ . '|nunmap ZshCheck' diff --git a/vim/autoload/compiler.vim b/vim/autoload/compiler.vim new file mode 100644 index 00000000..37e46275 --- /dev/null +++ b/vim/autoload/compiler.vim @@ -0,0 +1,11 @@ +function! compiler#Make(compiler) abort + if exists('b:current_compiler') + let l:save_compiler = b:current_compiler + endif + execute 'compiler ' . a:compiler + lmake! + lwindow + if exists('l:save_compiler') + execute 'compiler ' . l:save_compiler + endif +endfunction -- cgit v1.2.3