diff options
author | Mason Larobina <mason.larobina@gmail.com> | 2009-09-22 16:41:09 +0800 |
---|---|---|
committer | Mason Larobina <mason.larobina@gmail.com> | 2009-09-22 16:41:09 +0800 |
commit | 568e2e24a7bbaf2ba279aaa5ddcd3c25e5902ec8 (patch) | |
tree | 164fefb70a8a0aa98da09003880abfe34d5560cc /examples/data/uzbl/scripts | |
parent | d122dfcde37a2c24af29bddc031da6189b63a34e (diff) |
on_event now transforms "%@ %1 %2.." into "<all args> <arg1> <arg2>.."
Diffstat (limited to 'examples/data/uzbl/scripts')
-rw-r--r-- | examples/data/uzbl/scripts/plugins/on_event.py | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/examples/data/uzbl/scripts/plugins/on_event.py b/examples/data/uzbl/scripts/plugins/on_event.py index a05d91a..dc81fcc 100644 --- a/examples/data/uzbl/scripts/plugins/on_event.py +++ b/examples/data/uzbl/scripts/plugins/on_event.py @@ -1,9 +1,19 @@ -'''Plugin provides arbitrarily binding uzbl events to uzbl commands. - You can use $1,$2 to refer to the arguments appearing in the relevant event messages - -For example: - request ON_EVENT LINK_HOVER 'set SELECTED_URI = $1' - this will set the SELECTED_URI variable which you can display in your statusbar +'''Plugin provides arbitrary binding of uzbl events to uzbl commands. + +Formatting options: + %@ = space separated string of the arguments + %1 = argument 1 + %2 = argument 2 + %n = argument n + +Usage: + request ON_EVENT LINK_HOVER set selected_uri = $1 + --> LINK_HOVER http://uzbl.org/ + <-- set selected_uri = http://uzbl.org/ + + request ON_EVENT CONFIG_CHANGED print Config changed: %1 = %2 + --> CONFIG_CHANGED selected_uri http://uzbl.org/ + <-- print Config changed: selected_uri = http://uzbl.org/ ''' import sys @@ -40,20 +50,15 @@ def get_on_events(uzbl): def expand(cmd, args): - '''Replaces "%s %s %s.." with "arg1 arg2 arg3..". - - This could be improved by specifing explicitly which argument to substitue - for what by parsing "$@ $0 $1 $2 $3.." found in the command string.''' - - if '%s' not in cmd or not len(args): - return cmd + '''Replaces "%@ %1 %2 %3..." with "<all args> <arg 0> <arg 1>...".''' - if len(args) > 1: - for arg in args: - cmd = cmd.replace('%s', unicode(arg), 1) + if '%@' in cmd: + cmd = cmd.replace('%@', ' '.join(map(unicode, args))) - else: - cmd = cmd.replace('%s', unicode(args[0])) + for (index, arg) in enumerate(args): + index += 1 + if '%%%d' % index in cmd: + cmd = cmd.replace('%%%d' % index, unicode(arg)) return cmd |