From 7c0d66962b044bf0001005e911aefe78bb10c95f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 24 Mar 2011 18:53:12 -0400 Subject: Allow for multiple characters to bound words Word deletion in URLs is a lot better when characters such as: \ -./&?= are considered to separate words. --- examples/config/config | 2 +- examples/data/plugins/keycmd.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index ab690e0..a1a3494 100644 --- a/examples/config/config +++ b/examples/config/config @@ -194,7 +194,7 @@ set ebind = @mode_bind global,-insert @ebind = event KEYCMD_DELETE @ebind = event START_COMPLETION # Readline-ish bindings. -@ebind w = event KEYCMD_STRIP_WORD +@ebind w = event KEYCMD_STRIP_WORD \ -./&?= @ebind u = event SET_KEYCMD @ebind a = event SET_CURSOR_POS 0 @ebind e = event SET_CURSOR_POS -1 diff --git a/examples/data/plugins/keycmd.py b/examples/data/plugins/keycmd.py index 928c597..76e2d75 100644 --- a/examples/data/plugins/keycmd.py +++ b/examples/data/plugins/keycmd.py @@ -406,16 +406,22 @@ def append_keycmd(uzbl, keycmd): update_event(uzbl, k, False) -def keycmd_strip_word(uzbl, sep): +def keycmd_strip_word(uzbl, seps): ''' Removes the last word from the keycmd, similar to readline ^W ''' - sep = sep or ' ' + seps = seps or ' ' k = uzbl.keylet if not k.keycmd: return - head, tail = k.keycmd[:k.cursor].rstrip(sep), k.keycmd[k.cursor:] - rfind = head.rfind(sep) + head, tail = k.keycmd[:k.cursor].rstrip(seps), k.keycmd[k.cursor:] + rfind = -1 + for sep in seps: + p = head.rfind(sep) + if p >= 0 and rfind < p + 1: + rfind = p + 1 + if rfind == len(head) and head[-1] in seps: + rfind -= 1 head = head[:rfind] if rfind + 1 else '' k.keycmd = head + tail k.cursor = len(head) -- cgit v1.2.3