From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27447 invoked by alias); 12 Jan 2016 07:32:47 -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: 37570 Received: (qmail 8980 invoked from network); 12 Jan 2016 07:32:45 -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,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:to:subject:mime-version:content-type; bh=bQDOH2Ivmeaob+rTc9EuMq3UnJIDJIk5KM1OpR13tdY=; b=Wr7rzwlAGsWX2Z8c3qjzw9tpn/8pBj3HxS8ekGi6R0MhZkbAnOJLmWceki3AmqSS5O CKWN3LeIIT6nAyMZrmGDzERz7rNCObitRC6dUCE/zt7WB3WP0pI7+MxhUdMNSddUAdbG ccSKi5C+mTYWWhqlpa3G9Nc+cMZmjIvhMEO0NK0NIoIBtNbcq8lOgVqNXTXWcHJcR00c wRE4Ali3XEEz76eduTJ6R4Jq8w7BL0kH2R4VChoM7f/RLfeAGbQqoyYFMiX7qu8tbWQu f0VHykJryDB0k4sT83uxg/gmHI3e4J/H0pW/Uk1e47LzCH3Y08Z3jG5Wrss1FTEpuu3y HoHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:to:subject:mime-version :content-type; bh=bQDOH2Ivmeaob+rTc9EuMq3UnJIDJIk5KM1OpR13tdY=; b=gnfpuzdEAJveSHnNVqLIGD9UwdDwzwSxwDZNCMsdcjEgsQTwMsiIf/HQx+zvbS96Td pZTh1EtpbVCQub9it0xykruHBRGFS4yWucR+1RbrxKF6iWtE9kErB4vGqKMSE+8LX3ke NsWGTQhScN9wgswl24vaJhFJgVyKT9/+0lrEbxWhlsJA5KGBq3ZXCx17xTwPukjp1T58 MkdflagAPQY2vScJ03G2sMZ7+WHQN3DbwhnExhR/LSkMnCH9NfU1ZqOC7YM/rPZv3nAu 4fvK1q5F9Qaq2qu0qYA9prBkBjpfMTq//GTnJN6gIY7b55pJyMPWf9DfZ367/FFCN/49 bc9w== X-Gm-Message-State: ALoCoQnF+53oB3Ir+mYfFtsYLmlv0FkTWHj9S7obGVy6eQZpvw2RYv8vBxxlDwvbVJ9fSupMry9hFVx0JTeCyek4T/EfrypF2w== X-Received: by 10.66.234.200 with SMTP id ug8mr110623631pac.129.1452583964358; Mon, 11 Jan 2016 23:32:44 -0800 (PST) From: Bart Schaefer Message-Id: <160111233259.ZM6719@torch.brasslantern.com> Date: Mon, 11 Jan 2016 23:32:59 -0800 X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: "drop-in replacement" and transpose-words-match MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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. Also, it looks to me as though transpose-words-match assumes zsh emulation but (unlike e.g. select-word-style) never declares it. Also "skip" is a local in match-words-by-style, it doesn't help to declare it here. This still isn't perfect -- if you are on or immediately after a space in the middle of a quoted string, for example, you'll swap around that space. I haven't decided on the best way to deal with that. But this works much better if you are at the end of a line and invoke transpose: it swaps the two words to the left, like the builtin. diff --git a/Functions/Zle/transpose-words-match b/Functions/Zle/transpose-words-match index c1db310..4d2ac71 100644 --- a/Functions/Zle/transpose-words-match +++ b/Functions/Zle/transpose-words-match @@ -11,14 +11,23 @@ # on X would be turned into `barXfoo' with the cursor still on the X, # regardless of what the character X is. +emulate -L zsh autoload -Uz match-words-by-style -local curcontext=":zle:$WIDGET" skip +local curcontext=":zle:$WIDGET" local -a matched_words integer count=${NUMERIC:-1} neg (( count < 0 )) && (( count = -count, neg = 1 )) +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 + while (( count-- > 0 )); do match-words-by-style