From 8d83da217a376a44312b3f9f2bb0db288b598cb0 Mon Sep 17 00:00:00 2001 From: Wu Zhenyu Date: Sat, 1 Jul 2023 07:20:34 +0800 Subject: [PATCH] Improve zsh completion Refer https://github.com/pallets/click/pull/2544/files --- doc/texdoc.tex | 8 +------- script/texdoclib-const.tlu | 14 +++++++++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/texdoc.tex b/doc/texdoc.tex index ce01c8e..f4b39b6 100644 --- a/doc/texdoc.tex +++ b/doc/texdoc.tex @@ -787,13 +787,7 @@ \subsection{Zsh} \item adding \code{eval "\$(texdoc \lopt{print-completion} zsh)"} to your zsh configuration file. -\item adding a file somewhere in \code{\$fpath} with the following contents: -% -\begin{htcode} -#compdef texdoc -(( $+functions[__texdoc] )) || eval "$(texdoc \textbackslash - --print-completion zsh)" && __texdoc -\end{htcode} +\item creating a file named \code{\_texdoc} in \code{\$fpath} whose content is the output of \code{texdoc \lopt{print-completion} zsh}. \end{itemize} \section{Licence} diff --git a/script/texdoclib-const.tlu b/script/texdoclib-const.tlu index c551bf4..1340a82 100644 --- a/script/texdoclib-const.tlu +++ b/script/texdoclib-const.tlu @@ -50,8 +50,8 @@ Website: Repository: Please email bugs to .]] -zsh_completion = [[ -compdef __texdoc texdoc +zsh_completion = [=[ +#compdef texdoc __texdoc() { local options=( @@ -72,7 +72,15 @@ __texdoc() { ;; esac } -]] + +if [[ $zsh_eval_context[-1] == loadautofunc ]]; then + # autoload from fpath, call function directly + __texdoc "$@" +else + # eval/source/. command, register function for later + compdef __texdoc texdoc +fi +]=] --[[ structure of the options table