zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: get-line shouldn't set histline
Date: Wed, 12 Aug 2015 16:26:47 +0200	[thread overview]
Message-ID: <3787.1439389607@thecus.kiddle.eu> (raw)

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


             reply	other threads:[~2015-08-12 14:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-12 14:26 Oliver Kiddle [this message]
2015-08-12 14:45 ` Peter Stephenson
2015-08-12 16:04 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3787.1439389607@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).