aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/uzbl/plugins/mode.py
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-11-24 18:51:33 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-11-24 18:51:33 +0800
commit0e7d35e4512bf576a2bd3096c24905a711ab2666 (patch)
tree358973f9011cee5275fd59c8a9f6c8d14fc4dfca /examples/data/uzbl/plugins/mode.py
parent2c23115387a668eff89e7dc048f565a3971174e0 (diff)
Mode plugin cleanup & removed hardcoded KEY_PRESS action.
Diffstat (limited to 'examples/data/uzbl/plugins/mode.py')
-rw-r--r--examples/data/uzbl/plugins/mode.py43
1 files changed, 19 insertions, 24 deletions
diff --git a/examples/data/uzbl/plugins/mode.py b/examples/data/uzbl/plugins/mode.py
index e7705a0..74e805a 100644
--- a/examples/data/uzbl/plugins/mode.py
+++ b/examples/data/uzbl/plugins/mode.py
@@ -7,7 +7,6 @@ UZBLS = {}
DEFAULTS = {
'mode': '',
- 'default': '',
'modes': {
'insert': {
'forward_keys': True,
@@ -20,8 +19,8 @@ DEFAULTS = {
'modcmd_updates': True,
'indicator': 'C'}}}
-_RE_FINDSPACES = re.compile("\s+")
-
+FINDSPACES = re.compile("\s+")
+VALID_KEY = re.compile("^[\w_]+$").match
def error(msg):
sys.stderr.write("mode plugin: error: %s\n" % msg)
@@ -55,24 +54,22 @@ def get_mode(uzbl):
return get_mode_dict(uzbl)['mode']
-def key_press(uzbl, key):
- if key != "Escape":
- return
-
- set_mode(uzbl)
-
-
def set_mode(uzbl, mode=None):
mode_dict = get_mode_dict(uzbl)
+ config = uzbl.get_config()
+
if mode is None:
- if not mode_dict['default']:
- return error("no default mode to fallback on")
+ if 'default_mode' not in config:
+ return
- mode = mode_dict['default']
+ mode = config['default_mode']
+
+ if not VALID_KEY(mode):
+ raise KeyError("invalid mode name: %r" % mode)
- config = uzbl.get_config()
if 'mode' not in config or config['mode'] != mode:
config['mode'] = mode
+ return
mode_dict['mode'] = mode
mode_config = get_mode_config(uzbl, mode)
@@ -92,31 +89,30 @@ def set_mode(uzbl, mode=None):
def config_changed(uzbl, key, value):
+ value = None if not value else value
if key == 'default_mode':
- mode_dict = get_mode_dict(uzbl)
- mode_dict['default'] = value
- if value and not mode_dict['mode']:
+ if not get_mode(uzbl):
set_mode(uzbl, value)
elif key == 'mode':
- if not value:
- value = None
-
set_mode(uzbl, value)
def mode_config(uzbl, args):
- split = map(unicode.strip, _RE_FINDSPACES.split(args.lstrip(), 1))
+ split = map(unicode.strip, FINDSPACES.split(args.lstrip(), 1))
if len(split) != 2:
- return error("invalid MODE_CONFIG syntax: %r" % args)
+ raise SyntaxError('invalid config syntax: %r' % args)
mode, set = split
split = map(unicode.strip, set.split('=', 1))
if len(split) != 2:
- return error("invalid MODE_CONFIG set command: %r" % args)
+ raise SyntaxError('invalid set syntax: %r' % args)
key, value = split
+ if not VALID_KEY(key):
+ raise KeyError('invalid config key: %r' % key)
+
mode_config = get_mode_config(uzbl, mode)
mode_config[key] = value
@@ -150,7 +146,6 @@ def init(uzbl):
connects = {'CONFIG_CHANGED': config_changed,
'INSTANCE_EXIT': del_instance,
'INSTANCE_START': add_instance,
- 'KEY_PRESS': key_press,
'MODE_CONFIG': mode_config,
'LOAD_START': load_reset,
'TOGGLE_MODES': toggle_modes}