* Feature suggestion for autoload
@ 2008-07-15 17:10 Richard Hartmann
2008-07-16 1:39 ` Bart Schaefer
0 siblings, 1 reply; 8+ messages in thread
From: Richard Hartmann @ 2008-07-15 17:10 UTC (permalink / raw)
To: Zsh hackers list
I just wanted to put some functions in an extra folder & autoload
them, but I don't have my ZSH book here so I could not look up
the snippet to autoload all functions in a directory. This has got
me thinking about an extra option for autoload which allows you
to autoload all functions in a directory. Additionally, an option to
autoload everything it finds could be useful for some though I
doubt I would use it.
Another option would be to define an array and load everything
in said array. This could make a long list os autoloads more
readable.
I am not sure how useful this would be for others, so feedback
would be appreciated.
Richard
PS: Yes, I am aware this could all be done in a function. A
function which could the be autoloaded for some nice
recursion :)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Feature suggestion for autoload
2008-07-15 17:10 Feature suggestion for autoload Richard Hartmann
@ 2008-07-16 1:39 ` Bart Schaefer
2008-07-16 23:44 ` Richard Hartmann
0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2008-07-16 1:39 UTC (permalink / raw)
To: Zsh hackers list
On Jul 15, 7:10pm, Richard Hartmann wrote:
}
} I just wanted to put some functions in an extra folder & autoload
} them, but I don't have my ZSH book here so I could not look up
} the snippet to autoload all functions in a directory.
Er, how would you do anything *else* to all the files in a directory?
OK, so it's not *quite* that easy because you need file base names, but
even if you can't remember
fpath+=(thedirectory)
autoload thedirectory/*(:t)
then it still shouldn't be too hard to think of
fpath+=(thedirectory)
cd thedirectory
autoload *
cd -
Some people make all/only the autoloadable functions executable so
that they can use
autoload *(*)
} This has got me thinking about an extra option for autoload which
} allows you to autoload all functions in a directory.
"autoload" is just an alias for "typeset -fu" ... I'm excited neither
about making it a separate implementation nor about teaching typedef
how to read directories.
} Additionally, an option to autoload everything it finds could be
} useful for some though I doubt I would use it.
"Finds" where?
Anyway, have a look at the zcompile builtin ...
} Another option would be to define an array and load everything
} in said array. This could make a long list os autoloads more
} readable.
Yes, you can certainly do that. There's no practical limit on the
number of function names you can pass to a single autoload command.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Feature suggestion for autoload
2008-07-16 1:39 ` Bart Schaefer
@ 2008-07-16 23:44 ` Richard Hartmann
2008-07-17 0:55 ` Phil Pennock
2008-07-17 9:05 ` Peter Stephenson
0 siblings, 2 replies; 8+ messages in thread
From: Richard Hartmann @ 2008-07-16 23:44 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh hackers list
On Wed, Jul 16, 2008 at 03:39, Bart Schaefer <schaefer@brasslantern.com> wrote:
> fpath+=(thedirectory)
> autoload thedirectory/*(:t)
Peter's snippet is
autoload -- ~/.zfunc/[^_]*(:t)
It was the part with not loading files that have a leading underscore that
eluded me.
> fpath+=(thedirectory)
> cd thedirectory
> autoload *
> cd -
True, but that's not as elegant as the above. As it was not time critical,
I prefered not to 'hack' something up.
> "autoload" is just an alias for "typeset -fu" ... I'm excited neither
> about making it a separate implementation nor about teaching typedef
> how to read directories.
Good reason, agreed.
> "Finds" where?
What I meant was 'autoload every file you find in fpath'. That suggestion
is moot now, though.
> Yes, you can certainly do that. There's no practical limit on the
> number of function names you can pass to a single autoload command.
Brain fart, of course you can. Sorry.
Thanks,
Richard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Feature suggestion for autoload
2008-07-16 23:44 ` Richard Hartmann
@ 2008-07-17 0:55 ` Phil Pennock
2008-07-17 9:05 ` Peter Stephenson
1 sibling, 0 replies; 8+ messages in thread
From: Phil Pennock @ 2008-07-17 0:55 UTC (permalink / raw)
To: Richard Hartmann; +Cc: Zsh hackers list
On 2008-07-17 at 01:44 +0200, Richard Hartmann wrote:
> What I meant was 'autoload every file you find in fpath'. That suggestion
> is moot now, though.
While it may be moot, this might be helpful anyway.
You might want to look at the demonstration start-up files supplied with
zsh. StartupFiles/ sub-directory of the source, no idea what any given
distribution does with them.
The provided example to do just this is:
----------------------------8< cut here >8------------------------------
# Autoload all shell functions from all directories in $fpath (following
# symlinks) that have the executable bit on (the executable bit is not
# necessary, but gives you an easy way to stop the autoloading of a
# particular shell function). $fpath should not be empty for this to work.
for func in $^fpath/*(N-.x:t); autoload $func
----------------------------8< cut here >8------------------------------
My preferred OS (FreeBSD) happens to not preserve executability on the
zsh-supplied files for the Port, so I end up with:
autoload ${^fpath}/*(N-.:t)
typeset -U fpath
fpath=(~/bin/zsh-funcs $fpath)
set -A _foo ~/bin/zsh-funcs/*(N-.x:t)
[[ ${#_foo} -gt 0 ]] && autoload $_foo
unset _foo
Just two examples.
-Phil
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Feature suggestion for autoload
2008-07-16 23:44 ` Richard Hartmann
2008-07-17 0:55 ` Phil Pennock
@ 2008-07-17 9:05 ` Peter Stephenson
2008-07-17 13:24 ` Richard Hartmann
1 sibling, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2008-07-17 9:05 UTC (permalink / raw)
To: Zsh hackers list
On Thu, 17 Jul 2008 01:44:33 +0200
"Richard Hartmann" <richih.mailinglist@gmail.com> wrote:
> On Wed, Jul 16, 2008 at 03:39, Bart Schaefer <schaefer@brasslantern.com> wrote:
> > fpath+=(thedirectory)
> > autoload thedirectory/*(:t)
>
> Peter's snippet is
>
> autoload -- ~/.zfunc/[^_]*(:t)
(Just to get this out of the way---I'm stating the absolute blindingly
obvious but of course you need the directory in fpath in the second case,
too.)
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Feature suggestion for autoload
2008-07-17 9:05 ` Peter Stephenson
@ 2008-07-17 13:24 ` Richard Hartmann
2008-07-17 13:43 ` Bart Schaefer
0 siblings, 1 reply; 8+ messages in thread
From: Richard Hartmann @ 2008-07-17 13:24 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh hackers list
On Thu, Jul 17, 2008 at 11:05, Peter Stephenson <pws@csr.com> wrote:
> (Just to get this out of the way---I'm stating the absolute blindingly
> obvious but of course you need the directory in fpath in the second case,
> too.)
Of course. Incidentially, that is that I meant with 'load a whole directory'
in my first mail. A command that wraps the adding to fpath & adding to
the list of autoloaded functions into one statement.
Thanks,
Richard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Feature suggestion for autoload
2008-07-17 13:24 ` Richard Hartmann
@ 2008-07-17 13:43 ` Bart Schaefer
2008-07-17 14:33 ` Richard Hartmann
0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2008-07-17 13:43 UTC (permalink / raw)
To: Zsh hackers list
On Jul 17, 3:24pm, Richard Hartmann wrote:
}
} Incidentially, that is that I meant with 'load a whole directory'
} in my first mail. A command that wraps the adding to fpath & adding to
} the list of autoloaded functions into one statement.
If/when we have ksh-style discipline functions, we can make it a side-
effect of adding something to fpath that all the files therein get
fed to autoload.
(Not that we should have that happen by default, but it would make a
good example.)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Feature suggestion for autoload
2008-07-17 13:43 ` Bart Schaefer
@ 2008-07-17 14:33 ` Richard Hartmann
0 siblings, 0 replies; 8+ messages in thread
From: Richard Hartmann @ 2008-07-17 14:33 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh hackers list
On Thu, Jul 17, 2008 at 15:43, Bart Schaefer <schaefer@brasslantern.com> wrote:
> If/when we have ksh-style discipline functions, we can make it a side-
> effect of adding something to fpath that all the files therein get
> fed to autoload.
>From what google tells me, ksh disciplines are 'methods' for the
'object' of a variable? Another way of putting it would be that they
resemble hooks for variable handling?
Sounds like a nice, and powerful, concept.
> (Not that we should have that happen by default, but it would make a
> good example.)
Aye. Having something like this happen by default would probably
manage to break a lot of installations in weird ways.
Richard
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-07-17 14:34 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-15 17:10 Feature suggestion for autoload Richard Hartmann
2008-07-16 1:39 ` Bart Schaefer
2008-07-16 23:44 ` Richard Hartmann
2008-07-17 0:55 ` Phil Pennock
2008-07-17 9:05 ` Peter Stephenson
2008-07-17 13:24 ` Richard Hartmann
2008-07-17 13:43 ` Bart Schaefer
2008-07-17 14:33 ` Richard Hartmann
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).