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

Re: Quoting the arguments to a function



Bart Schaefer wrote on Fri, Sep 16, 2016 at 10:09:34 -0700:
> The nice thing about url-quote-magic is that it can make all of its
> decisions based solely on examinination of the current word; if the
> beginning of the word looks like "schema:" (for various values of
> schema), then the rest of the word is subject to quoting.
> 
> To do argument quoting based on the command context, one must either
> accept the naive solution of examining only the first word on the
> line, or do more detailed command-line analysis on the level of
> what's done by the completion system.

z-sy-h implements something like this to be able to highlight command
positions throughout $PREBUFFER and $BUFFER.  Specifically, z-sy-h's
parser knows at any point what the last command word was and what are
the $BUFFER start and end offsets of the current shell word.

> It's also pretty easy to create a little widget to quote the current
> word:
> 
> quote-this-word() { zle select-in-blank-word; zle quote-region }
> zle -N quote-this-word
> bindkey \'\' quote-this-word
> 
> (That is, if I type single-quote twice in fairly rapid succession,
> quote the word the cursor is in or follows.  Users of RC_QUOTES may
> want to use two double-quotes or some other combination.)

Even without RC_QUOTES, the binding «''» collides with the «'\''»
sequence for embedding a literal single quote in a single-quoted string.



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