mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-21 08:17:15 +09:00
Add onBufferOpen plugin callback
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user