diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-04 22:41:15 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-04 22:41:15 +1300 |
commit | 1175a6d4338b43b8521617606f44a3c29a2ec0ff (patch) | |
tree | 2c15a1f3416f4c547fd1834e2991eb60c4cf18c9 /vim/plugin/fixed_join.vim | |
parent | Simplify shell linting code with single vars (diff) | |
download | dotfiles-1175a6d4338b43b8521617606f44a3c29a2ec0ff.tar.gz dotfiles-1175a6d4338b43b8521617606f44a3c29a2ec0ff.zip |
Add short-circuit boilerplate to plugins
Set a g:loaded_* flag to prevent repeated reloads, and refuse to load at
all if &compatible is set or if required features are missing.
Some more accommodating plugins avoid the problems 'compatible' causes
by saving its value at startup into a script variable, setting the
option to the Vim default, and then restoring it when the plugin is
done, to prevent any of its flags from interfering in the plugin code:
let s:save_cpo = &cpo
set cpo&vim
...
let &cpo = s:save_cpo
unlet s:save_cpo
I don't want this boilerplate, so I'm going to do what Tim Pope's
modules seem to, and just have the plugin refuse to do a single thing if
'compatible' is set.
Diffstat (limited to 'vim/plugin/fixed_join.vim')
-rw-r--r-- | vim/plugin/fixed_join.vim | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim index 5e3a5c2b..18f563f3 100644 --- a/vim/plugin/fixed_join.vim +++ b/vim/plugin/fixed_join.vim @@ -5,26 +5,29 @@ " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself " -if has('eval') +if exists('g:loaded_fixed_join') + \ || &compatible + finish +endif +let g:loaded_fixed_join = 1 - " Declare function - function! s:FixedJoin() +" Declare function +function! s:FixedJoin() - " Save current cursor position - let l:lc = line('.') - let l:cc = col('.') + " Save current cursor position + let l:lc = line('.') + let l:cc = col('.') - " Build and execute join command - let l:command = '.,+' . v:count1 . 'join' - execute l:command + " Build and execute join command + let l:command = '.,+' . v:count1 . 'join' + execute l:command - " Restore cursor position - call cursor(l:lc, l:cc) + " Restore cursor position + call cursor(l:lc, l:cc) - endfunction +endfunction - " Create mapping proxy to the function just defined - noremap <silent> <unique> - \ <Plug>FixedJoin - \ :<C-U>call <SID>FixedJoin()<CR> -endif +" Create mapping proxy to the function just defined +noremap <silent> <unique> + \ <Plug>FixedJoin + \ :<C-U>call <SID>FixedJoin()<CR> |