]> git.lizzy.rs Git - micro.git/blob - internal/buffer/settings.go
Add readonly option
[micro.git] / internal / buffer / settings.go
1 package buffer
2
3 import (
4         "github.com/zyedidia/micro/internal/config"
5         "github.com/zyedidia/micro/internal/screen"
6 )
7
8 func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
9         b.Settings[option] = nativeValue
10
11         if option == "fastdirty" {
12                 if !nativeValue.(bool) {
13                         e := calcHash(b, &b.origHash)
14                         if e == ErrFileTooLarge {
15                                 b.Settings["fastdirty"] = false
16                         }
17                 }
18         } else if option == "statusline" {
19                 screen.Redraw()
20         } else if option == "filetype" {
21                 b.UpdateRules()
22         } else if option == "fileformat" {
23                 switch b.Settings["fileformat"].(string) {
24                 case "unix":
25                         b.Endings = FFUnix
26                 case "dos":
27                         b.Endings = FFDos
28                 }
29                 b.isModified = true
30         } else if option == "syntax" {
31                 if !nativeValue.(bool) {
32                         b.ClearMatches()
33                 } else {
34                         b.UpdateRules()
35                 }
36         } else if option == "encoding" {
37                 b.isModified = true
38         } else if option == "readonly" {
39                 b.Type.Readonly = nativeValue.(bool)
40         }
41
42         return nil
43 }
44
45 // SetOption sets a given option to a value just for this buffer
46 func (b *Buffer) SetOption(option, value string) error {
47         if _, ok := b.Settings[option]; !ok {
48                 return config.ErrInvalidOption
49         }
50
51         nativeValue, err := config.GetNativeValue(option, b.Settings[option], value)
52         if err != nil {
53                 return err
54         }
55
56         return b.SetOptionNative(option, nativeValue)
57 }