Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Problem with motion commands defined using match-word-by-style used with vi-delete
- X-seq: zsh-users 10172
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Problem with motion commands defined using match-word-by-style used with vi-delete
- Date: Mon, 24 Apr 2006 00:08:31 +0100
- In-reply-to: Your message of "Sun, 23 Apr 2006 08:53:10 PDT." <060423085310.ZM31491@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
Bart Schaefer wrote:
> } I fear my time would be
> } better spent implementing .recursive-edit-read-one-key.
>
> There must be a better name for it than that. GNU emacs appears to call
> it read-key-sequence.
Here's a simple internal widget that reads a key sequence and sets
REPLY to the command bound to it (so you can run zle on that). The key
sequence reading is just like normal operation, so you can even use M-x.
I think this is better than reading just the key sequence, but no doubt
you'll let me know if this doesn't do the job. It's so easy to
implement I'll commit it anyway. (I called it read-command because a
command is what you get back, but pedantically it ought to be something
like read-key-sequence-and-return-command; that didn't seem very memorable.)
You need to use it something like:
local REPLY
if zle read-command && [[ $REPLY != undefined-key ]]; then
zle $REPLY
zle -M "I just executed $REPLY!"
else
zle -M "No such command"
fi
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.51
diff -u -r1.51 zle.yo
--- Doc/Zsh/zle.yo 21 Mar 2006 19:19:15 -0000 1.51
+++ Doc/Zsh/zle.yo 23 Apr 2006 23:06:56 -0000
@@ -103,6 +103,12 @@
detect loops the process will be stopped if there are twenty such replacements
without a real command being read.
+A key sequence typed by the user can be turned into a command name for use
+in user-defined widgets with the tt(read-command) widget, described
+ifzman(below)\
+ifnzman(in noderef(Miscellaneous) below)\
+.
+
texinode(Zle Builtins)(Zle Widgets)(Keymaps)(Zsh Line Editor)
sect(Zle Builtins)
cindex(zle, builtin commands)
@@ -1767,6 +1773,16 @@
construct into the editor buffer.
The latter is equivalent to tt(push-input) followed by tt(get-line).
)
+tindex(read-command)
+item(tt(read-command))(
+Only useful from a user-defined widget. A keystroke is read just as in
+normal operation, but instead of the command being executed the name
+of the command that would be executed is stored in the shell parameter
+tt(REPLY). This can be used as the argument of a future tt(zle)
+command. If the key sequence is not bound, status 1 is returned;
+typically, however, tt(REPLY) is set to tt(undefined-key) to indicate
+a useless key sequence.
+)
tindex(recursive-edit)
item(tt(recursive-edit))(
Only useful from a user-defined widget. At this point in the function,
Index: Src/Zle/iwidgets.list
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/iwidgets.list,v
retrieving revision 1.8
diff -u -r1.8 iwidgets.list
--- Src/Zle/iwidgets.list 24 Nov 2005 10:25:34 -0000 1.8
+++ Src/Zle/iwidgets.list 23 Apr 2006 23:06:56 -0000
@@ -86,6 +86,7 @@
"quoted-insert", quotedinsert, ZLE_MENUCMP | ZLE_KEEPSUFFIX
"quote-line", quoteline, 0
"quote-region", quoteregion, 0
+"read-command", readcommand, 0
"recursive-edit", recursiveedit, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL
"redisplay", redisplay, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL
"redo", redo, ZLE_KEEPSUFFIX
Index: Src/Zle/zle_keymap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v
retrieving revision 1.24
diff -u -r1.24 zle_keymap.c
--- Src/Zle/zle_keymap.c 28 Jan 2006 15:02:26 -0000 1.24
+++ Src/Zle/zle_keymap.c 23 Apr 2006 23:06:57 -0000
@@ -1441,3 +1441,16 @@
return;
linkkeymap(km, "main", 0);
}
+
+/**/
+mod_export int
+readcommand(UNUSED(char **args))
+{
+ Thingy thingy = getkeycmd();
+
+ if (!thingy)
+ return 1;
+
+ setsparam("REPLY", ztrdup(thingy->nam));
+ return 0;
+}
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page still at http://www.pwstephenson.fsnet.co.uk/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author