2019-01-14 05:06:58 +03:00
|
|
|
package buffer
|
|
|
|
|
|
|
|
import (
|
2019-02-04 07:17:24 +03:00
|
|
|
"github.com/zyedidia/micro/internal/config"
|
|
|
|
"github.com/zyedidia/micro/internal/screen"
|
2019-01-14 05:06:58 +03:00
|
|
|
)
|
|
|
|
|
2019-06-17 00:35:00 +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) {
|
|
|
|
e := calcHash(b, &b.origHash)
|
|
|
|
if e == ErrFileTooLarge {
|
|
|
|
b.Settings["fastdirty"] = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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()
|
|
|
|
}
|
2019-01-24 03:06:20 +03:00
|
|
|
} 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)
|
2019-01-14 05:06:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2019-06-17 00:35:00 +03:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|