zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: another match-words-by-style fix
Date: Thu, 09 Dec 2004 17:22:01 +0000	[thread overview]
Message-ID: <200412091722.iB9HM2IL009937@news01.csr.com> (raw)

We're heading into too-clever-by-half territory here...

While I was looking at match-words-by-style, I noticed it was
inconsistent if the cursor was inside a quoted word 'like this'.  It
could think the word was "this'", for example.  This fixes it up.

Although potentially being able to look inside an individual word is a
useful feature, it's an unexpected effect if widget is documented as
producing words as the shell sees them.

Index: Functions/Zle/match-words-by-style
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Zle/match-words-by-style,v
retrieving revision 1.3
diff -u -r1.3 match-words-by-style
--- Functions/Zle/match-words-by-style	9 Dec 2004 14:44:47 -0000	1.3
+++ Functions/Zle/match-words-by-style	9 Dec 2004 17:19:02 -0000
@@ -69,13 +69,13 @@
 
 local wordstyle spacepat wordpat1 wordpat2 opt charskip wordchars wordclass
 local match mbegin mend pat1 pat2 word1 word2 ws1 ws2 ws3 skip
-local MATCH MBEGIN MEND
+local nwords MATCH MBEGIN MEND
 
 if [[ -z $curcontext ]]; then
     local curcontext=:zle:match-words-by-style
 fi
 
-while getopts "w:s:c:C:" opt; do
+while getopts "w:s:c:C:tT" opt; do
   case $opt in
     (w)
     wordstyle=$OPTARG
@@ -107,6 +107,7 @@
   (shell) local bufwords
 	  # This splits the line into words as the shell understands them.
 	  bufwords=(${(z)LBUFFER})
+	  nwords=${#bufwords}
 	  # Work around bug: if stripping quotes failed, a bogus
 	  # space is appended.  Not a good test, since this may
 	  # be a quoted space, but it's hard to get right.
@@ -129,6 +130,23 @@
 	    wordpat2="${(q)wordpat2}"
 	  fi
 	  spacepat='[[:space:]]#'
+
+	  # Assume the words are at the top level, i.e. if we are inside
+	  # 'something with spaces' then we need to ignore the embedded
+	  # spaces and consider the whole word.
+	  bufwords=(${(z)BUFFER})
+	  if (( ${#bufwords[$nwords]} > ${#wordpat1} )); then
+	    # Yes, we're in the middle of a shell word.
+	    # Find out what's in front.
+	    eval pat1='${LBUFFER%%(#b)('${wordpat1}')('${spacepat}')}'
+	    # Now everything from ${#pat1}+1 is wordy
+	    wordpat1=${(q)LBUFFER[${#pat1}+1,-1]}
+
+	    # Likewise at the end...
+	    eval pat2='${RBUFFER##(#b)('${charskip}${spacepat}')('\
+${wordpat2}')('${spacepat}')}'
+	    wordpat2=${(q)RBUFFER[1,-1-${#pat2}]}
+	  fi
 	  ;;
   (*space) spacepat='[[:space:]]#'
            wordpat1='[^[:space:]]##'

-- 
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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


             reply	other threads:[~2004-12-09 17:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-09 17:22 Peter Stephenson [this message]
2004-12-09 17:40 ` Peter Stephenson

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=200412091722.iB9HM2IL009937@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).