zsh-workers
 help / color / mirror / code / Atom feed
* Wierd autoload problems with nested directories
@ 2005-06-14  0:55 Ulf Magnusson
  2005-06-14  3:05 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Ulf Magnusson @ 2005-06-14  0:55 UTC (permalink / raw)
  To: zsh-workers

I keep my completion functions in /home/ulf/lib/zsh/completions and
other, general-purpose functions in its parent dir, /home/ulf/lib/zsh.
For some reason, my completions will only work ('work' as in zsh not
using its default completion behaviour for the context in question) if
I place them in /home/ulf/lib/zsh.

I set the completion and other functions up for autoloading in two
sections of my .zshrc with the following code:


fpath=(/home/ulf/lib/zsh/completions $fpath)
autoload -U $fpath[1]/*(:t)

fpath=(/home/ulf/lib/zsh $fpath)
autoload -U $fpath[1]/*(:t)


print -l ${fpath[1,3]} yields

/home/ulf/lib/zsh/completions
/home/ulf/lib/zsh
/usr/local/share/zsh/site-functions

, as expected. I do not have KSH_AUTOLOAD nor any other options I
imagine could cause this problem set. My completion function (the only
one so far), stored in the file /home/ulf/lib/zsh/completions/_xmms
looks as follows:


#compdef xmms

local directories
directories=( /s/Music/**/(/) )
_files -W directories -g '*.(mp3|ogg)'


(It's not done yet, do not bug me about it :) )

Ulf


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

* Re: Wierd autoload problems with nested directories
  2005-06-14  0:55 Wierd autoload problems with nested directories Ulf Magnusson
@ 2005-06-14  3:05 ` Bart Schaefer
  2005-06-14 15:40   ` Ulf Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2005-06-14  3:05 UTC (permalink / raw)
  To: zsh-workers

On Jun 14,  2:55am, Ulf Magnusson wrote:
}
} fpath=(/home/ulf/lib/zsh/completions $fpath)
} autoload -U $fpath[1]/*(:t)
} 
} fpath=(/home/ulf/lib/zsh $fpath)
} autoload -U $fpath[1]/*(:t)

You might note that this will result in the "completions" subdirectory
being treated as the name of a function for autoloading.  You probably
should be doing

    autoload -U $fpath[1]/*(.:t)

Also please note that the location from which the function is loaded
depends on the value of $fpath at the time you call the function, NOT
upon the value of $fpath at the time you run "autoload".

} print -l ${fpath[1,3]} yields
} 
} /home/ulf/lib/zsh/completions
} /home/ulf/lib/zsh
} /usr/local/share/zsh/site-functions
} 
} , as expected.

That's certainly not what *I* would have expected.  If the two fpath
assignments really do appear in the order that you show them, I would
expect:

    /home/ulf/lib/zsh
    /home/ulf/lib/zsh/completions
    /usr/local/share/zsh/site-functions

Also, I'd have expected /usr/local/share/zsh/$ZSH_VERSION/functions
(for suitable expansion of $ZSH_VERSION) to appear in the list.

} For some reason, my completions will only work ('work' as in zsh not
} using its default completion behaviour for the context in question) if
} I place them in /home/ulf/lib/zsh.

At what point amidst all of this do you run "compinit"?

Merely autoloading a completion function isn't good enough -- compinit
has to examine the file and read the #compdef line.  That means you must
not run compinit until after you've added to fpath all the directories
where completion functions might be found.


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

* Re: Wierd autoload problems with nested directories
  2005-06-14  3:05 ` Bart Schaefer
@ 2005-06-14 15:40   ` Ulf Magnusson
  0 siblings, 0 replies; 3+ messages in thread
From: Ulf Magnusson @ 2005-06-14 15:40 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On 6/14/05, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Jun 14,  2:55am, Ulf Magnusson wrote:
> }
> } fpath=(/home/ulf/lib/zsh/completions $fpath)
> } autoload -U $fpath[1]/*(:t)
> }
> } fpath=(/home/ulf/lib/zsh $fpath)
> } autoload -U $fpath[1]/*(:t)
> 
> You might note that this will result in the "completions" subdirectory
> being treated as the name of a function for autoloading.  You probably
> should be doing
> 
>     autoload -U $fpath[1]/*(.:t)
> 

You're right of course.

> Also please note that the location from which the function is loaded
> depends on the value of $fpath at the time you call the function, NOT
> upon the value of $fpath at the time you run "autoload".
> 
> } print -l ${fpath[1,3]} yields
> }
> } /home/ulf/lib/zsh/completions
> } /home/ulf/lib/zsh
> } /usr/local/share/zsh/site-functions
> }
> } , as expected.
> 
> That's certainly not what *I* would have expected.  If the two fpath
> assignments really do appear in the order that you show them, I would
> expect:
> 
>     /home/ulf/lib/zsh
>     /home/ulf/lib/zsh/completions
>     /usr/local/share/zsh/site-functions
> 

Another mistake there, the two fpath= / autoload pairs appear in the
opposite order in my .zshrc.

> Also, I'd have expected /usr/local/share/zsh/$ZSH_VERSION/functions
> (for suitable expansion of $ZSH_VERSION) to appear in the list.

/usr/local/share/zsh/$ZSH_VERSION/functions doesn't show up in my
fpath even if I comment out all fpath-altering lines in my .zshrc.
Only the subdirectories of /usr/local/share/zsh/$ZSH_VERSION/functions
do. It shouldn't be a problem though, since no functions are stored it
the base directory anyway.

> 
> } For some reason, my completions will only work ('work' as in zsh not
> } using its default completion behaviour for the context in question) if
> } I place them in /home/ulf/lib/zsh.
> 
> At what point amidst all of this do you run "compinit"?
> 
> Merely autoloading a completion function isn't good enough -- compinit
> has to examine the file and read the #compdef line.  That means you must
> not run compinit until after you've added to fpath all the directories
> where completion functions might be found.
> 

I ran compinit before autoload:ing the functions in
/home/ulf/lib/zsh/completions. Moving the call after the autoload
fixed my problems. The user-friendly guide could have been clearer in
telling you that you need to call compinit after setting up fpath. I
only skimmed the manual (it's often way over my head as a zsh newbie),
so I don't know if it's clearer on this point. Thanks for the help!

Ulf


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

end of thread, other threads:[~2005-06-14 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-14  0:55 Wierd autoload problems with nested directories Ulf Magnusson
2005-06-14  3:05 ` Bart Schaefer
2005-06-14 15:40   ` Ulf Magnusson

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