zplug / zplug2

:no_entry_sign: DEPRECATED
https://github.com/b4b4r07/zplug/tree/v2
8 stars 3 forks source link

Improve regex for detecting OMZ function dependencies #24

Closed NigoroJr closed 8 years ago

NigoroJr commented 8 years ago

This change makes the pattern more strict so that expressions that are only in valid function call forms are added as dependencies. Valid forms of function use with examples are:

Error message:

update_terminalapp_cwd:4: command not found: omz_urlencode

Is shown before every prompt when using Terminal.app on a Mac OS X.

This is because lib/termsupport.zsh is considered a dependency of pip.plugin.zsh and is therefore sourced, adding update_terminalapp_cwd function to the precmd hook.

Environment

source $ZPLUG_HOME/init.zsh
zplug 'plugins/pip', \
    from:oh-my-zsh, \
    ignore:{oh-my-zsh.sh,plugins/pip/pip.plugin.zsh}, \
    nice:10

zplug check || zplug install
zplug load

Steps to Reproduce

  1. Start a new zsh session
  2. Observe the message:

    update_terminalapp_cwd:4: command not found: omz_urlencode

    Why this happens

plugins/pip/pip.plugin.zsh has a <title> HTML tag here. There is also a title function defined here. Since zplug only checks the presence of the function name in pip.plugin.zsh, it thinks that the function is being used and sources lib/termsupport.zsh.

Apart from this issue, maybe the check for dependency (i.e. call to __zplug::support::omz::depends) need to be after excluding files specified by the ignore tag, but this is a different issue.

What this PR fixes

In the example, it was <title> (an invalid form of function call) but from what I see it seems like foo_title_bar would also be considered a use of the title function. This PR fixes that scenario too. Valid function uses are described at the top and also in the commit message.

Checking

$ cat <<EOF | egrep "(^|\s|['\"(\`])func[0-9]($|\s|[\\\\'\")\`])"
func1
<func2>
 func3
func4\\
  bar
eval 'func5'
eval "func6 foo"
\`func7\`
foo_func8_bar
EOF
# Outputs:
# func1
#  func3
# func4\
# eval 'func5'
# eval "func6 foo"
# `func7`
NigoroJr commented 8 years ago

Thanks!