Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:lua io.write() default input/output #10652

Open
zgpio opened this issue Jul 29, 2019 · 9 comments
Open

:lua io.write() default input/output #10652

zgpio opened this issue Jul 29, 2019 · 9 comments
Labels
io lua stdlib
Milestone

Comments

@zgpio
Copy link

zgpio commented Jul 29, 2019

  • nvim --version: NVIM v0.4.0-1447-gfe2ada737
  • vim -u DEFAULTS (version: ) behaves differently? yes
  • Operating system/version: macos 10.14
  • Terminal name/version: mac terminal

Steps to reproduce using nvim -u NORC

  1. nvim -u NONE
  2. :lua io.write('aaaa')
    Show as follow:
    image

Actual behaviour

cmd line mess up

Expected behaviour

@zgpio zgpio added the bug issues reporting wrong behavior label Jul 29, 2019
@justinmk justinmk removed the bug issues reporting wrong behavior label Jul 29, 2019
@justinmk
Copy link
Member

It writes to stdout. What do you expect?

Use :lua print() if you want :echo-like behavior.

@justinmk justinmk added the lua stdlib label Jul 29, 2019
@zgpio
Copy link
Author

zgpio commented Jul 29, 2019

Sorry, I got it.

@bfredl
Copy link
Member

bfredl commented Jul 29, 2019

maybe we should disable the default input and output file of the io. module. These are not hardwired to be stdin/stdout, this is just the initial state of the module (and expected to be changed). Plugins can still use io.stdout if they have a good reason.

@justinmk justinmk reopened this Jul 29, 2019
@justinmk justinmk added this to the todo milestone Jul 29, 2019
@justinmk justinmk changed the title cmdline mess up when :lua io.write() :lua io.write() default input/output Jul 29, 2019
@justinmk justinmk added the io label Jul 29, 2019
@luiz00martins
Copy link

I came across the same problem while trying to use io.write to print some text without a newline (which is what is recommended in the official lua site).

@justinmk Is there a way to use print without outputting a linefeed?

@lewis6991
Copy link
Member

Luajit also recommends using io.write over print():

print() is not compiled, use io.write().

Would it not be possible to make io.print() output to the same place print() does?

@gpanders
Copy link
Member

gpanders commented Aug 16, 2021

print() is compiled in Nvim https://github.com/neovim/neovim/blob/master/src/nvim/lua/executor.c#L412-L413

Is there a way to use print without outputting a linefeed?

I'm curious: considering print writes to the Nvim message area, what would omitting a linefeed even look like?

Would it not be possible to make io.print() output to the same place print() does?

This is possible and would actually be easy, but it would change the semantics of io.write (since writing to the message area always adds a newline). But I'm beginning to get out of my depth here, I'll wait for bfredl to come in and set me straight.

@luiz00martins
Copy link

I'm curious: considering print writes to the Nvim message area, what would omitting a linefeed even look like?

I don't actually intend to use it to echo things. My objective was to use it in an expr mapping, since using execute('lua <...>') doesn't seem to work with returned values from lua, only printed ones. However, values printed with print always come with an extra linefeed at the end, messing up the mapping.

@gpanders
Copy link
Member

I don't actually intend to use it to echo things. My objective was to use it in an expr mapping, since using execute('lua <...>') doesn't seem to work with returned values from lua, only printed ones. However, values printed with print always come with an extra linefeed at the end, messing up the mapping.

Let's move this discussion to the Matrix room, but you might be able to use luaeval() here.

@luiz00martins
Copy link

No need to continue the discussion, as luaeval() did the trick! Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io lua stdlib
Projects
None yet
Development

No branches or pull requests

6 participants