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 ++++--------- vim/autoload/compiler.vim | 33 --------------------------------- vim/autoload/filter.vim | 7 ------- vim/autoload/vimrc.vim | 6 ++++++ vim/vimrc | 7 +++++++ 11 files changed, 69 insertions(+), 93 deletions(-) delete mode 100644 vim/autoload/compiler.vim delete mode 100644 vim/autoload/filter.vim create mode 100644 vim/autoload/vimrc.vim (limited to 'vim') 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<' diff --git a/vim/autoload/compiler.vim b/vim/autoload/compiler.vim deleted file mode 100644 index b4bf66b6..00000000 --- a/vim/autoload/compiler.vim +++ /dev/null @@ -1,33 +0,0 @@ -" Run a compiler check (:lmake, :lwindow) without trampling over previous -" settings, by temporarily loading the compiler with the given name -function! compiler#Make(compiler) abort - - " Save the given compiler or failing that the current 'makeprg' and - " 'errorformat' values - if exists('b:current_compiler') - let l:save_compiler = b:current_compiler - else - let l:save_makeprg = &makeprg - let l:save_errorformat = &errorformat - endif - - " Choose the compiler - execute 'compiler ' . a:compiler - - " Run the 'makeprg' with results in location list - lmake! - - " If we saved a compiler, switch back to it, otherwise restore the previous - " values for 'makeprg' and 'errorformat' - if exists('l:save_compiler') - execute 'compiler ' . l:save_compiler - else - unlet! b:current_compiler - let &l:makeprg = l:save_makeprg - let &l:errorformat = l:save_errorformat - endif - - " Show location list - lwindow - -endfunction diff --git a/vim/autoload/filter.vim b/vim/autoload/filter.vim deleted file mode 100644 index 0a39f23a..00000000 --- a/vim/autoload/filter.vim +++ /dev/null @@ -1,7 +0,0 @@ -" Run a filter over the entire buffer, but save the window position and -" restore it after doing so -function! filter#Stable(command) abort - let l:view = winsaveview() - execute '%!' . a:command - call winrestview(l:view) -endfunction diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim new file mode 100644 index 00000000..0dff8ffd --- /dev/null +++ b/vim/autoload/vimrc.vim @@ -0,0 +1,6 @@ +" Run some normal-mode keystrokes without jumping around +function! vimrc#Anchor(keys) abort + let l:view = winsaveview() + execute 'normal! '.a:keys + call winrestview(l:view) +endfunction diff --git a/vim/vimrc b/vim/vimrc index 312b982f..c08ec677 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -285,6 +285,13 @@ nnoremap y :registers " \z sets NZ English spelling (compare \u) nnoremap z :setlocal spelllang=en_nz +" \= runs the whole buffer through =, preserving position +nnoremap = :call vimrc#Anchor('1G=G') +" \+ runs the whole buffer through gq, preserving position +nnoremap + :call vimrc#Anchor('1GgqG') +" \. runs the configured make program to location list +nnoremap . :lmake! + " \DEL deletes the current buffer nnoremap :bdelete " \INS edits a new buffer -- cgit v1.2.3