8000 Autoload functions even for custom fpath · Issue #551 · zimfw/zimfw · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Autoload functions even for custom fpath #551
Open
@yxtay

Description

@yxtay

Prerequisites

  • I've checked the existing issues and I'm not duplicating a report.
  • I've checked the zimfw Changelog and I'm not being affected by documented changes.
  • I've checked the zimfw 📢 Announcements and I'm not being affected by announced changes.

Bug description

In the current implementation if zmodule is specified with any of the following options, --source, --fpath, zimfw no longer automatically search the plugin for functions to autoload.

I feel that the more user friendly behaviour is that zimfw searches the fpath for functions to autoload unless --autoload is specified by the user. The number of functions to autoload can be potentially numerous, so it is not ergonomic to expect the user to specify all functions to autoload by themselves just because a plugin has an unusual --source or --fpath.

Steps to reproduce

  1. cd ${$(mktemp -d):A} && \
        ZDOTDIR=${PWD} HOME=${PWD} ZIM_HOME=${PWD}/.zim && \
        curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
    
  2. # ${ZDOTDIR}/.zimrc
    zmodule romkatv/zsh-defer --fpath .
    
  3. exec zsh
  4. cat $ZIM_HOME/init.zh
    # $ZIM_HOME/init.zh
    fpath=("${HOME}/.config/zim/modules/zsh-defer")
    
    # expected function to be autoloaded, but it is not
    # autoload -Uz -- zsh-defer
    

Current behavior

Functions to autoload are not automatically detected if custom --fpath is specified.

Expected behavior

Expect zimfw to automatically search fpath to autoload functions even if custom --source or --fpath is specified.

zimfw info

ZIM_HOME:             ~/.config/zim
zimfw config:         ~/.config/zsh/.zimrc
zimfw script:         ~/.config/zim/zimfw.zsh
zimfw version:        1.16.0 (built at 2024-11-25 13:50:33 UTC, previous commit is 2d5718e)
LANG:                 en_US.UTF-8
OSTYPE:               darwin24.0
TERM:                 xterm-256color
TERM_PROGRAM:         WezTerm
TERM_PROGRAM_VERSION: 20240203-110809-5046fc22
ZSH_VERSION:          5.9

Additional context

I think the reason for this behaviour is that automatically searching for function is done only if none of --source, --fpath and --autoload is specified. I feel that autoloading function (L334) should be moved into it's own block and skipped only if --autoload ((( ! ${#zfunctions} ))) is specified.

zimfw/zimfw.zsh

Lines 330 to 344 in 4f1c59a

if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
zfpaths=(${zroot_dir}/functions(NF))
# _* functions are autoloaded by compinit
# prompt_*_setup functions are autoloaded by promptinit
zfunctions=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t))
local -ra prezto_scripts=(${zroot_dir}/init.zsh(N))
if (( ${#zfpaths} && ${#prezto_scripts} )); then
# this follows the prezto module format, no need to check for other scripts
zcmds=('source '${(qqq)^prezto_scripts:a})
else
# get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first)
local -ra zscripts=(${zroot_dir}/(init.zsh|(${zname:t}|${zroot_dir:t}).(zsh|plugin.zsh|zsh-theme|sh))(NOL[1]))
zcmds=('source '${(qqq)^zscripts:a})
fi
fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0