Skip to content
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

try to fix #916: add maps to show all mappings #1146

Merged
merged 1 commit into from
Mar 12, 2023

Conversation

jackielii
Copy link
Contributor

I know there is a previous effort at #918 . I took the stdio suggestion. I think this opens up doors for other internal state to be echo'ed easily, e.g. copy/cut buffers, selections etc

@jackielii jackielii changed the title try to fix #916 try to fix #916: add maps to show all mappings Mar 10, 2023
@jackielii
Copy link
Contributor Author

I suggest we rename this to list-mappings so we can also have list-selections, list-buffers for copy/cut buffers?

@jackielii
Copy link
Contributor Author

I have implemented the list-* commands: jackielii@aa183fe

If interested, I'll submit that as a PR

Copy link
Collaborator

@ilyagr ilyagr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I quite like the idea of maps as the name of the command. Update: Something like list-mappings, list-buffers also sounds good to me. I was thinking about the possibility of cmaps, but if we ever want that, it could be list-cmd-mappings instead.

I am not sure what chance, if any, this has of going into lf. That's up to @gokcehan.

I did leave a couple of comments from a technical point of view. I wouldn't spend too much time on my comments unless we get a go-ahead with this PR and this approach.

// This function is used to run a shell command. Modes are as follows:
//
// Prefix Wait Async Stdin Stdout Stderr UI action
// $ No No Yes Yes Yes Pause and then resume
// % No No Yes Yes Yes Statline for input/output
// ! Yes No Yes Yes Yes Pause and then resume
// & No Yes No No No Do nothing
func (app *app) runShell(s string, args []string, prefix string) {
// $| No No Pipe Yes Yes Pause, Pipe execute, return cleanup to resume
func (app *app) runShell(s string, args []string, prefix string) cleanFunc {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning a cleanup function, I would either make $| a separate function or (this is probably easier):

  • rename this function to runShellInternal and add an sendToStdin string argument to it.
  • create a new runShell function that calls runShellInternal and passes "" for sendToStdin
  • create a runShellWithStding function with arguments s, args, and sendToStdin that calls runShellInternal(s, args, "$|", sendToStdin).

Perhaps we can think of something more elegant than exactly what I suggested. However, we should avoid returning functions that the caller must to remember to call in some cases, but are completely ignored in other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's certainly a good idea! I did thought of the possibility that cleanup is not called. Although I figured the docs should help.

Separating the runShell in different modes should certainly help with cleanness of the code. Although existing runShell feels a bit cramped up as well, there is a good separation of start, run/start, cleanup state in it, but the switch cases had to be duplicated a couple of times. I think $, % etc should be separated as well.

Anyway, that's just some of my thoughts. I'll definitely try to get this in another function as the $| is a internal one. I have the list-mappings etc in a branch ready to go. I'll modify all this in the other PR. sending it soon.

@@ -2076,6 +2076,11 @@ func (e *callExpr) eval(app *app, args []string) {

app.ui.cmdAccLeft = acc
update(app)
case "maps":
cleanUp := app.runShell("$PAGER", nil, "$|")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should try doing something like what I did in #918 to try to support Windows.

It'd be even better if somebody could test it on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! I'm on Mac. Didn't really test on Windows.

Although did a quick search seems pipe should work for windows. We're only invoking pager...

@jackielii jackielii mentioned this pull request Mar 12, 2023
@gokcehan
Copy link
Owner

@jackielii Thanks for working on this. I think I'm ok with this patch. @ilyagr From what I understand, I think you are also ok with this patch as well.

@jackielii One small suggestion/nitpick, can we not simply use | as the prefix instead of $|? Is there a reason for the latter? I'll merge the patch as it is but feel free to change it in a separate PR if that makes sense.

@gokcehan gokcehan merged commit a85ce89 into gokcehan:master Mar 12, 2023
@gokcehan
Copy link
Owner

By the way, this does not seem to work on windows unfortunately.

@jackielii
Copy link
Contributor Author

@gokcehan thanks for merging this. I actually created another patch #1152 including @ilyagr 's code review suggestions and the other list commands.

@ilyagr
Copy link
Collaborator

ilyagr commented Mar 12, 2023

This wasn't quite ready to be merged, unfortunately. I'll look at the fix-up PR when I get a moment.

@gokcehan
Copy link
Owner

@ilyagr Sorry for rushing the merge. I just did not want to leave this feature out as you have been really helpful as a contributor lately and proven yourself to be responsible. Feel free to make any changes with @jackielii in the followup patch or patches and let me know when it is ready.

ilyagr added a commit to ilyagr/lf that referenced this pull request Apr 7, 2023
This makes the `:maps` command from gokcehan#1146 work on Windows.

This (as well as `:maps` itself) is based on @jackielli's work in gokcehan#1146 and
gokcehan#1152.

I intend to refactor the code in this or a separate PR, but I thought I'd
submit the critical and simple bit first.
ilyagr added a commit to ilyagr/lf that referenced this pull request Apr 7, 2023
After the naming scheme from gokcehan#1146, it would seem weird to not have a :cmaps
command. This could help with issues like gokcehan#876.
gokcehan pushed a commit that referenced this pull request Apr 8, 2023
* Make `:maps` work on Windows

This makes the `:maps` command from #1146 work on Windows.

This (as well as `:maps` itself) is based on @jackielli's work in #1146 and
#1152.

I intend to refactor the code in this or a separate PR, but I thought I'd
submit the critical and simple bit first.

* Add `:cmaps` command

After the naming scheme from #1146, it would seem weird to not have a :cmaps
command. This could help with issues like #876.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants