Skip to content

Commit 2e94235

Browse files
committed
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.
1 parent 4a9058c commit 2e94235

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

internal/buffer/settings.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
1414
settings := config.ParsedSettings()
1515
config.UpdatePathGlobLocals(settings, b.AbsPath)
1616

17+
oldFiletype := b.Settings["filetype"].(string)
18+
1719
_, local := b.LocalSettings["filetype"]
1820
_, volatile := config.VolatileSettings["filetype"]
1921
if reloadFiletype && !local && !volatile {
@@ -27,7 +29,13 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
2729
// update syntax rules, which will also update filetype if needed
2830
b.UpdateRules()
2931

30-
config.UpdateFileTypeLocals(settings, b.Settings["filetype"].(string))
32+
curFiletype := b.Settings["filetype"].(string)
33+
if oldFiletype != curFiletype {
34+
b.doCallbacks("filetype", oldFiletype, curFiletype)
35+
}
36+
37+
config.UpdateFileTypeLocals(settings, curFiletype)
38+
3139
for k, v := range config.DefaultCommonSettings() {
3240
if k == "filetype" {
3341
// prevent recursion
@@ -119,15 +127,7 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
119127
}
120128
}
121129

122-
if b.OptionCallback != nil {
123-
b.OptionCallback(option, nativeValue)
124-
}
125-
126-
if err := config.RunPluginFn("onBufferOptionChanged",
127-
luar.New(ulua.L, b), luar.New(ulua.L, option),
128-
luar.New(ulua.L, oldValue), luar.New(ulua.L, nativeValue)); err != nil {
129-
screen.TermMessage(err)
130-
}
130+
b.doCallbacks(option, oldValue, nativeValue)
131131
}
132132

133133
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
@@ -154,3 +154,15 @@ func (b *Buffer) SetOption(option, value string) error {
154154

155155
return b.SetOptionNative(option, nativeValue)
156156
}
157+
158+
func (b *Buffer) doCallbacks(option string, oldValue interface{}, newValue interface{}) {
159+
if b.OptionCallback != nil {
160+
b.OptionCallback(option, newValue)
161+
}
162+
163+
if err := config.RunPluginFn("onBufferOptionChanged",
164+
luar.New(ulua.L, b), luar.New(ulua.L, option),
165+
luar.New(ulua.L, oldValue), luar.New(ulua.L, newValue)); err != nil {
166+
screen.TermMessage(err)
167+
}
168+
}

0 commit comments

Comments
 (0)