zsh-users
 help / color / mirror / code / Atom feed
* Playing with list-expand + complete-word
@ 2014-07-19  5:22 Silas Silva
  2014-07-20  1:21 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Silas Silva @ 2014-07-19  5:22 UTC (permalink / raw)
  To: zsh-users

Hello all!

I always wanted to change default behaviour of zsh expand and completion
behaviour to something similar to ksh or bash, that is:

    % ls *<tab>

After pressing tab, in expand-or-complete widget would expand * to every
file in current directory.  In ksh it would just print a list of files
that match the glob.

This can be achieved by list-expand widget, but then it looses
completion.  After reading chapter 6 of the zsh user guide and changing
a lot of style, the solution I found was to create a new widget with the
following line:

    zle list-expand || zle complete-word

That is, when it failed to expand the glob, it would them try to
complete the word.

It worked really fine until I realized the problem with variables and
tildes.  So, the following:

    % cd ~/<Tab>

Will not list directories in $HOME, but just give a list ofone item:
/home/username.  The same happens if I change ~ by $HOME variable.

I'd like that it ignored the expansion of tilde and variables if there
was slash.  Any clue?  Or maybe I'm complicating everything and this can
be achieved with standard widgets and some style changing?

Thank you very much.

-- 
Silas Silva


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

* Re: Playing with list-expand + complete-word
  2014-07-19  5:22 Playing with list-expand + complete-word Silas Silva
@ 2014-07-20  1:21 ` Bart Schaefer
  2014-07-20 14:49   ` Silas Silva
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2014-07-20  1:21 UTC (permalink / raw)
  To: zsh-users

On Jul 19,  2:22am, Silas Silva wrote:
}
} I always wanted to change default behaviour of zsh expand and completion
} behaviour to something similar to ksh or bash, that is:
} 
}     % ls *<tab>
} 
} After pressing tab, in expand-or-complete widget would expand * to every
} file in current directory.  In ksh it would just print a list of files
} that match the glob.

Since you've read chapter 6 of the user guide and fiddled with styles,
I presume you have run compinit, and have also bound TAB to complete-word
instead of expand-or-complete?

Whether or not you've run compinit,

    bindkey $'\t' complete-word
    setopt glob_complete

will probably get you very close to the behavior you want.  How it works
out in combination with the zstyle settings you've experimented with, I
can't say.

Equivalently (if you *have* run compinit), you should be able to add
_match to your list of completers, e.g.

    zstyle ':completion:*' completer _complete _match

If glob_complete doesn't seem to be what you want ...

} ... the solution I found was to create a new widget with the
} following line:
} 
}     zle list-expand || zle complete-word
} 
} It worked really fine until I realized the problem with variables and
} tildes.  So, the following:
} 
}     % cd ~/<Tab>
} 
} Will not list directories in $HOME, but just give a list ofone item:
} /home/username.  The same happens if I change ~ by $HOME variable.

What you probably want there is

    zle list-choices || zle list-expand || zle complete-word

However ...

} I'd like that it ignored the expansion of tilde and variables if there
} was slash.  Any clue?

You've just described the behavior of the _expand completer when the
"suffix" zstyle is true (the default).  What's the current value of
your "completer" zstyle?


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

* Re: Playing with list-expand + complete-word
  2014-07-20  1:21 ` Bart Schaefer
@ 2014-07-20 14:49   ` Silas Silva
  2014-07-20 17:02     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Silas Silva @ 2014-07-20 14:49 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Hi there Bart and guys!  Thank you for the answer.  Here we go!

> Whether or not you've run compinit,
> 
>     bindkey $'\t' complete-word
>     setopt glob_complete
> 
> will probably get you very close to the behavior you want.  How it works
> out in combination with the zstyle settings you've experimented with, I
> can't say.
> 
> Equivalently (if you *have* run compinit), you should be able to add
> _match to your list of completers, e.g.
> 
>     zstyle ':completion:*' completer _complete _match
> 
> If glob_complete doesn't seem to be what you want ...

Both setopt glob_complete and using zstyle mechanism have the same
effect.  It is near of what I need, but it still expand the glob to the
first entry of the matching list, instead of listing the glob expansions
(what list-expand would do) and let the original glob intact.

> What you probably want there is
> 
>     zle list-choices || zle list-expand || zle complete-word

It works really great, with the exception that it never completes
(probably complete-word) is never called.  I took your suggestion and
switched them to:

    zle complete-word || zle list-choices || zle list-expand

