From 0388a3468f7531b8a02c0fcbec873500f2135441 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 2 Jun 2018 17:28:30 +1200 Subject: Use consistent plugin and file names --- README.markdown | 4 +- doc/toggle_option_flag.txt | 30 ------------ doc/toggle_option_flags.txt | 30 ++++++++++++ plugin/toggle_option_flag.vim | 104 ----------------------------------------- plugin/toggle_option_flags.vim | 104 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 136 deletions(-) delete mode 100644 doc/toggle_option_flag.txt create mode 100644 doc/toggle_option_flags.txt delete mode 100644 plugin/toggle_option_flag.vim create mode 100644 plugin/toggle_option_flags.vim diff --git a/README.markdown b/README.markdown index 0203257..6333e16 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,5 @@ -toggle\_option\_flag.vim -======================== +toggle\_option\_flags.vim +========================= This plugin provides `:ToggleOptionFlag` and `:ToggleOptionFlagLocal` commands to toggle the values of options like `'formatoptions'` or `'complete'` that diff --git a/doc/toggle_option_flag.txt b/doc/toggle_option_flag.txt deleted file mode 100644 index a421da3..0000000 --- a/doc/toggle_option_flag.txt +++ /dev/null @@ -1,30 +0,0 @@ -*toggle_option_flag.txt* For Vim version 7.0 Last change: 2018 May 30 - -DESCRIPTION *toggle_option_flag* - - *:ToggleOptionFlag* *:ToggleOptionFlagLocal* -This plugin provides `:ToggleOptionFlag` and `:ToggleOptionFlagLocal` commands -to toggle the values of options like |'formatoptions'| or |'complete'| that -have values comprised of single-character or comma-separated flags. The author -originally designed it for toggling flags in |'formatoptions'| quickly. - -EXAMPLES *toggle_option_flag-examples* -> - :ToggleOptionFlag formatoptions a - :ToggleOptionFlag switchbuf useopen - :ToggleOptionFlagLocal shortmess I -< -REQUIREMENTS *toggle_option_flag-requirements* - -This plugin is only available if 'compatible' is not set. It also requires the -|+user_commands| Vim feature. - -AUTHOR *toggle_option_flag-author* - -Written and maintained by Tom Ryder . - -LICENSE *toggle_option_flag-license* - -Licensed for distribution under the same terms as Vim itself (see |license|). - - vim:tw=78:ts=8:ft=help:norl: diff --git a/doc/toggle_option_flags.txt b/doc/toggle_option_flags.txt new file mode 100644 index 0000000..0ab9e72 --- /dev/null +++ b/doc/toggle_option_flags.txt @@ -0,0 +1,30 @@ +*toggle_option_flags.txt* For Vim version 7.0 Last change: 2018 May 30 + +DESCRIPTION *toggle_option_flags* + + *:ToggleOptionFlag* *:ToggleOptionFlagLocal* +This plugin provides `:ToggleOptionFlag` and `:ToggleOptionFlagLocal` commands +to toggle the values of options like |'formatoptions'| or |'complete'| that +have values comprised of single-character or comma-separated flags. The author +originally designed it for toggling flags in |'formatoptions'| quickly. + +EXAMPLES *toggle_option_flags-examples* +> + :ToggleOptionFlag formatoptions a + :ToggleOptionFlag switchbuf useopen + :ToggleOptionFlagLocal shortmess I +< +REQUIREMENTS *toggle_option_flags-requirements* + +This plugin is only available if 'compatible' is not set. It also requires the +|+user_commands| Vim feature. + +AUTHOR *toggle_option_flags-author* + +Written and maintained by Tom Ryder . + +LICENSE *toggle_option_flags-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/toggle_option_flag.vim b/plugin/toggle_option_flag.vim deleted file mode 100644 index bc7ccd7..0000000 --- a/plugin/toggle_option_flag.vim +++ /dev/null @@ -1,104 +0,0 @@ -" -" toggle_option_flag.vim: Provide commands to toggle flags in grouped options -" like 'formatoptions', 'shortmess', 'complete', 'switchbuf', etc. -" -" Author: Tom Ryder -" License: Same as Vim itself -" -if exists('g:loaded_toggle_option_flag') || &compatible - finish -endif -if !has('user_commands') - finish -endif -let g:loaded_toggle_option_flag = 1 - -" Show an error-highlighted message and beep, but without a real :echoerr -function! s:Error(message) - execute 'normal! \' - echohl ErrorMsg - echomsg a:message - echohl None -endfunction - -" Test whether an option currently has a flag as part of its value -function! s:Has(option, flag) - - " Horrible :execute to get the option's current setting into a variable - " (I couldn't get {curly braces} indirection to work) - let l:current = '' - execute 'let l:current = &' . a:option - - " If the flag we're toggling is longer than one character, this must by - " necessity be a delimited option. I think all of those in VimL are - " comma-separated. Extend the flag and value so that they'll still match at - " the start and end. Otherwise, use them as-is. - if strlen(a:flag) > 1 - let l:search_flag = ',' . a:flag . ',' - let l:search_value = ',' . l:current . ',' - else - let l:search_flag = a:flag - let l:search_value = l:current - endif - - " Return whether - return stridx(l:search_value, l:search_flag) > -1 - -endfunction - -" Internal function to do the toggling -function! s:Toggle(option, flag, local) - - " Check for spurious option strings, we don't want to :execute anything funny - if a:option =~# '\m\L' - call s:Error('Illegal option name') - return 0 - endif - - " Check the option actually exists - if !exists('&' . a:option) - call s:Error('No such option: ' . a:option) - return 0 - endif - - " Choose which set command to use - let l:set = a:local - \ ? 'setlocal' - \ : 'set' - - " Find whether the flag is set before the change - let l:before = s:Has(a:option, a:flag) - - " Assign -= or += as the operation to run based on whether the flag already - " appears in the option value or not - let l:operation = l:before - \ ? '-=' - \ : '+=' - - " Try to set the option; suppress errors, we'll check our work - silent! execute l:set - \ . ' ' - \ . a:option . l:operation . escape(a:flag, '\ ') - - " Find whether the flag is set after the change - let l:after = s:Has(a:option, a:flag) - - " If we made a difference, report the new value; if we didn't, admit it - if l:before != l:after - execute l:set . ' ' . a:option . '?' - else - call s:Error('Unable to toggle '.a:option.' flag '.a:flag) - endif - - " Return value is whether we made a change - return l:before != l:after - -endfunction - -" User commands wrapping around calls to the above function -command -nargs=+ -complete=option - \ ToggleOptionFlag - \ call Toggle(, 0) -command -nargs=+ -complete=option - \ ToggleOptionFlagLocal - \ call Toggle(, 1) diff --git a/plugin/toggle_option_flags.vim b/plugin/toggle_option_flags.vim new file mode 100644 index 0000000..1a639f4 --- /dev/null +++ b/plugin/toggle_option_flags.vim @@ -0,0 +1,104 @@ +" +" toggle_option_flags.vim: Provide commands to toggle flags in grouped options +" like 'formatoptions', 'shortmess', 'complete', 'switchbuf', etc. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if exists('g:loaded_toggle_option_flags') || &compatible + finish +endif +if !has('user_commands') + finish +endif +let g:loaded_toggle_option_flags = 1 + +" Show an error-highlighted message and beep, but without a real :echoerr +function! s:Error(message) + execute 'normal! \' + echohl ErrorMsg + echomsg a:message + echohl None +endfunction + +" Test whether an option currently has a flag as part of its value +function! s:Has(option, flag) + + " Horrible :execute to get the option's current setting into a variable + " (I couldn't get {curly braces} indirection to work) + let l:current = '' + execute 'let l:current = &' . a:option + + " If the flag we're toggling is longer than one character, this must by + " necessity be a delimited option. I think all of those in VimL are + " comma-separated. Extend the flag and value so that they'll still match at + " the start and end. Otherwise, use them as-is. + if strlen(a:flag) > 1 + let l:search_flag = ',' . a:flag . ',' + let l:search_value = ',' . l:current . ',' + else + let l:search_flag = a:flag + let l:search_value = l:current + endif + + " Return whether + return stridx(l:search_value, l:search_flag) > -1 + +endfunction + +" Internal function to do the toggling +function! s:Toggle(option, flag, local) + + " Check for spurious option strings, we don't want to :execute anything funny + if a:option =~# '\m\L' + call s:Error('Illegal option name') + return 0 + endif + + " Check the option actually exists + if !exists('&' . a:option) + call s:Error('No such option: ' . a:option) + return 0 + endif + + " Choose which set command to use + let l:set = a:local + \ ? 'setlocal' + \ : 'set' + + " Find whether the flag is set before the change + let l:before = s:Has(a:option, a:flag) + + " Assign -= or += as the operation to run based on whether the flag already + " appears in the option value or not + let l:operation = l:before + \ ? '-=' + \ : '+=' + + " Try to set the option; suppress errors, we'll check our work + silent! execute l:set + \ . ' ' + \ . a:option . l:operation . escape(a:flag, '\ ') + + " Find whether the flag is set after the change + let l:after = s:Has(a:option, a:flag) + + " If we made a difference, report the new value; if we didn't, admit it + if l:before != l:after + execute l:set . ' ' . a:option . '?' + else + call s:Error('Unable to toggle '.a:option.' flag '.a:flag) + endif + + " Return value is whether we made a change + return l:before != l:after + +endfunction + +" User commands wrapping around calls to the above function +command -nargs=+ -complete=option + \ ToggleOptionFlag + \ call Toggle(, 0) +command -nargs=+ -complete=option + \ ToggleOptionFlagLocal + \ call Toggle(, 1) -- cgit v1.2.3 From d72e027191b2f2ec958299e206b4597325cdcfc8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 2 Jun 2018 17:33:35 +1200 Subject: Add VERSION --- VERSION | 1 + 1 file changed, 1 insertion(+) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..0ea3a94 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.2.0 -- cgit v1.2.3