@@ -423,6 +423,8 @@ bundle edit_line set_variable_values_ini(tab, sectionName)
423
423
# If the line is commented out with `#`, it gets uncommented first.
424
424
# Adds a new line if none exists.
425
425
#
426
+ # It does support = in value
427
+ #
426
428
# @param tab An associative array containing `tab[sectionName][LHS]="RHS"`.
427
429
# The value is not changed when the `RHS` is "dontchange"
428
430
# @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)
436
438
# Be careful if the index string contains funny chars
437
439
"cindex[$(index)]" string => canonify("$(index)");
438
440
441
+ # Escape the value so that it can be regexed
442
+ "ctab[$(index)]" string => escape("$($(tab)[$(sectionName)][$(index)])");
443
+
439
444
classes:
440
445
"edit_$(cindex[$(index)])" not => strcmp("$($(tab)[$(sectionName)][$(index)])","dontchange"),
441
446
comment => "Create conditions to make changes";
442
447
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";
457
450
458
451
insert_lines:
459
452
"[$(sectionName)]"
460
453
location => start,
461
454
comment => "Insert lines";
462
455
456
+ pass2::
463
457
"$(index)=$($(tab)[$(sectionName)][$(index)])"
464
458
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)])";
466
478
467
479
}
468
480
0 commit comments