zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: capturing output of !! not working
Date: Sun, 22 Mar 2015 18:35:56 +0000	[thread overview]
Message-ID: <20150322183556.1fa0f143@ntlworld.com> (raw)
In-Reply-To: <150320090420.ZM21908@torch.brasslantern.com>

On Fri, 20 Mar 2015 09:04:20 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> Your patch does not entirely resolve the problem -- this works:
> 
> torch% echo $(!!)
> echo $(echo foo bar)
> foo bar
> 
> But this does not:
> 
> torch% echo foo bar
> foo bar
> torch% echo $( !! )
> echo $( echo foo bar )
> zsh: command not found: !!echo

oh for @*!*!'s sake.

As I've noted in the comment, to get this stuff to work cleanly we need
to capture character-by-character input at a level over the history, but
we don't have one and there are probably too many levels anyway.  So
this will have to do --- it's at least fairly obvious what's going on.

pws

diff --git a/Src/hist.c b/Src/hist.c
index b7ef522..f3ab2b5 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -527,10 +527,20 @@ histsubchar(int c)
     static int marg = -1;
     static zlong mev = -1;
     char *buf, *ptr;
-    char *sline;
+    char *sline, *lexraw_mark;
     Histent ehist;
     size_t buflen;
 
+    /*
+     * If accumulating raw input for use in command substitution,
+     * we don't want the history text, so mark it for later removal.
+     * It would be better to do this at a level above the history
+     * and below the lexer --- but there isn't one.
+     *
+     * Include the character we are attempting to substitute.
+     */
+    lexraw_mark = zshlex_raw_mark(-1); 
+
     /* look, no goto's */
     if (isfirstch && c == hatchar) {
 	int gbal = 0;
@@ -864,6 +874,8 @@ histsubchar(int c)
 	}
     }
 
+    zshlex_raw_back_to_mark(lexraw_mark);
+
     /*
      * Push the expanded value onto the input stack,
      * marking this as a history word for purposes of the alias stack.
diff --git a/Src/lex.c b/Src/lex.c
index 1eb0bc7..6b9e942 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1871,6 +1871,25 @@ zshlex_raw_back(void)
     lexbuf_raw.len--;
 }
 
+/**/
+char *
+zshlex_raw_mark(int offset)
+{
+    if (!lex_add_raw)
+	return NULL;
+    return lexbuf_raw.ptr + offset;
+}
+
+/**/
+void
+zshlex_raw_back_to_mark(char *mark)
+{
+    if (!lex_add_raw)
+	return;
+    lexbuf_raw.len -= lexbuf_raw.ptr - mark;
+    lexbuf_raw.ptr = mark;
+}
+
 /*
  * Skip (...) for command-style substitutions: $(...), <(...), >(...)
  *


  reply	other threads:[~2015-03-22 18:41 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19  1:49 Vin Shelton
2015-03-19  2:28 ` Bart Schaefer
2015-03-19 10:57 ` Peter Stephenson
2015-03-19 12:27   ` Vin Shelton
2015-03-19 12:53     ` Peter Stephenson
2015-03-20 10:57       ` Peter Stephenson
2015-03-20 16:04         ` Bart Schaefer
2015-03-22 18:35           ` Peter Stephenson [this message]
2015-03-22 19:18             ` Peter Stephenson
2015-03-22 23:22             ` Bart Schaefer
2015-03-23 21:34               ` Peter Stephenson
2015-03-24  0:54                 ` Testing interactive features (Re: capturing output of !! not working) Bart Schaefer
2015-03-24  4:12                   ` Bart Schaefer
2015-03-24  4:45                     ` Bart Schaefer
2015-03-24 16:09                       ` Bart Schaefer
2016-05-23 14:53                         ` Mikael Magnusson
2015-03-25 15:48                 ` PATCH: Removing aliases from history, 2015 style (was " Peter Stephenson
2015-03-25 17:57                   ` PATCH: Removing aliases from history, 2015 style Peter Stephenson
2015-03-25 18:42                     ` Mikael Magnusson
2015-03-27 10:06                       ` Peter Stephenson
2015-03-27 15:25                         ` Bart Schaefer
2015-03-27 15:41                           ` Peter Stephenson
2015-03-27 17:17                             ` Bart Schaefer
2015-03-27 17:47                               ` Peter Stephenson
2015-03-29 18:38                         ` Peter Stephenson
2015-03-25 18:58                     ` Bart Schaefer
2015-03-25 19:40                   ` PATCH: Removing aliases from history, 2015 style (was capturing output of !! not working) Bart Schaefer
2015-03-26  3:43                     ` Word breaks around aliased tokens (was Re: PATCH: Removing aliases from history, 2015 style (was capturing output of !! not working)) Bart Schaefer
2015-03-30 18:04                       ` Daniel Shahaf
2015-03-30 20:05                         ` Mikael Magnusson
2015-03-30 18:08                       ` Daniel Shahaf
2015-03-26  9:41                     ` PATCH: Removing aliases from history, 2015 style (was capturing output of !! not working) Peter Stephenson
2015-03-26 15:22                       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150322183556.1fa0f143@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).