Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: get-line shouldn't set histline



Using narrow-to-region modified to use undo to take advantage of the
undo limits, I'm finding issues related to the way undo handles separate
history lines. The following is one such case. The get-line widget is
meant to insert the line from the buffer stack into the current line.
Changing histline without setting the line to correspond to the text
stored for the history entry results in undo information that doesn't
make sense.

To put this into context, I've also included the function I have bound
to Ctrl-R below. Note the use of get-line towards the end. I don't
really use get-line directly anymore as narrow-to-region tends to be an
easier way to collect past history lines together in a new line. Can
anyone see how the change might cause a problem for normal get-line
usage?

Oliver

  local left right
  if [[ -n $PREDISPLAY || -z $BUFFER ]]; then
    zle .$WIDGET
  else
    zle .vi-add-next
    while true; do
      (( MARK )) || MARK=CURSOR
      if ((MARK < CURSOR)); then
	left="$LBUFFER[0,MARK-CURSOR-1]"
	right="$RBUFFER"
      else
	left="$LBUFFER"
	right="$BUFFER[MARK+1,-1]"
      fi
      narrow-to-region -p "$left"$'\u25b8' -P $'\u25c0'"$right"
      if [[ $WIDGET = accept-line-and-down-history ]]; then
	LBUFFER+=$'\n'"${(M)${LBUFFER##[^$'\n']#?}##[[:blank:]]#}"
	(( MARK = CURSOR ))
	zle split-undo
	zle get-line
      else
	MARK=-1
	break
      fi
    done
  fi


diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index ffb7ce9..c61b4ef 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -894,10 +894,8 @@ zgetline(UNUSED(char **args))
 	free(s);
 	free(lineadd);
 	clearlist = 1;
-	if (stackhist != -1) {
-	    histline = stackhist;
-	    stackhist = -1;
-	}
+	/* not restoring stackhist as we're inserting into current line */
+	stackhist = -1;
     }
     return 0;
 }



Messages sorted by: Reverse Date, Date, Thread, Author