From 6abb42a0665bc532ead67ec838823e10684f0de5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 19 Feb 2018 06:25:28 +0100 Subject: [PATCH] Make saving in autoconfig.yml work --- qutebrowser/config/config.py | 4 ++-- qutebrowser/config/configfiles.py | 14 +++++++++++--- qutebrowser/config/configutils.py | 6 ++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index b3ebc97c3..13f745216 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -415,8 +415,8 @@ class Config(QObject): file. """ for name, values in self._values.items(): - cleared = values.clear() - if cleared: + if values: + values.clear() self.changed.emit(name) if save_yaml: diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index f2e104c05..d7ba4493c 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -115,10 +115,17 @@ class YamlConfig(QObject): if not self._dirty: return - data = {'config_version': self.VERSION, 'global': self._values} - for pattern, values in sorted(self._values.items()): - data[str(pattern)] = values + settings = {} + for name, values in sorted(self._values.items()): + if not values: + continue + settings[name] = {} + for scoped in values: + key = ('global' if scoped.pattern is None + else str(scoped.pattern)) + settings[name][key] = scoped.value + data = {'config_version': self.VERSION, 'settings': settings} with qtutils.savefile_open(self._filename) as f: f.write(textwrap.dedent(""" # DO NOT edit this file by hand, qutebrowser will overwrite it. @@ -231,6 +238,7 @@ class YamlConfig(QObject): def set_obj(self, name, value, *, pattern=None): """Set the given setting to the given value.""" self._values[name].add(value, pattern) + self._mark_changed() def unset(self, name, *, pattern=None): """Remove the given option name if it's configured.""" diff --git a/qutebrowser/config/configutils.py b/qutebrowser/config/configutils.py index cae1de7b7..ef6e87359 100644 --- a/qutebrowser/config/configutils.py +++ b/qutebrowser/config/configutils.py @@ -73,6 +73,10 @@ class Values: """ yield from self._values + def __bool__(self): + """Check whether this value is customized.""" + return bool(self._values) + def add(self, value, pattern=None): """Add a value with the given pattern to the list of values. @@ -92,9 +96,7 @@ class Values: def clear(self): """Clear all customization for this value.""" - had_values = bool(self._values) self._values = [] - return had_values def _get_fallback(self): """Get the fallback global/default value."""