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

Re: bracketed paste - chopping trailing newlines



Carsten Hey wrote on Fri, Sep 04, 2015 at 01:59:36 +0200:
> An other main paste feature, not running a pasted command without user
> interaction, would be disabled by this (which makes it, for my private
> setup, a good candidate for being activated if needed by some currently
> unused function key).
> 
> Btw., I also think that highlighting is sufficient to alert the user
> that no command is running - that it vanishes if a command runs makes
> this pretty clear for the second time, and the first time the previously
> unseen highlighing should catch the attention of the users and make them
> check what happend.  zle -M ... seems to be a bit too verbose for
> a default behaviour.

I'm attaching a patch and a zshrc that together demonstrate the proposed
behaviour.  To test them, apply the patch, run the resulting 'zsh -f',
and source the script.

I propose to make the _resulting behaviour_ the default in 5.1.1.  However,
before I spend time on rewriting the attached patch entirely in C, I'd
like to ensure we have consensus for making this change.

The behaviour is: (a) pastes are never executed until <Enter> is pressed;
(b) zle_highlight is set; (c) newlines are removed only at <accept-line>.

Cheers,

Daniel
diff --git a/ChangeLog b/ChangeLog
index 7b98bfe..af3a4a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -366,6 +366,7 @@
 
 	* 36125: Src/Zle/zle_hist.c: don't set history context in get-line
 
+	[reverted post-5.1]
 	* 35834 (tweaked): Src/Zle/zle_misc.c: strip a final newline from
 	pasted text: inserting is hard to tell apart from accepting it
 
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index 2d18628..c1005dc 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -787,12 +787,6 @@ bracketedpaste(char **args)
 	    zmult = 1;
 	    if (region_active)
 		killregion(zlenoargs);
-	    /* Chop a final newline if its insertion would be hard to
-	     * distinguish by the user from the line being accepted. */
-	    else if (n > 1 && zlecontext != ZLCON_VARED &&
-		    (zlecs + (insmode ? 0 : n - 1)) >= zlell &&
-		    wpaste[n-1] == ZWC('\n'))
-		n--;
 	    yankcs = yankb = zlecs;
 	    doinsert(wpaste, n);
 	    yanke = zlecs;
accept-line accept-and-hold() {
  if [[ $LASTWIDGET == bracketed-paste ]] && 
     [[ $BUFFER[-1] == $'\n' ]]; then
    zle .backward-delete-char
  fi
  zle .$WIDGET -- "$@"
}
zle -N accept-line
zle -N accept-and-hold

# Maybe do the same for the other accept-* widgets.

(( $+zle_highlight )) || zle_highlight=()
zle_highlight+=( paste:standout )



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