nvimdev / galaxyline.nvim

neovim statusline plugin written in lua
MIT License
867 stars 113 forks source link

highlight link ignored error #131

Closed horseinthesky closed 3 years ago

horseinthesky commented 3 years ago

After the last update a lot of action start raising the following error:

Error executing vim.schedule lua callback: ...k/packer/start/galaxyline.nvim/lua/galaxyline/colors.lua:43: Vim(highlight):E414: group has settings, highlight link ignored

It can be fixed by changing

api.nvim_command('highlight link ' .. group .. ' ' .. hi_info)

to

api.nvim_command('highlight! link ' .. group .. ' ' .. hi_info)

on 43 of colors.lua

But I'm not sure if it is a good solution.

glepnir commented 3 years ago

default support link to exist highlight group.

horseinthesky commented 3 years ago

default support link to exist highlight group.

I'm afraid I don't understand.

glepnir commented 3 years ago

Okay .what do you want? use exist highlight group right?

glepnir commented 3 years ago

https://github.com/glepnir/galaxyline.nvim/blob/b4ca8f1ff287b9beb5a30bf6add442683bae0e05/lua/galaxyline/colors.lua#L42-L45

horseinthesky commented 3 years ago

I got errors pretty much everywhere with this bug. I don't understand what highlight group galaxyline is trying to link but since it (group) has some settings, NVIM won't allow that. It can be fixed by adding ! to the highlight command but as I said since I don't know what group it is trying to link I also don't know if it is a good idea to fix it this way.

glepnir commented 3 years ago

no worry can you provide a min config ?

horseinthesky commented 3 years ago

no worry can you provide a min config ?

This is my super simplified statusline

local gl = require 'galaxyline'
local gls = gl.section

local icons = {
  locker = "", -- f023
  not_modifiable = "", -- f05e
  pencil = "", -- f040
}

-- Gruvbox
local colors = {
  bg0_h = "#1d2021",
  bg0 = "#282828",
  bg1 = "#3c3836",
  bg2 = "#504945",
  bg3 = "#665c54",
  bg4 = "#7c6f64",
  gray = "#928374",
  fg0 = "#fbf1c7",
  fg1 = "#ebdbb2",
  fg2 = "#d5c4a1",
  fg3 = "#bdae93",
  fg4 = "#a89984",
  bright_red = "#fb4934",
  bright_green = "#b8bb26",
  bright_yellow = "#fabd2f",
  bright_blue = "#83a598",
  bright_purple = "#d3869b",
  bright_aqua = "#8ec07c",
  bright_orange = "#fe8019",
  neutral_red = "#cc241d",
  neutral_green = "#98971a",
  neutral_yellow = "#d79921",
  neutral_blue = "#458588",
  neutral_purple = "#b16286",
  neutral_aqua = "#689d6a",
  neutral_orange = "#d65d0e",
  faded_red = "#9d0006",
  faded_green = "#79740e",
  faded_yellow = "#b57614",
  faded_blue = "#076678",
  faded_purple = "#8f3f71",
  faded_aqua = "#427b58",
  faded_orange = "#af3a03"
}

local mode_map = {
  ['n'] = {'NORMAL', colors.fg3, colors.bg2},
  -- ['n'] = {'NORMAL', colors.bright_green, colors.faded_green},
  ['i'] = {'INSERT', colors.bright_blue, colors.faded_blue},
  ['R'] = {'REPLACE', colors.bright_red, colors.faded_red},
  ['v'] = {'VISUAL', colors.bright_orange, colors.faded_orange},
  ['V'] = {'V-LINE', colors.bright_orange, colors.faded_orange},
  ['c'] = {'COMMAND', colors.bright_yellow, colors.faded_yellow},
  ['s'] = {'SELECT', colors.bright_orange, colors.faded_orange},
  ['S'] = {'S-LINE', colors.bright_orange, colors.faded_orange},
  ['t'] = {'TERMINAL', colors.bright_aqua, colors.faded_aqua},
  [''] = {'V-BLOCK', colors.bright_orange, colors.faded_orange},
  [''] = {'S-BLOCK', colors.bright_orange, colors.faded_orange},
  ['Rv'] = {'VIRTUAL'},
  ['rm'] = {'--MORE'},
}

local function mode_hl()
  local mode = mode_map[vim.fn.mode()]
  if mode == nil then
    mode = mode_map['v']
    return {'V-BLOCK', mode[2], mode[3]}
  end
  return mode
end

local function highlight(group, fg, bg, gui)
  local cmd = string.format('highlight %s guifg=%s guibg=%s', group, fg, bg)
  if gui ~= nil then cmd = cmd .. ' gui=' .. gui end
  vim.cmd(cmd)
end

local function buffer_not_empty()
  if vim.fn.empty(vim.fn.expand('%:t')) ~= 1 then return true end
  return false
end

local function wide_enough(width)
  if vim.fn.winwidth(0) > width then return true end
  return false
end

gls.left[2] = {
  ViMode = {
    provider = function()
      local label, fg, nested_fg = unpack(mode_hl())
      highlight('GalaxyViMode', nested_fg, fg)
      highlight('GalaxyViModeInv', fg, nested_fg)
      highlight('GalaxyViModeNested', fg, nested_fg)
      highlight('GalaxyViModeInvNested', nested_fg, colors.bg1)
      return string.format('  %s ', label)
    end,
  }
}
gls.left[4] = {
  FileName = {
    provider = function()
      if vim.bo.buftype == 'terminal' then return '' end
      if not buffer_not_empty() then return '' end

      local fname
      if wide_enough(120) then
        fname = vim.fn.fnamemodify(vim.fn.expand('%'), ':~:.')
        if #fname > 35 then fname = vim.fn.expand '%:t' end
      else
        fname = vim.fn.expand '%:t'
      end
      if #fname == 0 then return '' end

      if vim.bo.readonly then fname = fname .. ' ' .. icons.locker end
      if not vim.bo.modifiable then fname = fname .. ' ' .. icons.not_modifiable end
      if vim.bo.modified then fname = fname .. ' ' .. icons.pencil end

      return ' ' .. fname .. ' '
    end,
    highlight = 'GalaxyViModeNested',
    condition = buffer_not_empty,
  }
}
glepnir commented 3 years ago

use highlight! can work. fixed

horseinthesky commented 3 years ago

Thank you.