ronantakizawa/codereview-bench huggingface dataset:
Repository: neovim/neovim
File: test/functional/autocmd/markset_spec.lua (Lua)

Code before:
local n = require('test.functional.testnvim')()

local api = n.api
local clear = n.clear
local command = n.command
local feed = n.feed
local poke_eventloop = n.poke_eventloop
local eval = n.eval

local eq = t.eq
local neq = t.neq

describe('MarkSet', function()
  -- TODO(justinmk): support other marks?: [, ] <, > . ^ " '

  before_each(function()
    clear()
  end)

  it('emits when lowercase/uppercase/[/] marks are set', function()
    command([[
      let g:mark_names = ''
      let g:mark_events = []
      autocmd MarkSet * call add(g:mark_events, {'event': deepcopy(v:event)}) | let g:mark_names ..= expand('<amatch>')
      " TODO: there is a bug lurking here.
      " autocmd MarkSet * let g:mark_names ..= expand('<amatch>')
    ]])

    api.nvim_buf_set_lines(0, 0, -1, true, {
      'foo\0bar',
      'baz text',
    })

    feed('ma')
    feed('j')
    feed('mb')

    poke_eventloop()
    eq('ab', eval('g:mark_names'))

    -- event-data is copied to `v:event`.
    eq({
      {
        event = {
          col = 0,
          line = 1,
          name = 'a',
        },
      },
      {
        event = {

Review comment (bug):
I think there's a bug lurking somewhere. If I uncomment this extra `MarkSet` handler, and remove the `let g:mark_names` from the above handler, then the `eq('ab', eval('g:mark_names'))` test fails.

This makes me wonder if there is a problem when more than one handler is defined.

Code after:
local n = require('test.functional.testnvim')()

local api = n.api
local clear = n.clear
local command = n.command
local feed = n.feed
local poke_eventloop = n.poke_eventloop
local eval = n.eval

local eq = t.eq
local neq = t.neq

describe('MarkSet', function()
  -- TODO(justinmk): support other marks?: [, ] <, > . ^ " '

  before_each(function()
    clear()
  end)

  it('emits when lowercase/uppercase/[/] marks are set', function()
    command([[
      let g:mark_names = ''
      let g:mark_events = []
      autocmd MarkSet * call add(g:mark_events, {'event': deepcopy(v:event)}) | let g:mark_names ..= expand('<amatch>')
      " TODO: there is a bug lurking here.
      " autocmd MarkSet * let g:mark_names ..= expand('<amatch>')
    ]])

    api.nvim_buf_set_lines(0, 0, -1, true, {
      'foo\0bar',
      'baz text',
      'line 3',
    })

    feed('ma')
    feed('j')
    command('mark b')

    poke_eventloop()
    eq('ab', eval('g:mark_names'))

    -- event-data is copied to `v:event`.
    eq({
      {
        event = {
          col = 0,
          line = 1,
          name = 'a',
        },
      },
      {
Repository: neovim/neovim
File: test/functional/autocmd/markset_spec.lua (Lua)

Code before:
          col = 0,
          line = 1,
          name = 'a',
        },
      },
      {
        event = {
          col = 0,
          line = 2,
          name = 'b',
        },
      },
    }, eval('g:mark_events'))

    feed('mA')
    feed('l')
    feed('mB')
    feed('j')
    feed('mC')

    feed('x') -- TODO(justinmk): Sets [,] marks but does not emit MarkSet event (yet).
    feed('0vll<esc>') -- TODO(justinmk): Sets <,> marks but does not emit MarkSet event (yet).
    -- XXX: set these marks manually to exercise these cases.
    api.nvim_buf_set_mark(0, '[', 2, 0, {})
    api.nvim_buf_set_mark(0, ']', 2, 0, {})
    api.nvim_buf_set_mark(0, '<', 2, 0, {})
    api.nvim_buf_set_mark(0, '>', 2, 0, {})
    api.nvim_buf_set_mark(0, '"', 2, 0, {})

    poke_eventloop()
    eq('abABC[]<>"', eval('g:mark_names'))
  end)

  it('can subscribe to specific marks by pattern', function()
    command([[
      let g:mark_names = ''
      autocmd MarkSet [ab] let g:mark_names ..= expand('<amatch>')
    ]])

    api.nvim_buf_set_lines(0, 0, -1, true, {
      'foo\0bar',
      'baz text',
    })

    feed('md')
    feed('mc')
    feed('l')
    feed('mb')
    feed('j')
    feed('ma')


Review comment (suggestion):
I combined all the "basic" tests in this first `it()`. It is important to avoid verbose tests, because then it isn't obvious what behavior is important, there's a whole phone book to read. 

Code after:
        event = {
          col = 0,
          line = 1,
          name = 'a',
        },
      },
      {
        event = {
          col = 0,
          line = 2,
          name = 'b',
        },
      },
    }, eval('g:mark_events'))

    feed('mA')
    feed('l')
    feed('mB')
    feed('j')
    feed('mC')

    feed('x') -- TODO(justinmk): Sets [,] marks but does not emit MarkSet event (yet).
    feed('0vll<esc>') -- TODO(justinmk): Sets <,> marks but does not emit MarkSet event (yet).
    -- XXX: set these marks manually to exercise these cases.
    api.nvim_buf_set_mark(0, '[', 2, 0, {})
    api.nvim_buf_set_mark(0, ']', 2, 0, {})
    api.nvim_buf_set_mark(0, '<', 2, 0, {})
    api.nvim_buf_set_mark(0, '>', 2, 0, {})
    api.nvim_buf_set_mark(0, '"', 2, 0, {})

    poke_eventloop()
    eq('abABC[]<>"', eval('g:mark_names'))
  end)

  it('can subscribe to specific marks by pattern', function()
    command([[
      let g:mark_names = ''
      autocmd MarkSet [ab] let g:mark_names ..= expand('<amatch>')
    ]])

    api.nvim_buf_set_lines(0, 0, -1, true, {
      'foo\0bar',
      'baz text',
    })

    feed('md')
    feed('mc')
    feed('l')
    feed('mb')
    feed('j')
    feed('ma')
Repository: neovim/neovim
File: test/functional/autocmd/markset_spec.lua (Lua)

Code before:
  end)

  it('handles an autocommand that calls bwipeout!', function()
    api.nvim_buf_set_lines(0, 0, -1, true, {
      'line 1',
      'line 2',
      'line 3',
    })

    local test_bufnr = api.nvim_get_current_buf()

    command("autocmd MarkSet * let g:autocmd ..= expand('<amatch>') | bwipeout!")
    command([[let g:autocmd = '']])

    feed('ma')
    poke_eventloop()

    eq('a', eval('g:autocmd'))

    eq(false, api.nvim_buf_is_valid(test_bufnr))

    local current_bufnr = api.nvim_get_current_buf()
    neq(current_bufnr, test_bufnr)
  end)

  it('emits after :mark command', function()
    api.nvim_buf_set_lines(0, 0, -1, true, {
      'line 1',
      'line 2',
      'line 3',
    })

    command([[
      let g:markset_events = []
      autocmd MarkSet * call add(g:markset_events, {'event': deepcopy(v:event)})
    ]])

    feed('j')
    command('mark a')
    poke_eventloop()

    eq(1, #eval('g:markset_events'))
    local mark_event = eval('g:markset_events')[1]
    eq('a', mark_event.event.name)
    eq(2, mark_event.event.line)
    eq(0, mark_event.event.col)
  end)

  it('when autocommand switches windows and tabs', function()
    api.nvim_buf_set_lines(0, 0, -1, true, {
      'first buffer line 1',

Review comment (suggestion):
this entire test becomes a single line in the first test, since storing `g:mark_names` instead of just 'M' makes it clear what is being verified.

Code after:
    }, eval('g:markset_events'))
  end)

  it('handles an autocommand that calls bwipeout!', function()
    api.nvim_buf_set_lines(0, 0, -1, true, {
      'line 1',
      'line 2',
      'line 3',
    })

    local test_bufnr = api.nvim_get_current_buf()

    command("autocmd MarkSet * let g:autocmd ..= expand('<amatch>') | bwipeout!")
    command([[let g:autocmd = '']])

    feed('ma')
    poke_eventloop()

    eq('a', eval('g:autocmd'))

    eq(false, api.nvim_buf_is_valid(test_bufnr))

    local current_bufnr = api.nvim_get_current_buf()
    neq(current_bufnr, test_bufnr)
  end)

  it('when autocommand switches windows and tabs', function()
    api.nvim_buf_set_lines(0, 0, -1, true, {
      'first buffer line 1',
      'first buffer line 2',
      'first buffer line 3',
    })
    local first_bufnr = api.nvim_get_current_buf()

    command('split')
    command('enew')
    api.nvim_buf_set_lines(0, 0, -1, true, {
      'second buffer line 1',
      'second buffer line 2',
    })
    local second_bufnr = api.nvim_get_current_buf()

    command('tabnew')
    api.nvim_buf_set_lines(0, 0, -1, true, {
      'third buffer line 1',
      'third buffer line 2',
      'third buffer line 3',
    })
    local third_bufnr = api.nvim_get_current_buf()

    command([[
Repository: neovim/neovim
File: test/functional/shada/marks_spec.lua (Lua)

Code before:
    eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
  end)

  it('updates deleted marks with :delmarks!', function()
    nvim_command('edit ' .. testfilename)

    nvim_command('mark A')
    nvim_command('mark a')
    feed('ggifoobar<esc>')
    nvim_command('wshada')

    reset()
    nvim_command('edit ' .. testfilename)
    nvim_command('normal! `A`a`.')
    nvim_command('delmarks!')
    nvim_command('wshada')

    reset()
    nvim_command('edit ' .. testfilename)
    eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
    eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
    -- Make sure that uppercase marks aren't deleted.
    nvim_command('normal! `A')
  end)

  it('preserves marks after bdelete #35770', function()
    nvim_command('edit foo')
    nvim_command('mark X')
    nvim_command('bdelete')
    nvim_command('wshada')

    reset()
    local mX = api.nvim_get_mark('X', {})
    t.matches(vim.pesc('foo'), mX[4])

    nvim_command('delmarks X')
    nvim_command('edit foo')
    nvim_command('mark X')
    nvim_command('edit bar')
    nvim_command('mark Y')
    nvim_command('bufdo bdelete')
    nvim_command('edit foo')
    nvim_command('wshada')

    reset()
    mX = api.nvim_get_mark('X', {})
    local mY = api.nvim_get_mark('Y', {})
    t.matches(vim.pesc('foo'), mX[4])
    t.matches(vim.pesc('bar'), mY[4])
  end)
end)

Review comment (suggestion):
```suggestion
  it('preserves marks after :bdelete #35770', function()
```

Code after:
    eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
  end)

  it('updates deleted marks with :delmarks!', function()
    nvim_command('edit ' .. testfilename)

    nvim_command('mark A')
    nvim_command('mark a')
    feed('ggifoobar<esc>')
    nvim_command('wshada')

    reset()
    nvim_command('edit ' .. testfilename)
    nvim_command('normal! `A`a`.')
    nvim_command('delmarks!')
    nvim_command('wshada')

    reset()
    nvim_command('edit ' .. testfilename)
    eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
    eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
    -- Make sure that uppercase marks aren't deleted.
    nvim_command('normal! `A')
  end)

  it('preserves marks after :bdelete #35770', function()
    nvim_command('edit foo')
    nvim_command('mark X')
    nvim_command('bdelete')
    nvim_command('wshada')

    reset()
    local mX = api.nvim_get_mark('X', {})
    t.matches(vim.pesc('foo'), mX[4])

    nvim_command('delmarks X')
    nvim_command('edit foo')
    nvim_command('mark X')
    nvim_command('edit bar')
    nvim_command('mark Y')
    nvim_command('bufdo bdelete')
    nvim_command('edit foo')
    nvim_command('wshada')

    reset()
    mX = api.nvim_get_mark('X', {})
    local mY = api.nvim_get_mark('Y', {})
    t.matches(vim.pesc('foo'), mX[4])
    t.matches(vim.pesc('bar'), mY[4])
  end)
end)
Repository: neovim/neovim
File: contrib/nvim.bash (Shell)

Code before:
# nvim completion for bash.

if [[ -n ${BASH_COMPLETION_VERSINFO[*]} ]] \
  && ((BASH_COMPLETION_VERSINFO[0] > 2 || (\
  BASH_COMPLETION_VERSINFO[0] == 2 && BASH_COMPLETION_VERSINFO[1] >= 12))); then
  # use bash-completion >= 2.12
  _comp_nvim() {
    local cur prev words cword
    _comp_initialize -n : -- "$@" || return

    case "$prev" in
      --listen | --server)
        _comp_compgen_filedir

        if [[ "$cur" != /* ]]; then
          _comp_compgen_ip_addresses -a
          compopt -o nospace
        fi

        return
        ;;
    esac

    if [[ "$cur" =~ ^- ]]; then
      _comp_compgen_help
      _comp_compgen -a -- -W "-c -Es -v -h"

      if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
        case "${COMPREPLY-}" in
          -o | -O | -p | -V)
            compopt -o nospace
            ;;
        esac
      fi
      return
    fi

    _comp_compgen_filedir
  } \
    && complete -F _comp_nvim nvim
else
  _comp_nvim() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD - 1]}"

    opts="
      --cmd
      -c
      -l

Review comment (suggestion):
Interesting, does this read the args from `--help`? That is cool and worth mentioning here. It adds weight to our decisions about `--help`.

Code after:
# Provides bash completion for "nvim".

if [[ -n ${BASH_COMPLETION_VERSINFO[*]} ]] \
  && ((BASH_COMPLETION_VERSINFO[0] > 2 || (\
  BASH_COMPLETION_VERSINFO[0] == 2 && BASH_COMPLETION_VERSINFO[1] >= 12))); then
  # use bash-completion >= 2.12
  _comp_nvim() {
    local cur prev words cword
    _comp_initialize -n : -- "$@" || return

    case "$prev" in
      --listen | --server)
        _comp_compgen_filedir

        if [[ "$cur" != /* ]]; then
          _comp_compgen_ip_addresses -a
          compopt -o nospace
        fi

        return
        ;;
    esac

    if [[ "$cur" =~ ^- ]]; then
      # Infers args from "nvim --help".
      _comp_compgen_help
      _comp_compgen -a -- -W "-c -Es -v -h"

      if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
        case "${COMPREPLY-}" in
          -o | -O | -p | -V)
            compopt -o nospace
            ;;
        esac
      fi
      return
    fi

    _comp_compgen_filedir
  } \
    && complete -F _comp_nvim nvim
else
  _comp_nvim() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD - 1]}"

    opts="
      --cmd
      -c
Repository: neovim/neovim
File: contrib/nvim.bash (Shell)

Code before:
# nvim completion for bash.

if [[ -n ${BASH_COMPLETION_VERSINFO[*]} ]] \
  && ((BASH_COMPLETION_VERSINFO[0] > 2 || (\
  BASH_COMPLETION_VERSINFO[0] == 2 && BASH_COMPLETION_VERSINFO[1] >= 12))); then
  # use bash-completion >= 2.12
  _comp_nvim() {
    local cur prev words cword
    _comp_initialize -n : -- "$@" || return

    case "$prev" in
      --listen | --server)
        _comp_compgen_filedir

        if [[ "$cur" != /* ]]; then
          _comp_compgen_ip_addresses -a
          compopt -o nospace
        fi

        return
        ;;
    esac

    if [[ "$cur" =~ ^- ]]; then
      _comp_compgen_help
      _comp_compgen -a -- -W "-c -Es -v -h"

      if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
        case "${COMPREPLY-}" in
          -o | -O | -p | -V)
            compopt -o nospace
            ;;
        esac
      fi
      return
    fi

    _comp_compgen_filedir
  } \
    && complete -F _comp_nvim nvim
else
  _comp_nvim() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD - 1]}"

    opts="
      --cmd
      -c
      -l

Review comment (suggestion):
```suggestion
      # Infers args from "nvim --help".
      _comp_compgen_help
```

Code after:
# Provides bash completion for "nvim".

if [[ -n ${BASH_COMPLETION_VERSINFO[*]} ]] \
  && ((BASH_COMPLETION_VERSINFO[0] > 2 || (\
  BASH_COMPLETION_VERSINFO[0] == 2 && BASH_COMPLETION_VERSINFO[1] >= 12))); then
  # use bash-completion >= 2.12
  _comp_nvim() {
    local cur prev words cword
    _comp_initialize -n : -- "$@" || return

    case "$prev" in
      --listen | --server)
        _comp_compgen_filedir

        if [[ "$cur" != /* ]]; then
          _comp_compgen_ip_addresses -a
          compopt -o nospace
        fi

        return
        ;;
    esac

    if [[ "$cur" =~ ^- ]]; then
      # Infers args from "nvim --help".
      _comp_compgen_help
      _comp_compgen -a -- -W "-c -Es -v -h"

      if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
        case "${COMPREPLY-}" in
          -o | -O | -p | -V)
            compopt -o nospace
            ;;
        esac
      fi
      return
    fi

    _comp_compgen_filedir
  } \
    && complete -F _comp_nvim nvim
else
  _comp_nvim() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD - 1]}"

    opts="
      --cmd
      -c
Repository: neovim/neovim
File: contrib/nvim.bash (Shell)

Code before:
#!/usr/bin/env bash

# nvim completion for bash.

if [[ -n ${BASH_COMPLETION_VERSINFO[*]} ]] \
  && ((BASH_COMPLETION_VERSINFO[0] > 2 || (\
  BASH_COMPLETION_VERSINFO[0] == 2 && BASH_COMPLETION_VERSINFO[1] >= 12))); then
  # use bash-completion >= 2.12
  _comp_nvim() {
    local cur prev words cword
    _comp_initialize -n : -- "$@" || return

    case "$prev" in
      --listen | --server)
        _comp_compgen_filedir

        if [[ "$cur" != /* ]]; then
          _comp_compgen_ip_addresses -a
          compopt -o nospace
        fi

        return
        ;;
    esac

    if [[ "$cur" =~ ^- ]]; then
      # Infers args from "nvim --help".
      _comp_compgen_help

Review comment (suggestion):
```suggestion
# Provides bash completion for "nvim".
```

Code after:
#!/usr/bin/env bash

# Provides bash completion for "nvim".

if [[ -n ${BASH_COMPLETION_VERSINFO[*]} ]] \
  && ((BASH_COMPLETION_VERSINFO[0] > 2 || (\
  BASH_COMPLETION_VERSINFO[0] == 2 && BASH_COMPLETION_VERSINFO[1] >= 12))); then
  # use bash-completion >= 2.12
  _comp_nvim() {
    local cur prev words cword
    _comp_initialize -n : -- "$@" || return

    case "$prev" in
      --listen | --server)
        _comp_compgen_filedir

        if [[ "$cur" != /* ]]; then
          _comp_compgen_ip_addresses -a
          compopt -o nospace
        fi

        return
        ;;
    esac

    if [[ "$cur" =~ ^- ]]; then
      # Infers args from "nvim --help".
      _comp_compgen_help
Repository: neovim/neovim
File: test/functional/core/startup_spec.lua (Lua)

Code before:
  end)
end)

describe('v:argf', function()
  local files = {}

  before_each(function()
    clear()
    files = {}

    for _, f in ipairs({
      'Xargf_file1', 'Xargf_file2',
      'Xargf_persist',
      'Xargf_sep1', 'Xargf_sep2'
    }) do
      os.remove(f)
    end
  end)

  after_each(function()
    for _, f in ipairs(files) do
      os.remove(f)
    end
  end)

  it('contains absolute paths for startup files', function()
    local file1, file2 = 'Xargf_file1', 'Xargf_file2'
    write_file(file1, '')
    write_file(file2, '')
    files = { file1, file2 }

    local abs1 = fn.fnamemodify(file1, ':p')
    local abs2 = fn.fnamemodify(file2, ':p')

    local out = fn.system({
      nvim_prog,
      '--headless',
      '-u', 'NONE',
      '-i', 'NONE',
      '--cmd', 'echo v:argf',
      file1,
      file2,
      '-c', 'qall',
    })

    matches(pesc(abs1), out)
    matches(pesc(abs2), out)
  end)

  it('retains absolute paths after :cd', function()
    local file1 = 'Xargf_persist'

Review comment (suggestion):
```suggestion
  it('stores full path of file args', function()
```

Code after:
      table.concat({ xdata, nvimdata, 'site', 'pack', 'xa', 'start', 'yb' }, pathsep)
    local plugin_folder_path = table.concat({ plugin_path, 'plugin' }, pathsep)
    local plugin_after_path = table.concat({ plugin_path, 'after', 'plugin' }, pathsep)
    local plugin_file_path = table.concat({ plugin_folder_path, 'plugin.lua' }, pathsep)
    local plugin_after_file_path = table.concat({ plugin_after_path, 'helloo.lua' }, pathsep)
    mkdir_p(plugin_folder_path)
    mkdir_p(plugin_after_path)
    finally(function()
      rmdir(plugin_path)
    end)

    write_file(plugin_file_path, [[table.insert(_G.lista, "unos")]])
    write_file(plugin_after_file_path, [[table.insert(_G.lista, "dos")]])

    clear { args_rm = { '-u' }, args = { '--cmd', 'lua _G.lista = {}' }, env = xenv }

    eq({ 'unos', 'dos' }, exec_lua 'return _G.lista')
  end)

  it('no crash setting &rtp in plugins with :packloadall called before #18315', function()
    local plugin_folder_path = table.concat({ xconfig, 'nvim', 'plugin' }, pathsep)
    mkdir_p(plugin_folder_path)
    finally(function()
      rmdir(plugin_folder_path)
    end)

    write_file(
      table.concat({ plugin_folder_path, 'plugin.vim' }, pathsep),
      [[
        let &runtimepath = &runtimepath
        let g:vim_plugin = 1
      ]]
    )
    write_file(
      table.concat({ plugin_folder_path, 'plugin.lua' }, pathsep),
      [[
        vim.o.runtimepath = vim.o.runtimepath
        vim.g.lua_plugin = 1
      ]]
    )

    clear { args_rm = { '-u' }, args = { '--cmd', 'packloadall' }, env = xenv }

    eq(1, eval('g:vim_plugin'))
    eq(1, eval('g:lua_plugin'))
  end)

  it("loads ftdetect/*.{vim,lua} respecting 'rtp' order", function()
    local rtp_folder = table.concat({ xconfig, 'nvim' }, pathsep)
    local after_rtp_folder = table.concat({ rtp_folder, 'after' }, pathsep)
    local ftdetect_folder = table.concat({ rtp_folder, 'ftdetect' }, pathsep)
Repository: neovim/neovim
File: runtime/lua/vim/_defaults.lua (Lua)

Code before:
        path = vim.fs.dirname((vim.uv.cwd())),
      })
      for _, file in ipairs(files) do
        local trusted = vim.secure.read(file) --[[@as string|nil]]
        if trusted then
          if vim.endswith(file, '.lua') then
            assert(loadstring(trusted, '@' .. file))()
          else
            vim.api.nvim_exec2(trusted, {})
          end
        end
        -- If the user unset 'exrc' in the current exrc then stop searching
        if not vim.o.exrc then
          return
        end
      end
    end,
  })

  -- Show progress bars in supporting terminals
  vim.api.nvim_create_autocmd('Progress', {
    group = vim.api.nvim_create_augroup('nvim.progress', {}),
    desc = 'Display native progress bars',
    callback = function(ev)
      if ev.data.status == 'running' then
        vim.api.nvim_ui_send(string.format('\027]9;4;1%d\027\\', ev.data.percent))
      else
        vim.api.nvim_ui_send('\027]9;4;0;0\027\\')
      end
    end,
  })
end

--- Default options
do
  --- Default 'grepprg' to ripgrep if available.
  if vim.fn.executable('rg') == 1 then
    -- Use -uu to make ripgrep not check ignore files/skip dot-files
    vim.o.grepprg = 'rg --vimgrep -uu '
    vim.o.grepformat = '%f:%l:%c:%m'
  end
end


Review comment (suggestion):
This will run even if a TUI is not attached. But I guess that's harmless, and wouldn't gain much if this callback manually checked if a TUI is attached.

The more "proper" way would be to only define this event handler after a TUI attaches. But I think it makes sense to always define it, since we ostensibly plan to support GUIs somehow later.

Code after:
        path = vim.fs.dirname((vim.uv.cwd())),
      })
      for _, file in ipairs(files) do
        local trusted = vim.secure.read(file) --[[@as string|nil]]
        if trusted then
          if vim.endswith(file, '.lua') then
            assert(loadstring(trusted, '@' .. file))()
          else
            vim.api.nvim_exec2(trusted, {})
          end
        end
        -- If the user unset 'exrc' in the current exrc then stop searching
        if not vim.o.exrc then
          return
        end
      end
    end,
  })

  if tty then
    -- Show progress bars in supporting terminals
    vim.api.nvim_create_autocmd('Progress', {
      group = vim.api.nvim_create_augroup('nvim.progress', {}),
      desc = 'Display native progress bars',
      callback = function(ev)
        if ev.data.status == 'running' then
          vim.api.nvim_ui_send(string.format('\027]9;4;1;%d\027\\', ev.data.percent))
        else
          vim.api.nvim_ui_send('\027]9;4;0;0\027\\')
        end
      end,
    })
  end
end

--- Default options
do
  --- Default 'grepprg' to ripgrep if available.
  if vim.fn.executable('rg') == 1 then
    -- Use -uu to make ripgrep not check ignore files/skip dot-files
    vim.o.grepprg = 'rg --vimgrep -uu '
    vim.o.grepformat = '%f:%l:%c:%m'
  end
end