Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/maktaba/command.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ function! maktaba#command#GetOutput(command) abort
" Example: #GetOutput('echo')
return l:output
else
" Neovim's UI2 handles captured output differently.
if has('nvim') && luaeval('pcall(require, "vim._core.ui2") and (require("vim._core.ui2").cfg ~= nil) and true or false')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty fragile as a check.

But isn't this just a (compatibility) bug in Neovim that should be fixed in ui2?

While the existing behavior of redir (adding an initial newline to the output) is strange, it seems like Neovim currently does implement the same behavior as Vim, and ui2 should presumably do the same?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick reply!

UI2 allows you to enter and navigate command output as a buffer; the change in behavior is probably because of that.
I kept getting errors from the assertion below, because UI2 seems to prune these on purpose (neovim/neovim#37697)

It's hardly ideal as a check but there isn't really any other way to check that UI2 is enabled right now AFAICT.

Happy to let it sit for now revisit this once UI2 is rolled out as a production feature. If the behavior is backwards compatible again I can drop the PR, otherwise there is hopefully a more robust way to check which behavior to expect.

return l:output
endif

" Vim will dump an extra newline at the beginning of the redir output.
" Yeah, I think it's dumb too.
call maktaba#ensure#IsTrue(
Expand Down