ramojus/mellifluous.nvim

Issue customizing colors

Closed this issue · 6 comments

Hey there, I am trying to customize a few colors, but I can't quite figure out how to get it working. I have been trying to read up on lush and how to modify a colorscheme made with it, and the below is what I came up with, but it just gives me an error.

I put this code in after/plugins/colorscheme.lua

I must be doing something incorrectly, I am just not quite sure what. I hope I am at least on the right track with this?

 require 'mellifluous'.setup({
  color_set = 'mellifluous',   
  ... -- The rest of my config items
})

local is_loaded, lush = pcall(require, 'lush')

if is_loaded then
  local mell_loaded, mellifluous = pcall(require, 'mellifluous')
  if not mell_loaded then
    return
  end

  local spec = lush.extends({mellifluous}).with(function()
    ---@diagnostic disable: undefined-global
    --stylua: ignore start
    return {
      Exception { fg =  '#FD1C35',},
    }
    --stylua: ignore end
  end)

  lush(spec)
else
  vim.notify("lush.nvim not found")
end

Unfortunately, the error itself is not at all helpful either.

Failed to source `/home/mosthated/.config/nvim/after/plugin/colorscheme.lua`
...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:438: Vim(source):E5113: Error while calling lua chunk: [NULL]
# stacktrace:
  - .config/nvim/lua/plugins.lua:219

Hey, you have to call mellifluous.load() function to get mellifluous spec. Changing this line:

  local spec = lush.extends({mellifluous}).with(function()

to this line:

  local spec = lush.extends({mellifluous.load()}).with(function()

should make it work.

Let me know if this works for you. I'll have to update the README to include instructions for people attempting this.

I definitely appreciate the reply. That did indeed take care of the error, though, it did not actually change the color for some reason. It seemed like that would be all that was needed according to what I saw with the lush examples I saw.

I also tried to look through some of the code in this repo to make sure I was trying to adjust the right thing, and it seemed to be correct as well.

I was able to do something similar, albeit different, to change something in LuaLine:

I tried making the change first in the 'color-override' plugin as I had done for lualine, but it didn't work there, which is what lead me to trying the lush.extends technique. Considering neither seem to work, it makes me think I must have missed something needed for this particular change?

Color-Override Plugin
local my_clear_colors = {'SignColumn'}
local my_colors = {
  -- Exception =             { ctermbg='NONE', ctermfg='NONE', guibg='#292929', guifg='#FD1C35' },

  --| Search Highlight ------
  Search =                { ctermbg='NONE', ctermfg='NONE', guibg='#292929', guifg='#4A86CF' },
  MatchParen  =           { ctermbg='NONE', ctermfg='NONE', guibg='#303A3E', guifg='#E7E85A' },
  --| Git -------------------
  GitGutterAdd =          { ctermbg='NONE', ctermfg='green', guibg='NONE', guifg='green' },
  GitGutterChange =       { ctermbg='NONE', ctermfg='green', guibg='NONE', guifg='#2B5B77' },
  GitGutterDelete =       { ctermbg='NONE', ctermfg='#FD1C35',   guibg='NONE', guifg='#FD1C35' },
  GitGutterChangeDelete = { ctermbg='NONE', ctermfg='#FD1C35',   guibg='NONE', guifg='#2B5B77' },

  --| Mode Line -------------
  ModeMsg  = { ctermbg='NONE', ctermfg='green', guibg='NONE', guifg='#1b1b1b' },
  MsgArea  = { ctermbg='NONE', ctermfg='green', guibg='NONE', guifg='#a3a3a3' }
}

require('color-overrides').set_overrides(my_clear_colors, my_colors)

I also tried a few different table keys, in addition to just fg = #color, just in case they were needed, similar to the ones in the code example above, ex: guifg = #color, etc, but those didn't do anything either.
I didn't expect them to considering the items in your code I linked above had simply used fg = #color, but was worth a shot, lol.

This is the specific code that I've tried and it works for me:

require 'mellifluous'.setup {
    color_set = 'mountain',
}

local lush = require('lush')
local mellifluous_spec = require('mellifluous').load()

local new_spec = lush.extends({ mellifluous_spec }).with(function()
    ---@diagnostic disable: undefined-global
    return {
        Exception { fg = '#FD1C35', },
        LineNr { fg = '#FD1C35', },
    }
end)

lush(new_spec)

Do you have colorscheme mellifluous command called somewhere after lush(new_spec)? If so, this could explain why you're not seeing any changes. This is because lush(new_spec) itself applies the modified colorscheme, and calling colorscheme mellifluous afterwards will overwrite the changes made by lush(new_spec) and restore the original colorscheme.

There is an even simpler option to customise colorschemes without additional plugins -- call nvim_set_hl after setting the colorscheme, example that achieves what you want:

vim.cmd('colorscheme mellifluous')

vim.api.nvim_set_hl(0, "Exception", { fg = '#FD1C35' })

I've just realised that you probably want to change the treesitter highlight group as well.

I think then you have to use ["@exception"] for highlight name in the second version that I've suggested. All treesitter highlight groups are named like that, with the "@" sign.
For lush.extends version with treesitter highlights, follow the syntax in source code (in the place that you've linked, with sym()

Also you can use :Telescope highlights command, or something like that (if you have telescope plugin) to easily search for currently applied highlights and see what they are set to.

Hope this helps

After trying a bunch of things, I finally did find something that worked. Strangely, it was putting ["@exception"] = { guifg = "#FD1C35" }, into the color-override plugin. No other attempts seemed to work for some reason. I made sure to double check that I was not setting the colorscheme any additional places (only in init.lua, just after requiring plugins.lua). It works, though, so that is really what matters I suppose. I definitely appreciate the assistance.

edit: Unless the color-override plugin itself is calling colorscheme again to do whatever it is doing? I will have to check on that. Perhaps it might be the reason that nothing else worked, and it did.

color-overrides plugin automatically reapplies highlights whenever colorscheme changes, so it makes sense that it works for you.

Just to reiterate on what I said before:

  • if you use lush(new_spec) command where new_spec is the extended colorscheme, you don't need to call colorscheme mellifluous (it would override all the extended highlights with the original ones) .
  • For another (simpliest) method, vim.api.nvim_set_hl(), has to be called after the colorscheme mellifluous command.

Anyways, I'm happy to help and that you've got something working.