diff options
author | Nathan Vegdahl | 2021-06-14 01:09:22 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-06-15 01:32:23 +0000 |
commit | 358ea6a37ccc3ee98f3680c9b4ee0dd0aa0781d2 (patch) | |
tree | 4278424ca919d4caf0a6e57eb877c8055467f94a /helix-term/src/commands.rs | |
parent | 8648e483f772b4791e5618c4c8b3db8926ae356d (diff) |
Implement command to change the indent-style setting of a document.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b5f37563..94003c2e 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -9,7 +9,7 @@ use helix_core::{ }; use helix_view::{ - document::Mode, + document::{IndentStyle, Mode}, view::{View, PADDING}, Document, DocumentId, Editor, ViewId, }; @@ -979,6 +979,28 @@ mod cmd { doc.format(view.id) } + fn set_indent_style(editor: &mut Editor, args: &[&str], event: PromptEvent) { + use IndentStyle::*; + + let style = match args.get(0) { + Some(arg) if "tabs".starts_with(&arg.to_lowercase()) => Some(Tabs), + Some(arg) if arg.len() == 1 => { + let ch = arg.chars().next().unwrap(); + if ('1'..='8').contains(&ch) { + Some(Spaces(ch.to_digit(10).unwrap() as u8)) + } else { + None + } + } + _ => None, + }; + + if let Some(s) = style { + let (_, doc) = editor.current(); + doc.indent_style = s; + } + } + fn earlier(editor: &mut Editor, args: &[&str], event: PromptEvent) { let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() { Ok(uk) => uk, @@ -1144,6 +1166,13 @@ mod cmd { completer: None, }, Command { + name: "indent_style", + alias: None, + doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)", + fun: set_indent_style, + completer: None, + }, + Command { name: "earlier", alias: Some("ear"), doc: "Jump back to an earlier point in edit history. Accepts a number of steps or a time span.", |