Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: minor addition to match-words-by-style
- X-seq: zsh-workers 20612
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: minor addition to match-words-by-style
- Date: Thu, 09 Dec 2004 14:41:06 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
This allows options to match-words-by-style; it's useful when writing
your own widgets which need a particular style of word.
Also slightly improved indentation.
Index: Doc/Zsh/contrib.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v
retrieving revision 1.37
diff -u -r1.37 contrib.yo
--- Doc/Zsh/contrib.yo 20 Sep 2004 15:43:34 -0000 1.37
+++ Doc/Zsh/contrib.yo 9 Dec 2004 14:38:48 -0000
@@ -513,6 +513,18 @@
non-word characters following that word (7) the remainder of the line. Any
of the elements may be an empty string; the calling function should test
for this to decide whether it can perform its function.
+
+It is possible to pass options with arguments to tt(match-words-by-style)
+to override the use of styles. The options are:
+startsitem()
+sitem(tt(-w))(var(word-style))
+sitem(tt(-s))(var(skip-chars))
+sitem(tt(-c))(var(word-class))
+sitem(tt(-C))(var(word-chars))
+endsitem()
+
+For example, tt(match-words-by-style -w shell -c 0) may be used to
+extract the command argument around the cursor.
)
tindex(delete-whole-word-match)
item(tt(delete-whole-word-match))(
Index: Functions/Zle/match-words-by-style
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Zle/match-words-by-style,v
retrieving revision 1.2
diff -u -r1.2 match-words-by-style
--- Functions/Zle/match-words-by-style 25 Apr 2003 11:19:10 -0000 1.2
+++ Functions/Zle/match-words-by-style 9 Dec 2004 14:38:48 -0000
@@ -57,12 +57,17 @@
# will appear in <whitespace-after-cursor> if it is whitespace, else in
# <word-after-cursor>. This style is mostly useful for forcing
# transposition to ignore the current character.
-
+#
+# The values of the styles can be overridden by options to the function:
+# -w <word-style>
+# -s <skip-chars>
+# -c <word-class>
+# -C <word-chars>
emulate -L zsh
setopt extendedglob
-local wordstyle spacepat wordpat1 wordpat2 opt charskip
+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
@@ -70,8 +75,32 @@
local curcontext=:zle:match-words-by-style
fi
-zstyle -s $curcontext word-style wordstyle
-zstyle -s $curcontext skip-chars skip
+while getopts "w:s:c:C:" opt; do
+ case $opt in
+ (w)
+ wordstyle=$OPTARG
+ ;;
+
+ (s)
+ skip=$OPTARG
+ ;;
+
+ (c)
+ wordclass=$OPTARG
+ ;;
+
+ (C)
+ wordchars=$OPTARG
+ ;;
+
+ (*)
+ return 1
+ ;;
+ esac
+done
+
+[[ -z $wordstyle ]] && zstyle -s $curcontext word-style wordstyle
+[[ -z $skip ]] && zstyle -s $curcontext skip-chars skip
[[ -z $skip ]] && skip=0
case $wordstyle in
@@ -107,20 +136,24 @@
;;
(*) local wc
# See if there is a character class.
- if zstyle -s $curcontext word-class wc; then
- # Treat as a character class: do minimal quoting.
- wc=${wc//(#m)[\'\"\`\$\(\)\^]/\\$MATCH}
+ wc=$wordclass
+ if [[ -n $wc ]] || zstyle -s $curcontext word-class wc; then
+ # Treat as a character class: do minimal quoting.
+ wc=${wc//(#m)[\'\"\`\$\(\)\^]/\\$MATCH}
else
- # See if there is a local version of $WORDCHARS.
+ # See if there is a local version of $WORDCHARS.
+ wc=$wordchars
+ if [[ -z $wc ]]; then
zstyle -s $curcontext word-chars wc ||
wc=$WORDCHARS
- if [[ $wc = (#b)(?*)-(*) ]]; then
- # We need to bring any `-' to the front to avoid confusing
- # character classes... we get away with `]' since in zsh
- # this isn't a pattern character if it's quoted.
- wc=-$match[1]$match[2]
- fi
- wc="${(q)wc}"
+ fi
+ if [[ $wc = (#b)(?*)-(*) ]]; then
+ # We need to bring any `-' to the front to avoid confusing
+ # character classes... we get away with `]' since in zsh
+ # this isn't a pattern character if it's quoted.
+ wc=-$match[1]$match[2]
+ fi
+ wc="${(q)wc}"
fi
# Quote $wc where necessary, because we don't want those
# characters to be considered as pattern characters later on.
--
Peter Stephenson <pws@xxxxxxx> 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
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author