7 "github.com/zyedidia/micro/cmd/micro/config"
10 // LoadHistory attempts to load user history from configDir/buffers/history
11 // into the history map
12 // The savehistory option must be on
13 func (i *InfoBuf) LoadHistory() {
14 if config.GetGlobalOption("savehistory").(bool) {
15 file, err := os.Open(config.ConfigDir + "/buffers/history")
17 var decodedMap map[string][]string
19 decoder := gob.NewDecoder(file)
20 err = decoder.Decode(&decodedMap)
23 i.Error("Error loading history:", err)
28 if decodedMap != nil {
29 i.History = decodedMap
31 i.History = make(map[string][]string)
34 i.History = make(map[string][]string)
38 // SaveHistory saves the user's command history to configDir/buffers/history
39 // only if the savehistory option is on
40 func (i *InfoBuf) SaveHistory() {
41 if config.GetGlobalOption("savehistory").(bool) {
42 // Don't save history past 100
43 for k, v := range i.History {
45 i.History[k] = v[len(i.History[k])-100:]
49 file, err := os.Create(config.ConfigDir + "/buffers/history")
52 encoder := gob.NewEncoder(file)
54 err = encoder.Encode(i.History)
56 i.Error("Error saving history:", err)