ronantakizawa/codereview-bench huggingface dataset:
Repository: neovim/neovim
File: src/nvim/grid.h (C/C++)

Code before:
/// grid, then this is only used for global screen elements that hasn't been
/// externalized.
///
/// Note: before the screen is initialized and when out of memory these can be
/// NULL.
EXTERN ScreenGrid default_grid INIT( = SCREEN_GRID_INIT);
EXTERN GridView default_gridview INIT( = { .target = &default_grid });

#define DEFAULT_GRID_HANDLE 1  // handle for the default_grid

/// While resizing the screen this flag is set.
EXTERN bool resizing_screen INIT( = 0);

EXTERN schar_T *linebuf_char INIT( = NULL);
EXTERN sattr_T *linebuf_attr INIT( = NULL);
EXTERN colnr_T *linebuf_vcol INIT( = NULL);
EXTERN char *linebuf_scratch INIT( = NULL);

/// flags for grid_put_linebuf()
enum {
  SLF_RIGHTLEFT   = 1,
  SLF_WRAP        = 2,
  SLF_INC_VCOL    = 4,
  SLF_TERM_ATTRS  = 8,  // On if this line is associated with a terminal buffer. If so then we need
                        // to ensure we don't go past index `TERM_ATTRS_MAX` in the highlight
                        // attributes.
};

/// Put a ASCII character in a screen cell.
///
/// If `x` is a compile time constant, schar_from_ascii(x) will also be.
/// But the specific value varies per platform.
#ifdef ORDER_BIG_ENDIAN
# define schar_from_ascii(x) ((schar_T)((x) << 24))
#else
# define schar_from_ascii(x) ((schar_T)(x))
#endif

#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "grid.h.generated.h"
#endif


Review comment (suggestion):
```suggestion
  SLF_TERMATTRS  = 8,  // Indicates the line is in a terminal buffer, so we must not exceed
                       // index `TERM_ATTRS_MAX` in the highlight attributes.
```

Code after:
/// grid, then this is only used for global screen elements that hasn't been
/// externalized.
///
/// Note: before the screen is initialized and when out of memory these can be
/// NULL.
EXTERN ScreenGrid default_grid INIT( = SCREEN_GRID_INIT);
EXTERN GridView default_gridview INIT( = { .target = &default_grid });

#define DEFAULT_GRID_HANDLE 1  // handle for the default_grid

/// While resizing the screen this flag is set.
EXTERN bool resizing_screen INIT( = 0);

EXTERN schar_T *linebuf_char INIT( = NULL);
EXTERN sattr_T *linebuf_attr INIT( = NULL);
EXTERN colnr_T *linebuf_vcol INIT( = NULL);
EXTERN char *linebuf_scratch INIT( = NULL);

/// flags for grid_put_linebuf()
enum {
  SLF_RIGHTLEFT = 1,
  SLF_WRAP      = 2,
  SLF_INC_VCOL  = 4,
};

/// Put a ASCII character in a screen cell.
///
/// If `x` is a compile time constant, schar_from_ascii(x) will also be.
/// But the specific value varies per platform.
#ifdef ORDER_BIG_ENDIAN
# define schar_from_ascii(x) ((schar_T)((x) << 24))
#else
# define schar_from_ascii(x) ((schar_T)(x))
#endif

#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "grid.h.generated.h"
#endif
Repository: neovim/neovim
File: test/functional/terminal/highlight_spec.lua (Lua)

Code before:
      {9:-- TERMINAL --}                                    |
    ]])
  end)
end)

describe(':terminal', function()
  before_each(clear)

  it('can display URLs', function()
    local screen = Screen.new(50, 7)
    screen:add_extra_attr_ids {
      [100] = { url = 'https://example.com' },
    }
    local chan = api.nvim_open_term(0, {})
    api.nvim_chan_send(
      chan,
      'This is an \027]8;;https://example.com\027\\example\027]8;;\027\\ of a link'
    )
    screen:expect([[
      ^This is an {100:example} of a link                      |
                                                        |*6
    ]])
  end)
end)

