Wednesday, August 16, 2017

Re: Silently edit a buffer

16.08.2017, 23:46, "Bram Moolenaar" <bram@moolenaar.net>:
> Dmitry Zotikov wrote:
>
>>  Dear all,
>>
>>  what would be the best way to silently edit a buffer? In particular, I want to
>>  be able to write the content of a variable to it, as well as to delete all of
>>  its content.
>>
>>  The story goes, I'm writing a plugin that among other things reads from a
>>  network socket using Vim 8 channels and jobs; this is the corresponding call:
>>
>>  call job_start(command_cmd, {'out_io': 'buffer', 'out_name': '_out'})
>>
>>  The problem is that on the other side of the socket there's a server process
>>  reading from the channel set to NL mode would always leave one line of
>>  input in the socket, and so I'm forced to either fall back to RAW
>>  mode, or to check whether there's something left in the socket and
>>  read it later with a separate ch_read call:
>
> I created a file "temp" that is missing the final EOL.
> If I then do:
>          call job_start("cat temp", {'out_io': 'buffer', 'out_name': '_out'})
> Then I see the last line of "temp" in _out.
> Thus it appears to work.
> Perhaps the server process doesn't flush the output?

Yes, most likely. Seems like there's nothing I could do about it (the process is
SAS interpreter).

>
>>  - Writing in RAW mode directly to the buffer leaves ^@ in place of proper
>>  linefeeds, meaning a callback function would have to be called, that would
>>  substitute ^@ with ^M and only then write to the buffer; this is where the
>>  initial question stems from.
>>  - ch_read() call would also have to be performed by a callback function that
>>  will, again, need a way to somehow write to the buffer.
>>
>>  The closest solution I've got is to do something like
>>
>>  :bufnr('_out') bufdo put =msg
>>
>>  but that switches the current window to "_out" buffer.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: