on master help sign in
feat: show current language when no argument is provided (#5895)
commit78a1e2db6035b326d7536fbd0fb60f9fc586d978 authorGuillaume <guillaume.frichet@gmail.com> dateThu 16 Feb 2023, 15:48 (4 years ago) parenta1a6d5f
4 files changed+15−4
book/src/generated/typable-cmd.md+1−1 helix-term/src/commands/typed.rs+10−2 helix-term/src/ui/statusline.rs+2−1 helix-view/src/document.rs+2
book/src/generated/typable-cmd.md+1−1
@@ -59,7 +59,7 @@
5959| `:hsplit-new`, `:hnew` | Open a scratch buffer in a horizontal split. |
6060| `:tutor` | Open the tutorial. |
6161| `: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). |
6363| `:set-option`, `:set` | Set a config option at runtime.<br>For example to disable smart case search, use `:set search.smart-case false`. |
6464| `:toggle-option`, `:toggle` | Toggle a boolean config option at runtime.<br>For example to toggle smart case search, use `:toggle search.smart-case`. |
6565| `: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;
66use super::*;
77
88use helix_core::encoding;
9+use helix_view::document::DEFAULT_LANGUAGE_NAME;
910use helix_view::editor::{Action, CloseError, ConfigEvent};
1011use serde_json::Value;
1112use ui::completers::{self, Completer};
@@ -1697,13 +1698,20 @@ fn language(
16971698 return Ok(());
16981699 }
16991700
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+
17001708 if args.len() != 1 {
17011709 anyhow::bail!("Bad arguments. Usage: `:set-language language`");
17021710 }
17031711
17041712 let doc = doc_mut!(cx.editor);
17051713
1706− if args[0] == "text" {
1714+ if args[0] == DEFAULT_LANGUAGE_NAME {
17071715 doc.set_language(None, None)
17081716 } else {
17091717 doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone())?;
@@ -2414,7 +2422,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
24142422 TypableCommand {
24152423 name: "set-language",
24162424 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).",
24182426 fun: language,
24192427 completer: Some(completers::language),
24202428 },
helix-term/src/ui/statusline.rs+2−1
@@ -1,5 +1,6 @@
11use helix_core::{coords_at_pos, encoding, Position};
22use helix_lsp::lsp::DiagnosticSeverity;
3+use helix_view::document::DEFAULT_LANGUAGE_NAME;
34use helix_view::{
45 document::{Mode, SCRATCH_BUFFER_NAME},
56 graphics::Rect,
@@ -405,7 +406,7 @@ fn render_file_type<F>(context: &mut RenderContext, write: F)
405406where
406407 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
407408{
408− let file_type = context.doc.language_name().unwrap_or("text");
409+ let file_type = context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
409410
410411 write(context, format!(" {} ", file_type), None);
411412}
helix-view/src/document.rs+2
@@ -39,6 +39,8 @@ const BUF_SIZE: usize = 8192;
3939
4040const DEFAULT_INDENT: IndentStyle = IndentStyle::Tabs;
4141
42+pub const DEFAULT_LANGUAGE_NAME: &str = "text";
43+
4244pub const SCRATCH_BUFFER_NAME: &str = "[scratch]";
4345
4446#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]