plugin: Add new onBufferOptionChanged callback

This can become handy in the moment a plugin needs to react on e.g. changed
file type.
This commit is contained in:
Jöran Karl
2023-10-13 01:56:16 +02:00
parent 2898f1590d
commit 415ceee46b
2 changed files with 14 additions and 1 deletions

View File

@@ -5,7 +5,9 @@ import (
"reflect"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
luar "layeh.com/gopher-luar"
)
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
@@ -46,7 +48,8 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
}
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
if reflect.DeepEqual(b.Settings[option], nativeValue) {
oldValue := b.Settings[option]
if reflect.DeepEqual(oldValue, nativeValue) {
return
}
@@ -117,6 +120,12 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
if b.OptionCallback != nil {
b.OptionCallback(option, nativeValue)
}
if err := config.RunPluginFn("onBufferOptionChanged",
luar.New(ulua.L, b), luar.New(ulua.L, option),
luar.New(ulua.L, oldValue), luar.New(ulua.L, nativeValue)); err != nil {
screen.TermMessage(err)
}
}
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {