Skip to content

Commit 7a250b7

Browse files
Changing behavior for SetGlobalOption*() for lua to not write to file
1 parent b39b5b5 commit 7a250b7

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

cmd/micro/initlua.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func luaImportMicroConfig() *lua.LTable {
8888
ulua.L.SetField(pkg, "RegisterCommonOption", luar.New(ulua.L, config.RegisterCommonOptionPlug))
8989
ulua.L.SetField(pkg, "RegisterGlobalOption", luar.New(ulua.L, config.RegisterGlobalOptionPlug))
9090
ulua.L.SetField(pkg, "GetGlobalOption", luar.New(ulua.L, config.GetGlobalOption))
91-
ulua.L.SetField(pkg, "SetGlobalOption", luar.New(ulua.L, action.SetGlobalOption))
92-
ulua.L.SetField(pkg, "SetGlobalOptionNative", luar.New(ulua.L, action.SetGlobalOptionNative))
91+
ulua.L.SetField(pkg, "SetGlobalOption", luar.New(ulua.L, action.SetGlobalOptionPlug))
92+
ulua.L.SetField(pkg, "SetGlobalOptionNative", luar.New(ulua.L, action.SetGlobalOptionNativePlug))
9393
ulua.L.SetField(pkg, "ConfigDir", luar.New(ulua.L, config.ConfigDir))
9494

9595
return pkg

internal/action/command.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ func doSetGlobalOptionNative(option string, nativeValue any) error {
630630
return nil
631631
}
632632

633-
func SetGlobalOptionNative(option string, nativeValue any) error {
633+
func SetGlobalOptionNative(option string, nativeValue any, writeToFile bool) error {
634634
if err := config.OptionIsValid(option, nativeValue); err != nil {
635635
return err
636636
}
@@ -653,6 +653,10 @@ func SetGlobalOptionNative(option string, nativeValue any) error {
653653
delete(b.LocalSettings, option)
654654
}
655655

656+
if !writeToFile {
657+
return nil
658+
}
659+
656660
err := config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
657661
if err != nil {
658662
if errors.Is(err, util.ErrOverwrite) {
@@ -665,7 +669,7 @@ func SetGlobalOptionNative(option string, nativeValue any) error {
665669
return nil
666670
}
667671

668-
func SetGlobalOption(option, value string) error {
672+
func SetGlobalOption(option, value string, writeToFile bool) error {
669673
if _, ok := config.GlobalSettings[option]; !ok {
670674
return config.ErrInvalidOption
671675
}
@@ -675,7 +679,15 @@ func SetGlobalOption(option, value string) error {
675679
return err
676680
}
677681

678-
return SetGlobalOptionNative(option, nativeValue)
682+
return SetGlobalOptionNative(option, nativeValue, writeToFile)
683+
}
684+
685+
func SetGlobalOptionNativePlug(option string, nativeValue any) error {
686+
return SetGlobalOptionNative(option, nativeValue, false)
687+
}
688+
689+
func SetGlobalOptionPlug(option, value string) error {
690+
return SetGlobalOption(option, value, false)
679691
}
680692

681693
// ResetCmd resets a setting to its default value
@@ -689,7 +701,7 @@ func (h *BufPane) ResetCmd(args []string) {
689701
defaults := config.DefaultAllSettings()
690702

691703
if _, ok := defaults[option]; ok {
692-
SetGlobalOptionNative(option, defaults[option])
704+
SetGlobalOptionNative(option, defaults[option], true)
693705
return
694706
}
695707
InfoBar.Error(config.ErrInvalidOption)
@@ -705,7 +717,7 @@ func (h *BufPane) SetCmd(args []string) {
705717
option := args[0]
706718
value := args[1]
707719

708-
err := SetGlobalOption(option, value)
720+
err := SetGlobalOption(option, value, true)
709721
if err == config.ErrInvalidOption {
710722
err := h.Buf.SetOption(option, value)
711723
if err != nil {
@@ -761,7 +773,7 @@ func (h *BufPane) toggleOption(option string, local bool) error {
761773
return err
762774
}
763775
} else {
764-
if err := SetGlobalOptionNative(option, newVal); err != nil {
776+
if err := SetGlobalOptionNative(option, newVal, true); err != nil {
765777
return err
766778
}
767779
}

runtime/help/plugins.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ The packages and their contents are listed below (in Go type signatures):
223223
given plugin in the `GlobalSettings` map.
224224

225225
- `SetGlobalOption(option, value string) error`: sets an option to a
226-
given value. Same as using the `> set` command. This will try to convert
227-
the value into the proper type for the option. Can return an error if the
228-
option name is not valid, or the value can not be converted.
226+
given value. This will try to convert the value into the proper
227+
type for the option. Can return an error if the option name is not
228+
valid, or the value can not be converted.
229229

230230
- `SetGlobalOptionNative(option string, value any) error`: sets
231231
an option to a given value, where the type of value is the actual

0 commit comments

Comments
 (0)