diff options
author | Mason Larobina <mason.larobina@gmail.com> | 2009-11-24 00:17:41 +0800 |
---|---|---|
committer | Mason Larobina <mason.larobina@gmail.com> | 2009-11-24 00:17:41 +0800 |
commit | 56fbba912984070b50cca1320e514e92cf834f43 (patch) | |
tree | 73f688a423e69f768bc3b4388dc7256119a80071 /examples | |
parent | f12bfe4243e5b337033a555986db08a0ab2e6c29 (diff) |
Added in distinction between START_COMPLETION events and keycmd updates.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/config/uzbl/config | 4 | ||||
-rw-r--r-- | examples/data/uzbl/plugins/completion.py | 50 |
2 files changed, 35 insertions, 19 deletions
diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config index 3dcc103..8abe554 100644 --- a/examples/config/uzbl/config +++ b/examples/config/uzbl/config @@ -71,9 +71,11 @@ set modcmd_style = weight="bold" foreground="red" set keycmd_style = weight="light" foreground="red" set prompt_style = foreground="grey" set cursor_style = underline="single" +set completion_style = foreground="green" +set hint_style = weight="bold" set mode_section = <span background="khaki" foreground="black">[\@[\@mode_indicator]\@]</span> -set keycmd_section = [<span \@prompt_style>\@[\@keycmd_prompt]\@</span><span \@modcmd_style>\@modcmd</span><span \@keycmd_style>\@keycmd</span>] <span foreground="green">\@completion_list</span> +set keycmd_section = [<span \@prompt_style>\@[\@keycmd_prompt]\@</span><span \@modcmd_style>\@modcmd</span><span \@keycmd_style>\@keycmd</span><span \@completion_style>\@completion_list</span>] set progress_section = <span foreground="#606060">\@[\@progress_format]\@</span> set uri_section = <span foreground="#99FF66">\@[\@uri]\@</span> set name_section = <span foreground="khaki">\@[\@NAME]\@</span> diff --git a/examples/data/uzbl/plugins/completion.py b/examples/data/uzbl/plugins/completion.py index df3b139..2da42ba 100644 --- a/examples/data/uzbl/plugins/completion.py +++ b/examples/data/uzbl/plugins/completion.py @@ -18,8 +18,8 @@ DEFAULTS = {'completions': [], 'level': NONE, 'lock': False} FIND_SEGMENT = re.compile("(\@[\w_]+|[\w_]+)$").findall # Formats -LIST_FORMAT = "[ %s ]" -ITEM_FORMAT = "<b>%s</b>%s" +LIST_FORMAT = "<span> %s </span>" +ITEM_FORMAT = "<span @hint_style>%s</span>%s" def escape(str): @@ -44,7 +44,7 @@ def get_completion_dict(uzbl): return UZBLS[uzbl] -def get_incomplete_cmd(uzbl): +def get_incomplete_keyword(uzbl): '''Gets the segment of the keycmd leading up to the cursor position and uses a regular expression to search backwards finding parially completed keywords or @variables. Returns a null string if the correct completion @@ -56,6 +56,8 @@ def get_incomplete_cmd(uzbl): def stop_completion(uzbl, *args): + '''Stop command completion and return the level to NONE.''' + d = get_completion_dict(uzbl) d['level'] = NONE uzbl.set('completion_list') @@ -77,13 +79,34 @@ def partial_completion(uzbl, partial, hint): uzbl.inject_keycmd(remainder) -def start_completion(uzbl, start=True): +def update_completion_list(uzbl, *args): + '''Checks if the user still has a partially completed keyword under his + cursor then update the completion hints list.''' + + partial = get_incomplete_keyword(uzbl) + if not partial: + return stop_completion(uzbl) d = get_completion_dict(uzbl) - if d['lock'] or not start and not d['level']: + if d['level'] != LIST: return - partial = get_incomplete_cmd(uzbl) + hints = [h for h in d['completions'] if h.startswith(partial)] + if not hints: + return uzbl.set('completion_list') + + j = len(partial) + l = [ITEM_FORMAT % (escape(h[:j]), h[j:]) for h in sorted(hints)] + uzbl.set('completion_list', LIST_FORMAT % ' '.join(l)) + + +def start_completion(uzbl, *args): + + d = get_completion_dict(uzbl) + if d['lock']: + return + + partial = get_incomplete_keyword(uzbl) if not partial: return stop_completion(uzbl) @@ -125,12 +148,7 @@ def start_completion(uzbl, start=True): partial_completion(uzbl, partial, partial+common) d['lock'] = False - partial += common - if d['level'] == LIST: - j = len(partial) - l = [ITEM_FORMAT % (h[:j], h[j:]) for h in sorted(hints)] - print l - uzbl.set('completion_list', escape(LIST_FORMAT % ' '.join(l))) + update_completion_list(uzbl) def add_builtins(uzbl, args): @@ -160,6 +178,8 @@ def init(uzbl): 'INSTANCE_EXIT': del_instance, 'BUILTINS': add_builtins, 'CONFIG_CHANGED': add_config_key, + 'KEYCMD_UPDATE': update_completion_list, + 'START_COMPLETION': start_completion, } # And connect the dicts event handlers to the handler stack. @@ -167,9 +187,3 @@ def init(uzbl): for event in ['STOP_COMPLETION', 'KEYCMD_EXEC', 'KEYCMD_CLEAR']: uzbl.connect(event, stop_completion) - - uzbl.connect('START_COMPLETION', - lambda uzbl, args: start_completion(uzbl)) - - uzbl.connect('KEYCMD_UPDATE', - lambda uzbl, args: start_completion(uzbl, False)) |