From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15345 invoked by alias); 19 Jul 2015 02:56:09 -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: 35824 Received: (qmail 13529 invoked from network); 19 Jul 2015 02:56:03 -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_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=1437274235; bh=EJ1Q6yx3MBFzWBICzYJK58O6Z2xA/Ni7rarHlCyvcq0=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=nqm4INZ33PH+uTW0JmkMs8IgOPdtLToiLzXHvqWsijYpW3flS18udZTy6ypu7pr57kzEZyzJsinfmaWsAMQySNtLXusLEfB3Pk6xAtaOI1R49ciiS/4NUqiwU6LJfgSc/SnL7IjEU9wOqkipW/Mzzq/tW7XPVw1wuO+POPLMlH2hGHpPFabmikxLCoKY4pzBVXCNALYvaJV/woEghuunzIi1zQqciz6Fr5UiUEwNgwBq7TNFsQDfJdBZTRMzJru1dkcC7PNnfCJ+PiXc/cTivfzWKmrynGyvHk0X136TQsZMYAFp6+YGqTZUdgHbYZqzfDmykrfMVcW45AoCKaWgZg== X-Yahoo-Newman-Id: 454929.79076.bm@smtp105.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: JeMRDuMVM1ksk_Yv30HG7s2_r8hD2yg7jxlQO8rg5j4QHDF qMg.NyQsAitgRVnVlsdeS1cguQLpNzA5mVBykszCnyFDcrftMNOib.mSGfH3 7L_k.j0Tnbcxtu.bP4dcnsNvoIVjt1t9iWFO_7WnJCMH_0HcCS7MNf2YuacM o0RvelWrdF4awzpAV1d352k3NmSqnJ2Inf9I6yYb7y4Cuk5I7GryBxaLnhpe AQjifh6GsoEbvuSnN9uYKEJ8Exn0h1WoEzjgqzKLy3GylIudr2qLXxRZiAeE SLzwLFl5O2G6l3d9_15zfti_8iQ1NjaXcZL8MtlDc1.EerHdEvzJEYa2EH15 7kzUq4mr5NOLAS.bNyfa6kS.8psUdljXc7oe4rIPliXbLCRKtqwziugwbrbV g2ZT2QK_ih7ivi4h7OXa8jbzv0.p6fwIApnyh0M_jH7dwK9ELNjAw69Nio4B NfYtHkP0tIG6rUpj7j5hthlnRJXvM8Ud5IHWs283x.e2W_0HNIppVs31Kyvb AHy_Z_eYQ0iCLsshoNVIUmJqOPrmcPw-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <150718110859.ZM4405@torch.brasslantern.com> From: Oliver Kiddle References: <7277.1437023995@thecus.kiddle.eu> <150716131504.ZM18155@torch.brasslantern.com> <150718110859.ZM4405@torch.brasslantern.com> To: zsh-workers@zsh.org Subject: PATCH: highlight pasted text MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19087.1437274234.1@thecus.kiddle.eu> Date: Sun, 19 Jul 2015 04:50:34 +0200 Message-ID: <19088.1437274234@thecus.kiddle.eu> Bart wrote: > There are a couple of features that might be useful if we could come up > with a way to do them. One would be an indication of whether bracketed > paste is supported at all, so that no one is taken by surprise when the That's not possible as far as I know. If it was possible to detect that, we'd be able to make the sending of the start/end strings conditional. > shell starts executing what they pasted. Another is some indication of > what text was pasted (maybe highlight-color it differently?). How about the following patch? This adds another special token to zle_highlight. So you can do, e.g: zle_highlight+=( paste:bg=87 ) This applies also for vi put and emacs yank commands. We were already tracking start/end positions of a paste for the purposes of the yank-pop widget. Using those, leads to some further changes: Text from a bracketed paste is now added to the cutbuffer. As far as I can tell, this seems to actually also be what the GUI mode of emacs does. Though emacs is perhaps not putting duplicates in. It'd be good if some actual emacs users could check that it all makes sense, however. I had been pondering how to interface bracketed-paste with vi registers, anyway. This will now also put the bracketed paste in the numbered registers. If you explicitly name a vi register, the pasted text is now NOT inserted: it is only assigned to the register. This seems quite useful if not the most vim compatible. For a middle-mouse click after naming a register, gvim will paste the named register at the position under the mouse. Oliver diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index da8ee47..ef73f4d 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2510,6 +2510,9 @@ a directory name. Note that suffix removal is configurable; the circumstances under which the suffix will be removed may differ for different completions. ) +item(tt(paste))( +Following a command to paste text, the characters that were inserted. +) enditem() tt(zle_highlight) may contain additional fields for controlling how diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index 6a07212..ebcf317 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -28,7 +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 +"bracketed-paste", bracketedpaste, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_YANKBEFORE "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.h b/Src/Zle/zle.h index ab2428e..59f4591 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -429,8 +429,9 @@ struct region_highlight { * 0: region between point and mark * 1: isearch region * 2: suffix + * 3: pasted text */ -#define N_SPECIAL_HIGHLIGHTS (3) +#define N_SPECIAL_HIGHLIGHTS (4) #ifdef MULTIBYTE_SUPPORT diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index d350688..b040b97 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -517,10 +517,12 @@ copyregionaskill(char **args) /* * kct: index into kill ring, or -1 for original cutbuffer of yank. - * yankb, yanke: mark the start and end of last yank in editing buffer. * yankcs marks the cursor position preceding the last yank */ -static int kct, yankb, yanke, yankcs; +static int kct, yankcs; + +/**/ +int yankb, yanke; /* mark the start and end of last yank in editing buffer. */ /* The original cutbuffer, either cutbuf or one of the vi buffers. */ static Cutbuffer kctbuf; @@ -778,10 +780,17 @@ bracketedpaste(char **args) 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); + cuttext(wpaste, n, CUT_REPLACE); + if (!(zmod.flags & MOD_VIBUF)) { + kct = -1; + kctbuf = &cutbuf; + zmult = 1; + if (region_active) + killregion(zlenoargs); + yankcs = yankb = zlecs; + doinsert(wpaste, n); + yanke = zlecs; + } free(pbuf); free(wpaste); } return 0; diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c index fe33799..5b3b89b 100644 --- a/Src/Zle/zle_refresh.c +++ b/Src/Zle/zle_refresh.c @@ -318,6 +318,7 @@ zle_set_highlight(void) int region_atr_on_set = 0; int isearch_atr_on_set = 0; int suffix_atr_on_set = 0; + int paste_atr_on_set = 0; struct region_highlight *rhp; special_atr_on = default_atr_on = 0; @@ -337,7 +338,8 @@ zle_set_highlight(void) for (; *atrs; atrs++) { if (!strcmp(*atrs, "none")) { /* reset attributes for consistency... usually unnecessary */ - special_atr_on = default_atr_on = 0; + special_atr_on = default_atr_on = + paste_atr_on_set = 0; special_atr_on_set = region_atr_on_set = isearch_atr_on_set = suffix_atr_on_set = 1; } else if (strpfx("default:", *atrs)) { @@ -354,6 +356,9 @@ zle_set_highlight(void) } else if (strpfx("suffix:", *atrs)) { match_highlight(*atrs + 7, &(region_highlights[2].atr)); suffix_atr_on_set = 1; + } else if (strpfx("paste:", *atrs)) { + match_highlight(*atrs + 6, &(region_highlights[3].atr)); + paste_atr_on_set = 1; } } } @@ -367,6 +372,7 @@ zle_set_highlight(void) region_highlights[1].atr = TXTUNDERLINE; if (!suffix_atr_on_set) region_highlights[2].atr = TXTBOLDFACE; + /* paste defaults to 0 */ allocate_colour_buffer(); } @@ -1073,6 +1079,14 @@ zrefresh(void) region_highlights[2].start = region_highlights[2].end = -1; } + if (lastcmd & ZLE_YANK) { + region_highlights[3].start = yankb; + region_highlights[3].end = yanke; + } else { + region_highlights[3].start = region_highlights[3].end = -1; + } + + if (clearlist && listshown > 0) { if (tccan(TCCLEAREOD)) { int ovln = vln, ovcs = vcs;