mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-19 07:17:11 +09:00
Allow any plugin to be enabled or disabled via settings
This commit is contained in:
@@ -365,6 +365,12 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
|
||||
} else {
|
||||
screen.Screen.EnableMouse()
|
||||
}
|
||||
} else {
|
||||
for _, pl := range config.Plugins {
|
||||
if option == pl.Name && nativeValue.(bool) && !pl.Loaded {
|
||||
pl.Load()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
|
||||
@@ -2,7 +2,6 @@ package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
ulua "github.com/zyedidia/micro/internal/lua"
|
||||
@@ -21,7 +20,9 @@ func LoadAllPlugins() {
|
||||
func RunPluginFn(fn string, args ...lua.LValue) error {
|
||||
var reterr error
|
||||
for _, p := range Plugins {
|
||||
log.Println(p.Name, fn)
|
||||
if !p.IsEnabled() {
|
||||
continue
|
||||
}
|
||||
_, err := p.Call(fn, args...)
|
||||
if err != nil && err != ErrNoSuchFunction {
|
||||
reterr = errors.New("Plugin " + p.Name + ": " + err.Error())
|
||||
@@ -31,15 +32,26 @@ func RunPluginFn(fn string, args ...lua.LValue) error {
|
||||
}
|
||||
|
||||
type Plugin struct {
|
||||
Name string // name of plugin
|
||||
Info RuntimeFile // json file containing info
|
||||
Srcs []RuntimeFile // lua files
|
||||
Name string // name of plugin
|
||||
Info RuntimeFile // json file containing info
|
||||
Srcs []RuntimeFile // lua files
|
||||
Loaded bool
|
||||
}
|
||||
|
||||
func (p *Plugin) IsEnabled() bool {
|
||||
if v, ok := GlobalSettings[p.Name]; ok {
|
||||
return v.(bool)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var Plugins []*Plugin
|
||||
|
||||
func (p *Plugin) Load() error {
|
||||
for _, f := range p.Srcs {
|
||||
if !p.IsEnabled() {
|
||||
return nil
|
||||
}
|
||||
dat, err := f.Data()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -48,6 +60,10 @@ func (p *Plugin) Load() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Loaded = true
|
||||
if _, ok := GlobalSettings[p.Name]; !ok {
|
||||
AddOption(p.Name, true)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func SetStatusInfoFnLua(s string, fn string) {
|
||||
}
|
||||
}
|
||||
statusInfo[s] = func(b *buffer.Buffer) string {
|
||||
if pl == nil {
|
||||
if pl == nil || !pl.IsEnabled() {
|
||||
return ""
|
||||
}
|
||||
val, err := pl.Call(plFn, luar.New(ulua.L, b))
|
||||
|
||||
Reference in New Issue
Block a user