From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20415 invoked by alias); 22 Mar 2015 18:41:38 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34758 Received: (qmail 1595 invoked from network); 22 Mar 2015 18:41:34 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=UrbtNoAB c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=q2GGsy2AAAAA:8 a=qc8UA4YsHfYqhItYX0wA:9 a=CjuIK1q_8ugA:10 Date: Sun, 22 Mar 2015 18:35:56 +0000 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: capturing output of !! not working Message-ID: <20150322183556.1fa0f143@ntlworld.com> In-Reply-To: <150320090420.ZM21908@torch.brasslantern.com> References: <20150319105716.620cd931@pwslap01u.europe.root.pri> <20150319125351.1e270c2d@pwslap01u.europe.root.pri> <20150320105703.2754b6af@pwslap01u.europe.root.pri> <150320090420.ZM21908@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 20 Mar 2015 09:04:20 -0700 Bart Schaefer 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: $(...), <(...), >(...) *