zsh-workers
 help / color / mirror / code / Atom feed
* autoload path completion with expansions
@ 2021-09-05 18:54 Bart Schaefer
  2021-09-07 23:04 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2021-09-05 18:54 UTC (permalink / raw)
  To: Zsh hackers list

Starting from zsh -f + compinit + zstyle '*' format %d (so, no completer style)

% autoload $PWD/<TAB>
`vars' or `shell function'

This surprised me, because

% ls $PWD/<TAB>
file
(list of files in the current directory)

Turns out this is because _typeset (which handles autoload) only calls
_files when the word on the command line already begins with "/" or
"~".

I debated also adding \` to the pattern.  Thoughts?

diff --git a/Completion/Zsh/Command/_typeset b/Completion/Zsh/Command/_typeset
index d3304bed0..26eab0b21 100644
--- a/Completion/Zsh/Command/_typeset
+++ b/Completion/Zsh/Command/_typeset
@@ -101,9 +101,9 @@ if [[ "$state" = vars_eq ]]; then
     elif (( $+opt_args[-w] )); then
       _wanted files expl 'zwc file' _files -g '*.zwc(-.)' && ret=0
     elif [[ $service = autoload || -n $opt_args[(i)-[uU]] ]]; then
-      if [[ $PREFIX[1] = [/~] ]]; then
+      if [[ $PREFIX[1] = [$/~] ]] && _files; then
        # Autoload by absolute path
-       _files && ret=0
+       ret=0
       else
          args=(${^fpath}/*(-.:t))
          # Filter out functions already loaded or marked for autoload.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: autoload path completion with expansions
  2021-09-05 18:54 autoload path completion with expansions Bart Schaefer
@ 2021-09-07 23:04 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2021-09-07 23:04 UTC (permalink / raw)
  To: Zsh hackers list

On Sun, Sep 5, 2021 at 11:54 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> +      if [[ $PREFIX[1] = [$/~] ]] && _files; then
>         # Autoload by absolute path

Turns out this doesn't do the right thing when $PREFIX contains a
valid relative directory name (such as "." or ".." among other
things).

Slightly different patch against the original source.

diff --git a/Completion/Zsh/Command/_typeset b/Completion/Zsh/Command/_typeset
index d3304bed0..058842378 100644
--- a/Completion/Zsh/Command/_typeset
+++ b/Completion/Zsh/Command/_typeset
@@ -101,9 +101,9 @@ if [[ "$state" = vars_eq ]]; then
     elif (( $+opt_args[-w] )); then
       _wanted files expl 'zwc file' _files -g '*.zwc(-.)' && ret=0
     elif [[ $service = autoload || -n $opt_args[(i)-[uU]] ]]; then
-      if [[ $PREFIX[1] = [/~] ]]; then
+      if [[ ${"${(e)PREFIX}"[1]} = [/~] ]] && _files; then
        # Autoload by absolute path
-       _files && ret=0
+       ret=0
       else
          args=(${^fpath}/*(-.:t))
          # Filter out functions already loaded or marked for autoload.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-07 23:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-05 18:54 autoload path completion with expansions Bart Schaefer
2021-09-07 23:04 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).