it(':terminal does not cause crash on zoomout with large horizontal output #30374', function()
  skip(is_os('win'))

  clear()
  -- Start terminal smaller.
  local screen = Screen.new(50, 50, { rgb = false })
  feed([[:terminal<cr>]])

  -- Generate very wide output.
  feed('ifor i in $(seq 1 10000); do echo -n $i; done\r\n')

  -- Make terminal big.
  screen:try_resize(5000, 5000)
  command('call jobresize(b:terminal_job_id, 5000, 5000)')

  assert_alive()
end)


Review comment (suggestion):
this should be in one of the existing describe() blocks : https://github.com/neovim/neovim/blob/4ee2e365a583e26468e7ea820f5416a980515504/test/functional/terminal/highlight_spec.lua#L392


Code after:
      {9:-- TERMINAL --}                                    |
    ]])
  end)
end)

describe(':terminal', function()
  before_each(clear)

  it('can display URLs', function()
    local screen = Screen.new(50, 7)
    screen:add_extra_attr_ids {
      [100] = { url = 'https://example.com' },
    }
    local chan = api.nvim_open_term(0, {})
    api.nvim_chan_send(
      chan,
      'This is an \027]8;;https://example.com\027\\example\027]8;;\027\\ of a link'
    )
    screen:expect([[
      ^This is an {100:example} of a link                      |
                                                        |*6
    ]])
  end)

  it('zoomout with large horizontal output #30374', function()
    skip(is_os('win'))

    -- Start terminal smaller.
    local screen = Screen.new(50, 50, { rgb = false })
    feed([[:terminal<cr>]])

    -- Generate very wide output.
    feed('ifor i in $(seq 1 10000); do echo -n $i; done\r\n')

    -- Make terminal big.
    screen:try_resize(5000, 5000)
    command('call jobresize(b:terminal_job_id, 5000, 5000)')

    assert_alive()
  end)
end)
Repository: neovim/neovim
File: test/functional/terminal/highlight_spec.lua (Lua)

Code before:
      {9:-- TERMINAL --}                                    |
    ]])
  end)
end)

describe(':terminal', function()
  before_each(clear)

  it('can display URLs', function()
    local screen = Screen.new(50, 7)
    screen:add_extra_attr_ids {
      [100] = { url = 'https://example.com' },
    }
    local chan = api.nvim_open_term(0, {})
    api.nvim_chan_send(
      chan,
      'This is an \027]8;;https://example.com\027\\example\027]8;;\027\\ of a link'
    )
    screen:expect([[
      ^This is an {100:example} of a link                      |
                                                        |*6
    ]])
  end)
end)

it(':terminal does not cause crash on zoomout with large horizontal output #30374', function()
  skip(is_os('win'))

  clear()
  -- Start terminal smaller.
  local screen = Screen.new(50, 50, { rgb = false })
  feed([[:terminal<cr>]])

  -- Generate very wide output.
  feed('ifor i in $(seq 1 10000); do echo -n $i; done\r\n')

  -- Make terminal big.
  screen:try_resize(5000, 5000)
  command('call jobresize(b:terminal_job_id, 5000, 5000)')

  assert_alive()
end)


Review comment (suggestion):
```suggestion
it('zoomout with large horizontal output #30374', function()
```

Code after:
      {9:-- TERMINAL --}                                    |
    ]])
  end)
end)

