mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09: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:
@@ -14,6 +14,8 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
|
|||||||
settings := config.ParsedSettings()
|
settings := config.ParsedSettings()
|
||||||
config.UpdatePathGlobLocals(settings, b.AbsPath)
|
config.UpdatePathGlobLocals(settings, b.AbsPath)
|
||||||
|
|
||||||
|
oldFiletype := b.Settings["filetype"].(string)
|
||||||
|
|
||||||
_, local := b.LocalSettings["filetype"]
|
_, local := b.LocalSettings["filetype"]
|
||||||
_, volatile := config.VolatileSettings["filetype"]
|
_, volatile := config.VolatileSettings["filetype"]
|
||||||
if reloadFiletype && !local && !volatile {
|
if reloadFiletype && !local && !volatile {
|
||||||
@@ -27,7 +29,13 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
|
|||||||
// update syntax rules, which will also update filetype if needed
|
// update syntax rules, which will also update filetype if needed
|
||||||
b.UpdateRules()
|
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() {
|
for k, v := range config.DefaultCommonSettings() {
|
||||||
if k == "filetype" {
|
if k == "filetype" {
|
||||||
// prevent recursion
|
// prevent recursion
|
||||||
@@ -119,15 +127,7 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.OptionCallback != nil {
|
b.doCallbacks(option, oldValue, nativeValue)
|
||||||
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 {
|
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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user