Skip to content

Commit

Permalink
Add autocompletion for available boolean options
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalk committed Apr 21, 2014
1 parent dbab0ce commit 78f709e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.mkd
Expand Up @@ -20,7 +20,8 @@ nnore <Leader>i :Onoff list<cr>

For those who want to use `:Onoff` command explicitly, `:onoff` abbreviation is
available. Abbreviation works on when 'onoff' is the first word on the command
line.
line. Note that `:Onoff` command has autocompletion for all available boolean
options supported by your Vim distribution.

Installation
------------
Expand Down
34 changes: 34 additions & 0 deletions autoload/onoff.vim
Expand Up @@ -22,3 +22,37 @@ fun! onoff#toggle(option)
endf

" }}}
" Read file content line by line {{{

fun! s:readfile(fname)
let fname = fnameescape(a:fname)
if filereadable(fname)
return readfile(fname)
endif
return []
endf

" }}}
" Autocompletion {{{

fun! s:complist()
let complist = []
let pattern = '\*''no\(\w\+\)'''
for line in s:readfile($VIMRUNTIME . '/doc/options.txt')
let value = matchstr(line, pattern)
if !empty(value)
call add(complist, substitute(value, pattern, '\1', ''))
endif
endfor
return sort(complist)
endf

fun! onoff#compfunc(...)
" Cache completion list on first call for later reuse
if !exists('s:cache')
let s:cache = join(s:complist(), "\n")
endif
return s:cache
endf

" }}}
3 changes: 3 additions & 0 deletions doc/onoff.txt
Expand Up @@ -42,6 +42,9 @@ works only when 'onoff' is the first word on the command line.
:Onoff [option] Switch value of boolean option and show new value at
bottom of the window.

Note: command has autocompletion for all available
boolean options in your Vim distribution.

==============================================================================
3. About *onoff-about*

Expand Down
4 changes: 3 additions & 1 deletion plugin/onoff.vim
Expand Up @@ -12,7 +12,9 @@ let g:loaded_onoff = 1
" }}}
" Public API {{{

command! -nargs=1 Onoff
command! -nargs=1
\ -complete=custom,onoff#compfunc
\ Onoff
\ call onoff#toggle(<f-args>)

cabbr onoff <c-r>=(getcmdtype() == ':' && getcmdpos() == 1 ? 'Onoff' : 'onoff')<cr>
Expand Down

0 comments on commit 78f709e

Please sign in to comment.