From 91c83b92cd6c051b732f03e06955b7e2af9bef9e Mon Sep 17 00:00:00 2001 From: Dan Church Date: Wed, 1 Nov 2023 13:19:16 -0500 Subject: [PATCH 1/2] Change default keymap add behavior to respect no_plugin_maps This is what the system ftplugin scripts that ship with Vim test for before installing their own keymaps. --- plugin/rubocop.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index 2d98d4e..bc22067 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -29,7 +29,7 @@ if !exists('g:vimrubocop_extra_args') endif if !exists('g:vimrubocop_keymap') - let g:vimrubocop_keymap = 1 + let g:vimrubocop_keymap = !exists('no_plugin_maps') endif let s:rubocop_switches = ['-l', '--lint', '-R', '--rails', '-a', '--auto-correct'] From 7ec21044e3ec328ecac62d5bb2e05cc0b4829c07 Mon Sep 17 00:00:00 2001 From: Dan Church Date: Wed, 1 Nov 2023 13:24:00 -0500 Subject: [PATCH 2/2] Use get(g:, ...) to read config Don't pollute global variable space with this plugin's config if we don't have to. get( {list}, {idx}, {def} ) has been part of Vim since version 7.0033 (2005-01-07). --- plugin/rubocop.vim | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index bc22067..830d652 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -15,23 +15,6 @@ let g:loaded_vimrubocop = 1 let s:save_cpo = &cpo set cpo&vim -if !exists('g:vimrubocop_rubocop_cmd') - let g:vimrubocop_rubocop_cmd = 'rubocop ' -endif - -" Options -if !exists('g:vimrubocop_config') - let g:vimrubocop_config = '' -endif - -if !exists('g:vimrubocop_extra_args') - let g:vimrubocop_extra_args = '' -endif - -if !exists('g:vimrubocop_keymap') - let g:vimrubocop_keymap = !exists('no_plugin_maps') -endif - let s:rubocop_switches = ['-l', '--lint', '-R', '--rails', '-a', '--auto-correct'] function! s:RuboCopSwitches(...) @@ -39,11 +22,11 @@ function! s:RuboCopSwitches(...) endfunction function! s:RuboCop(current_args) - let l:extra_args = g:vimrubocop_extra_args + let l:extra_args = get(g:, 'vimrubocop_extra_args', '') let l:filename = @% - let l:rubocop_cmd = g:vimrubocop_rubocop_cmd + let l:rubocop_cmd = get(g:, 'vimrubocop_rubocop_cmd', 'rubocop ') let l:rubocop_opts = ' '.a:current_args.' '.l:extra_args.' --format emacs' - if g:vimrubocop_config != '' + if get(g:, 'vimrubocop_config', '') != '' let l:rubocop_opts = ' '.l:rubocop_opts.' --config '.g:vimrubocop_config endif @@ -71,7 +54,7 @@ endfunction command! -complete=custom,s:RuboCopSwitches -nargs=? RuboCop :call RuboCop() " Shortcuts for RuboCop -if g:vimrubocop_keymap == 1 +if get(g:, 'vimrubocop_keymap', !exists('no_plugin_maps')) nmap ru :RuboCop endif