-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switches for typable commands #5828
Comments
|
Would support for this be added by just changing the command function implementations ( |
I think this will be a fair amount of work so I've added the "hard" tag. The work should basically all be scoped to Whatever Kakoune is doing for their switches may be good inspiration and also existing crates like xflags or clap. Though I don't think we would accept a patch that pulls in a dependency like clap - it should be possible to build something specific to our usecase without any extra deps. |
This could be something I can start looking into once #11149 is finished. I'll do some initial scouting to see what the scope of this would look like before I start asking questions on specific features/behavior. |
I think it's worth to remove all these commands:
Instead we can have just two:
Not only does it clean up the mess, it also gives more flexibility. Now we can use any register Note: Instead of using
What if it was like this instead:
I think making it as if we are passing an argument rather than a flag in this case provides a better experience |
I hadn't thought much of alternate ways the order could be, I built around the idea of flags first. With the current implimentation I have in #12288 both yank --register=* --join and yank * --join would be possible (though I am not handling = assignment yet, but just having a space would work though). The changes in #11149 make the arguments an iterator, so in argument first case, its just a normal |
I do know quite a few commands could be combined, but that feels like it would be something that would hold up the base implimentation getting merged for longer than needed, especially when its so easily atomized into separate prs. I did mark that the PR would close this on merger, but perhaps I shouldn't, and then we can add commands here that need to be converted. I can do a few examples (already doing sort), to show how to handle some common flag use. Before that though I am going to wait for some feedback if what I am doing is what is wanted. |
oh yeah, definitely. There's a lot of design decision as to which commands should be removed exactly. so I personally think that you shouldn't worry about thinking about those for your PR. it would be easier to have separate PRs that replace existing commands with switches |
Thinking on some combinations being collapsed, Something like #4423 could be done to add aliases ourselves, but that feature is its own can of worms. Like, is there default aliases provided for these? How do we get the prompt to propagate? etc. |
I don't think that aliases like So the alternative is to keep those aliases but don't have aliases show up in the command prompt. E.g. a command like Instead you'll be able to see the aliases in a sub-menu. Like this:
please let me know what you think about this idea and #4423 may make more sense as a plugin, see this comment by mikedavis. I don't think it's worth worrying about that for now |
For those not familiar with what a typeable command looks like: TypableCommand {
name: "write-all",
aliases: &["wa"],
flags: &[],
doc: "Write changes from all buffers to disk.",
fun: write_all,
signature: CommandSignature::none(),
}, The issue is that the aliases are per command. If you wanted to collapse all let command = shellwords.command();
match command {
"w" => ...
"w!" => ...
} Then, you would have to have to also handle the case where its written with flags. For write, I don't think there is a need for any other kind of flag beside a switch flag, but for other commands, you might have to also handle when a flag might have something assigned to it, and as |
With the docs in mind, though, an TypableCommand {
name: "write",
aliases: alias!["w" => "write", "wa" => "write --all", "w!" => "write --force"],
flags: &[flag!{ long: "force", short: "f", "desc: "forcefully saves buffer" }],
doc: "Write changes from buffer to disk.",
fun: write,
signature: CommandSignature::none(),
}, If the custom commands ever went anywhere, it could potentially use the |
Clap like attribute syntax would be cool here. #[alias("w")]
#[alias("wa" = "% --all")]
#[alias("w!" = "% --force")]
TypableCommamd {
....
} % being placeholder for self cmd |
An update on progress in #12288, have been able to collapse all write commands down to one main one, and map aliases in a way that uses the provided flags to achieve the same behavior as before: |
For some other commands worth looking at to combine, where, If done for all of them, it would bring 31 commands to 7.:
|
awesome! This is really good because users won't be overwhelmed with 100 commands in the completion prompt when they use |
Seeing how large the
":wq" = [":write", ":quit"]
":x" = [":write", ":quit"]
":wbc" = [":write", "buffer --kill"] Then the remaining aliases on |
shell [<flags>]: ...
flags:
--no-popup disables popup
--register, -r <register> saves output to register
move [<flags>]: ...
flags:
--rename, -r renames the current file in-place
--force, -f forcefully moves, creating directories if needed
open [<flags>]: ...
flags:
--register, -r <register> register to read in the path from In conjunction with [keys.normal.space]
e = [":sh --no-popup --register + ...", ":open --register +"] This would do Can also add an As an example of usage, helix would launch a floating pane of yazi with the current buffers file as the starting point. From there, a [keys.normal.space]
e = [":sh --no-popup wezterm sli spawn --floating-pane yazi %{path}", ":open --env YAZI_LAST_OPENED_FILE"]
register [<flags>]: ...
flags:
--set, -s <register> ...
--copy, -c <register> ...
--clear ...
--all, -a ... |
Some typable commands might benefit from taking switches to control small parts of their behavior. A few examples of commands that could take advantage of switches:
:write
and friends could take a--no-format
switch which prevents auto-formatting (#4853, #4909 (comment)):sort
and:rsort
could be merged into one command with reverse-sorting accomplished by:sort --reverse
(#1288 (comment)):clear-registers
(#5695) could take an--all
switch to clear all registers (#5695 (comment))Kakoune has switches and it has a nice way of showing the available switches in the documentation popup:
A few items worth some discussion:
-a
would be a shorthand for--all
in the:clear-registers
example.The text was updated successfully, but these errors were encountered: