zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: _urls, _netscape, a seg fault and new completion thoughts
@ 1999-10-13 14:17 Sven Wischnowsky
  1999-10-13 15:34 ` Oliver Kiddle
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 1999-10-13 14:17 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> I had a bit of difficulty in getting the remote command completion to
> work properly with different types of quoting and there is probably
> plenty of scope for that to be further improved. I'm not sure how many
> of the problems with the quoting are my fault though: zsh will seg
> fault if I do:
> netscape -remote 'openURL(<tab>

Whew. When trying to reproduce this, I:

- first couldn't get the completion to do the right thing at all,
  because there was a buglet in the computil module
- after fixing this I found a bug in the parameter module which I
  fixed in utils.c: zwarnnam() was called with a NULL cmd argument,
  this is handled now by simply not trying to print a `cmd:'
- then I found a bug in sep_comp_sep(): the string in the quotes was
  tokenized which caused trouble in sep_comp_string()

Partly this was caused by `_netscape' not declaring enough local
parameters (`line' and `options' were missing). Or more precisely
because this caused the shell to set the `options' parameter from the
`parameter' module. Damn, I should have used another name, I knew this 
would cause trouble some time.

> Is there a good reason why I don't get a list of matches when
> completing inside quotes? This is the general case not anything to do
> with completing urls etc. e.g. cd 'm<tab> will complete to 'man/ but
> if I added another directory beginning with m, nothing would happen - no
> list.

Hm, this works for me -- unless you mean `cd man m<TAB>' which of
course shouldn't work.

> While writing this completion, I came across a number of circumstances
> where I wanted to pass certain compadd style options (e.g. -r, -s, -M)
> to _urls or _files but couldn't because they were not handled in some
> circumstances. As a way of making the new completions simpler, I think
> we should try to make all the completion commands standardise much more
> on their options so things such as -P -s -S -r can be used throughout
> with a common meaning and can be safely passed from one completion
> function to another.

`-P', `-S', and `-r': yes. `-s': no, this is needed by some functions
and I think calling functions shouldn't mess with them. For such
prefixes or suffixes they should use `I{PRE,SUF}FIX' (and `compset').

In fact, I tried to make the basic completion functions (the utility
functions) accept all options that may be interesting for calling
functions. Seems like I forgot to add `-r' when that was added.

> I think it would make things easier if compgen in particular took more
> of compadd's options. The problem is that most of the option letters
> are already used because compgen takes all the standard compctl
> options. Maybe we should strip compgen of many of the options
> which nolonger are of much use because they are implemented by new
> functions (e.g. -f -/ -g -u). I would even say we should consider
> ditching compgen altogether: it would fit in much better with the rest
> of the system where different functions complete different types of
> things if for example jobs were completed with compjob instead of the
> not very readable compgen -j, -z and -r. Alternatively, the option
> letters could be freed by moving compgen syntax away from the compctl
> style and use more full words to describe what it is completing -
> compgen suspended-jobs would be much easier to read.

I would be against a plethora of new builtins just to add completions
for only jobs and such. Also I don't like changing it to a full-word
argument style because no other buitlin does it this way. What I would 
like is to add more basic functions acting as wrappers around certain
compgen options (probably also giving interesting match specs for them 
and adding the `_description' stuff). We have already made steps
toward that, just look at functions like `_parameter', but not for
everything for which it makes sense (for some of compgen's options it
doesn't make sense because they are useful only for one or two
commands). The only problem is that noone seems to have found the time 
to do the work.
About disallowing some of the options: for some I did it from the
beginning. For other I'm not sure, mainly because I (and I guess by
now I'm really the only one) still think of the completion system as
an *example* (a rather biggish one). I'd like to not restrict the
possibilities of other completion system implementations by removing
options just because `we have already functions for it'.

*But*: I like to think of the moment where everyone uses the function
system and I can finally remove compctl altogether, i.e. that type of
interface, and clean up the code in tricky.c because there are
differences enough to cause trouble (and they already did because I
constantly forget to test the compctl style of completion).

So, I wouldn't be against removing `compgen' altogether... when we
finally have a way to produce all the matches that can be added by it
in another way. Actually I wrote the parameter module with that in
mind. But there are still things that aren't supported by it (jobs,
history, user names, and so on...). Once we have ways to produce
everything in a form we can give to compadd, I'll be happy to remove
compgen.

A complete list of the things compgen can do we can't easily generate
otherwise (preferably without the expensive `$(...)' constructs!)
might already help here, so if anyone finds the time...


Ok, this patch fixes the bugs described above. It also changes `_urls' 
and `_netscape' to use `_description' for the URL prefixes (folks,
please use it everywhere; for one, it looks weird if you suddenly get
a list without description after have gotten used to them, and then
a certain list member is currently thinking about combining it with
the tag stuff we have discussed -- which will make it more important).

