Add onBufferOpen plugin callback

This commit is contained in:
Zachary Yedidia
2016-08-24 17:03:02 -07:00
parent dbdfef632e
commit 0711c29c0a
4 changed files with 21 additions and 9 deletions

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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])

View File

@@ -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)