From 0abe4270262ef287799fbb509b1860e9619cf27e Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 20 Jan 2020 22:03:32 -0500 Subject: [PATCH] Make readonly and filetype local-only --- internal/action/command.go | 84 +++++++++++++++++++++---------------- internal/config/settings.go | 9 ++++ internal/util/util.go | 1 - 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/internal/action/command.go b/internal/action/command.go index 4960ae9e..8b1d2aff 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -527,45 +527,55 @@ func (h *BufPane) NewTabCmd(args []string) { } func SetGlobalOptionNative(option string, nativeValue interface{}) error { - config.GlobalSettings[option] = nativeValue + local := false + for _, s := range config.LocalSettings { + if s == option { + local = true + break + } + } - if option == "colorscheme" { - // LoadSyntaxFiles() - config.InitColorscheme() - for _, b := range buffer.OpenBuffers { - b.UpdateRules() - } - } else if option == "infobar" || option == "keymenu" { - Tabs.Resize() - } else if option == "mouse" { - if !nativeValue.(bool) { - screen.Screen.DisableMouse() + if !local { + config.GlobalSettings[option] = nativeValue + + if option == "colorscheme" { + // LoadSyntaxFiles() + config.InitColorscheme() + for _, b := range buffer.OpenBuffers { + b.UpdateRules() + } + } else if option == "infobar" || option == "keymenu" { + Tabs.Resize() + } else if option == "mouse" { + if !nativeValue.(bool) { + screen.Screen.DisableMouse() + } else { + screen.Screen.EnableMouse() + } + // autosave option has been removed + // } else if option == "autosave" { + // if nativeValue.(float64) > 0 { + // config.SetAutoTime(int(nativeValue.(float64))) + // config.StartAutoSave() + // } else { + // config.SetAutoTime(0) + // } + } else if option == "paste" { + screen.Screen.SetPaste(nativeValue.(bool)) } else { - screen.Screen.EnableMouse() - } - // autosave option has been removed - // } else if option == "autosave" { - // if nativeValue.(float64) > 0 { - // config.SetAutoTime(int(nativeValue.(float64))) - // config.StartAutoSave() - // } else { - // config.SetAutoTime(0) - // } - } else if option == "paste" { - screen.Screen.SetPaste(nativeValue.(bool)) - } else { - for _, pl := range config.Plugins { - if option == pl.Name { - if nativeValue.(bool) && !pl.Loaded { - pl.Load() - _, err := pl.Call("init") - if err != nil && err != config.ErrNoSuchFunction { - screen.TermMessage(err) - } - } else if !nativeValue.(bool) && pl.Loaded { - _, err := pl.Call("deinit") - if err != nil && err != config.ErrNoSuchFunction { - screen.TermMessage(err) + for _, pl := range config.Plugins { + if option == pl.Name { + if nativeValue.(bool) && !pl.Loaded { + pl.Load() + _, err := pl.Call("init") + if err != nil && err != config.ErrNoSuchFunction { + screen.TermMessage(err) + } + } else if !nativeValue.(bool) && pl.Loaded { + _, err := pl.Call("deinit") + if err != nil && err != config.ErrNoSuchFunction { + screen.TermMessage(err) + } } } } diff --git a/internal/config/settings.go b/internal/config/settings.go index c85340de..cab3cdf4 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -212,6 +212,8 @@ func DefaultCommonSettings() map[string]interface{} { return commonsettings } +// a list of settings that should only be globally modified and their +// default values var defaultGlobalSettings = map[string]interface{}{ // "autosave": float64(0), "colorscheme": "default", @@ -223,6 +225,12 @@ var defaultGlobalSettings = map[string]interface{}{ "sucmd": "sudo", } +// a list of settings that should never be globally modified +var LocalSettings = []string{ + "filetype", + "readonly", +} + // DefaultGlobalSettings returns the default global settings for micro // Note that colorscheme is a global only option func DefaultGlobalSettings() map[string]interface{} { @@ -249,6 +257,7 @@ func DefaultAllSettings() map[string]interface{} { return allsettings } +// GetNativeValue parses and validates a value for a given option func GetNativeValue(option string, realValue interface{}, value string) (interface{}, error) { var native interface{} kind := reflect.TypeOf(realValue).Kind() diff --git a/internal/util/util.go b/internal/util/util.go index c3624bab..5f3890ec 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -275,7 +275,6 @@ func MakeRelative(path, base string) (string, error) { return path, nil } -// TODO: consider changing because of snap segfault // ReplaceHome takes a path as input and replaces ~ at the start of the path with the user's // home directory. Does nothing if the path does not start with '~'. func ReplaceHome(path string) (string, error) {