about summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2013-07-24 15:54:55 +0100
committerPeter Stephenson <pws@zsh.org>2013-07-24 15:54:55 +0100
commite282fd8ecb65ef558a5b145f674460476087027a (patch)
tree2c44f977c186fa20b2d32075e5fa9acfcff40900 /Src/hist.c
parent31c5c7bb1101ccafac023c1aac69881f85c03186 (diff)
downloadzsh-e282fd8ecb65ef558a5b145f674460476087027a.tar.gz
zsh-e282fd8ecb65ef558a5b145f674460476087027a.tar.xz
zsh-e282fd8ecb65ef558a5b145f674460476087027a.zip
31750: fix for HISTREDUCEBLANKS option.
Don't truncate line after marked words if there's more
non-white-space text, which is probably comments.
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/Src/hist.c b/Src/hist.c
index 561e2acd5..5e962e92f 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++))
+	    ;
+    }
 }
 
 /**/