From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5539 invoked from network); 2 Apr 2008 09:32:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 2 Apr 2008 09:32:36 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 21119 invoked from network); 2 Apr 2008 09:32:22 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 2 Apr 2008 09:32:22 -0000 Received: (qmail 25741 invoked by alias); 2 Apr 2008 09:32:17 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24781 Received: (qmail 25724 invoked from network); 2 Apr 2008 09:32:16 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 2 Apr 2008 09:32:16 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [85.115.41.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id E449082DC378 for ; Wed, 2 Apr 2008 11:32:12 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly08g.srv.mailcontrol.com (MailControl) with ESMTP id m329TIpN017128 for ; Wed, 2 Apr 2008 10:31:49 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Wed, 2 Apr 2008 10:28:08 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.14.2/8.13.4) with ESMTP id m329S8MR032439 for ; Wed, 2 Apr 2008 10:28:08 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.14.2/8.14.2/Submit) with ESMTP id m329S7uG032436 for ; Wed, 2 Apr 2008 10:28:08 +0100 X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: improved word-context X-Mailer: MH-E 8.0.3; nmh 1.2-20070115cvs; GNU Emacs 22.1.1 Date: Wed, 02 Apr 2008 10:28:07 +0100 Message-ID: <32435.1207128487@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 02 Apr 2008 09:28:08.0883 (UTC) FILETIME=[DD068030:01C894A3] X-Scanned-By: MailControl A-08-00-04 (www.mailcontrol.com) on 10.71.0.118 X-Virus-Scanned: ClamAV 0.91.2/6553/Wed Apr 2 10:18:52 2008 on bifrost X-Virus-Status: Clean I won't commit this before the immediately pending release (which may happen later today), and in fact I'm just sending it so I can back it off to make sure I don't release it. (Actually, I think this is an unambiguous improvement but it's too late to try out properly.) You may or may not have noticed the word-context style which applies to the enhanced context-based ZLE word-handling widgets described in zshcontrib. This is applied when "select-word-style" is in effect. I haven't been using it myself as much as I hoped and I think I've discovered the design flaw. Instead of giving you a special context between words, it should decide based on the widget to be executed whether to use the previous word or the next one, which is the behaviour of the widgets themselves. With this patch it's hard-wired to use the presence of "back" in the context to decide this. Here's an example: if you have autoload -U select-word-style select-word-style whitespace # actual mode irrelevant here zstyle ':zle:*' word-context "*[,=]*" list zstyle ':zle:*kill-*:list' word-style normal zstyle ':zle:*kill-*:list' word-chars '-_.~' it means that when operating on a command argument that contains an "=" you want only a limited set of punctuation characters to be considered part of the word (in particular, not "=", "," or ":", so you can manipulate chunks of the list separately). So if the line looks like make RELEASE=foo,bar,stuff the cursor is at the end, and you execute backward-kill-word, with the new code the cursor is considered to be in a "list" word context, and it will only delete "stuff". With the old code, as you weren't on a word at all, it would delete the entire argument. Index: Doc/Zsh/contrib.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v retrieving revision 1.77 diff -u -r1.77 contrib.yo --- Doc/Zsh/contrib.yo 1 Apr 2008 09:22:30 -0000 1.77 +++ Doc/Zsh/contrib.yo 2 Apr 2008 09:16:08 -0000 @@ -494,9 +494,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. If the cursor is at the end of the line the test is -performed against an empty string; if it is on whitespace between words the -test is made against a single space. Some examples are given below. +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. Here are some examples of use of the styles, actually taken from the simplified interface in tt(select-word-style): Index: Functions/Zle/match-word-context =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Zle/match-word-context,v retrieving revision 1.1 diff -u -r1.1 match-word-context --- Functions/Zle/match-word-context 14 Aug 2006 16:14:41 -0000 1.1 +++ Functions/Zle/match-word-context 2 Apr 2008 09:16:08 -0000 @@ -6,7 +6,7 @@ setopt extendedglob local -a worcon bufwords -local pat tag lastword word +local pat tag lastword word backword forword integer iword zstyle -a $curcontext word-context worcon || return 0 @@ -23,21 +23,18 @@ if [[ $lastword = ${bufwords[iword]} ]]; then # If the word immediately left of the cursor is complete, - # we're not on it. Either we're on unquoted whitespace, or - # the start of a new word. Test the latter. - if [[ -z $RBUFFER ]]; then - # Nothing there, so not in a word. - word='' - elif [[ $RBUFFER[1] = [[:space:]] ]]; then - # Whitespace, so not in a word. - word=' ' - else - # We want the next word along. - word=${bufwords[iword+1]} - fi + # we're not on it for forward operations. + forword=${bufwords[iword+1]} else # We're on a word. - word=${bufwords[iword]} + forword=${bufwords[iword]} +fi +backword=${bufwords[iword]} + +if [[ $curcontext = *back* ]]; then + word=$backword +else + word=$forword fi for pat tag in "${worcon[@]}"; do -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070