diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/ex_cmds.lua | 2 | ||||
| -rw-r--r-- | src/nvim/ex_docmd.c | 58 | ||||
| -rw-r--r-- | src/nvim/testdir/Makefile | 1 | ||||
| -rw-r--r-- | src/nvim/testdir/test_hide.vim | 97 | ||||
| -rw-r--r-- | src/nvim/version.c | 2 | 
5 files changed, 127 insertions, 33 deletions
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index 5757964f0f..5a578cd088 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -1076,7 +1076,7 @@ return {    },    {      command='hide', -    flags=bit.bor(BANG, RANGE, NOTADR, COUNT, EXTRA, NOTRLCOM), +    flags=bit.bor(BANG, RANGE, NOTADR, COUNT, EXTRA, TRLBAR),      addr_type=ADDR_WINDOWS,      func='ex_hide',    }, diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index d1ce589db1..1a766821a9 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4674,17 +4674,17 @@ char_u *find_nextcmd(const char_u *p)    return (char_u *)p + 1;  } -/* - * Check if *p is a separator between Ex commands. - * Return NULL if it isn't, (p + 1) if it is. - */ +/// 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)  { -  p = skipwhite(p); -  if (*p == '|' || *p == '\n') -    return p + 1; -  else -    return NULL; +    char_u *s = skipwhite(p); + +    if (*s == '|' || *s == '\n') { +        return (s + 1); +    } else { +        return NULL; +    }  }  /* @@ -6254,31 +6254,27 @@ void ex_all(exarg_T *eap)  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); +    // ":hide" or ":hide | cmd": hide current window      if (!eap->skip) { -      if (eap->addr_count == 0) -        win_close(curwin, FALSE); /* don't free buffer */ -      else { -        int winnr = 0; -        win_T *win = NULL; - -        FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { -          winnr++; -          if (winnr == eap->line2) { -            win = wp; -            break; -          } +        if (eap->addr_count == 0) { +            win_close(curwin, false);  // don't free buffer +        } else { +            int winnr = 0; +            win_T *win = NULL; + +            FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { +                winnr++; +                if (winnr == eap->line2) { +                    win = wp; +                    break; +                } +            } +            if (win == NULL) { +                win = lastwin; +            } +            win_close(win, false);          } -        if (win == NULL) -          win = lastwin; -        win_close(win, FALSE); -      }      } -  }  }  /* diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index b45bd6ee14..944222dbb6 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -45,6 +45,7 @@ NEW_TESTS ?= \  	    test_gn.res \  	    test_hardcopy.res \  	    test_help_tagjump.res \ +	    test_hide.res \  	    test_history.res \  	    test_hlsearch.res \  	    test_increment.res \ diff --git a/src/nvim/testdir/test_hide.vim b/src/nvim/testdir/test_hide.vim new file mode 100644 index 0000000000..128b8ff945 --- /dev/null +++ b/src/nvim/testdir/test_hide.vim @@ -0,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 diff --git a/src/nvim/version.c b/src/nvim/version.c index 81152bbaa4..9305618eae 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -866,7 +866,7 @@ static const int included_patches[] = {    // 89 NA    88,    // 87 NA -  // 86, +  86,    85,    84,    83,  | 
