zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: editor subword context tweak
Date: Fri, 30 Oct 2015 16:50:14 +0000	[thread overview]
Message-ID: <20151030165014.0cb4e953@pwslap01u.europe.root.pri> (raw)

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


                 reply	other threads:[~2015-10-30 16:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151030165014.0cb4e953@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).