From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4689 invoked by alias); 30 Oct 2015 16:50:28 -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: 37027 Received: (qmail 18408 invoked from network); 30 Oct 2015 16:50:26 -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_HDRS_LCASE, T_MANY_HDRS_LCASE autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79c56d0000012ee-d2-56339fcf0e5a Date: Fri, 30 Oct 2015 16:50:14 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: editor subword context tweak Message-id: <20151030165014.0cb4e953@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJLMWRmVeSWpSXmKPExsVy+t/xq7rn5xuHGbxZwG5xsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mu5OPchccEak4kL7FpYGxusCXYycHBICJhI9J46yQdhiEhfu rQezhQSWMkp8uxXYxcgFZM9gkvg9YTEThLONUeLy/2PsIFUsAqoSEz+8ButgEzCUmLppNmMX IweHiIC2RPtHMRBTWEBH4tV0CZAKXgF7iW1TPjKD2PwC+hJX/35igthrLzHzyhlGiBpBiR+T 77GA2MwCWhKbtzWxQtjyEpvXvGWGuE1d4sbd3ewTGAVmIWmZhaRlFpKWBYzMqxhFU0uTC4qT 0nMN9YoTc4tL89L1kvNzNzFCAvDLDsbFx6wOMQpwMCrx8P5IMAoTYk0sK67MPcQowcGsJMLL NNU4TIg3JbGyKrUoP76oNCe1+BCjNAeLkjjv3F3vQ4QE0hNLUrNTUwtSi2CyTBycUg2MCoFr HsyTuiVW8Iw367+e/6sUjX35i86HX3376ONu9g22PO3WYTtN/hWqvjl/Uu3PQUeuSSJuwkEd s2fMfvdagTfSeGfZP6nlX75cfXw+6m5/6zLB47c2cmwOsqw9lmFl+dCsqmQtu7f6UpG+RWGT 91zmtrvyVmZW7+TN2VVse6XWGL/rN39fpsRSnJFoqMVcVJwIAK8EVR48AgAA This introduces a minor tweak to a facility I introduced a while ago that allows you to have different editing behaviour in different parts of the command line based on styles (e.g. word characters are different if it looks like a filename, etc.). I've just discovered I need a way of knowing if I'm between command-line words, which I thought I already had but apparently I don't. If you don't use this, and I doubt anyone else does, I suggest you avert your eyes. pws diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index cb68952..f74f7d7 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2016,9 +2016,10 @@ matched against each var(pattern) in turn until one matches; if it does, the context is extended by a colon and the corresponding var(subcontext). Note that the test is made against the original word on the line, with no stripping of quotes. Special handling is done between words: the current -context is examined and if it contains the string tt(back), the word before -the cursor is considered, else the word after cursor is considered. Some -examples are given below. +context is examined and if it contains the string tt(between) the word +is set to a single space; else if it is contains the string tt(back), +the word before the cursor is considered, else the word after cursor is +considered. Some examples are given below. The style tt(skip-whitespace-first) is only used with the tt(forward-word) widget. If it is set to true, then tt(forward-word) diff --git a/Functions/Zle/match-word-context b/Functions/Zle/match-word-context index 7f11544..0bc7e81 100644 --- a/Functions/Zle/match-word-context +++ b/Functions/Zle/match-word-context @@ -7,7 +7,7 @@ setopt extendedglob local -a worcon bufwords local pat tag lastword word backword forword -integer iword +integer iword between zstyle -a $curcontext word-context worcon || return 0 @@ -25,13 +25,18 @@ if [[ $lastword = ${bufwords[iword]} ]]; then # If the word immediately left of the cursor is complete, # we're not on it for forward operations. forword=${bufwords[iword+1]} + # If, furthermore, we're on whitespace, then we're between words. + # It can't be significant whitespace because the previous word is complete. + [[ $RBUFFER[1] = [[:space:]] ]] && between=1 else # We're on a word. forword=${bufwords[iword]} fi backword=${bufwords[iword]} -if [[ $curcontext = *back* ]]; then +if [[ between -ne 0 && $curcontext = *between* ]]; then + word=' ' +elif [[ $curcontext = *back* ]]; then word=$backword else word=$forword