Documentation
¶
Overview ¶
Package memory is what nem remembers from one session to the next: what was typed at each kind of prompt, the files opened most recently, where point was in each file when it was left, the language a file was set to be read as, and the projects worked in.
It is one small JSON file in the state directory, beside the backups. Saving merges with what is on disk rather than overwriting it, so two nem windows open at once add to one history instead of each erasing the other's.
Index ¶
- Constants
- type Language
- type Memory
- func (m *Memory) AddHistory(kind, s string)
- func (m *Memory) AddProject(root string)
- func (m *Memory) AddRecent(path string)
- func (m *Memory) ForgetProject(root string)
- func (m *Memory) HistoryOf(kind string) []string
- func (m *Memory) LanguageOf(path string) string
- func (m *Memory) PlaceOf(path string) (Place, bool)
- func (m *Memory) Save() error
- func (m *Memory) SetLanguage(path, name string)
- func (m *Memory) SetPlace(path string, p Place)
- type Place
Constants ¶
const FileName = "memory.json"
FileName is the memory's file, in the state directory.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Language ¶ added in v0.14.0
type Language struct {
// Name is the language, or "" when the choice was undone: kept, so the
// undoing outlasts a merge with an older choice on disk.
Name string `json:"name"`
// Used is when it was chosen, in Unix seconds: the newer wins a merge.
Used int64 `json:"used"`
}
Language is the language a file was set to be coloured as, when it is not the one its name says.
type Memory ¶
type Memory struct {
History map[string][]string `json:"history"`
Recent []string `json:"recent"`
Places map[string]Place `json:"places"`
Projects []string `json:"projects"`
// Languages are the languages files were set to be coloured as, by
// path.
Languages map[string]Language `json:"languages,omitempty"`
// contains filtered or unexported fields
}
Memory is the remembered state. The zero value is empty and does not persist; Load gives one that does.
func Load ¶
Load reads the memory kept in dir, or starts an empty one there if there is none yet. A file that cannot be parsed is set aside rather than trusted or deleted: losing a history is a nuisance, but it is not worth an error that stops the editor starting.
func (*Memory) AddHistory ¶
AddHistory records s as the most recent entry at prompts of this kind.
func (*Memory) AddProject ¶ added in v0.6.0
AddProject records root as the project most recently worked in.
func (*Memory) ForgetProject ¶ added in v0.6.0
ForgetProject takes root off the known projects.
func (*Memory) HistoryOf ¶
HistoryOf is what has been entered at prompts of this kind, most recent first.
func (*Memory) LanguageOf ¶ added in v0.14.0
LanguageOf is the language the file at path was set to be coloured as, or "" when it was not.
func (*Memory) Save ¶
Save writes the memory, merged with whatever another session saved since this one loaded: this session's entries first, since they are the newer, then the other's that this one does not have. A memory that was not loaded from a directory is not saved anywhere.
func (*Memory) SetLanguage ¶ added in v0.14.0
SetLanguage records that the file at path is to be coloured as name, or, with "", that it is to be coloured as its name says after all.
type Place ¶
type Place struct {
Line int `json:"line"`
Col int `json:"col"`
Top int `json:"top"`
// Used is when the place was recorded, in Unix seconds: the most recent
// wins a merge, and the oldest go first when there are too many.
Used int64 `json:"used"`
}
Place is where point was in a file, and the first line on screen.