zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: improved word-context
@ 2008-04-02  9:28 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2008-04-02  9:28 UTC (permalink / raw)
  To: Zsh hackers list

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 <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-02  9:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-02  9:28 PATCH: improved word-context Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).