]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/micro.go
Merge pull request #1125 from nabeelomer/master
[micro.git] / cmd / micro / micro.go
index e835bab8f1fd19eb237a3a542928e756850267dd..dc35ed2708f853b0a9c45bbc1b076200fe067892 100644 (file)
@@ -7,6 +7,7 @@ import (
        "os"
        "path/filepath"
        "runtime"
+       "strings"
        "time"
 
        "github.com/go-errors/errors"
@@ -95,30 +96,23 @@ func LoadInput() []*Buffer {
                // Option 1
                // We go through each file and load it
                for i := 0; i < len(args); i++ {
-                       filename = args[i]
-
-                       // Check that the file exists
-                       var input *os.File
-                       if _, e := os.Stat(filename); e == nil {
-                               // If it exists we load it into a buffer
-                               input, err = os.Open(filename)
-                               stat, _ := input.Stat()
-                               defer input.Close()
-                               if err != nil {
-                                       TermMessage(err)
-                                       continue
-                               }
-                               if stat.IsDir() {
-                                       TermMessage("Cannot read", filename, "because it is a directory")
-                                       continue
+                       if strings.HasPrefix(args[i], "+") {
+                               if strings.Contains(args[i], ":") {
+                                       split := strings.Split(args[i], ":")
+                                       *flagStartPos = split[0][1:] + "," + split[1]
+                               } else {
+                                       *flagStartPos = args[i][1:] + ",0"
                                }
+                               continue
                        }
-                       // 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, FSize(input), filename))
-                       } else {
-                               buffers = append(buffers, NewBufferFromString("", filename))
+
+                       buf, err := NewBufferFromFile(args[i])
+                       if err != nil {
+                               TermMessage(err)
+                               continue
                        }
+                       // If the file didn't exist, input will be empty, and we'll open an empty buffer
+                       buffers = append(buffers, buf)
                }
        } else if !isatty.IsTerminal(os.Stdin.Fd()) {
                // Option 2
@@ -242,7 +236,7 @@ func RedrawAll() {
                }
        }
 
-       for _, v := range tabs[curTab].views {
+       for _, v := range tabs[curTab].Views {
                v.Display()
        }
        DisplayTabs()
@@ -274,7 +268,7 @@ func LoadAll() {
        InitColorscheme()
 
        for _, tab := range tabs {
-               for _, v := range tab.views {
+               for _, v := range tab.Views {
                        v.Buf.UpdateRules()
                }
        }
@@ -292,7 +286,9 @@ func main() {
                fmt.Println("-config-dir dir")
                fmt.Println("    \tSpecify a custom location for the configuration directory")
                fmt.Println("-startpos LINE,COL")
+               fmt.Println("+LINE:COL")
                fmt.Println("    \tSpecify a line and column to start the cursor at when opening a buffer")
+               fmt.Println("    \tThis can also be done by opening file:LINE:COL")
                fmt.Println("-options")
                fmt.Println("    \tShow all option help")
                fmt.Println("-version")
@@ -384,7 +380,7 @@ func main() {
                tab.SetNum(len(tabs))
                tabs = append(tabs, tab)
                for _, t := range tabs {
-                       for _, v := range t.views {
+                       for _, v := range t.Views {
                                v.Center(false)
                        }
 
@@ -423,6 +419,7 @@ func main() {
        L.SetGlobal("GetLeadingWhitespace", luar.New(L, GetLeadingWhitespace))
        L.SetGlobal("MakeCompletion", luar.New(L, MakeCompletion))
        L.SetGlobal("NewBuffer", luar.New(L, NewBufferFromString))
+       L.SetGlobal("NewBufferFromFile", luar.New(L, NewBufferFromFile))
        L.SetGlobal("RuneStr", luar.New(L, func(r rune) string {
                return string(r)
        }))
@@ -462,7 +459,7 @@ func main() {
        LoadPlugins()
 
        for _, t := range tabs {
-               for _, v := range t.views {
+               for _, v := range t.Views {
                        GlobalPluginCall("onViewOpen", v)
                        GlobalPluginCall("onBufferOpen", v.Buf)
                }
@@ -508,7 +505,7 @@ func main() {
                case <-updateterm:
                        continue
                case vnum := <-closeterm:
-                       tabs[curTab].views[vnum].CloseTerminal()
+                       tabs[curTab].Views[vnum].CloseTerminal()
                case event = <-events:
                }
 
@@ -538,7 +535,7 @@ func main() {
                                                if CurView().mouseReleased {
                                                        // We loop through each view in the current tab and make sure the current view
                                                        // is the one being clicked in
-                                                       for _, v := range tabs[curTab].views {
+                                                       for _, v := range tabs[curTab].Views {
                                                                if x >= v.x && x < v.x+v.Width && y >= v.y && y < v.y+v.Height {
                                                                        tabs[curTab].CurView = v.Num
                                                                }
@@ -547,9 +544,9 @@ func main() {
                                        } else if e.Buttons() == tcell.WheelUp || e.Buttons() == tcell.WheelDown {
                                                var view *View
                                                x, y := e.Position()
-                                               for _, v := range tabs[curTab].views {
+                                               for _, v := range tabs[curTab].Views {
                                                        if x >= v.x && x < v.x+v.Width && y >= v.y && y < v.y+v.Height {
-                                                               view = tabs[curTab].views[v.Num]
+                                                               view = tabs[curTab].Views[v.Num]
                                                        }
                                                }
                                                if view != nil {