@@ -423,6 +423,8 @@ bundle edit_line set_variable_values_ini(tab, sectionName)
423423# If the line is commented out with `#`, it gets uncommented first.
424424# Adds a new line if none exists.
425425#
426+ # It does support = in value
427+ #
426428# @param tab An associative array containing `tab[sectionName][LHS]="RHS"`.
427429# The value is not changed when the `RHS` is "dontchange"
428430# @param sectionName The section in the file within which values should be
@@ -436,33 +438,43 @@ bundle edit_line set_variable_values_ini(tab, sectionName)
436438 # Be careful if the index string contains funny chars
437439 "cindex[$(index)]" string => canonify("$(index)");
438440
441+ # Escape the value so that it can be regexed
442+ "ctab[$(index)]" string => escape("$($(tab)[$(sectionName)][$(index)])");
443+
439444 classes:
440445 "edit_$(cindex[$(index)])" not => strcmp("$($(tab)[$(sectionName)][$(index)])","dontchange"),
441446 comment => "Create conditions to make changes";
442447
443- field_edits:
444-
445- # If the line is there, but commented out, first uncomment it
446- "#+\s*$(index)\s*=.*"
447- select_region => INI_section(escape("$(sectionName)")),
448- edit_field => col("\s*=\s*","1","$(index)","set"),
449- if => "edit_$(cindex[$(index)])";
450-
451- # match a line starting like the key something
452- "\s*$(index)\s*=.*"
453- edit_field => col("\s*=\s*","2","$($(tab)[$(sectionName)][$(index)])","set"),
454- select_region => INI_section(escape("$(sectionName)")),
455- classes => results("bundle", "set_variable_values_ini_not_$(cindex[$(index)])"),
456- if => "edit_$(cindex[$(index)])";
448+ "pass2" expression => "pass1";
449+ "pass1" expression => "any";
457450
458451 insert_lines:
459452 "[$(sectionName)]"
460453 location => start,
461454 comment => "Insert lines";
462455
456+ pass2::
463457 "$(index)=$($(tab)[$(sectionName)][$(index)])"
464458 select_region => INI_section(escape("$(sectionName)")),
465- if => "!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired).edit_$(cindex[$(index)])";
459+ if => "edit_$(cindex[$(index)])";
460+
461+ replace_patterns:
462+ # If the line is commented out, uncomment and replace with
463+ # the correct value
464+ "^\s*#\s*($(index)\s*=\s*.*)$"
465+ comment => "If we find a commented entry we uncomment it",
466+ select_region => INI_section(escape("$(set_variable_values_ini.sectionName)")),
467+ replace_with => value("$(index)=$($(tab)[$(sectionName)][$(index)])"),
468+ if => "edit_$(cindex[$(index)]).!set_variable_values_ini_not_$(cindex[$(index)])_reached";
469+
470+ # If the line is there with the wrong value, replace with
471+ # the correct value
472+ "^\s*($(index)\s*=\s*(?!$(ctab[$(index)])$).*)$"
473+ comment => "Correct the value $(index)",
474+ replace_with => value("$(index)=$($(tab)[$(sectionName)][$(index)])"),
475+ select_region => INI_section(escape("$(set_variable_values_ini.sectionName)")),
476+ classes => results("bundle", "set_variable_values_ini_not_$(cindex[$(index)])"),
477+ if => "edit_$(cindex[$(index)])";
466478
467479}
468480
0 commit comments