zsh-users
 help / color / mirror / code / Atom feed
* [bug?] How to make _expand behave like the expand-word or list-expand widgets?
@ 2024-04-02  7:12 Marlon Richert
  2024-04-02  7:45 ` Marlon Richert
  0 siblings, 1 reply; 2+ messages in thread
From: Marlon Richert @ 2024-04-02  7:12 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 797 bytes --]

I would expect _expand to behave by default like expand-word or list-expand,
but it doesn't.

For example, given default shell options, if `foo=*`, then expand-word and
list-expand will complete `$foo` to `*` and `$~foo` to the files matched by
`*` as a glob expression.

However, no matter what zstyle options I set, _expand will either complete
both of these to `\*` or both of these to the files globbed by `*`.

By default, I would expect _expand to complete expressions in the same way
as the shell substitutes them when evaluating the command line.

Is there a combination of zstyles that makes _expand complete `$foo` to its
literal value and `$~foo` to the files globbed by its value?

If not, then I would like to see this being added somehow and preferably be
made the default behavior.

[-- Attachment #2: Type: text/html, Size: 2551 bytes --]

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

* Re: [bug?] How to make _expand behave like the expand-word or list-expand widgets?
  2024-04-02  7:12 [bug?] How to make _expand behave like the expand-word or list-expand widgets? Marlon Richert
@ 2024-04-02  7:45 ` Marlon Richert
  0 siblings, 0 replies; 2+ messages in thread
From: Marlon Richert @ 2024-04-02  7:45 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1564 bytes --]

This actually seems to do what I want:

  _expand() {
    local -a expl
    local expansion
    expansion="${(b)$( eval print -r -- $words[CURRENT] )}" 2> /dev/null ||
return 1
    _description expansions expl expansion
    compadd -QU "$expl[@]" -- $expansion
  }

This code can of course cause undesirable side effects when expanding
certain special parameters and command substitutions, but _expand suffers
from this, too.

Is there a way to locally disable special parameters and command
substitutions? Are there any other drawbacks to this approach? Why isn't
_expand doing something like this?


On Tue, Apr 2, 2024 at 10:12 AM Marlon Richert <marlon.richert@gmail.com>
wrote:

> I would expect _expand to behave by default like expand-word or
> list-expand, but it doesn't.
>
> For example, given default shell options, if `foo=*`, then expand-word
> and list-expand will complete `$foo` to `*` and `$~foo` to the files
> matched by `*` as a glob expression.
>
> However, no matter what zstyle options I set, _expand will either
> complete both of these to `\*` or both of these to the files globbed by
> `*`.
>
> By default, I would expect _expand to complete expressions in the same
> way as the shell substitutes them when evaluating the command line.
>
> Is there a combination of zstyles that makes _expand complete `$foo` to
> its literal value and `$~foo` to the files globbed by its value?
>
> If not, then I would like to see this being added somehow and preferably
> be made the default behavior.
>
>

[-- Attachment #2: Type: text/html, Size: 4081 bytes --]

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

end of thread, other threads:[~2024-04-02  7:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02  7:12 [bug?] How to make _expand behave like the expand-word or list-expand widgets? Marlon Richert
2024-04-02  7:45 ` Marlon Richert

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