zsh-users
 help / color / mirror / code / Atom feed
* Quoting the arguments to a function
@ 2016-09-15 21:41 zv
  2016-09-15 22:17 ` Philippe Troin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: zv @ 2016-09-15 21:41 UTC (permalink / raw)
  To: zsh-users

I want to supply the arguments of a function (an alias to Emacs `calc') without expansion, e.g:

	zv@computer# calc 20/2*15
	150


Today of course the result gives "zsh: no matches found: 20*15/2"

Is there any way to signal to ZSH that an alias or fn should have arguments supplied literally?

- Zephyr


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

* Re: Quoting the arguments to a function
  2016-09-15 21:41 Quoting the arguments to a function zv
@ 2016-09-15 22:17 ` Philippe Troin
  2016-09-16  0:09 ` Lawrence Velázquez
  2016-09-16 10:52 ` Vincent Lefevre
  2 siblings, 0 replies; 9+ messages in thread
From: Philippe Troin @ 2016-09-15 22:17 UTC (permalink / raw)
  To: zsh-users

On Thu, 2016-09-15 at 14:41 -0700, zv wrote:
> I want to supply the arguments of a function (an alias to Emacs `calc') without expansion, e.g:
> 
> 	zv@computer# calc 20/2*15
> 	150
> 
> 
> Today of course the result gives "zsh: no matches found: 20*15/2"
> 
> Is there any way to signal to ZSH that an alias or fn should have arguments supplied literally?

Well, not exactly, you can turn off globbing with:
  alias calc='noglob calc'

But that won't work for:
  % calc 0xff&0x80
still would be parsed as:
  % calc 0xff &
  % 0x80

Phil.


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

* Re: Quoting the arguments to a function
  2016-09-15 21:41 Quoting the arguments to a function zv
  2016-09-15 22:17 ` Philippe Troin
@ 2016-09-16  0:09 ` Lawrence Velázquez
  2016-09-16  0:10   ` zv
  2016-09-16 10:52 ` Vincent Lefevre
  2 siblings, 1 reply; 9+ messages in thread
From: Lawrence Velázquez @ 2016-09-16  0:09 UTC (permalink / raw)
  To: zv; +Cc: zsh-users

