]> git.lizzy.rs Git - micro.git/commitdiff
Make readonly and filetype local-only
authorZachary Yedidia <zyedidia@gmail.com>
Tue, 21 Jan 2020 03:03:32 +0000 (22:03 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Tue, 21 Jan 2020 03:03:32 +0000 (22:03 -0500)
internal/action/command.go
internal/config/settings.go
internal/util/util.go

index 4960ae9e960d3674938de62c40a784dfee1931b0..8b1d2aff1b51751c92fdb4731918733ee3ccb417 100644 (file)
@@ -527,45 +527,55 @@ func (h *BufPane) NewTabCmd(args []string) {
 }
 
 func SetGlobalOptionNative(option string, nativeValue interface{}) error {
-       config.GlobalSettings[option] = nativeValue
-
-       if option == "colorscheme" {
-               // LoadSyntaxFiles()
-               config.InitColorscheme()
-               for _, b := range buffer.OpenBuffers {
-                       b.UpdateRules()
+       local := false
+       for _, s := range config.LocalSettings {
+               if s == option {
+                       local = true
+                       break
                }
-       } 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)
+                                               }
                                        }
                                }
                        }
index c85340de6123e57a6e80f36d2258c54b8ef21668..cab3cdf4dd2cf17d7cc4b00e73589f999a58232c 100644 (file)
@@ -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()
index c3624bab8bf7eadbc6e762208b5e21cdfbb749e6..5f3890ec5f24f278af29b00317b094be6c2a4661 100644 (file)
@@ -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) {