@@ -8,6 +8,43 @@ import (
88 "github.com/zyedidia/micro/v2/internal/screen"
99)
1010
11+ func (b * Buffer ) ReloadSettings (reloadFiletype bool ) {
12+ settings := config .ParsedSettings ()
13+
14+ if _ , ok := b .LocalSettings ["filetype" ]; ! ok && reloadFiletype {
15+ // need to update filetype before updating other settings based on it
16+ b .Settings ["filetype" ] = "unknown"
17+ if v , ok := settings ["filetype" ]; ok {
18+ b .Settings ["filetype" ] = v
19+ }
20+ }
21+
22+ // update syntax rules, which will also update filetype if needed
23+ b .UpdateRules ()
24+ settings ["filetype" ] = b .Settings ["filetype" ]
25+
26+ config .InitLocalSettings (settings , b .Path )
27+ for k , v := range config .DefaultCommonSettings () {
28+ if k == "filetype" {
29+ // prevent recursion
30+ continue
31+ }
32+ if _ , ok := config .VolatileSettings [k ]; ok {
33+ // reload should not override volatile settings
34+ continue
35+ }
36+ if _ , ok := b .LocalSettings [k ]; ok {
37+ // reload should not override local settings
38+ continue
39+ }
40+ if _ , ok := settings [k ]; ok {
41+ b .DoSetOptionNative (k , settings [k ])
42+ } else {
43+ b .DoSetOptionNative (k , v )
44+ }
45+ }
46+ }
47+
1148func (b * Buffer ) DoSetOptionNative (option string , nativeValue interface {}) {
1249 if reflect .DeepEqual (b .Settings [option ], nativeValue ) {
1350 return
@@ -31,28 +68,7 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
3168 } else if option == "statusline" {
3269 screen .Redraw ()
3370 } else if option == "filetype" {
34- settings := config .ParsedSettings ()
35- settings ["filetype" ] = nativeValue
36- config .InitLocalSettings (settings , b .Path )
37- for k , v := range config .DefaultCommonSettings () {
38- if k == "filetype" {
39- continue
40- }
41- if _ , ok := config .VolatileSettings [k ]; ok {
42- // filetype should not override volatile settings
43- continue
44- }
45- if _ , ok := b .LocalSettings [k ]; ok {
46- // filetype should not override local settings
47- continue
48- }
49- if _ , ok := settings [k ]; ok {
50- b .DoSetOptionNative (k , settings [k ])
51- } else {
52- b .DoSetOptionNative (k , v )
53- }
54- }
55- b .UpdateRules ()
71+ b .ReloadSettings (false )
5672 } else if option == "fileformat" {
5773 switch b .Settings ["fileformat" ].(string ) {
5874 case "unix" :
0 commit comments