From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26963 invoked by alias); 3 Jun 2015 15:37:51 -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: 35376 Received: (qmail 10529 invoked from network); 3 Jun 2015 15:37:48 -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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1433345492; bh=+zvxtWTBlaTXezQxG4xPNckz0hM1ubhNVynChJHXYsc=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=qMZK8HCWh2c3JyNIdpvzxSpEzublYjlE27xUWpsJv+qdEN/8vGMGWVwncoKSBx/Pc7pn/WqhX8v5QvnVCU3ZV5swSXHxKb9moEeqh8YTpC8hX7mQ0rw1FcTZG3T6Va+YY5vTQXeHNjBG5onCSHlGbrj/HnXpZzfWt54bmRqjgYu4bKv+S/TRv9Q6MD+9p6OH/zcWWTnpdRdQ3GZtApViLLdk/ZcHt1g1CRchSowesydmIQcv2DYYcfstm52ooz/yxxPLwmELJOaKQDe1tjNekVReCbocac2VKKjrP7MsYztktJYz9fL9XqIYSjhJ0MMIocjbIJw6oHSmEtDMT77xiw== X-Yahoo-Newman-Id: 802862.72130.bm@smtp148.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: IJGnie4VM1lGO6xS2OPiAwd_AV6OVLQA3KYsLoS0PDLC44x 21.QyNsncLQaIWutttIp_IGf_PA7U1PApCGwsS7HHOQlAQ3obF5xYuzUr9av Qsj5H.cvF.heEZYgOoxqu7xTDgIuPcNlCOpWNMYEaRDBpBnlEobiOrTowQyx wqUzfeh_yP_njyJkI_cICk2cJZBrpvU9T51z9r1CojPADBRTvYx7Y.cdoqqp IxWltTwGtstPJduQpt0F.i2sfc_aSVZ9IcSdHawfSjEcbzmj4ddGks8h.QQK GESoDX4a_JBcPsVpwlmleEkQRn6_QGFpTyLwyjMds7JwYl4Mhxy8x6oqX9o7 u0onQrORVIRFXs4PWOVBVbD2WLilxIPTu24VdbhVOhe6J9L2jjFKgwSAgDZL 3FS6.H8kUs6qjRzBzljF_UAeydYYK9j9AM0mbq6T0TP2myecUZ4zj4UVsGzS RlLEWGkm_sS5.NTNoupWSVLsczNn3xbt98SNkhlm4rgG9_.t2w23fJTp5Y_5 B9UGiC8GMZEv6biEQwYFtfkO30drNL6eu X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: From: Oliver Kiddle References: <55677AF5.50709@thequod.de> To: zsh-workers@zsh.org Subject: Re: bracketed paste mode in xterm and urxvt MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27003.1433345491.1@thecus.kiddle.eu> Date: Wed, 03 Jun 2015 17:31:31 +0200 Message-ID: <27004.1433345491@thecus.kiddle.eu> [ moved to -workers ] Yuri D'Elia wrote: > On 05/28/2015 10:30 PM, Daniel Hahler wrote: > > Apart from that I think that this (bracketed paste mode) should be > > included in Zsh's and get maintained this way. Then it could also be > > adjusted for vi-mode. > > I do agree that mainlining this would make a lot of sense, even as a > setopt. Or at least provide the keymap/functions needed to enable it. I've been using bracketed paste for a while now and would also agree. The question is in what form to provide it? Note that I posted an alternative mechanism in workers/29898. The patch below is a port of that to C. This doesn't use a keymap which I don't think is any loss as such? Quoting is enabled with a numeric argument. I like the idea of using a Ctrl-X prefix to enable quoting but a small wrapper function can provide for that. With the patch as it stands, which is not meant to be final, users must still manually enable the mode for their terminal with zle-line-init etc (I actually append the strings to PS1/PS2/POSTEDIT). It'd certainly possible to add a setopt option to zsh to automatically output the enable/disable strings for bracketed paste. Testing a few ancient terminals (xterm and dtterm on Solaris 10), they seem to have no ill effect. Perhaps it'd be better to apply some sort of heuristics based on terminfo, however. Any thoughts on this? What behaviour would you want in vi-mode? What about with the region active? Replacing the region might make sense but isn't really what emacs or vim do. Oliver diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index b41661a..6a07212 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -28,6 +28,7 @@ "beginning-of-history", beginningofhistory, 0 "beginning-of-line", beginningofline, 0 "beginning-of-line-hist", beginningoflinehist, 0 +"bracketed-paste", bracketedpaste, ZLE_MENUCMP | ZLE_KEEPSUFFIX "capitalize-word", capitalizeword, 0 "clear-screen", clearscreen, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_NOTCOMMAND "complete-word", completeword, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_ISCOMP diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index c6fae25..6da31f3 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1400,6 +1400,10 @@ default_bindings(void) bindkey(emap, "\30\30", refthingy(t_exchangepointandmark), NULL); bindkey(emap, "\30=", refthingy(t_whatcursorposition), NULL); + /* bracketed paste applicable to all keymaps */ + bindkey(emap, "\33[200~", refthingy(t_bracketedpaste), NULL); + bindkey(vmap, "\33[200~", refthingy(t_bracketedpaste), NULL); + /* emacs mode: ESC sequences, all taken from the meta binding table */ buf[0] = '\33'; buf[2] = 0; diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index 4669ef2..2eec8fa 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -737,6 +737,42 @@ yankpop(UNUSED(char **args)) /**/ int +bracketedpaste(UNUSED(char **args)) +{ + static const char endesc[] = "\e[201~"; + int endpos = 0; + size_t psize = 64; + char *buf, *pbuf = zalloc(psize); + size_t current = 0; + int n, next, timeout; + ZLE_STRING_T wpaste; + + while (endesc[endpos]) { + if ((next = getbyte(1L, &timeout)) == EOF) + break; + if (!endpos || next != endesc[endpos++]) + endpos = (next == *endesc); + if (current + 1 >= psize) + pbuf = zrealloc(pbuf, psize *= 2); + if (imeta(next)) { + pbuf[current++] = Meta; + pbuf[current++] = next ^ 32; + } else if (next == '\r') + pbuf[current++] = '\n'; + else + pbuf[current++] = next; + } + pbuf[current-sizeof(endesc)+1] = '\0'; + buf = zmult == 1 ? pbuf : quotestring(pbuf, NULL, QT_BACKSLASH); + zmult = 1; + wpaste = stringaszleline(buf, 0, &n, NULL, NULL); + doinsert(wpaste, n); + free(pbuf); free(wpaste); + return 0; +} + +/**/ +int overwritemode(UNUSED(char **args)) { insmode ^= 1;