draft

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package draft keeps recovery copies of the text of unsaved documents, so that a crash, a forced quit or a quit that keeps documents loses nothing.

A copy is one file of UTF-8 text, with the document's line endings, and an entry in index.json that says which document it belongs to: its file, its unstyled number, its encoding, and the size and modification time the file had when the copy was made. Saving a document, closing it or discarding its changes removes the copy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewID

func NewID() string

NewID returns an id for a copy: random, so that it does not follow a path that may be long, hold a colon on Windows or be written in a case the file system folds.

func ValidID

func ValidID(id string) bool

ValidID reports whether id can name a copy's file.

Types

type Entry

type Entry struct {
	ID string `json:"id"`
	// Path is the document's file; "" for an untitled document, whose
	// Untitled number names it.
	Path     string `json:"path,omitempty"`
	Untitled int    `json:"untitled,omitempty"`
	// Encoding is what a save of the document writes; the copy itself is
	// always UTF-8.
	Encoding string `json:"encoding,omitempty"`
	// Language is the language an untitled document was given in the status
	// bar, by name; "" for none. A document with a path takes its language
	// from the file name instead.
	Language string `json:"language,omitempty"`
	// Size and ModTime are the file's size and modification time when the
	// copy was made, in Unix nanoseconds; zero for an untitled document. A
	// file that changed since is in conflict with the copy.
	Size    int64 `json:"size,omitempty"`
	ModTime int64 `json:"modTime,omitempty"`
	// SavedAt is when the copy was written, in Unix nanoseconds.
	SavedAt int64 `json:"savedAt,omitempty"`
}

Entry describes one recovery copy.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the directory of recovery copies. Its methods are safe from any goroutine.

func Open

func Open(dir string) (*Store, error)

Open reads the copies in dir, creating it when it is not there. An index that cannot be read is kept as index.json.bak and its copies are left on disk, for a person to recover.

func (*Store) Entries

func (s *Store) Entries() []Entry

Entries returns the copies, oldest first.

func (*Store) Purge

func (s *Store) Purge() error

Purge deletes every copy, as turning off the keeping of unsaved content does.

func (*Store) Remove

func (s *Store) Remove(id string) error

Remove deletes the copy id, if it is there.

func (*Store) Save

func (s *Store) Save(e Entry, write func(io.Writer) error, alive func() bool) (bool, error)

Save writes a copy of a document, if alive reports that the copy is still the one to write at the moment it would be written. It reports whether the copy was written.

func (*Store) SetPath

func (s *Store) SetPath(id, path string) error

SetPath moves a copy's document to path, keeping everything else. It is what a rename of the file, or of a folder it is in, asks for.

func (*Store) Text

func (s *Store) Text(id string) (string, error)

Text reads the text of the copy id.

Jump to

Keyboard shortcuts

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