From 3ded2f9307531d451c3a5e0ae871d3dd95ac3888 Mon Sep 17 00:00:00 2001 From: LEI Date: Fri, 10 Feb 2023 00:07:23 +0100 Subject: [PATCH] feat: show current language when no argument is provided --- book/src/generated/typable-cmd.md | 2 +- helix-core/src/lib.rs | 2 ++ helix-term/src/commands/typed.rs | 13 ++++++++++--- helix-term/src/ui/statusline.rs | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 0ff501a33fdb3..32c850057844e 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -59,7 +59,7 @@ | `:hsplit-new`, `:hnew` | Open a scratch buffer in a horizontal split. | | `:tutor` | Open the tutorial. | | `:goto`, `:g` | Goto line number. | -| `:set-language`, `:lang` | Set the language of current buffer. | +| `:set-language`, `:lang` | Set the language of current buffer (show current language if no value specified). | | `:set-option`, `:set` | Set a config option at runtime.
For example to disable smart case search, use `:set search.smart-case false`. | | `:get-option`, `:get` | Get the current value of a config option. | | `:sort` | Sort ranges in selection. | diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index e3f862a6054c4..9d1b55b4f94b2 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -111,3 +111,5 @@ pub use diagnostic::Diagnostic; pub use line_ending::{LineEnding, DEFAULT_LINE_ENDING}; pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction}; + +pub const DEFAULT_LANGUAGE: &str = "text"; diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 0cc1b7432978c..8b00f83cc25b0 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -5,7 +5,7 @@ use crate::job::Job; use super::*; -use helix_core::encoding; +use helix_core::{DEFAULT_LANGUAGE, encoding}; use helix_view::editor::{Action, CloseError, ConfigEvent}; use ui::completers::{self, Completer}; @@ -1656,13 +1656,20 @@ fn language( return Ok(()); } + if args.is_empty() { + let doc = doc!(cx.editor); + let language = &doc.language_name().unwrap_or(DEFAULT_LANGUAGE); + cx.editor.set_status(language.to_string()); + return Ok(()); + } + if args.len() != 1 { anyhow::bail!("Bad arguments. Usage: `:set-language language`"); } let doc = doc_mut!(cx.editor); - if args[0] == "text" { + if args[0] == DEFAULT_LANGUAGE { doc.set_language(None, None) } else { doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone())?; @@ -2373,7 +2380,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "set-language", aliases: &["lang"], - doc: "Set the language of current buffer.", + doc: "Set the language of current buffer (show current language if no value specified).", fun: language, completer: Some(completers::language), }, diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index a25b4540d1f90..712e8b2d74f57 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -1,4 +1,4 @@ -use helix_core::{coords_at_pos, encoding, Position}; +use helix_core::{coords_at_pos, encoding, Position, DEFAULT_LANGUAGE}; use helix_lsp::lsp::DiagnosticSeverity; use helix_view::{ document::{Mode, SCRATCH_BUFFER_NAME}, @@ -402,7 +402,7 @@ fn render_file_type(context: &mut RenderContext, write: F) where F: Fn(&mut RenderContext, String, Option