aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-12-23 21:15:18 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-12-23 21:15:18 +0800
commit09d59497d1c06f07b1915e34c0110401916231b9 (patch)
treed2c2b3c09dbf3ef6ba359c8369b0439a8ef3af20 /examples
parent49941155e43eb520c43b02b55e0bbced2b657cf6 (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.py10
-rw-r--r--examples/data/uzbl/plugins/on_event.py11
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: