Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: transpose-words-match (Re: New widget "transpose-segments")

On Jan 11,  2:13pm, Sebastian Gniazdowski wrote:
} Bart there already is "copy-prev-shell-word". It's good to not be
} bound to global select-word-style setting.

Just for the record, although there is a global select-word-style
setting for convenience, you can also select different word styles
for different contexts.  There are a few examples in the manual.

The word styles can also handle things like swapping CapsLikeThis
to CapsThisLike where the only "word break" is a case difference.

Further, copy-prev-shell-word is a built-in widget; and it appears to
have a bug when the previous shell word is a single character with no
whitespace between it and the cursor.  (The transpose-words builtin
has a similar difficulty with one-character words, I think.)

} That said I tested your bksw and it doesn't fully work for following
} There is a space after "". When cursor is positioned after this space,
} invoking bksw joins lines "" and a\ b instead of deleting "".

select-in-shell-word is intended to emulate some vim functionality that
excludes quotes (only selects what's inside them) so empty quotes might
be expected to confuse it.

I have to thank you for this example, because it allowed me to realize
why newlines confuse match-words-by-style.  It needs to be using the
(Z:n:) flag rather than the (z) flag; the latter converts newlines into
semicolons, but this wants newlines as whitespace.

I see Daniel has also done something for interactive_comments, I'm not
sure whether that's needed in match-words-by-style.  [By the way, Daniel,
(zZ:c:) is redundant, you only need (Z:c:).]

diff --git a/Functions/Zle/match-words-by-style b/Functions/Zle/match-words-by-style
index b387828..7ba6157 100644
--- a/Functions/Zle/match-words-by-style
+++ b/Functions/Zle/match-words-by-style
@@ -111,20 +111,20 @@ done
 case $wordstyle in
   (*shell*) local bufwords
 	  # This splits the line into words as the shell understands them.
-	  bufwords=(${(z)LBUFFER})
+	  bufwords=(${(Z:n:)LBUFFER})
 	  # Take substring of RBUFFER to skip over $skip characters
 	  # from the cursor position.
-	  bufwords=(${(z)RBUFFER[1+$skip,-1]})
+	  bufwords=(${(Z:n:)RBUFFER[1+$skip,-1]})
 	  # 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})
+	  bufwords=(${(Z:n:)BUFFER})
 	  if (( ${#bufwords[$nwords]} > ${#wordpat1} )); then
 	    # Yes, we're in the middle of a shell word.
 	    # Find out what's in front.

Messages sorted by: Reverse Date, Date, Thread, Author