Unserialize loads the buffer info from config.ConfigDir/buffers
()
| 57 | |
| 58 | // Unserialize loads the buffer info from config.ConfigDir/buffers |
| 59 | func (b *Buffer) Unserialize() error { |
| 60 | // If either savecursor or saveundo is turned on, we need to load the serialized information |
| 61 | // from ~/.config/micro/buffers |
| 62 | if b.Path == "" { |
| 63 | return nil |
| 64 | } |
| 65 | name, _ := util.DetermineEscapePath(filepath.Join(config.ConfigDir, "buffers"), b.AbsPath) |
| 66 | file, err := os.Open(name) |
| 67 | if err == nil { |
| 68 | defer file.Close() |
| 69 | var buffer SerializedBuffer |
| 70 | decoder := gob.NewDecoder(file) |
| 71 | err = decoder.Decode(&buffer) |
| 72 | if err != nil { |
| 73 | return errors.New(err.Error() + "\nYou may want to remove the files in ~/.config/micro/buffers (these files\nstore the information for the 'saveundo' and 'savecursor' options) if\nthis problem persists.\nThis may be caused by upgrading to version 2.0, and removing the 'buffers'\ndirectory will reset the cursor and undo history and solve the problem.") |
| 74 | } |
| 75 | if b.Settings["savecursor"].(bool) { |
| 76 | b.StartCursor = buffer.Cursor |
| 77 | } |
| 78 | |
| 79 | if b.Settings["saveundo"].(bool) { |
| 80 | // We should only use last time's eventhandler if the file wasn't modified by someone else in the meantime |
| 81 | if b.ModTime == buffer.ModTime { |
| 82 | b.EventHandler = buffer.EventHandler |
| 83 | b.EventHandler.cursors = b.cursors |
| 84 | b.EventHandler.buf = b.SharedBuffer |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | return nil |
| 89 | } |
no test coverage detected