mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 14:55:38 -04:00
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:
parent
2898f1590d
commit
415ceee46b
@ -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 {
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user