mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 14:55:38 -04:00
buffer: Perform filetype
callbacks on ReloadSettings()
In `ReloadSettings()` the `filetype` can change upon globbed path given by the `settings.json` or by identifying a different `filetype` based on the file name given or pattern present inside the file. To prevent further recursion caused by checking the `filetype` again, its processing stops here and isn't considered in `DoSetOptionNative()` once again where the callbacks are usually triggered.
This commit is contained in:
parent
4a9058c3bd
commit
2e94235905
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user