From 733ebcdaebfb73c6dd4e2a5773ab032b57c4e757 Mon Sep 17 00:00:00 2001 From: Erasin Wang Date: Thu, 29 May 2025 21:20:22 +0800 Subject: [PATCH] Add file indentation style for statusline (#13632) --- book/src/editor.md | 1 + helix-term/src/ui/statusline.rs | 19 +++++++++++++++++++ helix-view/src/editor.rs | 3 +++ 3 files changed, 23 insertions(+) diff --git a/book/src/editor.md b/book/src/editor.md index c2a7af764..00db71d27 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -133,6 +133,7 @@ The following statusline elements can be configured: | `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) | | `file-encoding` | The encoding of the opened file if it differs from UTF-8 | | `file-line-ending` | The file line endings (CRLF or LF) | +| `file-indent-style` | The file indentation style | | `read-only-indicator` | An indicator that shows `[readonly]` when a file cannot be written | | `total-line-numbers` | The total line numbers of the opened file | | `file-type` | The type of the opened file | diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index df23123c5..ea3d27bd6 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -1,5 +1,6 @@ use std::borrow::Cow; +use helix_core::indent::IndentStyle; use helix_core::{coords_at_pos, encoding, Position}; use helix_lsp::lsp::DiagnosticSeverity; use helix_view::document::DEFAULT_LANGUAGE_NAME; @@ -142,6 +143,7 @@ where helix_view::editor::StatusLineElement::ReadOnlyIndicator => render_read_only_indicator, helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding, helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending, + helix_view::editor::StatusLineElement::FileIndentStyle => render_file_indent_style, helix_view::editor::StatusLineElement::FileType => render_file_type, helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics, helix_view::editor::StatusLineElement::WorkspaceDiagnostics => render_workspace_diagnostics, @@ -554,3 +556,20 @@ where write(context, format!(" reg={} ", reg).into()) } } + +fn render_file_indent_style<'a, F>(context: &mut RenderContext<'a>, write: F) +where + F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, +{ + let style = context.doc.indent_style; + + write( + context, + match style { + IndentStyle::Tabs => " tabs ".into(), + IndentStyle::Spaces(indent) => { + format!(" {} space{} ", indent, if indent == 1 { "" } else { "s" }).into() + } + }, + ); +} diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 0ecddd879..bc811b88b 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -580,6 +580,9 @@ pub enum StatusLineElement { /// The file line endings (CRLF or LF) FileLineEnding, + /// The file indentation style + FileIndentStyle, + /// The file type (language ID or "text") FileType,