summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2013-02-24 22:40:23 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2013-03-03 13:49:45 +0000
commitca3e0c9c1f11ad9afc5094d33e377742783d3b46 (patch)
tree1d8e84e6d60584f843259a72429a04aeedc1976e /alot
parent33da123cc13327596e14574a940451b04dd77fe1 (diff)
postpone binding if candidates with same prefix exist
This ensures that commandlines that are bound to a key are not fired right away but wait a little (config option 'input_timeout') in case there are other bindings with this key as prefix. This allows to bind for instance 'g g' to move up while at the same time one can bind 'g' to global replies. Without this change, the 'g' binding would be fired right away.
Diffstat (limited to 'alot')
-rw-r--r--alot/settings/manager.py8
-rw-r--r--alot/ui.py31
2 files changed, 25 insertions, 14 deletions
diff --git a/alot/settings/manager.py b/alot/settings/manager.py
index 2b9adde9..9a74080a 100644
--- a/alot/settings/manager.py
+++ b/alot/settings/manager.py
@@ -313,7 +313,13 @@ class SettingsManager(object):
candidates = self._bindings.scalars
if mode != 'global':
candidates = candidates + self._bindings[mode].scalars
- return [s for s in candidates if s.startswith(prefix)]
+ if prefix is not None:
+ prefixs = prefix + ' '
+ cand = filter(lambda x: x.startswith(prefixs), candidates)
+ if prefix in candidates:
+ candidates = cand + [prefix]
+ else: candidates = cand
+ return candidates
def get_keybinding(self, mode, key):
"""look up keybinding from `MODE-maps` sections
diff --git a/alot/ui.py b/alot/ui.py
index 9a0dda86..f4a59e34 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -117,6 +117,16 @@ class UI(object):
self.input_queue = []
self.update()
+ def fire(ignored, cmdline):
+ clear()
+ logging.debug("cmdline: '%s'" % cmdline)
+ # move keys are always passed
+ if cmdline.startswith('move ') or not self._locked:
+ try:
+ self.apply_commandline(cmdline)
+ except CommandParseError, e:
+ self.notify(e.message, priority='error')
+
key = keys[0]
self.input_queue.append(key)
keyseq = ' '.join(self.input_queue)
@@ -127,19 +137,14 @@ class UI(object):
# get binding and interpret it if non-null
cmdline = settings.get_keybinding(self.mode, keyseq)
if cmdline:
- clear()
- logging.debug("cmdline: '%s'" % cmdline)
- # move keys are always passed
- if cmdline.startswith('move '):
- movecmd = cmdline[5:].strip()
- logging.debug("GOT MOVE: '%s'" % movecmd)
- if movecmd in ['up', 'down', 'page up', 'page down']:
- return [movecmd]
- elif not self._locked:
- try:
- self.apply_commandline(cmdline)
- except CommandParseError, e:
- self.notify(e.message, priority='error')
+ if len(candidates) > 1:
+ timeout = float(settings.get('input_timeout'))
+ if self._alarm is not None:
+ self.mainloop.remove_alarm(self._alarm)
+ self._alarm = self.mainloop.set_alarm_in(timeout, fire, cmdline)
+ else:
+ fire(self.mainloop, cmdline)
+
elif not candidates:
# case: no sequence with prefix keyseq is mapped
# just clear the input queue