diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go index 838df4a5..3bb3d0c0 100644 --- a/internal/buffer/settings.go +++ b/internal/buffer/settings.go @@ -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 { diff --git a/runtime/help/plugins.md b/runtime/help/plugins.md index fbab6469..5d4830fb 100644 --- a/runtime/help/plugins.md +++ b/runtime/help/plugins.md @@ -62,6 +62,10 @@ that micro defines: * `onBufferOpen(buf)`: runs when a buffer is opened. The input contains the buffer object. +* `onBufferOptionChanged(buf, option, old, new)`: runs when an option of the + buffer has changed. The input contains the buffer object, the option name, + the old and the new value. + * `onBufPaneOpen(bufpane)`: runs when a bufpane is opened. The input contains the bufpane object.