Thanks all!
Sorry -- I normally would include an example but I sent that email from my phone and have unreliable access to my computer (where I've been playing with this). I am on a Mac, for what it's worth (not yet using Vim on the iPhone :D ).---
Tis is
text this is
---
And this code:
---
let dir = "test"
function! Append()
let contents = readfile(g:dir . "test.txt", "b")
call add(contents, join(getline(1, '$'), "\n"))
call writefile(contents, g:dir . "does-this-work.txt", "b")
endfunction
---
---
let dir = "test"
function! Append()
let contents = readfile(g:dir . "test.txt", "b")
call add(contents, join(getline(1, '$'), "\n"))
call writefile(contents, g:dir . "does-this-work.txt", "b")
endfunction
---
when Append() is called on this buffer content:
---
This is one line of text.
This is another line.
---
---
This is one line of text.
This is another line.
---
gives me the file does-this-work.txt:
---
Tis is
text this is
This is one line of text.^@This is another line.
---
---
Tis is
text this is
This is one line of text.^@This is another line.
---
--
On Mon, Oct 6, 2014 at 7:37 PM, John Little <John.B.Little@gmail.com> wrote:
On Tuesday, October 7, 2014 9:59:53 AM UTC+13, Benjamin Klein wrote:
> As far as I can tell, readfile() and writefile() have something against new lines...
> Sent from my iPhone
;) I'd guess you're not running Vim on an iPhone (however fun that might be) but on Windows. Looking at the code, I don't think DOS endings are written. There is this comment when writing a file:
/* Always open the file in binary mode, library functions have a mind of
* their own about CR-LF conversion. */
I would expect the written file to be ok when read again by readfile(), or by vim if you have "unix" in your setting of the 'fileformats' option, or even by MS Word, but to hammer away on one line if you use the DOS command "type", and problematic in various Windows utilities, or (I'm guessing here) some Mac software.
Regards, John Little
--
--
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.
--
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:
Post a Comment