From ed20475b5589ec6232daa04f27d95b804c62b7c6 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 18 Apr 2003 08:34:49 +0000 Subject: 18449: complete dictionary databases and strategies, handle suffixes better and handle the separate-sections style for separate databases with dict words --- Completion/Unix/Type/_dict_words | 48 +++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'Completion/Unix/Type/_dict_words') diff --git a/Completion/Unix/Type/_dict_words b/Completion/Unix/Type/_dict_words index 770319036..4928a50f0 100644 --- a/Completion/Unix/Type/_dict_words +++ b/Completion/Unix/Type/_dict_words @@ -1,17 +1,43 @@ #autoload -local dict dictresult dictwords j expl +local begin end ret=1 +local -a args dict dicts dictwords expl -[[ -z $words[CURRENT] ]] && return 1 +if [[ $service = dict ]]; then + args=( ${(kv)opt_args[(I)-([hpdauk]|-(host|port|database|noauth|user|key))]} ) +fi -dictresults=(${${(f)${"$(dict -m -s prefix $words[CURRENT])":gs/ - / /}}:#[0-9]*matches found}) +if [[ -z $words[CURRENT] ]]; then + _message -e dict 'dictionary word' + return 1 +elif [[ -z $SUFFIX ]]; then + dictwords=( ${(z)${(f)"$(_call_program words dict $args -m -s prefix $PREFIX 2>/dev/null)"}} ) +elif [[ -z $PREFIX ]]; then + dictwords=( ${(z)${(f)"$(_call_program words dict $args -m -s suffix $SUFFIX 2>/dev/null)"}} ) +else + dictwords=( ${(z)${(f)"$(_call_program words dict $args -m -s regexp $PREFIX.\*$SUFFIX 2>/dev/null)"}} ) +fi -for j in ${dictresults} -do - dict=${j%%:*} - dictwords=(${(z)j#*:}) +dictwords=( ${${dictwords#\"}%\"} ) +dicts=( ${${(M)dictwords:#*:}%:} ) - _wanted $dict expl "words from $dict" \ - compadd -M 'm:{a-zA-Z}={A-Za-z} r:|=*' -a "$@" - dictwords -done +if zstyle -t ":completion:${curcontext}:words" separate-sections; then + _tags words.$^dicts + while _tags; do + for dict in $dicts; do + if _requested words.$dict expl "word from $dict"; then + (( begin=${dictwords[(i)$dict:]} + 1 )) + end=${dictwords[(ib.begin.)*:]} + [[ $end = 1 ]] && end=$#dictwords + compadd "$expl[@]" "$@" -M 'm:{a-zA-Z}={A-Za-z} r:|=*' -a - \ + 'dictwords[begin,end]' && ret=0 + fi + done + (( ret )) || break + done + + return 1 +else + _wanted words expl word compadd -M 'm:{a-zA-Z}={A-Za-z} r:|=*' "$@" - \ + ${dictwords:#*:} +fi -- cgit 1.4.1