zsh-users
 help / color / mirror / code / Atom feed
* compsys issues
@ 2004-10-27 13:26 DervishD
  2004-10-27 14:08 ` Oliver Kiddle
  0 siblings, 1 reply; 6+ messages in thread
From: DervishD @ 2004-10-27 13:26 UTC (permalink / raw)
  To: Zsh Users

    Hi all :)

    As I told a couple of messages ago, I'm playing with the new
completion system but without using the set of functions shipped with
zsh, since I want to learn as goog as I can how it works.

    Obviously, this leads to problems...

    Anyway, I want to ask you a question about compsys. Let's say I
set up this simple widget for learning:

    # expand-or-complete is currently bound to <TAB>
    zle -C expand-or-complete expand-or-complete _completer

    function _completer () {

        compstate[insert]=${compstate[insert]//tab /}

        compadd -f - $PREFIX*(/)

        return 0
    }

    When I write 'cd ' at the prompt and hit tab, I'm presented with
the list of subdirs in the current dir (e.g):

    $ cd <TAB>
    Projects/ Music/ Work/ temporary/

    Let's say I pick 'Projects' and hit tab again. Now I'm presented
with this:

    $ cd Projects/<TAB>

    Projects/mta/ Projects/zsh-things/ Projects/more/

    But what I want is to be presented with:

    $ cd Projects/<TAB>

    mta/ zsh-things/ more/

    that's what I'm presented with the default .expand-or-complete
widget, and that's the behaviour I want.

    I've tried tweaking IPREFIX and PREFIX (with and without the help
from compset), I've tried generating the list of matches before
calling compadd, cleaning the undesired part before, etc. and nothing
works. I've read the info pages for compadd, compset, the special
parameters for completion and I've even taken a look at the provided
functions and I've not learnt anything :((( I've even eat a segfault
or two when using compadd with the '-p' option.

    Could anybody lend me a hand and explain me how all this works so
I can keep on practicing? Thanks a lot in advance :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/


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

* Re: compsys issues
  2004-10-27 13:26 compsys issues DervishD
@ 2004-10-27 14:08 ` Oliver Kiddle
  2004-10-27 14:54   ` DervishD
  2004-10-27 16:44   ` DervishD
  0 siblings, 2 replies; 6+ messages in thread
From: Oliver Kiddle @ 2004-10-27 14:08 UTC (permalink / raw)
  To: Zsh Users

DervishD wrote:
>     # expand-or-complete is currently bound to <TAB>
>     zle -C expand-or-complete expand-or-complete _completer
> 
>     function _completer () {
> 
>         compstate[insert]=${compstate[insert]//tab /}
> 
>         compadd -f - $PREFIX*(/)

I realise that it is there to get any preceding directory portion but
you're overriding the internal matching by starting the pattern match
with $PREFIX. I'd use something like ${(M)PREFIX##*/} instead.

>     Let's say I pick 'Projects' and hit tab again. Now I'm presented
> with this:
> 
>     $ cd Projects/<TAB>
> 
>     Projects/mta/ Projects/zsh-things/ Projects/more/
> 
>     But what I want is to be presented with:
> 
>     $ cd Projects/<TAB>
> 
>     mta/ zsh-things/ more/

For that, you need to use compset -P '*/' to move the initial directory
portions to $IPREFIX so they are not part of matching.

>     I've tried tweaking IPREFIX and PREFIX (with and without the help
> from compset), I've tried generating the list of matches before

You need to tweak the compadd command too. After compset, any initial
directory portion will be in $IPREFIX instead of $PREFIX. That will
include a trailing slash so you can do $IPREFIX*(/) to get the files.

That will now try to add stuff like `Projects/more' as a match when
`Projects/' is in IPREFIX. You don't want to include the stuff in
$IPREFIX in the possible matches so you can use the :t modifier to get
just the filenames as matches: $IPREFIX*(/:t)

Next, you need to use compadd's -W option so that the -f option can find
the right directory. Try something like the following to begin with:

compadd -W $PWD/$IPREFIX -f - $IPREFIX*(/:t)

That won't work with paths starting with variable expansions or
non-relative directories. You'll need more logic to work out the
argument to -W. Using $~IPREFIX will help resolve any expansions on the
command line.

Hope that helps

Oliver


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

* Re: compsys issues
  2004-10-27 14:08 ` Oliver Kiddle
@ 2004-10-27 14:54   ` DervishD
  2004-10-27 15:43     ` Oliver Kiddle
  2004-10-27 16:44   ` DervishD
  1 sibling, 1 reply; 6+ messages in thread
From: DervishD @ 2004-10-27 14:54 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh Users

    Hi Oliver :)

 * Oliver Kiddle <okiddle@yahoo.co.uk> dixit:
