From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20846 invoked from network); 27 Mar 2001 13:02:50 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 27 Mar 2001 13:02:50 -0000 Received: (qmail 5614 invoked by alias); 27 Mar 2001 13:02:36 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 13790 Received: (qmail 5603 invoked from network); 27 Mar 2001 13:02:35 -0000 Date: Tue, 27 Mar 2001 15:02:35 +0200 (MET DST) Message-Id: <200103271302.PAA15735@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.dk In-reply-to: Sven Wischnowsky's message of Mon, 26 Mar 2001 11:21:50 +0200 (MET DST) Subject: PATCH: Re: return code of _arguments I wrote: > Bart Schaefer wrote: > > > On Mar 23, 11:33pm, Oliver Kiddle wrote: > > } Subject: return code of _arguments > > } > > } If my understanding is correct the test [[ $? = 300 ]] after _arguments > > } is going to be equivalent to the test [[ -n $state ]]? > > > > I suggested getting rid of the 300 return code once before. > > Hm. We could of course add an option to _arguments to make it return > 300 when needed. Non-_arguments-wrappers would call it without the > option... Here's that change. No more return 300 unless you give the -R option to _arguments. Bye Sven Index: Completion/Base/_arguments =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/_arguments,v retrieving revision 1.32 diff -u -r1.32 _arguments --- Completion/Base/_arguments 2000/08/02 10:36:20 1.32 +++ Completion/Base/_arguments 2001/03/27 13:00:03 @@ -4,7 +4,7 @@ # descriptions given as arguments to this function. local long cmd="$words[1]" descr mesg subopts opt usecc autod -local oldcontext="$curcontext" hasopts +local oldcontext="$curcontext" hasopts rawret long=$argv[(I)--] if (( long )); then @@ -173,11 +173,12 @@ fi subopts=() -while [[ "$1" = -(O*|C) ]]; do +while [[ "$1" = -(O*|[CR]) ]]; do case "$1" in - -C) usecc=yes; shift ;; - -O) subopts=( "${(@P)2}" ); shift 2 ;; - -O*) subopts=( "${(@P)1[3,-1]}" ); shift ;; + -C) usecc=yes; shift ;; + -O) subopts=( "${(@P)2}" ); shift 2 ;; + -O*) subopts=( "${(@P)1[3,-1]}" ); shift ;; + -R) rawret=yes; shift;; esac done @@ -394,10 +395,11 @@ [[ -z "$aret" || -z "$usecc" ]] && curcontext="$oldcontext" - [[ -n "$aret" ]] && return 300 - - [[ -n "$noargs" && nm -eq "$compstate[nmatches]" ]] && _message "$noargs" - + if [[ -n "$aret" ]]; then + [[ -n $rawret ]] && return 300 + else + [[ -n "$noargs" && nm -eq "$compstate[nmatches]" ]] && _message "$noargs" + fi # Set the return value. [[ nm -ne "$compstate[nmatches]" ]] Index: Completion/X/_x_arguments =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/X/_x_arguments,v retrieving revision 1.1.1.6 diff -u -r1.1.1.6 _x_arguments --- Completion/X/_x_arguments 2000/02/22 09:02:43 1.1.1.6 +++ Completion/X/_x_arguments 2001/03/27 13:00:03 @@ -1,6 +1,6 @@ #compdef -P */X11(|R[456])/* -local ret long xargs +local ret long xargs opts rawret nm="$compstate[nmatches]" xargs=( '-display:display:_x_display' @@ -16,10 +16,20 @@ set -- "$@" "$xargs[@]" fi -_arguments "$@" +opts=() +while [[ $1 = -(O*|[CR]) ]]; do + opts=($opts $1) + [[ $1 = -R ]] && rawret=yes + shift +done +_arguments -R "$opts[@]" "$@" + ret=$? -[[ "$ret" = 300 ]] && compstate[restore]='' +if [[ "$ret" = 300 ]]; then + compstate[restore]='' + [[ -z $rawret ]] && ret=$(( nm == $compstate[nmatches] )) +fi return ret Index: Completion/X/_xt_arguments =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/X/_xt_arguments,v retrieving revision 1.1.1.7 diff -u -r1.1.1.7 _xt_arguments --- Completion/X/_xt_arguments 2000/03/23 03:51:36 1.1.1.7 +++ Completion/X/_xt_arguments 2001/03/27 13:00:04 @@ -20,7 +20,7 @@ # cf. XrmParseCommand(3X11), X11R6.4/xc/lib/Xt/Initialize.c, X(5) -local ret long xargs +local ret long xargs opts rawret nm="$compstate[nmatches]" xargs=( -+{rv,synchronous} @@ -52,10 +52,20 @@ set -- "$@" "$xargs[@]" fi -_arguments "$@" +opts=() +while [[ $1 = -(O*|[CR]) ]]; do + opts=($opts $1) + [[ $1 = -R ]] && rawret=yes + shift +done +_arguments -R "$opts[@]" "$@" + ret=$? -[[ "$ret" = 300 ]] && compstate[restore]='' +if [[ "$ret" = 300 ]]; then + compstate[restore]='' + [[ -z $rawret ]] && ret=$(( nm == $compstate[nmatches] )) +fi return ret Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.111 diff -u -r1.111 compsys.yo --- Doc/Zsh/compsys.yo 2001/03/26 08:27:04 1.111 +++ Doc/Zsh/compsys.yo 2001/03/27 13:00:06 @@ -3070,12 +3070,18 @@ An var(action) of the form `tt(->)var(string)' is used by functions that implement a state machine. In this case, the `var(string)'s (with all leading and trailing spaces and tabs removed) of all actions that -have to be used will be stored in -the global array tt(state) and the function returns with a return +have to be used will be stored in the global array tt(state). The +function returns with a non-zero return value if the cursor is not in +a position where options can be completed or if the current word could +not be completed to an option. But if the tt(-R) option is given to +tt(_arguments), the function will instead return with a return value of 300 (to make it distinguishable from other return values) after setting the global `tt(context)', `tt(line)' and `tt(opt_args)' parameters as described below, and without resetting any changes made -to the special parameters such as tt(PREFIX) and tt(words). +to the special parameters such as tt(PREFIX) and tt(words). This +allows to write wrapper functions around tt(_arguments) that have to +be able to find out if they have to make sure that the special +completion parameters are not reset when they return. Note that this means that a function calling tt(_arguments) with at least one action containing such a `tt(->)var(string)' has to declare -- Sven Wischnowsky wischnow@informatik.hu-berlin.de