aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2010-01-19 19:41:37 +0800
committerGravatar Dieter Plaetinck <dieter@plaetinck.be>2010-01-25 21:38:18 +0100
commitf9bce576e263743010971bee92604b8cdcccbd4c (patch)
treec600c698e67576e2d94c651143b1a5991402b74b
parentfa89c2c0bd97a916a8e1e3fd69613e00a05cf6e2 (diff)
Reduced the {key,mod}cmd_{update,exec} functions into a single function.
-rw-r--r--examples/data/plugins/bind.py59
1 files changed, 11 insertions, 48 deletions
diff --git a/examples/data/plugins/bind.py b/examples/data/plugins/bind.py
index 9e09337..427c8d3 100644
--- a/examples/data/plugins/bind.py
+++ b/examples/data/plugins/bind.py
@@ -444,12 +444,12 @@ def match_and_exec(uzbl, bind, depth, keylet, bindlet):
return True
-def keycmd_update(uzbl, keylet):
+def key_event(uzbl, keylet, modcmd=False, onexec=False):
bindlet = get_bindlet(uzbl)
depth = bindlet.depth
for bind in bindlet.get_binds():
t = bind[depth]
- if t[MOD_CMD] or t[ON_EXEC]:
+ if (bool(t[MOD_CMD]) != modcmd) or (t[ON_EXEC] != onexec):
continue
if match_and_exec(uzbl, bind, depth, keylet, bindlet):
@@ -458,60 +458,23 @@ def keycmd_update(uzbl, keylet):
bindlet.after()
-def keycmd_exec(uzbl, keylet):
- bindlet = get_bindlet(uzbl)
- depth = bindlet.depth
- for bind in bindlet.get_binds():
- t = bind[depth]
- if t[MOD_CMD] or not t[ON_EXEC]:
- continue
-
- if match_and_exec(uzbl, bind, depth, keylet, bindlet):
- return uzbl.clear_keycmd()
-
- bindlet.after()
-
-
-def modcmd_update(uzbl, keylet):
- bindlet = get_bindlet(uzbl)
- depth = bindlet.depth
- for bind in bindlet.get_binds():
- t = bind[depth]
- if not t[MOD_CMD] or t[ON_EXEC]:
- continue
-
- if match_and_exec(uzbl, bind, depth, keylet, bindlet):
- return
-
- bindlet.after()
-
-
-def modcmd_exec(uzbl, keylet):
- bindlet = get_bindlet(uzbl)
- depth = bindlet.depth
- for bind in bindlet.get_binds():
- t = bind[depth]
- if not t[MOD_CMD] or not t[ON_EXEC]:
- continue
-
- if match_and_exec(uzbl, bind, depth, keylet, bindlet):
- return uzbl.clear_modcmd()
-
- bindlet.after()
-
-
def init(uzbl):
# Event handling hooks.
uzbl.connect_dict({
'BIND': parse_bind,
- 'KEYCMD_EXEC': keycmd_exec,
- 'KEYCMD_UPDATE': keycmd_update,
- 'MODCMD_EXEC': modcmd_exec,
- 'MODCMD_UPDATE': modcmd_update,
'MODE_BIND': parse_mode_bind,
'MODE_CHANGED': mode_changed,
})
+ # Connect key related events to the key_event function.
+ events = [['KEYCMD_UPDATE', 'KEYCMD_EXEC'],
+ ['MODCMD_UPDATE', 'MODCMD_EXEC']]
+
+ for modcmd in range(2):
+ for onexec in range(2):
+ event = events[modcmd][onexec]
+ uzbl.connect(event, key_event, bool(modcmd), bool(onexec))
+
# Function exports to the uzbl object, `function(uzbl, *args, ..)`
# becomes `uzbl.function(*args, ..)`.
uzbl.export_dict({