zsh-users
 help / color / mirror / code / Atom feed
* trying to learn zstyle
@ 1999-12-22  0:49 Shao Zhang
  1999-12-22 23:08 ` Peter Stephenson
  1999-12-22 23:13 ` Peter Stephenson
  0 siblings, 2 replies; 5+ messages in thread
From: Shao Zhang @ 1999-12-22  0:49 UTC (permalink / raw)
  To: ZSH Mail List

Hi,
	I am trying to learn zstyle to do command completion, but I am
	very very confused how everything works after reading the doc
	and trying out.

	I have the following lines in my .zshrc:

	zstyle ':completion:*:hello:*:hosts' hosts $HOSTS
	zstyle ':completion:*:mtvp:*:hosts' hosts $HOSTS
	zstyle ':completion:*:telnet:*:hosts' hosts $HOSTS

	But all of them behaves differently.

	hello [TAB] gives me a completion of list of files in my current
	dir.

	mtvp [TAB] give me a completion of -display    -geometry

	telnet behaves the way I want, which gives me a list of hosts
	defined in $HOSTS.

	What I am doing wrong?

	How do I use zstyle to make mtvp to complete to the files with
	*.mpg or *.mpeg or *.MPG and so on.

	Thanks for the help very much.

Shao.

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


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

* Re: trying to learn zstyle
  1999-12-22  0:49 trying to learn zstyle Shao Zhang
@ 1999-12-22 23:08 ` Peter Stephenson
  1999-12-22 23:13 ` Peter Stephenson
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1999-12-22 23:08 UTC (permalink / raw)
  To: ZSH Mail List

As a preface:  the stuff discussed below is new since 3.1.6.  I should
perhaps explain to zsh-users readers not on zsh-workers that the latest
development version of the shell is now available on the archive and
mirrors in the `development' subdirectory.

Shao Zhang wrote:
> Hi,
> 	I am trying to learn zstyle to do command completion, but I am
> 	very very confused how everything works after reading the doc
> 	and trying out.

It's quite complicated.  I'm working on the chapter of my zsh guide which
deals with completion to try to help.

> 	I have the following lines in my .zshrc:
> 
> 	zstyle ':completion:*:hello:*:hosts' hosts $HOSTS
> 	zstyle ':completion:*:mtvp:*:hosts' hosts $HOSTS
> 	zstyle ':completion:*:telnet:*:hosts' hosts $HOSTS
> 
> 	But all of them behaves differently.
> 
> 	hello [TAB] gives me a completion of list of files in my current
> 	dir.
>
> 	mtvp [TAB] give me a completion of -display    -geometry

(It's not part of your question, but if you want to use the same list of
hosts in all contexts, you can set
  zstyle '*' hosts $HOSTS
which simplifies things a bit.)

The style `hosts' just gives values for cases where hosts are completed ---
it doesn't say where hosts are to be completed.  You can think of styles
just as a sort of shell parameter, but (as you realised) with the ability
to have different values in different contexts.  You need to tell the
system that the command `hello' has to take hosts as arguments.  The
easiest way to do it is this (after loading completion, of course):

  compdef _hosts hello mtvp

> 	telnet behaves the way I want, which gives me a list of hosts
> 	defined in $HOSTS.

That's because it's already set up to use hosts.  You can check this by
doing
  print ${_comps[telnet]}
which gives `_telnet' (surprised?).  If you look in the function _telnet,
the hosts handling is buried inside the `combination '' hosts-ports-users'
call.

We ought to add things like the handling function to the output of ^Xh
(that's what tells you the context you're completing in).  It helps in this
case a bit, because if you did it with `hello' you'd have got:

tags in context `:complete::hello:': 
    files
    all-files

which would have told you that the only valid tags were files and
all-files, but not hosts.

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>


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

* Re: trying to learn zstyle
  1999-12-22  0:49 trying to learn zstyle Shao Zhang
  1999-12-22 23:08 ` Peter Stephenson
@ 1999-12-22 23:13 ` Peter Stephenson
  1999-12-23  1:28   ` Shao Zhang
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 1999-12-22 23:13 UTC (permalink / raw)
  To: ZSH Mail List

Shao Zhang wrote:
> 	How do I use zstyle to make mtvp to complete to the files with
> 	*.mpg or *.mpeg or *.MPG and so on.

Sorry, missed this bit.  The easy answer (again, this is post-3.1.6) is


_mtvp() { 
  local expl

  _description files expl 'MPEG file'
  _files "$expl[@]" -g '*.(mpg|mpeg|MPG)'
}
compdef _mtvp mtvp


I got that simply by copying the file _gunzip, which does the same thing
with .gz files.  Copying existing files is usually the way.

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>


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

* Re: trying to learn zstyle
  1999-12-22 23:13 ` Peter Stephenson
@ 1999-12-23  1:28   ` Shao Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Shao Zhang @ 1999-12-23  1:28 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: ZSH Mail List

