From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 359 invoked by alias); 15 Jul 2015 18:15:06 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35796 Received: (qmail 24793 invoked from network); 15 Jul 2015 18:15:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=GkRn8edCDqlMQU1jfVpLo63fe0W5gMR5BypU06pe+lw=; b=BKZmPd3lH6QCX0VN+9sV8MKOE06weUdqMUCOlLhYP//W2n5MNE7vw1+6dTl8XEJ58I Y6t/0/Wku86n9jWAYR2cfl5L3Hkhj4vHWtfLlKsmSNL9TYUu0PJBvwA4MHVvV6yg20i/ WYYlH3P495don0OJ/TUKtC8JIichfaGZ+Txps2EC0KCmxYO2ghTxPfC0zBt+PiRCpGjG a4zQLp8OroTfPEY60jsQmgAzIJTVscrY8Si7Qfxxtv9g3/mgROPrxrdCYVox/pI4yXD6 yl3RPl8Mw0ZeckVqrFi32HOHGdMwLRm4NfYLWAhHnEVBabf+PRrlaxhSiO72wrfMBqW9 erMw== MIME-Version: 1.0 X-Received: by 10.107.15.18 with SMTP id x18mr7392288ioi.167.1436984100651; Wed, 15 Jul 2015 11:15:00 -0700 (PDT) In-Reply-To: References: Date: Wed, 15 Jul 2015 20:15:00 +0200 Message-ID: Subject: Re: bracketed paste From: Mikael Magnusson To: "Yuri D'Elia" Cc: zsh workers Content-Type: text/plain; charset=UTF-8 On Wed, Jul 15, 2015 at 7:33 PM, Yuri D'Elia 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