describe(':terminal', function()
  before_each(clear)

  it('can display URLs', function()
    local screen = Screen.new(50, 7)
    screen:add_extra_attr_ids {
      [100] = { url = 'https://example.com' },
    }
    local chan = api.nvim_open_term(0, {})
    api.nvim_chan_send(
      chan,
      'This is an \027]8;;https://example.com\027\\example\027]8;;\027\\ of a link'
    )
    screen:expect([[
      ^This is an {100:example} of a link                      |
                                                        |*6
    ]])
  end)

  it('zoomout with large horizontal output #30374', function()
    skip(is_os('win'))

    -- Start terminal smaller.
    local screen = Screen.new(50, 50, { rgb = false })
    feed([[:terminal<cr>]])

    -- Generate very wide output.
    feed('ifor i in $(seq 1 10000); do echo -n $i; done\r\n')

    -- Make terminal big.
    screen:try_resize(5000, 5000)
    command('call jobresize(b:terminal_job_id, 5000, 5000)')

    assert_alive()
  end)
end)
Repository: neovim/neovim
File: src/nvim/ex_docmd.c (C)

Code before:
/// Returns FAIL when quitting should be aborted.
int before_quit_all(exarg_T *eap)
{
  if (cmdwin_type != 0) {
    cmdwin_result = eap->forceit
                    ? K_XF1  // open_cmdwin() takes care of this
                    : K_XF2;
    return FAIL;
  }

  // Don't quit while editing the command line.
  if (text_locked()) {
    text_locked_msg();
    return FAIL;
  }

  if (before_quit_autocmds(curwin, true, eap->forceit)) {
    return FAIL;
  }

  return OK;
}

/// ":qall": try to quit all windows
/// ":restart": restart the Nvim server
static void ex_quit_all(exarg_T *eap)
{
  if (before_quit_all(eap) == FAIL) {
    return;
  }
  exiting = true;
  Error err = ERROR_INIT;
  if ((eap->forceit || !check_changed_any(false, false))
      && (eap->cmdidx != CMD_restart || remote_ui_restart(current_ui, &err))) {
    getout(0);
  }
  not_exiting();
  if (ERROR_SET(&err)) {
    emsg(err.msg);  // UI disappeared already?
    api_clear_error(&err);
  }
}

