on master help sign in
Implement command to change the indent-style setting of a document.
358ea6aNathan Vegdahl
helix-term/src/commands.rs+30−1
@@ -9,7 +9,7 @@ use helix_core::{
9};
9};
10
10
11use helix_view::{
11use helix_view::{
12− document::Mode,
12+ document::{IndentStyle, Mode},
13 view::{View, PADDING},
13 view::{View, PADDING},
14 Document, DocumentId, Editor, ViewId,
14 Document, DocumentId, Editor, ViewId,
15};
15};
@@ -979,6 +979,28 @@ mod cmd {
979 doc.format(view.id)
979 doc.format(view.id)
980 }
980 }
981
981
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+
982 fn earlier(editor: &mut Editor, args: &[&str], event: PromptEvent) {
1004 fn earlier(editor: &mut Editor, args: &[&str], event: PromptEvent) {
983 let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() {
1005 let uk = match args.join(" ").parse::<helix_core::history::UndoKind>() {
984 Ok(uk) => uk,
1006 Ok(uk) => uk,
@@ -1143,6 +1165,13 @@ mod cmd {
1143 fun: format,
1165 fun: format,
1144 completer: None,
1166 completer: None,
1145 },
1167 },
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+ },
1146 Command {
1175 Command {
1147 name: "earlier",
1176 name: "earlier",
1148 alias: Some("ear"),
1177 alias: Some("ear"),
helix-term/src/ui/editor.rs+1−1
@@ -501,7 +501,7 @@ impl EditorView {
501 // Compute the individual info strings.
501 // Compute the individual info strings.
502 let diag_count = format!("{}", doc.diagnostics().len());
502 let diag_count = format!("{}", doc.diagnostics().len());
503 let indent_info = match doc.indent_style {
503 let indent_info = match doc.indent_style {
504− IndentStyle::Tabs => "tab",
504+ IndentStyle::Tabs => "tabs",
505 IndentStyle::Spaces(1) => "spaces:1",
505 IndentStyle::Spaces(1) => "spaces:1",
506 IndentStyle::Spaces(2) => "spaces:2",
506 IndentStyle::Spaces(2) => "spaces:2",
507 IndentStyle::Spaces(3) => "spaces:3",
507 IndentStyle::Spaces(3) => "spaces:3",