Skip to content

Commit 0552959

Browse files
committed
action/command: Prevent overwriting settings set locally or by plugin
- on `reload` - on `filetype` change
1 parent f661b64 commit 0552959

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

internal/action/command.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func reloadRuntime(reloadPlugins bool) {
410410
for _, b := range buffer.OpenBuffers {
411411
config.InitLocalSettings(b.Settings, b.Path)
412412
for k, v := range b.Settings {
413-
b.SetOptionNative(k, v)
413+
b.DoSetOptionNative(k, v)
414414
}
415415
b.UpdateRules()
416416
}
@@ -610,9 +610,8 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
610610

611611
// ...at last check the buffer locals
612612
for _, b := range buffer.OpenBuffers {
613-
if err := b.SetOptionNative(option, nativeValue); err != nil {
614-
return err
615-
}
613+
b.DoSetOptionNative(option, nativeValue)
614+
delete(b.LocalSettings, option)
616615
}
617616

618617
return config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))

internal/buffer/buffer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ type SharedBuffer struct {
8686

8787
// Settings customized by the user
8888
Settings map[string]interface{}
89+
// LocalSettings customized by the user for this buffer only
90+
LocalSettings map[string]bool
8991

9092
Suggestions []string
9193
Completions []string
@@ -326,6 +328,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
326328
// assigning the filetype.
327329
settings := config.DefaultCommonSettings()
328330
b.Settings = config.DefaultCommonSettings()
331+
b.LocalSettings = make(map[string]bool)
329332
for k, v := range config.GlobalSettings {
330333
if _, ok := config.DefaultGlobalOnlySettings[k]; !ok {
331334
// make sure setting is not global-only

internal/buffer/settings.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ import (
88
"github.com/zyedidia/micro/v2/internal/screen"
99
)
1010

11-
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
12-
if err := config.OptionIsValid(option, nativeValue); err != nil {
13-
return err
14-
}
15-
11+
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
1612
if reflect.DeepEqual(b.Settings[option], nativeValue) {
17-
return nil
13+
return
1814
}
1915

2016
b.Settings[option] = nativeValue
@@ -46,10 +42,14 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
4642
// filetype should not override volatile settings
4743
continue
4844
}
45+
if _, ok := b.LocalSettings[k]; ok {
46+
// filetype should not override local settings
47+
continue
48+
}
4949
if _, ok := settings[k]; ok {
50-
b.SetOptionNative(k, settings[k])
50+
b.DoSetOptionNative(k, settings[k])
5151
} else {
52-
b.SetOptionNative(k, v)
52+
b.DoSetOptionNative(k, v)
5353
}
5454
}
5555
b.UpdateRules()
@@ -101,6 +101,15 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
101101
if b.OptionCallback != nil {
102102
b.OptionCallback(option, nativeValue)
103103
}
104+
}
105+
106+
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
107+
if err := config.OptionIsValid(option, nativeValue); err != nil {
108+
return err
109+
}
110+
111+
b.DoSetOptionNative(option, nativeValue)
112+
b.LocalSettings[option] = true
104113

105114
return nil
106115
}

0 commit comments

Comments
 (0)