aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/config/uzbl/config4
-rw-r--r--examples/data/uzbl/plugins/completion.py50
-rw-r--r--examples/data/uzbl/plugins/keycmd.py29
3 files changed, 51 insertions, 32 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))
diff --git a/examples/data/uzbl/plugins/keycmd.py b/examples/data/uzbl/plugins/keycmd.py
index 82c95f8..b1e8299 100644
--- a/examples/data/uzbl/plugins/keycmd.py
+++ b/examples/data/uzbl/plugins/keycmd.py
@@ -97,7 +97,7 @@ class Keylet(object):
l.append('modcmd=%r' % self.get_modcmd())
elif self.held:
- l.append('held=%r' % ''.join(['<%s>'%key for key in self.held]))
+ l.append('held=%r' % ''.join(sorted(self.held)))
if self.keycmd:
l.append('keycmd=%r' % self.get_keycmd())
@@ -178,8 +178,8 @@ def clear_keycmd(uzbl):
k.cursor = 0
k._repr_cache = False
config = uzbl.get_config()
- if 'keycmd' not in config or config['keycmd'] != '':
- uzbl.set('keycmd', '')
+ if 'keycmd' not in config or config['keycmd']:
+ uzbl.set('keycmd')
uzbl.event('KEYCMD_CLEAR')
@@ -195,8 +195,8 @@ def clear_modcmd(uzbl, clear_held=False):
k.held = set()
config = uzbl.get_config()
- if 'modcmd' not in config or config['modcmd'] != '':
- uzbl.set('modcmd', '')
+ if 'modcmd' not in config or config['modcmd']:
+ uzbl.set('modcmd')
uzbl.event('MODCMD_CLEAR')
@@ -240,9 +240,9 @@ def update_event(uzbl, k, execute=True):
if 'keycmd_events' in config and config['keycmd_events'] != '1':
return
- new_keycmd = k.get_keycmd()
- if not new_keycmd or new_keycmd != keycmd:
- return uzbl.set('keycmd', '')
+ keycmd = k.get_keycmd()
+ if not keycmd:
+ return uzbl.set('keycmd')
# Generate the pango markup for the cursor in the keycmd.
curchar = keycmd[k.cursor] if k.cursor < len(keycmd) else ' '
@@ -288,13 +288,16 @@ def key_press(uzbl, key):
elif not k.held and len(key) == 1:
config = uzbl.get_config()
- if 'keycmd_events' not in config or config['keycmd_events'] == '1':
- k.keycmd = inject_str(k.keycmd, k.cursor, key)
- k.cursor += 1
-
- elif k.keycmd:
+ if 'keycmd_events' in config and config['keycmd_events'] != '1':
k.keycmd = ''
k.cursor = 0
+ if config['keycmd']:
+ uzbl.set('keycmd')
+
+ return
+
+ k.keycmd = inject_str(k.keycmd, k.cursor, key)
+ k.cursor += 1
elif len(key) > 1:
k.is_modcmd = True