Which really seems what I want (still testing).  Thank you! :-)

> You've just described the behavior of the _expand completer when the
> "suffix" zstyle is true (the default).  What's the current value of
> your "completer" zstyle?

I also tried setting tab to complete-word and changing zstyle to:

    zstyle ':completion:*' completer _expand _complete

It listed options but still cycled through them (replacing glob, which I
doesn't want).  So I did:

    zstyle ':completion::expand:*' tag-order original -

It didn't replace the glob, but obviously disabled listing.

Creating the new widget that calls different completers seem to be the
best solution for this, but I'm still testing it.

Thank you very much!

-- 
Silas Silva


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

* Re: Playing with list-expand + complete-word
  2014-07-20 14:49   ` Silas Silva
@ 2014-07-20 17:02     ` Bart Schaefer
  2014-07-21 13:40       ` Silas Silva
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2014-07-20 17:02 UTC (permalink / raw)
  To: Silas Silva; +Cc: zsh-users

On Jul 20, 11:49am, Silas Silva wrote:
}
} Both setopt glob_complete and using zstyle mechanism have the same
} effect.  It is near of what I need, but it still expand the glob to the
} first entry of the matching list, instead of listing the glob expansions
} (what list-expand would do) and let the original glob intact.

Yes, I started a second thread about this on zsh-workers as it seems
there are some problems with turning menu completion off.

See what you think of

bindkey $'\t' complete-word
zstyle ':completion:*' completer _complete _match _expand
zstyle ':completion:*:match:*' insert-unambiguous pattern


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

* Re: Playing with list-expand + complete-word
  2014-07-20 17:02     ` Bart Schaefer
@ 2014-07-21 13:40       ` Silas Silva
  2014-07-21 14:38         ` Silas Silva
  0 siblings, 1 reply; 6+ messages in thread
From: Silas Silva @ 2014-07-21 13:40 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

On Sun, Jul 20, 2014 at 10:02:38AM -0700, Bart Schaefer wrote:
> See what you think of
> 
> bindkey $'\t' complete-word
> zstyle ':completion:*' completer _complete _match _expand
> zstyle ':completion:*:match:*' insert-unambiguous pattern

It seems to work really fine and almost exactly what I achieve by
creating a new widget that calls all other widgets.  Thank you!

The only difference is that, if I press tab twice, then glob is replaced
by the first entry, and so on as I press tab again (which is better than
I got) :-)

Is there any advantage on using complete-word and configuring it with
styles than doing what I did? (creating a new widget that calls
list-choices, complete-word and list-expand)?

Your way is more zshish :-)

Thanks again!

-- 
Silas Silva


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

* Re: Playing with list-expand + complete-word
  2014-07-21 13:40       ` Silas Silva
@ 2014-07-21 14:38         ` Silas Silva
  0 siblings, 0 replies; 6+ messages in thread
From: Silas Silva @ 2014-07-21 14:38 UTC (permalink / raw)
  To: Bart Schaefer, zsh-users

On Mon, Jul 21, 2014 at 10:40:40AM -0300, Silas Silva wrote:
> On Sun, Jul 20, 2014 at 10:02:38AM -0700, Bart Schaefer wrote:
> > See what you think of
> > 
> > bindkey $'\t' complete-word
> > zstyle ':completion:*' completer _complete _match _expand
> > zstyle ':completion:*:match:*' insert-unambiguous pattern
> 
(...)
> 
> The only difference is that, if I press tab twice, then glob is replaced
> by the first entry, and so on as I press tab again (which is better than
> I got) :-)
> 
> Is there any advantage on using complete-word and configuring it with
> styles than doing what I did? (creating a new widget that calls
> list-choices, complete-word and list-expand)?

Actually your way is much better, for instance, think in the following
example:

    $ cd /foo/bar/*x*<Tab>

My widget would just print all possible expansions, no matter if entries
are directories or files.  In your way, it sees the context is "cd" and
prints only directories.

I'm going to study styles further and check how can it be improved.

Thank you again! :-)

-- 
Silas Silva


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

end of thread, other threads:[~2014-07-21 14:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-19  5:22 Playing with list-expand + complete-word Silas Silva
2014-07-20  1:21 ` Bart Schaefer
2014-07-20 14:49   ` Silas Silva
2014-07-20 17:02     ` Bart Schaefer
2014-07-21 13:40       ` Silas Silva
2014-07-21 14:38         ` Silas Silva

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).