Then I changed the names of the arrays used by `_arguments' and
`_values' to `opt_args' and `val_args' so that they at least don't
collide with the parameters in the parameter module.

Bye
 Sven

diff -u -r oldsrc/Zle/computil.c Src/Zle/computil.c
--- oldsrc/Zle/computil.c	Wed Oct 13 11:47:13 1999
+++ Src/Zle/computil.c	Wed Oct 13 14:41:11 1999
@@ -812,8 +812,8 @@
 		return p;
     } else {
 	for (p = d->opts; p; p = p->next)
-	    if (p->active && p->args && p->type != CAO_NEXT &&
-		strpfx(p->name, line)) {
+	    if (p->active && ((!p->args || p->type == CAO_NEXT) ?
+			      !strcmp(p->name, line) : strpfx(p->name, line))) {
 		if (end) {
 		    int l = strlen(p->name);
 
diff -u -r oldsrc/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- oldsrc/Zle/zle_tricky.c	Wed Oct 13 11:47:15 1999
+++ Src/Zle/zle_tricky.c	Wed Oct 13 15:23:01 1999
@@ -5452,6 +5452,7 @@
 
     if (compisuffix)
 	s = dyncat(s, compisuffix);
+    untokenize(s);
 
     return sep_comp_string("", s, lip + lp, 0);
 }
diff -u -r oldsrc/utils.c Src/utils.c
--- oldsrc/utils.c	Wed Oct 13 11:47:03 1999
+++ Src/utils.c	Wed Oct 13 14:53:58 1999
@@ -91,8 +91,10 @@
 	nicezputs(scriptname ? scriptname : argzero, stderr);
 	fputs(": ", stderr);
     }
-    nicezputs(cmd, stderr);
-    fputs(": ", stderr);
+    if (cmd) {
+	nicezputs(cmd, stderr);
+	fputs(": ", stderr);
+    }
     zerrmsg(fmt, str, num);
 }
 
diff -u olddoc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- olddoc/Zsh/compsys.yo	Wed Oct 13 14:25:15 1999
+++ Doc/Zsh/compsys.yo	Wed Oct 13 16:14:28 1999
@@ -863,7 +863,7 @@
 all leading and trailing spaces and tabs removed) will be stored in
 the global parameter tt(state) and the function returns with a return
 value of 300 (to make it distinguishable from other return values)
-after setting the global `tt(line)' and `tt(options)'
+after setting the global `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).
 
@@ -894,7 +894,7 @@
 will be set to the command name and normal arguments from the command
 line, i.e. to the words from the command line excluding all options
 and their arguments. These are stored in the associative array
-`tt(options)', using the option names as keys and their arguments as
+`tt(opt_args)', using the option names as keys and their arguments as
 the values. For options that have more than one argument these are
 given as one string, separated by colons. All colons in the original
 arguments are preceded with backslashes.
@@ -1044,6 +1044,10 @@
 arguments) should be printed, the configuration key
 tt(describe_values) is used in the same way as the key
 tt(describe_options) is used by the tt(_arguments) function.
+
+One last difference is that this function uses the associative array
+tt(val_args) to report values and their arguments (but otherwise this
+is the same as the tt(opt_args) association used by tt(_arguments)).
 )
 item(tt(_regex_arguments))(
 This function is a compiler to generate a completion function.  The
diff -u -r oldcompletion/Base/_arguments Completion/Base/_arguments
--- oldcompletion/Base/_arguments	Wed Oct 13 11:47:42 1999
+++ Completion/Base/_arguments	Wed Oct 13 16:00:58 1999
@@ -171,18 +171,18 @@
       _description expl "$descr"
 
       if [[ "$action" = -\>* ]]; then
-        comparguments -W line options
+        comparguments -W line opt_args
         state="${${action[3,-1]##[ 	]#}%%[ 	]#}"
         compstate[restore]=''
         aret=yes
       else
         if [[ -z "$local" ]]; then
           local line
-          typeset -A options
+          typeset -A opt_args
           local=yes
         fi
 
-        comparguments -W line options
+        comparguments -W line opt_args
 
         if [[ "$action" = \ # ]]; then
 
diff -u -r oldcompletion/Base/_values Completion/Base/_values
--- oldcompletion/Base/_values	Wed Oct 13 11:47:43 1999
+++ Completion/Base/_values	Wed Oct 13 15:59:34 1999
@@ -59,14 +59,14 @@
       expl=( "-qS$sep" "$expl[@]" )
 
   if [[ "$action" = -\>* ]]; then
-    compvalues -v values
+    compvalues -v val_args
     state="${${action[3,-1]##[ 	]#}%%[ 	]#}"
     compstate[restore]=''
     return 1
   else
-    typeset -A values
+    typeset -A val_args
 
-    compvalues -v values
+    compvalues -v val_args
 
     if [[ "$action" = \ # ]]; then
 
diff -u -r oldcompletion/Linux/_rpm Completion/Linux/_rpm
--- oldcompletion/Linux/_rpm	Wed Oct 13 11:47:49 1999
+++ Completion/Linux/_rpm	Wed Oct 13 16:03:09 1999
@@ -44,7 +44,7 @@
 # Used by `_arguments', made local here.
 
 local state lstate line
-typeset -A options
+typeset -A opt_args
 
 state=''
 
diff -u -r oldcompletion/User/_flex Completion/User/_flex
--- oldcompletion/User/_flex	Wed Oct 13 14:25:27 1999
+++ Completion/User/_flex	Wed Oct 13 16:03:37 1999
@@ -1,7 +1,7 @@
 #compdef flex
 
 local state line ret=1
-typeset -A options
+typeset -A opt_args
 
 _arguments -s \
   --help --version \
diff -u -r oldcompletion/User/_gcc Completion/User/_gcc
--- oldcompletion/User/_gcc	Wed Oct 13 14:25:27 1999
+++ Completion/User/_gcc	Wed Oct 13 16:03:47 1999
@@ -1,7 +1,7 @@
 #compdef gcc
 
 local state line ret=1 expl args
-typeset -A options
+typeset -A opt_args
 
 args=()
 case $MACHTYPE in
