]> git.lizzy.rs Git - micro.git/commitdiff
Set filetype to 'off' to disable completely
authorZachary Yedidia <zyedidia@gmail.com>
Fri, 3 Jan 2020 00:00:42 +0000 (19:00 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Fri, 3 Jan 2020 00:00:42 +0000 (19:00 -0500)
Ref #1427

cmd/micro/micro.go
internal/action/command.go
internal/buffer/backup.go
internal/buffer/buffer.go

index 910706a438030d583aa0809e8d4998a4f61bf080..3be216e7b69f1cb58811600778f87c521b02f07d 100644 (file)
@@ -174,23 +174,6 @@ func main() {
 
        screen.Init()
 
-       action.InitBindings()
-       action.InitCommands()
-
-       err = config.InitColorscheme()
-       if err != nil {
-               screen.TermMessage(err)
-       }
-
-       err = config.LoadAllPlugins()
-       if err != nil {
-               screen.TermMessage(err)
-       }
-       err = config.RunPluginFn("init")
-       if err != nil {
-               screen.TermMessage(err)
-       }
-
        // If we have an error, we can exit cleanly and not completely
        // mess up the terminal being worked in
        // In other words we need to shut down tcell before the program crashes
@@ -208,6 +191,23 @@ func main() {
                }
        }()
 
+       action.InitBindings()
+       action.InitCommands()
+
+       err = config.InitColorscheme()
+       if err != nil {
+               screen.TermMessage(err)
+       }
+
+       err = config.LoadAllPlugins()
+       if err != nil {
+               screen.TermMessage(err)
+       }
+       err = config.RunPluginFn("init")
+       if err != nil {
+               screen.TermMessage(err)
+       }
+
        b := LoadInput()
 
        if len(b) == 0 {
index 5947a63478aab0f1d5d184dc666e1c76eb0a009f..1d88d8cc60cbb6421cb1f0402af354b9ec924a51 100644 (file)
@@ -540,6 +540,7 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
                } else {
                        screen.Screen.EnableMouse()
                }
+               // autosave option has been removed
                // } else if option == "autosave" {
                //      if nativeValue.(float64) > 0 {
                //              config.SetAutoTime(int(nativeValue.(float64)))
@@ -554,9 +555,15 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
                        if option == pl.Name {
                                if nativeValue.(bool) && !pl.Loaded {
                                        pl.Load()
-                                       pl.Call("init")
+                                       _, err := pl.Call("init")
+                                       if err != nil && err != config.ErrNoSuchFunction {
+                                               screen.TermMessage(err)
+                                       }
                                } else if !nativeValue.(bool) && pl.Loaded {
-                                       pl.Call("deinit")
+                                       _, err := pl.Call("deinit")
+                                       if err != nil && err != config.ErrNoSuchFunction {
+                                               screen.TermMessage(err)
+                                       }
                                }
                        }
                }
index 1ba7acc37556281f43aa8cbdfb96f77fbb0f5380..8a2e24bef1cf0307d81f0be1062d0c83bc3d478c 100644 (file)
@@ -29,7 +29,7 @@ Options: [r]ecover, [i]gnore: `
 
 // Backup saves the current buffer to ConfigDir/backups
 func (b *Buffer) Backup(checkTime bool) error {
-       if !b.Settings["backup"].(bool) || b.Path == "" {
+       if !b.Settings["backup"].(bool) || b.Path == "" || b.Type != BTDefault {
                return nil
        }
 
@@ -78,7 +78,7 @@ func (b *Buffer) Backup(checkTime bool) error {
 
 // RemoveBackup removes any backup file associated with this buffer
 func (b *Buffer) RemoveBackup() {
-       if !b.Settings["backup"].(bool) || b.Path == "" {
+       if !b.Settings["backup"].(bool) || b.Path == "" || b.Type != BTDefault {
                return
        }
        f := config.ConfigDir + "/backups/" + util.EscapePath(b.AbsPath)
@@ -88,7 +88,7 @@ func (b *Buffer) RemoveBackup() {
 // ApplyBackup applies the corresponding backup file to this buffer (if one exists)
 // Returns true if a backup was applied
 func (b *Buffer) ApplyBackup(fsize int64) bool {
-       if b.Settings["backup"].(bool) && len(b.Path) > 0 {
+       if b.Settings["backup"].(bool) && len(b.Path) > 0 && b.Type == BTDefault {
                backupfile := config.ConfigDir + "/backups/" + util.EscapePath(b.AbsPath)
                if info, err := os.Stat(backupfile); err == nil {
                        backup, err := os.Open(backupfile)
index c9f56f50fa96cf4bb142fc94b1230972e324be9a..4c8743fbbb1c803abc7db0cf195555e909a94ef5 100644 (file)
@@ -453,8 +453,11 @@ func (b *Buffer) UpdateRules() {
        if !b.Type.Syntax {
                return
        }
-       syntaxFile := ""
        ft := b.Settings["filetype"].(string)
+       if ft == "off" {
+               return
+       }
+       syntaxFile := ""
        var header *highlight.Header
        for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) {
                data, err := f.Data()