From 3a53baf2ca965e6c14c88bda075dacd550d3c0df Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 09:39:36 +1300 Subject: Complete ToggleOptionFlag commands with opt names Only a small subset of option names actually apply, so I'm not entirely sure this is actually better than nothing. --- vim/plugin/toggle_option_flag.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index ad89d080..f8dcd3a9 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -46,9 +46,9 @@ function! s:Toggle(option, flag, local) endfunction " User commands wrapping around calls to the above function -command! -nargs=+ +command! -nargs=+ -complete=option \ ToggleOptionFlag \ call Toggle(, 0) -command! -nargs=+ +command! -nargs=+ -complete=option \ ToggleOptionFlagLocal \ call Toggle(, 1) -- cgit v1.2.3 From a74f73043be2eb355e96311f5a4d01a915e024fe Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 09:41:52 +1300 Subject: Make background detection return not set value This approach allows more flexibility from the caller's side. --- vim/autoload/detect_background.vim | 7 +++++-- vim/config/syntax.vim | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim index e4fee199..9758f8d3 100644 --- a/vim/autoload/detect_background.vim +++ b/vim/autoload/detect_background.vim @@ -3,6 +3,9 @@ " light backgrounds; we'll default to choosing a dark background unless we " find some reason *not* to. " +" Return the string to which we think the option should be set, to allow the +" caller to use it as they see fit. +" " Author: Tom Ryder " License: Same as Vim itself " @@ -27,9 +30,9 @@ function! detect_background#DetectBackground() abort if l:bg ==# 'default' \ || l:bg ==# '7' \ || l:bg ==# '15' - set background=light + return 'light' else - set background=dark + return 'dark' endif endfunction diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim index 8cb1228b..f1116528 100644 --- a/vim/config/syntax.vim +++ b/vim/config/syntax.vim @@ -5,9 +5,11 @@ if has('syntax') silent! syntax enable silent! syntax sync minlines=100 - " If we can, detect a light background, but default to a dark one + " If we can, detect a light background, but default to a dark one. This is + " only because it's more likely the author of this configuration will be + " using one. if has('eval') && v:version >= 701 - silent! call detect_background#DetectBackground() + silent! let &background = detect_background#DetectBackground() else set background=dark endif -- cgit v1.2.3 From 62d652645dbe31f2e476a7bdcde18ba22445d555 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 09:43:32 +1300 Subject: Don't overwrite plugin-specified user commands The Google Vimscript Style Guide says: > Excluding [!] prevents your plugin from silently clobbering existing > commands. Command conflicts should be resolved by the user. This makes sense to me as we can think of mapping and user commands as being the user-accessible portion of the interface, rather than the functions which can be properly namespaced with autoload#Syntax(), if exposed at all. --- vim/plugin/command_typos.vim | 18 +++++++++--------- vim/plugin/toggle_option_flag.vim | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/vim/plugin/command_typos.vim b/vim/plugin/command_typos.vim index 16ba654d..adf2d0eb 100644 --- a/vim/plugin/command_typos.vim +++ b/vim/plugin/command_typos.vim @@ -14,30 +14,30 @@ endif let g:loaded_command_typos = 1 " Define commands -command! -bang -complete=file -nargs=? +command -bang -complete=file -nargs=? \ E \ edit -command! -bang -complete=file -nargs=? +command -bang -complete=file -nargs=? \ W \ write -command! -bang -complete=file -nargs=? +command -bang -complete=file -nargs=? \ WQ \ wq -command! -bang -complete=file -nargs=? +command -bang -complete=file -nargs=? \ Wq \ wq -command! -bang +command -bang \ Q \ quit -command! -bang +command -bang \ Qa \ qall -command! -bang +command -bang \ QA \ qall -command! -bang +command -bang \ Wa \ wall -command! -bang +command -bang \ WA \ wa diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index f8dcd3a9..2543b8c3 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -46,9 +46,9 @@ function! s:Toggle(option, flag, local) endfunction " User commands wrapping around calls to the above function -command! -nargs=+ -complete=option +command -nargs=+ -complete=option \ ToggleOptionFlag \ call Toggle(, 0) -command! -nargs=+ -complete=option +command -nargs=+ -complete=option \ ToggleOptionFlagLocal \ call Toggle(, 1) -- cgit v1.2.3 From 9927b230dd5ae7004f4d14ea9f684d06cd11a856 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 09:51:09 +1300 Subject: Don't use VimL ==# for number comparisons The Google VimScript Guide says: > Always use case-explicit operators for strings (=~# and =~?, never =~). > > This also applies to !~ == != > >= < and <= > This only applies for strings. == and >= are fine for numbers, but ==# > and >=# must be used for strings. --- vim/autoload/detect_background.vim | 4 ++-- vim/config/format.vim | 4 ++-- vim/vimrc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim index 9758f8d3..c010dc53 100644 --- a/vim/autoload/detect_background.vim +++ b/vim/autoload/detect_background.vim @@ -28,8 +28,8 @@ function! detect_background#DetectBackground() abort " Choose the background setting based on this value if l:bg ==# 'default' - \ || l:bg ==# '7' - \ || l:bg ==# '15' + \ || l:bg == 7 + \ || l:bg == 15 return 'light' else return 'dark' diff --git a/vim/config/format.vim b/vim/config/format.vim index 54d46dc2..1f24ee56 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -5,7 +5,7 @@ if has('eval') " Figure out if we have the 'j' flag for 'formatoptions', to automatically " delete comment leaders when joining lines; keep it in a script variable let s:formatoptions_has_j = v:version > 703 - \ || v:version ==# 703 && has('patch541') + \ || v:version == 703 && has('patch541') " If we do have 'j', default to setting it if s:formatoptions_has_j @@ -38,7 +38,7 @@ if has('eval') " 'textwidth' wrapping to the current paragraph on every insertion or " deletion; keep in a script variable let s:formatoptions_has_a = v:version > 610 - \ || v:version ==# 610 && has('patch142') + \ || v:version == 610 && has('patch142') " 'a' needs testing if s:formatoptions_has_a diff --git a/vim/vimrc b/vim/vimrc index 1730edd2..eab24946 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -16,7 +16,7 @@ if v:version >= 701 " The 'sahara' colorscheme only works for dark backgrounds with 256 colors if has('syntax') \ && &background ==# 'dark' - \ && (has('gui_running') || &t_Co ==# 256) + \ && (has('gui_running') || &t_Co == 256) silent! colorscheme sahara endif endif -- cgit v1.2.3 From 9ea61ae2122a7d87e89479d5a286b8af66e67b01 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 09:54:57 +1300 Subject: Remove \m\C prefix from inapplicable VimL regexes --- vim/plugin/strip_trailing_whitespace.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index ceeaec7c..677e51c5 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -30,11 +30,11 @@ function! s:StripTrailingWhitespace() " Replace the line with a subsitution of its text stripping extraneous " whitespace - call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g')) + call setline(l:li, substitute(l:line, '\s\+$', '', 'g')) " If this line has any non-whitespace characters on it, update l:lw with " its index - if l:line =~# '\m\C\S' + if l:line =~# '\S' let l:lw = l:li endif -- cgit v1.2.3 From ae2eb0590ec65e4c6e1830bbe7c64cd07052eb91 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 10:07:26 +1300 Subject: Move pipes from end to start of continued lines The Google Vimscript Guide says: > Place one space after the backslash denoting a line continuation. > > When continuing a multi-line command a pipe can be substituted for > this space as necessary, as follows: > > autocommand BufEnter > \ if !empty(s:var) > \| call some#function() > \|else > \| call some#function(s:var) > \|endif --- vim/ftdetect/sh.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vim/ftdetect/sh.vim b/vim/ftdetect/sh.vim index 3df9c3ce..f00a5659 100644 --- a/vim/ftdetect/sh.vim +++ b/vim/ftdetect/sh.vim @@ -5,19 +5,19 @@ augroup dotfiles_ftdetect_sh " Names/paths of things that are Bash shell script autocmd BufNewFile,BufRead \ **/.dotfiles/bash/**,bash-fc-* - \ let b:is_bash = 1 | - \ setfiletype sh + \ let b:is_bash = 1 + \ | setfiletype sh " Names/paths of things that are Korn shell script autocmd BufNewFile,BufRead \ **/.dotfiles/ksh/**,.kshrc,*.ksh - \ let b:is_kornshell = 1 | - \ setfiletype sh + \ let b:is_kornshell = 1 + \ | setfiletype sh " Names/paths of things that are POSIX shell script autocmd BufNewFile,BufRead \ **/.dotfiles/sh/**,.shinit,.shrc,.xinitrc,/etc/default/* - \ let b:is_posix = 1 | - \ setfiletype sh + \ let b:is_posix = 1 + \ | setfiletype sh augroup END -- cgit v1.2.3 From 04dcf0c24618ab0c3c2d0ac7dfed3178d409a0e3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:37:52 +1300 Subject: Caution about :execute not eval() in VimL comments May as well refer to the actual command I'm using. --- vim/config/substitution.vim | 2 +- vim/plugin/toggle_option_flag.vim | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/config/substitution.vim b/vim/config/substitution.vim index 415665ef..982d25f3 100644 --- a/vim/config/substitution.vim +++ b/vim/config/substitution.vim @@ -5,7 +5,7 @@ nnoremap \ :&& " Same again for visual mode; we use vnoremap rather than xnoremap to stay -" compatible with old Vims without doing eval() dances +" compatible with old Vims without doing :execute dances vnoremap \ & \ :&& diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index 2543b8c3..cbe8035e 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -17,7 +17,7 @@ let g:loaded_toggle_option_flag = 1 " Internal function to do the toggling function! s:Toggle(option, flag, local) - " Check for weird options, we don't want to eval() anything funny + " Check for weird options, we don't want to :execute anything funny if a:option =~# '[^a-z]' echoerr 'Illegal option name' return @@ -34,12 +34,12 @@ function! s:Toggle(option, flag, local) \ ? 'setlocal' \ : 'set' - " eval() to assign -= or += to l:op for the option toggle + " :execute 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 ? "-=" : "+="' - " eval() to perform the option toggle and then print the value + " :execute to perform the option toggle and then print the value execute l:set . ' ' . a:option . l:op . a:flag execute l:set . ' ' . a:option . '?' -- cgit v1.2.3 From 679f0d577f2cf0faa1b3cc5ef49f392904a1d42d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:38:24 +1300 Subject: Remove redundant has('eval') VimL test From what I understand from ":help if", ancient Vim and/or vim-tiny without the 'eval' feature will simply gloss over all commands between :if and :endif without executing them. Therefore as soon as we test a version, we're implicitly excluding everything that doesn't have 'eval' anyway. --- vim/config/syntax.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim index f1116528..b493c0a9 100644 --- a/vim/config/syntax.vim +++ b/vim/config/syntax.vim @@ -8,7 +8,7 @@ if has('syntax') " If we can, detect a light background, but default to a dark one. This is " only because it's more likely the author of this configuration will be " using one. - if has('eval') && v:version >= 701 + if v:version >= 701 silent! let &background = detect_background#DetectBackground() else set background=dark -- cgit v1.2.3 From f9e95b30a6dedb5f09ef904ae5d1993cd2d6115a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:40:20 +1300 Subject: Restore some judicious \m\C hedging in Vim These are technically not really needed, but this is more consistent with good style recommendations in the Google VimScript style guide. --- vim/plugin/strip_trailing_whitespace.vim | 4 ++-- vim/plugin/toggle_option_flag.vim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index 677e51c5..d5f5624a 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -30,11 +30,11 @@ function! s:StripTrailingWhitespace() " Replace the line with a subsitution of its text stripping extraneous " whitespace - call setline(l:li, substitute(l:line, '\s\+$', '', 'g')) + call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g')) " If this line has any non-whitespace characters on it, update l:lw with " its index - if l:line =~# '\S' + if l:line =~# '\m\S' let l:lw = l:li endif diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index cbe8035e..b63e0eb8 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -18,13 +18,13 @@ let g:loaded_toggle_option_flag = 1 function! s:Toggle(option, flag, local) " Check for weird options, we don't want to :execute anything funny - if a:option =~# '[^a-z]' + if a:option =~# '\m[^a-z]' echoerr 'Illegal option name' return endif " Weird flags, too; should be a single inoffensive char - if a:flag !~# '^[a-z0-9.]$' + if a:flag !~# '\m^[a-z0-9.]$' echoerr 'Illegal flag' return endif -- cgit v1.2.3 From 9fbceec83a5e1c0b7d34de217e7ef038985c695d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:42:14 +1300 Subject: Use idiomatic VimL regex for param validation \a and \L are, I think, perlre-style VimL regex inventions. --- vim/plugin/toggle_option_flag.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index b63e0eb8..c3ea01a0 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -18,13 +18,13 @@ let g:loaded_toggle_option_flag = 1 function! s:Toggle(option, flag, local) " Check for weird options, we don't want to :execute anything funny - if a:option =~# '\m[^a-z]' + if a:option =~# '\m\L' echoerr 'Illegal option name' return endif " Weird flags, too; should be a single inoffensive char - if a:flag !~# '\m^[a-z0-9.]$' + if a:flag !~# '\m^[\a.]$' echoerr 'Illegal flag' return endif -- cgit v1.2.3 From 553af93ba2f16c36e74c5dc1b6c9d434520cf712 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:49:11 +1300 Subject: Separate command building from execution in toggle These are functionally equivalent; it's just clearer and more editing-friendly to do one thing at a time. --- vim/plugin/toggle_option_flag.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index c3ea01a0..5376a279 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -39,9 +39,13 @@ function! s:Toggle(option, flag, local) let l:op = '' execute 'let l:op = &' . a:option . ' =~# a:flag ? "-=" : "+="' - " :execute to perform the option toggle and then print the value - execute l:set . ' ' . a:option . l:op . a:flag - execute l:set . ' ' . a:option . '?' + " Build the command strings to set and then show the value + let l:cmd_set = l:set . ' ' . a:option . l:op . a:flag + let l:cmd_show = l:set . ' ' . a:option . '?' + + " Run the set and show command strings + execute l:cmd_set + execute l:cmd_show endfunction -- cgit v1.2.3 From 3c72b4439f16a45871a56a7b233223c0ecdd6af7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:50:27 +1300 Subject: Rename l:op to l:operation for clarity Just to avoid confusing it with something like l:option. --- vim/plugin/toggle_option_flag.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index 5376a279..dd7c95f7 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -36,11 +36,11 @@ function! s:Toggle(option, flag, local) " :execute 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 ? "-=" : "+="' + let l:operation = '' + execute 'let l:operation = &' . a:option . ' =~# a:flag ? "-=" : "+="' " Build the command strings to set and then show the value - let l:cmd_set = l:set . ' ' . a:option . l:op . a:flag + let l:cmd_set = l:set . ' ' . a:option . l:operation . a:flag let l:cmd_show = l:set . ' ' . a:option . '?' " Run the set and show command strings -- cgit v1.2.3 From 57b34a5645b5d0325426dbb60b8d3f80ff6bfe7a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:51:07 +1300 Subject: Extend toggle_option_flag.vim for string flags This commit extends toggle_option_flag.vim to allow the exported commands to toggle values of more than one character, for comma-separated options like 'switchbuf', e.g.: :ToggleOptionFlag switchbuf useopen --- vim/doc/toggle_option_flag.txt | 7 ++++--- vim/plugin/toggle_option_flag.vim | 35 ++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/vim/doc/toggle_option_flag.txt b/vim/doc/toggle_option_flag.txt index 16557d5c..9415ae6b 100644 --- a/vim/doc/toggle_option_flag.txt +++ b/vim/doc/toggle_option_flag.txt @@ -1,14 +1,15 @@ -*toggle_option_flag.txt* Commands to toggle single-character option flags +*toggle_option_flag.txt* Commands to toggle option flags Author: Tom Ryder License: Same terms as Vim itself (see |license|) This plugin provides commands :ToggleOptionFlag and :ToggleOptionFlagLocal to toggle the values of options like |'formatoptions'| or |'complete'| that have -values comprised of single-character flags. The author originally designed it -for toggling flags in |'formatoptions'| quickly. +values comprised of single-character or comma-separated flags. The author +originally designed it for toggling flags in |'formatoptions'| quickly. :ToggleOptionFlag formatoptions a + :ToggleOptionFlag switchbuf useopen :ToggleOptionFlagLocal shortmess I This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index dd7c95f7..68db2703 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -1,8 +1,6 @@ " -" toggle_option_flag.vim: Provide commands 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! +" 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 @@ -23,21 +21,32 @@ function! s:Toggle(option, flag, local) return endif - " Weird flags, too; should be a single inoffensive char - if a:flag !~# '\m^[\a.]$' - echoerr 'Illegal flag' - return - endif - " Choose which set command to use let l:set = a:local \ ? 'setlocal' \ : 'set' - " :execute to assign -= or += to l:op for the option toggle + " Make a flag pattern to allow us to search for the literal string with no + " regular expression devilry at all + let l:flag_pattern = escape(a:flag, '\') + + " Horrible :execute to get the option's current current into a variable " (I couldn't get {curly braces} indirection to work) - let l:operation = '' - execute 'let l:operation = &' . a:option . ' =~# a:flag ? "-=" : "+="' + 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 pattern and current setting so that they'll + " still match at the start and end. + if len(a:flag) > 1 + let l:flag_pattern = ',' . l:flag_pattern . ',' + let l:current = ',' . l:current . ',' + endif + + " Assign -= or += as the operation to run based on whether the flag already + " appears in the option value or not + let l:operation = l:current =~# '\V\C' . l:flag_pattern ? '-=' : '+=' " Build the command strings to set and then show the value let l:cmd_set = l:set . ' ' . a:option . l:operation . a:flag -- cgit v1.2.3 From 65fda89e04424b454d9e3c5792344bba98fb5f60 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:56:07 +1300 Subject: Escape option value assign correctly This allows e.g.: ':ToggleOptionFlag fillchars diff: '; note the whitespace! --- vim/plugin/toggle_option_flag.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index 68db2703..809e1f53 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -49,7 +49,7 @@ function! s:Toggle(option, flag, local) let l:operation = l:current =~# '\V\C' . l:flag_pattern ? '-=' : '+=' " Build the command strings to set and then show the value - let l:cmd_set = l:set . ' ' . a:option . l:operation . a:flag + let l:cmd_set = l:set . ' ' . a:option . l:operation . escape(a:flag, '\ ') let l:cmd_show = l:set . ' ' . a:option . '?' " Run the set and show command strings -- cgit v1.2.3 From 1a805f6d50d471751fce4eb98c6ce8ea9443c13a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 11:57:58 +1300 Subject: Use strlen() instead of len() strlen() is older, and also more specific to what we want to do. len() just happens to work on strings, but was introduced for counting Lists and Dictionaries. --- vim/plugin/toggle_option_flag.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index 809e1f53..da9a6110 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -39,7 +39,7 @@ function! s:Toggle(option, flag, local) " necessity be a delimited option. I think all of those in VimL are " comma-separated. Extend the pattern and current setting so that they'll " still match at the start and end. - if len(a:flag) > 1 + if strlen(a:flag) > 1 let l:flag_pattern = ',' . l:flag_pattern . ',' let l:current = ',' . l:current . ',' endif -- cgit v1.2.3 From eecdc7ea6b7bd1f7c7d4b94f4e05775a95306c3e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 12:49:52 +1300 Subject: Use stridx() instead of very-nomagic regex match I couldn't find this function at first, but it's what I need: a way to check whether a string appears in another one. --- vim/plugin/toggle_option_flag.vim | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index da9a6110..ea7064d4 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -26,10 +26,6 @@ function! s:Toggle(option, flag, local) \ ? 'setlocal' \ : 'set' - " Make a flag pattern to allow us to search for the literal string with no - " regular expression devilry at all - let l:flag_pattern = escape(a:flag, '\') - " Horrible :execute to get the option's current current into a variable " (I couldn't get {curly braces} indirection to work) let l:current = '' @@ -37,16 +33,21 @@ function! s:Toggle(option, flag, local) " 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 pattern and current setting so that they'll - " still match at the start and end. + " comma-separated. Extend the flag and current setting so that they'll still + " match at the start and end. Otherwise, use them as-is. if strlen(a:flag) > 1 - let l:flag_pattern = ',' . l:flag_pattern . ',' - let l:current = ',' . l:current . ',' + let l:search_flag = ',' . a:flag . ',' + let l:search_current = ',' . l:current . ',' + else + let l:search_flag = a:flag + let l:search_current = l:current endif " Assign -= or += as the operation to run based on whether the flag already " appears in the option value or not - let l:operation = l:current =~# '\V\C' . l:flag_pattern ? '-=' : '+=' + let l:operation = stridx(l:search_current, l:search_flag) > -1 + \ ? '-=' + \ : '+=' " Build the command strings to set and then show the value let l:cmd_set = l:set . ' ' . a:option . l:operation . escape(a:flag, '\ ') -- cgit v1.2.3 From ab305d7ca1eef3ce32afb4e549c07722de8d2264 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 12:51:16 +1300 Subject: Correct a comment This likely got butchered by a wayward search-and-replace. --- vim/plugin/toggle_option_flag.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index ea7064d4..1d4b11ce 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -26,7 +26,7 @@ function! s:Toggle(option, flag, local) \ ? 'setlocal' \ : 'set' - " Horrible :execute to get the option's current current into a variable + " 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 -- cgit v1.2.3 From 4fce1494a43ea8445533e6f5af87a4e6fb96a06d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 12:53:54 +1300 Subject: Bump version number to 0.10.0 --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index bd0a99d4..a559f617 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v0.9.1 -Sun Nov 5 02:50:48 UTC 2017 +tejr dotfiles v0.10.0 +Sun Nov 5 23:53:44 UTC 2017 -- cgit v1.2.3