From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21128 invoked from network); 5 Mar 1999 14:45:08 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 5 Mar 1999 14:45:08 -0000 Received: (qmail 28576 invoked by alias); 5 Mar 1999 14:44:51 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5665 Received: (qmail 28563 invoked from network); 5 Mar 1999 14:44:49 -0000 Date: Fri, 5 Mar 1999 15:43:28 +0100 (MET) Message-Id: <199903051443.PAA04629@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk Subject: PATCH: return value in examples This makes at least the basic helper functions in `Core' return zero if matches were added and non-zero otherwise (so that you can do `_path_files -g "*.c" || _files "*.h"' or whatever). I have not changed all the command functions, though. Bye Sven diff -u -r oc/Core/_comp_parts Completion/Core/_comp_parts --- oc/Core/_comp_parts Fri Mar 5 14:23:23 1999 +++ Completion/Core/_comp_parts Fri Mar 5 15:22:54 1999 @@ -21,11 +21,11 @@ # `_match_test' and `_match_pattern' for this. local str arr sep test testarr tmparr prefix suffixes matchers autosuffix -local matchflags opt group expl +local matchflags opt group expl nm=$compstate[nmatches] # Test if we should use this function for the global matcher in use. -_match_test _comp_parts || return +_match_test _comp_parts || return 1 # Get the options. @@ -71,7 +71,7 @@ # If there are no matches we give up. If there is more than one # match, this is the part we will complete. - (( $#testarr )) || return + (( $#testarr )) || return 1 [[ $#testarr -gt 1 ]] && break # Only one match, add it to the prefix and skip over it in `str', @@ -98,7 +98,7 @@ testarr=( "${(@)testarr:#}" ) fi -[[ $#testarr -eq 0 || ${#testarr[1]} -eq 0 ]] && return +[[ $#testarr -eq 0 || ${#testarr[1]} -eq 0 ]] && return 1 # Now we build the suffixes to give to the completion code. shift @@ -154,3 +154,7 @@ compadd -U "$group[@]" "$expl[@]" "$matchers[@]" "$autosuffix[@]" \ -i "$IPREFIX" -p "$prefix" -s "$i" - "$testarr[@]" done + +# This sets the return value to indicate that we added matches (or not). + +[[ nm -ne compstate[nmatches] ]] diff -u -r oc/Core/_files Completion/Core/_files --- oc/Core/_files Fri Mar 5 14:23:23 1999 +++ Completion/Core/_files Fri Mar 5 15:38:01 1999 @@ -3,9 +3,10 @@ # Utility function for completing files of a given type or any file. # In many cases you will want to call this one instead of _path_files(). -local nm=$compstate[nmatches] +local nm=$compstate[nmatches] ret _path_files "$@" +ret=$? if [[ $# -ne 0 && compstate[nmatches] -eq nm ]]; then local opt opts @@ -23,4 +24,6 @@ done _path_files "$opts[@]" +else + return $ret fi diff -u -r oc/Core/_normal Completion/Core/_normal --- oc/Core/_normal Fri Mar 5 14:23:23 1999 +++ Completion/Core/_normal Fri Mar 5 15:36:53 1999 @@ -1,6 +1,6 @@ #autoload -local comp command cmd1 cmd2 pat val name i +local comp command cmd1 cmd2 pat val name i ret # Completing in command position? If not we set up `cmd1' and `cmd2' as # two strings we have search in the completion definition arrays (e.g. @@ -29,9 +29,10 @@ val="${i#* }" if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then "$val" + ret=$? if (( $+_compskip )); then unset _compskip - return + return $ret fi fi done diff -u -r oc/Core/_path_files Completion/Core/_path_files --- oc/Core/_path_files Fri Mar 5 14:23:23 1999 +++ Completion/Core/_path_files Fri Mar 5 15:22:11 1999 @@ -14,13 +14,13 @@ # First see if we should generate matches for the global matcher in use. -_match_test _path_files || return +_match_test _path_files || return 1 # Yes, so... 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 expl orig ostr +local addpfx addsfx expl orig ostr nm=$compstate[nmatches] setopt localoptions nullglob rcexpandparam globdots extendedglob unsetopt markdirs globsubst shwordsplit nounset @@ -123,7 +123,7 @@ # If this generated any matches, we don't want to do in-path completion. - [[ compstate[nmatches] -eq nm ]] || return + [[ compstate[nmatches] -eq nm ]] || return 0 # No `-F' option, so we want to use `fignore'. @@ -142,7 +142,7 @@ linepath="${str%%/*}/" eval realpath\=$linepath - [[ "$realpath" = "$linepath" ]] && return + [[ "$realpath" = "$linepath" ]] && return 1 str="${str#*/}" orig="${orig#*/}" donepath='' @@ -331,7 +331,7 @@ [[ -n "$ostr" && -n "$linepath$testpath" ]] && ostr="/$ostr" # But only if something changed. - [[ "$linepath$testpath$ostr" = "$PREFIX$SUFFIX" ]] && return + [[ "$linepath$testpath$ostr" = "$PREFIX$SUFFIX" ]] && return 1 compadd -QU -S '' "$group[@]" "$expl[@]" \ -i "$IPREFIX" -f - "${linepath:q}${testpath:q}$ostr" @@ -341,3 +341,7 @@ -W "$prepath$realpath$testpath" - "${(@)tmp2#$tmp1}" fi done + +# This sets the return value to indicate that we added matches (or not). + +[[ nm -ne compstate[nmatches] ]] -- Sven Wischnowsky wischnow@informatik.hu-berlin.de