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

user-mode keymap selection



Long-overdue functionality.

-zefram

Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.14
diff -c -r1.14 zle.yo
*** Doc/Zsh/zle.yo	2001/07/26 11:34:58	1.14
--- Doc/Zsh/zle.yo	2001/09/03 01:32:18
***************
*** 305,310 ****
--- 305,311 ----
  xitem(tt(zle) tt(-R) [ tt(-c) ] [ var(display-string) ] [ var(string) ... ])
  xitem(tt(zle) tt(-M) var(string))
  xitem(tt(zle) tt(-U) var(string))
+ xitem(tt(zle) tt(-K) var(keymap))
  xitem(tt(zle) tt(-I))
  xitem(tt(zle) var(widget) tt([ -n) var(num) tt(]) tt([ -N ]) var(args) ...)
  item(tt(zle))(
***************
*** 394,399 ****
--- 395,408 ----
  the characters in each var(string) will be processed in the order in which
  they appear in the string.
  )
+ item(tt(-K) var(keymap))(
+ Selects the keymap named var(keymap).  An error message will be displayed if
+ there is no such keymap.
+ 
+ This keymap selection affects the interpretation of following keystrokes
+ within this invocation of ZLE.  Any following invocation (e.g., the next
+ command line) will start as usual with the `tt(main)' keymap selected.
+ )
  item(tt(-I))(
  Unusually, this option is only useful em(outside) ordinary widget functions.
  It invalidates the current zle display in preparation for output; usually
***************
*** 518,523 ****
--- 527,536 ----
  vindex(HISTNO)
  item(tt(HISTNO) (integer))(
  The current history number.
+ )
+ vindex(KEYMAP)
+ item(tt(KEYMAP) (scalar))(
+ The name of the currently selected keymap.
  )
  vindex(KEYS)
  item(tt(KEYS) (scalar))(
Index: Src/Zle/zle_hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_hist.c,v
retrieving revision 1.4
diff -c -r1.4 zle_hist.c
*** Src/Zle/zle_hist.c	2001/05/29 21:41:53	1.4
--- Src/Zle/zle_hist.c	2001/09/03 01:32:22
***************
*** 660,666 ****
      int odir = dir, sens = zmult == 1 ? 3 : 1;
      int hl = histline, savekeys = -1, feep = 0;
      Thingy cmd;
!     char *okeymap = curkeymapname;
      static char *previous_search = NULL;
      static int previous_search_len = 0;
      Histent he;
--- 660,666 ----
      int odir = dir, sens = zmult == 1 ? 3 : 1;
      int hl = histline, savekeys = -1, feep = 0;
      Thingy cmd;
!     char *okeymap = ztrdup(curkeymapname);
      static char *previous_search = NULL;
      static int previous_search_len = 0;
      Histent he;
***************
*** 883,888 ****
--- 883,889 ----
      }
      statusline = NULL;
      selectkeymap(okeymap, 1);
+     zsfree(okeymap);
      /*
       * Don't allow unused characters provided as a string to the
       * widget to overflow and be used as separated commands.
***************
*** 960,966 ****
      char *sbuf = zhalloc(80);
      int sptr = 1, ret = 0, ssbuf = 80, feep = 0;
      Thingy cmd;
!     char *okeymap = curkeymapname;
  
      if (vipenultsrchstr) {
  	zsfree(vipenultsrchstr);
--- 961,967 ----
      char *sbuf = zhalloc(80);
      int sptr = 1, ret = 0, ssbuf = 80, feep = 0;
      Thingy cmd;
!     char *okeymap = ztrdup(curkeymapname);
  
      if (vipenultsrchstr) {
  	zsfree(vipenultsrchstr);
***************
*** 1044,1049 ****
--- 1045,1051 ----
      }
      statusline = NULL;
      selectkeymap(okeymap, 1);
+     zsfree(okeymap);
      return ret;
  }
  
Index: Src/Zle/zle_keymap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v
retrieving revision 1.7
diff -c -r1.7 zle_keymap.c
*** Src/Zle/zle_keymap.c	2001/04/19 19:43:45	1.7
--- Src/Zle/zle_keymap.c	2001/09/03 01:32:25
***************
*** 388,394 ****
  	    return 1;
  	km = openkeymap(name = ".safe");
      }
!     curkeymapname = name;
      curkeymap = km;
      return 0;
  }
--- 388,397 ----
  	    return 1;
  	km = openkeymap(name = ".safe");
      }
!     if(name != curkeymapname) {
! 	zsfree(curkeymapname);
! 	curkeymapname = ztrdup(name);
!     }
      curkeymap = km;
      return 0;
  }
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.19
diff -c -r1.19 zle_main.c
*** Src/Zle/zle_main.c	2001/07/08 00:32:12	1.19
--- Src/Zle/zle_main.c	2001/09/03 01:32:27
***************
*** 1100,1106 ****
  static struct builtin bintab[] = {
      BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLRp", NULL),
      BUILTIN("vared",   0, bin_vared,   1,  7, 0, NULL,             NULL),
!     BUILTIN("zle",     0, bin_zle,     0, -1, 0, "lDANCLmMgGcRaUI", NULL),
  };
  
  /* The order of the entries in this table has to match the *HOOK
--- 1100,1106 ----
  static struct builtin bintab[] = {
      BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLRp", NULL),
      BUILTIN("vared",   0, bin_vared,   1,  7, 0, NULL,             NULL),
!     BUILTIN("zle",     0, bin_zle,     0, -1, 0, "lDANCLmMgGcRaUKI", NULL),
  };
  
  /* The order of the entries in this table has to match the *HOOK
Index: Src/Zle/zle_misc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v
retrieving revision 1.5
diff -c -r1.5 zle_misc.c
*** Src/Zle/zle_misc.c	2001/08/28 08:41:52	1.5
--- Src/Zle/zle_misc.c	2001/09/03 01:32:29
***************
*** 669,675 ****
      int len, l = strlen(prmt), feep = 0, listed = 0, curlist = 0;
      int ols = (listshown && validlist), olll = lastlistlen;
      char *ptr;
!     char *okeymap = curkeymapname;
  
      clearlist = 1;
      cmdbuf = zhalloc(l + NAMLEN + 2);
--- 669,675 ----
      int len, l = strlen(prmt), feep = 0, listed = 0, curlist = 0;
      int ols = (listshown && validlist), olll = lastlistlen;
      char *ptr;
!     char *okeymap = ztrdup(curkeymapname);
  
      clearlist = 1;
      cmdbuf = zhalloc(l + NAMLEN + 2);
***************
*** 685,690 ****
--- 685,691 ----
  	if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) {
  	    statusline = NULL;
  	    selectkeymap(okeymap, 1);
+ 	    zsfree(okeymap);
  	    if ((listshown = ols)) {
  		showinglist = -2;
  		lastlistlen = olll;
***************
*** 752,757 ****
--- 753,759 ----
  		    unrefthingy(r);
  		    statusline = NULL;
  		    selectkeymap(okeymap, 1);
+ 		    zsfree(okeymap);
  		    if ((listshown = ols)) {
  			showinglist = -2;
  			lastlistlen = olll;
Index: Src/Zle/zle_params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_params.c,v
retrieving revision 1.2
diff -c -r1.2 zle_params.c
*** Src/Zle/zle_params.c	2000/04/05 08:49:50	1.2
--- Src/Zle/zle_params.c	2001/09/03 01:32:30
***************
*** 69,74 ****
--- 69,76 ----
          zleunsetfn, NULL },
      { "LASTWIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_lwidget),
          zleunsetfn, NULL },
+     { "KEYMAP", PM_SCALAR | PM_READONLY, NULL, FN(get_keymap),
+         zleunsetfn, NULL },
      { "KEYS", PM_SCALAR | PM_READONLY, NULL, FN(get_keys),
          zleunsetfn, NULL },
      { "NUMERIC", PM_INTEGER | PM_UNSET, FN(set_numeric), FN(get_numeric),
***************
*** 269,274 ****
--- 271,283 ----
  get_lwidget(Param pm)
  {
      return (lbindk ? lbindk->nam : "");
+ }
+ 
+ /**/
+ static char *
+ get_keymap(Param pm)
+ {
+     return dupstring(curkeymapname);
  }
  
  /**/
Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.3
diff -c -r1.3 zle_thingy.c
*** Src/Zle/zle_thingy.c	2000/11/11 19:50:29	1.3
--- Src/Zle/zle_thingy.c	2001/09/03 01:32:34
***************
*** 339,344 ****
--- 339,345 ----
  	{ 'R', bin_zle_refresh, 0, -1 },
  	{ 'M', bin_zle_mesg, 1, 1 },
  	{ 'U', bin_zle_unget, 1, 1 },
+ 	{ 'K', bin_zle_keymap, 1, 1 },
  	{ 'I', bin_zle_invalidate, 0, 0 },
  	{ 0,   bin_zle_call, 0, -1 },
      };
***************
*** 462,467 ****
--- 463,479 ----
      while (p > b)
  	ungetkey((int) *--p);
      return 0;
+ }
+ 
+ /**/
+ static int
+ bin_zle_keymap(char *name, char **args, char *ops, char func)
+ {
+     if (!zleactive) {
+ 	zwarnnam(name, "can only be called from widget function", NULL, 0);
+ 	return 1;
+     }
+     return selectkeymap(*args, 0);
  }
  
  /**/



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