zsh-workers
 help / color / mirror / code / Atom feed
* History expansion surprisingly sets event designator
@ 2017-06-06 15:50 ` Leah Neukirchen
  2017-06-06 16:43   ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Leah Neukirchen @ 2017-06-06 15:50 UTC (permalink / raw)
  To: zsh-workers

Hi,

on #zsh we discovered:

zsh 5.3.1 (x86_64-unknown-linux-gnu)
zsh-5.3.1-0-g06b1b7a    (and zsh-5.3.1-204-g62c4169, via danielsh)
% zsh -f
juno% printf a b c
a%
juno% echo x y z
x y z
juno% echo !printf:2<TAB><DEL>!:3<RET>
c

The first tab expansion will correctly expand to "b", but it changes
the event designator to the printf-line, resulting in !:3 expanding to "c",
while the typed in line "echo !:3" itself would refer to the previous
line, the echo-line, and should result in "z".
(Same for tab-expanding the second history reference.)

Pressing ^U will not reset this, but pressing ^C will.

thx,
-- 
Leah Neukirchen  <leah@vuxu.org>  http://leah.zone


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

* Re: History expansion surprisingly sets event designator
  2017-06-06 15:50 ` History expansion surprisingly sets event designator Leah Neukirchen
@ 2017-06-06 16:43   ` Peter Stephenson
  2017-06-06 16:54     ` Leah Neukirchen
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2017-06-06 16:43 UTC (permalink / raw)
  To: Leah Neukirchen, zsh-workers

On Tue, 6 Jun 2017 17:50:03 +0200
Leah Neukirchen <leah@vuxu.org> wrote:
> Hi,
> 
> on #zsh we discovered:
> 
> zsh 5.3.1 (x86_64-unknown-linux-gnu)
> zsh-5.3.1-0-g06b1b7a    (and zsh-5.3.1-204-g62c4169, via danielsh)
> % zsh -f
> juno% printf a b c
> a%
> juno% echo x y z
> x y z
> juno% echo !printf:2<TAB><DEL>!:3<RET>
> c
>
> The first tab expansion will correctly expand to "b", but it changes
> the event designator to the printf-line, resulting in !:3 expanding to "c",
> while the typed in line "echo !:3" itself would refer to the previous
> line, the echo-line, and should result in "z".
> (Same for tab-expanding the second history reference.)
> 
> Pressing ^U will not reset this, but pressing ^C will.

Yes, that's how it works.  I haven't understood why you think it's a
problem but I presume you're used to some other shell.

If you want to turn this feature off, use CSH_JUNKIE_HISTORY; see the
HISTORY EXPANSION section in the zshexpn manual.  Or use two !!s to
refer to the immediately preceding event.

       By  default, a history reference with no event designator refers to the
       same event as any preceding history reference on that command line;  if
       it  is the only history reference in a command, it refers to the previ‐
       ous command.  However, if the option CSH_JUNKIE_HISTORY  is  set,  then
       every  history  reference  with no event specification always refers to
       the previous command.

pws


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

* Re: History expansion surprisingly sets event designator
  2017-06-06 16:43   ` Peter Stephenson
@ 2017-06-06 16:54     ` Leah Neukirchen
  2017-06-06 17:13       ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Leah Neukirchen @ 2017-06-06 16:54 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

Peter Stephenson <p.stephenson@samsung.com> writes:

> On Tue, 6 Jun 2017 17:50:03 +0200
> Leah Neukirchen <leah@vuxu.org> wrote:
>
>> Hi,
>> 
>> on #zsh we discovered:
>> 
>> zsh 5.3.1 (x86_64-unknown-linux-gnu)
>> zsh-5.3.1-0-g06b1b7a    (and zsh-5.3.1-204-g62c4169, via danielsh)
>> % zsh -f
>> juno% printf a b c
>> a%
>> juno% echo x y z
>> x y z
>> juno% echo !printf:2<TAB><DEL>!:3<RET>
>> c
>>
>> The first tab expansion will correctly expand to "b", but it changes
>> the event designator to the printf-line, resulting in !:3 expanding to "c",
>> while the typed in line "echo !:3" itself would refer to the previous
>> line, the echo-line, and should result in "z".
>> (Same for tab-expanding the second history reference.)
>> 
>> Pressing ^U will not reset this, but pressing ^C will.
>
> Yes, that's how it works.  I haven't understood why you think it's a
> problem but I presume you're used to some other shell.

If my command line is "echo !:3" before pressing RET, it should always
print z, even if I fiddled around with tab expansion during editing.
I think this is quite confusing as-is.

-- 
Leah Neukirchen  <leah@vuxu.org>  http://leah.zone


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

* Re: History expansion surprisingly sets event designator
  2017-06-06 16:54     ` Leah Neukirchen
@ 2017-06-06 17:13       ` Peter Stephenson
  2017-06-06 21:09         ` Leah Neukirchen
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2017-06-06 17:13 UTC (permalink / raw)
  To: Leah Neukirchen, zsh-workers

On Tue, 6 Jun 2017 18:54:57 +0200
Leah Neukirchen <leah@vuxu.org> wrote:
> If my command line is "echo !:3" before pressing RET, it should always
> print z, even if I fiddled around with tab expansion during editing.

I see what you mean.  It's not obvious the default event propagates
from the line editor to the history line substitution performed
on input.

We can restrict the scope easily enough.

pws

diff --git a/Src/hist.c b/Src/hist.c
index 350688d..da5a8b2 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -253,6 +253,7 @@ hist_context_save(struct hist_stack *hs, int toplevel)
     hs->hwend = hwend;
     hs->addtoline = addtoline;
     hs->hlinesz = hlinesz;
+    hs->defev = defev;
     /*
      * We save and restore the command stack with history
      * as it's visible to the user interactively, so if
@@ -296,6 +297,7 @@ hist_context_restore(const struct hist_stack *hs, int toplevel)
     hwend = hs->hwend;
     addtoline = hs->addtoline;
     hlinesz = hs->hlinesz;
+    defev = hs->defev;
     if (cmdstack)
 	zfree(cmdstack, CMDSTACKSZ);
     cmdstack = hs->cstack;
diff --git a/Src/zsh.h b/Src/zsh.h
index 22f73f8..137b2a5 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2918,6 +2918,7 @@ struct hist_stack {
     int histdone;
     int stophist;
     int hlinesz;
+    zlong defev;
     char *hline;
     char *hptr;
     short *chwords;


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

* Re: History expansion surprisingly sets event designator
  2017-06-06 17:13       ` Peter Stephenson
@ 2017-06-06 21:09         ` Leah Neukirchen
  0 siblings, 0 replies; 5+ messages in thread
From: Leah Neukirchen @ 2017-06-06 21:09 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson <p.stephenson@samsung.com> writes:

> On Tue, 6 Jun 2017 18:54:57 +0200
> Leah Neukirchen <leah@vuxu.org> wrote:
>> If my command line is "echo !:3" before pressing RET, it should always
>> print z, even if I fiddled around with tab expansion during editing.
>
> I see what you mean.  It's not obvious the default event propagates
> from the line editor to the history line substitution performed
> on input.
>
> We can restrict the scope easily enough.

This seems to work as I expected it, thank you!

-- 
Leah Neukirchen  <leah@vuxu.org>  http://leah.zone


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

end of thread, other threads:[~2017-06-06 21:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170606161125epcas2p251421009eed052386daeae65f8bfd810@epcas2p2.samsung.com>
2017-06-06 15:50 ` History expansion surprisingly sets event designator Leah Neukirchen
2017-06-06 16:43   ` Peter Stephenson
2017-06-06 16:54     ` Leah Neukirchen
2017-06-06 17:13       ` Peter Stephenson
2017-06-06 21:09         ` Leah Neukirchen

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