zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: get-line shouldn't set histline
@ 2015-08-12 14:26 Oliver Kiddle
  2015-08-12 14:45 ` Peter Stephenson
  2015-08-12 16:04 ` Bart Schaefer
  0 siblings, 2 replies; 3+ messages in thread
From: Oliver Kiddle @ 2015-08-12 14:26 UTC (permalink / raw)
  To: Zsh workers

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;
 }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: get-line shouldn't set histline
  2015-08-12 14:26 PATCH: get-line shouldn't set histline Oliver Kiddle
@ 2015-08-12 14:45 ` Peter Stephenson
  2015-08-12 16:04 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2015-08-12 14:45 UTC (permalink / raw)
  To: Zsh workers

On Wed, 12 Aug 2015 16:26:47 +0200
Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
> 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.

Yes, I think this is just because the code was copied from the case
where the line is being set when the line editor starts.  In that case
popping the line gives you the history context around where you pushed
it.  get-line seems like it should just grab the string and keep the
current context.  But most of the times I use get-line it doesn't
actually matter, so I can't swear this is always right.

pws


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: get-line shouldn't set histline
  2015-08-12 14:26 PATCH: get-line shouldn't set histline Oliver Kiddle
  2015-08-12 14:45 ` Peter Stephenson
@ 2015-08-12 16:04 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2015-08-12 16:04 UTC (permalink / raw)
  To: Zsh workers

On Aug 12,  4:26pm, Oliver Kiddle wrote:
}
} 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.
}
} Can anyone see how the change might cause a problem for normal
} get-line usage?

I can't think of a way this would cause a problem, but I hardly ever
use get-line.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-12 16:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-12 14:26 PATCH: get-line shouldn't set histline Oliver Kiddle
2015-08-12 14:45 ` Peter Stephenson
2015-08-12 16:04 ` Bart Schaefer

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