micro/internal/buffer/settings.go

70 lines
1.6 KiB
Go
Raw Normal View History

2019-01-14 05:06:58 +03:00
package buffer
import (
2020-05-04 17:16:15 +03:00
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
2019-01-14 05:06:58 +03:00
)
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
2019-01-14 05:06:58 +03:00
b.Settings[option] = nativeValue
if option == "fastdirty" {
if !nativeValue.(bool) {
2020-07-05 03:09:44 +03:00
if !b.Modified() {
e := calcHash(b, &b.origHash)
if e == ErrFileTooLarge {
b.Settings["fastdirty"] = false
}
2019-01-14 05:06:58 +03:00
}
}
} else if option == "statusline" {
screen.Redraw()
} else if option == "filetype" {
b.UpdateRules()
} else if option == "fileformat" {
2019-01-15 07:24:49 +03:00
switch b.Settings["fileformat"].(string) {
case "unix":
b.Endings = FFUnix
case "dos":
b.Endings = FFDos
}
2019-01-15 00:52:25 +03:00
b.isModified = true
2019-01-14 05:06:58 +03:00
} else if option == "syntax" {
if !nativeValue.(bool) {
b.ClearMatches()
} else {
b.UpdateRules()
}
} else if option == "encoding" {
b.isModified = true
2020-02-09 03:37:37 +03:00
} else if option == "readonly" && b.Type.Kind == BTDefault.Kind {
2019-06-18 00:45:38 +03:00
b.Type.Readonly = nativeValue.(bool)
} else if option == "hlsearch" {
for _, buf := range OpenBuffers {
if b.SharedBuffer == buf.SharedBuffer {
buf.HighlightSearch = nativeValue.(bool)
}
}
2019-01-14 05:06:58 +03:00
}
if b.OptionCallback != nil {
b.OptionCallback(option, nativeValue)
}
2019-01-14 05:06:58 +03:00
return nil
}
// SetOption sets a given option to a value just for this buffer
func (b *Buffer) SetOption(option, value string) error {
if _, ok := b.Settings[option]; !ok {
return config.ErrInvalidOption
}
nativeValue, err := config.GetNativeValue(option, b.Settings[option], value)
if err != nil {
return err
}
return b.SetOptionNative(option, nativeValue)
}