diff -u -r oldcompletion/User/_gprof Completion/User/_gprof
--- oldcompletion/User/_gprof	Wed Oct 13 14:25:28 1999
+++ Completion/User/_gprof	Wed Oct 13 16:04:03 1999
@@ -1,7 +1,7 @@
 #compdef gprof
 
 local state line ret=1
-typeset -A options
+typeset -A opt_args
 
 _arguments -s -{a,b,c,D,h,i,l,L,s,T,v,w,x,y,z} \
            -{A,C,e,E,f,F,J,n,N,O,p,P,q,Q,Z}:'function name:->funcs' \
diff -u -r oldcompletion/User/_gs Completion/User/_gs
--- oldcompletion/User/_gs	Wed Oct 13 14:25:28 1999
+++ Completion/User/_gs	Wed Oct 13 16:04:16 1999
@@ -9,7 +9,7 @@
   fi
 else
   local state line ret=1
-  typeset -A options
+  typeset -A opt_args
 
   _x_arguments \
     '-q[quiet startup]' \
diff -u -r oldcompletion/User/_lynx Completion/User/_lynx
--- oldcompletion/User/_lynx	Wed Oct 13 14:25:29 1999
+++ Completion/User/_lynx	Wed Oct 13 16:04:31 1999
@@ -1,7 +1,7 @@
 #compdef lynx
 
 local state line
-typeset -A options
+typeset -A opt_args
 
 _arguments \
   '-accept_all_cookies' \
diff -u -r oldcompletion/User/_mount Completion/User/_mount
--- oldcompletion/User/_mount	Wed Oct 13 14:25:29 1999
+++ Completion/User/_mount	Wed Oct 13 16:05:46 1999
@@ -6,7 +6,7 @@
 # are below these table.
 
 local state line ret=1 args fss deffs=iso9660 descr tmp
-typeset -A options
+typeset -A opt_args
 
 if (( ! $+_fs_any )); then
 
@@ -233,30 +233,30 @@
   compadd "$expl[@]" -qS, -M 'L:|no=' - "$fss[@]" && ret=0
   ;;
 fsopt)
-  eval 'tmp=(' '"$_fs_'${(s:,:)^${options[-t]:-${deffs}}}'[@]"' ')'
+  eval 'tmp=(' '"$_fs_'${(s:,:)^${opt_args[-t]:-${deffs}}}'[@]"' ')'
   tmp=( "$_fs_any[@]" "${(@)tmp:#}" )
   _values -s , 'file system options' "$tmp[@]" && ret=0
   ;;
 devordir)
