Re: how to disable keys?

clemens fischer <[email protected]> Wed, 24 Jun 2009 23:05:54 +0200
Newsgroups gmane.network.tin.user
Message-ID <[email protected]>
clemens fischer wrote:

> Urs Jan?en wrote:
>
>> the patch works for me:
>
> Yes, that was the case in my first experiments.  I don't know if I
> mixed up something, but yesterday typing "[" would show me thread-info
> _and_ hotlist an author.

That was nonsense I'm afraid.  I wanted to be real smart and cooked up
this:

#v+
diff --git a/tin-1.9.4/src/keymap.c b/tin-1.9.4/src/keymap.c
--- a/tin-1.9.4/src/keymap.c
+++ b/tin-1.9.4/src/keymap.c
@@ -161,18 +161,29 @@
     // Message-ID: <[email protected]>
     // Date: Mon, 22 Jun 2009 20:14:14 +0200
     // Subject: Re: how to disable keys?
-    // for (i = 0; i < keys->used; i++) {
-       for (i = 0; key != '\0' && i < keys->used; i++) {
-               if (keys->list[i].key == key)
-                       entry = &keys->list[i];
-       }
+       // for (i = 0; key != '\0' && i < keys->used; i++) {
+
+    if (key == '\0') {
+        for (i = 0; i < keys->used; i++) {
+            if (keys->list[i].function == func) {
+                keys->list[i].function = NOT_ASSIGNED;
+                keys->list[i].key = '\0';
+            }
+        }
+        return override;
+    } else {
+        for (i = 0; i < keys->used; i++) {
+            if (keys->list[i].key == key)
+                entry = &keys->list[i];
+        }
+    }

        if (entry != NULL) {
                if (override) {
+                       //entry->function = (key == '\0') ? /*NOT_ASSIGNED*/ GLOBAL_ABORT : func;
                        entry->function = func;
-                       return TRUE;
-               } else
-                       return FALSE;
+        }
+        return override;
        } else {
                /* add a new entry */
                if (keys->used >= keys->max) {
#v-

This patch broke, although I don't know why.  I wasn't satisfied with
the inner workings of add_key() when given a zero to map.  In this case
the unmodified code tries to find the command mapped to '\0', your patch
skips this step, but then that zero is treated as a key to bind to the
command in question (ie. when entry==NULL).  The code above was intended
to find all keybindings of a particular command and unmap them given
a '\0' as the key.

Ok, but now I switched back to the version with your much simpler patch
and tried to break something, which didn't work.  This means your patch
indeed worked!  I can disable the keys/commands giving me trouble and
still rebind anything I need.


clemens