Merge branch 'master' into help-command

pull/997/head
Omnikar 3 years ago
commit 911efce77d
No known key found for this signature in database
GPG Key ID: 7DE6694CDA7885ED

@ -34,7 +34,7 @@
| protobuf | ✓ | | ✓ | |
| python | ✓ | ✓ | ✓ | `pylsp` |
| racket | | | | `racket` |
| ruby | ✓ | | | `solargraph` |
| ruby | ✓ | | | `solargraph` |
| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
| scala | ✓ | | ✓ | `metals` |
| svelte | ✓ | | ✓ | `svelteserver` |

@ -42,4 +42,6 @@
| `: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. |
| `:help`, `:h` | Open documentation for a command or keybind. |

@ -2671,6 +2671,56 @@ pub mod cmd {
Ok(())
}
fn sort(
cx: &mut compositor::Context,
args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
sort_impl(cx, args, false)
}
fn sort_reverse(
cx: &mut compositor::Context,
args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
sort_impl(cx, args, true)
}
fn sort_impl(
cx: &mut compositor::Context,
_args: &[Cow<str>],
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(())
}
fn help(
cx: &mut compositor::Context,
args: &[Cow<str>],
@ -2999,6 +3049,20 @@ pub mod cmd {
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,
},
TypableCommand {
name: "help",
aliases: &["h"],

@ -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",
]
Loading…
Cancel
Save