Repository: neovim/neovim
File: src/nvim/options.lua (Lua)

Code before:
        	let &stc='%#NonText#%{&nu?v:lnum:""}' .
        	 '%=%{&rnu&&(v:lnum%2)?"\ ".v:relnum:""}' .
        	 '%#LineNr#%{&rnu&&!(v:lnum%2)?"\ ".v:relnum:""}'

        <	WARNING: this expression is evaluated for each screen line so defining
        an expensive expression can negatively affect render performance.
      ]=],
      full_name = 'statuscolumn',
      redraw = { 'current_window' },
      scope = { 'win' },
      secure = true,
      short_desc = N_('custom format for the status column'),
      type = 'string',
    },
    {
      abbreviation = 'stl',
      cb = 'did_set_statusline',
      defaults = table.concat({
        '%<',
        '%f %h%w%m%r ',
        '%=',
        "%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}",
        "%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}",
        "%{% &busy > 0 ? '◐ ' : '' %}",
        "%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}",
      }),
      desc = [=[
        Sets the |status-line|.

        The option consists of printf style '%' items interspersed with
        normal text.  Each status line item is of the form:
          %-0{minwid}.{maxwid}{item}
        All fields except the {item} are optional.  A single percent sign can
        be given as "%%".

        						*stl-%!*
        When the option starts with "%!" then it is used as an expression,
        evaluated and the result is used as the option value.  Example: >vim
        	set statusline=%!MyStatusLine()
        <	The *g:statusline_winid* variable will be set to the |window-ID| of the
        window that the status line belongs to.
        The result can contain %{} items that will be evaluated too.
        Note that the "%!" expression is evaluated in the context of the
        current window and buffer, while %{} items are evaluated in the
        context of the window that the statusline belongs to.

        When there is error while evaluating the option then it will be made
        empty to avoid further errors.  Otherwise screen updating would loop.
        When the result contains unprintable characters the result is
        unpredictable.


Review comment (refactor):
Can't we simplify it to something like?

```lua
%{% v:lua.vim.diagnostic.status() %}
```

Since runtime files are shipped with the binaries they should be in sync with the defaults in binaries. And we can return empty string from the status function to handle the case where we don't want to show anything.

Code after:
        	let &stc='%#NonText#%{&nu?v:lnum:""}' .
        	 '%=%{&rnu&&(v:lnum%2)?"\ ".v:relnum:""}' .
        	 '%#LineNr#%{&rnu&&!(v:lnum%2)?"\ ".v:relnum:""}'

        <	WARNING: this expression is evaluated for each screen line so defining
        an expensive expression can negatively affect render performance.
      ]=],
      full_name = 'statuscolumn',
      redraw = { 'current_window' },
      scope = { 'win' },
      secure = true,
      short_desc = N_('custom format for the status column'),
      type = 'string',
    },
    {
      abbreviation = 'stl',
      cb = 'did_set_statusline',
      defaults = {
        if_true = table.concat({
          '%<',
          '%f %h%w%m%r ',
          '%=',
          "%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}",
          "%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}",
          "%{% &busy > 0 ? '◐ ' : '' %}",
          "%(%{luaeval('(pcall(require, ''vim.diagnostic'') and vim.diagnostic.status()) or '''' ')} %)",
          "%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}",
        }),
        doc = 'is very long',
      },
      desc = [=[
        Sets the |status-line|.

        The option consists of printf style '%' items interspersed with
        normal text.  Each status line item is of the form:
          %-0{minwid}.{maxwid}{item}
        All fields except the {item} are optional.  A single percent sign can
        be given as "%%".

        						*stl-%!*
        When the option starts with "%!" then it is used as an expression,
        evaluated and the result is used as the option value.  Example: >vim
        	set statusline=%!MyStatusLine()
        <	The *g:statusline_winid* variable will be set to the |window-ID| of the
        window that the status line belongs to.
        The result can contain %{} items that will be evaluated too.
        Note that the "%!" expression is evaluated in the context of the
        current window and buffer, while %{} items are evaluated in the
        context of the window that the statusline belongs to.

        When there is error while evaluating the option then it will be made