editor

Launching the user’s external editor on a temporary file.

enum Error

source

pub enum Error

Errors that can occur when launching an external editor.

Variant Description
EditorFailed(String, String) The editor process exited with a non-zero status or was terminated by a signal.
EditorNotFound The editor command is empty after shell splitting, such as EDITOR=" ".
Io(Error) An underlying I/O error occurred while reading or writing the temp file.

Implements Debug, Error, Display, From<Error>.

fn edit_text_with_suffix

source

pub fn edit_text_with_suffix(initial: &str, suffix: &str) -> Result<String, Error>

Open the user’s preferred editor with initial text pre-filled in a temporary file using the given suffix (e.g. ".md") for syntax highlighting, and return the final contents after the editor exits.

Parameter Type Description
initial &str the text to start with; an empty string leaves the file empty
suffix &str the temporary file’s suffix, such as ".md"
returns Result<String, Error> The file’s contents after the editor exits, or an error when the file cannot be written or read, or the editor fails.

fn resolve_editor

source

pub fn resolve_editor() -> String

Return the editor command from $EDITOR, falling back to $VISUAL, then vi.

Parameter Type Description
returns String The editor command line, which may hold arguments. An empty $EDITOR gives vi without trying $VISUAL.

fn open_editor

source

fn open_editor(path: &Path) -> Result<(), Error>

Run the editor on path and wait for it to exit.

The editor command is split with shell quoting rules, so it may carry arguments such as code --wait.

Parameter Type Description
path &Path the file to edit
returns Result<(), Error> Ok(()) when the editor exits successfully; Error::EditorFailed for a non-zero exit or a signal, Error::EditorNotFound for an empty command, or Error::Io when the command cannot be parsed or started.