From a796482c835e2a2e44c830938c3d1e6985ead9e5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 12 Sep 2014 07:33:52 +0200 Subject: [PATCH] Support !-keysections, don't bind leave-mode in normal mode. --- qutebrowser/config/configdata.py | 6 +++++- qutebrowser/config/keyconfparser.py | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 500bd9628..a780d9f93 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -797,6 +797,10 @@ KEY_FIRST_COMMENT = """ # All blank lines and lines starting with '#' are ignored. # Inline-comments are not permitted. # +# keymode is a comma separated list of modes in which the keybinding should be +# active. If keymode starts with !, the keybinding is active in all modes +# except the listed modes. +# # For special keys (can't be part of a keychain), enclose them in `<`...`>`. # For modifiers, you can use either `-` or `+` as delimiters, and these names: # @@ -854,7 +858,7 @@ KEY_SECTION_DESC = { KEY_DATA = collections.OrderedDict([ - ('all', collections.OrderedDict([ + ('!normal', collections.OrderedDict([ ('leave-mode', ['', '']), ])), diff --git a/qutebrowser/config/keyconfparser.py b/qutebrowser/config/keyconfparser.py index 46654f478..108941b48 100644 --- a/qutebrowser/config/keyconfparser.py +++ b/qutebrowser/config/keyconfparser.py @@ -175,7 +175,15 @@ class KeyConfigParser(QObject): def _normalize_sectname(self, s): """Normalize a section string like 'foo, bar,baz' to 'bar,baz,foo'.""" - return ','.join(sorted(s.split(','))) + if s.startswith('!'): + inverted = True + s = s[1:] + else: + inverted = False + sections = ','.join(sorted(s.split(','))) + if inverted: + sections = '!' + sections + return sections def _load_default(self): """Load the built-in default keybindings.""" @@ -246,8 +254,14 @@ class KeyConfigParser(QObject): """Get a dict with all merged keybindings for a section.""" bindings = {} for sectstring, d in self.keybindings.items(): + if sectstring.startswith('!'): + inverted = True + sectstring = sectstring[1:] + else: + inverted = False sects = [s.strip() for s in sectstring.split(',')] - if any(s == section for s in sects): + matches = any(s == section for s in sects) + if (not inverted and matches) or (inverted and not matches): bindings.update(d) try: bindings.update(self.keybindings['all'])