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'})
>   * ...

With an "and" relation between those, I suppose.  This seems a bit
complicated.

> 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.

That is what makes it more complicated.

Alternative: add a function that returns all mappings.  It's the
simplest way.  It might be a bit slower, because the result would be a
longer list, but does that matter?  The ":map" command does the same,
but outputs text instead of exact info.  The advantage is that this is a
simple function, which can then be combined with existing functions such
as filter().  It's the Unix philosophy to combine multiple simple
commands, instead of making one complex one.

-- 
My sister Cecilia opened a computer store in Hawaii.
She sells C shells by the seashore.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220421223056.7F4751C0216%40moolenaar.net.

Raspunde prin e-mail lui