1
0
Fork 0
mirror of synced 2024-11-29 18:55:34 -05:00

Compile functions.zwc for each functions directory

instead of a big single `functions.zwc` file containing functions from
all the `functions` subdirectories.

Having a big single digest file did reduce the number of OS file
descriptors to 1, instead of:
* as many functions as are declared in enabled modules, what we had
  before commit 55df5a4
* as many enabled modules, as we have implemented in this commit

but it also raised bigger and still unsolved issues as #231, #232, and
#234.

This solution here better suits the functions autoloading mechanism in
zsh, as documented in
http://zsh.sourceforge.net/Doc/Release/Functions.html#index-autoloading-functions

Given `~/.zim/modules/foo/functions` is in the `fpath`, autoload looks
for functions in the following files, picking the **newest one** in this
order:
* `~/.zim/modules/foo/functions.zwc`, which should contain all
  functions in the directory named `functions`
* `~/.zim/modules/foo/functions/function.zwc`
* `~/.zim/modules/foo/functions/function`

A relevant change in this approach is also having individual entries
back in `fpath` for the `functions` subdirectory of each enabled module
(as was the case before commit 55df5a4). With this back, we don't need
to worry anymore about being absolutely sure that all functions are
zcompiled, thanks to the autoloading mechanism described above.

Fixes #231. Fixes #232. Closes #234.
This commit is contained in:
Eric Nielsen 2018-01-03 10:16:45 -05:00
parent 3c96d0b8e1
commit be58a63041
2 changed files with 7 additions and 6 deletions

View file

@ -20,7 +20,7 @@ fi
setopt LOCAL_OPTIONS EXTENDED_GLOB setopt LOCAL_OPTIONS EXTENDED_GLOB
# autoload searches fpath for function locations; add enabled module function paths # autoload searches fpath for function locations; add enabled module function paths
fpath=(${ZIM_HOME}/functions.zwc ${ZIM_HOME}/modules/prompt/functions ${fpath}) [[ -n ${zmodules} ]] && fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath})
for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*|*.zwc|*.zwc.old)(-.N:t); do for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*|*.zwc|*.zwc.old)(-.N:t); do
autoload -Uz ${mod_function} autoload -Uz ${mod_function}

View file

@ -8,8 +8,7 @@
# #
( (
local file local dir file
local zmodule
setopt LOCAL_OPTIONS EXTENDED_GLOB setopt LOCAL_OPTIONS EXTENDED_GLOB
autoload -U zrecompile autoload -U zrecompile
@ -20,11 +19,13 @@
zrecompile -pq ${ZDOTDIR:-${HOME}}/.zshrc zrecompile -pq ${ZDOTDIR:-${HOME}}/.zshrc
# zcompile enabled module autoloaded functions # zcompile enabled module autoloaded functions
zrecompile -pq ${ZIM_HOME}/functions ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*|*.zwc|*.zwc.old)(-.N) for dir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do
zrecompile -pq ${dir}.zwc ${dir}/^([_.]*|prompt_*_setup|README*|*.zwc|*.zwc.old)(-.N)
done
# zcompile enabled module init scripts # zcompile enabled module init scripts
for zmodule (${zmodules}); do for file in ${ZIM_HOME}/modules/${^zmodules}/init.zsh(-.N); do
zrecompile -pq ${ZIM_HOME}/modules/${zmodule}/init.zsh zrecompile -pq ${file}
done done
# zcompile all prompt setup scripts # zcompile all prompt setup scripts