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.
Procedures for creating new buffers and related accessors.
Create a new, initially empty, line buffer.
(make-buffer)Returns the element at index in the buffer, starting at zero.
(buffer-ref buffer index)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)Length of the buffer, i.e. amount of lines currently stored in it.
(buffer-length buffer)Predicate which returns true if the buffer is empty.
(buffer-empty? buffer)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!.
Execute the given thunk and make all buffer operations performed
in thunk undoable.
(buffer-with-undo buffer thunk)Predicate to check if the undo stack is empty, returns false if it is.
(buffer-has-undo? buffer)Revert last operation tracked by buffer-with-undo. The undo is itself reversible via buffer-undo!.
(buffer-undo! buffer)Procedures which modify the buffer content. All operations can be undone using buffer-undo!.
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)Removes all lines within the buffer at the given inclusive range
range between start and end.
(buffer-remove! buffer start end)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)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)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)