zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: was: oops, a set -x
@ 1999-11-23 14:12 Sven Wischnowsky
  1999-11-23 15:40 ` Tanaka Akira
  0 siblings, 1 reply; 2+ messages in thread
From: Sven Wischnowsky @ 1999-11-23 14:12 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> In article <199911121503.QAA30053@beta.informatik.hu-berlin.de>,
>   Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:
> 
> > Tanaka: have you mentioned that at the time you wrote it and I missed
> > it? I tried and since `_telnet' doesn't support options for my
> > `telnet' at all, I couldn't find out what goes wrong with these
> > options. Could you explain that to me so that we can fix it and
> > simplify `_telnet'?
> 
> I wrote _telnet with the telnet source of FreeBSD.
> http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/telnet/main.c?rev=1.9
> 
> It may have short option "-n" and long options "-noasynch",
> "-noasynchtty" and "-noasynchnet" under some circumstances.  These
> long options are implemented by special case of short option "-n".
> 
> When completion is tryed just after "-n", zsh cannot decide that it is
> the short option or not.  So, _telnet should complete option arguments
> for "-n" and long options as:
> 
> % telnet -<TAB>
> -n -noasynch -noasynchtty -noasynchnet and other options
> 
> % telnet -n<TAB>
> -noasynch -noasynchtty -noasynchnet and filenames
> 
> % telnet -n <TAB>
> filenames
> 
> % telnet -no<TAB>
> -noasynch -noasynchtty -noasynchnet and filenames start with "o".

This patch should do the job. One `side-effect' is that _arguments in
single-letter mode now prefers to take strings from the line as long
options if possible. I.e. if possible options are `-b', `-a', `-r',
and `-bar' and you do `foo -bar -<TAB>', it will take the `-bar' as
the the option `-bar' and offer you only the other ones. But I think
this is actually a good change.

I've tested the whole thing with:

  _arguments -s \
    '-n+:xx:(foo bar)' -k -l \
    '-lnoasync' -lnofrob -noasync

...to make sure that in this case even `-ln<TAB>' does the right thing 
(take it as the options `-l' and `-n' or the start of `-lno*').

However, I have *not* change _telnet because, as I said, I don't have
a version with these options. Tanaka, could you...? If I'm not
completely mistaken it should just make it much simpler.

Bye
 Sven

P.S.: It also required some saving/restoring of $PREFIX and $IPREFIX
      in _arguments.

diff -u oldsrc/Zle/computil.c Src/Zle/computil.c
--- oldsrc/Zle/computil.c	Tue Nov 23 12:49:14 1999
+++ Src/Zle/computil.c	Tue Nov 23 15:00:41 1999
@@ -941,13 +941,17 @@
 {
     Caopt p;
 
-    if (full) {
-	/* The full string has to be an option. */
+    /* The full string may be an option. */
 
-	for (p = d->opts; p; p = p->next)
-	    if (p->active && !strcmp(p->name, line))
-		return p;
-    } else {
+    for (p = d->opts; p; p = p->next)
+	if (p->active && !strcmp(p->name, line)) {
+	    if (end)
+		*end = line + strlen(line);
+
+	    return p;
+	}
+
+    if (!full) {
 	/* The string from the line probably only begins with an option. */
 	for (p = d->opts; p; p = p->next)
 	    if (p->active && ((!p->args || p->type == CAO_NEXT) ?
@@ -1160,7 +1164,7 @@
 	    } LASTALLOC;
 	    ca_inactive(d, state.curopt->xor);
 
-	    /* Collect the argument strings. MAybe. */
+	    /* Collect the argument strings. Maybe. */
 
 	    if (state.def &&
 		(state.curopt->type == CAO_DIRECT ||
@@ -1431,7 +1435,7 @@
 	    return 1;
 	}
     case 'O':
-	if (ca_laststate.opt) {
+	if (ca_laststate.opt || (ca_laststate.doff && ca_laststate.def)) {
 	    LinkList next = newlinklist();
 	    LinkList direct = newlinklist();
 	    LinkList odirect = newlinklist();
@@ -1484,7 +1488,8 @@
 	    return 1;
 	}
     case 's':
-	if (ca_laststate.d->single && ca_laststate.singles) {
+	if (ca_laststate.d->single && ca_laststate.singles &&
+	    ca_laststate.opt) {
 	    setsparam(args[1],
 		      ztrdup(ca_laststate.ddef ?
 			     (ca_laststate.ddef->type == CAO_DIRECT ?
diff -u -r oldcompletion/Base/_arguments Completion/Base/_arguments
--- oldcompletion/Base/_arguments	Tue Nov 23 12:50:00 1999
+++ Completion/Base/_arguments	Tue Nov 23 15:00:20 1999
@@ -165,8 +165,9 @@
 
 if comparguments -i "$autod" "$@"; then
   local nm="$compstate[nmatches]" action noargs aret expl local
-  local next direct odirect equal single match matched ws tmp1 tmp2
+  local next direct odirect equal single match matched ws tmp1 tmp2 tmp3
   local opts subc prefix suffix
+  local origpre="$PREFIX" origipre="$IPREFIX"
 
   if comparguments -D descr action; then
     comparguments -C subc
@@ -254,11 +255,17 @@
           fi
         fi
       fi
+
       if [[ -z "$matched" ]] && _requested options &&
           { ! _style options prefix-needed ||
-            [[ "$PREFIX" = [-+]* ]] } ; then
-        comparguments -M match
+            [[ "$origpre" = [-+]* ]] } ; then
+	local prevpre="$PREFIX" previpre="$IPREFIX"
+
+	PREFIX="$origpre"
+	IPREFIX="$origipre"
 
+        comparguments -M match
+	
         if comparguments -s single; then
 
           _description expl option
@@ -271,11 +278,13 @@
 	    compadd "$expl[@]" -QqS= - "${PREFIX}${SUFFIX}"
           else
 	    tmp1=( "$next[@]" "$direct[@]" "$odirect[@]" "$equal[@]" )
+	    tmp3=( "${(M@)tmp1:#[-+]?[^:]*}" )
 	    tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" )
 	    tmp2=( "${PREFIX}${(@M)^${(@)${(@)tmp1%%:*}#[-+]}:#?}" )
 
             _describe -o option \
-                      tmp1 tmp2 -Q -S ''
+                      tmp1 tmp2 -Q -S '' -- \
+		      tmp3 -Q
           fi
           single=yes
         else
@@ -285,10 +294,15 @@
             direct -QS '' -M "$match" -- \
             equal -QqS= -M "$match"
         fi
+	PREFIX="$prevpre"
+	IPREFIX="$previpre"
       fi
     done
     if [[ -n "$opts" && -z "$aret$matched" &&
           nm -eq compstate[nmatches] ]]; then
+
+      PREFIX="$origpre"
+      IPREFIX="$origipre"
 
       prefix="${PREFIX#*\=}"
       suffix="$SUFFIX"

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: was: oops, a set -x
  1999-11-23 14:12 PATCH: was: oops, a set -x Sven Wischnowsky
@ 1999-11-23 15:40 ` Tanaka Akira
  0 siblings, 0 replies; 2+ messages in thread
