From 568e2e24a7bbaf2ba279aaa5ddcd3c25e5902ec8 Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Tue, 22 Sep 2009 16:41:09 +0800 Subject: on_event now transforms "%@ %1 %2.." into " .." --- examples/data/uzbl/scripts/plugins/on_event.py | 41 +++++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'examples/data/uzbl/scripts') 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 " ...".''' - 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 -- cgit v1.2.3