mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-15 21:37:09 +09:00
Changing behavior for SetGlobalOption*() for lua to not write to file
This commit is contained in:
@@ -88,8 +88,8 @@ func luaImportMicroConfig() *lua.LTable {
|
|||||||
ulua.L.SetField(pkg, "RegisterCommonOption", luar.New(ulua.L, config.RegisterCommonOptionPlug))
|
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, "RegisterGlobalOption", luar.New(ulua.L, config.RegisterGlobalOptionPlug))
|
||||||
ulua.L.SetField(pkg, "GetGlobalOption", luar.New(ulua.L, config.GetGlobalOption))
|
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, "SetGlobalOption", luar.New(ulua.L, action.SetGlobalOptionPlug))
|
||||||
ulua.L.SetField(pkg, "SetGlobalOptionNative", luar.New(ulua.L, action.SetGlobalOptionNative))
|
ulua.L.SetField(pkg, "SetGlobalOptionNative", luar.New(ulua.L, action.SetGlobalOptionNativePlug))
|
||||||
ulua.L.SetField(pkg, "ConfigDir", luar.New(ulua.L, config.ConfigDir))
|
ulua.L.SetField(pkg, "ConfigDir", luar.New(ulua.L, config.ConfigDir))
|
||||||
|
|
||||||
return pkg
|
return pkg
|
||||||
|
|||||||
@@ -630,7 +630,7 @@ func doSetGlobalOptionNative(option string, nativeValue any) error {
|
|||||||
return nil
|
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 {
|
if err := config.OptionIsValid(option, nativeValue); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -653,6 +653,10 @@ func SetGlobalOptionNative(option string, nativeValue any) error {
|
|||||||
delete(b.LocalSettings, option)
|
delete(b.LocalSettings, option)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !writeToFile {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err := config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
|
err := config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrOverwrite) {
|
if errors.Is(err, util.ErrOverwrite) {
|
||||||
@@ -665,7 +669,7 @@ func SetGlobalOptionNative(option string, nativeValue any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetGlobalOption(option, value string) error {
|
func SetGlobalOption(option, value string, writeToFile bool) error {
|
||||||
if _, ok := config.GlobalSettings[option]; !ok {
|
if _, ok := config.GlobalSettings[option]; !ok {
|
||||||
return config.ErrInvalidOption
|
return config.ErrInvalidOption
|
||||||
}
|
}
|
||||||
@@ -675,7 +679,15 @@ func SetGlobalOption(option, value string) error {
|
|||||||
return err
|
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
|
// ResetCmd resets a setting to its default value
|
||||||
@@ -689,7 +701,7 @@ func (h *BufPane) ResetCmd(args []string) {
|
|||||||
defaults := config.DefaultAllSettings()
|
defaults := config.DefaultAllSettings()
|
||||||
|
|
||||||
if _, ok := defaults[option]; ok {
|
if _, ok := defaults[option]; ok {
|
||||||
SetGlobalOptionNative(option, defaults[option])
|
SetGlobalOptionNative(option, defaults[option], true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
InfoBar.Error(config.ErrInvalidOption)
|
InfoBar.Error(config.ErrInvalidOption)
|
||||||
@@ -705,7 +717,7 @@ func (h *BufPane) SetCmd(args []string) {
|
|||||||
option := args[0]
|
option := args[0]
|
||||||
value := args[1]
|
value := args[1]
|
||||||
|
|
||||||
err := SetGlobalOption(option, value)
|
err := SetGlobalOption(option, value, true)
|
||||||
if err == config.ErrInvalidOption {
|
if err == config.ErrInvalidOption {
|
||||||
err := h.Buf.SetOption(option, value)
|
err := h.Buf.SetOption(option, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -761,7 +773,7 @@ func (h *BufPane) toggleOption(option string, local bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := SetGlobalOptionNative(option, newVal); err != nil {
|
if err := SetGlobalOptionNative(option, newVal, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,9 +223,9 @@ The packages and their contents are listed below (in Go type signatures):
|
|||||||
given plugin in the `GlobalSettings` map.
|
given plugin in the `GlobalSettings` map.
|
||||||
|
|
||||||
- `SetGlobalOption(option, value string) error`: sets an option to a
|
- `SetGlobalOption(option, value string) error`: sets an option to a
|
||||||
given value. Same as using the `> set` command. This will try to convert
|
given value. This will try to convert the value into the proper
|
||||||
the value into the proper type for the option. Can return an error if the
|
type for the option. Can return an error if the option name is not
|
||||||
option name is not valid, or the value can not be converted.
|
valid, or the value can not be converted.
|
||||||
|
|
||||||
- `SetGlobalOptionNative(option string, value any) error`: sets
|
- `SetGlobalOptionNative(option string, value any) error`: sets
|
||||||
an option to a given value, where the type of value is the actual
|
an option to a given value, where the type of value is the actual
|
||||||
|
|||||||
Reference in New Issue
Block a user