From: Tanaka Akira @ 1999-11-23 15:40 UTC (permalink / raw)
  To: zsh-workers

In article <199911231412.PAA09062@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> However, I have *not* change _telnet because, as I said, I don't have
> a version with these options. Tanaka, could you...? If I'm not
> completely mistaken it should just make it much simpler.

In reality, I don't have such telnet too.  So, I test _telnet with
following function.  I think _arguments works well.

telnet () {
  print -r - \
'Usage: telnet [-8] [-E] [-K] [-L] [-N] [-S tos] [-X atype] [-a] [-c] [-d]
	[-e char] [-k realm] [-l user] [-f/-F] [-n tracefile] [-noasynch] [-noasynctty]
	[-noasyncnet] [-r] [-s src_addr] [-t transcom] [host-name [port]]' >&2
}

Index: Completion/User/_telnet
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_telnet,v
retrieving revision 1.1.1.11
diff -u -r1.1.1.11 _telnet
--- Completion/User/_telnet	1999/11/22 13:31:19	1.1.1.11
+++ Completion/User/_telnet	1999/11/23 15:28:53
@@ -8,7 +8,7 @@
 local curcontext="$curcontext" state line expl
 typeset -A opt_args
 
-if (( ! $+_telnet_short )); then
+if (( ! $+_telnet_args )); then
   local k help="$(telnet -\? < /dev/null 2>&1)"
   local -A optionmap
   optionmap=( "[-8]" '-8[allow 8-Bit data]' \
@@ -30,34 +30,21 @@
               "[-r]" '-r[rlogin like user interface]' \
               "[-s src_addr]" '-s+[set source IP address]:src_addr:' \
               "[-x]" '-x' \
-              "[-t transcom]" '-t+:transcom:' )
-
-  _telnet_short=()
-  for k in ${(k)optionmap}
-  do
-    [[ "$help" = *"$k"* ]] &&
-      _telnet_short=( "$_telnet_short[@]" "$optionmap[$k]" )
-  done
-
-  # _arguments cannot handle following three options.
-  optionmap=( "[-noasynch]" '-noasynch' \
+              "[-t transcom]" '-t+:transcom:' \
+              "[-noasynch]" '-noasynch' \
               "[-noasyncnet]" '-noasyncnet' \
               "[-noasynctty]" '-noasynctty' )
 
-  _telnet_long=()
+  _telnet_args=()
   for k in ${(k)optionmap}
   do
     [[ "$help" = *"$k"* ]] &&
-      _telnet_long=( "$_telnet_long[@]" "$optionmap[$k]" )
+      _telnet_args=( "$_telnet_args[@]" "$optionmap[$k]" )
   done
 fi
 
-(( $#_telnet_long )) && _wanted options expl option &&
-   { ! _style options prefix-needed || [[ "$PREFIX" = [-+]* ]] } &&
-    _describe -o option _telnet_long "$expl[@]"
-
 _arguments -C -s \
-  "$_telnet_short[@]" \
+  "$_telnet_args[@]" \
   ':host:->hosts' \
   ':port:->ports'
 
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-11-23 15:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-23 14:12 PATCH: was: oops, a set -x Sven Wischnowsky
1999-11-23 15:40 ` Tanaka Akira

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).