on master help sign in
feat: show current language when no argument is provided (#5895)
78a1e2dGuillaume
book/src/generated/typable-cmd.md+1−1
@@ -59,7 +59,7 @@
59| `:hsplit-new`, `:hnew` | Open a scratch buffer in a horizontal split. |
59| `:hsplit-new`, `:hnew` | Open a scratch buffer in a horizontal split. |
60| `:tutor` | Open the tutorial. |
60| `:tutor` | Open the tutorial. |
61| `:goto`, `:g` | Goto line number. |
61| `:goto`, `:g` | Goto line number. |
62−| `:set-language`, `:lang` | Set the language of current buffer. |
62+| `:set-language`, `:lang` | Set the language of current buffer (show current language if no value specified). |
63| `:set-option`, `:set` | Set a config option at runtime.<br>For example to disable smart case search, use `:set search.smart-case false`. |
63| `:set-option`, `:set` | Set a config option at runtime.<br>For example to disable smart case search, use `:set search.smart-case false`. |
64| `:toggle-option`, `:toggle` | Toggle a boolean config option at runtime.<br>For example to toggle smart case search, use `:toggle search.smart-case`. |
64| `:toggle-option`, `:toggle` | Toggle a boolean config option at runtime.<br>For example to toggle smart case search, use `:toggle search.smart-case`. |
65| `:get-option`, `:get` | Get the current value of a config option. |
65| `:get-option`, `:get` | Get the current value of a config option. |
helix-term/src/commands/typed.rs+10−2
@@ -6,6 +6,7 @@ use crate::job::Job;
6use super::*;
6use super::*;
7
7
8use helix_core::encoding;
8use helix_core::encoding;
9+use helix_view::document::DEFAULT_LANGUAGE_NAME;
9use helix_view::editor::{Action, CloseError, ConfigEvent};
10use helix_view::editor::{Action, CloseError, ConfigEvent};
10use serde_json::Value;
11use serde_json::Value;
11use ui::completers::{self, Completer};
12use ui::completers::{self, Completer};
@@ -1697,13 +1698,20 @@ fn language(
1697 return Ok(());
1698 return Ok(());
1698 }
1699 }
1699
1700
1701+ if args.is_empty() {
1702+ let doc = doc!(cx.editor);
1703+ let language = &doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
1704+ cx.editor.set_status(language.to_string());
1705+ return Ok(());
1706+ }
1707+
1700 if args.len() != 1 {
1708 if args.len() != 1 {
1701 anyhow::bail!("Bad arguments. Usage: `:set-language language`");
1709 anyhow::bail!("Bad arguments. Usage: `:set-language language`");
1702 }
1710 }
1703
1711
1704 let doc = doc_mut!(cx.editor);
1712 let doc = doc_mut!(cx.editor);
1705
1713
1706− if args[0] == "text" {
1714+ if args[0] == DEFAULT_LANGUAGE_NAME {
1707 doc.set_language(None, None)
1715 doc.set_language(None, None)
1708 } else {
1716 } else {
1709 doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone())?;
1717 doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone())?;
@@ -2414,7 +2422,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2414 TypableCommand {
2422 TypableCommand {
2415 name: "set-language",
2423 name: "set-language",
2416 aliases: &["lang"],
2424 aliases: &["lang"],
2417− doc: "Set the language of current buffer.",
2425+ doc: "Set the language of current buffer (show current language if no value specified).",
2418 fun: language,
2426 fun: language,
2419 completer: Some(completers::language),
2427 completer: Some(completers::language),
2420 },
2428 },
helix-term/src/ui/statusline.rs+2−1
@@ -1,5 +1,6 @@
1use helix_core::{coords_at_pos, encoding, Position};
1use helix_core::{coords_at_pos, encoding, Position};
2use helix_lsp::lsp::DiagnosticSeverity;
2use helix_lsp::lsp::DiagnosticSeverity;
3+use helix_view::document::DEFAULT_LANGUAGE_NAME;
3use helix_view::{
4use helix_view::{
4 document::{Mode, SCRATCH_BUFFER_NAME},
5 document::{Mode, SCRATCH_BUFFER_NAME},
5 graphics::Rect,
6 graphics::Rect,
@@ -405,7 +406,7 @@ fn render_file_type<F>(context: &mut RenderContext, write: F)
405where
406where
406 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
407 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
407{
408{
408− let file_type = context.doc.language_name().unwrap_or("text");
409+ let file_type = context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
409
410
410 write(context, format!(" {} ", file_type), None);
411 write(context, format!(" {} ", file_type), None);
411}
412}
helix-view/src/document.rs+2
@@ -39,6 +39,8 @@ const BUF_SIZE: usize = 8192;
39
39
40const DEFAULT_INDENT: IndentStyle = IndentStyle::Tabs;
40const DEFAULT_INDENT: IndentStyle = IndentStyle::Tabs;
41
41
42+pub const DEFAULT_LANGUAGE_NAME: &str = "text";
43+
42pub const SCRATCH_BUFFER_NAME: &str = "[scratch]";
44pub const SCRATCH_BUFFER_NAME: &str = "[scratch]";
43
45
44#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
46#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]