-  if (( $+options[-a] )); then
+  if (( $+opt_args[-a] )); then
     _message "no device or directory with option \`-a'"
   else
     _description expl device
     compadd "$expl[@]" /dev/* && ret=0
-    if (( ! $+options[-t] )); then
+    if (( ! $+opt_args[-t] )); then
       _description expl 'mount point'
       _files "$expl[@]" -/ && ret=0
     fi
   fi
   ;;
 udevordir)
-  if (( $+options[-a] )); then
+  if (( $+opt_args[-a] )); then
     _message "no device or directory with option \`-a'"
   else
     tmp=( "${(@f)$(< /etc/mtab)}" )
     _description expl device
     compadd "$expl[@]" - "${(@)${(@)tmp%% *}:#none}" && ret=0
-    if (( ! $+options[-t] )); then
+    if (( ! $+opt_args[-t] )); then
       _description expl 'mount point'
       compadd "$expl[@]" - "${(@)${(@)tmp#* }%% *}"
     fi
diff -u -r oldcompletion/User/_netscape Completion/User/_netscape
--- oldcompletion/User/_netscape	Wed Oct 13 14:25:29 1999
+++ Completion/User/_netscape	Wed Oct 13 16:14:08 1999
@@ -1,6 +1,7 @@
 #compdef netscape
 
-local state
+local state line
+typeset -A opt_args
 
 _x_arguments \
   '-xrm:resource:_x_resource' \
@@ -69,7 +70,8 @@
     compadd authors blank cache document fonts global hype image-cache \
         license logo memory-cache mozilla plugins
   else
-    compadd -S '' about: mocha: javascript:
+    _description expl 'URL prefix'
+    compadd "$expl[@]" -S '' about: mocha: javascript:
     _urls "$@"
   fi
 fi
diff -u -r oldcompletion/User/_nslookup Completion/User/_nslookup
--- oldcompletion/User/_nslookup	Wed Oct 13 14:25:29 1999
+++ Completion/User/_nslookup	Wed Oct 13 16:06:15 1999
@@ -113,7 +113,7 @@
     return
     ;;
   set)
-    typeset -A values
+    typeset -A val_args
 
     _values 'state information' "$setopts[@]" && ret=0
 
@@ -130,7 +130,7 @@
 
 if [[ -z "$state" ]]; then
   local line
-  typeset -A options
+  typeset -A opt_args
 
   _arguments \
     "-${(@)^${(@M)setopts:#*\]:*}/\[/=[}" \
diff -u -r oldcompletion/User/_rlogin Completion/User/_rlogin
--- oldcompletion/User/_rlogin	Wed Oct 13 14:25:30 1999
+++ Completion/User/_rlogin	Wed Oct 13 16:07:07 1999
@@ -21,7 +21,7 @@
     ;;
   rsh|remsh)
     local state line ret=1
-    typeset -A options
+    typeset -A opt_args
 
     _arguments -s \
       '-n[ignore stdin]' \
@@ -39,7 +39,7 @@
     ;;
   rcp)
     local state line ret=1
-    typeset -A options
+    typeset -A opt_args
 
     _arguments -s \
       '-p[preserve modification times]' \
@@ -71,7 +71,7 @@
     _combination accounts_users_hosts "users=${IPREFIX/@}" hosts "$@"
   else
     _combination accounts_users_hosts \
-      ${options[-l]:+"users=${options[-l]:q}"} hosts "$@"
+      ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@"
   fi
 }
 
diff -u -r oldcompletion/User/_socket Completion/User/_socket
--- oldcompletion/User/_socket	Wed Oct 13 14:25:30 1999
+++ Completion/User/_socket	Wed Oct 13 16:07:36 1999
@@ -6,7 +6,7 @@
 #    The array that contains paris `host:port'.
 
 local state line expl
-typeset -A options
+typeset -A opt_args
 
 if [[ $CURRENT -eq 2 && (
   -z "$compconfig[option_prefix]" ||
@@ -41,7 +41,7 @@
   ;;
 
 arg1)
-  if (( $+options[-s] )); then
+  if (( $+opt_args[-s] )); then
     _description expl 'port to listen'
     _ports "$expl[@]"
   else
@@ -51,7 +51,7 @@
   ;;
 
 arg2)
-  if (( ! $+options[-s] )); then
+  if (( ! $+opt_args[-s] )); then
     _description expl 'port to connect'
     _combination socket_hosts_ports hosts="${line[2]:q}" ports "$expl[@]"
   fi
diff -u -r oldcompletion/User/_ssh Completion/User/_ssh
--- oldcompletion/User/_ssh	Wed Oct 13 14:25:31 1999
+++ Completion/User/_ssh	Wed Oct 13 16:08:03 1999
@@ -2,7 +2,7 @@
 
 _ssh () {
   local state lstate line ret=1 expl args
-  typeset -A options
+  typeset -A opt_args
 
   local accounts_users_hosts
 
@@ -143,7 +143,7 @@
         else
           _description expl 'remote host name'
           _ssh_hosts "$expl[@]" && ret=0
-          if (( ! $+options[-l] )); then
+          if (( ! $+opt_args[-l] )); then
             _description expl 'login name'
             _ssh_users "$expl[@]" -S@ -q && ret=0
           fi
@@ -230,7 +230,7 @@
     _combination accounts_users_hosts "users=${IPREFIX/@}" hosts "$@"
   else
     _combination accounts_users_hosts \
-      ${options[-l]:+"users=${options[-l]:q}"} hosts "$@"
+      ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@"
   fi
 }
 
diff -u -r oldcompletion/User/_telnet Completion/User/_telnet
--- oldcompletion/User/_telnet	Wed Oct 13 14:25:31 1999
+++ Completion/User/_telnet	Wed Oct 13 16:08:29 1999
@@ -6,7 +6,7 @@
 #    The array that contains 3-tuples `host:port:user'.
 
 local state line expl
-typeset -A options
+typeset -A opt_args
 
 if (( ! $+_telnet_short )); then
   local k help="$(telnet -\? < /dev/null 2>&1)"
@@ -69,14 +69,14 @@
 hosts)
   _description expl 'host'
   _combination telnet_hosts_ports_users \
-    ${options[-l]:+users=${options[-l]:q}} \
+    ${opt_args[-l]:+users=${opt_args[-l]:q}} \
     hosts "$expl[@]"
   ;;
 
 ports)
   _description expl 'port'
   _combination telnet_hosts_ports_users \
-    ${options[-l]:+users=${options[-l]:q}} \
+    ${opt_args[-l]:+users=${opt_args[-l]:q}} \
     hosts="${line[2]:q}" \
     ports "$expl[@]"
   ;;
diff -u -r oldcompletion/User/_urls Completion/User/_urls
--- oldcompletion/User/_urls	Wed Oct 13 14:25:31 1999
+++ Completion/User/_urls	Wed Oct 13 15:29:52 1999
@@ -37,7 +37,7 @@
 #    name used by a user placing web pages within their home area.
 #    e.g. compconf urls_localhttp=www:/usr/local/apache/htdocs:public_html
 
-local ipre scheme host user dirs files ret=1
+local ipre scheme host user dirs files ret=1 expl
 
 if [[ "$1" = -f ]]; then
   shift
@@ -54,9 +54,10 @@
   scheme="${PREFIX%%:*}"
   compset -P "[-+.a-z0-9]#:"
 else
-  [ -d $compconfig[urls_path]/bookmark ] &&
-      compadd "$@" -S '' bookmark: && ret=0
-  compadd "$@" -S '' file: ftp:// gopher:// http:// && ret=0
+  _description expl 'URL prefix'
+  [[ -d $compconfig[urls_path]/bookmark ]] &&
+      compadd "$@" "$expl[@]" -S '' bookmark: && ret=0
+  compadd "$@" "$expl[@]" -S '' file: ftp:// gopher:// http:// && ret=0
   return $ret
 fi
 
diff -u -r oldcompletion/User/_wget Completion/User/_wget
--- oldcompletion/User/_wget	Wed Oct 13 14:25:32 1999
+++ Completion/User/_wget	Wed Oct 13 16:09:03 1999
@@ -1,7 +1,7 @@
 #compdef wget
 
 local state line
-typeset -A options
+typeset -A opt_args
 
 local tmp1 tmp2
 
diff -u -r oldcompletion/User/_yp Completion/User/_yp
--- oldcompletion/User/_yp	Wed Oct 13 14:25:32 1999
+++ Completion/User/_yp	Wed Oct 13 16:09:18 1999
@@ -1,7 +1,7 @@
 #compdef ypcat ypmatch yppasswd ypwhich ypset ypserv ypbind yppush yppoll ypxfr domainname
 
 local line state ret=1
-typeset -A options
+typeset -A opt_args
 
 if (( ! $+_yp_cache_maps )); then
   _yp_cache_maps=( "${(@)${(@f)$(ypwhich -m)}%% *}" )
@@ -93,7 +93,7 @@
 
   compadd "$expl[@]" -M 'l:.|by=by l:.|=by r:|.=* r:|=*' - \
           "$_yp_cache_maps[@]" && ret=0
-  if [[ $+options[-t] -eq 0 && "$state" != maponly ]]; then
+  if [[ $+opt_args[-t] -eq 0 && "$state" != maponly ]]; then
     _description expl 'nicknames'
     compadd "$expl[@]" - "$_yp_cache_nicks[@]" && ret=0
   fi
diff -u -r oldcompletion/X/_xmodmap Completion/X/_xmodmap
--- oldcompletion/X/_xmodmap	Wed Oct 13 11:47:56 1999
+++ Completion/X/_xmodmap	Wed Oct 13 16:09:32 1999
@@ -3,7 +3,7 @@
 setopt localoptions extendedglob
 
 local state line ret=1
-typeset -A options
+typeset -A opt_args
 
 _x_arguments \
   -{help,grammar,verbose,quiet} \


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


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

* Re: PATCH: _urls, _netscape, a seg fault and new completion thoughts
  1999-10-13 14:17 PATCH: _urls, _netscape, a seg fault and new completion thoughts Sven Wischnowsky
@ 1999-10-13 15:34 ` Oliver Kiddle
  1999-10-13 16:09   ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Oliver Kiddle @ 1999-10-13 15:34 UTC (permalink / raw)
  To: Zsh workers

Sven Wischnowsky wrote:
> 
> Partly this was caused by `_netscape' not declaring enough local
> parameters (`line' and `options' were missing). Or more precisely

I hadn't realised the significance of the part about line and options in
the documentation. It should possibly be made very clear in the
_arguments documentation that you need to declare line and opt_args
local.

> > Is there a good reason why I don't get a list of matches when
> > completing inside quotes? This is the general case not anything to do
> > with completing urls etc. e.g. cd 'm<tab> will complete to 'man/ but
> > if I added another directory beginning with m, nothing would happen - no
> > list. 
> Hm, this works for me -- unless you mean `cd man m<TAB>' which of
> course shouldn't work.

I did mean as I said. It still doesn't work (3.1.6-pws-6 on AIX or 3.1.6
on Linux). I tried it also with zsh -f;autoload -U compinit;compinit so
it isn't my setup files preventing it from working. Double quotes have
the same problem as single. Am I possibly missing a required option or
configuration key (or patch since pws-6)? Does anyone else have the same
problem?

One other thought I have relating to the new completion system stems
from the following line which I still have in my .zshrc:

compctl -M 'm:{a-z}={A-Z}'

It might be better if a configuration key was added to give a default
matching control.

The only other compctl line I have left in .zshrc is:
compctl -k '( )' true false
So to completely cleanse my setup of the old completion system I'd also
have to create a function which explicitly completes nothing.

Anyway, thanks Sven for those fixes

Oliver Kiddle


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

* Re: PATCH: _urls, _netscape, a seg fault and new completion thoughts
  1999-10-13 15:34 ` Oliver Kiddle
@ 1999-10-13 16:09   ` Bart Schaefer
  1999-10-13 16:37     ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 1999-10-13 16:09 UTC (permalink / raw)
  To: Zsh workers

On Oct 13,  4:34pm, Oliver Kiddle wrote:
} Subject: Re: PATCH: _urls, _netscape, a seg fault and new completion thoug
}
} > > Is there a good reason why I don't get a list of matches when
} > > completing inside quotes? This is the general case not anything to do
} > > with completing urls etc. e.g. cd 'm<tab> will complete to 'man/ but
} > > if I added another directory beginning with m, nothing would happen - no
} > > list. 
} > Hm, this works for me -- unless you mean `cd man m<TAB>' which of
} > course shouldn't work.
} 
} I did mean as I said. It still doesn't work (3.1.6-pws-6 on AIX or 3.1.6
} on Linux).

Doesn't work for me either; not even the first bit that works for Oliver.
I get a listing if I ask for one with ^D, but not with TAB, and automenu
does not work if there's a quote on the line.  See:

zagzig[21] compinit
zagzig[22] cd l<TAB>      
lg/            lib/           linux@         linux-2.0.36/  local@
zagzig[23] cd 'l<TAB>
(nothing)

(I get those five completions because /usr/src is in $cdpath.)  Here's a
test that doesn't need cdpath:

zagzig[24] cd z<TAB>
z-code/   zanshin/  zscript/  zshfun/
zagzig[24] cd 'z<TAB>
(nothing)

Doesn't matter if the command is ls, cd, bindkey ... unambiguous prefixes
get inserted, but as soon as there's an ambiguity it all stops.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: PATCH: _urls, _netscape, a seg fault and new completion thoughts
  1999-10-13 16:09   ` Bart Schaefer
@ 1999-10-13 16:37     ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 1999-10-13 16:37 UTC (permalink / raw)
  To: Zsh workers

On Oct 13,  4:09pm, Bart Schaefer wrote:
} Subject: Re: PATCH: _urls, _netscape, a seg fault and new completion thoug
}
} On Oct 13,  4:34pm, Oliver Kiddle wrote:
} } Subject: Re: PATCH: _urls, _netscape, a seg fault and new completion thoug
} }
} } > > Is there a good reason why I don't get a list of matches when
} } > > completing inside quotes?
} } > Hm, this works for me -- unless you mean `cd man m<TAB>' which of
} } > course shouldn't work.
} } 
} } I did mean as I said. It still doesn't work (3.1.6-pws-6 on AIX or 3.1.6
} } on Linux).
} 
} Doesn't work for me either; not even the first bit that works for Oliver.
} 
} Doesn't matter if the command is ls, cd, bindkey ... unambiguous prefixes
} get inserted, but as soon as there's an ambiguity it all stops.

Incidentally, it doesn't work with old-style completion either, so it's
not a problem with the shell functions or compstate.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: PATCH: _urls, _netscape, a seg fault and new completion thoughts
@ 1999-10-14  6:43 Sven Wischnowsky
  0 siblings, 0 replies; 7+ messages in thread
From: Sven Wischnowsky @ 1999-10-14  6:43 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> Doesn't work for me either; not even the first bit that works for Oliver.
> I get a listing if I ask for one with ^D, but not with TAB, and automenu
> does not work if there's a quote on the line.  See:
> 
> ...
> 
> Doesn't matter if the command is ls, cd, bindkey ... unambiguous prefixes
> get inserted, but as soon as there's an ambiguity it all stops.

Ah, I didn't understand Oliver, sorry.

The problem was that in d_ambiguous() we test if the line changed or
not to decide if LIST_AMBIGUOUS should be used. But with a quote on the
original line, that quote was intermediately removed, but cline_str()
inserted the final string, so the comparison failed and it thought it
should use LIST_AMBIGUOUS (i.e. don't do anything further in that part 
of the code).

Bye
 Sven

diff -u oldsrc/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- oldsrc/Zle/zle_tricky.c	Wed Oct 13 16:17:37 1999
+++ Src/Zle/zle_tricky.c	Thu Oct 14 08:37:51 1999
@@ -66,7 +66,7 @@
 /* The line before completion was tried. */
 
 static char *origline;
