To: vim_dev@googlegroups.com Subject: Patch 7.4a.041 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4a.041 Problem: When using ":new ++ff=unix" and "dos" is first in 'fileformats' then 'ff' is set to "dos" instead of "unix". (Ingo Karkat) Solution: Create set_file_options() and invoke it from do_ecmd(). Files: src/fileio.c, src/proto/fileio.pro, src/ex_cmds.c, src/testdir/test91.in, src/testdir/test91.ok *** ../vim-7.4a.040/src/fileio.c 2013-07-03 16:27:10.000000000 +0200 --- src/fileio.c 2013-07-24 14:32:11.000000000 +0200 *************** *** 474,496 **** } #endif ! /* set default 'fileformat' */ ! if (set_options) ! { ! if (eap != NULL && eap->force_ff != 0) ! set_fileformat(get_fileformat_force(curbuf, eap), OPT_LOCAL); ! else if (*p_ffs != NUL) ! set_fileformat(default_fileformat(), OPT_LOCAL); ! } ! ! /* set or reset 'binary' */ ! if (eap != NULL && eap->force_bin != 0) ! { ! int oldval = curbuf->b_p_bin; ! ! curbuf->b_p_bin = (eap->force_bin == FORCE_BIN); ! set_options_bin(oldval, curbuf->b_p_bin, OPT_LOCAL); ! } /* * When opening a new file we take the readonly flag from the file. --- 474,481 ---- } #endif ! /* Set default or forced 'fileformat' and 'binary'. */ ! set_file_options(set_options, eap); /* * When opening a new file we take the readonly flag from the file. *************** *** 647,661 **** check_marks_read(); #endif #ifdef FEAT_MBYTE ! if (eap != NULL && eap->force_enc != 0) ! { ! /* set forced 'fileencoding' */ ! fenc = enc_canonize(eap->cmd + eap->force_enc); ! if (fenc != NULL) ! set_string_option_direct((char_u *)"fenc", -1, ! fenc, OPT_FREE|OPT_LOCAL, 0); ! vim_free(fenc); ! } #endif #ifdef FEAT_AUTOCMD apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, --- 632,640 ---- check_marks_read(); #endif #ifdef FEAT_MBYTE ! /* Set forced 'fileencoding'. */ ! if (eap != NULL) ! set_forced_fenc(eap); #endif #ifdef FEAT_AUTOCMD apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, *************** *** 2738,2744 **** return OK; } ! #ifdef FEAT_MBYTE /* * Find next fileencoding to use from 'fileencodings'. * "pp" points to fenc_next. It's advanced to the next item. --- 2717,2768 ---- return OK; } ! /* ! * Set default or forced 'fileformat' and 'binary'. ! */ ! void ! set_file_options(set_options, eap) ! int set_options; ! exarg_T *eap; ! { ! /* set default 'fileformat' */ ! if (set_options) ! { ! if (eap != NULL && eap->force_ff != 0) ! set_fileformat(get_fileformat_force(curbuf, eap), OPT_LOCAL); ! else if (*p_ffs != NUL) ! set_fileformat(default_fileformat(), OPT_LOCAL); ! } ! ! /* set or reset 'binary' */ ! if (eap != NULL && eap->force_bin != 0) ! { ! int oldval = curbuf->b_p_bin; ! ! curbuf->b_p_bin = (eap->force_bin == FORCE_BIN); ! set_options_bin(oldval, curbuf->b_p_bin, OPT_LOCAL); ! } ! } ! ! #if defined(FEAT_MBYTE) || defined(PROTO) ! /* ! * Set forced 'fileencoding'. ! */ ! void ! set_forced_fenc(eap) ! exarg_T *eap; ! { ! if (eap->force_enc != 0) ! { ! char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); ! ! if (fenc != NULL) ! set_string_option_direct((char_u *)"fenc", -1, ! fenc, OPT_FREE|OPT_LOCAL, 0); ! vim_free(fenc); ! } ! } ! /* * Find next fileencoding to use from 'fileencodings'. * "pp" points to fenc_next. It's advanced to the next item. *** ../vim-7.4a.040/src/proto/fileio.pro 2013-07-06 14:15:02.000000000 +0200 --- src/proto/fileio.pro 2013-07-24 14:31:03.000000000 +0200 *************** *** 2,7 **** --- 2,9 ---- void filemess __ARGS((buf_T *buf, char_u *name, char_u *s, int attr)); int readfile __ARGS((char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap, int flags)); int prep_exarg __ARGS((exarg_T *eap, buf_T *buf)); + void set_file_options __ARGS((int set_options, exarg_T *eap)); + void set_forced_fenc __ARGS((exarg_T *eap)); int prepare_crypt_read __ARGS((FILE *fp)); char_u *prepare_crypt_write __ARGS((buf_T *buf, int *lenp)); int check_file_readonly __ARGS((char_u *fname, int perm)); *** ../vim-7.4a.040/src/ex_cmds.c 2013-06-15 16:16:33.000000000 +0200 --- src/ex_cmds.c 2013-07-24 14:31:51.000000000 +0200 *************** *** 3448,3456 **** curwin->w_buffer = buf; curbuf = buf; ++curbuf->b_nwindows; ! /* set 'fileformat' */ ! if (*p_ffs && !oldbuf) ! set_fileformat(default_fileformat(), OPT_LOCAL); } /* May get the window options from the last time this buffer --- 3448,3460 ---- curwin->w_buffer = buf; curbuf = buf; ++curbuf->b_nwindows; ! ! /* Set 'fileformat', 'binary' and 'fenc' when forced. */ ! if (!oldbuf && eap != NULL) ! { ! set_file_options(TRUE, eap); ! set_forced_fenc(eap); ! } } /* May get the window options from the last time this buffer *** ../vim-7.4a.040/src/testdir/test91.in 2013-04-15 14:59:31.000000000 +0200 --- src/testdir/test91.in 2013-07-24 14:53:47.000000000 +0200 *************** *** 3,8 **** --- 3,9 ---- STARTTEST :so small.vim + :so mbyte.vim :" :" Test for getbufvar() :" Use strings to test for memory leaks. *************** *** 22,27 **** --- 23,39 ---- :$put =string(getbufvar(1, '&autoindent')) :$put =string(getbufvar(1, '&autoindent', 1)) :" + :" Open new window with forced option values + :set fileformats=unix,dos + :new ++ff=dos ++bin ++enc=iso-8859-2 + :let otherff = getbufvar(bufnr('%'), '&fileformat') + :let otherbin = getbufvar(bufnr('%'), '&bin') + :let otherfenc = getbufvar(bufnr('%'), '&fenc') + :close + :$put =otherff + :$put =string(otherbin) + :$put =otherfenc + :unlet otherff otherbin otherfenc :" test for getwinvar() :let w:var_str = "Dance" :let def_str = "Chance" *** ../vim-7.4a.040/src/testdir/test91.ok 2013-04-15 15:02:45.000000000 +0200 --- src/testdir/test91.ok 2013-07-24 14:52:47.000000000 +0200 *************** *** 10,15 **** --- 10,18 ---- '5678' 0 0 + dos + 1 + iso-8859-2 'Dance' 'Dance' {'var_str': 'Dance'} *** ../vim-7.4a.040/src/version.c 2013-07-24 13:49:18.000000000 +0200 --- src/version.c 2013-07-24 14:24:30.000000000 +0200 *************** *** 729,730 **** --- 729,732 ---- { /* Add new patch number below this line */ + /**/ + 41, /**/ -- hundred-and-one symptoms of being an internet addict: 22. You've already visited all the links at Yahoo and you're halfway through Lycos. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///