on master help sign in
Implement command to change the indent-style setting of a document.
commit358ea6a37ccc3ee98f3680c9b4ee0dd0aa0781d2 authorNathan Vegdahl <cessen@cessen.com> dateSun 13 Jun 2021, 18:09 (5 years ago) parent8648e48
2 files changed+31−2
helix-term/src/commands.rs+30−1 helix-term/src/ui/editor.rs+1−1
helix-term/src/commands.rs+30−1
@@ -9,7 +9,7 @@ use helix_core::{
99};
1010
1111use helix_view::{
12− document::Mode,
12+ document::{IndentStyle, Mode},
1313 view::{View, PADDING},
1414 Document, DocumentId, Editor, ViewId,
1515};
@@ -979,6 +979,28 @@ mod cmd {
979979 doc.format(view.id)
980980 }
981981
982+ fn set_indent_style(editor: &mut Editor, args: &[&str], event: PromptEvent) {
983+ use IndentStyle::*;
984+
985+ let style = match args.get(0) {
986+ Some(arg) if "tabs".starts_with(&arg.to_lowercase()) => Some(Tabs),
987+ Some(arg) if arg.len() == 1 => {
988+ let ch = arg.chars().next().unwrap();
989+ if ('1'..='8').contains(&ch) {
990+ Some(Spaces(ch.to_digit(10).unwrap() as u8))
991+ } else {
992+ None
993+ }
994+ }
995+ _ => None,
996+ };
997+
998+ if let Some(s) = style {
999+ let (_, doc) = editor.current();
1000+ doc.indent_style = s;
1001+ }
1002+ }
1003+
9821004 fn earlier(editor: &mut Editor, args: &[&str], event: PromptEvent) {
9831005 let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() {
9841006 Ok(uk) => uk,
@@ -1143,6 +1165,13 @@ mod cmd {
11431165 fun: format,
11441166 completer: None,
11451167 },
1168+ Command {
1169+ name: "indent_style",
1170+ alias: None,
1171+ doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)",
1172+ fun: set_indent_style,
1173+ completer: None,
1174+ },
11461175 Command {
11471176 name: "earlier",
11481177 alias: Some("ear"),
helix-term/src/ui/editor.rs+1−1
@@ -501,7 +501,7 @@ impl EditorView {
501501 // Compute the individual info strings.
502502 let diag_count = format!("{}", doc.diagnostics().len());
503503 let indent_info = match doc.indent_style {
504− IndentStyle::Tabs => "tab",
504+ IndentStyle::Tabs => "tabs",
505505 IndentStyle::Spaces(1) => "spaces:1",
506506 IndentStyle::Spaces(2) => "spaces:2",
507507 IndentStyle::Spaces(3) => "spaces:3",