On 2011/3/26 15:48, H Xu wrote:
Hello,
To reproduce:
:!echo -n 'Hello' >temp.txt
:echo readfile('temp.txt')
Then an empty list is displayed rather than the content of this file.
The attached patch fixes this problem.
Regards,
Hong Xu
2011/3/26
Hello,
The last patch has some problem. Use this patch instead.
The solution is, when readfile() in text mode, if we reach the end of
the file and we still didn't find a NL, then add an NL to the end of the
buffer.
Regards,
Hong Xu
2011/3/26
--
You received this message from the "vim_dev" 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
diff -r 719ff65f993e src/eval.c
--- a/src/eval.c Tue Mar 22 20:54:25 2011 +0100
+++ b/src/eval.c Sat Mar 26 18:23:50 2011 +0800
@@ -14249,6 +14249,7 @@
int len;
long maxline = MAXLNUM;
long cnt = 0;
+ int havenl = 0; /* does the file contain an nl */
if (argvars[1].v_type != VAR_UNKNOWN)
{
@@ -14273,13 +14274,23 @@
filtd = 0;
while (cnt < maxline || maxline < 0)
{
- readlen = (int)fread(buf + filtd, 1, FREAD_SIZE - filtd, fd);
+ readlen = (int)fread(buf + filtd, 1, FREAD_SIZE - filtd - 1, fd);
buflen = filtd + readlen;
tolist = 0;
+
+ if (readlen <= 0 && !havenl && !binary)
+ {
+ buf[0] = '\n';
+ ++buflen;
+ ++readlen;
+ }
+
for ( ; filtd < buflen || readlen <= 0; ++filtd)
{
if (buf[filtd] == '\n' || readlen <= 0)
{
+ havenl = 1;
+
/* Only when in binary mode add an empty list item when the
* last line ends in a '\n'. */
if (!binary && readlen == 0 && filtd == 0)