zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: keymap for execute-named-command
@ 2009-01-28  4:58 Greg Klanderman
  0 siblings, 0 replies; only message in thread
From: Greg Klanderman @ 2009-01-28  4:58 UTC (permalink / raw)
  To: Zsh list

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 404 bytes --]


Hi,

After binding <return> to a user defined widget, I found that the
execute-named-command and where-is widgets no longer work because like
isearch and menu-select they have hard-coded a check for accept-line.
This patch adds a local keymap for these widgets to use when reading
the command name making it easier to use a user-defined widget in your
main keymap to replace accept-line.

thanks,
Greg


[-- Attachment #2: zsh-command.patch --]
[-- Type: text/plain, Size: 4436 bytes --]

Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.76
diff -u -r1.76 zle.yo
--- Doc/Zsh/zle.yo	19 Jan 2009 17:57:43 -0000	1.76
+++ Doc/Zsh/zle.yo	28 Jan 2009 04:26:28 -0000
@@ -60,13 +60,14 @@
 findex(bindkey, use of)
 tt(bindkey) can be used to manipulate keymap names.
 
-Initially, there are five keymaps:
+Initially, there are six keymaps:
 
 startsitem()
 sitem(tt(emacs))(EMACS emulation)
 sitem(tt(viins))(vi emulation - insert mode)
 sitem(tt(vicmd))(vi emulation - command mode)
 sitem(tt(isearch))(incremental search mode)
+sitem(tt(command))(read a command name)
 sitem(tt(.safe))(fallback keymap)
 endsitem()
 
@@ -1862,7 +1868,9 @@
 item(tt(execute-named-cmd) (ESC-x) (unbound) (unbound))(
 Read the name of an editor command and
 execute it.  A restricted set of editing functions is available in the
-mini-buffer.  An interrupt signal, as defined by the stty setting, will
+mini-buffer.  Keys are looked up in the special
+tt(command) keymap, and if not found there in the main keymap.
+An interrupt signal, as defined by the stty setting, will
 abort the function. The allowed functions are:
 tt(backward-delete-char),
 tt(vi-backward-delete-char),
@@ -2087,6 +2095,9 @@
 item(tt(where-is))(
 Read the name of an editor command and and print the listing of key
 sequences that invoke the specified command.
+A restricted set of editing functions is available in the
+mini-buffer.  Keys are looked up in the special
+tt(command) keymap, and if not found there in the main keymap.
 )
 tindex(which-command)
 item(tt(which-command) (ESC-?) (unbound) (unbound))(
Index: Src/Zle/zle_keymap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v
retrieving revision 1.31
diff -u -r1.31 zle_keymap.c
--- Src/Zle/zle_keymap.c	19 Jan 2009 17:57:43 -0000	1.31
+++ Src/Zle/zle_keymap.c	28 Jan 2009 04:26:28 -0000
@@ -1176,8 +1176,6 @@
     char buf[3], *ed;
     int i;
 
-    isearch_keymap = newkeymap(NULL, "isearch");
-
     /* vi insert mode and emacs mode:  *
      *   0-31   taken from the tables  *
      *  32-126  self-insert            *
@@ -1276,10 +1274,19 @@
     else
 	linkkeymap(emap, "main", 0);
 
-    linkkeymap(isearch_keymap, "isearch", 0);
-
     /* the .safe map cannot be modified or deleted */
     smap->flags |= KM_IMMUTABLE;
+
+    /* isearch keymap: initially empty */
+    isearch_keymap = newkeymap(NULL, "isearch");
+    linkkeymap(isearch_keymap, "isearch", 0);
+
+    /* command keymap: make sure accept-line and send-break are bound */
+    command_keymap = newkeymap(NULL, "command");
+    command_keymap->first['\n'] = refthingy(t_acceptline);
+    command_keymap->first['\r'] = refthingy(t_acceptline);
+    command_keymap->first['G'&0x1F] = refthingy(t_sendbreak);
+    linkkeymap(command_keymap, "command", 0);
 }
 
 /*************************/
Index: Src/Zle/zle_misc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v
retrieving revision 1.56
diff -u -r1.56 zle_misc.c
--- Src/Zle/zle_misc.c	26 Sep 2008 09:11:30 -0000	1.56
+++ Src/Zle/zle_misc.c	28 Jan 2009 04:26:28 -0000
@@ -966,11 +966,19 @@
 
 #define NAMLEN 60
 
+/*
+ * Local keymap used when reading a command name for the
+ * execute-named-command and where-is widgets.
+ */
+
+/**/
+Keymap command_keymap;
+
 /**/
 Thingy
 executenamedcommand(char *prmt)
 {
-    Thingy cmd;
+    Thingy cmd, retval = NULL;
     int l, len, feep = 0, listed = 0, curlist = 0;
     int ols = (listshown && validlist), olll = lastlistlen;
     char *cmdbuf, *ptr;
@@ -988,6 +996,7 @@
     strcpy(cmdbuf, prmt);
     zsfree(prmt);
     statusline = cmdbuf;
+    selectlocalmap(command_keymap);
     selectkeymap("main", 1);
     ptr = cmdbuf += l;
     len = 0;
@@ -1005,7 +1014,8 @@
 	    } else if (listed)
 		clearlist = listshown = 1;
 
-	    return NULL;
+	    retval = NULL;
+	    goto done;
 	}
 	if(cmd == Th(z_clearscreen)) {
 	    clearscreen(zlenoargs);
@@ -1090,7 +1100,9 @@
 			lastlistlen = olll;
 		    } else if (listed)
 			clearlist = listshown = 1;
-		    return r;
+
+		    retval = r;
+		    goto done;
 		}
 		unrefthingy(r);
 	    }
@@ -1180,6 +1192,10 @@
 	    handlefeep(zlenoargs);
 	feep = 0;
     }
+
+ done:
+    selectlocalmap(NULL);
+    return retval;
 }
 
 /*****************/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-01-28  4:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-28  4:58 PATCH: keymap for execute-named-command Greg Klanderman

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).