memory

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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

func Load(dir string) (*Memory, error)

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

func (m *Memory) AddHistory(kind, s string)

AddHistory records s as the most recent entry at prompts of this kind.

func (*Memory) AddProject added in v0.6.0

func (m *Memory) AddProject(root string)

AddProject records root as the project most recently worked in.

func (*Memory) AddRecent

func (m *Memory) AddRecent(path string)

AddRecent records path as the most recently opened file.

func (*Memory) ForgetProject added in v0.6.0

func (m *Memory) ForgetProject(root string)

ForgetProject takes root off the known projects.

func (*Memory) HistoryOf

func (m *Memory) HistoryOf(kind string) []string

HistoryOf is what has been entered at prompts of this kind, most recent first.

func (*Memory) LanguageOf added in v0.14.0

func (m *Memory) LanguageOf(path string) string

LanguageOf is the language the file at path was set to be coloured as, or "" when it was not.

func (*Memory) PlaceOf

func (m *Memory) PlaceOf(path string) (Place, bool)

PlaceOf is where point was left in the file at path.

func (*Memory) Save

func (m *Memory) Save() error

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

func (m *Memory) SetLanguage(path, name string)

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.

func (*Memory) SetPlace

func (m *Memory) SetPlace(path string, p Place)

SetPlace records where point was in the file at path.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL