diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index b539b5ebf..65eaa047a 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -57,6 +57,7 @@ class NewConfig: def __init__(self): self.config = configdata.configdata() + print(str(self)) def __getitem__(self, key): """Get a section from the config.""" @@ -65,21 +66,39 @@ class NewConfig: def __str__(self): """Get the whole config as a string.""" # FIXME empty lines get discared - # FIXME we should set subsequent_indent for config options later - wrapper = textwrap.TextWrapper( + normal_wrapper = textwrap.TextWrapper( width=72, replace_whitespace=False, break_long_words=False, break_on_hyphens=False, initial_indent='# ', subsequent_indent='# ') + option_wrapper = textwrap.TextWrapper( + width=72, replace_whitespace=False, break_long_words=False, + break_on_hyphens=False, initial_indent='# ', + subsequent_indent='# ') lines = [] - for par in map(wrapper.wrap, configdata.FIRST_COMMENT.splitlines()): + for par in map(normal_wrapper.wrap, + configdata.FIRST_COMMENT.splitlines()): lines += par for secname, section in self.config.items(): - lines.append('\n[{}]'.format(secname)) - for par in map(wrapper.wrap, - configdata.SECTION_DESC[secname].splitlines()): - lines += par + lines.append('\n\n[{}]\n'.format(secname)) + seclines = configdata.SECTION_DESC[secname].splitlines() + for secline in seclines: + if 'http://' in secline: + lines.append('# ' + secline) + else: + lines += normal_wrapper.wrap(secline) + lines.append('') for optname, option in section.items(): - # FIXME display option comment + try: + desc = self.config[secname].descriptions[optname] + except KeyError: + continue + wrapped_desc = [] + for descline in desc.splitlines(): + if 'http://' in descline: + wrapped_desc.append('# ' + descline) + else: + wrapped_desc += option_wrapper.wrap(descline) + lines.append('\n'.join(wrapped_desc)) lines.append('{} = {}'.format(optname, option)) return '\n'.join(lines) diff --git a/qutebrowser/config/sections.py b/qutebrowser/config/sections.py index 5f8f46204..022496575 100644 --- a/qutebrowser/config/sections.py +++ b/qutebrowser/config/sections.py @@ -34,6 +34,7 @@ class KeyValue: values: An OrderedDict with key as index and value as value. key: string value: SettingValue + descriptions: A dict with the description strings for the keys. """ @@ -47,9 +48,11 @@ class KeyValue: """ if args: + self.descriptions = {} self.values = OrderedDict() for (k, settingval, desc) in args: self.values[k] = settingval + self.descriptions[k] = desc def __getitem__(self, key): """Get the value for key. diff --git a/qutebrowser/config/templates.py b/qutebrowser/config/templates.py index 815a31b89..e1447e098 100644 --- a/qutebrowser/config/templates.py +++ b/qutebrowser/config/templates.py @@ -84,12 +84,16 @@ class ValueListSection: default: An OrderedDict with the default configuration as strings. After __init__, the strings become key/value types. types: A tuple for (keytype, valuetype) + descriptions: A dict with the description strings for the keys. + Currently a global empty dict to be compatible with + KeyValue section. """ values = None default = None types = None + descriptions = {} def __init__(self): """Wrap types over default values. Take care when overriding this."""