diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go index 661ba3fd..3db35e97 100644 --- a/internal/buffer/settings.go +++ b/internal/buffer/settings.go @@ -14,6 +14,8 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) { settings := config.ParsedSettings() config.UpdatePathGlobLocals(settings, b.AbsPath) + oldFiletype := b.Settings["filetype"].(string) + _, local := b.LocalSettings["filetype"] _, volatile := config.VolatileSettings["filetype"] if reloadFiletype && !local && !volatile { @@ -27,7 +29,13 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) { // update syntax rules, which will also update filetype if needed b.UpdateRules() - config.UpdateFileTypeLocals(settings, b.Settings["filetype"].(string)) + curFiletype := b.Settings["filetype"].(string) + if oldFiletype != curFiletype { + b.doCallbacks("filetype", oldFiletype, curFiletype) + } + + config.UpdateFileTypeLocals(settings, curFiletype) + for k, v := range config.DefaultCommonSettings() { if k == "filetype" { // prevent recursion @@ -119,15 +127,7 @@ 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) - } + b.doCallbacks(option, oldValue, nativeValue) } func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error { @@ -154,3 +154,15 @@ func (b *Buffer) SetOption(option, value string) error { return b.SetOptionNative(option, nativeValue) } + +func (b *Buffer) doCallbacks(option string, oldValue interface{}, newValue interface{}) { + if b.OptionCallback != nil { + b.OptionCallback(option, newValue) + } + + if err := config.RunPluginFn("onBufferOptionChanged", + luar.New(ulua.L, b), luar.New(ulua.L, option), + luar.New(ulua.L, oldValue), luar.New(ulua.L, newValue)); err != nil { + screen.TermMessage(err) + } +}