From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4011 invoked by alias); 27 Jul 2016 23:12:15 -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: 38957 Received: (qmail 26960 invoked from network); 27 Jul 2016 23:12:15 -0000 X-Qmail-Scanner-Diagnostics: from nm21-vm9.bullet.mail.ir2.yahoo.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(212.82.97.6):SA:0(0.0/5.0):. Processed in 0.322106 secs); 27 Jul 2016 23:12:15 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM,SPF_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: okiddle@yahoo.co.uk X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.mail.yahoo.com designates 212.82.97.6 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1469660746; bh=8gzHAsGAQp1lMtquMloIaIUm5g/7QbMuTDjnZvmj/a4=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=K08KZ25LlQz2scyi9vDjk/NLE418yj68R7rw9nmTjkI639eSWNFAv9txcxxRItjVbS31pZXr0co2/bDvi0hCZDCcG3CeE1uR9W5e1FQYEikobBIFGzFP9hzaOsUbaAYMKBK27QkGVYpREQ1RohabALl+ikvR5K9J8YaFPRWwCn/8CHrEo3sAGamY4ZRuQTrfjHnXJvXmt54dNcuOcZv0wobba4XLZhh9EdncCh03ul0HvNc/at14NXRHFWzh6glMshJQUZWopepKyrEjLw2v3is5vCCC0OcEokZdc6dKDEGejfoQGIqCCNg/XSgAIV8n/RZFlEls50zJeqJTh6lNeQ== X-Yahoo-Newman-Id: 913567.66111.bm@smtp121.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: _k13EZ0VM1kzyZrmmf7.2KRamiWSlbpdjma3N1jwn17CyaK 9gN2lw2MsmUuoUpPyGBhJ0_Zxis_QL7MXPxOhl_2r0FpUlTdK0VY_OxPdv3U sLzwTtzbVG9Uq7dvIfX_.CVOus_2lJ2zZyi.68Kmtp918uQh70RyzpC5m1gj w1ap4uuHGbR.ln1.uehDeEzbOi.egq2veOPleqxdFYbFNYpgT6h622HuDD2s n4opxhHZBbgAqI47BJEKMWXEmfo0XFIIe9IxhD5Hvyg7xk07kY9gF41LBktl iIz6CQCEHsbGE5xO5obZbdmxAM1wUwfqu7MFqSwlYKVQeAH7AEu4j2mpm4j. banBns19KtofqEeNJP2kJoN0b9USCDi5ruXdCED.lP0TrL6guNk7u0bvTgvj JtvLKEgKN57Y_7xnigt8rqv_lPn4zp0Lda5HariBxU_r_dN0bq3.wpm30pz3 I1per7wUgH0v7Y.7.aRvBzPRln8bfmkwpl4QeJzId4Ie7mbwmQLDEwWyPsK1 SC0122yD2gOOV9PtVAZEpBvlfOzz.7gY7DE9faSmv_6E- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <20160727095421.5c919e22@pwslap01u.europe.root.pri> From: Oliver Kiddle References: <588168129.3340906.1467709726474.JavaMail.yahoo.ref@mail.yahoo.com> <588168129.3340906.1467709726474.JavaMail.yahoo@mail.yahoo.com> <20160705111900.7e1599f0@pwslap01u.europe.root.pri> <5374.1469315162@hydra.kiddle.eu> <20160726145224.7910b718@pwslap01u.europe.root.pri> <57127.1469557325@hydra.kiddle.eu> <20160727095421.5c919e22@pwslap01u.europe.root.pri> To: zsh-workers@zsh.org Subject: Re: bug with camel case and delete-whole-word-match function MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <83726.1469660746.1@hydra.kiddle.eu> Date: Thu, 28 Jul 2016 01:05:46 +0200 Message-ID: <83727.1469660746@hydra.kiddle.eu> Peter wrote: > OK, we need to check that there actually is a word after the cursor, as > we should also do before setting is-word-start. Thanks. That now works nicely. Attached patch adjusts select-word-match to take advantage of this. I've also updated zstyle completion slightly for the word-style and word-class styles. The documentation seems a bit confusing in the way it mixes "normal" and "standard" and there might be an error there. I have adjusted the word-context example for what looks like an error to me. I've also now had a chance to experiment with select-word-match. I had previously used select-bracketed for directory components and lists using i/ a/ i, and a, etc. For things that are essentially list separators, select-word-match works better because it can grab the first and last components of a list and the a forms such as a/ will grab just one surrounding / rather than both. Unfortunately, for the last component of a path, it'll grab the following whitespace rather than the preceding slash but we can perhaps add a style for patterns specifying preferred whitespace. That might have other uses like prefering preceding whitespace over a following newline. Oliver diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index 9a6d618..20ff47f 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -173,6 +173,7 @@ styles=( url-seps e: whence e: word-chars e: + word-class e: word-style e:word-style word-context e: @@ -241,11 +242,13 @@ while (( $#state )); do case "$state[1]" in (contexts) if [[ ! -prefix :*: ]]; then - _wanted contexts expl context compadd -P : -qS : completion vcs_info zftp + _wanted contexts expl context compadd -P : -qS : chpwd completion vcs_info zftp zle elif compset -P :completion:; then contexts=( functions _completers cmdorcont argument tag ) elif compset -P :vcs_info:; then contexts=( vcs-string user-context repo-root-name ) + elif compset -P :zle:; then + _wanted widgets expl widget _widgets -qS : fi if (( $#contexts )); then for ostate in $contexts; do @@ -521,7 +524,7 @@ while (( $#state )); do ;; (word-style) - _wanted word-styles expl 'word style' compadd normal shell space + _wanted word-styles expl 'word style' compadd {normal,specified,unspecified,shell,whitespace}-subword ;; (vcs-string) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 8db7395..00ed080 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2105,7 +2105,7 @@ Here are some examples of use of the tt(word-context) style to extend the context. example(zstyle ':zle:*' word-context \ - "*/*" file "[[:space:]]" whitespace + "*/*" filename "[[:space:]]" whitespace zstyle ':zle:transpose-words:whitespace' word-style shell zstyle ':zle:transpose-words:filename' word-style normal zstyle ':zle:transpose-words:filename' word-chars '') diff --git a/Functions/Zle/select-word-match b/Functions/Zle/select-word-match index 24620c9..8440852 100644 --- a/Functions/Zle/select-word-match +++ b/Functions/Zle/select-word-match @@ -12,7 +12,7 @@ emulate -L zsh setopt extendedglob local curcontext=:zle:$WIDGET -local -a matched_words +local -A matched_words # Start and end of range of characters integer pos1 pos2 num=${NUMERIC:-1} local style word @@ -28,10 +28,10 @@ while (( num-- )); do if (( MARK > CURSOR )); then # if cursor is at the start of the selection, just move back a word match-words-by-style - if [[ $style = i && -n $matched_words[3] ]]; then - word=$matched_words[3] + if [[ $style = i && -n $matched_words[ws-before-cursor] ]]; then + word=$matched_words[ws-before-cursor] else - word=$matched_words[2]$matched_words[3] + word=$matched_words[word-before-cursor]$matched_words[ws-before-cursor] fi if [[ -n $word ]]; then (( CURSOR -= ${#word} )) @@ -43,41 +43,40 @@ while (( num-- )); do (( CURSOR+1 == $#BUFFER )) && return 1 (( CURSOR++ )) match-words-by-style - if [[ -n $matched_words[4] ]]; then + if [[ -n $matched_words[ws-after-cursor] ]]; then if [[ $style = i ]]; then # just skip the whitespace - word=$matched_words[4] + word=$matched_words[ws-after-cursor] else # skip the whitespace plus word - word=$matched_words[4]$matched_words[5] + word=$matched_words[ws-after-cursor]$matched_words[word-after-cursor] fi else if [[ $style = i ]]; then # skip the word - word=$matched_words[5] + word=$matched_words[word-after-cursor] else # skip word and following whitespace - word=$matched_words[5]$matched_words[6] + word=$matched_words[word-after-cursor]$matched_words[ws-after-word] fi fi (( CURSOR += ${#word} - 1 )) else match-words-by-style - if [[ -n "${matched_words[3]}" ]]; then - # There's whitespace before the cursor, so the word we are selecting - # starts at the cursor position. + if (( ${matched_words[is-word-start]} )); then + # The word we are selecting starts at the cursor position. pos1=$CURSOR else # No whitespace before us, so select any wordcharacters there. - pos1="${#matched_words[1]}" + pos1="${#matched_words[start]}" fi - if [[ -n "${matched_words[4]}" ]]; then - if [[ -n "${matched_words[3]}" ]] || (( CURSOR == 0 )); then + if [[ -n "${matched_words[ws-after-cursor]}" ]]; then + if [[ -n "${matched_words[ws-before-cursor]}" ]] || (( CURSOR == 0 )); then # whitespace either side, select it - (( pos1 = CURSOR - ${#matched_words[3]} )) - (( pos2 = CURSOR + ${#matched_words[4]} )) + (( pos1 = CURSOR - ${#matched_words[ws-before-cursor]} )) + (( pos2 = CURSOR + ${#matched_words[ws-after-cursor]} )) else # There's whitespace at the cursor position, so only select # up to the cursor position. @@ -86,28 +85,28 @@ while (( num-- )); do else # No whitespace at the cursor position, so select the # current character and any following wordcharacters. - (( pos2 = CURSOR + ${#matched_words[5]} )) + (( pos2 = CURSOR + ${#matched_words[word-after-cursor]} )) fi if [[ $style = a ]]; then - if [[ -n "${matched_words[4]}" && ( -n "${matched_words[3]}" || CURSOR -eq 0 ) ]]; then + if [[ -n "${matched_words[ws-after-cursor]}" && ( -n "${matched_words[ws-before-cursor]}" || CURSOR -eq 0 ) ]]; then # in the middle of whitespace so grab a word - if [[ -n "${matched_words[5]}" ]]; then - (( pos2 += ${#matched_words[5]} )) # preferably the one after + if [[ -n "${matched_words[word-after-cursor]}" ]]; then + (( pos2 += ${#matched_words[word-after-cursor]} )) # preferably the one after else - (( pos1 -= ${#matched_words[2]} )) # otherwise the one before + (( pos1 -= ${#matched_words[word-before-cursor]} )) # otherwise the one before fi - elif [[ -n "${matched_words[6]}" ]]; then - (( pos2 += ${#matched_words[6]} )) - elif [[ -n "${matched_words[3]}" ]]; then + elif [[ -n "${matched_words[ws-after-word]}" ]]; then + (( pos2 += ${#matched_words[ws-after-word]} )) + elif [[ -n "${matched_words[ws-before-cursor]}" ]]; then # couldn't grab whitespace forwards so try backwards - (( pos1 -= ${#matched_words[3]} )) + (( pos1 -= ${#matched_words[ws-before-cursor]} )) elif (( pos1 > 0 )); then # There might have been whitespace before the word (( CURSOR = pos1 )) match-words-by-style - if [[ -n "${matched_words[3]}" ]]; then - (( pos1 -= ${#matched_words[3]} )) + if [[ -n "${matched_words[ws-before-cursor]}" ]]; then + (( pos1 -= ${#matched_words[ws-before-cursor]} )) fi fi fi