Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version:content-type;
        bh=L+cPg0rEORNXnsnkLYz0Ul/gmdsdoqnJrnimYqyn7+g=;
        b=XwTEXy/XYvYxQcUTGEN8T0TQ5pd2s85Z2AZwjRQ4S0Z/227+O/QSdBbInegBKuOsVN
         0hnSuSoJQT/bmIR0rT4qerp8evrCdPf7jQr8W7R0N3ATTnSdv13F5vUchtRMbr02OV/T
         dvisHaxqcqSX7Mq0gqAqxKThDASNwA9gSRPr9XqVv8RsPw0lhVBt6GK84Rau23OZTxTd
         TXuvAkj9ulhvBl/Z+MfFmj61sBHgecE5fS5Wig5iXR8BD1Ln9Wfqw2fmuaQSPXyJ6dXf
         qoN4jOQAh2K/WwUw0ks1RMfAEc6podFMmKrzLA7bG5hkIfxjpqwmo1aJLzA+rcfApVtt
         BcGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version:content-type;
        bh=L+cPg0rEORNXnsnkLYz0Ul/gmdsdoqnJrnimYqyn7+g=;
        b=Sox950uSOxa0YsmmSybBj5L+y3iu+qiUXLYT52D8hnVBVW70EaMezqtzMUkQJuWBDL
         pNjLAEp3s9F+2uffvqiOcOlsl3RlnVWS9FkOvAv/IQjQBiEQ4xhuZIyVeg5EpGZNpMFx
         SdmA2VmO/J3UiDzwOiBNeS2n/ZYbDU+SfTg2zs0cH80noKBqnDi2w9ZK2f3/oubFGh29
         NjryB+UQvGqUDWO8YuMul8snQee/JW6XMRhy7W/EnriuzoV77IchFoTC1E1D48Qf8T72
         +jjK7TklUWfQSWMqgvJfCwS1jbMVeQQtEMXJyNFD4sf789frqKRv/17rvdCUOor+YcVj
         1piw==
X-Gm-Message-State: AG10YORVgwFe5mb0Wb1bKU9oZ8Ekcbp4jKl6HHAAEThnWYHt+8/Ol2SD67lU5OzMoOUFCg==
X-Received: by 10.98.40.131 with SMTP id o125mr1862162pfo.83.1453959866599;
        Wed, 27 Jan 2016 21:44:26 -0800 (PST)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160127214510.ZM2878@torch.brasslantern.com>
Date: Wed, 27 Jan 2016 21:45:10 -0800
In-Reply-To: <CAHYJk3TY-JsahHgYWJSe_knx0Xo6D9ecXiTJQ=w+aUTDGHOT8A@mail.gmail.com>
Comments: In reply to Mikael Magnusson <mikachu@gmail.com>
        "Aborted command saved in history" (Jan 28,  2:06am)
References: <CAHYJk3TY-JsahHgYWJSe_knx0Xo6D9ecXiTJQ=w+aUTDGHOT8A@mail.gmail.com>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: Aborted command saved in history
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 37819

On Jan 28,  2:06am, Mikael Magnusson wrote:
}
} If i type
}  {<enter>
} and press ctrl-c, the " {" is saved in my history file without
} consulting zshaddhistory()

zshaddhistory is consulted, it just immediately returns without doing
anything because the error condition from the keyboard interrupt is
still persisting.

I'm a little reluctant to push this down into callhookfunc() because
it may be the right thing in other contexts that an error condition
prevents hooks from running?  Although if that's true we could save
a lot of no-op doshfunc() calls by testing errflag in callhookfunc().

Moved hookargs to the closer scope because why not, and so that the
newlinklist() happens inside queue_signals().

diff --git a/Src/hist.c b/Src/hist.c
index 007366a..7f9e4db 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1378,7 +1378,6 @@ should_ignore_line(Eprog prog)
 mod_export int
 hend(Eprog prog)
 {
-    LinkList hookargs = newlinklist();
     int flag, hookret, stack_pos = histsave_stack_pos;
     /*
      * save:
@@ -1418,9 +1417,17 @@ hend(Eprog prog)
 	DPUTS(hptr < chline, "History end pointer off start of line");
 	*hptr = '\0';
     }
-    addlinknode(hookargs, "zshaddhistory");
-    addlinknode(hookargs, chline);
-    callhookfunc("zshaddhistory", hookargs, 1, &hookret);
+    {
+	LinkList hookargs = newlinklist();
+	int save_errflag = errflag;
+	errflag = 0;
+
+	addlinknode(hookargs, "zshaddhistory");
+	addlinknode(hookargs, chline);
+	callhookfunc("zshaddhistory", hookargs, 1, &hookret);
+
+	errflag |= save_errflag;
+    }
     /* For history sharing, lock history file once for both read and write */
     hf = getsparam("HISTFILE");
     if (isset(SHAREHISTORY) && !lockhistfile(hf, 0)) {