-static int origcs;
+static int origcs, origll;
 
 /* wb and we hold the beginning/end position of the word we are completing. */
 
@@ -936,6 +936,7 @@
     ocs = cs;
     origline = dupstring((char *) line);
     origcs = cs;
+    origll = ll;
     if (!isfirstln && chline != NULL) {
 	/* If we are completing in a multi-line buffer (which was not  *
 	 * taken from the history), we have to prepend the stuff saved *
@@ -8272,15 +8273,11 @@
 	 * completion options.                                             */
 	do_ambig_menu();
     } else if (ainfo) {
-	int atend = (cs == we), oll = ll, la, eq, tcs;
-	VARARR(char, oline, ll);
+	int atend = (cs == we), la, eq, tcs;
 
 	minfo.cur = NULL;
 	minfo.asked = 0;
 
-	/* Copy the line buffer to be able to easily test if it changed. */
-	memcpy(oline, line, ll);
-
 	fixsuffix();
 
 	/* First remove the old string from the line. */
@@ -8299,7 +8296,7 @@
 	/* la is non-zero if listambiguous may be used. Copying and
 	 * comparing the line looks like BFI but it is the easiest
 	 * solution. Really. */
-	la = (ll != oll || strncmp(oline, (char *) line, ll));
+	la = (ll != origll || strncmp(origline, (char *) line, ll));
 
 	/* If REC_EXACT and AUTO_MENU are set and what we inserted is an  *
 	 * exact match, we want menu completion the next time round       *

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


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

* Re: PATCH: _urls, _netscape, a seg fault and new completion thoughts
@ 1999-10-13 14:22 Sven Wischnowsky
  0 siblings, 0 replies; 7+ messages in thread
From: Sven Wischnowsky @ 1999-10-13 14:22 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> Then I changed the names of the arrays used by `_arguments' and
> `_values' to `opt_args' and `val_args' so that they at least don't
> collide with the parameters in the parameter module.

I forgot to save one file before making the patch...


I also forgot to say that this remove-compgen stuff isn't new. I think 
Bart was the first one who suggested doing everything with compadd
(which didn't even exist at that time) plus ways to generate all the
stuff we might want to complete.

Bye
 Sven

diff -u oldcompletion/User/_tiff Completion/User/_tiff
--- oldcompletion/User/_tiff	Wed Oct 13 16:18:25 1999
+++ Completion/User/_tiff	Wed Oct 13 16:19:40 1999
@@ -20,7 +20,7 @@
 local _in_tiff=yes
 
 local state line ret=1
-typeset -A options
+typeset -A opt_args
 
 case "$words[1]" in
 tiff2bw)

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


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

* PATCH: _urls, _netscape, a seg fault and new completion thoughts
@ 1999-10-13 12:11 Oliver Kiddle
  0 siblings, 0 replies; 7+ messages in thread
From: Oliver Kiddle @ 1999-10-13 12:11 UTC (permalink / raw)
  To: Zsh workers

Attached is a completion for Netscape and a modified completion for
urls. The netscape completion handles the normal options, remote
commands and some Netscape specific urls. The main change to _urls is
support for a new configuration option which allows intelligent
completing for a local web server. I've also fixed the problem I
introduced with completing file urls from the root directory. A small
(untested with yodl) doc patch is also included.

I had a bit of difficulty in getting the remote command completion to
work properly with different types of quoting and there is probably
plenty of scope for that to be further improved. I'm not sure how many
of the problems with the quoting are my fault though: zsh will seg
fault if I do:
netscape -remote 'openURL(<tab>

Is there a good reason why I don't get a list of matches when
completing inside quotes? This is the general case not anything to do
with completing urls etc. e.g. cd 'm<tab> will complete to 'man/ but
if I added another directory beginning with m, nothing would happen - no
list.

While writing this completion, I came across a number of circumstances
where I wanted to pass certain compadd style options (e.g. -r, -s, -M)
to _urls or _files but couldn't because they were not handled in some
circumstances. As a way of making the new completions simpler, I think
we should try to make all the completion commands standardise much more
on their options so things such as -P -s -S -r can be used throughout
with a common meaning and can be safely passed from one completion
function to another.

I think it would make things easier if compgen in particular took more
of compadd's options. The problem is that most of the option letters
are already used because compgen takes all the standard compctl
options. Maybe we should strip compgen of many of the options
which nolonger are of much use because they are implemented by new
functions (e.g. -f -/ -g -u). I would even say we should consider
ditching compgen altogether: it would fit in much better with the rest
of the system where different functions complete different types of
things if for example jobs were completed with compjob instead of the
not very readable compgen -j, -z and -r. Alternatively, the option
letters could be freed by moving compgen syntax away from the compctl
style and use more full words to describe what it is completing -
compgen suspended-jobs would be much easier to read.

Oliver Kiddle


*** Completion/User/_urls.bak2	Fri Oct  8 10:40:46 1999
--- Completion/User/_urls	Wed Oct 13 12:31:56 1999
***************
*** 4,10 ****
  # Options:
  #  -f : complete files.
  #
! # Configuration key used:
  #
  #  urls_path
  #    The path to a directory containing a URL database, such as:
--- 4,10 ----
  # Options:
  #  -f : complete files.
  #
! # Configuration keys used:
  #
  #  urls_path
  #    The path to a directory containing a URL database, such as:
***************
*** 28,35 ****
  #      http://sunsite.auc.dk/zsh/
  #      % cat bookmark/zsh/meta
  #      http://www.zsh.org/
  
! local ipre scheme dirs files
  
  if [[ "$1" = -f ]]; then
    shift
--- 28,43 ----
  #      http://sunsite.auc.dk/zsh/
  #      % cat bookmark/zsh/meta
  #      http://www.zsh.org/
+ #
+ #  urls_localhttp
+ #    Specify a local web server in the form:
+ #      hostname:doc root:user area
+ #    where hostname is the name of the web server, doc root is the path to
+ #    the default web pages for the server and user area is the directory
+ #    name used by a user placing web pages within their home area.
+ #    e.g. compconf urls_localhttp=www:/usr/local/apache/htdocs:public_html
  
! local ipre scheme host user dirs files ret=1
  
  if [[ "$1" = -f ]]; then
    shift
***************
*** 46,82 ****
    scheme="${PREFIX%%:*}"
    compset -P "[-+.a-z0-9]#:"
  else
!   compadd "$@" -S '' http:// ftp:// bookmark: file:
!   return
  fi
  
  case "$scheme" in
!   http|ftp) compset -P // || { compadd "$@" -S '' //; return };;
    file)
!     if [[ -prefix // ]]; then
!       compset -P //
!     elif [ -prefix / ]; then
!       _files "$@"
!       return
!     elif [ ! "$PREFIX" ]; then
!       compadd -S '/' ~+
!       return
      fi
    ;;
  esac
  
! if [[ "$scheme" = bookmark &&
!       -f "$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX" &&
!       -s "$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX" ]]; then
!   compadd "$@" -QU -- "$ipre$(<"$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX")"
! else
!   dirs=($compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(/:t))
!   files=($compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(.:t))
!   compset -P '*/'
!   compadd "$@" -Q -S '/' - $dirs
!   if [[ "$scheme" = bookmark ]]; then
!     compadd "$@" -QS '' - $files
    else
!     compadd "$@" -Q - $files
    fi
  fi
--- 54,120 ----
    scheme="${PREFIX%%:*}"
    compset -P "[-+.a-z0-9]#:"
  else
!   [ -d $compconfig[urls_path]/bookmark ] &&
!       compadd "$@" -S '' bookmark: && ret=0
!   compadd "$@" -S '' file: ftp:// gopher:// http:// && ret=0
!   return $ret
  fi
  
  case "$scheme" in
!   http|ftp|gopher) compset -P // || { compadd "$@" -S '' //; return };;
    file)
!     if ! compset -P //; then
!       if [ -prefix / ]; then
! 	_files "$@"
! 	return
!       elif [ ! "$PREFIX" ]; then
! 	compadd -S '/' - "${PWD%/}"
! 	return
!       fi
      fi
    ;;
+   bookmark)
+     if [[ -f "$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX" &&
+         -s "$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX" ]]; then
+       compadd "$@" -QU -- \
+           "$ipre$(<"$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX")"
+     else
+       compadd "$@" -Q -S '/' - \
+           $compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(/:t) && ret=0
+       compadd "$@" -QS '' - \
+           $compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(.:t) || return $ret
+     fi
+     return 
+   ;;
  esac
  
! if [[ -prefix */* ]]; then
! 
!   # Complete part after hostname
!   host=${PREFIX%%/*}
!   compset -P "$host/"
!   if [[ "$compconfig[urls_localhttp]" = ${host}:* ]]; then
!     if [[ -prefix \~ ]]; then
!       compset -P \~
!       if [[ -prefix */* ]]; then
!         user=${PREFIX%%/*}
! 	compset -P $user/
! 	_path_files -W ~$user/${${(s.:.)compconfig[urls_localhttp]}[3]}/
!       else
!         _users -S/
!       fi
!     else
!       _path_files -W ${${(s.:.)compconfig[urls_localhttp]}[2]}
!     fi
    else
!     _path_files -W $compconfig[urls_path]/$scheme/$host/
    fi
+ else
+ 
+   # Complete hosts
+   dirs=($compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(/:t))
+   (( $#dirs )) || _hosts -S/ && ret=0
+   [ "$scheme" = "http" ] && 
+       dirs=($dirs ${${(s.:.)compconfig[urls_localhttp]}[1]})
+   compadd "$@" -Q -S '/' - $dirs || return $ret
  fi
*** Completion/User/_webbrowser.bak	Fri Oct  8 14:58:01 1999
--- Completion/User/_webbrowser	Fri Oct  8 14:59:07 1999
***************
*** 1,3 ****
! #compdef amaya arena chimera express grail gzilla hotjava mmm mozilla netscape w3m www xmosaic Mosaic
  
  _urls -f
--- 1,3 ----
! #compdef amaya arena chimera express grail gzilla hotjava mmm mozilla w3m www xmosaic Mosaic
  
  _urls -f
*** /dev/null	Wed Oct 13 04:01:01 1999
--- Completion/User/_netscape	Wed Oct 13 12:28:49 1999
***************
*** 0 ****
--- 1,75 ----
+ #compdef netscape
+ 
+ local state
+ 
+ _x_arguments \
+   '-xrm:resource:_x_resource' \
+   '-help[show usage message]' \
+   '-version[show the version number and build date]' \
+   '-visual[use a specific server visual]:id-or-number:' \
+   '-install[install a private colormap]' \
+   '-no-install[use the default colormap]' \
+   '-ncols[max no. of colors to allocate for images]:n:' \
+   '-mono[force 1-bit-deep image display]' \
+   '-iconic[start up iconified]' \
+   '-remote[execute a command in an existing Netscape]:remote command:->remote' \
+   '-id[id of X window to send remote commands to]:window-id:' \
+   '-raise[raise window following remote command]' \
+   "-noraise[don't raise window following remote command]" \
+   '-nethelp[show nethelp]' \
+   -{dont-force-window-stacking,no-about-splash} \
+   -{,no-}{,irix-}session-management \
+   -{done-save,ignore}-geometry-prefs \
+   -{component-bar,composer,edit,messenger,mail,discussions,news} \
+   '*:location:->urls'
+ 
+ [ "$state" = "urls" ] && _files "$@" && return
+ 
+ # Handle netscape remote commands
+ if [ "$state" = "remote" ]; then  
+   local -a remote_commands
+   remote_commands=(openURL openFile saveAs mailto addBookmark)
+ 
+   [[ $compstate[quoting] = (double|single) ]] && compset -q
+   compset -P '*\('
+   case $IPREFIX in
+     openURL*|addBookmark* ) state=urls;;
+     openFile* ) _files -W ~;;
+     saveAs* ) 
+       if compset -P "*,"; then
+         compadd -s")" -M 'm:{a-zA-Z}={A-Za-z}' HTML Text PostScript
+       else
+         _path_files -W ~
+       fi
+     ;;
+     mailto* )
+       compset -P "*,"
+       if compset -P '*@'; then
+         _description expl 'remote host name'
+         _hosts "$expl[@]" -q -S,
+       else
+         _description expl 'login name'
+         _users "$expl[@]" -q -S@
+       fi
+     ;;
+     * )
+       if [ "$QIPREFIX" ]; then
+         compadd -q -S '(' -M 'm:{a-zA-Z}={A-Za-z}' $remote_commands
+       else
+ 	compadd -s'(' -S '' -M 'm:{a-zA-Z}={A-Za-z}' $remote_commands
+       fi
+     ;;
+   esac
+ fi
+ 
+ if [ "$state" = "urls" ]; then
+   # Complete netscape urls
+   if [[ -prefix about: ]]; then
+     compset -P about:
+     compadd authors blank cache document fonts global hype image-cache \
+         license logo memory-cache mozilla plugins
+   else
+     compadd -S '' about: mocha: javascript:
+     _urls "$@"
+   fi
+ fi
*** Doc/Zsh/compsys.yo.bak	Wed Oct 13 12:11:01 1999
--- Doc/Zsh/compsys.yo	Wed Oct 13 12:23:36 1999
***************
*** 1582,1587 ****
--- 1582,1596 ----
  output of tt(ps) called with the value of this key as its argument
  when showing completion lists.
  )
+ item(tt(urls_localhttp))(
+ This key is used by completion functions which generate URLs as
+ possible matches to add suitable matches when a URL points to a
+ local web server. Its value should be of the form
+ `tt(hostname:doc root:user area)' where hostname is the name of the web
+ server, doc root is the path to the default web pages for the server
+ and user area is the directory name used by a user placing web pages
+ within their home area
+ )
  item(tt(urls_path))(
  This key is used by completion functions that generate URLs as
  possible matches. It should be set to the path of a directory


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

end of thread, other threads:[~1999-10-14  6:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-13 14:17 PATCH: _urls, _netscape, a seg fault and new completion thoughts Sven Wischnowsky
1999-10-13 15:34 ` Oliver Kiddle
1999-10-13 16:09   ` Bart Schaefer
1999-10-13 16:37     ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
1999-10-14  6:43 Sven Wischnowsky
1999-10-13 14:22 Sven Wischnowsky
1999-10-13 12:11 Oliver Kiddle

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).