diff --git a/TODO b/TODO index 511e46687..69ff3d4ce 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,6 @@ Bugs All kind of FIXMEs Changing completion models is awfully slow -values starting with ; need to be escaped Style ===== diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 05e4d05c1..9ecf6bc26 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -87,6 +87,11 @@ class ConfigManager(QObject): """Configuration manager for qutebrowser. + Class attributes: + SPECIAL_CHARS: Chars which need escaping when they occur as first char + in a line. + ESCAPE_CHAR: The char to be used for escaping + Attributes: sections: The configuration data as an OrderedDict. _configparser: A ReadConfigParser instance to load the config. @@ -103,6 +108,9 @@ class ConfigManager(QObject): Args: the changed section and option. """ + SPECIAL_CHARS = r'\#;[' + ESCAPE_CHAR = '\\' + changed = pyqtSignal(str, str) style_changed = pyqtSignal(str, str) @@ -190,6 +198,9 @@ class ConfigManager(QObject): """Get the option items as string for section.""" lines = [] for optname, option in section.items(): + for c in self.SPECIAL_CHARS: + if optname.startswith(c): + optname = optname.replace(c, self.ESCAPE_CHAR + c, 1) keyval = '{} = {}'.format(optname, option.get_first_value( startlayer='conf')) lines.append(keyval) @@ -205,6 +216,8 @@ class ConfigManager(QObject): if secname not in cp: continue for k, v in cp[secname].items(): + if k.startswith(self.ESCAPE_CHAR): + k = k[1:] try: self.set('conf', secname, k, v) except ValidationError as e: