aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/uzbl/plugins/keycmd.py
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-11-04 23:01:06 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-11-04 23:01:06 +0800
commit32c2a87c3206565f0d0d14a6b707d82b0b693116 (patch)
tree6acf9db93f20348f2ff53c25ac710242c01a6ced /examples/data/uzbl/plugins/keycmd.py
parent35c1e804e1dc1204f6e9ffe5942123b0f11eb59a (diff)
Added INJECT_KEYCMD and APPEND_KEYCMD events in keycmd.py
Diffstat (limited to 'examples/data/uzbl/plugins/keycmd.py')
-rw-r--r--examples/data/uzbl/plugins/keycmd.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/examples/data/uzbl/plugins/keycmd.py b/examples/data/uzbl/plugins/keycmd.py
index d01d2ac..8961f74 100644
--- a/examples/data/uzbl/plugins/keycmd.py
+++ b/examples/data/uzbl/plugins/keycmd.py
@@ -227,11 +227,10 @@ def update_event(uzbl, k, execute=True):
uzbl.set('keycmd', KEYCMD_FORMAT % tuple(map(uzbl_escape, chunks)))
-def inject_char(str, index, char):
- '''Inject character into string at at given index.'''
+def inject_str(str, index, inj):
+ '''Inject a string into string at at given index.'''
- assert len(char) == 1
- return "%s%s%s" % (str[:index], char, str[index:])
+ return "%s%s%s" % (str[:index], inj, str[index:])
def key_press(uzbl, key):
@@ -253,13 +252,13 @@ def key_press(uzbl, key):
return
if key == 'Space' and not k.held and k.keycmd:
- k.keycmd = inject_char(k.keycmd, k.cursor, ' ')
+ k.keycmd = inject_str(k.keycmd, k.cursor, ' ')
k.cursor += 1
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_char(k.keycmd, k.cursor, key)
+ k.keycmd = inject_str(k.keycmd, k.cursor, key)
k.cursor += 1
elif k.keycmd:
@@ -317,6 +316,26 @@ def set_keycmd(uzbl, keycmd):
update_event(uzbl, k, False)
+def inject_keycmd(uzbl, keycmd):
+ '''Allow injecting of a string into the keycmd at the cursor position.'''
+
+ k = get_keylet(uzbl)
+ k.keycmd = inject_str(k.keycmd, k.cursor, keycmd)
+ k._repr_cache = None
+ k.cursor += len(keycmd)
+ update_event(uzbl, k, False)
+
+
+def append_keycmd(uzbl, keycmd):
+ '''Allow appening of a string to the keycmd.'''
+
+ k = get_keylet(uzbl)
+ k.keycmd += keycmd
+ k._repr_cache = None
+ k.cursor = len(k.keycmd)
+ update_event(uzbl, k, False)
+
+
def keycmd_strip_word(uzbl, sep):
''' Removes the last word from the keycmd, similar to readline ^W '''
@@ -406,6 +425,8 @@ def init(uzbl):
'SET_CURSOR_POS': set_cursor_pos,
'FOCUS_LOST': focus_changed,
'FOCUS_GAINED': focus_changed,
- 'MODMAP': modmap_parse}
+ 'MODMAP': modmap_parse,
+ 'APPEND_KEYCMD': append_keycmd,
+ 'INJECT_KEYCMD': inject_keycmd}
uzbl.connect_dict(connects)