From 85b05425ed3be65439fefa5f0074d3d7f18217f9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 17:33:06 +1300 Subject: Don't suggest mappings in Vim plugin comments Pretty useless, really. --- vim/autoload/flag_toggle.vim | 54 ++++++++++++++++++++++++++++++++ vim/plugin/copy_linebreak.vim | 2 -- vim/plugin/fixed_join.vim | 2 -- vim/plugin/option_flags.vim | 54 -------------------------------- vim/plugin/strip_trailing_whitespace.vim | 2 -- 5 files changed, 54 insertions(+), 60 deletions(-) create mode 100644 vim/autoload/flag_toggle.vim delete mode 100644 vim/plugin/option_flags.vim diff --git a/vim/autoload/flag_toggle.vim b/vim/autoload/flag_toggle.vim new file mode 100644 index 00000000..10739149 --- /dev/null +++ b/vim/autoload/flag_toggle.vim @@ -0,0 +1,54 @@ +" +" option_flags.vim: Provide functions to toggle flags in single-char grouped +" options like 'formatoptions', 'shortmess', 'complete' etc. +" +" This will fail hilariously if you try to set e.g. 'switchbuf' with it! +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if has('eval') + + " Public wrapper function to toggle a flag with 'set' + function! option_flags#toggle(option, flag) + call s:toggle(a:option, a:flag, 0) + endfunction + + " Public wrapper function to toggle a flag with 'setlocal' + function! option_flags#toggle_local(option, flag) + call s:toggle(a:option, a:flag, 1) + endfunction + + " Internal function to do the toggling + function! s:toggle(option, flag, local) + + " Check for weird options, we don't want to eval() anything funny + if a:option =~# '[^a-z]' + echoerr 'Illegal option name' + return + endif + + " Weird flags, too; should be a single inoffensive char + if a:flag !~# '^[a-z0-9.]$' + echoerr 'Illegal flag' + return + endif + + " Choose which set command to use + if a:local + let l:set = 'setlocal ' + else + let l:set = 'set ' + endif + + " Use eval() to assign -= or += to l:op for the option toggle + " (I couldn't get {curly braces} indirection to work) + let l:op = '' + execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' + + " Use eval() to perform the option toggle and then print the value + execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' + + endfunction + +endif diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim index ac21b66d..cba2c866 100644 --- a/vim/plugin/copy_linebreak.vim +++ b/vim/plugin/copy_linebreak.vim @@ -3,7 +3,6 @@ " showbreak characters and breakindent mode on and off, for convenience of " copying multiple lines from terminal emulators. " -" Suggested mapping: b " if has('eval') @@ -30,7 +29,6 @@ if has('eval') endfunction " Provide mapping proxy to the function just defined - " Suggested mapping: b noremap CopyLinebreak \ :call CopyLinebreak() endif diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim index ef1b03ef..81e61614 100644 --- a/vim/plugin/fixed_join.vim +++ b/vim/plugin/fixed_join.vim @@ -1,6 +1,5 @@ " User-defined key mapping to keep cursor in place when joining lines in " normal mode -" Suggesting mapping: normal J if has('eval') " Declare function @@ -20,7 +19,6 @@ if has('eval') endfunction " Create mapping proxy to the function just defined - " Suggesting mapping: normal J noremap FixedJoin \ :call FixedJoin() endif diff --git a/vim/plugin/option_flags.vim b/vim/plugin/option_flags.vim deleted file mode 100644 index 10739149..00000000 --- a/vim/plugin/option_flags.vim +++ /dev/null @@ -1,54 +0,0 @@ -" -" option_flags.vim: Provide functions to toggle flags in single-char grouped -" options like 'formatoptions', 'shortmess', 'complete' etc. -" -" This will fail hilariously if you try to set e.g. 'switchbuf' with it! -" -" Author: Tom Ryder -" License: Same as Vim itself -" -if has('eval') - - " Public wrapper function to toggle a flag with 'set' - function! option_flags#toggle(option, flag) - call s:toggle(a:option, a:flag, 0) - endfunction - - " Public wrapper function to toggle a flag with 'setlocal' - function! option_flags#toggle_local(option, flag) - call s:toggle(a:option, a:flag, 1) - endfunction - - " Internal function to do the toggling - function! s:toggle(option, flag, local) - - " Check for weird options, we don't want to eval() anything funny - if a:option =~# '[^a-z]' - echoerr 'Illegal option name' - return - endif - - " Weird flags, too; should be a single inoffensive char - if a:flag !~# '^[a-z0-9.]$' - echoerr 'Illegal flag' - return - endif - - " Choose which set command to use - if a:local - let l:set = 'setlocal ' - else - let l:set = 'set ' - endif - - " Use eval() to assign -= or += to l:op for the option toggle - " (I couldn't get {curly braces} indirection to work) - let l:op = '' - execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' - - " Use eval() to perform the option toggle and then print the value - execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' - - endfunction - -endif diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index 6a83eb53..36e1d2ad 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -1,5 +1,4 @@ " User-defined key mapping to strip trailing whitespace in the whole document -" Suggested mapping: \x if has('eval') " Define function for stripping whitespace @@ -53,7 +52,6 @@ if has('eval') endfunction " Create mapping proxy to the function just defined - " Suggested mapping: x noremap StripTrailingWhitespace \ :call StripTrailingWhitespace() endif -- cgit v1.2.3