zsh-users
 help / color / mirror / code / Atom feed
* zstyle problems
@ 2002-10-01 11:34 Jonas Juselius
  2002-10-01 11:43 ` Jonas Juselius
  2002-10-02  3:15 ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Jonas Juselius @ 2002-10-01 11:34 UTC (permalink / raw)
  To: zsh-users

Hello,

first off, I'm pretty much a newbie to zsh. I have been using it for a
year or so, and I'm pretty familiar with the basic stuff. Now, I decided
that I wanted to try squeeze the rest of the juice out of zsh, since I'm
spending roughly 8-10 hours with the thing :)
One thing that I want to do is set up completion so that it works
_precisely_ how _I_ want it to work. So, I read up on using zstyle and
writing completion widgets. Then I tried to do the following (this is
not what I really want, it's just a simple test): I wanted different
completion for 'cd' and the rest of the commands. I put the following
lines in my .zshrc: 

zstyle ':completion:*:*:cd:*' completer _complete 
zstyle ':completion:*' completer _complete _correct _approximate

But to my big surprise, I still get exactly the same completion (with
corrections) for 'cd' and the other progs. Am I missing something here?
I also tried to change tag-order for the -prefix- completer so that it
would complete named directories before users, but that failed as
well... I am, however, able to make zsh complete on specific file
extensions for some programs I wrote, using the file-patterns style.

Any help appreciated,
                      .jonas.

-- 
"Time shared nodes are not considered to consist of virtual nodes and these
nodes or used by, but not allocated to, jobs." -- PBS Admin Guide

[ PGP public key: http://www.iki.fi/jonas/pubkey.asc ]


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

* Re: zstyle problems
  2002-10-01 11:34 zstyle problems Jonas Juselius
@ 2002-10-01 11:43 ` Jonas Juselius
  2002-10-02  3:15 ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: Jonas Juselius @ 2002-10-01 11:43 UTC (permalink / raw)
  To: zsh-users

Ooops, 

small typo: the -prefix- should be -tilde- obviously... sorry.

.jonas.

On Tue, Oct 01, 2002 at 02:34:53PM +0300, Jonas Juselius wrote:
> corrections) for 'cd' and the other progs. Am I missing something here?
> I also tried to change tag-order for the -prefix- completer so that it
> would complete named directories before users, but that failed as
-- 
The day Microsoft makes something that doesn't suck is probably the day they
start making vacuum cleaners.

[ PGP public key: http://www.iki.fi/jonas/pubkey.asc ]


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

* Re: zstyle problems
  2002-10-01 11:34 zstyle problems Jonas Juselius
  2002-10-01 11:43 ` Jonas Juselius
@ 2002-10-02  3:15 ` Bart Schaefer
  2002-10-02  7:50   ` Jonas Juselius
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2002-10-02  3:15 UTC (permalink / raw)
  To: Jonas Juselius, zsh-users

On Oct 1,  2:34pm, Jonas Juselius wrote:
} Subject: zstyle problems
}
} I wanted different completion for 'cd' and the rest of the commands. I
} put the following lines in my .zshrc:
} 
} zstyle ':completion:*:*:cd:*' completer _complete 
} zstyle ':completion:*' completer _complete _correct _approximate
} 
} But to my big surprise, I still get exactly the same completion (with
} corrections) for 'cd' and the other progs. Am I missing something here?

The individual command context is not yet established at the time the
completer style is looked up; more specifically, the completer style is
always checked with the context ":completion:::::" (except in specialty
widgets like insert-and-predict).  The precise context including the
command name (or contexts like "-tilde-") is actually set up *by* the
completers.

} I also tried to change tag-order for the [-tilde-] completer so that it
} would complete named directories before users, but that failed as
} well...

Hmm.  The following works for me:

    zstyle ':completion::complete:-tilde-:*' tag-order \
	    named-directories users directory-stack

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: zstyle problems
  2002-10-02  3:15 ` Bart Schaefer
@ 2002-10-02  7:50   ` Jonas Juselius
  2002-10-02  8:16     ` Borzenkov Andrey
  2002-10-02  8:33     ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Jonas Juselius @ 2002-10-02  7:50 UTC (permalink / raw)
  To: zsh-users; +Cc: Bart Schaefer

Thanks,

but I still think this is a bit confusing. Typing 'cd' and then
pressing ^Xh says 'tags in context :completion::complete:cd::', which
made me think that this was the actual context... What would be the
correct way of defining different (individual) completions for 'cd' and other 
commands?

On Wed, Oct 02, 2002 at 03:15:16AM +0000, Bart Schaefer wrote:
> The individual command context is not yet established at the time the
> completer style is looked up; more specifically, the completer style is
> always checked with the context ":completion:::::" (except in specialty
> widgets like insert-and-predict).  The precise context including the
> command name (or contexts like "-tilde-") is actually set up *by* the
> completers.
> 

Ok, I tried this but I didn't see any difference from the standard
completion... Could this have something to do with menu completion and
sorting? If so, how can I disable sorting? The problem is that I have
more than 10 named dirs, and more than 100 users, and 98% of the time I
want to complete for my named dirs.

> } I also tried to change tag-order for the [-tilde-] completer so that it
> } would complete named directories before users, but that failed as
> } well...
> 
> Hmm.  The following works for me:
> 
>     zstyle ':completion::complete:-tilde-:*' tag-order \
> 	    named-directories users directory-stack
> 

Best regards, 
               .jonas.


-- 
while (!world->perfect) {
        whine (); 
}

[ PGP public key: http://www.iki.fi/jonas/pubkey.asc ]


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

* RE: zstyle problems
  2002-10-02  7:50   ` Jonas Juselius
@ 2002-10-02  8:16     ` Borzenkov Andrey
  2002-10-02  8:33     ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: Borzenkov Andrey @ 2002-10-02  8:16 UTC (permalink / raw)
  To: 'Jonas Juselius', zsh-users

> but I still think this is a bit confusing. Typing 'cd' and then
> pressing ^Xh says 'tags in context :completion::complete:cd::', which
> made me think that this was the actual context...

That is correct for the time when actual completion for cd is done. 
But completion is a hierarchical process, and it looks up styles at
different steps, so in early stage some information is not yet
available.

When completion starts, it knows only

- it is completion :-)
- actual command line contents
- whether it has been called as default, context sensitive, completion
or explicitly as special completion widget.

So at this stage it can just fill  in the first two fields, notably

:completion:     :
     ^        ^
     |        + default completion (for a widget here is a widget name)

     + completion (as opposed to e.g. styles for zftp function
sybsystem)

The first step it does at this point (after some initialization) is to
decide what completer to use. It is completer that actually generates
matches. Because the above is the only available information, completion
looks up completer(s) using the context :completion:::::, for a
complete-history widget this would be (probably)
:completion:history-complete::::.

Then completer fills in next part of context, then it decides if we are
completing command, parameter etc and fills in next part of context etc.

I too wish it is better described in manuals. At least, those cases when
styles are looked up using non-standard context definitely must be made
clear. Unfortunately, most examples overuse wildcards thus hiding this.

> What would be the
> correct way of defining different (individual) completions for 'cd'
and
> other
> commands?
>

Mostly it is what you have done. For cd context is
:completion::complete:cd:: with optional specific tag names appended.
For completion based on _arguments you may add argument-N or option-N as
last part to modify completion for specific options/arguments. You may
also use :completion:*:... for both default context sensitive completion
and completion widgets.



-andrey


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

* Re: zstyle problems
  2002-10-02  7:50   ` Jonas Juselius
  2002-10-02  8:16     ` Borzenkov Andrey
@ 2002-10-02  8:33     ` Bart Schaefer
  2002-10-02  9:28       ` Jonas Juselius
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2002-10-02  8:33 UTC (permalink / raw)
  To: Jonas Juselius, zsh-users

On Oct 2, 10:50am, Jonas Juselius wrote:
} Subject: Re: zstyle problems
}
} I still think this is a bit confusing. Typing 'cd' and then pressing
} ^Xh says 'tags in context :completion::complete:cd::', which made me
} think that this was the actual context...

It is the context for the tags (hence "tags in context ..."), but not the
context for any old style that has nothing to do with tags.

I agree that it's confusing at first, but this is the way the system is
structured; because it isn't just based on simply completing after a
known command name any more, there has to be a way to bootstrap it.  The
completers are what figure out the full context by examining the command
line in detail (among other things that they do).

} What would be the correct way of defining different (individual)
} completions for 'cd' and other commands?

There's a difference between defining completions (which is done with
compdef and a function) and defining completion behaviors (which is done
with zstyles for completers and tags).  Some completers implement other
special styles (like max-errors for _correct) to adjust their behavior,
but there isn't direct support for changing the entire set of completers
based on the command name, because of the bootstrapping issue.

However, there's an example in the documentation under the _approximate
completer that shows how to change the entire list of completers based on
a condition of your own invention.  (Hmm, I just noticed that example is
missing a "-e" flag in the "zstyle" command.  Doc typo.)  You'd want
something like

    zstyle -e ':completion::*' completer '\
      case $words[1] in
      (cd|chdir) reply=(_complete);;
      (*) reply=(_complete _correct _approximate);;
      esac'

} Ok, I tried this but I didn't see any difference from the standard
} completion...

I presume you mean you tried *this*:

} >     zstyle ':completion::complete:-tilde-:*' tag-order \
} > 	    named-directories users directory-stack

} Could this have something to do with menu completion and sorting?

You want to look at the group-order style, and its partner group-name,
as well as tag-order.  If you haven't already, add to you .zshrc:

    zstyle ':completion:*' group-name ''

and see if that doesn't change something.  Then start experimenting
with group-order.

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: zstyle problems
  2002-10-02  8:33     ` Bart Schaefer
@ 2002-10-02  9:28       ` Jonas Juselius
  0 siblings, 0 replies; 7+ messages in thread
From: Jonas Juselius @ 2002-10-02  9:28 UTC (permalink / raw)
  To: zsh-users

Ok I get it ;)

Thanks for all your help.

.jonas.

-- 
	And what is good, Phaedrus,
	And what is not---
	Need we ask anyone to tell us these things?

[ PGP public key: http://www.iki.fi/jonas/pubkey.asc ]


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

end of thread, other threads:[~2002-10-02  9:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-01 11:34 zstyle problems Jonas Juselius
2002-10-01 11:43 ` Jonas Juselius
2002-10-02  3:15 ` Bart Schaefer
2002-10-02  7:50   ` Jonas Juselius
2002-10-02  8:16     ` Borzenkov Andrey
2002-10-02  8:33     ` Bart Schaefer
2002-10-02  9:28       ` Jonas Juselius

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