From 7001665342ade12823fba4f358a7e8efc2245a2b Mon Sep 17 00:00:00 2001 From: Stuart Hinson Date: Sun, 26 Dec 2021 23:07:09 -0500 Subject: [PATCH 1/2] Add ruby indents (#1372) * Add ruby indents * Include ruby in generated docs --- book/src/generated/lang-support.md | 2 +- runtime/queries/ruby/indents.toml | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/ruby/indents.toml diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 9c42005bb..280944843 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -34,7 +34,7 @@ | protobuf | ✓ | | ✓ | | | python | ✓ | ✓ | ✓ | `pylsp` | | racket | | | | `racket` | -| ruby | ✓ | | | `solargraph` | +| ruby | ✓ | | ✓ | `solargraph` | | rust | ✓ | ✓ | ✓ | `rust-analyzer` | | scala | ✓ | | ✓ | `metals` | | svelte | ✓ | | ✓ | `svelteserver` | diff --git a/runtime/queries/ruby/indents.toml b/runtime/queries/ruby/indents.toml new file mode 100644 index 000000000..b417751fc --- /dev/null +++ b/runtime/queries/ruby/indents.toml @@ -0,0 +1,25 @@ +indent = [ + "argument_list", + "array", + "begin", + "block", + "call", + "class", + "case", + "do_block", + "elsif", + "if", + "hash", + "method", + "module", + "singleton_class", + "singleton_method", +] + +outdent = [ + ")", + "}", + "]", + "end", + "when", +] From a4641a8613bcbe4ad01d28d3d2a6f4509fef96a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Dzivjak?= Date: Mon, 27 Dec 2021 05:11:06 +0100 Subject: [PATCH 2/2] feat(commands): sort command (#1288) * feat(commands): sort/rsort command Add basic implementation of sort command. * Sort by selections instead, implement reverse sort * Generate docs * Rename sort! to rsort --- book/src/generated/typable-cmd.md | 2 + helix-term/src/commands.rs | 66 ++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index f12082bb1..45129cc15 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -42,3 +42,5 @@ | `:tutor` | Open the tutorial. | | `:goto`, `:g` | Go to line number. | | `:set-option`, `:set` | Set a config option at runtime | +| `:sort` | Sort ranges in selection. | +| `:rsort` | Sort ranges in selection in reverse order. | diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 524c50ce5..16a2cf351 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2671,6 +2671,56 @@ pub mod cmd { Ok(()) } + fn sort( + cx: &mut compositor::Context, + args: &[Cow], + _event: PromptEvent, + ) -> anyhow::Result<()> { + sort_impl(cx, args, false) + } + + fn sort_reverse( + cx: &mut compositor::Context, + args: &[Cow], + _event: PromptEvent, + ) -> anyhow::Result<()> { + sort_impl(cx, args, true) + } + + fn sort_impl( + cx: &mut compositor::Context, + _args: &[Cow], + reverse: bool, + ) -> anyhow::Result<()> { + let (view, doc) = current!(cx.editor); + let text = doc.text().slice(..); + + let selection = doc.selection(view.id); + + let mut fragments: Vec<_> = selection + .fragments(text) + .map(|fragment| Tendril::from_slice(&fragment)) + .collect(); + + fragments.sort_by(match reverse { + true => |a: &Tendril, b: &Tendril| b.cmp(a), + false => |a: &Tendril, b: &Tendril| a.cmp(b), + }); + + let transaction = Transaction::change( + doc.text(), + selection + .into_iter() + .zip(fragments) + .map(|(s, fragment)| (s.from(), s.to(), Some(fragment))), + ); + + doc.apply(&transaction, view.id); + doc.append_changes_to_history(view.id); + + Ok(()) + } + pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "quit", @@ -2965,7 +3015,21 @@ pub mod cmd { doc: "Set a config option at runtime", fun: setting, completer: Some(completers::setting), - } + }, + TypableCommand { + name: "sort", + aliases: &[], + doc: "Sort ranges in selection.", + fun: sort, + completer: None, + }, + TypableCommand { + name: "rsort", + aliases: &[], + doc: "Sort ranges in selection in reverse order.", + fun: sort_reverse, + completer: None, + }, ]; pub static TYPABLE_COMMAND_MAP: Lazy> =