diff --git a/cmd/micro/buffer.go b/cmd/micro/buffer.go index 17abf531..6a855417 100644 --- a/cmd/micro/buffer.go +++ b/cmd/micro/buffer.go @@ -8,6 +8,7 @@ import ( "os/exec" "os/signal" "path/filepath" + "strings" "time" "unicode/utf8" ) @@ -114,6 +115,11 @@ func NewBuffer(txt []byte, path string) *Buffer { file.Close() } + _, err := Call("onBufferOpen", b) + if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") { + TermMessage(err) + } + return b } diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 1c9e88c8..b7eae904 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "runtime" + "strings" "github.com/go-errors/errors" "github.com/layeh/gopher-luar" @@ -247,14 +248,6 @@ func main() { tab := NewTabFromView(NewView(buf)) tab.SetNum(len(tabs)) tabs = append(tabs, tab) - for _, t := range tabs { - for _, v := range t.views { - v.Center(false) - if settings["syntax"].(bool) { - v.matches = Match(v) - } - } - } } // Load all the plugin stuff @@ -284,6 +277,18 @@ func main() { jobs = make(chan JobFunction, 100) events = make(chan tcell.Event) + for _, t := range tabs { + for _, v := range t.views { + _, err := Call("onBufferOpen", v.Buf) + if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") { + TermMessage(err) + } + if settings["syntax"].(bool) { + v.matches = Match(v) + } + } + } + // Here is the event loop which runs in a separate thread go func() { for { diff --git a/cmd/micro/plugin.go b/cmd/micro/plugin.go index f2091bfc..97e9c6b4 100644 --- a/cmd/micro/plugin.go +++ b/cmd/micro/plugin.go @@ -21,7 +21,7 @@ var preInstalledPlugins = []string{ // Call calls the lua function 'function' // If it does not exist nothing happens, if there is an error, // the error is returned -func Call(function string, args []string) (lua.LValue, error) { +func Call(function string, args ...interface{}) (lua.LValue, error) { var luaFunc lua.LValue if strings.Contains(function, ".") { plugin := L.GetGlobal(strings.Split(function, ".")[0]) diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 798a570d..b0d72a89 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -189,6 +189,7 @@ func (v *View) OpenBuffer(buf *Buffer) { v.leftCol = 0 v.Cursor.ResetSelection() v.Relocate() + v.Center(false) v.messages = make(map[string][]GutterMessage) v.matches = Match(v)