To: vim_dev@googlegroups.com Subject: Patch 8.0.0086 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0086 Problem: Cannot add a comment after ":hide". (Norio Takagi) Solution: Make it work, add a test. (Hirohito Higashi) Files: src/Makefile, src/ex_cmds.h, src/ex_docmd.c, src/testdir/Make_all.mak, src/testdir/test_hide.vim *** ../vim-8.0.0085/src/Makefile 2016-11-12 21:12:48.534182259 +0100 --- src/Makefile 2016-11-15 20:38:20.349739241 +0100 *************** *** 2097,2102 **** --- 2097,2103 ---- test_gui \ test_hardcopy \ test_help_tagjump \ + test_hide \ test_history \ test_hlsearch \ test_increment \ *** ../vim-8.0.0085/src/ex_cmds.h 2016-11-12 19:16:42.212999914 +0100 --- src/ex_cmds.h 2016-11-15 20:38:20.349739241 +0100 *************** *** 623,629 **** BANG|EXTRA|TRLBAR|SBOXOK|CMDWIN, ADDR_LINES), EX(CMD_hide, "hide", ex_hide, ! BANG|RANGE|NOTADR|COUNT|EXTRA|NOTRLCOM, ADDR_WINDOWS), EX(CMD_history, "history", ex_history, EXTRA|TRLBAR|CMDWIN, --- 623,629 ---- BANG|EXTRA|TRLBAR|SBOXOK|CMDWIN, ADDR_LINES), EX(CMD_hide, "hide", ex_hide, ! BANG|RANGE|NOTADR|COUNT|EXTRA|TRLBAR, ADDR_WINDOWS), EX(CMD_history, "history", ex_history, EXTRA|TRLBAR|CMDWIN, *** ../vim-8.0.0085/src/ex_docmd.c 2016-11-12 19:16:42.216999886 +0100 --- src/ex_docmd.c 2016-11-15 20:38:20.353739214 +0100 *************** *** 5632,5646 **** #endif /* ! * Check if *p is a separator between Ex commands. ! * Return NULL if it isn't, (p + 1) if it is. */ char_u * check_nextcmd(char_u *p) { ! p = skipwhite(p); ! if (*p == '|' || *p == '\n') ! return (p + 1); else return NULL; } --- 5632,5647 ---- #endif /* ! * Check if *p is a separator between Ex commands, skipping over white space. ! * Return NULL if it isn't, the following character if it is. */ char_u * check_nextcmd(char_u *p) { ! char_u *s = skipwhite(p); ! ! if (*s == '|' || *s == '\n') ! return (s + 1); else return NULL; } *************** *** 7572,7609 **** static void ex_hide(exarg_T *eap) { ! if (*eap->arg != NUL && check_nextcmd(eap->arg) == NULL) ! eap->errmsg = e_invarg; ! else ! { ! /* ":hide" or ":hide | cmd": hide current window */ ! eap->nextcmd = check_nextcmd(eap->arg); #ifdef FEAT_WINDOWS ! if (!eap->skip) ! { # ifdef FEAT_GUI ! need_mouse_correct = TRUE; # endif ! if (eap->addr_count == 0) ! win_close(curwin, FALSE); /* don't free buffer */ ! else ! { ! int winnr = 0; ! win_T *win; ! FOR_ALL_WINDOWS(win) ! { ! winnr++; ! if (winnr == eap->line2) ! break; ! } ! if (win == NULL) ! win = lastwin; ! win_close(win, FALSE); } } - #endif } } /* --- 7573,7604 ---- static void ex_hide(exarg_T *eap) { ! /* ":hide" or ":hide | cmd": hide current window */ #ifdef FEAT_WINDOWS ! if (!eap->skip) ! { # ifdef FEAT_GUI ! need_mouse_correct = TRUE; # endif ! if (eap->addr_count == 0) ! win_close(curwin, FALSE); /* don't free buffer */ ! else ! { ! int winnr = 0; ! win_T *win; ! FOR_ALL_WINDOWS(win) ! { ! winnr++; ! if (winnr == eap->line2) ! break; } + if (win == NULL) + win = lastwin; + win_close(win, FALSE); } } + #endif } /* *** ../vim-8.0.0085/src/testdir/Make_all.mak 2016-10-15 17:06:42.094912699 +0200 --- src/testdir/Make_all.mak 2016-11-15 20:38:20.357739188 +0100 *************** *** 156,161 **** --- 156,162 ---- test_gn.res \ test_gui.res \ test_hardcopy.res \ + test_hide.res \ test_history.res \ test_hlsearch.res \ test_increment.res \ *** ../vim-8.0.0085/src/testdir/test_hide.vim 2016-11-15 21:16:01.358754552 +0100 --- src/testdir/test_hide.vim 2016-11-15 20:38:20.357739188 +0100 *************** *** 0 **** --- 1,97 ---- + " Tests for :hide command/modifier and 'hidden' option + + function SetUp() + let s:save_hidden = &hidden + let s:save_bufhidden = &bufhidden + let s:save_autowrite = &autowrite + set nohidden + set bufhidden= + set noautowrite + endfunc + + function TearDown() + let &hidden = s:save_hidden + let &bufhidden = s:save_bufhidden + let &autowrite = s:save_autowrite + endfunc + + function Test_hide() + let orig_bname = bufname('') + let orig_winnr = winnr('$') + + new Xf1 + set modified + call assert_fails('edit Xf2') + bwipeout! Xf1 + + new Xf1 + set modified + edit! Xf2 + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 0], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + bwipeout! Xf2 + + new Xf1 + set modified + " :hide as a command + hide + call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + + new Xf1 + set modified + " :hide as a command with trailing comment + hide " comment + call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + + new Xf1 + set modified + " :hide as a command with bar + hide | new Xf2 " comment + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + bwipeout! Xf2 + + new Xf1 + set modified + " :hide as a modifier with trailing comment + hide edit Xf2 " comment + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + bwipeout! Xf2 + + new Xf1 + set modified + " To check that the bar is not recognized to separate commands + hide echo "one|two" + call assert_equal(['Xf1', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + + " set hidden + new Xf1 + set hidden + set modified + edit Xf2 " comment + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + bwipeout! Xf2 + + " set hidden bufhidden=wipe + new Xf1 + set bufhidden=wipe + set modified + hide edit! Xf2 " comment + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([0, 0], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf2 + endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.0.0085/src/version.c 2016-11-14 21:49:57.080090226 +0100 --- src/version.c 2016-11-15 20:39:04.805438063 +0100 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 86, /**/ -- How To Keep A Healthy Level Of Insanity: 10. Ask people what sex they are. Laugh hysterically after they answer. /// 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 ///