zsh-workers
 help / color / mirror / code / Atom feed
* Re: Announce of Zsh Navigation Tools
       [not found] ` <55F465E6.1040405@eastlink.ca>
@ 2015-09-13  9:10   ` Sebastian Gniazdowski
  2015-09-13 16:11     ` autoloading fpath (was Re: Announce of Zsh Navigation Tools) Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2015-09-13  9:10 UTC (permalink / raw)
  To: zsh-workers; +Cc: Ray Andrews

On 12 September 2015 at 19:50, Ray Andrews <rayandrews@eastlink.ca> wrote:
> Thanks for those Sebastian, I'm playing with them now, several look very
> useful.  One thing, I had to create '/usr/local/share/zsh/site-functions'.
> I wonder if there is a location for the files that is in keeping with my
> directory structure.  A trivial point: in the files, you call them
> 'functions' whereas they are scrips, I believe.  However, I'm tempted to
> convert them to functions anyway.
>

What was your $fpath? As far I know, $fpath[1] should point to a
site-functions directory.

I the rest of the emails you apparently have an idea of a
autostart-functions directory that would automatically do "autoload
{function}" for each file placed there. It would make installation of
scripts like ZNT easier and I thought about such directory too.

Best regards,
Sebastian Gniazdowski


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

* autoloading fpath (was Re: Announce of Zsh Navigation Tools)
  2015-09-13  9:10   ` Announce of Zsh Navigation Tools Sebastian Gniazdowski
@ 2015-09-13 16:11     ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2015-09-13 16:11 UTC (permalink / raw)
  To: zsh-workers

On Sep 13, 11:10am, Sebastian Gniazdowski wrote:
}
} I the rest of the emails you apparently have an idea of a
} autostart-functions directory that would automatically do "autoload
} {function}" for each file placed there. It would make installation of
} scripts like ZNT easier and I thought about such directory too.

This is effectively what "compinit" does for every file in the $fpath
that is named beginning with an underscore.  It reads the first line
of every such file to decide what to do with it.

While we're on the subject, though, take a look at the "zcompile"
builtin and the "zrecompile" utility.  If you zcompile a collection
of functions into a .zwc file, you can --

-- add the .zwc file name directly to $fpath and it will be searched
   like a directory at autoloaded-function execution time

-- specify the -z / -k behavior options at zcompile time so they don't
   have to be passed to autoload

-- easily autoload everything in the file:   autoload -w functions.zwc

ZWC files are machine-independent but zsh-version-dependent.  They get
memory-mapped when that's supported so the OS pages them efficiently.
The drawbacks are the version dependency if you frequently rebuild a
bleeding-edge shell (but see zrecompile) and that zcompile doesn't yet
support "sticky emulation" in any meaningful way.  Also, a ZWC file is
not like an archive file (e.g. a ZIP); you can't append or remove
individual functions, the whole file has to be rebuilt.

Finally, for Ray, you can for example replace your entire $fpath with
a single ZWC file:

    # Assume starting here with the default $fpath
    zsh_default_functions=~/.zsh-default-functions.zwc
    if ! zcompile -t $zsh_default_functions >&/dev/null
    then
      # File is missing or out of date.  Rebuild it.
      # Removes the file if any function cannot be compiled.
      zcompile $zsh_default_functions $^fpath/*(N.:A)
    fi
    if [[ -f $zsh_default_functions ]]
    then
      fpath=( $zsh_default_functions )
      autoload -w $zsh_default_functions
    fi


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

end of thread, other threads:[~2015-09-13 16:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAKc7PVCFRY-e+KvHzYK-VFFeRhRWL+HPWThYSJsTtZr6L3CT-Q@mail.gmail.com>
     [not found] ` <55F465E6.1040405@eastlink.ca>
2015-09-13  9:10   ` Announce of Zsh Navigation Tools Sebastian Gniazdowski
2015-09-13 16:11     ` autoloading fpath (was Re: Announce of Zsh Navigation Tools) Bart Schaefer

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