zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: "Yuri D'Elia" <wavexx@thregr.org>
Cc: zsh workers <zsh-workers@zsh.org>
Subject: Re: bracketed paste
Date: Wed, 15 Jul 2015 20:15:00 +0200	[thread overview]
Message-ID: <CAHYJk3RRx9GgC18Zi_PYwdzyUYJACSChm_7yggQkT+zqMMriSw@mail.gmail.com> (raw)
In-Reply-To: <mo65gp$4im$1@ger.gmane.org>

On Wed, Jul 15, 2015 at 7:33 PM, Yuri D'Elia <wavexx@thregr.org> wrote:
> On 15/07/15 18:51, Yuri D'Elia wrote:
>> I'd like to do the same using the final widget if possible.
>
> To give an example, if you still remember the code I posted earlier:
>
> function _end_paste() {
>   bindkey -e
>   setopt localoptions extendedglob
>   _paste_content=${${_paste_content%%[[:space:]]#}##[[:space:]]#}
>   [[ $_paste_quoted == 1 ]] && LBUFFER+=${(q)_paste_content} || LBUFFER+=$_paste_content
>   unset _paste_content _paste_quoted
> }
>
> And yes, that whitespace trimming looks ugly.
> Is there a better way?

Here's my local .zshrc diff that adapts to the new widget, if that
helps, and yeah, you'll have to wait for 5.0.9.

diff --git a/.zshrc b/.zshrc
index 7fc4091..b972f40 100644
--- a/.zshrc
+++ b/.zshrc
@@ -443,9 +443,7 @@ zle -N _hextochar
 zle -N _chartohex
 zle -N zle-line-init _zle_line_init
 zle -N zle-line-finish _zle_line_finish
-zle -N _start_paste
-zle -N _end_paste
-zle -N paste-insert _paste_insert
+zle -N bracketed-paste _start_paste
 zle -N _spaceafterpastequote
 zle -N self-insert-unmeta-right _self_insert_unmeta_right
 zle -N overwrite-mode _overwrite_mode
@@ -547,13 +545,6 @@ bindkey "^[j"  backward-char
 bindkey "^[k"  forward-char
 bindkey "^[ "  self-insert-unmeta-right

-# Hooks
-bindkey -N paste
-bindkey -R -M paste "^@"-"\M-^?" paste-insert
-bindkey '^[[200~' _start_paste
-bindkey -M paste '^[[201~' _end_paste
-bindkey -M paste -s '^M' '^J'
-
 # Unbind defaults that conflict with keychains
 bindkey -r "^_"

diff --git a/hooks.zsh b/hooks.zsh
index 5916774..d579aa3 100644
--- a/hooks.zsh
+++ b/hooks.zsh
@@ -486,8 +486,6 @@ function _zle_line_init() {
   zle set-local-history -n 1
   function _zle_line_init() {
     zle -N zle-line-pre-redraw _line_redraw
-    # Tell urxvt to send escape codes around a paste
-    [[ $TERM == rxvt-unicode || $TERM = xterm ]] && printf '\e[?2004h'
     bindkey -e
   }
   _zle_line_init
@@ -495,8 +493,6 @@ function _zle_line_init() {

 function _zle_line_finish() {
   [[ $CONTEXT = vared ]] || ZLE_LINE_ABORTED=$BUFFER
-  # Tell it to stop
-  [[ $TERM == rxvt-unicode || $TERM = xterm ]] && printf '\e[?2004l'
 }

 function _recover_line_or_else() {
@@ -510,18 +506,13 @@ function _recover_line_or_else() {
 zle -N up-history _recover_line_or_else

 function _start_paste() {
-  unset _paste_content
-  bindkey -A paste main
-}
-
-function _end_paste() {
-  bindkey -e
+  local content
+  zle .$WIDGET -N content
   if [[ $_SPACE_AFTER_PASTE_QUOTE = 1 ]]; then
-    LBUFFER+=${(q-)_paste_content}' '
+    LBUFFER+=${(q-)content}' '
   else
-    LBUFFER+=$_paste_content
+    LBUFFER+=$content
   fi
-  unset _paste_content
 }

 function _spaceafterpastequote() {
@@ -721,10 +712,6 @@ function _chartohex() {
   (( CURSOR = pos + $#new - 1 ))
 }

-function _paste_insert() {
-  _paste_content+=$KEYS
-}
-

-- 
Mikael Magnusson


  reply	other threads:[~2015-07-15 18:15 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-15 16:51 Yuri D'Elia
2015-07-15 17:33 ` Yuri D'Elia
2015-07-15 18:15   ` Mikael Magnusson [this message]
2015-07-15 18:43     ` Yuri D'Elia
2015-07-16  5:19 ` Oliver Kiddle
2015-07-16 14:32   ` Yuri D'Elia
2015-07-18  2:33     ` Oliver Kiddle
2015-07-18 11:55       ` Yuri D'Elia
2015-07-18 17:17       ` Bart Schaefer
2015-07-18 23:28         ` Oliver Kiddle
2015-07-19  8:13           ` Unmetafy of getsparam() Bart Schaefer
2015-07-21 20:07             ` Peter Stephenson
2015-07-21 23:08               ` Bart Schaefer
2015-07-23  8:50             ` Peter Stephenson
2015-07-16 20:15   ` bracketed paste Bart Schaefer
2015-07-18 12:05     ` Yuri D'Elia
2015-07-18 18:08       ` Bart Schaefer
2015-07-19  2:50         ` PATCH: highlight pasted text Oliver Kiddle
2015-07-19  8:17           ` Bart Schaefer
2015-07-19 12:13           ` Yuri D'Elia
2015-07-19 17:12             ` Daniel Shahaf
2015-07-19 18:10               ` Bart Schaefer
2015-07-21 15:23                 ` Oliver Kiddle
2015-07-21 17:35                   ` Bart Schaefer
2015-07-23  3:57                     ` Oliver Kiddle
2015-07-19 17:57             ` Oliver Kiddle
2015-07-19 18:09               ` Yuri D'Elia
2015-08-08 21:51               ` Daniel Shahaf
2015-08-14  1:38                 ` Oliver Kiddle
2015-08-14  5:28                   ` Bart Schaefer
2015-07-23  5:00           ` Mikael Magnusson
2015-07-23  6:23             ` Oliver Kiddle
2015-07-24  5:06               ` Bart Schaefer
2015-07-24  5:21                 ` Bart Schaefer
2015-07-24 22:22                   ` Oliver Kiddle
2015-07-24 23:13                     ` Bart Schaefer
2015-07-25  7:49                       ` Oliver Kiddle
2015-07-25 16:46                         ` zle options (was Re: PATCH: highlight pasted text) Bart Schaefer
2015-07-28  9:09                           ` Oliver Kiddle
2015-07-24 19:06                 ` Vim special marks - Re: PATCH: highlight pasted text Oliver Kiddle
2015-07-24 19:45                   ` Bart Schaefer
2015-08-11 11:16                   ` Oliver Kiddle
2015-08-13 23:14             ` Daniel Shahaf
2015-08-13 23:50               ` Bart Schaefer
2015-08-14  2:09                 ` Oliver Kiddle
2015-08-14  5:24                   ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2015-11-18 19:57 bracketed paste Yuri D'Elia
2015-11-19  6:05 ` Bart Schaefer
2015-11-19  9:33   ` Yuri D'Elia
2011-11-07 22:31 Oliver Kiddle
2011-11-07 22:42 ` Mikael Magnusson

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=CAHYJk3RRx9GgC18Zi_PYwdzyUYJACSChm_7yggQkT+zqMMriSw@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=wavexx@thregr.org \
    --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).