Repository: neovim
Issue: maparg() is incompatible with Vim, and nvim's own docs
Labels: needs:decision,vimscript,compatibility,complexity:high

### Problem

This came to my attention following a bug report [on one of my (Vimscript) plugins](https://github.com/LunarWatcher/auto-pairs/issues/78).

The docs for maparg, which are currently identical to Vim's docs, state:
```
		When {dict} is omitted or zero: Return the rhs of mapping
		{name} in mode {mode}.  The returned String has special
		characters translated like in the output of the ":map" command
		listing. When {dict} is TRUE a dictionary is returned, see
		below. To get a list of all mappings see |maplist()|.

		When there is no mapping for {name}, an empty String is
		returned if {dict} is FALSE, otherwise returns an empty Dict.
		When the mapping for {name} is empty, then "<Nop>" is
		returned.
...
		When {dict} is there and it is |TRUE| return a dictionary
		containing **all the information of the mapping with the
		following items:**			*mapping-dict*
		  "lhs"	     The {lhs} of the mapping as it would be typed
		  "lhsraw"   The {lhs} of the mapping as raw bytes
		  "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
			      form, only present when it differs from "lhsraw"
		  "rhs"	     The {rhs} of the mapping as typed.
		  "silent"   1 for a |:map-silent| mapping, else 0.
		  "noremap"  1 if the {rhs} of the mapping is not remappable.
		  "script"   1 if mapping was defined with <script>.
		  "expr"     1 for an expression mapping (|:map-<expr>|).
		  "buffer"   1 for a buffer local mapping (|:map-local|).
		  "mode"     Modes for which the mapping is defined. In
			     addition to the modes mentioned above, these
			     characters will be used:
			     " "     Normal, Visual and Operator-pending
			     "!"     Insert and Commandline mode
				     (|mapmode-ic|)
		  "sid"	     The script local ID, used for <sid> mappings
			     (|<SID>|).
		  "scriptversion"  The version of the script.  999999 for
				   |Vim9| script.
		  "lnum"     The line number in "sid", zero if unknown.
		  "nowait"   Do not wait for other, longer mappings.
			     (|:map-<nowait>|).
		  "abbr"     True if this is an abbreviation |abbreviations|.
		  "mode_bits" Vim's internal binary representation of "mode".
			     |mapset()| ignores this; only "mode" is used.
			     See |maplist()| for usage examples. The values
			     are from src/vim.h and may change in the future.

```
Instead, via the reproduction method, a result like this is returned:
```
{'lnum': 0, 'script': 0, 'mode': 'i', 'silent': 0, 'callback': function('<lambda>1'), 'noremap': 1, 'lhs': '<CR>', 'lhsr', 'nowait': 0, 'expr': 0, 'sid': -8, 'buffer': 0}
```

Note both the existence of the undefined `callback` key, as well as the lack of `rhs`, the latter of which is guaranteed to be present by the function call. This is completely breaking for vim-nvim plugin compatibility, as it prevents many plugins currently relying on `rhs` to map keys compatibly with other plugins. This especially matters in insert mode, due to the many plugins wanting to map to a few keys (particularly map, space, enter, and backspace)

There are two options, as far as I see it:
1. Update the docs to reflect the existence of callback, and update `maparg` to return an `rhs` defined in a way that's compatible with a conversion to a Vim-based mapping. This is the single best option for maintaining compatibility between Vimscript-based plugins and Lua-based plugins
2. Update the docs to reflect the current situation; that callback exists, and rhs isn't guaranteed. This will break plugins

### Steps to reproduce

init.lua:
```
vim.keymap.set('i', '<CR>', function()
    print("y u do dis?")
end)
```
Runtime:
``` 
:echo maparg('<cr>', i, 0, 1)
```

Note that a normal `imap` in vimscript still populates `rhs`; this problem is exclusively caused by Lua mappings, and specifically function mappings (though there may be other triggers I'm unaware of).

### Expected behavior

`rhs` should be defined, in line with the docs.

### Neovim version (nvim -v)

0.9.0

### Vim (not Nvim) behaves the same?

This problem is specific to a situation caused by nvim's Lua API. AFAIK, Vim doesn't have any equivalent Lua-level functionality, and therefore cannot cause this bug

### Operating system/version

Linux Mint 21.1

### Terminal name/version

GNOME terminal 3.44.0

### $TERM environment variable

xterm-256color

### Installation

Appimage