Skip to content

org_return passes non-string to nvim_feedkeys() #799

Closed
@broken-pen

Description

@broken-pen

Describe the bug

Under some conditions, pressing <CR> in insert mode results in the following message:

[orgmode] Invalid 'keys': Expected Lua string

The editor then hangs until ctrl-c is pressed, which will interrupt a call to vim.cmd[[redraw!]].

As far as I can tell, this is caused by these lines in the org_return action handler:

local old_mapping = vim.b.org_old_cr_mapping
-- No other mapping for <CR>, just reproduce it.
if not old_mapping or vim.tbl_isempty(old_mapping) then
return vim.api.nvim_feedkeys(utils.esc('<CR>'), 'n', true)
end
local rhs = old_mapping.rhs
local eval = old_mapping.expr > 0
if old_mapping.callback then
rhs = old_mapping.callback()
eval = false
end
if eval then
rhs = vim.api.nvim_eval(rhs)
end
return vim.api.nvim_feedkeys(rhs, 'n', true)

In cases where this bug occurs, b:org_old_cr_mapping has a field callback but no field rhs. The fallback then correctly calls callback(). However, it seems the return value is unconditionally passed to nvim_feedkeys(), even if eval is false and the return value is, say, nil.

This should be easily fixable and I wouldn't mind submitting a PR. I'd just like someone who knows the code to look over it and make sure my train of thought is correct.

Steps to reproduce

Not quite clear what is necessary. I think this is caused by orgmode setting up its imap <CR> ... after nvim-cmp has set up its imap <CR>. Lazy-loading makes this trigger reliably, but it should be possible to hit this with eager loading, too.

Expected behavior

No error message, org_return forwards <CR> to nvim-cmp, which then falls back to a regular line break.

Emacs functionality

No response

Minimal init.lua

N/A

Screenshots and recordings

No response

OS / Distro

Fedora 40

Neovim version/commit

0.10.1

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions