Skip to content

Commit

Permalink
feat: show current language when no argument is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
LEI committed Feb 10, 2023
1 parent 8a3ec44 commit 3ded2f9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion book/src/generated/typable-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>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. |
Expand Down
2 changes: 2 additions & 0 deletions helix-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
13 changes: 10 additions & 3 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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())?;
Expand Down Expand Up @@ -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),
},
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -402,7 +402,7 @@ fn render_file_type<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let file_type = context.doc.language_name().unwrap_or("text");
let file_type = context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE);

write(context, format!(" {} ", file_type), None);
}
Expand Down

0 comments on commit 3ded2f9

Please # to comment.