Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Strange behavior when calling select-a-shell-word multiple times from the same user-defined widget



On Wed, 2021-12-22 at 22:08 +0000, Daniel Shahaf wrote:
> Adding «-N» to both select-a-shell-word calls does the trick.

Thanks, that fixed it! I do still think it's pretty strange, though,
because select-a-shell-word does not normally seem to respond to the
numeric argument in a command like `v3aa` (still only selects one
word).

> While here, you can simplify the function a bit.  For one, you could
> use
> a «repeat» loop — its repeat count is a math expression, so you can
> actually do «repeat "NUMERIC - 1"; do …; done»

Nice, thanks for pointing that out.

>  — but I'm not sure why you
> select-a-shell-word more than once.  Why not just this:
> 
> select-n-shell-word() {
>   CURSOR=0
>   repeat "${NUMERIC:-1} - 1" zle vi-forward-word
>   zle visual-mode
>   zle select-a-shell-word -N
> }

I want to select the nth argument on the command line, taking into
account spaces, so using vi-forward-word is not a good choice. For
example, on the command `echo "these are all one" third` I want
3:select-n-shell-word to select

echo "these are all one"[ third]

not

echo[ "these are all one"] third

> «CURSOR=0» is not equivalent to «zle vi-beginning-of-line» when
> there's
> a literal newline in $BUFFER.  Pick what you prefer.

Oops, thank you for that as well.

I appreciate all the help! It's working perfectly now.


Attachment: signature.asc
Description: This is a digitally signed message part



Messages sorted by: Reverse Date, Date, Thread, Author