Add getmaps() builtin#10273
Add getmaps() builtin#10273errael wants to merge 1 commit intovim:masterfrom errael:AddGetmapsBuiltin
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10273 +/- ##
==========================================
- Coverage 81.00% 80.97% -0.03%
==========================================
Files 161 161
Lines 185553 185590 +37
Branches 41946 41956 +10
==========================================
- Hits 150301 150289 -12
- Misses 22742 22786 +44
- Partials 12510 12515 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| :echo getloclist(5, {'filewinid': 0}) | ||
|
|
||
|
|
||
| getmaps() *getmaps()* |
There was a problem hiding this comment.
All the map related functions start with the map prefix. To be consistent, this function should
be called mapget().
There was a problem hiding this comment.
Except hasmapto(). It would be nice to start with "map", but what to call it then? mapgetall() ? maplist()?
mapget() suggests getting one mapping.
I used getmappings() for now.
There was a problem hiding this comment.
Given the presence of getloclist I'd say getmaplist is the name that fits best the existing functions.
| getmaps() *getmaps()* | ||
| Returns a |List| of all mappings. Each List item is a |Dict| | ||
| as defined by |maparg()|. For a given mapping, the Dict from | ||
| getmaps() is identical to the dict from |maparg()|. |
There was a problem hiding this comment.
A user can use the Dict returned by getmaps() and call mapset() to recreate the mapping?
There was a problem hiding this comment.
I would think the {mode} argument to mapset() could be a special value and then the "mode" from the dict is uesd.
The new function should also have an "abbr" optional argument to get a list of abbreviations instead of mappings.
There was a problem hiding this comment.
The test does assert_equal(getmaps_entry, maparg_return) for all mappings; how could it not work? (Famous last words)
have an "abbr" optional argument
And here we go... :-)
So getmappings([{abbr}]), if abbr true, then return the abbreviations.
It could be getmappings({dict}), where the key abbr can be true/false. Just in case there's more options on the way. With that in mind, I'm in favor of just an optional bool for abbreviations.
There was a problem hiding this comment.
I would think the {mode} argument to mapset() could be a special value and then the "mode" from the dict is uesd.
I would suggest mapset({dict}) means take abbr and mode from dict, that's easy for a user to understand.
It's unclear to me, whether or not mapcheck() would want a similar change.
Either way, is there a reason not to include "abbr: true/false" in the mapping-dict? I think it could be done right now, without any negative consequences. I'm guessing mapset() wouldn't care today.
I'm a casual vim user, so I'm mostly clueless about a lot of vim stuff. Considering the above, and playing with the new maplist() function, I did the following experiment because I was trying to figure out where nox came from for the Q mapping. I'm sure whatever drives having [on]unmap also implicitly do sunmap gives a better user experience.
map X xyzzy [' ']
nunmap X ['ov']
map X xyzzy [' ']
xunmap X ['nos']
map X xyzzy [' ']
sunmap X ['nox']
map X xyzzy [' ']
ounmap X ['nv']
map X xyzzy [' ']
sunmap X ['nox']
smap X xyzzy ['s', 'nox']
There was a problem hiding this comment.
If overloading functions is philosophically undesirable, mapset(null, null, dict) is a possibility.
|
"maps" isn't commonly used, let's call this "getmappings". |
|
Hi Bram,
On Sun, Apr 24, 2022 at 10:44 AM Bram Moolenaar ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In runtime/doc/builtin.txt
<#10273 (comment)>:
> @@ -3570,6 +3571,17 @@ getloclist({nr} [, {what}]) *getloclist()*
:echo getloclist(5, {'filewinid': 0})
+getmaps() *getmaps()*
Except hasmapto(). It would be nice to start with "map", but what to call
it then? mapgetall() ? maplist()?
mapget() suggests getting one mapping.
I used getmappings() for now.
I think we should call this function maplist() or map_getlist(). There is
some precedence for
this with existing functions: digraph_getlist(), prop_type_list(),
popup_list(), term_list()
and tabpagebuflist().
On the other hand, we also have the following function
names: getchangelist(), getjumplist(),
getloclist(), getmarklist() and getqflist().
Regards,
Yegappan
|
|
I'll sit on this for a day, planning on
|
…pping Problem: Not simple programmatic way to find a specific mapping. Solution: Add getmappings(). (Ernie Rael, closes vim/vim#10273) vim/vim@659c240 Co-authored-by: Ernie Rael <errael@raelity.com>
…pping Problem: Not simple programmatic way to find a specific mapping. Solution: Add getmappings(). (Ernie Rael, closes vim/vim#10273) vim/vim@659c240 Co-authored-by: Ernie Rael <errael@raelity.com>
…pping Problem: Not simple programmatic way to find a specific mapping. Solution: Add getmappings(). (Ernie Rael, closes vim/vim#10273) vim/vim@659c240 Co-authored-by: Ernie Rael <errael@raelity.com>
No description provided.