Hi

Sorry for the long delay. I like this idea, but this diff breaks -t
without -a, because the key is not set. I'm going with this change
instead which is also smaller:

Index: cmd-unbind-key.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/cmd-unbind-key.c,v
retrieving revision 1.12
diff -u -p -r1.12 cmd-unbind-key.c
--- cmd-unbind-key.c    21 Jan 2012 11:12:13 -0000      1.12
+++ cmd-unbind-key.c    5 May 2012 17:39:06 -0000
@@ -42,8 +42,8 @@ const struct cmd_entry cmd_unbind_key_en
 int
 cmd_unbind_key_check(struct args *args)
 {
-       if (args_has(args, 'a') && (args->argc != 0 || args_has(args, 't')))
-           return (-1);
+       if (args_has(args, 'a') && args->argc != 0)
+               return (-1);
        if (!args_has(args, 'a') && args->argc != 1)
                return (-1);
        return (0);
@@ -56,7 +56,19 @@ cmd_unbind_key_exec(struct cmd *self, un
        struct key_binding      *bd;
        int                      key;
 
-       if (args_has(args, 'a')) {
+       if (!args_has(args, 'a')) {
+               key = key_string_lookup_string(args->argv[0]);
+               if (key == KEYC_NONE) {
+                       ctx->error(ctx, "unknown key: %s", args->argv[0]);
+                       return (-1);
+               }
+       } else
+               key = KEYC_NONE;
+
+       if (args_has(args, 't'))
+               return (cmd_unbind_key_table(self, ctx, key));
+
+       if (key == KEYC_NONE) {
                while (!RB_EMPTY(&key_bindings)) {
                        bd = RB_ROOT(&key_bindings);
                        key_bindings_remove(bd->key);
@@ -64,15 +76,6 @@ cmd_unbind_key_exec(struct cmd *self, un
                return (0);
        }
 
-       key = key_string_lookup_string(args->argv[0]);
-       if (key == KEYC_NONE) {
-               ctx->error(ctx, "unknown key: %s", args->argv[0]);
-               return (-1);
-       }
-
-       if (args_has(args, 't'))
-               return (cmd_unbind_key_table(self, ctx, key));
-
        if (!args_has(args, 'n'))
                key |= KEYC_PREFIX;
        key_bindings_remove(key);
@@ -91,6 +94,15 @@ cmd_unbind_key_table(struct cmd *self, s
        if ((mtab = mode_key_findtable(tablename)) == NULL) {
                ctx->error(ctx, "unknown key table: %s", tablename);
                return (-1);
+       }
+
+       if (key == KEYC_NONE) {
+               while (!RB_EMPTY(mtab->tree)) {
+                       mbind = RB_ROOT(mtab->tree);
+                       RB_REMOVE(mode_key_tree, mtab->tree, mbind);
+                       xfree(mbind);
+               }
+               return (0);
        }
 
        mtmp.key = key;



On Thu, Apr 12, 2012 at 10:48:35PM +0900, Kazuhiko Sakaguchi wrote:
> Hi
> 
> This patch implements a combination action of the -a flag and the -t argument 
> of
> the unbind-key command.
> 
> example:
> $ tmux unbind-key -a -t vi-edit
> (remove all key bindings from vi-edit key table)


> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2

> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to