From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15712 invoked from network); 17 Jun 1999 07:24:12 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 17 Jun 1999 07:24:12 -0000 Received: (qmail 21313 invoked by alias); 17 Jun 1999 07:23:54 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6685 Received: (qmail 21306 invoked from network); 17 Jun 1999 07:23:53 -0000 Date: Thu, 17 Jun 1999 09:23:52 +0200 (MET DST) Message-Id: <199906170723.JAA07682@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: Peter Stephenson's message of Tue, 15 Jun 1999 11:15:55 +0200 Subject: PATCH: numeric arg (was: Re: pws-22) Peter Stephenson wrote: > we probably have to change $NUMERIC in zle widgets so > that it's not set if there is no prefix. This makes NUMERIC be unset when no numeric argument was typed. It also allows unsetting NUMERIC to make called widgets behave as if no num arg was given. Finally, it also allows `unset NUMERIC;NUMERIC=9' in a way that the assignment treats NUMERIC as a special parameter even after that `unset'. For this to work I had to change the `pm-level = locallevel' to `...locallevel + 1'. Hm, this is nice to have at least in this case and somehow it feals right (after all, we are creating parameters for a function that is still to be called), but I'd like to hear if you all agree. Bye Sven P.S.: The uses in the completion code have been changed. Are there others? diff -u -r os/Zle/compctl.c Src/Zle/compctl.c --- os/Zle/compctl.c Wed Jun 16 10:31:46 1999 +++ Src/Zle/compctl.c Thu Jun 17 09:13:31 1999 @@ -2223,7 +2223,7 @@ DPUTS(!pm, "param not set in addcompparams"); *pp = pm; - pm->level = locallevel; + pm->level = locallevel + 1; if ((pm->u.data = cp->var)) { switch(PM_TYPE(cp->type)) { case PM_SCALAR: diff -u -r os/Zle/zle_params.c Src/Zle/zle_params.c --- os/Zle/zle_params.c Wed Jun 16 10:31:47 1999 +++ Src/Zle/zle_params.c Thu Jun 17 09:13:32 1999 @@ -69,8 +69,8 @@ zleunsetfn, NULL }, { "keys", PM_ARRAY | PM_READONLY, NULL, FN(get_keys), zleunsetfn, NULL }, - { "NUMERIC", PM_INTEGER, FN(set_numeric), FN(get_numeric), - zleunsetfn, NULL }, + { "NUMERIC", PM_INTEGER | PM_UNSET, FN(set_numeric), FN(get_numeric), + unset_numeric, NULL }, { "HISTNO", PM_INTEGER | PM_READONLY, NULL, FN(get_histno), zleunsetfn, NULL }, { NULL, 0, NULL, NULL, NULL, NULL } @@ -89,7 +89,7 @@ pm = (Param) paramtab->getnode(paramtab, zp->name); DPUTS(!pm, "param not set in makezleparams"); - pm->level = locallevel; + pm->level = locallevel + 1; pm->u.data = zp->data; switch(PM_TYPE(zp->type)) { case PM_SCALAR: @@ -107,6 +107,8 @@ break; } pm->unsetfn = zp->unsetfn; + if ((zp->type & PM_UNSET) && (zmod.flags & MOD_MULT)) + pm->flags &= ~PM_UNSET; } } @@ -267,6 +269,7 @@ set_numeric(Param pm, zlong x) { zmult = x; + zmod.flags = MOD_MULT; } /**/ @@ -274,6 +277,17 @@ get_numeric(Param pm) { return zmult; +} + +/**/ +static void +unset_numeric(Param pm, int exp) +{ + if (exp) { + stdunsetfn(pm, exp); + zmod.flags = 0; + zmult = 1; + } } /**/ diff -u -r od/Zsh/zle.yo Doc/Zsh/zle.yo --- od/Zsh/zle.yo Thu Jun 17 09:09:42 1999 +++ Doc/Zsh/zle.yo Thu Jun 17 09:13:33 1999 @@ -162,7 +162,11 @@ ) vindex(NUMERIC) item(tt(NUMERIC) (integer))( -The numeric argument. +The numeric argument. If no numeric argument was given, this parameter +is unset. When this is set inside a widget function, builtin widgets +called with the tt(zle) builtin command will use the value +assigned. If it is unset inside awidget function, builtin widgets +called behave as if no numeric argument was given. ) vindex(HISTNO) item(tt(HISTNO) (integer))( diff -u -r oc/Base/_first Completion/Base/_first --- oc/Base/_first Wed Jun 16 10:31:21 1999 +++ Completion/Base/_first Thu Jun 17 09:13:32 1999 @@ -40,9 +40,9 @@ # PREFIX="$PREFIX[1,-2]" # # If a numeric prefix is given, we use it as the number of # # lines (multiplied by ten below) in the history to search. -# if [[ NUMERIC -gt 1 ]]; then +# if [[ ${NUMERIC:-1} -gt 1 ]]; then # max=$NUMERIC -# NUMERIC=1 +# unset NUMERIC # else # # The default is to search the last 100 lines. # max=10 diff -u -r oc/Commands/_correct_filename Completion/Commands/_correct_filename --- oc/Commands/_correct_filename Wed Jun 16 10:31:24 1999 +++ Completion/Commands/_correct_filename Thu Jun 17 09:13:32 1999 @@ -23,7 +23,7 @@ file=$1 local IPREFIX else - (( NUMERIC > 1 )) && max_approx=$NUMERIC + (( ${NUMERIC:-1} > 1 )) && max_approx=$NUMERIC fi if [[ $file = \~*/* ]]; then diff -u -r oc/Commands/_most_recent_file Completion/Commands/_most_recent_file --- oc/Commands/_most_recent_file Wed Jun 16 10:31:24 1999 +++ Completion/Commands/_most_recent_file Thu Jun 17 09:13:32 1999 @@ -14,9 +14,9 @@ if [[ $PREFIX = \~*/* ]]; then tilde=${PREFIX%%/*} etilde=${~tilde} - file=($~PREFIX*$~SUFFIX(om[$NUMERIC]N)) + file=($~PREFIX*$~SUFFIX(om[${NUMERIC:-1}]N)) file=(${file/#$etilde/$tilde}) else - file=($~PREFIX*$~SUFFIX(om[$NUMERIC]N)) + file=($~PREFIX*$~SUFFIX(om[${NUMERIC:-1}]N)) fi (( $#file )) && compadd -U -i "$IPREFIX" -I "$ISUFFIX" -f -Q $file diff -u -r oc/Core/_approximate Completion/Core/_approximate --- oc/Core/_approximate Wed Jun 16 10:31:26 1999 +++ Completion/Core/_approximate Thu Jun 17 09:13:32 1999 @@ -89,14 +89,14 @@ # Get the number of errors to accept. -if [[ "$cfgacc" = *[nN]* && NUMERIC -ne 1 ]]; then +if [[ "$cfgacc" = *[nN]* && ${NUMERIC:-1} -ne 1 ]]; then # Stop if we also have a `!'. [[ "$cfgacc" = *\!* ]] && return 1 # Prefer the numeric argument if that has a sensible value. - comax="$NUMERIC" + comax="${NUMERIC:-1}" else comax="${cfgacc//[^0-9]}" fi diff -u -r oc/Core/_expand Completion/Core/_expand --- oc/Core/_expand Wed Jun 16 10:31:26 1999 +++ Completion/Core/_expand Thu Jun 17 09:13:33 1999 @@ -17,7 +17,7 @@ # In this case, expansion of substitutions will be done if the # expression evaluates to `1'. For example, with # -# compconf expand_substitute='NUMERIC != 1' +# compconf expand_substitute='${NUMERIC:-1} != 1' # # substitution will be performed only if given an explicit numeric # argument other than `1', as by typing ESC 2 TAB. diff -u -r oc/Core/_list Completion/Core/_list --- oc/Core/_list Wed Jun 16 10:31:26 1999 +++ Completion/Core/_list Thu Jun 17 09:13:33 1999 @@ -14,7 +14,7 @@ # will be done if the expression evaluates to `1'. # For example, with # -# compconf list_condition='NUMERIC != 1' +# compconf list_condition='${NUMERIC:-1} != 1' # # delaying will be done only if given an explicit numeric argument # other than `1'. -- Sven Wischnowsky wischnow@informatik.hu-berlin.de