From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5413 invoked by alias); 18 Jan 2016 02:32:40 -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: 37660 Received: (qmail 4026 invoked from network); 18 Jan 2016 02:32:38 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Date: Mon, 18 Jan 2016 02:25:56 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: Re: "drop-in replacement" and transpose-words-match Message-ID: <20160118022556.GA18047@tarsus.local2> References: <160111233259.ZM6719@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <160111233259.ZM6719@torch.brasslantern.com> User-Agent: Mutt/1.5.23 (2014-03-12) [ Sorry for the late reply, I missed this mail last week. ] Bart Schaefer wrote on Mon, Jan 11, 2016 at 23:32:59 -0800: > Of the eight match-words-by-style functions, transpose-words-match is the > only one that is not really a drop-in, because it adopts the paradigm of > match-words-by-style where a cursor in the middle of a word splits that > word (treating the LBUFFER part as "word before the cursor" and RBUFFER > part as "word after the cursor"). > > There are some useful things about this behavior, e.g., "skip-chars 1" > where you can make "fooXbar" swap as "barXfoo", but there are also some > drawbacks -- cases where transpose-words would do something but -match > does nothing or does something very different. So how about this: if > the skip-chars style is set (even to zero), then keep the cursor where > it is and split the word, otherwise act like the builtin. The subword > flavor of word-style can similarly be checked. > That wouldn't let a user have the skip_chars=0 beahaviour for a wider context and the "act like the builtin" behaviour for a more specific subcontext. (It's not possible to unset for a subcontext a style that's set on a wider context.) How about changing the pattern from «*» to «<->»? Then a setting on a wider context can be hidden for a subcontext by setting the style to '' on the subcontext. Cheers, Daniel > +++ b/Functions/Zle/transpose-words-match > @@ -11,14 +11,23 @@ > +if [[ $WIDGET == transpose-words ]]; then > + # default is to be a drop-in replacement, check styles for change > + zstyle -m $curcontext skip-chars \* || > + zstyle -m $curcontext word-style '*subword*' || > + { [[ $LBUFFER[-1] != [[:space:]] && $RBUFFER[1] != [[:space:]] || > + -z ${RBUFFER//[[:space:]]/} ]] && zle backward-word } > +fi