diff options
author | keis <keijser@gmail.com> | 2009-10-14 17:56:12 +0200 |
---|---|---|
committer | keis <keijser@gmail.com> | 2009-10-15 04:03:48 +0200 |
commit | 02aa78b2d2e8117de894ea75d87f437d94458738 (patch) | |
tree | 9da00231efec0138f34359262951ebf6315cf19c /examples | |
parent | c7a4e5d5d26f59d7d0f0b40f4d69fa8560bf5454 (diff) |
add event to strip last word from keycmd.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/data/uzbl/scripts/plugins/keycmd.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/data/uzbl/scripts/plugins/keycmd.py b/examples/data/uzbl/scripts/plugins/keycmd.py index c423ab2..565d054 100644 --- a/examples/data/uzbl/scripts/plugins/keycmd.py +++ b/examples/data/uzbl/scripts/plugins/keycmd.py @@ -291,6 +291,25 @@ def set_keycmd(uzbl, keycmd): update_event(uzbl, k, False) +def keycmd_strip_word(uzbl, sep): + sep = sep or ' ' + k = get_keylet(uzbl) + cmd = k.cmd[:k.cursor] + tail = len(k.cmd) - k.cursor + + if sep in cmd: + tmp = cmd.rstrip(sep).rsplit(sep, 1) + else: + tmp = ('',) + + k.cmd = tmp[0] + (sep if len(tmp) == 2 else '') + k.cmd[k.cursor:] + k.cursor = len(tmp[0]) + (len(tmp) - 1) + + assert len(k.cmd) - k.cursor == tail, "tail size changed (%s) (%s - %s)" % (tail, len(k.cmd), k.cursor) + + update_event(uzbl, k, False) + + def set_cursor_pos(uzbl, index): '''Allow setting of the cursor position externally. Supports negative indexing.''' @@ -319,6 +338,7 @@ def init(uzbl): 'KEY_PRESS': key_press, 'KEY_RELEASE': key_release, 'SET_KEYCMD': set_keycmd, + 'KEYCMD_STRIP_WORD': keycmd_strip_word, 'SET_CURSOR_POS': set_cursor_pos} uzbl.connect_dict(connects) |