From 04d299c17014b0802c79613252e4de26da84a7c9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 20:42:55 +0800 Subject: vim-patch:8.2.4932: not easy to filter the output of maplist() Problem: Not easy to filter the output of maplist(). Solution: Add mode_bits to the dictionary. (Ernie Rael, closes vim/vim#10356) https://github.com/vim/vim/commit/d8f5f766219273a8579947cc80b92580b6988a4b Co-authored-by: Ernie Rael --- src/nvim/eval.lua | 25 +++++++++++++++++++++++++ src/nvim/mapping.c | 1 + 2 files changed, 26 insertions(+) (limited to 'src') diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index d65b584faa..a2ba0f0189 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -6195,6 +6195,11 @@ M.funcs = { "nowait" Do not wait for other, longer mappings. (|:map-|). "abbr" True if this is an |abbreviation|. + "mode_bits" Nvim's internal binary representation of "mode". + |mapset()| ignores this; only "mode" is used. + See |maplist()| for usage examples. The values + are from src/nvim/vim.h and may change in the + future. The dictionary can be used to restore a mapping with |mapset()|. @@ -6269,6 +6274,26 @@ M.funcs = { echo maplist()->filter({_, m -> \ match(get(m, 'rhs', ''), 'MultiMatch') >= 0 \ }) + vim + let saved_maps = [] + for m in maplist() + if and(m.mode_bits, 0x19) != 0 + eval saved_maps->add(m) + endif + endfor + echo saved_maps->mapnew({_, m -> m.lhs}) + vim + omap xyzzy + let op_bit = maplist()->filter( + \ {_, m -> m.lhs == 'xyzzy'})[0].mode_bits + ounmap xyzzy + echo printf("Operator-pending mode bit: 0x%x", op_bit) ]], name = 'maplist', params = {}, diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index c90c0c5529..2ee1e2e02d 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2125,6 +2125,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs } PUT(dict, "mode", CSTR_AS_OBJ(mapmode)); PUT(dict, "abbr", INTEGER_OBJ(abbr ? 1 : 0)); + PUT(dict, "mode_bits", INTEGER_OBJ(mp->m_mode)); return dict; } -- cgit