zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@sunsite.dk
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	[thread overview]
Message-ID: <200604232308.k3NN8Wtj004945@pwslaptop.csr.com> (raw)
In-Reply-To: Your message of "Sun, 23 Apr 2006 08:53:10 PDT." <060423085310.ZM31491@torch.brasslantern.com>

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@ntlworld.com>
Web page still at http://www.pwstephenson.fsnet.co.uk/


  parent reply	other threads:[~2006-04-23 23:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-21 23:10 Nikolai Weibull
2006-04-22  5:00 ` Bart Schaefer
2006-04-22 11:04   ` Nikolai Weibull
2006-04-22 18:35     ` Bart Schaefer
2006-04-22 21:38       ` Nikolai Weibull
2006-04-23  6:09         ` Bart Schaefer
     [not found]           ` <dbfc82860604230157h52f91585ncfd5a984a1a08c67@mail.gmail.com>
2006-04-23 15:53             ` Bart Schaefer
2006-04-23 16:13               ` Nikolai Weibull
2006-04-23 23:08               ` Peter Stephenson [this message]
2006-04-24 19:39                 ` Nikolai Weibull
2006-04-25  3:06                   ` Bart Schaefer

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=200604232308.k3NN8Wtj004945@pwslaptop.csr.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@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).