zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: "Zsh hackers list" <zsh-workers@sunsite.dk>
Subject: Re: Bug(?) in builtin r
Date: Fri, 25 Jul 2008 09:52:52 +0100	[thread overview]
Message-ID: <20080725095252.7f9af36d@news01> (raw)
In-Reply-To: <20080724181636.5dd92ddd@news01>

On Thu, 24 Jul 2008 18:16:36 +0100
Peter Stephenson <pws@csr.com> 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 <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


  reply	other threads:[~2008-07-25  8:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-24 14:52 Richard Hartmann
2008-07-24 16:36 ` thomasg
2008-07-24 17:16 ` Peter Stephenson
2008-07-25  8:52   ` Peter Stephenson [this message]
2008-07-27  9:05     ` Richard Hartmann
2008-07-27 17:27       ` Peter Stephenson
2008-07-27 17:41         ` Richard Hartmann

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=20080725095252.7f9af36d@news01 \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).