> >     # expand-or-complete is currently bound to <TAB>
> >     zle -C expand-or-complete expand-or-complete _completer
> > 
> >     function _completer () {
> > 
> >         compstate[insert]=${compstate[insert]//tab /}
> > 
> >         compadd -f - $PREFIX*(/)
> I realise that it is there to get any preceding directory portion but
> you're overriding the internal matching by starting the pattern match
> with $PREFIX. I'd use something like ${(M)PREFIX##*/} instead.

    OK, but that doesn't solve the problem I explained below. And I
assumed that I must use $PREFIX :? I don't understand why I must
remove the last path element from PREFIX :?

 
> >     Let's say I pick 'Projects' and hit tab again. Now I'm presented
> > with this:
> > 
> >     $ cd Projects/<TAB>
> > 
> >     Projects/mta/ Projects/zsh-things/ Projects/more/
> > 
> >     But what I want is to be presented with:
> > 
> >     $ cd Projects/<TAB>
> > 
> >     mta/ zsh-things/ more/
> For that, you need to use compset -P '*/' to move the initial directory
> portions to $IPREFIX so they are not part of matching.

    Done, but then I'm presented the same list again and again:

    $ cd Projects/<TAB>

    Projects Work ...

    I see, I need more tweaking. I'll keep on reading...
 
> >     I've tried tweaking IPREFIX and PREFIX (with and without the help
> > from compset), I've tried generating the list of matches before
> You need to tweak the compadd command too. After compset, any initial
> directory portion will be in $IPREFIX instead of $PREFIX. That will
> include a trailing slash so you can do $IPREFIX*(/) to get the files.

    First error I made, then. I did something like this:

    compset -P '*/'
    compadd -f - $IPREFIX$PREFIX*(/)

> That will now try to add stuff like `Projects/more' as a match when
> `Projects/' is in IPREFIX. You don't want to include the stuff in
> $IPREFIX in the possible matches so you can use the :t modifier to get
> just the filenames as matches: $IPREFIX*(/:t)

    I tried to do something like that but it didn't work. I don't
know what my mistake was, I'm afraid...
 
> Next, you need to use compadd's -W option so that the -f option can find
> the right directory. Try something like the following to begin with:
> compadd -W $PWD/$IPREFIX -f - $IPREFIX*(/:t)

    That works perfectly, thanks a lot :) The only part I didn't
understand was the -W flag. I mean, the manual says this flag adds the
string to the WORDS, and I though that the process was:

    - compadd expands the pattern and build a list of words
    - compadd matches the words with the current word being completed
    - compadd produces a list of matches
    - the contents of -W is added to THAT list

    But if I understand correctly, the string that follows '-W' is
added *before* compadd does the matching, am I wrong?

> Hope that helps

    It *really* helps, thanks a lot, Oliver :)

    Only one more thing, abusing of you O:). I get a segfault under
4.0.9 (probably it is fixed in newer versions) if I do this:

    zle -C expand-or-complete expand-or-complete _completer

    function _completer () {

        emulate -L zsh

        setopt extendedglob globdots globassign null_glob

        compstate[insert]=${compstate[insert]//tab /}

        compadd -p 'A' -f - $PREFIX*(/)

        return 0
    }

    and I do something like 'cd A <TAB>'. Do you know why?

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/


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

* Re: compsys issues
  2004-10-27 14:54   ` DervishD
@ 2004-10-27 15:43     ` Oliver Kiddle
  2004-10-27 16:07       ` DervishD
  0 siblings, 1 reply; 6+ messages in thread
From: Oliver Kiddle @ 2004-10-27 15:43 UTC (permalink / raw)
  To: Zsh Users

DervishD wrote:
> 
>     OK, but that doesn't solve the problem I explained below. And I
> assumed that I must use $PREFIX :? I don't understand why I must
> remove the last path element from PREFIX :?

Sorry, I probably only confused things by mentioning that point. It only
really matters if you use matching control. For example, if you want
case-insensitive matching. If $PREFIX contains `mo', mo* would not match
a file named More while just adding * as matches allows the completion
matching control to decide for itself which files match.

>     That works perfectly, thanks a lot :) The only part I didn't
> understand was the -W flag. I mean, the manual says this flag adds the
> string to the WORDS, and I though that the process was:

