Closed ghost closed 10 years ago
This touches on two separate problems:
Wordy<tab>
to see the list of options. But it exacerbates problem (1) above.Rather than expand the number of commands, I'd suggest two alternatives:
A. Use the recent 'ring' feature, to rapidly cycle among the dictionaries in the ring. That's user-configurable.
B. I'll consider a parameterized list that the user can tab through with Wordy<space><tab>
such as that found in my Thematic plugin: https://github.com/reedes/vim-thematic/blob/master/plugin/thematic.vim#L44-L54
Then the existing command names could be deprecated.
Thank you for the feedback on this. Do you think something like the code below would be suitable? It gets a list of available dictionaries from the data dir to provide as arguments to the new Wordy
command based on Thematic. It has en
hardcoded at the moment:
if !exists('g:wordy#all_dicts')
let g:wordy#all_dicts = []
let dic_dir = g:wordy_dir . '/data/en/'
for f in split(glob(dic_dir . '*.dic'), '\n')
let filename = fnamemodify(f, ':t') " get filename
let dname = fnamemodify(filename, ':r') " remove extension
call add(g:wordy#all_dicts, dname)
endfor
endif
function! <SID>chooseRing(ArgLead, CmdLine, CursorPos)
return g:wordy#all_dicts
endfunction
command -nargs=1 -complete=customlist,<SID>chooseRing
\ Wordy
\ call wordy#init({ 'd': <f-args> })
Yep, it'll look something like that, but I'm not sure yet if the list should be pulled from filesystem or from the user-filtered g:wordy#ring. Maybe that could be configurable?
Also, if filesystem, should it build the list during init, or dynamically? If the latter, the 'lang' would have to be retained.
I'll give this more thought, but feel free to post additional ideas for this feature.
I did have another idea which I abandoned as it seemed like too big of a change and a bit hacky, I've included it below for reference. I've been using the ring feature bound to a key so option A is working well for me. I find myself no longer using the commands now I'm more familiar with the plugin.
The idea was a Thematic style autocomplete using the ring but I bumped in to the following issue:
For the "customlist" argument, the function should return the completion candidates as a Vim List. Non-string items in the list are ignored.
Vim's autocomplete includes regular string items in the ring like weak and weasel, but list items like ['being', 'passive-voice', ]
are excluded. This can be worked around by converting the ring from a list to a dictionary instead:
plugin\wordy.vim
" user configurable ring of dictionaries
if !exists('g:wordy#ring')
let g:wordy#ring = {
\ 'weak': 'weak',
\ 'passive': ['being', 'passive-voice', ],
\ 'business-jargon': 'business-jargon',
\ 'weasel': 'weasel',
\ 'puffery': 'puffery',
\ 'problem': ['problematic', 'redundant', ],
\ 'trite': ['colloquial', 'idiomatic', 'similies', ],
\ }
endif
function! <SID>chooseRing(ArgLead, CmdLine, CursorPos)
return keys(g:wordy#ring)
endfunction
command -nargs=1 -complete=customlist,<SID>chooseRing
\ Wordy
\ call wordy#init({ 'd': get(g:wordy#ring, <f-args>) })
autoload\wordy.vim
...
let l:dkey = keys(g:wordy#ring)[ g:wordy_ring_index ]
let l:dvalues = get(g:wordy#ring, l:dkey)
call wordy#init({ 'd': l:dvalues })
...
I'd thought about using a dictionary for the ring, but figured it was best to keep it simple by using an array.
So I'm leaning towards the source of the customlist as: (1) the flattened ring, or (2) a glob() from the filesystem queried during init() with the specified language. The first would be the default, as it can exclude dictionaries the user doesn't care about. For users who want more flexibility, the second would be a configurable option.
The flattened ring idea sounds like a good alternative to a dictionary :+1:
Should be addressed by recent changes. Thanks for the push.
Add 'Wordy' prefixed aliases to make them easier to remember. Fixes #1.