From fa9a2faf9c739bf61592e86f7997a9f8a5959536 Mon Sep 17 00:00:00 2001 From: Reed Esau Date: Mon, 10 Mar 2014 22:17:23 -0600 Subject: [PATCH] First cut of experimental ring of dictionaries --- README.markdown | 27 ++++++++++++++++++++++++++ autoload/wordy.vim | 44 +++++++++++++++++++++++++++++++++++++++++++ plugin/wordy.vim | 47 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 104 insertions(+), 14 deletions(-) diff --git a/README.markdown b/README.markdown index 07f609d..0b19cd7 100644 --- a/README.markdown +++ b/README.markdown @@ -15,6 +15,7 @@ * Includes 16 dictionaries covering different types of word usage * Buffer-scoped configuration (leaves your global settings alone) * Unicode-friendly, including support for ‘typographic quotes’ +* User-configurable ring of dictionaries ## What is _wordy_? @@ -55,6 +56,8 @@ package manager. ## Configuration +### On demand + You’ll typically use this plugin on-demand. It does not require any special configuration. @@ -74,6 +77,30 @@ Press ENTER or type command to continue As instructed, press the enter key and it will disturb you no longer, at least until _wordy_ feels the urge to build again. +### Ring + +Optionally map a key in your `.vimrc` to rapidly cycle among available dictionaries: + +``` +nnoremap K :NextWordy +``` + +In addition, you can define your own ring of dictionaries. This is the +default, which you can override in your `.vimrc`: + +``` +let g:wordy#ring = [ + \ 'jargon' , + \ 'passive' , + \ 'puffery' , + \ 'redundant' , + \ 'to-be' , + \ 'trite' , + \ 'weak' , + \ 'weasel' , + \ ] +``` + ## Using _wordy_ You’ll use the commands that follow to enable _wordy_. To disable it and diff --git a/autoload/wordy.vim b/autoload/wordy.vim index e0df01a..28bbc94 100644 --- a/autoload/wordy.vim +++ b/autoload/wordy.vim @@ -61,4 +61,48 @@ function! wordy#init(...) abort endif endfunction +function! wordy#jump(mode) + let g:wordy = s:wordy_get(a:mode) + let l:entry = get(g:wordy#data, g:wordy, []) + if len(l:entry) > 0 + call wordy#init({ 'd': l:entry[0] }) + echo g:wordy . ': ' . l:entry[1] + endif +endfunction + +function! s:wordy_get(mode) + let l:avail_count = len(g:wordy#ring) + let l:new_n = -1 + if a:mode == '#first' + let l:new_n = 0 + elseif a:mode == '#last' + let l:new_n = l:avail_count - 1 + elseif a:mode == '#random' + let l:new_n = + \ str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:]) + \ % l:avail_count + elseif a:mode == '#next' || a:mode == '#previous' + let l:current_n = index(g:wordy#ring, g:wordy) + if a:mode == '#next' + if l:current_n == -1 || l:current_n == l:avail_count - 1 + let l:new_n = 0 + else + let l:new_n = l:current_n + 1 + endif + elseif a:mode == '#previous' + if l:current_n <= 0 + let l:new_n = l:avail_count - 1 + else + let l:new_n = l:current_n - 1 + endif + endif + endif + + if l:new_n == -1 + return a:mode + else + return g:wordy#ring[l:new_n] + endif +endfunction + " vim:ts=2:sw=2:sts=2 diff --git a/plugin/wordy.vim b/plugin/wordy.vim index 0dbf9a9..0898c1c 100644 --- a/plugin/wordy.vim +++ b/plugin/wordy.vim @@ -39,21 +39,40 @@ command -nargs=0 OpineWordy call wordy#init({ 'd': ['opinion',] }) command -nargs=0 SaidWordy call wordy#init({ 'd': ['said-synonyms',] }) command -nargs=0 AintWordy call wordy#init({ 'd': ['contractions',] }) -" tools for creative writing -command -nargs=0 CreativeWordy call wordy#init({ 'd': [ 'being', - \ 'colloquial', - \ 'idiomatic', - \ 'business-jargon', - \ 'art-jargon', - \ 'weasel', - \ 'opinion', - \ 'passive-voice', - \ 'puffery', - \ 'redundant', - \ 'similies', - \ 'weak', - \ ]}) +command -nargs=0 NextWordy call wordy#jump('#next') +command -nargs=0 PrevWordy call wordy#jump('#prev') +let g:wordy = '' + +" ordered list of keys into s:wordy#data; user configurable +if !exists('g:wordy#ring') + let g:wordy#ring = [ + \ 'jargon' , + \ 'passive' , + \ 'puffery' , + \ 'redundant' , + \ 'to-be' , + \ 'trite' , + \ 'weak' , + \ 'weasel' , + \ ] +endif + +if !exists('g:wordy#data') + let g:wordy#data = { + \ 'to-be' : [['being' ], 'Subject-verb agreement' ], + \ 'trite' : [['colloquial' , + \ 'idiomatic' , + \ 'similies' ], 'colloquialisms, idioms, and similes' ], + \ 'jargon' : [['business-jargon' ], 'insidery jargon for business' ], + \ 'weasel' : [['weasel' ], 'manipulative and equivocating words and phrases' ], + \ 'passive' : [['being' , + \ 'passive-voice' ], 'can be used to avoid responsibility for actions taken' ], + \ 'puffery' : [['puffery' ], 'statements and claims that express subjective rather than objective views' ], + \ 'redundant' : [['redundant' ], 'redundant phrasings' ], + \ 'weak' : [['weak' ], 'weak and lazy language' ], + \ } +endif let &cpo = s:save_cpo unlet s:save_cpo