Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: expansion of custom abbreviations in configure (autoconf) completion
dana wrote:
> it's a cute idea imo. a more generic solution might be interesting.
> maybe like a _snippet completer?
Completers are invoked early while $curcontext is still nascent so
that doesn't allow styles to be especially targetted.
It's trivial to factor out into a separate function so the patch
below does that. I didn't have a better name so used your "snippet"
suggestion though I'm not sure if that's really appropriate here.
I've got _configure calling it directly which is fine if we only expect
it to be useful in limited places. We could handle it similarly to the
fake style. But that applies when you already have a tag to complete.
Maybe it would be best done from _dispatch so when we have the command
but no more.
> re: clashing, i guess you could just use a special prefix that's
> unlikely to have that issue, like ',,' ?
This does that by looking up a prefix style. It should possibly also
consider prefix-hidden but with an opposite default.
Oliver
diff --git a/Completion/Base/Completer/_snippets b/Completion/Base/Completer/_snippets
new file mode 100644
index 000000000..8bcea1ef2
--- /dev/null
+++ b/Completion/Base/Completer/_snippets
@@ -0,0 +1,22 @@
+#autoload
+
+local prefix pad sep ret=1
+local -a sniplist filter
+local -A snippets
+
+zstyle -a ":completion:${curcontext}:arguments" snippets sniplist || return 1
+
+zstyle -s ":completion:${curcontext}:snippets" prefix prefix &&
+ [[ ! -prefix "${(b)prefix}" ]] && return 1
+
+snippets=( "$sniplist[@]" )
+_description snippets expl "snippet"
+compadd "$expl[@]" -P "$prefix" -O filter -k snippets
+pad=${#${(O)${filter//?/.}}[1]}
+snippets=( ${(kv)snippets[(I)(${(j.|.)${(@b)filter}})]} )
+zstyle -s ":completion:${curcontext}:snippets" list-separator sep || sep=--
+print -v sniplist -f "%-${pad}s $sep %s" ${(kv)snippets}
+compadd "$expl[@]" -Q -U -P "$IPREFIX" -S "$ISUFFIX" -ld sniplist -a snippets && ret=0
+[[ -n "$PREFIX$SUFFIX" && compstate[nmatches] -gt 1 ]] && compstate[insert]=
+
+return ret
diff --git a/Completion/Unix/Command/_configure b/Completion/Unix/Command/_configure
index 3b22b53db..e1f6003e5 100644
--- a/Completion/Unix/Command/_configure
+++ b/Completion/Unix/Command/_configure
@@ -1,6 +1,11 @@
#compdef configure config.status
-_arguments -- -i '(--(disable|enable)-FEATURE* --(with|without)-PACKAGE*)' \
+local ret=1
+local -a suf
+
+[[ -prefix - ]] ||
+ ! zstyle -T ":completion:${curcontext}:options" prefix-needed &&
+ _arguments -- -i '(--(disable|enable)-FEATURE* --(with|without)-PACKAGE*)' \
-s '((#s)--disable- --enable-
(#s)--enable- --disable-
(#s)--with- --without-
@@ -8,4 +13,22 @@ _arguments -- -i '(--(disable|enable)-FEATURE* --(with|without)-PACKAGE*)' \
'*=(E|)PREFIX*:prefix directory:_files -/' \
'*=PROGRAM*:program:_command_names -e' \
'*=NAME*executable*:program:_command_names -e' \
- '*=NAME*:file:_files'
+ '*=NAME*:file:_files' && ret=0
+
+if [[ ! -prefix - ]]; then
+ if [[ "$PREFIX" = *\=* ]]; then
+ compstate[parameter]="${PREFIX%%\=*}"
+ compset -P 1 '*='
+ _value && ret=0
+ else
+ compset -S '=*' || suf=( -S = )
+ _alternative \
+ 'variables:variable: compadd "${expl[@]:/-X/-x}" $suf
+ CC CFLAGS CPP CPPFLAGS CXX CXXFLAGS DEFS
+ ERLCFLAGS FCFLAGS FFLAGS GOFLAGS LDFLAGS LIBS OBJCFLAGS
+ OBJCXXFLAGS' \
+ 'snippets:snippet:_snippets' && ret=0
+ fi
+fi
+
+return ret
diff --git a/Completion/Unix/Command/_gcc b/Completion/Unix/Command/_gcc
index 1f05edb73..3c7db6beb 100644
--- a/Completion/Unix/Command/_gcc
+++ b/Completion/Unix/Command/_gcc
@@ -1,10 +1,18 @@
-#compdef gcc g++ cc c++ llvm-gcc llvm-g++ clang clang++ -value-,LDFLAGS,-default- -value-,CFLAGS,-default- -value-,CXXFLAGS,-default- -value-,CPPFLAGS,-default- -P gcc-* -P g++-* -P c++-*
+#compdef gcc g++ cc c++ llvm-gcc llvm-g++ clang clang++ -value-,LDFLAGS,-default- -value-,CFLAGS,-default- -value-,CXXFLAGS,-default- -value-,CPPFLAGS,-default- -value-,CC,-default- -value-,CXX,-default- -P gcc-* -P g++-* -P c++-*
local curcontext="$curcontext" state line ret=1 expl i
local -a args args2 warnings arch
typeset -A opt_args
-if [[ "$service" = -value-* ]]; then
+if [[ "$service" = -value-,CC,* ]]; then
+ _description compilers expl compiler
+ compadd "$expl[@]" -M 'r:|-=* r:|=*' -k 'commands[(I)(clang|([ig]|sun|open)cc(|<->|-devel)|icx)]'
+ return
+elif [[ "$service" = -value-,CXX,* ]]; then
+ _description compilers expl compiler
+ compadd "$expl[@]" -M 'r:|-=* r:|=*' -k 'commands[(I)((clang|g)++(|<->|-devel)|(sun|open|)CC|icpx)]'
+ return
+elif [[ "$service" = -value-* ]]; then
compset -q
words=( fake "$words[@]" )
(( CURRENT++ ))
Messages sorted by:
Reverse Date,
Date,
Thread,
Author