edward.buffer

A text buffer for line-based data with undo support. Operations on the buffer address lines, the first line starts at index 1. The special index 0 can be used with the append command to insert text before the first line. For other commands, index 0 is equivalent to index 1. Targeting a line outside the current buffer bounds causes an error to be raised.

Index

Table of contents

Buffer Interface

Procedures for creating new buffers and related accessors.

procedure make-buffer

Create a new, initially empty, line buffer.

(make-buffer)

procedure buffer-ref

Returns the element at index in the buffer, starting at zero.

(buffer-ref buffer index)

procedure buffer->list

Convert the line buffer to a list of lines. Additionally, this procedure accepts an optional start and end parameter. If these parameters are given the list only contains the elements between start and end. By default the whole buffer is converted.

(buffer->list buffer . o)

procedure buffer-length

Length of the buffer, i.e. amount of lines currently stored in it.

(buffer-length buffer)

procedure buffer-empty?

Predicate which returns true if the buffer is empty.

(buffer-empty? buffer)

Undo Stack

Procedures for managing the undo stack of the line buffer. The undo stack does not support multilevel undo. That is, the last undo can itself be undone using buffer-undo!.

procedure buffer-with-undo

Execute the given thunk and make all buffer operations performed in thunk undoable.

(buffer-with-undo buffer thunk)

procedure buffer-has-undo?

Predicate to check if the undo stack is empty, returns false if it is.

(buffer-has-undo? buffer)

procedure buffer-undo!

Revert last operation tracked by buffer-with-undo. The undo is itself reversible via buffer-undo!.

(buffer-undo! buffer)

Buffer Operations

Procedures which modify the buffer content. All operations can be undone using buffer-undo!.

procedure buffer-append!

Append the given text to the buffer after the given line number. The special line number 0 can be used here to add lines to the beginning of the buffer.

(buffer-append! buffer line text)

procedure buffer-remove!

Removes all lines within the buffer at the given inclusive range range between start and end.

(buffer-remove! buffer start end)

procedure buffer-replace!

Replace lines in the inclusive range between start and end with the data given by text which must be a list of lines (i.e. strings).

(buffer-replace! buffer start end text)

procedure buffer-join!

Join lines in the inclusive range between start and end into a single line by removing all newline characters within the specified range.

(buffer-join! buffer start end)

procedure buffer-move!

Move lines in the inclusive range between start and end to the destination line number dest. The destination must always be outside the specified inclusive range.

(buffer-move! buffer start end dest)