core: add option weechat.look.save_config_changed_only (issue #19) #1371
+17
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains a simple change to save changed options only as an attempt at fixing issue #19. It works for normal options but has many problems and far from production ready.
Use at your own risk! While experimenting, I managed to completely break WeeChat (and the existing configuration) in multiple ways (see problems below).
Problems
config_file_new_section
/weechat_config_new_section
allows specifying acallback_write
which, if specified, is used instead of the default config section writer. Even though the default config section writer can ignore unchanged options, each section with a custom writer would also have to duplicate that logic for consistent behavior.Luckily most WeeChat core, plugins and scripts that create their own config files and sections don't use a custom write callback. Of those that do, most write no options by default, e.g. the
filters
section has its own write callback but by default no filters exist so no non-default options get written anyway. The remaining cases need to be carefully analyzed (and potentially somehow fixed).bars
section consists of bar options. They are unusual because when they're read from the config file, the read values don't become option values but instead option default values. This means that they appear as unchanged from default values, even though the user might have changed them previously. Writing such config again would omit those options and thus user customizations!It also affects default bars because they get created once and later are indistinguishable from any custom bars, breaking even the default bars. This PR uses a condition to always write all options in the bars section to avoid this issue.
Similar problems might affect other sections, e.g. triggers.
key*
sections consists of key bindings for different contexts. They are written using special write callback which (in this PR) doesn't ignore unchanged key bindings. If unchanged key bindings were not written, no default keys would exist because the default keys are all written to the config initially. It would make WeeChat completely unusable because even enter is unbound and nothing can be sent/executed.