zsh-users
 help / color / mirror / code / Atom feed
From: "Nadav Har'El" <nyh@math.technion.ac.il>
To: Vadim Zeitlin <vz-zsh@zeitlins.org>
Cc: zsh-users@zsh.org
Subject: Re: Append cancelled commands to history
Date: Mon, 15 Mar 2010 18:42:37 +0200	[thread overview]
Message-ID: <20100315164237.GA23224@fermat.math.technion.ac.il> (raw)
In-Reply-To: <20090706155337.GB15663@fermat.math.technion.ac.il>

Last year, a discussion started on this list on how to save a partially
typed command to the history when you press the interrupt key - so that
you can return to this command later.

>From ideas of several people, we built the following simple function:

On Mon, Jul 06, 2009, Nadav Har'El wrote about "Re: Append cancelled commands to history":
> # When a line is killed, put it in the history anyway in case we want to
> # return to it
> TRAPINT() {
>         # Store the current buffer in the history.
>         zle && 
>         [[ $HISTNO -eq $HISTCMD ]] && # only if we're not back in the history
>         print -s -r -- $BUFFER
> 
>         # Return the default exit code so zsh aborts the current command.
>         return $1
> }

This runs on interrupt and saves the currently edited ZLE buffer to the
history, but only if we were editing a new command (if I go up the history
and then press interrupt, I see no reason to save the old command again in
my history): 

But now I have a new problem. I want this to also work when editing multi-line
commands, e.g., if I start typing

	for i in *
	do

and then right after the do - without a newline - I press interrupt, I want
to be able to later go up the history to continue editing this command.

I thought this would be simple - just replace the print line with
	print -s -r -- "$PREBUFFER$BUFFER"

to print the full multiline command. But the strange thing is: It appears
that when I kill a multiline zle, zsh already (regardless of my function)
saves all the previous lines except the one now edited (i.e., saves $PREBUFFER)
to the history, so with my function the command is saved twice, once without
the first line, and once with the first line.

Does anyone know why zsh saves interrupted partial multiline commands, but
without their last line? Can this be avoided? And what was the rationale
to save the beginning of a multiline command and not everything - or not
at all for a single line command?

Thanks,
Nadav.


-- 
Nadav Har'El                        |        Monday, Mar 15 2010, 1 Nisan 5770
nyh@math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Always go to other people's funerals,
http://nadav.harel.org.il           |otherwise they won't come to yours.


  reply	other threads:[~2010-03-15 16:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-18 21:50 thomasg
2008-09-19 16:20 ` Simon Ruderich
2009-07-06 15:16   ` Re[2]: " Vadim Zeitlin
2009-07-06 15:43     ` Nadav Har'El
2009-07-06 15:53       ` Nadav Har'El
2010-03-15 16:42         ` Nadav Har'El [this message]
2010-03-20 17:50           ` Bart Schaefer
2010-03-22  8:42             ` Nadav Har'El
2010-03-22 15:07               ` Bart Schaefer
2010-03-24 10:27                 ` Nadav Har'El
2010-03-24 16:19                   ` Bart Schaefer
2010-03-26 20:23                     ` Nadav Har'El
2010-03-27  4:23                       ` Bart Schaefer
2010-04-05 19:36       ` Simon Ruderich
2009-07-07 19:49     ` Simon Ruderich

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=20100315164237.GA23224@fermat.math.technion.ac.il \
    --to=nyh@math.technion.ac.il \
    --cc=vz-zsh@zeitlins.org \
    --cc=zsh-users@zsh.org \
    /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).