]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/micro.go
Correctly detect synatx ft from header
[micro.git] / cmd / micro / micro.go
index b7f7721cac8a239f186ed7c2696d6da32f029e88..663b217b1a4d0c11a58b6dd149031d278e3e298b 100644 (file)
@@ -84,13 +84,14 @@ func LoadInput() []*Buffer {
        var filename string
        var input []byte
        var err error
-       var buffers []*Buffer
+       args := flag.Args()
+       buffers := make([]*Buffer, 0, len(args))
 
-       if len(flag.Args()) > 0 {
+       if len(args) > 0 {
                // Option 1
                // We go through each file and load it
-               for i := 0; i < len(flag.Args()); i++ {
-                       filename = flag.Args()[i]
+               for i := 0; i < len(args); i++ {
+                       filename = args[i]
 
                        // Check that the file exists
                        var input *os.File
@@ -110,9 +111,9 @@ func LoadInput() []*Buffer {
                        }
                        // If the file didn't exist, input will be empty, and we'll open an empty buffer
                        if input != nil {
-                               buffers = append(buffers, NewBuffer(input, filename))
+                               buffers = append(buffers, NewBuffer(input, FSize(input), filename))
                        } else {
-                               buffers = append(buffers, NewBuffer(strings.NewReader(""), filename))
+                               buffers = append(buffers, NewBufferFromString("", filename))
                        }
                }
        } else if !isatty.IsTerminal(os.Stdin.Fd()) {
@@ -124,10 +125,10 @@ func LoadInput() []*Buffer {
                        TermMessage("Error reading from stdin: ", err)
                        input = []byte{}
                }
-               buffers = append(buffers, NewBuffer(strings.NewReader(string(input)), filename))
+               buffers = append(buffers, NewBufferFromString(string(input), filename))
        } else {
                // Option 3, just open an empty buffer
-               buffers = append(buffers, NewBuffer(strings.NewReader(string(input)), filename))
+               buffers = append(buffers, NewBufferFromString(string(input), filename))
        }
 
        return buffers
@@ -201,7 +202,14 @@ func InitScreen() {
 // RedrawAll redraws everything -- all the views and the messenger
 func RedrawAll() {
        messenger.Clear()
-       screen.Clear()
+
+       w, h := screen.Size()
+       for x := 0; x < w; x++ {
+               for y := 0; y < h; y++ {
+                       screen.SetContent(x, y, ' ', nil, defStyle)
+               }
+       }
+
        for _, v := range tabs[curTab].views {
                v.Display()
        }
@@ -223,14 +231,11 @@ func LoadAll() {
        InitCommands()
        InitBindings()
 
-       LoadSyntaxFiles()
+       InitColorscheme()
 
        for _, tab := range tabs {
                for _, v := range tab.views {
                        v.Buf.UpdateRules()
-                       if v.Buf.Settings["syntax"].(bool) {
-                               v.matches = Match(v)
-                       }
                }
        }
 }
@@ -302,6 +307,7 @@ func main() {
        // This is used for sending the user messages in the bottom of the editor
        messenger = new(Messenger)
        messenger.history = make(map[string][]string)
+       InitColorscheme()
 
        // Now we load the input
        buffers := LoadInput()
@@ -309,6 +315,7 @@ func main() {
                screen.Fini()
                os.Exit(1)
        }
+
        for _, buf := range buffers {
                // For each buffer we create a new tab and place the view in that tab
                tab := NewTabFromView(NewView(buf))
@@ -372,6 +379,7 @@ func main() {
        L.SetGlobal("ListRuntimeFiles", luar.New(L, PluginListRuntimeFiles))
        L.SetGlobal("AddRuntimeFile", luar.New(L, PluginAddRuntimeFile))
        L.SetGlobal("AddRuntimeFilesFromDirectory", luar.New(L, PluginAddRuntimeFilesFromDirectory))
+       L.SetGlobal("AddRuntimeFileFromMemory", luar.New(L, PluginAddRuntimeFileFromMemory))
 
        jobs = make(chan JobFunction, 100)
        events = make(chan tcell.Event, 100)
@@ -379,13 +387,8 @@ func main() {
 
        LoadPlugins()
 
-       // Load the syntax files, including the colorscheme
-       LoadSyntaxFiles()
-
        for _, t := range tabs {
                for _, v := range t.views {
-                       v.Buf.FindFileType()
-                       v.Buf.UpdateRules()
                        for pl := range loadedPlugins {
                                _, err := Call(pl+".onViewOpen", v)
                                if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
@@ -393,9 +396,6 @@ func main() {
                                        continue
                                }
                        }
-                       if v.Buf.Settings["syntax"].(bool) {
-                               v.matches = Match(v)
-                       }
                }
        }
 
@@ -485,7 +485,6 @@ func main() {
                        default:
                                event = nil
                        }
-
                }
        }
 }