memory

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 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, 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 Memory

type Memory struct {
	History  map[string][]string `json:"history"`
	Recent   []string            `json:"recent"`
	Places   map[string]Place    `json:"places"`
	Projects []string            `json:"projects"`
	// 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) 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) 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