Hi Peter,
	Thanks for your wonderfull explanation!

	While you have fixed all my problems, I still have to say, the
	zsh command completion is way too complex for a general user to
	program it, or compare to compctl.

	But I guess that is a trade off between powerfull and easy to
	use.

	I would love to see that in the zsh documentations, there will
	be more examples to teach users how to program the command
	completion. It would be easier for users to get started, and
	they can try to understand the entire completion system later. 

	At the moment, there is only one short example about 'kill' in
	the documentation, and I found it is quite hard for me to derive
	from it.

	Thanks for you help again. And thanks for creating this
	wonderfull shell. I am now completely switched from bash to zsh.

Cheers,

Shao.


Peter Stephenson [pws@pwstephenson.fsnet.co.uk] wrote:
> Shao Zhang wrote:
> > 	How do I use zstyle to make mtvp to complete to the files with
> > 	*.mpg or *.mpeg or *.MPG and so on.
> 
> Sorry, missed this bit.  The easy answer (again, this is post-3.1.6) is
> 
> 
> _mtvp() { 
>   local expl
> 
>   _description files expl 'MPEG file'
>   _files "$expl[@]" -g '*.(mpg|mpeg|MPG)'
> }
> compdef _mtvp mtvp
> 
> 
> I got that simply by copying the file _gunzip, which does the same thing
> with .gz files.  Copying existing files is usually the way.
> 
> -- 
> Peter Stephenson <pws@pwstephenson.fsnet.co.uk>

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


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

* Re: trying to learn zstyle
@ 2000-01-04  8:17 Sven Wischnowsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 2000-01-04  8:17 UTC (permalink / raw)
  To: zsh-users


Peter Stephenson wrote:

> ...
> 
> Shao Zhang wrote:
> > Hi,
> > 	I am trying to learn zstyle to do command completion, but I am
> > 	very very confused how everything works after reading the doc
> > 	and trying out.
> 
> It's quite complicated.  I'm working on the chapter of my zsh guide which
> deals with completion to try to help.

Sigh. I hope that all this is mainly a problem of me not being able to
describe things in an understandable way in the docs. And maybe we
should also try to make the manual clearer -- but I fear I'm too deep
into all this code again to know what exactly would be helpful...

> ...
> 
> We ought to add things like the handling function to the output of ^Xh
> (that's what tells you the context you're completing in).  It helps in this
> case a bit, because if you did it with `hello' you'd have got:
> 
> tags in context `:complete::hello:': 
>     files
>     all-files
> 
> which would have told you that the only valid tags were files and
> all-files, but not hosts.

The directly-calling-function isn't always helpful (it may be
_arguments or _describe), so the patch below shows what is hopefully
the most interesting part of the function call stack. The problem is
that this may make the display look ugly because it may result in
lines longer than screen width. And making it list the functions one
per line may quickly result in lists longer than screen height. Hm.
Any suggestions for a better layout?

Bye
 Sven

diff -u -r oldcompletion/Commands/_complete_help Completion/Commands/_complete_help
--- oldcompletion/Commands/_complete_help	Fri Dec 17 21:39:20 1999
+++ Completion/Commands/_complete_help	Mon Jan  3 22:09:02 2000
@@ -1,11 +1,8 @@
 #compdef -k complete-word \C-xh
 
 _complete_help() {
-  local _sort_tags=_help_sort_tags text i
-  typeset -A help_tags
-  typeset -U help_contexts
-
-  help_contexts=()
+  local _sort_tags=_help_sort_tags text i j
+  typeset -A help_funcs help_tags
 
   compadd() { return 1 }
 
@@ -13,9 +10,12 @@
 
   unfunction compadd
 
-  for i in "$help_contexts[@]"; do
+  for i in "${(@k)help_funcs}"; do
     text="${text}
-tags in context \`${i}': ${help_tags[$i]}"
+tags in context ${i}"
+    for j in "${(@s.:.)help_funcs[$i][2,-1]}"; do
+      text="${text}${help_tags[${i}${j}]}	(${j})"
+    done
   done
 
   compstate[list]='list force'
@@ -25,10 +25,13 @@
 }
 
 _help_sort_tags() {
-  help_contexts=( "$help_contexts[@]" "$curcontext" )
-  help_tags[$curcontext]="${help_tags[$curcontext]}
-    ${argv}"
-  comptry "$@"
+  local f="${${${funcstack[3,(i)_(main_complete|complete|approximate|normal)]}% *}#_(wanted|requested) }"
+  if [[ "$help_funcs[$curcontext]" != *${f}* ]]; then
+    help_funcs[$curcontext]="${help_funcs[$curcontext]}:${f}"
+    help_tags[${curcontext}${f}]="${help_tags[$curcontext]}
+      ${argv}"
+    comptry "$@"
+  fi
 }
 
 _complete_help "$@"

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


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

end of thread, other threads:[~2000-01-04  8:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-22  0:49 trying to learn zstyle Shao Zhang
1999-12-22 23:08 ` Peter Stephenson
1999-12-22 23:13 ` Peter Stephenson
1999-12-23  1:28   ` Shao Zhang
2000-01-04  8:17 Sven Wischnowsky

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