From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: interactivecomments and preexec
Date: Wed, 24 Jul 2013 15:43:53 +0100 [thread overview]
Message-ID: <20130724154353.0602bc07@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20130722203928.GF9580@chaz.gmail.com>
On Mon, 22 Jul 2013 21:39:28 +0100
Stephane Chazelas <stephane.chazelas@gmail.com> wrote:
> Or, to make it clearer, to reproduce:
>
> zsh -f
>
> setopt histreduceblanks interactivecomments
> : # blah
>
> Press <Up> here.
Finally remembered what I'm doing next...
diff --git a/Src/hist.c b/Src/hist.c
index 561e2ac..5e962e9 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -927,7 +927,8 @@ hbegin(int dohist)
void
histreduceblanks(void)
{
- int i, len, pos, needblank, spacecount = 0;
+ int i, len, pos, needblank, spacecount = 0, trunc_ok;
+ char *lastptr, *ptr;
if (isset(HISTIGNORESPACE))
while (chline[spacecount] == ' ') spacecount++;
@@ -939,6 +940,12 @@ histreduceblanks(void)
if (chline[len] == '\0')
return;
+ /* Remember where the delimited words end */
+ if (chwordpos)
+ lastptr = chline + chwords[chwordpos-1];
+ else
+ lastptr = chline;
+
for (i = 0, pos = spacecount; i < chwordpos; i += 2) {
len = chwords[i+1] - chwords[i];
needblank = (i < chwordpos-2 && chwords[i+2] > chwords[i+1]);
@@ -949,7 +956,25 @@ histreduceblanks(void)
}
pos += len + needblank;
}
- chline[pos] = '\0';
+
+ /*
+ * A terminating comment isn't recorded as a word.
+ * Only truncate the line if just whitespace remains.
+ */
+ trunc_ok = 1;
+ for (ptr = lastptr; *ptr; ptr++) {
+ if (!inblank(*ptr)) {
+ trunc_ok = 0;
+ break;
+ }
+ }
+ if (trunc_ok) {
+ chline[pos] = '\0';
+ } else {
+ ptr = chline + pos;
+ while ((*ptr++ = *lastptr++))
+ ;
+ }
}
/**/
pws
next prev parent reply other threads:[~2013-07-24 14:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-21 19:45 Stephane Chazelas
2013-07-21 20:28 ` Bart Schaefer
2013-07-22 7:00 ` Stephane Chazelas
2013-07-22 9:53 ` Peter Stephenson
2013-07-22 18:30 ` Peter Stephenson
2013-07-22 20:02 ` Peter Stephenson
2013-07-22 20:22 ` Stephane Chazelas
2013-07-22 20:27 ` Stephane Chazelas
2013-07-22 20:30 ` Peter Stephenson
2013-07-22 20:37 ` Stephane Chazelas
2013-07-22 20:39 ` Stephane Chazelas
2013-07-24 14:43 ` Peter Stephenson [this message]
2013-07-22 8:44 ` Stephane Chazelas
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=20130724154353.0602bc07@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@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).