From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9405 invoked from network); 2 May 2000 08:17:23 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 2 May 2000 08:17:23 -0000 Received: (qmail 6994 invoked by alias); 2 May 2000 08:17:17 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 11048 Received: (qmail 6977 invoked from network); 2 May 2000 08:17:16 -0000 Date: Tue, 2 May 2000 10:17:10 +0200 (MET DST) Message-Id: <200005020817.KAA30071@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk Subject: PATCH: completion-in-vared This moves the code that makes completion inside vared with no $compcontext set behave like completing parameter values from _first to _complete, as discussed lately. Then there are some small cleanups/optimisations for _path_files. No C-support for it yet, though. Bye Sven Index: Completion/Base/_first =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/_first,v retrieving revision 1.2 diff -u -r1.2 _first --- Completion/Base/_first 2000/04/11 07:57:56 1.2 +++ Completion/Base/_first 2000/05/02 08:15:16 @@ -6,29 +6,6 @@ # This just gives some examples of things you might want to do here. # # -# If you use the vared builtin and want completion in there to act the -# way completion on the right hand side of assignments is done, add -# (or un-comment) this code: -# -# if [[ -n $compstate[vared] ]]; then -# if [[ $compstate[vared] = *\[* ]]; then -# # vared on an array-element -# compstate[parameter]=${compstate[vared]%%\[*} -# compstate[context]=value -# else -# # vared on a parameter, let's see if it is an array -# compstate[parameter]=$compstate[vared] -# if [[ ${(tP)compstate[vared]} = *(array|assoc)* ]]; then -# compstate[context]=array_value -# else -# compstate[context]=value -# fi -# fi -# return -# fi -# -# -# # Other things you can do here is to complete different things if the # word on the line matches a certain pattern. This example allows # completion of words from the history by adding two commas at the end Index: Completion/Core/_complete =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Core/_complete,v retrieving revision 1.2 diff -u -r1.2 _complete --- Completion/Core/_complete 2000/04/01 20:43:43 1.2 +++ Completion/Core/_complete 2000/05/02 08:15:16 @@ -33,6 +33,24 @@ fi fi +# If we are inside `vared' and we don't have a $compcontext, we treat +# this like a parameter assignment. Which it is. + +if [[ -n $compstate[vared] ]]; then + if [[ $compstate[vared] = *\[* ]]; then + # vared on an array-element + compstate[parameter]=${compstate[vared]%%\[*} + compstate[context]=value + else + # vared on a parameter, let's see if it is an array + compstate[parameter]=$compstate[vared] + if [[ ${(tP)compstate[vared]} = *(array|assoc)* ]]; then + compstate[context]=array_value + else + compstate[context]=value + fi + fi +fi # For arguments and command names we use the `_normal' function. Index: Completion/Core/_path_files =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Core/_path_files,v retrieving revision 1.10 diff -u -r1.10 _path_files --- Completion/Core/_path_files 2000/04/26 06:12:25 1.10 +++ Completion/Core/_path_files 2000/05/02 08:15:17 @@ -5,8 +5,8 @@ local linepath realpath donepath prepath testpath exppath skips skipped local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre -local pats haspats=no ignore pfxsfx rem remt sopt gopt opt -local nm=$compstate[nmatches] menu matcher mopts atmp sort match +local pats haspats ignore pfxsfx remt sopt gopt opt sdirs ignpar +local nm=$compstate[nmatches] menu matcher mopts sort match typeset -U prepaths exppaths @@ -111,7 +111,7 @@ [[ "$tmp1" = *rev* ]] && sort[1]=O if [[ "$sort" = on ]]; then - sort='' + sort= else mopts=( "${(@)mopts/#-J/-V}" ) @@ -139,6 +139,11 @@ skips='((.|..)/)##' fi +zstyle -s ":completion:${curcontext}:paths" special-dirs sdirs && + [[ "$sdirs" = (yes|true|on|1) ]] && sdirs=yes + +zstyle -s ":completion:${curcontext}:files" ignore-parents ignpar + # We get the prefix and the suffix from the line and save the whole # original string. Then we see if we will do menucompletion. @@ -202,7 +207,7 @@ [[ "$realpath" = "$linepath" ]] && return 1 pre="${pre#*/}" orig="${orig#*/}" - donepath='' + donepath= prepaths=( '' ) elif [[ "$pre" = *\$*/* ]]; then @@ -218,14 +223,14 @@ pre="${pre#${linepath}}" i="${#linepath//[^\\/]}" orig="${orig[1,(in:i:)/][1,-2]}" - donepath='' + donepath= prepaths=( '' ) else # If the string does not start with a `~' we don't remove a prefix from the # string. - linepath='' - realpath='' + linepath= + realpath= if [[ "$pre[1]" = / ]]; then # If it is a absolute path name, we remove the first slash and put it in @@ -241,7 +246,7 @@ # `./' or `../' in which case we don't use the paths from `-W'. [[ "$pre" = (.|..)/* ]] && prepaths=( '' ) - donepath='' + donepath= fi fi @@ -271,7 +276,7 @@ if [[ "$tpre" = */* ]]; then PREFIX="${tpre%%/*}" - SUFFIX="" + SUFFIX= else PREFIX="${tpre}" SUFFIX="${tsuf%%/*}" @@ -286,11 +291,10 @@ else tmp1=( ${^tmp1}${skipped}*(-/) ) fi - if [[ -o globdots || "$PREFIX" = .* ]] && - zstyle -s ":completion:${curcontext}:paths" special-dirs atmp; then - if [[ "$atmp" = (yes|true|1|on) ]]; then + if [[ -n "$sdirs" && ( -o globdots || "$PREFIX" = .* ) ]]; then + if [[ "$sdirs" = yes ]]; then tmp1=( "$tmp1[@]" . .. ) - elif [[ "$atmp" = .. ]]; then + elif [[ "$sdirs" = .. ]]; then tmp1=( "$tmp1[@]" .. ) fi fi @@ -300,12 +304,12 @@ else tmp1=( ${^tmp1}${skipped}${^~pats} ) fi - if [[ ( "$sopt" = *[/f]* || "$pats" = *\([^[:blank:]]#/[^[:blank:]]#\)* ) && - ( -o globdots || "$PREFIX" = .* ) ]] && - zstyle -s ":completion:${curcontext}:paths" special-dirs atmp; then - if [[ "$atmp" = (yes|true|1|on) ]]; then + if [[ -n "$sdirs" && + ( "$sopt" = *[/f]* || "$pats" = *\([^[:blank:]]#/[^[:blank:]]#\)* ) && + ( -o globdots || "$PREFIX" = .* ) ]]; then + if [[ "$sdirs" = yes ]]; then tmp1=( "$tmp1[@]" . .. ) - elif [[ "$atmp" = .. ]]; then + elif [[ "$sdirs" = .. ]]; then tmp1=( "$tmp1[@]" .. ) fi fi @@ -368,8 +372,7 @@ ### ### tmp1=( "$tmp2[@]" ) ### break - elif [[ "$haspats" = no && -z "$tpre$tsuf" && - "$pre" = */ && -z "$suf" ]]; then + elif [[ -n "$haspats" && -z "$tpre$tsuf$suf" && "$pre" = */ ]]; then PREFIX="${opre}" SUFFIX="${osuf}" compadd -nQS '' - "$linepath$donepath$orig" @@ -378,11 +381,11 @@ continue 2 fi - if [[ -z "$_comp_no_ignore" && "$tpre$tsuf" != */* && $#tmp1 -ne 0 ]] && - zstyle -s ":completion:${curcontext}:files" ignore-parents rem && - [[ ( "$rem" != *dir* || "$pats" = '*(-/)' ) && - ( "$rem" != *..* || "$tmp1" = *../* ) ]]; then - if [[ "$rem" = *parent* ]]; then + if [[ -n "$ignpar" && -z "$_comp_no_ignore" && + "$tpre$tsuf" != */* && $#tmp1 -ne 0 && + ( "$ignpar" != *dir* || "$pats" = '*(-/)' ) && + ( "$ignpar" != *..* || "$tmp1" = *../* ) ]]; then + if [[ "$ignpar" = *parent* ]]; then for i in ${(M)^tmp1:#*/*}(-/); do remt="${${i#$prepath$realpath$donepath}%/*}" while [[ "$remt" = */* && @@ -393,7 +396,7 @@ _comp_ignore=( "$_comp_ignore[@]" "${(q)i}" ) done fi - if [[ "$rem" = *pwd* ]]; then + if [[ "$ignpar" = *pwd* ]]; then for i in ${^tmp1}(-/); do [[ "$i" -ef "$PWD" ]] && _comp_ignore=( "$_comp_ignore[@]" "${(q)i}" ) done @@ -407,7 +410,7 @@ tpre="${tpre#*/}" elif [[ "$tsuf" = */* ]]; then tpre="${tsuf#*/}" - tsuf="" + tsuf= else break fi @@ -475,7 +478,7 @@ if [[ -n $menu || -z "$compstate[insert]" ]] || ! zstyle -t ":completion:${curcontext}:paths" expand suffix; then (( tmp4 )) && zstyle -t ":completion:${curcontext}:paths" ambiguous && - compstate[to_end]='' + compstate[to_end]= if [[ "$tmp3" = */* ]]; then compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \ -W "$prepath$realpath$testpath" \ @@ -489,11 +492,11 @@ fi else if [[ "$tmp3" = */* ]]; then - atmp=( -Qf "$mopts[@]" -p "$linepath$tmp2" + tmp3=( -Qf "$mopts[@]" -p "$linepath$tmp2" -W "$prepath$realpath$testpath" "$pfxsfx[@]" -M "r:|/=* r:|=*" ) for i in "$tmp1[@]"; do - compadd "$atmp[@]" -s "/${i#*/}" - "${i%%/*}" + compadd "$tmp3[@]" -s "/${i#*/}" - "${i%%/*}" done else compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \ @@ -510,7 +513,7 @@ # strings collected after the loop. if [[ "$tmp3" != */* ]]; then - tmp4="" + tmp4= break fi @@ -528,17 +531,17 @@ elif [[ "$tsuf" = */* ]]; then cpre="${cpre}${tpre}/" tpre="${tsuf#*/}" - tsuf="" + tsuf= else - tpre="" - tsuf="" + tpre= + tsuf= fi done if [[ -z "$tmp4" ]]; then if [[ "$osuf" = */* ]]; then PREFIX="${opre}${osuf}" - SUFFIX="" + SUFFIX= else PREFIX="${opre}" SUFFIX="${osuf}" -- Sven Wischnowsky wischnow@informatik.hu-berlin.de