diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go index 838df4a568..3bb3d0c073 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 fbab646943..5d4830fbc9 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. diff --git a/runtime/plugins/linter/linter.lua b/runtime/plugins/linter/linter.lua index 0ce4b2b01e..068a8abfdf 100644 --- a/runtime/plugins/linter/linter.lua +++ b/runtime/plugins/linter/linter.lua @@ -66,7 +66,7 @@ function preinit() end makeLinter("gcc", "c", "gcc", {"-fsyntax-only", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m") - makeLinter("g++", "c++", "gcc", {"-fsyntax-only","-std=c++14", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m") + makeLinter("g++", "c++", "g++", {"-fsyntax-only","-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m") makeLinter("dmd", "d", "dmd", {"-color=off", "-o-", "-w", "-wi", "-c", "%f"}, "%f%(%l%):.+: %m") makeLinter("eslint", "javascript", "eslint", {"-f","compact","%f"}, "%f: line %l, col %c, %m") makeLinter("gobuild", "go", "go", {"build", "-o", devnull, "%d"}, "%f:%l:%c:? %m") @@ -107,26 +107,29 @@ function contains(list, element) return false end +function checkFtMatch(ft, v) + 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 + return ftmatch +end + function runLinter(buf) local ft = buf:FileType() local file = buf.Path local dir = "." .. util.RuneStr(os.PathSeparator) .. filepath.Dir(file) 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 + if checkFtMatch(ft, v) then local args = {} for k, arg in pairs(v.args) do args[k] = arg:gsub("%%f", file):gsub("%%d", dir) @@ -141,6 +144,19 @@ function onSave(bp) return true end +function onBufferOptionChanged(buf, option, old, new) + if option == "filetype" then + if old ~= new then + for k, v in pairs(linters) do + if checkFtMatch(old, v) then + buf:ClearMessages(k) + end + end + end + end + return true +end + function lint(buf, linter, cmd, args, errorformat, loff, coff, callback) buf:ClearMessages(linter)