[vim/vim] "maparg()" with the {dict} argument does not include a "script" key (#5873)

14 views
Skip to first unread message

lacygoill

unread,
Apr 1, 2020, 11:19:12 AM4/1/20
to vim/vim, Subscribed

Describe the bug

maparg() with the {dict} arugment does not include a script key.

To Reproduce

Run this shell command:

vim -Nu NONE +'nno <script> <c-a> <c-b>'

Then this Ex command:

:echo maparg('<c-a>', 'n', 0, 1)->keys()

The list does not contain the script key.

Expected behavior

The list does contain the script key.

Environment

  • Vim version: 8.2 Included patches: 1-480
  • OS: Ubuntu 16.04.6 LTS
  • Terminal: XTerm(322)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

lacygoill

unread,
Apr 1, 2020, 11:28:17 AM4/1/20
to vim/vim, Subscribed

I've also noticed that the pseudo-key <SID> is not translated in the rhs key when the {dict} argument is true. However, it is translated when {dict} is omitted or false.
I know that this is to be expected, because it seems to be documented:

The returned String has special characters translated like in the output of the ":map" command listing.
...
"rhs" The {rhs} of the mapping as typed.

However, I would argue that the translation is more useful when you want to save/restore a mapping; would it be possible to either:

  • translate <SID> in the rhs key
  • add another key (rhs_translated?) where <SID> is translated

I know it's currently doable via a substitute() call and using the value stored in the sid key, but it would make the process easier (and maybe more reliable).

Yegappan Lakshmanan

unread,
Apr 1, 2020, 12:17:09 PM4/1/20
to vim_dev, reply+ACY5DGDLIFZMQYLQCY...@reply.github.com, vim/vim, Subscribed
Hi,

In the recently added menu_info() function (which is similar to the
maparg() function), I have addressed the script local menu
mappings. A similar logic can be used for maparg().

- Yegappan

vim-dev ML

unread,
Apr 1, 2020, 12:17:24 PM4/1/20
to vim/vim, vim-dev ML, Your activity

Hi,

In the recently added menu_info() function (which is similar to the
maparg() function), I have addressed the script local menu
mappings. A similar logic can be used for maparg().

- Yegappan

On Wed, Apr 1, 2020 at 8:19 AM lacygoill <vim-dev...@256bit.org> wrote:

> *Describe the bug*

>
> maparg() with the {dict} arugment does not include a script key.
>
> *To Reproduce*

>
> Run this shell command:
>
> vim -Nu NONE +'nno <script> <c-a> <c-b>'
>
> Then this Ex command:
>
> :echo maparg('<c-a>', 'n', 0, 1)->keys()
>
> The list does not contain the script key.
>
> *Expected behavior*

>
> The list does contain the script key.
>
> *Environment*
>
> - Vim version: 8.2 Included patches: 1-480
> - OS: Ubuntu 16.04.6 LTS
> - Terminal: XTerm(322)

lacygoill

unread,
Apr 1, 2020, 12:25:51 PM4/1/20
to vim/vim, vim-dev ML, Comment

Thank you for the comment. Also, forget about <SID>, I think one can just invoke maparg() twice:

:echo extend(maparg('cd', 'n', 0, 1), {'rhs': escape(maparg('cd', 'n'), '|')})


You are receiving this because you commented.

Bram Moolenaar

unread,
Apr 1, 2020, 1:22:45 PM4/1/20
to vim/vim, vim-dev ML, Comment

Closed #5873 via 2da0f0c.


You are receiving this because you commented.

lacygoill

unread,
May 31, 2020, 8:07:33 AM5/31/20
to vim/vim, vim-dev ML, Comment

In the todo list, there is this item:

maparg() does not show the <script> flag. When temporarily changing a
mapping, how to restore the script ID?

As of 8.2.0855, you can determine whether a mapping was defined with the <script> argument via the script key:

:nno <c-a> <c-a>
:echo maparg('<c-a>', 'n', 0, 1).script
0

:nno <script> <c-b> <c-b>
:echo maparg('<c-b>', 'n', 0, 1).script
1

Similarly, you can get the script ID via the sid key:

vim -Nu NONE -S <(cat <<'EOF'
    nno <c-b> :call <sid>func()<cr>
    fu s:func()
    endfu
EOF
)
:echo maparg('<c-b>', 'n', 0, 1).sid
1

And you can get the rhs of the mapping in a form where the pseudo-key <sid> is translated, provided you don't pass the optional {dict} argument to maparg():

vim -Nu NONE -S <(cat <<'EOF'
    nno <c-b> :call <sid>func()<cr>
    fu s:func()
    endfu
EOF
)
:echo maparg('<c-b>', 'n')
:call <SNR>1_func()<CR>
      ^^^^^^^

And we now have mapset() to restore a mapping.

So I think the item is no longer relevant.


You are receiving this because you commented.

Bram Moolenaar

unread,
May 31, 2020, 11:03:21 AM5/31/20
to vim/vim, vim-dev ML, Comment

Thanks for checking. I'll remove the entry from the todo list.
There are a few more remarks about maparg(), is any of those obsolete, or needs adjustment now?


You are receiving this because you commented.

lacygoill

unread,
May 31, 2020, 11:46:54 AM5/31/20
to vim/vim, vim-dev ML, Comment

I haven't found anything obvious, but I've noticed this item:

-   <C--> cannot be mapped.  Should be possible to recognize this as a
    normal "-" with the Ctrl modifier.

As of 8.2.0862, it seems to work in the GUI, and in xterm when modifyOtherKeys is enabled.

There's also this sentence:

Even better: add a way to disable a mapping temporarily and re-enable it later.

Not sure whether it should be removed or updated, now that we have mapset().


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages