From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19274 invoked from network); 25 Jul 2008 08:53:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 25 Jul 2008 08:53:11 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 19474 invoked from network); 25 Jul 2008 08:53:07 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 Jul 2008 08:53:07 -0000 Received: (qmail 6277 invoked by alias); 25 Jul 2008 08:53:04 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25338 Received: (qmail 6267 invoked from network); 25 Jul 2008 08:53:04 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 25 Jul 2008 08:53:04 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [208.87.233.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id E13FC80561C5 for ; Fri, 25 Jul 2008 10:52:59 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly12g.srv.mailcontrol.com (MailControl) with ESMTP id m6P8qrCD027606 for ; Fri, 25 Jul 2008 09:52:53 +0100 Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Fri, 25 Jul 2008 09:52:52 +0100 Date: Fri, 25 Jul 2008 09:52:52 +0100 From: Peter Stephenson To: "Zsh hackers list" Subject: Re: Bug(?) in builtin r Message-ID: <20080725095252.7f9af36d@news01> In-Reply-To: <20080724181636.5dd92ddd@news01> References: <2d460de70807240752ge3b0a5qbfa640585c101c35@mail.gmail.com> <20080724181636.5dd92ddd@news01> Organization: CSR X-Mailer: Claws Mail 3.4.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 25 Jul 2008 08:52:52.0872 (UTC) FILETIME=[D2E05880:01C8EE33] X-Scanned-By: MailControl A-08-50-03 (www.mailcontrol.com) on 10.71.0.122 X-Virus-Scanned: ClamAV 0.92.1/7824/Fri Jul 25 03:48:33 2008 on bifrost X-Virus-Status: Clean On Thu, 24 Jul 2008 18:16:36 +0100 Peter Stephenson wrote: > Hmm... repeating the current line and doing something else with it (rather > than just repeating it) is potentially useful. However, in zsh this is > handled recursively, so you quickly get into problems on the stack. ...and also you end up with huge numbers of temporary files that stack up unless the whole sequence exits cleanly, which is possibly worse in the long run. > This disallows the specific case that the range includes the current > history entry and nothing before it, and there's no editor. Otherwise it > either truncates the history so that the current line isn't included, or if > you've specified an editor it lets you edit the current line, too, if you > really want. It's not clear that last bit is actually useful and it might > be better consistently to ignore the current history line here. That's what I'll do. Editing the line with an external editor isn't all that common and if you do it's likely to be better to reduce surprises rather than provide the almost certainly unnecessary current history line. I missed an unlink(fil) last time. Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.197 diff -u -r1.197 builtin.c --- Src/builtin.c 17 Jul 2008 11:27:57 -0000 1.197 +++ Src/builtin.c 25 Jul 2008 08:48:24 -0000 @@ -1446,6 +1446,20 @@ unqueue_signals(); zwarnnam("fc", "can't open temp file: %e", errno); } else { + /* + * Nasty behaviour results if we use the current history + * line here. Treat it as if it doesn't exist, unless + * that gives us an empty range. + */ + if (last >= curhist) { + last = curhist - 1; + if (first > last) { + unqueue_signals(); + zwarnnam("fc", "invalid use of current history line"); + unlink(fil); + return 1; + } + } ops->ind['n'] = 1; /* No line numbers here. */ if (!fclist(out, ops, first, last, asgf, pprog)) { char *editor; -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070