On 4/21/22 1:24 PM, Bram Moolenaar wrote:
> Ernie Rael wrote:
>
>> Looking to print/popup a list of plugin shortcuts (extracted from map
>> commands); the plugin has around a dozen commands. It is currently
>> difficult, if not impossible, to reliably get the mappings that exist
>> for a command.
>>
>> Suggest builtin like
>>
>> mapfind(match_to: dict<any> = null): list<dict<any>>
>>
>> Where each element of the returned list is a dict as described for the
>> return in maparg. Without "match_to" return a list of all mappings; if
>> match_to is present, only mappings that match are returned. For example,
>> match_to might be, "{rhs: 'DirDiff'}".
>>
>> Hoping to squeeze this into vim9; to that end I'm thinking of
>> implementing no-args mapfind first. This is much simpler and avoids the
>> discussion, for now, of what map_to can contain and its semantics.
>>
>> Looking for a "seems ok", before I embark on implementation.
> I suppose that if you want to know "what was that mapping I put in for
> that command" and don't even know where you defined it, it can be hard
> to find.
There can be default mappings as well. Does anyone set up multiple
mappings to same command?
>
> You can use :filter:
> :filter NextCommand map
>
> But you have to redirect the output and process it, which can be tricky
> for special keys.
I did some experimenting last month using the filter approach: var ms =
split(execute('filter MS map'), '\n')
Since one of the mappings I played with is <M-<Space>> it goes beyond
tricky. While experimenting, I had multiple things that mapped to MS and
they all had a blank lhs.
> I can't think of another function to use for this, thus adding mapfind()
> seems useful. Would we also make it possible to find using the LHS?
> At least the function name should somehow indicate matching the RHS, or
> be able to do both.
The argument is a dict that specifies what should be matched. It could
develop into
* mapfind() - return all mappings
* mapfind({rhs: 'pattern'}) - mappings with command that matches pattern
* mapfind({mode: 'mode'}) - mappings for the specified mode
* mapfind({lhs: 'pattern_lhs', rhs: 'pattern_rhs', mode: 'mode'})
* ...
Not sure of the rules for pattern for lhs/rhs, like :filter?. Are the
match items applied as "and" or "or", probably "and" is more
useful/expected. Anyway, some issues. Implement mapfind() with no arg
first, file an issue for discussion on how to extend it.
-ernie
>