From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20987 invoked by alias); 5 Aug 2013 19:21:26 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17908 Received: (qmail 6434 invoked from network); 5 Aug 2013 19:21:11 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 209.85.212.181 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=2Fr/+ShB24oJYqRzxFeiSLybUXRbG5AuYGDFG2uvzHU=; b=EobzJC/Dx6J1ayM9/LUR1ZF71C2ap4Xmr78YFRZfAbmDfsFM5E1SUYDLWuzs1ikz2m XTo8LMz9oBr21g6JhTLUm4cW2qVlGxeltceMvCnU046iQd/pRsZMRDMz7y2W/0s/lNJG r7yyKo8pp3leyW8DYBVpYsmLd188u+63jeItpy1RWGlXGgcDTHr/uzQKkqrZU6IFE3VW YkbxPNV8p+lhcyOvOIA/051vDWBFuwuZxHiGc2dXB7TSaGrYDvwPlQNmfj6iCTO5gAau uxaLU9J2xgOHyzXXAz/mLUJhRLc0vmmxfZ46kgQntFn7YtVHeXxoWYK6P7WF6289BzkF Ch3Q== X-Gm-Message-State: ALoCoQkDA4I2Pq6FB+t8LBB/qoWdyoRBk5J7sa8SpMLTAho2ONJ6gzisLkXi0HJ9XVfBnvHLfj/h X-Received: by 10.180.109.10 with SMTP id ho10mr4356506wib.14.1375728764010; Mon, 05 Aug 2013 11:52:44 -0700 (PDT) X-ProxyUser-IP: 86.6.30.159 Date: Mon, 5 Aug 2013 19:52:40 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: search through alternative HISTFILE Message-ID: <20130805195240.6c44b90a@pws-pc.ntlworld.com> In-Reply-To: <51FF7904.3030003@ofai.at> References: <51FF7904.3030003@ofai.at> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 05 Aug 2013 12:05:56 +0200 Maarten Grachten wrote: > # Define shell function to be used as widget: > > function accumulated-history-incremental-search-backward () { > fc -p "${HOME}/.accumulated-history" > zle .history-incremental-search-backward > } > > Is there any particular reason why calling fc -p inside the widget does > not affect the history search? It seems this is because reading the new history line doesn't update the record of the history line number in ZLE, so it tries to start from an invalid number. ZLE has its own history line number from the main shell because you can go up or down the history list regardless of what's already been stored. It's initialised when the line editor starts and after that is maintained internally. I think the answer is to check if ZLE is already active when pushing history, popping history or reading a line and if it is then update the internal history line directly to the current line number in the main history code. diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index a1d54dd..756ff11 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1934,6 +1934,13 @@ zle_main_entry(int cmd, va_list ap) break; } + case ZLE_CMD_SET_HIST_LINE: + { + histline = va_arg(ap, zlong); + + break; + } + default: #ifdef DEBUG dputs("Bad command %d in zle_main_entry", cmd); diff --git a/Src/hist.c b/Src/hist.c index 5e962e9..f78c97d 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -76,6 +76,9 @@ mod_export int excs, exlast; * and a temporary history entry is inserted while the user is editing. * If the resulting line was not added to the list, a flag is set so * that curhist will be decremented in hbegin(). + * + * Note curhist is passed to zle on variable length argument list: + * type must match that retrieved in zle_main_entry. */ /**/ @@ -2414,6 +2417,9 @@ readhistfile(char *fn, int err, int readflags) zerr("can't read history file %s", fn); unlockhistfile(fn); + + if (zleactive) + zleentry(ZLE_CMD_SET_HIST_LINE, curhist); } #ifdef HAVE_FCNTL_H @@ -3339,6 +3345,8 @@ pushhiststack(char *hf, zlong hs, zlong shs, int level) } hist_ring = NULL; curhist = histlinect = 0; + if (zleactive) + zleentry(ZLE_CMD_SET_HIST_LINE, curhist); histsiz = hs; savehistsiz = shs; inithist(); /* sets histtab */ @@ -3378,6 +3386,8 @@ pophiststack(void) histtab = h->histtab; hist_ring = h->hist_ring; curhist = h->curhist; + if (zleactive) + zleentry(ZLE_CMD_SET_HIST_LINE, curhist); histlinect = h->histlinect; histsiz = h->histsiz; savehistsiz = h->savehistsiz; diff --git a/Src/zsh.h b/Src/zsh.h index d7b130c..e6f0f65 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2756,7 +2756,8 @@ enum { ZLE_CMD_RESET_PROMPT, ZLE_CMD_REFRESH, ZLE_CMD_SET_KEYMAP, - ZLE_CMD_GET_KEY + ZLE_CMD_GET_KEY, + ZLE_CMD_SET_HIST_LINE }; /***************************************/ -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/