From: Wayne Davison <wayne@clari.net>
To: Peter Stephenson <pws@ifh.de>
Cc: Zsh hackers list <zsh-workers@math.gatech.edu>
Subject: hist_strip_spaces (was Re: histignoredups done properly)
Date: Mon, 12 Aug 1996 12:17:53 -0700 [thread overview]
Message-ID: <199608121917.MAA03396@bebop.clari.net> (raw)
In-Reply-To: pws's message of Mon, 12 Aug 1996 14:56:14 +0200. <199608121256.OAA02157@hydra.ifh.de>
Peter Stephenson writes:
> This fixes histignoredups so that only lines which are really
> different are stored; insignificant changes in whitespace are not
> treated as differences.
Nice change. I was working on something similar over the weekend: the
removal of insignificant spaces from history lines. Since I think my
change complements your patch, I've based this diff on previously
applying your histignoredups patch.
Since it may be that not everyone will want this, I made it depend on a
new option, HIST_STRIP_SPACES. I haven't modified the documentation yet,
however.
Note that since the histstrip() routine may change curhistent->text, I
had to change the cleanup code that frees chline. The new code has the
additional benefit of being much clearer in what it is trying to do (it
took me a while to figure out what the old code was for).
..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/globals.h
@@ -720,6 +720,7 @@
{"histignoredups", 'h', 0, 0},
{"histignorespace", 'g', 0, 0},
{"histnostore", 0, 0, 0},
+ {"histstripspaces", 0, 0, 0},
{"histverify", 0, 0, 0},
{"hup", 0, 0, OPT_EMULATE|OPT_ZSH},
{"ignorebraces", 'I', 0, OPT_EMULATE|OPT_SH},
Index: Src/hist.c
@@ -648,6 +648,36 @@
return 0;
}
+/**/
+void
+histstrip(Histent he)
+{
+ int i, len;
+ int limit = he->nwords*2;
+ char *str, *s;
+
+ for (i = 0, len = he->nwords-1; i < limit; i += 2)
+ len += he->words[i+1] - he->words[i];
+ if (len == he->words[limit-1])
+ return;
+
+ str = zalloc(len+1);
+
+ for (i = 0, s = str; i < limit; i += 2) {
+ len = he->words[i+1] - he->words[i];
+ memcpy(s, he->text + he->words[i], len);
+ he->words[i] = s - str;
+ he->words[i+1] = he->words[i] + len;
+ s += len;
+ *s++ = ' ';
+ }
+ s[-1] = '\0';
+
+ if (he->text != chline)
+ zsfree(he->text);
+ he->text = str;
+}
+
/* say we're done using the history mechanism */
/**/
@@ -694,7 +724,7 @@
chwordpos -= 2;
he = gethistent(curhist - 1);
if (isset(HISTIGNOREDUPS) && he->text && !histcmp(he))
- save = 2;
+ save = isset(HISTSTRIPSPACES)? 0 : 2;
}
}
if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) {
@@ -737,16 +767,13 @@
memcpy(curhistent->words, chwords,
curhistent->nwords*2*sizeof(short));
}
+ if (isset(HISTSTRIPSPACES))
+ histstrip(curhistent);
} else
remhist();
- if (chline && !curhistent->text)
- zfree(chline, hlinesz);
- if (curhistent->text) {
- char *s = ztrdup(curhistent->text);
-
- zfree(curhistent->text, hlinesz);
- curhistent->text = s;
- }
+ if (curhistent->text == chline)
+ curhistent->text = ztrdup(chline);
+ zfree(chline, hlinesz);
zfree(chwords, chwordlen*sizeof(short));
chline = NULL;
return !(flag & HISTFLAG_NOEXEC || errflag);
Index: Src/zsh.h
@@ -1102,6 +1102,7 @@
HISTIGNOREDUPS,
HISTIGNORESPACE,
HISTNOSTORE,
+ HISTSTRIPSPACES,
HISTVERIFY,
HUP,
IGNOREBRACES,
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
next prev parent reply other threads:[~1996-08-12 19:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-08-12 12:56 histignoredups done properly Peter Stephenson
1996-08-12 19:17 ` Wayne Davison [this message]
1996-08-12 21:13 ` hist_strip_spaces Wayne Davison
1996-08-13 9:22 ` hist_strip_spaces Wayne Davison
1996-08-13 5:48 ` hist_strip_spaces (was Re: histignoredups done properly) Andrej Borsenkow
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=199608121917.MAA03396@bebop.clari.net \
--to=wayne@clari.net \
--cc=pws@ifh.de \
--cc=zsh-workers@math.gatech.edu \
/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).