diff options
author | Mason Larobina <mason.larobina@gmail.com> | 2009-12-23 21:15:18 +0800 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2010-01-01 23:56:24 +0100 |
commit | 5fab9b5f81ff0d7eeebbd1bf07f4b945e1454165 (patch) | |
tree | 1a085265383d9af0c54dafcd972eea636ce93e61 /examples | |
parent | 7008808e0defff7a43abdd64d8c9df27b4eec000 (diff) |
Added the escaped and quoted %r replace for on_event and bind args.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/data/uzbl/plugins/bind.py | 10 | ||||
-rw-r--r-- | examples/data/uzbl/plugins/on_event.py | 11 |
2 files changed, 21 insertions, 0 deletions
diff --git a/examples/data/uzbl/plugins/bind.py b/examples/data/uzbl/plugins/bind.py index 1cba7b2..668b595 100644 --- a/examples/data/uzbl/plugins/bind.py +++ b/examples/data/uzbl/plugins/bind.py @@ -306,9 +306,19 @@ class Bind(object): def expand(cmd, args): '''Replaces "%s %1 %2 %3..." with "<all args> <arg 0> <arg 1>...".''' + # Direct string replace. if '%s' in cmd: cmd = cmd.replace('%s', ' '.join(map(unicode, args))) + # Escaped and quoted string replace. + if '%r' in cmd: + joined = ('%r' % ' '.join(map(unicode, args)))[1:] + for char in ['\\', '@']: + joined = joined.replace(char, '\\'+char) + + cmd = cmd.replace('%r', joined) + + # Arg index string replace. for (index, arg) in enumerate(args): index += 1 if '%%%d' % index in cmd: diff --git a/examples/data/uzbl/plugins/on_event.py b/examples/data/uzbl/plugins/on_event.py index afee4e6..9d2525b 100644 --- a/examples/data/uzbl/plugins/on_event.py +++ b/examples/data/uzbl/plugins/on_event.py @@ -2,6 +2,7 @@ Formatting options: %s = space separated string of the arguments + %r = escaped and quoted version of %s %1 = argument 1 %2 = argument 2 %n = argument n @@ -47,9 +48,19 @@ def get_on_events(uzbl): def expand(cmd, args): '''Replaces "%s %1 %2 %3..." with "<all args> <arg 0> <arg 1>...".''' + # Direct string replace. if '%s' in cmd: cmd = cmd.replace('%s', ' '.join(map(unicode, args))) + # Escaped and quoted string replace. + if '%r' in cmd: + joined = ('%r' % ' '.join(map(unicode, args)))[1:] + for char in ['\\', '@']: + joined = joined.replace(char, '\\'+char) + + cmd = cmd.replace('%r', joined) + + # Arg index string replace. for (index, arg) in enumerate(args): index += 1 if '%%%d' % index in cmd: |