> On Sep 15, 2016, at 5:41 PM, zv <zv@nxvr.org> wrote:
> 
> I want to supply the arguments of a function (an alias to Emacs `calc') without expansion, e.g:
> 
> 	zv@computer# calc 20/2*15
> 	150
> 
> 
> Today of course the result gives "zsh: no matches found: 20*15/2"

Why can't you just quote the argument?

	% calc '20/2*15'

vq

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

* Re: Quoting the arguments to a function
  2016-09-16  0:09 ` Lawrence Velázquez
@ 2016-09-16  0:10   ` zv
  2016-09-16  0:12     ` Lawrence Velázquez
  0 siblings, 1 reply; 9+ messages in thread
From: zv @ 2016-09-16  0:10 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: zsh-users

Yes, you can do that.


The goal is to not *have* to do that.


On 09/15/2016 05:09 PM, Lawrence Velázquez wrote:
>> On Sep 15, 2016, at 5:41 PM, zv <zv@nxvr.org> wrote:
>>
>> I want to supply the arguments of a function (an alias to Emacs `calc') without expansion, e.g:
>>
>> 	zv@computer# calc 20/2*15
>> 	150
>>
>>
>> Today of course the result gives "zsh: no matches found: 20*15/2"
> Why can't you just quote the argument?
>
> 	% calc '20/2*15'
>
> vq


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

* Re: Quoting the arguments to a function
  2016-09-16  0:10   ` zv
@ 2016-09-16  0:12     ` Lawrence Velázquez
  0 siblings, 0 replies; 9+ messages in thread
From: Lawrence Velázquez @ 2016-09-16  0:12 UTC (permalink / raw)
  To: zv; +Cc: zsh-users

> On Sep 15, 2016, at 8:10 PM, zv <zv@nxvr.org> wrote:
> 
> Yes, you can do that.
> 
> The goal is to not *have* to do that.

I know what the goal is. I asked WHY is that the goal.

vq


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

* Re: Quoting the arguments to a function
  2016-09-15 21:41 Quoting the arguments to a function zv
  2016-09-15 22:17 ` Philippe Troin
  2016-09-16  0:09 ` Lawrence Velázquez
@ 2016-09-16 10:52 ` Vincent Lefevre
  2016-09-16 17:09   ` Bart Schaefer
       [not found]   ` <160916100934.ZM11263__9881.101063411$1474045859$gmane$org@torch.brasslantern.com>
  2 siblings, 2 replies; 9+ messages in thread
From: Vincent Lefevre @ 2016-09-16 10:52 UTC (permalink / raw)
  To: zsh-users

On 2016-09-15 14:41:03 -0700, zv wrote:
> I want to supply the arguments of a function (an alias to Emacs
> `calc') without expansion, e.g:
> 
> 	zv@computer# calc 20/2*15
> 	150
> 
> Today of course the result gives "zsh: no matches found: 20*15/2"
> 
> Is there any way to signal to ZSH that an alias or fn should have
> arguments supplied literally?

IMHO, arguments should also be properly quoted, but the solution
would be a feature in ZLE to do the quoting automatically. Something
like url-quote-magic.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


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

* Re: Quoting the arguments to a function
  2016-09-16 10:52 ` Vincent Lefevre
@ 2016-09-16 17:09   ` Bart Schaefer
       [not found]   ` <160916100934.ZM11263__9881.101063411$1474045859$gmane$org@torch.brasslantern.com>
  1 sibling, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2016-09-16 17:09 UTC (permalink / raw)
  To: zsh-users

On Sep 16, 12:52pm, Vincent Lefevre wrote:
} Subject: Re: Quoting the arguments to a function
}
} On 2016-09-15 14:41:03 -0700, zv wrote:
} > Is there any way to signal to ZSH that an alias or fn should have
} > arguments supplied literally?
} 
} IMHO, arguments should also be properly quoted, but the solution
} would be a feature in ZLE to do the quoting automatically. Something
} like url-quote-magic.

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.

This could probably be done with a special completer supplied by a
zstyle to the incremental-complete-word function.  One difficulty
with that is that incremental-complete-word is itself crufty and
built using years-old functionality; there's probably a much better
way to accomplish the equivalent in modern zsh.

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


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

* Re: Quoting the arguments to a function
       [not found]   ` <160916100934.ZM11263__9881.101063411$1474045859$gmane$org@torch.brasslantern.com>
@ 2016-09-17  6:24     ` Daniel Shahaf
  2016-09-17 14:35       ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Shahaf @ 2016-09-17  6:24 UTC (permalink / raw)
  To: zsh-users

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.


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

* Re: Quoting the arguments to a function
  2016-09-17  6:24     ` Daniel Shahaf
@ 2016-09-17 14:35       ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2016-09-17 14:35 UTC (permalink / raw)
  To: zsh-users

On Sep 17,  6:24am, Daniel Shahaf wrote:
}
} Even without RC_QUOTES, the binding "''" collides with the "'\''"
} sequence for embedding a literal single quote in a single-quoted string.

Yeah, but how often does one type that at a command line, instead of
say "'" (including the doubles)?  I wasn't going for zero possible
clashes, I was going for memorable and quick to type in the necessary
circumstance.


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

end of thread, other threads:[~2016-09-17 14:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-15 21:41 Quoting the arguments to a function zv
2016-09-15 22:17 ` Philippe Troin
2016-09-16  0:09 ` Lawrence Velázquez
2016-09-16  0:10   ` zv
2016-09-16  0:12     ` Lawrence Velázquez
2016-09-16 10:52 ` Vincent Lefevre
2016-09-16 17:09   ` Bart Schaefer
     [not found]   ` <160916100934.ZM11263__9881.101063411$1474045859$gmane$org@torch.brasslantern.com>
2016-09-17  6:24     ` Daniel Shahaf
2016-09-17 14:35       ` 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).