diff options
author | Mason Larobina <mason.larobina@gmail.com> | 2009-11-26 23:15:35 +0800 |
---|---|---|
committer | Mason Larobina <mason.larobina@gmail.com> | 2009-11-26 23:15:35 +0800 |
commit | 780caeed5ecbf3d0b3fda7ec87c471bf50d6c777 (patch) | |
tree | e41be45888e3431e9c718d7a216a0e0681d01903 /examples/data | |
parent | 59f8345ba294b00db7ccb0b7fd3cbbdda6c26252 (diff) |
Removed stack mode requirement for stacked bindings in bind plugin.
Diffstat (limited to 'examples/data')
-rw-r--r-- | examples/data/uzbl/plugins/bind.py | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/examples/data/uzbl/plugins/bind.py b/examples/data/uzbl/plugins/bind.py index 509363d..4976a80 100644 --- a/examples/data/uzbl/plugins/bind.py +++ b/examples/data/uzbl/plugins/bind.py @@ -17,6 +17,7 @@ __export__ = ['bind', 'del_bind', 'del_bind_by_glob', 'get_binds'] # Hold the bind dicts for each uzbl instance. UZBLS = {} +DEFAULTS = {'binds': [], 'depth': 0, 'stack': [], 'args': []} # Commonly used regular expressions. starts_with_mod = re.compile('^<([A-Z][A-Za-z0-9-_]*)>') @@ -50,8 +51,7 @@ def split_glob(glob): def add_instance(uzbl, *args): - UZBLS[uzbl] = {'binds': [], 'depth': 0, 'stack': [], - 'args': [], 'last_mode': ''} + UZBLS[uzbl] = dict(DEFAULTS) def del_instance(uzbl, *args): @@ -276,39 +276,50 @@ def parse_bind_event(uzbl, args): bind(uzbl, glob, command) -def set_stack_mode(uzbl, prompt): - prompt, set = prompt - if uzbl.get_mode() != 'stack': - uzbl.set_mode('stack') +def clear_stack(uzbl, mode): + '''Clear everything related to stacked binds.''' + + bind_dict = get_bind_dict(uzbl) + bind_dict['stack'] = [] + bind_dict['depth'] = 0 + bind_dict['args'] = [] + + uzbl.set('keycmd_prompt', '') + + +def stack_bind(uzbl, bind, args, depth): + '''Increment the stack depth in the bind dict, generate filtered bind + list for stack mode and set keycmd prompt.''' + + bind_dict = get_bind_dict(uzbl) + if bind_dict['depth'] != depth: + if bind not in bind_dict['stack']: + bind_dict['stack'].append(bind) + + return + + globalcmds = [cmd for cmd in bind_dict['binds'] if cmd.is_global] + bind_dict['stack'] = [bind,] + globalcmds + bind_dict['args'] += args + bind_dict['depth'] = depth + 1 + uzbl.send('event BIND_STACK_LEVEL %d' % bind_dict['depth']) + + (prompt, set) = bind.prompts[depth] if prompt: - prompt = "%s: " % prompt + uzbl.set('keycmd_prompt', '%s:' % prompt) - uzbl.set('keycmd_prompt', prompt) + else: + uzbl.set('keycmd_prompt') if set: - # Go through uzbl-core to expand potential @-variables uzbl.send('event SET_KEYCMD %s' % set) else: uzbl.clear_keycmd() -def clear_stack(uzbl, mode): - bind_dict = get_bind_dict(uzbl) - if mode != "stack" and bind_dict['last_mode'] == "stack": - uzbl.set('keycmd_prompt', '') - - if mode != "stack": - bind_dict = get_bind_dict(uzbl) - bind_dict['stack'] = [] - bind_dict['depth'] = 0 - bind_dict['args'] = [] - - bind_dict['last_mode'] = mode - - -def match_and_exec(uzbl, bind, depth, keylet, mod_event=False): +def match_and_exec(uzbl, bind, depth, keylet): bind_dict = get_bind_dict(uzbl) (on_exec, has_args, mod_cmd, glob, more) = bind[depth] @@ -338,16 +349,7 @@ def match_and_exec(uzbl, bind, depth, keylet, mod_event=False): return True elif more: - if bind_dict['depth'] == depth: - globalcmds = [cmd for cmd in bind_dict['binds'] if cmd.is_global] - bind_dict['stack'] = [bind,] + globalcmds - bind_dict['args'] += args - bind_dict['depth'] = depth + 1 - - elif bind not in bind_dict['stack']: - bind_dict['stack'].append(bind) - - set_stack_mode(uzbl, bind.prompts[depth]) + stack_bind(uzbl, bind, args, depth) return False args = bind_dict['args'] + args |