* PATCH: bash-transpose-words
@ 2001-07-20 10:49 Peter Stephenson
2001-07-20 18:08 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2001-07-20 10:49 UTC (permalink / raw)
To: Zsh hackers list
This one I definitely plan to use, I've been frustrated by the other one
too often.
Now what I'd really like is for the cursor to stay at the point between the
words it's transposing instead of hopping around after it, but that
requires either doing the whole thing in a shell function, or some trickery
with marks --- which I still don't trust if text has been moving around,
but I haven't analysed what I don't trust well enough to suggest what needs
fixing.
Index: Doc/Zsh/contrib.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v
retrieving revision 1.11
diff -u -r1.11 contrib.yo
--- Doc/Zsh/contrib.yo 2001/07/06 17:25:54 1.11
+++ Doc/Zsh/contrib.yo 2001/07/20 10:45:27
@@ -366,15 +366,17 @@
tindex(bash-backward-word)
tindex(bash-kill-word)
tindex(bash-backward-kill-word)
+tindex(bash-transpowse-words)
xitem(tt(bash-forward-word), tt(bash-backward-word))
-item(tt(bash-kill-word), tt(bash-backward-kill-word))(
+xitem(tt(bash-kill-word), tt(bash-backward-kill-word))
+item(tt(bash-transpose-words))(
These work similarly to the corresponding builtin zle functions without the
`tt(bash-)' prefix, but a word is considered to consist of alphanumeric
characters only. If you wish to replace your existing bindings with these
four widgets, the following is sufficient:
example(for widget in kill-word backward-kill-word \
-forward-word backward-word; do
+forward-word backward-word transpose-words; do
autoload bash-$widget
zle -N $widget bash-$widget
done)
Index: Functions/Zle/bash-transpose-words
===================================================================
RCS file: bash-transpose-words
diff -N bash-transpose-words
--- /dev/null Thu May 24 22:33:05 2001
+++ bash-transpose-words Fri Jul 20 03:45:27 2001
@@ -0,0 +1,9 @@
+# This implements a bash-style transpose-words.
+# To use,
+# zle -N bash-transpose-words
+# bindkey '...' bash-transpose-words
+# or if you wish to replace existing transpose-words bindings,
+# zle -N transpose-words bash-transpose-words
+
+local WORDCHARS=''
+zle .transpose-words
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PATCH: bash-transpose-words
2001-07-20 10:49 PATCH: bash-transpose-words Peter Stephenson
@ 2001-07-20 18:08 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2001-07-20 18:08 UTC (permalink / raw)
To: Peter Stephenson, Zsh hackers list
On Jul 20, 11:49am, Peter Stephenson wrote:
}
} Now what I'd really like is for the cursor to stay at the point [...]
} with marks --- which I still don't trust if text has been moving around,
} but I haven't analysed what I don't trust well enough to suggest what needs
} fixing.
The mark in zsh is just an offset in $BUFFER. In emacs it (effectively)
is a zero-width pseudo-character located between two real characters.
That means you can move stuff around the mark in emacs and it shifts left
or right along with the unchanging characters adjacent to it. In zsh,
this effect is sometimes mimicked by (in|de)crementing the mark position
as characters are (inserted|deleted), but it is not done consistently.
So given this text:
echo abcdefg dcba
^
cursor and mark both here
In emacs, after transpose-words:
echo dcba abcdefg
^
cursor and mark both here (moved with the space)
But in zsh:
echo dcba abcdefg
^
mark here (same buffer offset), cursor at end
Sven and I had a discussion a while back about the difficulty of keeping
the mark consistent when one can do wholesale assignments to $BUFFER
without passing through the usual zle functions. It was inconclusive.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-07-20 18:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-20 10:49 PATCH: bash-transpose-words Peter Stephenson
2001-07-20 18:08 ` Bart Schaefer
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).