|
|
22c937 |
To: vim_dev@googlegroups.com
|
|
|
22c937 |
Subject: Patch 7.4.503
|
|
|
22c937 |
Fcc: outbox
|
|
|
22c937 |
From: Bram Moolenaar <Bram@moolenaar.net>
|
|
|
22c937 |
Mime-Version: 1.0
|
|
|
22c937 |
Content-Type: text/plain; charset=UTF-8
|
|
|
22c937 |
Content-Transfer-Encoding: 8bit
|
|
|
22c937 |
------------
|
|
|
22c937 |
|
|
|
22c937 |
Patch 7.4.503
|
|
|
22c937 |
Problem: Cannot append a list of lines to a file.
|
|
|
22c937 |
Solution: Add the append option to writefile(). (Yasuhiro Matsumoto)
|
|
|
22c937 |
Files: runtime/doc/eval.txt, src/Makefile, src/eval.c,
|
|
|
22c937 |
src/testdir/test_writefile.in, src/testdir/test_writefile.ok
|
|
|
22c937 |
|
|
|
22c937 |
|
|
|
22c937 |
*** ../vim-7.4.502/runtime/doc/eval.txt 2014-09-09 16:13:05.040531695 +0200
|
|
|
22c937 |
--- runtime/doc/eval.txt 2014-11-05 17:57:01.592454006 +0100
|
|
|
22c937 |
***************
|
|
|
22c937 |
*** 2040,2046 ****
|
|
|
22c937 |
winrestview( {dict}) none restore view of current window
|
|
|
22c937 |
winsaveview() Dict save view of current window
|
|
|
22c937 |
winwidth( {nr}) Number width of window {nr}
|
|
|
22c937 |
! writefile( {list}, {fname} [, {binary}])
|
|
|
22c937 |
Number write list of lines to file {fname}
|
|
|
22c937 |
xor( {expr}, {expr}) Number bitwise XOR
|
|
|
22c937 |
|
|
|
22c937 |
--- 2041,2047 ----
|
|
|
22c937 |
winrestview( {dict}) none restore view of current window
|
|
|
22c937 |
winsaveview() Dict save view of current window
|
|
|
22c937 |
winwidth( {nr}) Number width of window {nr}
|
|
|
22c937 |
! writefile( {list}, {fname} [, {flags}])
|
|
|
22c937 |
Number write list of lines to file {fname}
|
|
|
22c937 |
xor( {expr}, {expr}) Number bitwise XOR
|
|
|
22c937 |
|
|
|
22c937 |
***************
|
|
|
22c937 |
*** 6532,6545 ****
|
|
|
22c937 |
:endif
|
|
|
22c937 |
<
|
|
|
22c937 |
*writefile()*
|
|
|
22c937 |
! writefile({list}, {fname} [, {binary}])
|
|
|
22c937 |
Write |List| {list} to file {fname}. Each list item is
|
|
|
22c937 |
separated with a NL. Each list item must be a String or
|
|
|
22c937 |
Number.
|
|
|
22c937 |
! When {binary} is equal to "b" binary mode is used: There will
|
|
|
22c937 |
not be a NL after the last list item. An empty item at the
|
|
|
22c937 |
end does cause the last line in the file to end in a NL.
|
|
|
22c937 |
! All NL characters are replaced with a NUL character.
|
|
|
22c937 |
Inserting CR characters needs to be done before passing {list}
|
|
|
22c937 |
to writefile().
|
|
|
22c937 |
An existing file is overwritten, if possible.
|
|
|
22c937 |
--- 6555,6574 ----
|
|
|
22c937 |
:endif
|
|
|
22c937 |
<
|
|
|
22c937 |
*writefile()*
|
|
|
22c937 |
! writefile({list}, {fname} [, {flags}])
|
|
|
22c937 |
Write |List| {list} to file {fname}. Each list item is
|
|
|
22c937 |
separated with a NL. Each list item must be a String or
|
|
|
22c937 |
Number.
|
|
|
22c937 |
! When {flags} contains "b" then binary mode is used: There will
|
|
|
22c937 |
not be a NL after the last list item. An empty item at the
|
|
|
22c937 |
end does cause the last line in the file to end in a NL.
|
|
|
22c937 |
!
|
|
|
22c937 |
! When {flags} contains "a" then append mode is used, lines are
|
|
|
22c937 |
! append to the file: >
|
|
|
22c937 |
! :call writefile(["foo"], "event.log", "a")
|
|
|
22c937 |
! :call writefile(["bar"], "event.log", "a")
|
|
|
22c937 |
! >
|
|
|
22c937 |
! < All NL characters are replaced with a NUL character.
|
|
|
22c937 |
Inserting CR characters needs to be done before passing {list}
|
|
|
22c937 |
to writefile().
|
|
|
22c937 |
An existing file is overwritten, if possible.
|
|
|
22c937 |
*** ../vim-7.4.502/src/Makefile 2014-11-05 14:26:30.760758363 +0100
|
|
|
22c937 |
--- src/Makefile 2014-11-05 17:54:36.864457494 +0100
|
|
|
22c937 |
***************
|
|
|
22c937 |
*** 1899,1906 ****
|
|
|
22c937 |
--- 1899,1910 ----
|
|
|
22c937 |
test_insertcount \
|
|
|
22c937 |
test_listlbr \
|
|
|
22c937 |
test_listlbr_utf8 \
|
|
|
22c937 |
+ test_mapping \
|
|
|
22c937 |
test_options \
|
|
|
22c937 |
test_qf_title \
|
|
|
22c937 |
+ test_signs \
|
|
|
22c937 |
+ test_utf8 \
|
|
|
22c937 |
+ test_writefile \
|
|
|
22c937 |
test10 test11 test12 test13 test14 test15 test16 test17 test18 test19 \
|
|
|
22c937 |
test20 test21 test22 test23 test24 test25 test26 test27 test28 test29 \
|
|
|
22c937 |
test30 test31 test32 test33 test34 test35 test36 test37 test38 test39 \
|
|
|
22c937 |
*** ../vim-7.4.502/src/eval.c 2014-11-05 16:03:40.588617886 +0100
|
|
|
22c937 |
--- src/eval.c 2014-11-05 17:59:15.388450782 +0100
|
|
|
22c937 |
***************
|
|
|
22c937 |
*** 19689,19694 ****
|
|
|
22c937 |
--- 19689,19695 ----
|
|
|
22c937 |
typval_T *rettv;
|
|
|
22c937 |
{
|
|
|
22c937 |
int binary = FALSE;
|
|
|
22c937 |
+ int append = FALSE;
|
|
|
22c937 |
char_u *fname;
|
|
|
22c937 |
FILE *fd;
|
|
|
22c937 |
int ret = 0;
|
|
|
22c937 |
***************
|
|
|
22c937 |
*** 19704,19717 ****
|
|
|
22c937 |
if (argvars[0].vval.v_list == NULL)
|
|
|
22c937 |
return;
|
|
|
22c937 |
|
|
|
22c937 |
! if (argvars[2].v_type != VAR_UNKNOWN
|
|
|
22c937 |
! && STRCMP(get_tv_string(&argvars[2]), "b") == 0)
|
|
|
22c937 |
! binary = TRUE;
|
|
|
22c937 |
|
|
|
22c937 |
/* Always open the file in binary mode, library functions have a mind of
|
|
|
22c937 |
* their own about CR-LF conversion. */
|
|
|
22c937 |
fname = get_tv_string(&argvars[1]);
|
|
|
22c937 |
! if (*fname == NUL || (fd = mch_fopen((char *)fname, WRITEBIN)) == NULL)
|
|
|
22c937 |
{
|
|
|
22c937 |
EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname);
|
|
|
22c937 |
ret = -1;
|
|
|
22c937 |
--- 19705,19723 ----
|
|
|
22c937 |
if (argvars[0].vval.v_list == NULL)
|
|
|
22c937 |
return;
|
|
|
22c937 |
|
|
|
22c937 |
! if (argvars[2].v_type != VAR_UNKNOWN)
|
|
|
22c937 |
! {
|
|
|
22c937 |
! if (vim_strchr(get_tv_string(&argvars[2]), 'b') != NULL)
|
|
|
22c937 |
! binary = TRUE;
|
|
|
22c937 |
! if (vim_strchr(get_tv_string(&argvars[2]), 'a') != NULL)
|
|
|
22c937 |
! append = TRUE;
|
|
|
22c937 |
! }
|
|
|
22c937 |
|
|
|
22c937 |
/* Always open the file in binary mode, library functions have a mind of
|
|
|
22c937 |
* their own about CR-LF conversion. */
|
|
|
22c937 |
fname = get_tv_string(&argvars[1]);
|
|
|
22c937 |
! if (*fname == NUL || (fd = mch_fopen((char *)fname,
|
|
|
22c937 |
! append ? APPENDBIN : WRITEBIN)) == NULL)
|
|
|
22c937 |
{
|
|
|
22c937 |
EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname);
|
|
|
22c937 |
ret = -1;
|
|
|
22c937 |
*** ../vim-7.4.502/src/testdir/test_writefile.in 2014-11-05 18:04:54.912442601 +0100
|
|
|
22c937 |
--- src/testdir/test_writefile.in 2014-11-05 18:01:07.408448083 +0100
|
|
|
22c937 |
***************
|
|
|
22c937 |
*** 0 ****
|
|
|
22c937 |
--- 1,18 ----
|
|
|
22c937 |
+ Tests for writefile()
|
|
|
22c937 |
+
|
|
|
22c937 |
+ STARTTEST
|
|
|
22c937 |
+ :source small.vim
|
|
|
22c937 |
+ :%delete _
|
|
|
22c937 |
+ :let f = tempname()
|
|
|
22c937 |
+ :call writefile(["over","written"], f, "b")
|
|
|
22c937 |
+ :call writefile(["hello","world"], f, "b")
|
|
|
22c937 |
+ :call writefile(["!", "good"], f, "a")
|
|
|
22c937 |
+ :call writefile(["morning"], f, "ab")
|
|
|
22c937 |
+ :call writefile(["", "vimmers"], f, "ab")
|
|
|
22c937 |
+ :bwipeout!
|
|
|
22c937 |
+ :$put =readfile(f)
|
|
|
22c937 |
+ :1 delete _
|
|
|
22c937 |
+ :w! test.out
|
|
|
22c937 |
+ :qa!
|
|
|
22c937 |
+ ENDTEST
|
|
|
22c937 |
+
|
|
|
22c937 |
*** ../vim-7.4.502/src/testdir/test_writefile.ok 2014-11-05 18:04:54.916442601 +0100
|
|
|
22c937 |
--- src/testdir/test_writefile.ok 2014-11-05 17:53:19.776459351 +0100
|
|
|
22c937 |
***************
|
|
|
22c937 |
*** 0 ****
|
|
|
22c937 |
--- 1,5 ----
|
|
|
22c937 |
+ hello
|
|
|
22c937 |
+ world!
|
|
|
22c937 |
+ good
|
|
|
22c937 |
+ morning
|
|
|
22c937 |
+ vimmers
|
|
|
22c937 |
*** ../vim-7.4.502/src/version.c 2014-11-05 17:44:47.676471691 +0100
|
|
|
22c937 |
--- src/version.c 2014-11-05 17:55:08.508456731 +0100
|
|
|
22c937 |
***************
|
|
|
22c937 |
*** 743,744 ****
|
|
|
22c937 |
--- 743,746 ----
|
|
|
22c937 |
{ /* Add new patch number below this line */
|
|
|
22c937 |
+ /**/
|
|
|
22c937 |
+ 503,
|
|
|
22c937 |
/**/
|
|
|
22c937 |
|
|
|
22c937 |
--
|
|
|
22c937 |
BLACK KNIGHT: Come on you pansy!
|
|
|
22c937 |
[hah] [parry thrust]
|
|
|
22c937 |
[ARTHUR chops the BLACK KNIGHT's right arm off]
|
|
|
22c937 |
ARTHUR: Victory is mine! [kneeling]
|
|
|
22c937 |
We thank thee Lord, that in thy merc-
|
|
|
22c937 |
[Black Knight kicks Arthur in the head while he is praying]
|
|
|
22c937 |
The Quest for the Holy Grail (Monty Python)
|
|
|
22c937 |
|
|
|
22c937 |
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
|
|
|
22c937 |
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
|
|
|
22c937 |
\\\ an exciting new programming language -- http://www.Zimbu.org ///
|
|
|
22c937 |
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|