mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-19 07:15:34 -04:00
action/command: Refactor reload
& the filetype
change
This commit is contained in:
parent
724e29446f
commit
a3071b173b
@ -408,15 +408,7 @@ func reloadRuntime(reloadPlugins bool) {
|
|||||||
screen.TermMessage(err)
|
screen.TermMessage(err)
|
||||||
}
|
}
|
||||||
for _, b := range buffer.OpenBuffers {
|
for _, b := range buffer.OpenBuffers {
|
||||||
config.InitLocalSettings(b.Settings, b.Path)
|
b.ReloadSettings(true)
|
||||||
for k, v := range b.Settings {
|
|
||||||
if _, ok := b.LocalSettings[k]; ok {
|
|
||||||
// reload should not override local settings
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
b.DoSetOptionNative(k, v)
|
|
||||||
}
|
|
||||||
b.UpdateRules()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,43 @@ import (
|
|||||||
"github.com/zyedidia/micro/v2/internal/screen"
|
"github.com/zyedidia/micro/v2/internal/screen"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
|
||||||
|
settings := config.ParsedSettings()
|
||||||
|
|
||||||
|
if _, ok := b.LocalSettings["filetype"]; !ok && reloadFiletype {
|
||||||
|
// need to update filetype before updating other settings based on it
|
||||||
|
b.Settings["filetype"] = "unknown"
|
||||||
|
if v, ok := settings["filetype"]; ok {
|
||||||
|
b.Settings["filetype"] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update syntax rules, which will also update filetype if needed
|
||||||
|
b.UpdateRules()
|
||||||
|
settings["filetype"] = b.Settings["filetype"]
|
||||||
|
|
||||||
|
config.InitLocalSettings(settings, b.Path)
|
||||||
|
for k, v := range config.DefaultCommonSettings() {
|
||||||
|
if k == "filetype" {
|
||||||
|
// prevent recursion
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := config.VolatileSettings[k]; ok {
|
||||||
|
// reload should not override volatile settings
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := b.LocalSettings[k]; ok {
|
||||||
|
// reload should not override local settings
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := settings[k]; ok {
|
||||||
|
b.DoSetOptionNative(k, settings[k])
|
||||||
|
} else {
|
||||||
|
b.DoSetOptionNative(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
|
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
|
||||||
if reflect.DeepEqual(b.Settings[option], nativeValue) {
|
if reflect.DeepEqual(b.Settings[option], nativeValue) {
|
||||||
return
|
return
|
||||||
@ -31,28 +68,7 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
|
|||||||
} else if option == "statusline" {
|
} else if option == "statusline" {
|
||||||
screen.Redraw()
|
screen.Redraw()
|
||||||
} else if option == "filetype" {
|
} else if option == "filetype" {
|
||||||
settings := config.ParsedSettings()
|
b.ReloadSettings(false)
|
||||||
settings["filetype"] = nativeValue
|
|
||||||
config.InitLocalSettings(settings, b.Path)
|
|
||||||
for k, v := range config.DefaultCommonSettings() {
|
|
||||||
if k == "filetype" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, ok := config.VolatileSettings[k]; ok {
|
|
||||||
// filetype should not override volatile settings
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, ok := b.LocalSettings[k]; ok {
|
|
||||||
// filetype should not override local settings
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, ok := settings[k]; ok {
|
|
||||||
b.DoSetOptionNative(k, settings[k])
|
|
||||||
} else {
|
|
||||||
b.DoSetOptionNative(k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b.UpdateRules()
|
|
||||||
} else if option == "fileformat" {
|
} else if option == "fileformat" {
|
||||||
switch b.Settings["fileformat"].(string) {
|
switch b.Settings["fileformat"].(string) {
|
||||||
case "unix":
|
case "unix":
|
||||||
|
Loading…
Reference in New Issue
Block a user