pub trait Buffer {
Show 24 methods fn len(&self) -> usize; fn is_empty(&self) -> bool; fn get_tag(&self, tag: char) -> Result<usize, &'static str>; fn get_matching(
        &self,
        pattern: &str,
        curr_line: usize,
        backwards: bool
    ) -> Result<usize, &'static str>; fn mark_matching(
        &mut self,
        pattern: &str,
        selection: (usize, usize),
        inverse: bool
    ) -> Result<(), &'static str>; fn get_marked(&mut self) -> Result<Option<usize>, &'static str>; fn tag_line(&mut self, index: usize, tag: char) -> Result<(), &'static str>; fn insert<'a>(
        &mut self,
        data: &mut dyn Iterator<Item = &'a str>,
        index: usize
    ) -> Result<(), &'static str>; fn cut(&mut self, selection: (usize, usize)) -> Result<(), &'static str>; fn change<'a>(
        &mut self,
        data: &mut dyn Iterator<Item = &'a str>,
        selection: (usize, usize)
    ) -> Result<(), &'static str>; fn mov(
        &mut self,
        selection: (usize, usize),
        index: usize
    ) -> Result<(), &'static str>; fn mov_copy(
        &mut self,
        selection: (usize, usize),
        index: usize
    ) -> Result<(), &'static str>; fn join(&mut self, selection: (usize, usize)) -> Result<(), &'static str>; fn reflow(
        &mut self,
        selection: (usize, usize),
        width: usize
    ) -> Result<usize, &'static str>; fn copy(&mut self, selection: (usize, usize)) -> Result<(), &'static str>; fn paste(&mut self, index: usize) -> Result<usize, &'static str>; fn search_replace(
        &mut self,
        pattern: (&str, &str),
        selection: (usize, usize),
        global: bool
    ) -> Result<usize, &'static str>; fn read_from(
        &mut self,
        path: &str,
        index: Option<usize>,
        must_exist: bool
    ) -> Result<usize, &'static str>; fn write_to(
        &mut self,
        selection: Option<(usize, usize)>,
        path: &str,
        append: bool
    ) -> Result<(), &'static str>; fn saved(&self) -> bool; fn undo(&mut self, steps: isize) -> Result<(), &'static str>; fn undo_range(&self) -> Result<Range<isize>, &'static str>; fn snapshot(&mut self) -> Result<(), &'static str>; fn get_selection<'a>(
        &'a self,
        selection: (usize, usize)
    ) -> Result<Box<dyn Iterator<Item = (char, &'a str)> + 'a>, &'static str>;
}
Expand description

Trait that defines a buffer supporting ’ed’s base commands

BEWARE!!! 1-indexed! This means line 0 doesn’t exist, error if given (use verify_selection/verify_line below) BUT, index 0 is valid (therefore use verify_index instead) Subtract 1 to get 0 indexed. It is recommended to use .saturating_sub(1)

Required Methods

Return the number of lines stored in the buffer

Return true if the buffer is empty

Get line tagged with given letter. Not found is error

Return the nearest previous/following index in the selection that contains the regex pattern

Set the matched flag on all lines matching given pattern

Get a line with the matched flag set, clearing that line’s flag

Mark a line with a letter, mark with ‘\0’ to clear

Takes a iterator over lines in strings and inserts after given index

Cut the selection from the buffer, into the clipboard

Replace selection with input

Move selection to immediately after index

Insert a copy of the selection immediately after index

Join all lines in selection into one line

Join all lines to one and split into lines of less than given width Returns end of selection after change

Copy selected lines into clipboard

Paste the clipboard contents after given index Leave clipboard unchanged

Perform regex search and replace on the selection changing pattern.0 to pattern.1 Should interpret escape sequences in both patterns. At minimum \n and \. If pattern is empty, should re-use stored pattern from previous s command Returns new end of selection, since it may delete or add lines Beware that it may delete the whole selection just as ‘c’

Read to the buffer from given path If index is None replaces current buffer with read lines Else inserts read lines after given index Return number of lines read

Write the buffer to given path

Returns true if no changes have been made since last saving

Undo to given numbers of snapshots back (limited by snapshots created) If negative: redo that number of snapshots instead (limited by undone snapshots) Returns error if steps move to invalid snapshot, use undo_range to get limits

Get how far forward/backward redo/undo is possible Returns range of allowed undo arguments

Create a checkpoint to undo/redo to

Return selection as line iterator giving tag and text (‘\0’ as tag value represents absence of tag)

Implementors