MingaEditor.State.Buffers (Minga v0.1.0)

Copy Markdown View Source

Groups buffer-related fields from EditorState.

Tracks the active buffer pid, the list of open buffers, the active index, and special (unlisted) buffers like Messages.

Summary

Functions

Appends a buffer pid and makes it active.

Appends a buffer pid without changing the active buffer.

Removes a buffer pid, selecting a neighbor as the new active.

Replaces the buffer list and selects the buffer at the given index.

Removes dead pids from the buffer list and selects a live neighbor as active.

Overrides the active buffer pid without updating the index. Use for temporary buffer swaps where the pid is not in the buffer list.

Sets the help buffer pid.

Switches to the buffer at idx, wrapping around.

Switches to the buffer with the given pid, if it exists in the list.

Types

t()

@type t() :: %MingaEditor.State.Buffers{
  active: pid() | nil,
  active_index: non_neg_integer(),
  help: pid() | nil,
  list: [pid()]
}

Functions

add(bs, pid)

@spec add(t(), pid()) :: t()

Appends a buffer pid and makes it active.

add_background(bs, pid)

@spec add_background(t(), pid()) :: t()

Appends a buffer pid without changing the active buffer.

remove(bs, pid)

@spec remove(t(), pid()) :: t()

Removes a buffer pid, selecting a neighbor as the new active.

replace_list(bs, list, idx)

@spec replace_list(t(), [pid()], non_neg_integer()) :: t()

Replaces the buffer list and selects the buffer at the given index.

scrub_dead_active(bs)

@spec scrub_dead_active(t()) :: t()

Removes dead pids from the buffer list and selects a live neighbor as active.

If active is nil, not a pid, or still alive, returns unchanged. If active is dead, filters all dead pids from list and selects a neighbor using the same logic as remove/2.

set_active_override(bs, pid)

@spec set_active_override(t(), pid() | nil) :: t()

Overrides the active buffer pid without updating the index. Use for temporary buffer swaps where the pid is not in the buffer list.

set_help(bs, pid)

@spec set_help(t(), pid() | nil) :: t()

Sets the help buffer pid.

switch_to(bs, idx)

@spec switch_to(t(), non_neg_integer()) :: t()

Switches to the buffer at idx, wrapping around.

switch_to_pid(bs, pid)

@spec switch_to_pid(t(), pid()) :: t()

Switches to the buffer with the given pid, if it exists in the list.