-W only controls the way the -f option works. The string is added to the
WORDS purely for the purpose of finding out whether the match refers to
a regular file, a directory or whatever. -W has no effect on what the
list of matches will be. Try removing the -W and -f options from compadd
and use `-S /' instead if you want.

>     But if I understand correctly, the string that follows '-W' is
> added *before* compadd does the matching, am I wrong?

Whether it is before or after makes no difference. The string following
-W has nothing to do with matching.

Oliver


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

* Re: compsys issues
  2004-10-27 15:43     ` Oliver Kiddle
@ 2004-10-27 16:07       ` DervishD
  0 siblings, 0 replies; 6+ messages in thread
From: DervishD @ 2004-10-27 16:07 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh Users

    Hi Oliver :)

 * Oliver Kiddle <okiddle@yahoo.co.uk> dixit:
> >     OK, but that doesn't solve the problem I explained below. And I
> > assumed that I must use $PREFIX :? I don't understand why I must
> > remove the last path element from PREFIX :?
> Sorry, I probably only confused things by mentioning that point. It only
> really matters if you use matching control. For example, if you want
> case-insensitive matching. If $PREFIX contains `mo', mo* would not match
> a file named More while just adding * as matches allows the completion
> matching control to decide for itself which files match.

    OK, now I understand. If I use $PREFIX and '-M', that won't work,
am I right? If I use $PREFIX I should use too :t or something similar
so it affects the globbing pattern but not the matching mechanism of
compadd, right?

> >     That works perfectly, thanks a lot :) The only part I didn't
> > understand was the -W flag. I mean, the manual says this flag adds the
> > string to the WORDS, and I though that the process was:
> -W only controls the way the -f option works. The string is added to the
> WORDS purely for the purpose of finding out whether the match refers to
> a regular file, a directory or whatever. -W has no effect on what the
> list of matches will be. Try removing the -W and -f options from compadd
> and use `-S /' instead if you want.

    Nice :)) I want coloring in the matching list, so I'll keep -f.
 
> >     But if I understand correctly, the string that follows '-W' is
> > added *before* compadd does the matching, am I wrong?
> Whether it is before or after makes no difference. The string following
> -W has nothing to do with matching.

    Now I understand, right. I was confused by the manual and deduced
that -W affected the matching.

    Thanks a lot for your kind and useful explanation :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/


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

* Re: compsys issues
  2004-10-27 14:08 ` Oliver Kiddle
  2004-10-27 14:54   ` DervishD
@ 2004-10-27 16:44   ` DervishD
  1 sibling, 0 replies; 6+ messages in thread
From: DervishD @ 2004-10-27 16:44 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh Users

    Hi Oliver :)

 * Oliver Kiddle <okiddle@yahoo.co.uk> dixit:
> compadd -W $PWD/$IPREFIX -f - $IPREFIX*(/:t)
> 
> That won't work with paths starting with variable expansions or
> non-relative directories. You'll need more logic to work out the
> argument to -W. Using $~IPREFIX will help resolve any expansions on the
> command line.

    Just to make sure I've understood, if I want to make it work with
absolute and relative pathnames (I'll get into variable expansions
after that), I should do something like:

    compset -P '*/'
    PREPATH="$PWD/"
    [[ $IPREFIX[1] == "/" ]] && {
        IPPREFIX=${IPPREFIX#/}
        PREPATH="/"
    }
    compadd -W $PREPATH$IPREFIX -f - ${IPREFIX}*(:t)

    Quick'n'dirty hack, but it should work, shouldn't it?

    Thanks again, Oliver :)
    
    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/


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

end of thread, other threads:[~2004-10-27 16:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-27 13:26 compsys issues DervishD
2004-10-27 14:08 ` Oliver Kiddle
2004-10-27 14:54   ` DervishD
2004-10-27 15:43     ` Oliver Kiddle
2004-10-27 16:07       ` DervishD
2004-10-27 16:44   ` DervishD

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