diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go index ce9abf3ec..598c7a876 100644 --- a/internal/buffer/settings.go +++ b/internal/buffer/settings.go @@ -1,13 +1,23 @@ package buffer import ( + luar "layeh.com/gopher-luar" + ulua "github.com/zyedidia/micro/v2/internal/lua" "github.com/zyedidia/micro/v2/internal/config" "github.com/zyedidia/micro/v2/internal/screen" ) func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error { + oldValue := b.Settings[option] b.Settings[option] = nativeValue + if oldValue != nativeValue { + _, err := config.RunPluginFnBool(b.Settings, "onBufferOptionChanged", luar.New(ulua.L, b), luar.New(ulua.L, option), luar.New(ulua.L, string(oldValue.(string))), luar.New(ulua.L, string(nativeValue.(string)))) + if err != nil { + screen.TermMessage(err) + } + } + if option == "fastdirty" { if !nativeValue.(bool) { if !b.Modified() { diff --git a/runtime/help/plugins.md b/runtime/help/plugins.md index dc87476f1..7c177e2e2 100644 --- a/runtime/help/plugins.md +++ b/runtime/help/plugins.md @@ -55,6 +55,10 @@ which micro defines: * `onBufferOpen(buf)`: runs when a buffer is opened. The input contains the buffer object. +* `onBufferOptionChanged(buf, option, old, new)`: runs when a option of the + settings of a buffer has changed. The input contains the buffer object, + the option, the old and the new value. + * `onBufPaneOpen(bufpane)`: runs when a bufpane is opened. The input contains the bufpane object. diff --git a/runtime/plugins/linter/linter.lua b/runtime/plugins/linter/linter.lua index c10d17bd0..37b4ffd63 100644 --- a/runtime/plugins/linter/linter.lua +++ b/runtime/plugins/linter/linter.lua @@ -141,6 +141,33 @@ function onSave(bp) return true end +function onBufferOptionChanged(buf, option, old, new) + if option == "filetype" then + if old ~= new then + ft = old + for k, v in pairs(linters) do + local ftmatch = ft == v.filetype + if v.domatch then + ftmatch = string.match(ft, v.filetype) + end + + local hasOS = contains(v.os, runtime.GOOS) + if not hasOS and v.whitelist then + ftmatch = false + end + if hasOS and not v.whitelist then + ftmatch = false + end + + if ftmatch then + buf:ClearMessages(k) + end + end + end + end + return true +end + function lint(buf, linter, cmd, args, errorformat, loff, coff, callback) buf:ClearMessages(linter)