From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9660 invoked by alias); 16 Jun 2015 17:18: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: 35492 Received: (qmail 9947 invoked from network); 16 Jun 2015 17:18: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=1434474771; bh=Cp5C7bZ/NasbDMB0dtmJ1TeLE+lh7agmARhwL5AZ6CI=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=uKGPr/LT9LVgBmCdfTapj7OaZSvgo1T2TDmYkZtKq+tEqH/JB3049XHcQMAMxJsqWdn0IPlBwozqvy1vet6h21yMlQ89oM1rWktyM+lEl2xe/OkVuYlPVmG8Al5MqzndZyDCnV1VvWQBUbylcfZqNklEiXbRPoGIghDDm213JeLCSauy+IYt13JAIz3kYyYq3xn0MiS+g4HMnU3WRIMFzErp6DAzuyEjTy9cV9LTtanJ+U297XSJEIRU+8QUfHiH2aRHSUFfyQLAGJAtQGyL+mOQHkidkUGQRe4xjOFhbmZEaPFfsTVHotuPRUuDf64dIU6AXShksEs7KoKpLYuYIA== X-Yahoo-Newman-Id: 737604.32193.bm@smtp113.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 8zUdohkVM1mRRXdP5kJvES1Je90nykRtAWn.yJqgdHrvBt_ 1z2HovqVvSYgr_gTEsOYY9idcLRxqY7B51FfnjpIyl_WagTKiRAAXxoUQAna nf4Jy4UQYhyiGiZVHmxmT5L8pTDJd8.vVak4jymxsiPtsK3a9GtvYll_oZKh DWpYgS1Soznh3r4cW.sbcXudxuwv_IjrGGE3OgBWPCqWycKDz7U3tagXYPxU HiCP7nBPb_Jz8tR_5UKYZEVTWvgOZr1_Ilx5Ixqet6P4himqmk1bYXiw_YbB dQyLdvcFUhSjcV5tsxYzkn72XcZrF4_Nc54IZFavLAccVZrLmQ_.8F2.chrz Iq8c4AMJIlp214xeytFoPN0jTBHtdNo9Dy0RuHPRMu_gWLk.0ErRsWorQI74 w2HV4i.jY5RYpGN7i4ob1BksIsNsA6PLtKef0opIlOCTfxJctZvjVGN7xphH yDfVLsegYqfOcw0bWBJ4l9tkEFmqfhzMC4grVvl0El7GzR7R_05raUADhF_g DS1En2R.o4wjVuSSHfVA_6NsRA0SHMGdJ X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <150615172044.ZM25490@torch.brasslantern.com> From: Oliver Kiddle References: <55677AF5.50709@thequod.de> <27004.1433345491@thecus.kiddle.eu> <3098.1433511607@thecus.kiddle.eu> <7701.1433896116@thecus.kiddle.eu> <150609213830.ZM29868@torch.brasslantern.com> <20634.1434406318@thecus.kiddle.eu> <150615172044.ZM25490@torch.brasslantern.com> 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: <25204.1434474770.1@thecus.kiddle.eu> Date: Tue, 16 Jun 2015 19:12:50 +0200 Message-ID: <25205.1434474770@thecus.kiddle.eu> Bart wrote: > I might have chosen a single two-valued array and require it to either > be empty or to have two values (whether "exactly" or "at least" is less > important) so that it's harder e.g. to accidentally begin bracketed paste > mode and never exit from it. That does sound better. As an array, should the name be lowercase - zle_bracketed_paste? Mikael wrote: > This feature appears to be undocumented? I also think the > documentation for the widget should list the default bindings, as > other widgets do. I didn't list the bindings because they don't correspond to actual keys. It seems more of an implementation detail that may be adapted in future if other terminal emulators do things differently. I'm not especially bothered, however. > It might also be nice if the widget could take a parameter as an > argument to store the text in, rather than insert it into the command > line always. That's a good idea. Makes it quite easy to write a custom widget in terms of the default one. Besides the existing quoting use case, the only other idea that comes to mind is to strip comments out so that scripts can be copied without having to set interactive_comments. This patch goes on top of the previous one rather than replacing it. Thanks for the feedback. Oliver diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 48c973a..e209162 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1642,12 +1642,10 @@ item(tt(ZDOTDIR))( The directory to search for shell startup files (.zshrc, etc), if not tt($HOME). ) -vindex(ZLE_BRACKETED_PASTE_ON) -vindex(ZLE_BRACKETED_PASTE_OFF) +vindex(zle_bracketed_paste) cindex(bracketed paste) cindex(enabling bracketed paste) -xitem(tt(ZLE_BRACKETED_PASTE_ON)) -item(tt(ZLE_BRACKETED_PASTE_OFF))( +item(tt(zle_bracketed_paste))( Many terminal emulators have a feature that allows applications to identify when text is pasted into the terminal rather than being typed normally. For ZLE, this means that special characters such as tabs @@ -1655,10 +1653,10 @@ and newlines can be inserted instead of invoking editor commands. Furthermore, pasted text forms a single undo event and if the region is active, pasted text will replace the region. -These parameters contain the terminal escape sequences for enabling -and disabling the feature. These escape sequences are used to enable -bracketed paste when ZLE is active and disable it at other times. -Unsetting the parameters has the effect of ensuring that bracketed paste +This two-element array contains the terminal escape sequences for +enabling and disabling the feature. These escape sequences are used to +enable bracketed paste when ZLE is active and disable it at other times. +Unsetting the parameter has the effect of ensuring that bracketed paste remains disabled. ) vindex(ZLE_LINE_ABORTED) diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 9066681..30675b4 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2060,7 +2060,12 @@ Beep, unless the tt(BEEP) option is unset. tindex(bracketed-paste) item(tt(bracketed-paste))( This widget is invoked when text is pasted to the terminal emulator. -See also the ZLE_BRACKETED_PASTE_ON parameter. +If a numeric argument is given, shell quoting will be applied to the +pasted text before it is inserted. When called from a widget function, +an argument can be given to specify a variable to which pasted text is +assigned. + +See also the zle_bracketed_paste parameter. ) tindex(vi-cmd-mode) item(tt(vi-cmd-mode) (tt(^X^V)) (unbound) (tt(^[)))( diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 62ed157..7ccfb68 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1119,7 +1119,7 @@ zlecore(void) char * zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) { - char *s, *bracket; + char *s, **bracket; int old_errno = errno; int tmout = getiparam("TMOUT"); @@ -1248,8 +1248,8 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) zlecallhook(init, NULL); - if ((bracket = getsparam("ZLE_BRACKETED_PASTE_ON"))) - fputs(bracket, shout); + if ((bracket = getaparam("zle_bracketed_paste")) && arrlen(bracket) == 2) + fputs(*bracket, shout); zrefresh(); @@ -1260,8 +1260,8 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) "ZLE_VARED_ABORTED" : "ZLE_LINE_ABORTED", zlegetline(NULL, NULL)); - if ((bracket = getsparam("ZLE_BRACKETED_PASTE_OFF"))) - fputs(bracket, shout); + if ((bracket = getaparam("zle_bracketed_paste")) && arrlen(bracket) == 2) + fputs(bracket[1], shout); if (done && !exit_pending && !errflag) zlecallhook(finish, NULL); @@ -2010,6 +2010,8 @@ static struct features module_features = { int setup_(UNUSED(Module m)) { + char **bpaste; + /* Set up editor entry points */ zle_entry_ptr = zle_main_entry; zle_load_state = 1; @@ -2034,8 +2036,10 @@ setup_(UNUSED(Module m)) clwords = (char **) zshcalloc((clwsize = 16) * sizeof(char *)); - setsparam("ZLE_BRACKETED_PASTE_ON", ztrdup("\033[?2004h")); - setsparam("ZLE_BRACKETED_PASTE_OFF", ztrdup("\033[?2004l")); + bpaste = zshcalloc(3*sizeof(char *)); + bpaste[0] = ztrdup("\033[?2004h"); + bpaste[1] = ztrdup("\033[?2004l"); + setaparam("zle_bracketed_paste", bpaste); return 0; } diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index ef9d0a8..c2fb2e7 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -767,19 +767,23 @@ bracketedstring() /**/ int -bracketedpaste(UNUSED(char **args)) +bracketedpaste(char **args) { - int n; - ZLE_STRING_T wpaste; char *pbuf = bracketedstring(); - wpaste = stringaszleline((zmult == 1) ? pbuf : - quotestring(pbuf, NULL, QT_BACKSLASH), 0, &n, NULL, NULL); - zmult = 1; - if (region_active) - killregion(zlenoargs); - doinsert(wpaste, n); - free(pbuf); free(wpaste); + if (*args) { + setsparam(*args, pbuf); + } else { + int n; + ZLE_STRING_T wpaste; + wpaste = stringaszleline((zmult == 1) ? pbuf : + quotestring(pbuf, NULL, QT_BACKSLASH), 0, &n, NULL, NULL); + zmult = 1; + if (region_active) + killregion(zlenoargs); + doinsert(wpaste, n); + free(pbuf); free(wpaste); + } return 0; }