zsh-workers
 help / color / mirror / code / Atom feed
* Patch to add HIST_REDUCE_BLANKS
@ 1996-11-21 23:02 Wayne Davison
  0 siblings, 0 replies; only message in thread
From: Wayne Davison @ 1996-11-21 23:02 UTC (permalink / raw)
  To: zsh-workers

Here's a more modern version of my patch to remove superfluous blanks
from the history lines (and never any significant blanks, like those
in quotes).  The previous version used the option HIST_STRIP_SPACES,
but I thought that the name HIST_REDUCE_BLANKS would be better so
that what is used in this patch.  This is relative to zsh-3.1.0-test3.

..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/globals.h
@@ -740,6 +740,7 @@
     {"histignoredups", 		'h',  0,    0},
     {"histignorespace", 	'g',  0,    0},
     {"histnostore", 		0,    0,    0},
+    {"histreduceblanks",	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
@@ -636,6 +636,32 @@
     return 0;
 }
 
+/**/
+void
+histreduceblanks(void)
+{
+    int i, len, pos, needblank;
+
+    for (i = 0, len = 0; i < chwordpos; i += 2) {
+	len += chwords[i+1] - chwords[i]
+	     + (i > 0 && chwords[i] > chwords[i-1]);
+    }
+    if (chline[len] == '\0')
+	return;
+
+    for (i = 0, pos = 0; i < chwordpos; i += 2) {
+	len = chwords[i+1] - chwords[i];
+	needblank = (i < chwordpos-2 && chwords[i+2] > chwords[i+1]);
+	if (pos != chwords[i]) {
+	    memcpy(chline + pos, chline + chwords[i], len + needblank);
+	    chwords[i] = pos;
+	    chwords[i+1] = chwords[i] + len;
+	}
+	pos += len + needblank;
+    }
+    chline[pos] = '\0';
+}
+
 /* say we're done using the history mechanism */
 
 /**/
@@ -706,6 +732,9 @@
     curhistent->ftim = 0L;
     curhistent->flags = 0;
     if (save) {
+	/* strip superfluous blanks, if desired */
+	if (isset(HISTREDUCEBLANKS))
+	    histreduceblanks();
 	if (save == 2) {
 	    /* Don't duplicate history entry, but use the current rather than
 	     * the previous one, in case minor changes were made to it.
Index: Src/zsh.h
@@ -1107,6 +1107,7 @@
     HISTIGNOREDUPS,
     HISTIGNORESPACE,
     HISTNOSTORE,
+    HISTREDUCEBLANKS,
     HISTVERIFY,
     HUP,
     IGNOREBRACES,
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-11-21 23:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-21 23:02 Patch to add HIST_REDUCE_BLANKS Wayne Davison

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).