Add a bunch of aliases (#797)

* add a bunch of aliases

* apply code review from archseer
pull/804/head
Irevoire 3 years ago committed by GitHub
parent 0af8928d63
commit 7e958e1834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1492,7 +1492,7 @@ mod cmd {
#[derive(Clone)] #[derive(Clone)]
pub struct TypableCommand { pub struct TypableCommand {
pub name: &'static str, pub name: &'static str,
pub alias: Option<&'static str>, pub aliases: &'static [&'static str],
pub doc: &'static str, pub doc: &'static str,
// params, flags, helper, completer // params, flags, helper, completer
pub fun: fn(&mut compositor::Context, &[&str], PromptEvent) -> anyhow::Result<()>, pub fun: fn(&mut compositor::Context, &[&str], PromptEvent) -> anyhow::Result<()>,
@ -2092,252 +2092,252 @@ mod cmd {
pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand { TypableCommand {
name: "quit", name: "quit",
alias: Some("q"), aliases: &["q"],
doc: "Close the current view.", doc: "Close the current view.",
fun: quit, fun: quit,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "quit!", name: "quit!",
alias: Some("q!"), aliases: &["q!"],
doc: "Close the current view.", doc: "Close the current view.",
fun: force_quit, fun: force_quit,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "open", name: "open",
alias: Some("o"), aliases: &["o"],
doc: "Open a file from disk into the current view.", doc: "Open a file from disk into the current view.",
fun: open, fun: open,
completer: Some(completers::filename), completer: Some(completers::filename),
}, },
TypableCommand { TypableCommand {
name: "write", name: "write",
alias: Some("w"), aliases: &["w"],
doc: "Write changes to disk. Accepts an optional path (:write some/path.txt)", doc: "Write changes to disk. Accepts an optional path (:write some/path.txt)",
fun: write, fun: write,
completer: Some(completers::filename), completer: Some(completers::filename),
}, },
TypableCommand { TypableCommand {
name: "new", name: "new",
alias: Some("n"), aliases: &["n"],
doc: "Create a new scratch buffer.", doc: "Create a new scratch buffer.",
fun: new_file, fun: new_file,
completer: Some(completers::filename), completer: Some(completers::filename),
}, },
TypableCommand { TypableCommand {
name: "format", name: "format",
alias: Some("fmt"), aliases: &["fmt"],
doc: "Format the file using a formatter.", doc: "Format the file using a formatter.",
fun: format, fun: format,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "indent-style", name: "indent-style",
alias: None, aliases: &[],
doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)", doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)",
fun: set_indent_style, fun: set_indent_style,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "line-ending", name: "line-ending",
alias: None, aliases: &[],
doc: "Set the document's default line ending. Options: crlf, lf, cr, ff, nel.", doc: "Set the document's default line ending. Options: crlf, lf, cr, ff, nel.",
fun: set_line_ending, fun: set_line_ending,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "earlier", name: "earlier",
alias: Some("ear"), aliases: &["ear"],
doc: "Jump back to an earlier point in edit history. Accepts a number of steps or a time span.", doc: "Jump back to an earlier point in edit history. Accepts a number of steps or a time span.",
fun: earlier, fun: earlier,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "later", name: "later",
alias: Some("lat"), aliases: &["lat"],
doc: "Jump to a later point in edit history. Accepts a number of steps or a time span.", doc: "Jump to a later point in edit history. Accepts a number of steps or a time span.",
fun: later, fun: later,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "write-quit", name: "write-quit",
alias: Some("wq"), aliases: &["wq", "x"],
doc: "Writes changes to disk and closes the current view. Accepts an optional path (:wq some/path.txt)", doc: "Writes changes to disk and closes the current view. Accepts an optional path (:wq some/path.txt)",
fun: write_quit, fun: write_quit,
completer: Some(completers::filename), completer: Some(completers::filename),
}, },
TypableCommand { TypableCommand {
name: "write-quit!", name: "write-quit!",
alias: Some("wq!"), aliases: &["wq!", "x!"],
doc: "Writes changes to disk and closes the current view forcefully. Accepts an optional path (:wq! some/path.txt)", doc: "Writes changes to disk and closes the current view forcefully. Accepts an optional path (:wq! some/path.txt)",
fun: force_write_quit, fun: force_write_quit,
completer: Some(completers::filename), completer: Some(completers::filename),
}, },
TypableCommand { TypableCommand {
name: "write-all", name: "write-all",
alias: Some("wa"), aliases: &["wa"],
doc: "Writes changes from all views to disk.", doc: "Writes changes from all views to disk.",
fun: write_all, fun: write_all,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "write-quit-all", name: "write-quit-all",
alias: Some("wqa"), aliases: &["wqa", "xa"],
doc: "Writes changes from all views to disk and close all views.", doc: "Writes changes from all views to disk and close all views.",
fun: write_all_quit, fun: write_all_quit,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "write-quit-all!", name: "write-quit-all!",
alias: Some("wqa!"), aliases: &["wqa!", "xa!"],
doc: "Writes changes from all views to disk and close all views forcefully (ignoring unsaved changes).", doc: "Writes changes from all views to disk and close all views forcefully (ignoring unsaved changes).",
fun: force_write_all_quit, fun: force_write_all_quit,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "quit-all", name: "quit-all",
alias: Some("qa"), aliases: &["qa"],
doc: "Close all views.", doc: "Close all views.",
fun: quit_all, fun: quit_all,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "quit-all!", name: "quit-all!",
alias: Some("qa!"), aliases: &["qa!"],
doc: "Close all views forcefully (ignoring unsaved changes).", doc: "Close all views forcefully (ignoring unsaved changes).",
fun: force_quit_all, fun: force_quit_all,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "theme", name: "theme",
alias: None, aliases: &[],
doc: "Change the theme of current view. Requires theme name as argument (:theme <name>)", doc: "Change the theme of current view. Requires theme name as argument (:theme <name>)",
fun: theme, fun: theme,
completer: Some(completers::theme), completer: Some(completers::theme),
}, },
TypableCommand { TypableCommand {
name: "clipboard-yank", name: "clipboard-yank",
alias: None, aliases: &[],
doc: "Yank main selection into system clipboard.", doc: "Yank main selection into system clipboard.",
fun: yank_main_selection_to_clipboard, fun: yank_main_selection_to_clipboard,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "clipboard-yank-join", name: "clipboard-yank-join",
alias: None, aliases: &[],
doc: "Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc. doc: "Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
fun: yank_joined_to_clipboard, fun: yank_joined_to_clipboard,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "primary-clipboard-yank", name: "primary-clipboard-yank",
alias: None, aliases: &[],
doc: "Yank main selection into system primary clipboard.", doc: "Yank main selection into system primary clipboard.",
fun: yank_main_selection_to_primary_clipboard, fun: yank_main_selection_to_primary_clipboard,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "primary-clipboard-yank-join", name: "primary-clipboard-yank-join",
alias: None, aliases: &[],
doc: "Yank joined selections into system primary clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc. doc: "Yank joined selections into system primary clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
fun: yank_joined_to_primary_clipboard, fun: yank_joined_to_primary_clipboard,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "clipboard-paste-after", name: "clipboard-paste-after",
alias: None, aliases: &[],
doc: "Paste system clipboard after selections.", doc: "Paste system clipboard after selections.",
fun: paste_clipboard_after, fun: paste_clipboard_after,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "clipboard-paste-before", name: "clipboard-paste-before",
alias: None, aliases: &[],
doc: "Paste system clipboard before selections.", doc: "Paste system clipboard before selections.",
fun: paste_clipboard_before, fun: paste_clipboard_before,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "clipboard-paste-replace", name: "clipboard-paste-replace",
alias: None, aliases: &[],
doc: "Replace selections with content of system clipboard.", doc: "Replace selections with content of system clipboard.",
fun: replace_selections_with_clipboard, fun: replace_selections_with_clipboard,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "primary-clipboard-paste-after", name: "primary-clipboard-paste-after",
alias: None, aliases: &[],
doc: "Paste primary clipboard after selections.", doc: "Paste primary clipboard after selections.",
fun: paste_primary_clipboard_after, fun: paste_primary_clipboard_after,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "primary-clipboard-paste-before", name: "primary-clipboard-paste-before",
alias: None, aliases: &[],
doc: "Paste primary clipboard before selections.", doc: "Paste primary clipboard before selections.",
fun: paste_primary_clipboard_before, fun: paste_primary_clipboard_before,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "primary-clipboard-paste-replace", name: "primary-clipboard-paste-replace",
alias: None, aliases: &[],
doc: "Replace selections with content of system primary clipboard.", doc: "Replace selections with content of system primary clipboard.",
fun: replace_selections_with_primary_clipboard, fun: replace_selections_with_primary_clipboard,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "show-clipboard-provider", name: "show-clipboard-provider",
alias: None, aliases: &[],
doc: "Show clipboard provider name in status bar.", doc: "Show clipboard provider name in status bar.",
fun: show_clipboard_provider, fun: show_clipboard_provider,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "change-current-directory", name: "change-current-directory",
alias: Some("cd"), aliases: &["cd"],
doc: "Change the current working directory (:cd <dir>).", doc: "Change the current working directory (:cd <dir>).",
fun: change_current_directory, fun: change_current_directory,
completer: Some(completers::directory), completer: Some(completers::directory),
}, },
TypableCommand { TypableCommand {
name: "show-directory", name: "show-directory",
alias: Some("pwd"), aliases: &["pwd"],
doc: "Show the current working directory.", doc: "Show the current working directory.",
fun: show_current_directory, fun: show_current_directory,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "encoding", name: "encoding",
alias: None, aliases: &[],
doc: "Set encoding based on `https://encoding.spec.whatwg.org`", doc: "Set encoding based on `https://encoding.spec.whatwg.org`",
fun: set_encoding, fun: set_encoding,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "reload", name: "reload",
alias: None, aliases: &[],
doc: "Discard changes and reload from the source file.", doc: "Discard changes and reload from the source file.",
fun: reload, fun: reload,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "tree-sitter-scopes", name: "tree-sitter-scopes",
alias: None, aliases: &[],
doc: "Display tree sitter scopes, primarily for theming and development.", doc: "Display tree sitter scopes, primarily for theming and development.",
fun: tree_sitter_scopes, fun: tree_sitter_scopes,
completer: None, completer: None,
}, },
TypableCommand { TypableCommand {
name: "vsplit", name: "vsplit",
alias: Some("vs"), aliases: &["vs"],
doc: "Open the file in a vertical split.", doc: "Open the file in a vertical split.",
fun: vsplit, fun: vsplit,
completer: Some(completers::filename), completer: Some(completers::filename),
}, },
TypableCommand { TypableCommand {
name: "hsplit", name: "hsplit",
alias: Some("sp"), aliases: &["hs", "sp"],
doc: "Open the file in a horizontal split.", doc: "Open the file in a horizontal split.",
fun: hsplit, fun: hsplit,
completer: Some(completers::filename), completer: Some(completers::filename),
@ -2345,16 +2345,13 @@ mod cmd {
]; ];
pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| { pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| {
let mut map = HashMap::new(); TYPABLE_COMMAND_LIST
.into_iter()
for cmd in TYPABLE_COMMAND_LIST { .flat_map(|cmd| {
map.insert(cmd.name, cmd); std::iter::once((cmd.name, cmd))
if let Some(alias) = cmd.alias { .chain(cmd.aliases.into_iter().map(move |&alias| (alias, cmd)))
map.insert(alias, cmd); })
} .collect()
}
map
}); });
} }

Loading…
Cancel
Save