From ae133abca9cf14f56ddb72503e42a107da422b17 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Wed, 3 Jan 2018 10:16:45 -0500 Subject: [PATCH] Compile functions.zwc for each functions directory instead of a big single `functions.zwc` file containing functions from all the `functions` subdirectories. 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` With this approach, we're also having individual entries back in `fpath` for the `functions` subdirectory of each enabled module (as was the case before commit 55df5a4). This is also probably closest to the original plan at #86. The current code was not compiling "*all* files in a folder into a single digest", but instead compiling *all* files in *all* the functions folders into a single digest, which was a bad idea. This commit fixes this. Fixes #231. Fixes #232. Closes #234. Closes #239 --- init.zsh | 2 +- login_init.zsh | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/init.zsh b/init.zsh index 514d29d..0ee95ed 100755 --- a/init.zsh +++ b/init.zsh @@ -20,7 +20,7 @@ fi setopt LOCAL_OPTIONS EXTENDED_GLOB # autoload searches fpath for function locations; add enabled module function paths - fpath=(${ZIM_HOME}/functions.zwc ${ZIM_HOME}/modules/prompt/functions ${fpath}) + 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 autoload -Uz ${mod_function} diff --git a/login_init.zsh b/login_init.zsh index c9fb88b..5735026 100755 --- a/login_init.zsh +++ b/login_init.zsh @@ -8,8 +8,7 @@ # ( - local file - local zmodule + local dir file setopt LOCAL_OPTIONS EXTENDED_GLOB autoload -U zrecompile @@ -20,11 +19,13 @@ zrecompile -pq ${ZDOTDIR:-${HOME}}/.zshrc # 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 - for zmodule (${zmodules}); do - zrecompile -pq ${ZIM_HOME}/modules/${zmodule}/init.zsh + for file in ${ZIM_HOME}/modules/${^zmodules}/init.zsh(-.N); do + zrecompile -pq ${file} done # zcompile all prompt setup scripts