zsh-users
 help / color / mirror / code / Atom feed
* Filename expansion within a completion widget
@ 2004-11-02 23:36 DervishD
  2004-11-02 23:44 ` DervishD
  0 siblings, 1 reply; 4+ messages in thread
From: DervishD @ 2004-11-02 23:36 UTC (permalink / raw)
  To: Zsh Users

    Hi all :)

    Let's say I run the following script:

---
#!/bin/zsh
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 /}

    compset -P '*/'
    BASEDIR=""
    [[ $IPREFIX[1] != "/" ]] && BASEDIR="$PWD/"
    
    compadd -W $BASEDIR$IPREFIX -f - ${IPREFIX}*(:t)
    
    return 0
}
---

    Well, it handles both relative and absolute directories
correctly, but doesn't handle named directories :(( I don't
understand why because if I type 'cd ~X<TAB>' the named dir should be
expanded, shouldn't it?

    If it shouldn't, could anyone hint me how to do it? Should I
bother with any other similar problems (I mean, like mangling IPREFIX
for absolute directories and the like)?

    Thanks a lot, as always :)

    Raúl Núñez de Arenas Coronado

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


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

* Re: Filename expansion within a completion widget
  2004-11-02 23:36 Filename expansion within a completion widget DervishD
@ 2004-11-02 23:44 ` DervishD
  2004-11-04  2:19   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: DervishD @ 2004-11-02 23:44 UTC (permalink / raw)
  To: Zsh Users

    Hi all :)

>     compstate[insert]=${compstate[insert]//tab /}
> 
>     compset -P '*/'
> 
>     Well, it handles both relative and absolute directories
> correctly, but doesn't handle named directories :(( I don't
> understand why because if I type 'cd ~X<TAB>' the named dir should be
> expanded, shouldn't it?
> 
>     If it shouldn't, could anyone hint me how to do it? Should I
> bother with any other similar problems (I mean, like mangling IPREFIX
> for absolute directories and the like)?

    Of course, adding something like 'PREFIX=$~PREFIX' just before
the compset call solves the problem, but then the named dir is
'translated', which I don't want, and additional code is needed in
the compadd call to 'untranslate' it. There is surely another way of
doing this...

    Raúl Núñez de Arenas Coronado

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


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

* Re: Filename expansion within a completion widget
  2004-11-02 23:44 ` DervishD
@ 2004-11-04  2:19   ` Bart Schaefer
  2004-11-04 10:33     ` DervishD
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2004-11-04  2:19 UTC (permalink / raw)
  To: Zsh Users

On Wed, 3 Nov 2004, DervishD wrote:

> >     compset -P '*/'
> > 
> >     Well, it handles both relative and absolute directories
> > correctly, but doesn't handle named directories :(( I don't
> > understand why because if I type 'cd ~X<TAB>' the named dir should be
> > expanded, shouldn't it?

"Expanded" would mean that ~X was replaced by the path it represents.  
Yet later you say this isn't the behavior you want.  If the variable is 
really $X11, for example, then converting ~X to ~X11 is not "expanding", 
it's "completing", at least in zsh's terminology (e.g., for purposes of 
the widget "expand-or-complete").

And if you've written your own completion widget, you have to do the
completing yourself, right?

>     Of course, adding something like 'PREFIX=$~PREFIX' just before
> the compset call solves the problem, but then the named dir is
> 'translated', which I don't want

Just because you're not using zsh's completion system functions doesn't 
mean you can't look at them for hints.  Completion/Unix/Type/_tilde_files 
would be a good place to start; note in particular the case statement on
$PREFIX.

> There is surely another way of doing this...

The short answer is that if there is not a slash in the string yet, you 
remove the tilde from consideration with compset -P, and then you compadd 
the userdirs and/or nameddirs arrays from the zsh/parameter module.  If 
there is a slash in the string, you have to manipulate IPREFIX and then 
use compadd -W.


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

* Re: Filename expansion within a completion widget
  2004-11-04  2:19   ` Bart Schaefer
@ 2004-11-04 10:33     ` DervishD
  0 siblings, 0 replies; 4+ messages in thread
From: DervishD @ 2004-11-04 10:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> > >     compset -P '*/'
> > > 
> > >     Well, it handles both relative and absolute directories
> > > correctly, but doesn't handle named directories :(( I don't
> > > understand why because if I type 'cd ~X<TAB>' the named dir should be
> > > expanded, shouldn't it?
> "Expanded" would mean that ~X was replaced by the path it represents.  
> Yet later you say this isn't the behavior you want.

    I didn't explained correctly O:)) I want it expanded within the
completion widget, not in the command line. The problem is that the
compadd call doesn't work if the WORD has '~' as the first character.

    I want this:

    $ cd ~X<TAB><TAB>

    X11/    usr/    bin/    include/

    And after that, insert the completions. If I 'translate' PREFIX
so the named dir is expanded, completion works OK, but then I have
the named dir translated in the command line.

    I want to translate it only in the widget so compadd can
correctly generate the list.

> >     Of course, adding something like 'PREFIX=$~PREFIX' just before
> > the compset call solves the problem, but then the named dir is
> > 'translated', which I don't want
> Just because you're not using zsh's completion system functions doesn't 
> mean you can't look at them for hints.  Completion/Unix/Type/_tilde_files 
> would be a good place to start; note in particular the case statement on
> $PREFIX.

    I'll take a look, but my problem is that I don't understand most
of the code. It is not very readable and is quite complex for me O:)
But I'll take a look at _tilde_files. Thanks for the reference.
 
> > There is surely another way of doing this...
> The short answer is that if there is not a slash in the string yet, you 
> remove the tilde from consideration with compset -P, and then you compadd 
> the userdirs and/or nameddirs arrays from the zsh/parameter module.  If 
> there is a slash in the string, you have to manipulate IPREFIX and then 
> use compadd -W.

    Thanks a lot, Bart, I'll take a look at _tilde_files and try to
get the point. Thanks for coming to the rescue again ;)

    Raúl Núñez de Arenas Coronado

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


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

end of thread, other threads:[~2004-11-04 10:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-02 23:36 Filename expansion within a completion widget DervishD
2004-11-02 23:44 ` DervishD
2004-11-04  2:19   ` Bart Schaefer
2004-11-04 10:33     ` 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).