about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/Zle/zle_hist.c9
2 files changed, 10 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 31beb268e..fdaea5678 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2021-09-06  Bart Schaefer  <schaefer@zsh.org>
 
+	* unposted (cf. 49202 and 49217): Src/Zle/zle_hist.c: insertlastword
+	ignores blank/missing history entries when repeating
+
 	* 49196: Src/Modules/db_gdbm.c: gdbm keys not present in the
 	database appear unset in tied hashes
 
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index 581ca4979..cfaa70dae 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -683,8 +683,13 @@ insertlastword(char **args)
 	}
 	nwords = countlinknodes(l);
     } else {
-	/* Some stored line. */
-	if (!(he = quietgethist(evhist)) || !he->nwords) {
+	/* Some stored line.  By default, search for a non-empty line. */
+	while ((he = quietgethist(evhist)) && histstep == -1 && !*args) {
+	    if (he->nwords)
+		break;
+	    evhist = addhistnum(evhist, histstep, HIST_FOREIGN);
+	}
+	if (!he || !he->nwords) {
 	    unmetafy_line();
 	    return 1;
 	}