diff --git a/cmd/micro/initlua.go b/cmd/micro/initlua.go index 583085a0..ffe175a0 100644 --- a/cmd/micro/initlua.go +++ b/cmd/micro/initlua.go @@ -88,8 +88,8 @@ func luaImportMicroConfig() *lua.LTable { ulua.L.SetField(pkg, "RegisterCommonOption", luar.New(ulua.L, config.RegisterCommonOptionPlug)) ulua.L.SetField(pkg, "RegisterGlobalOption", luar.New(ulua.L, config.RegisterGlobalOptionPlug)) ulua.L.SetField(pkg, "GetGlobalOption", luar.New(ulua.L, config.GetGlobalOption)) - ulua.L.SetField(pkg, "SetGlobalOption", luar.New(ulua.L, action.SetGlobalOption)) - ulua.L.SetField(pkg, "SetGlobalOptionNative", luar.New(ulua.L, action.SetGlobalOptionNative)) + ulua.L.SetField(pkg, "SetGlobalOption", luar.New(ulua.L, action.SetGlobalOptionPlug)) + ulua.L.SetField(pkg, "SetGlobalOptionNative", luar.New(ulua.L, action.SetGlobalOptionNativePlug)) ulua.L.SetField(pkg, "ConfigDir", luar.New(ulua.L, config.ConfigDir)) return pkg diff --git a/internal/action/command.go b/internal/action/command.go index 3828afdb..bc26f0e9 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -630,7 +630,7 @@ func doSetGlobalOptionNative(option string, nativeValue any) error { return nil } -func SetGlobalOptionNative(option string, nativeValue any) error { +func SetGlobalOptionNative(option string, nativeValue any, writeToFile bool) error { if err := config.OptionIsValid(option, nativeValue); err != nil { return err } @@ -653,6 +653,10 @@ func SetGlobalOptionNative(option string, nativeValue any) error { delete(b.LocalSettings, option) } + if !writeToFile { + return nil + } + err := config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json")) if err != nil { if errors.Is(err, util.ErrOverwrite) { @@ -665,7 +669,7 @@ func SetGlobalOptionNative(option string, nativeValue any) error { return nil } -func SetGlobalOption(option, value string) error { +func SetGlobalOption(option, value string, writeToFile bool) error { if _, ok := config.GlobalSettings[option]; !ok { return config.ErrInvalidOption } @@ -675,7 +679,15 @@ func SetGlobalOption(option, value string) error { return err } - return SetGlobalOptionNative(option, nativeValue) + return SetGlobalOptionNative(option, nativeValue, writeToFile) +} + +func SetGlobalOptionNativePlug(option string, nativeValue any) error { + return SetGlobalOptionNative(option, nativeValue, false) +} + +func SetGlobalOptionPlug(option, value string) error { + return SetGlobalOption(option, value, false) } // ResetCmd resets a setting to its default value @@ -689,7 +701,7 @@ func (h *BufPane) ResetCmd(args []string) { defaults := config.DefaultAllSettings() if _, ok := defaults[option]; ok { - SetGlobalOptionNative(option, defaults[option]) + SetGlobalOptionNative(option, defaults[option], true) return } InfoBar.Error(config.ErrInvalidOption) @@ -705,7 +717,7 @@ func (h *BufPane) SetCmd(args []string) { option := args[0] value := args[1] - err := SetGlobalOption(option, value) + err := SetGlobalOption(option, value, true) if err == config.ErrInvalidOption { err := h.Buf.SetOption(option, value) if err != nil { @@ -761,7 +773,7 @@ func (h *BufPane) toggleOption(option string, local bool) error { return err } } else { - if err := SetGlobalOptionNative(option, newVal); err != nil { + if err := SetGlobalOptionNative(option, newVal, true); err != nil { return err } } diff --git a/runtime/help/plugins.md b/runtime/help/plugins.md index 8ce8fe6c..4e35b8c3 100644 --- a/runtime/help/plugins.md +++ b/runtime/help/plugins.md @@ -223,9 +223,9 @@ The packages and their contents are listed below (in Go type signatures): given plugin in the `GlobalSettings` map. - `SetGlobalOption(option, value string) error`: sets an option to a - given value. Same as using the `> set` command. This will try to convert - the value into the proper type for the option. Can return an error if the - option name is not valid, or the value can not be converted. + given value. This will try to convert the value into the proper + type for the option. Can return an error if the option name is not + valid, or the value can not be converted. - `SetGlobalOptionNative(option string, value any) error`: sets an option to a given value, where the type of value is the actual