/// ":close": close current window, unless it is the last one
static void ex_close(exarg_T *eap)
{
  win_T *win = NULL;
  int winnr = 0;
  if (cmdwin_type != 0) {
    cmdwin_result = Ctrl_C;
  } else if (!text_locked() && !curbuf_locked()) {

Review comment (suggestion):
nit: helps discovery, not much churn?

```suggestion
static void ex_quitall_or_restart(exarg_T *eap)
```

Code after:
/// Returns FAIL when quitting should be aborted.
int before_quit_all(exarg_T *eap)
{
  if (cmdwin_type != 0) {
    cmdwin_result = eap->forceit
                    ? K_XF1  // open_cmdwin() takes care of this
                    : K_XF2;
    return FAIL;
  }

  // Don't quit while editing the command line.
  if (text_locked()) {
    text_locked_msg();
    return FAIL;
  }

  if (before_quit_autocmds(curwin, true, eap->forceit)) {
    return FAIL;
  }

  return OK;
}

/// ":qall": try to quit all windows
/// ":restart": restart the Nvim server
static void ex_quitall_or_restart(exarg_T *eap)
{
  if (before_quit_all(eap) == FAIL) {
    return;
  }
  exiting = true;
  Error err = ERROR_INIT;
  if ((eap->forceit || !check_changed_any(false, false))
      && (eap->cmdidx != CMD_restart || remote_ui_restart(current_ui, &err))) {
    getout(0);
  }
  not_exiting();
  if (ERROR_SET(&err)) {
    emsg(err.msg);  // UI disappeared already?
    api_clear_error(&err);
  }
}

/// ":close": close current window, unless it is the last one
static void ex_close(exarg_T *eap)
{
  win_T *win = NULL;
  int winnr = 0;
  if (cmdwin_type != 0) {
    cmdwin_result = Ctrl_C;
  } else if (!text_locked() && !curbuf_locked()) {
Repository: neovim/neovim
File: test/functional/shada/buffers_spec.lua (Lua)

Code before:
    eq(2, fn.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, fn.bufnr('$'))
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it('does not add nobuflisted buffers to oldfiles', function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('set nobuflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    eq({}, api.nvim_get_vvar('oldfiles'))
  end)
end)


Review comment (suggestion):
"positive confirmation" gives more powerful tests. e.g. in this test, also open a `testfilename_2` (with 'buflisted', whereas the other is 'nobuflisted') and then assert that *only* its name appears in oldfiles.

Code after:
    eq(2, fn.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, fn.bufnr('$'))
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it("does not add 'nobuflisted' buffers to v:oldfiles", function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('setlocal nobuflisted')
    nvim_command('edit ' .. testfilename_2)
    nvim_command('setlocal buflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    local oldfiles = api.nvim_get_vvar('oldfiles')
    eq(1, #oldfiles)
    t.matches(vim.pesc(testfilename_2), oldfiles[1])
  end)
end)
Repository: neovim/neovim
File: test/functional/shada/buffers_spec.lua (Lua)

Code before:
  end)

  it('does not dump unnamed buffers', function()
    reset('set shada+=% hidden')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
    nvim_command('enew')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
    eq(2, fn.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, fn.bufnr('$'))
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it('does not add nobuflisted buffers to oldfiles', function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('set nobuflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    eq({}, api.nvim_get_vvar('oldfiles'))
  end)
end)


Review comment (suggestion):
```suggestion
  it("does not add 'nobuflisted' buffers to v:oldfiles", function()
```

Code after:
  end)

  it('does not dump unnamed buffers', function()
    reset('set shada+=% hidden')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
    nvim_command('enew')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
    eq(2, fn.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, fn.bufnr('$'))
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it("does not add 'nobuflisted' buffers to v:oldfiles", function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('setlocal nobuflisted')
    nvim_command('edit ' .. testfilename_2)
    nvim_command('setlocal buflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    local oldfiles = api.nvim_get_vvar('oldfiles')
    eq(1, #oldfiles)
    t.matches(vim.pesc(testfilename_2), oldfiles[1])
  end)
end)
Repository: neovim/neovim
File: test/functional/shada/buffers_spec.lua (Lua)

Code before:
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it("does not add 'nobuflisted' buffers to 'v:oldfiles'", function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('setlocal nobuflisted')
    nvim_command('edit ' .. testfilename_2)
    nvim_command('setlocal buflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    local oldfiles = api.nvim_get_vvar('oldfiles')
    eq(1, #oldfiles)
    t.matches(testfilename_2:gsub('%-', '%%-') .. '$', oldfiles[1])
  end)
end)


Review comment (suggestion):
```suggestion
    t.matches(vim.pesc(testfilename_2), oldfiles[1])
```

Code after:
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it("does not add 'nobuflisted' buffers to v:oldfiles", function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('setlocal nobuflisted')
    nvim_command('edit ' .. testfilename_2)
    nvim_command('setlocal buflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    local oldfiles = api.nvim_get_vvar('oldfiles')
    eq(1, #oldfiles)
    t.matches(vim.pesc(testfilename_2), oldfiles[1])
  end)
end)
Repository: neovim/neovim
File: test/functional/shada/buffers_spec.lua (Lua)

Code before:
  end)

  it('does not dump unnamed buffers', function()
    reset('set shada+=% hidden')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
    nvim_command('enew')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
    eq(2, fn.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, fn.bufnr('$'))
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it("does not add 'nobuflisted' buffers to 'v:oldfiles'", function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('setlocal nobuflisted')
    nvim_command('edit ' .. testfilename_2)
    nvim_command('setlocal buflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    local oldfiles = api.nvim_get_vvar('oldfiles')
    eq(1, #oldfiles)
    t.matches(vim.pesc(testfilename_2), oldfiles[1])
  end)
end)


Review comment (suggestion):
```suggestion
  it("does not add 'nobuflisted' buffers to v:oldfiles", function()
```

Code after:
  end)

  it('does not dump unnamed buffers', function()
    reset('set shada+=% hidden')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
    nvim_command('enew')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
    eq(2, fn.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, fn.bufnr('$'))
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it("does not add 'nobuflisted' buffers to v:oldfiles", function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('setlocal nobuflisted')
    nvim_command('edit ' .. testfilename_2)
    nvim_command('setlocal buflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    local oldfiles = api.nvim_get_vvar('oldfiles')
    eq(1, #oldfiles)
    t.matches(vim.pesc(testfilename_2), oldfiles[1])
  end)
end)
Repository: neovim/neovim
File: src/nvim/ex_docmd.c (C)

Code before:
/// ":detach!" with bang (!) detaches all UIs _except_ the current UI.
static void ex_detach(exarg_T *eap)
{
  // come on pooky let's burn this mf down
  if (eap && eap->forceit) {
    emsg("bang (!) not supported yet");
  } else {
    // 1. (TODO) Send "detach" UI-event (notification only).
    // 2. Perform server-side `nvim_ui_detach`.
    // 3. Close server-side channel without self-exit.

    if (!current_ui) {
      emsg("UI not attached");
      return;
    }

    Channel *chan = find_channel(current_ui);
    if (!chan) {
      emsg(e_invchan);
      return;
    }
    chan->detach = true;  // Prevent self-exit on channel-close.

    // Server-side UI detach. Doesn't close the channel.
    Error err2 = ERROR_INIT;
    remote_ui_disconnect(chan->id, &err2, true);
    if (ERROR_SET(&err2)) {
      emsg(err2.msg);  // UI disappeared already?
      api_clear_error(&err2);
      return;
    }

    // Server-side channel close.
    const char *err = NULL;
    bool rv = channel_close(chan->id, kChannelPartAll, &err);
    if (!rv && err) {
      emsg(err);  // UI disappeared already?
      return;
    }
    // XXX: Can't do this, channel_decref() is async...
    // assert(!find_channel(chan->id));

    ILOG("detach current_ui=%" PRId64, chan->id);
  }
}

/// ":mode":
/// If no argument given, get the screen size and redraw.
static void ex_mode(exarg_T *eap)
{
  if (*eap->arg == NUL) {

Review comment (suggestion):
on line 5563 the "TODO" can be changed to:

    // 1. Send "error_exit" UI-event (notification only).

Code after:
/// ":detach!" with bang (!) detaches all UIs _except_ the current UI.
static void ex_detach(exarg_T *eap)
{
  // come on pooky let's burn this mf down
  if (eap && eap->forceit) {
    emsg("bang (!) not supported yet");
  } else {
    // 1. Send "error_exit" UI-event (notification only).
    // 2. Perform server-side UI detach.
    // 3. Close server-side channel without self-exit.

    if (!current_ui) {
      emsg("UI not attached");
      return;
    }

    Channel *chan = find_channel(current_ui);
    if (!chan) {
      emsg(e_invchan);
      return;
    }
    chan->detach = true;  // Prevent self-exit on channel-close.

    // Server-side UI detach. Doesn't close the channel.
    Error err2 = ERROR_INIT;
    remote_ui_disconnect(chan->id, &err2, true);
    if (ERROR_SET(&err2)) {
      emsg(err2.msg);  // UI disappeared already?
      api_clear_error(&err2);
      return;
    }

    // Server-side channel close.
    const char *err = NULL;
    bool rv = channel_close(chan->id, kChannelPartAll, &err);
    if (!rv && err) {
      emsg(err);  // UI disappeared already?
      return;
    }
    // XXX: Can't do this, channel_decref() is async...
    // assert(!find_channel(chan->id));

    ILOG("detach current_ui=%" PRId64, chan->id);
  }
}

/// ":mode":
/// If no argument given, get the screen size and redraw.
static void ex_mode(exarg_T *eap)
{
  if (*eap->arg == NUL) {