lambdalisue / vim-fern

🌿 General purpose asynchronous tree viewer written in Pure Vim script
MIT License
1.29k stars 49 forks source link

Get list of all available actions #121

Closed Shatur closed 4 years ago

Shatur commented 4 years ago

I have a question. Is there a way to get list of all fern actions in Vimscript? I would like to wrap in into FZF in my vimrc. Thanks!

lambdalisue commented 4 years ago

Unfortunately no. But actions are just mapping (https://github.com/lambdalisue/fern.vim/blob/master/doc/fern.txt#L108-L112) so you can list it.

Shatur commented 4 years ago

Yes, I know that I can hardcode it, but I thought maybe there is more portable way :( Thanks!

Shatur commented 4 years ago

What if split s:map_help function into two? The first is public that returns a list of actions with shortcuts, and the second is private (s:) that displays them in echo.

lambdalisue commented 4 years ago

Hum... It's technically possible but it's inconsistent with a current specification.

I assumed that any APIs in internal# namespace are private. That means, at least for now, APIs for actions are assumed as private. Thus, even your suggestion had applied, I'd suggest you copy the part of the code instead of relying on the private (technically public but private in the specification) function. Or maybe APIs for actions should be moved out from internal# namespace to make it public in the specification (but it's a kind tough work.)

Note that I said "the specification" but it means like "my current coding rule" thus it might be ignored one day (or maybe already.)

Shatur commented 4 years ago

Thanks for the explanations! Consistency is important. But I see that s:map_help not relies at any other functions except s:compare. So, what if move list generation part from fern#internal# to just fern# and reuse this function in s:map_help? Just a suggestion. Of course I can just copy this code to get list of actions.

lambdalisue commented 4 years ago

Sorry. I've read and forgot about this issue.

Hum... It's a bit difficult. As you said, s:map_help does not rely on other functions but it has a context; the function is for building a help text of actions; thus I don't think it's a good idea to expose s:map_help as-is.

So I'm OK if

  1. The entire action feature become PUBLIC and documented so that 3rd-parties can access it via fern#action#BRABRA
  2. The core features of s:map_help are extracted as utility functions without its context as fern#util#BRABRABRA

One of above is required to change/keep the concept for action in fern but I feel it's kinda overkilling for things you need

Shatur commented 4 years ago

The entire action feature become PUBLIC and documented so that 3rd-parties can access it via fern#action#BRABRA

Yes, this is exactly what I suggested. A function that returns a dictionary with Fern actions and can be used by 3rd-parties and inside s:map_help.

But you are right, this is a bit overkill. I will just copy code and edit for my needs to use inside FZF. Thank you!

lambdalisue commented 4 years ago

Sorry for the inconvenience. I'll put the first one as a "maybe oneday" task.

Shatur commented 4 years ago

It would be nice to have, thanks :)

lambdalisue commented 4 years ago

@Shatur95 Now you can get action list by fern#action#list() https://github.com/lambdalisue/fern.vim/pull/176/commits/ae807617709c83a8d2c92d607adc2274c955335a

Shatur commented 4 years ago

Wow, thank you!

Shatur commented 4 years ago

Can I execute an action by text in Vimscript? Trying to create action selection via FZF.

lambdalisue commented 4 years ago

Use fern#action#call() on the fern buffer.

Shatur commented 4 years ago

Thanks! I wrote the following, maybe someone will be interested. I mapped it to A for Fern buffer.

lambdalisue commented 4 years ago

It would be nice if it's a plugin I guess

Shatur commented 4 years ago

This is just a few lines of very opinionated code :) If it is a plugin, it should be more extensible.