From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6209 invoked from network); 26 Feb 1999 14:00:20 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 26 Feb 1999 14:00:20 -0000 Received: (qmail 2969 invoked by alias); 26 Feb 1999 13:59:54 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5544 Received: (qmail 2960 invoked from network); 26 Feb 1999 13:59:53 -0000 Date: Fri, 26 Feb 1999 14:59:09 +0100 (MET) Message-Id: <199902261359.OAA31879@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk Subject: Yet another example cleanup The patch below makes `_path_files' accept the `-X' option. It also adds option handling to `_files'. I also made `_patcomps' be initialised in `init', which allows us to simplify the the places where it is used. Finally I renamed `COMPSKIP' to `_compskip'. Considering that the things that are used only internally are now all named `_something', we should probably do this. Bye Sven diff -u of/Completion/_files Functions/Completion/_files --- of/Completion/_files Fri Feb 26 12:50:26 1999 +++ Functions/Completion/_files Fri Feb 26 14:34:35 1999 @@ -7,4 +7,20 @@ _path_files "$@" -[[ $# -ne 0 && -nmatches nm ]] && _path_files +if [[ $# -ne 0 && -nmatches nm ]]; then + local opt opts + + # We didn't get any matches for those types of files described by + # the `-g' or `-/' option. Now we try it again accepting all files. + # First we get those options that we have to use even if then. If + # we find out that the `-f' option was given, we already accepted + # all files and give up immediatly. + + opts=() + while getopts "P:S:W:F:J:V:X:f/g:" opt; do + [[ "$opt" = f ]] && return + [[ "$opt" = [PSWFJVX] ]] && opts=("$opts[@]" "-$opt" "$OPTARG") + done + + _path_files "$opts[@]" +fi diff -u of/Completion/_main_complete Functions/Completion/_main_complete --- of/Completion/_main_complete Fri Feb 26 12:50:27 1999 +++ Functions/Completion/_main_complete Fri Feb 26 14:08:04 1999 @@ -11,14 +11,14 @@ unsetopt markdirs globsubst shwordsplit nounset # An entry for `-first-' is the replacement for `compctl -T' -# Completion functions may set `COMPSKIP' to any value to make the +# Completion functions may set `_compskip' to any value to make the # main loops stop calling other completion functions. comp="$_comps[-first-]" if [[ ! -z "$comp" ]]; then "$comp" "$@" - if (( $+COMPSKIP )); then - unset COMPSKIP + if (( $+_compskip )); then + unset _compskip return fi fi diff -u of/Completion/_normal Functions/Completion/_normal --- of/Completion/_normal Fri Feb 26 12:50:27 1999 +++ Functions/Completion/_normal Fri Feb 26 14:41:36 1999 @@ -23,19 +23,17 @@ # See if there are any matching pattern completions. -if (( $#_patcomps )); then - for i in "$_patcomps[@]"; do - pat="${i% *}" - val="${i#* }" - if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then - "$val" "$@" - if (( $+COMPSKIP )); then - unset COMPSKIP - return - fi +for i in "$_patcomps[@]"; do + pat="${i% *}" + val="${i#* }" + if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then + "$val" "$@" + if (( $+_compskip )); then + unset _compskip + return fi - done -fi + fi +done # Now look up the two names in the normal completion array. diff -u of/Completion/_path_files Functions/Completion/_path_files --- of/Completion/_path_files Fri Feb 26 12:50:27 1999 +++ Functions/Completion/_path_files Fri Feb 26 14:37:09 1999 @@ -2,12 +2,13 @@ # Utility function for in-path completion. # Supported arguments are: `-f', `-/', `-g ', `-J ', -# `-V ', `-W paths', and `-F '. All but the last have the -# same syntax and meaning as for `complist'. The `-F ' option -# may be used to give a list of suffixes either by giving the name of an -# array or literally by giving them in a string surrounded by parentheses. -# Files with one of the suffixes thus given are treated like files with -# one of the suffixes in the `fignore' array in normal completion. +# `-V ', `-W paths', `-X explanation', and `-F '. All but +# the last have the same syntax and meaning as for `complist'. The +# `-F ' option may be used to give a list of suffixes either by +# giving the name of an array or literally by giving them in a string +# surrounded by parentheses. Files with one of the suffixes thus given +# are treated like files with one of the suffixes in the `fignore' array +# in normal completion. # # This function uses the helper functions `_match_test' and `_match_pattern'. @@ -19,7 +20,7 @@ local nm prepaths str linepath realpath donepath patstr prepath testpath rest local tmp1 collect tmp2 suffixes i ignore matchflags opt group sopt pats gopt -local addpfx addsfx +local addpfx addsfx expl setopt localoptions nullglob rcexpandparam globdots extendedglob unsetopt markdirs globsubst shwordsplit nounset @@ -32,10 +33,11 @@ pats=() addpfx=() addsfx=() +expl=() # Get the options. -while getopts "P:S:W:F:J:V:f/g:" opt; do +while getopts "P:S:W:F:J:V:X:f/g:" opt; do case "$opt" in P) addpfx=(-P "$OPTARG") ;; @@ -60,6 +62,8 @@ ;; [JV]) group=("-$opt" "$OPTARG") ;; + X) expl=(-X "$OPTARG") + ;; f) sopt="${sopt}f" pats=("$pats[@]" '*') ;; @@ -112,9 +116,9 @@ nm=$NMATCHES if [[ -z "$gopt" ]]; then - complist "$addpfx[@]" "$addsfx[@]" "$group[@]" "$tmp1[@]" $sopt + complist "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" "$tmp1[@]" $sopt else - complist "$addpfx[@]" "$addsfx[@]" "$group[@]" "$tmp1[@]" $sopt -g "$pats" + complist "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" "$tmp1[@]" $sopt -g "$pats" fi # If this generated any matches, we don't want to do in-path completion. @@ -266,7 +270,7 @@ # (the `-f' and `-F' options). for i in $collect; do - compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" -p "$linepath$testpath" -W "$tmp1" -s "/${i#*/}" -f "$ignore[@]" - "${i%%/*}" + compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" -p "$linepath$testpath" -W "$tmp1" -s "/${i#*/}" -f "$ignore[@]" - "${i%%/*}" done # We have just finished handling all the matches from above, so we @@ -300,8 +304,8 @@ tmp2=( ${~tmp1}${~matchflags}${~suffixes} ) if [[ $#tmp2 -eq 0 && "$sopt" = */* ]]; then [[ "$testpath[-1]" = / ]] && testpath="$testpath[1,-2]" - compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" -f - "$linepath$testpath" + compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" -f - "$linepath$testpath" else - compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" -p "$linepath$testpath" -W "$prepath$realpath$testpath" -f "$ignore[@]" - ${(@)tmp2#$tmp1} + compadd "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" -p "$linepath$testpath" -W "$prepath$realpath$testpath" -f "$ignore[@]" - ${(@)tmp2#$tmp1} fi done diff -u of/Completion/_zftp Functions/Completion/_zftp --- of/Completion/_zftp Fri Feb 26 12:50:29 1999 +++ Functions/Completion/_zftp Fri Feb 26 14:08:55 1999 @@ -1,7 +1,7 @@ #defpatcomp zf* # Don't try any more completion after this. -COMPSKIP=1 +_compskip=1 # Completion for zftp builtin and zf* functions. The functions # zfcd_match and zfget_match (used for old-style completion) @@ -45,6 +45,6 @@ *) # dunno... try ordinary completion after all. - unset COMPSKIP + unset _compskip ;; esac diff -u of/Completion/dump Functions/Completion/dump --- of/Completion/dump Fri Feb 26 12:50:29 1999 +++ Functions/Completion/dump Fri Feb 26 14:56:26 1999 @@ -32,13 +32,11 @@ done >> $_d_file print ")" >> $_d_file -if (( $#_patcomps )); then - print "\n_patcomps=(" >> $_d_file - for _d_f in "$_patcomps[@]"; do - print -r - "'${_d_f//\'/'\\''}'" - done >> $_d_file - print ")" >> $_d_file -fi +print "\n_patcomps=(" >> $_d_file +for _d_f in "$_patcomps[@]"; do + print -r - "'${_d_f//\'/'\\''}'" +done >> $_d_file +print ")" >> $_d_file print >> $_d_file diff -u of/Completion/init Functions/Completion/init --- of/Completion/init Fri Feb 26 12:50:29 1999 +++ Functions/Completion/init Fri Feb 26 14:41:10 1999 @@ -57,6 +57,7 @@ # Definitions for patterns will be stored in the normal array `_patcomps'. typeset -A _comps +_patcomps=() # This function is used to register or delete completion functions. For # registering completion functions, it is invoked with the name of the @@ -147,11 +148,7 @@ # Patterns are stored in strings like `c* foo', with a space # between the pattern and the function name. - if (( $+_patcomps )); then - _patcomps=("$_patcomps[@]" "$1 $func") - else - _patcomps=("$1 $func") - fi + _patcomps=("$_patcomps[@]" "$1 $func") ;; key) if [[ $# -lt 2 ]]; then -- Sven Wischnowsky wischnow@informatik.hu-berlin.de