Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor setup() function, handle old configuration and update highlights #42

Merged
merged 6 commits into from
Jan 8, 2022

Conversation

xeluxee
Copy link
Contributor

@xeluxee xeluxee commented Dec 27, 2021

Fix #37

Changes introduced with this PR:

  • The configuration is kept in the global variable vim.g.onedark_config, to make it accessible from vimscript
  • refactor setup(): now it accepts an argument, a dictionary containing options. Note: setup() only manages configuration, it doesn't load the colorscheme. To load the colorscheme you can :colo onedark

Example:

require('onedark').setup {
  style = 'deep',
  toggle_style_key = '<leader>o',
  diagnostics = {
    darker = false,
    background = false,
  },
}

Of course it can be called without any argument: require('onedark').setup(), and the default configuration will be used

  • colors/onedark.vim -> colors/onedark.lua
  • lua/onedark/config.lua -> lua/onedark/old_config.lua, since this file is used to parse old configuration (if found it prints deprecation messages)
  • highlights: deprecate bold, underline, undercurl, italic and reverse options in favor of fmt, a string that is ready to be used in highlight command. Example: ErrorMsg = {fg = c.red, fmt = "bold,italic"}. To see all the available attributes :h attr-list or here (they are the same for cterm and gui)
  • highlights: trying to improve markdown highlights (TS markdown has no highlighting #41), trough groups TSTitle, TSURI, TSTextReference
  • highlights: update nvim-cmp highlights to support new kind icon colors
  • highlights: improve hop highlights
  • highlights: for C and C++ TSOperator is purple now, it looks better. I think we should consider colouring TSOperator for other languages too
  • highlights: implemented code_style customization for various elements (comments, keywords, functions, strings and variables)
  • colors: allow user to define custom colors or to overwrite existing ones.
  • highlights: allow user to define custom highlights or to overwrite existing ones. Dollar prefix means a color from the colorscheme must be used. Example:
require('onedark').setup {
  colors = {
    bright_orange = "#ff8800",    -- define a new color
    green = '#00ffaa',            -- redefine an existing color
  },
  highlights = {
    TSKeyword = {fg = '$green'},
    TSString = {fg = '$bright_orange', bg = '#00ff00', fmt = 'bold'},
    TSFunction = {fg = '#0000ff', sp = '$cyan', fmt = 'underline,italic'},
  }
}

Usage

NOTE: all configurations must be done before setting the colorscheme

Vimscript

let g:onedark_config = {
  \ 'style': 'deep',
  \ 'toggle_style_key': '<leader>ts',
  \ 'ending_tildes': v:true,
  \ 'diagnostics': {
    \ 'darker': v:false,
    \ 'background': v:false,
  \ },
\ }
colorscheme onedark

Note: when using vimscript boolean values must be set with v:true and v:false, not 0 and 1

Lua

require('onedark').setup {
  style = 'warmer',
  toggle_style_key = '<leader>t',
  code_style = {
    comment = 'italic',
    keywords = 'bold,italic',
    strings = 'italic',
  },
  diagnostics = {
    darker = false,
    background = false,
  },
}
vim.api.nvim_command('colorscheme onedark')

Full config

default_config = {
    -- Main options --
    style = 'dark',    -- choose between 'dark', 'darker', 'cool', 'deep', 'warm', 'warmer' and 'light'
    toggle_style_key = '<leader>ts',
    toggle_style_list = { 'dark', 'darker', 'cool', 'deep', 'warm', 'warmer', 'light' },
    transparent = false,     -- don't set background
    term_colors = true,      -- if true enable the terminal
    ending_tildes = false,    -- show the end-of-buffer tildes

    -- Changing Formats --
    code_style = {
        comments = 'italic',
        keywords = 'none',
        functions = 'none',
        strings = 'none',
        variables = 'none'
    },

    -- Custom Highlights --
    colors = {}, -- Override default colors
    highlights = {}, -- Override highlight groups

    -- Plugins Related --
    diagnostics = {
        darker = true, -- darker colors for diagnostic
        undercurl = true,   -- use undercurl for diagnostics
        background = true,    -- use background color for virtual text
    },
}

@xeluxee xeluxee marked this pull request as ready for review December 29, 2021 15:33
@xeluxee
Copy link
Contributor Author

xeluxee commented Dec 29, 2021

@navarasu now this PR is ready to be merged
Should we consider using stylua or something like that to format lua code?

@navarasu
Copy link
Owner

navarasu commented Jan 1, 2022

Thanks @xeluxee for your valuable. contribution. I will pull this code and will check in my local with all cases. Also will update the doc and merge tomorrow.

@xeluxee
Copy link
Contributor Author

xeluxee commented Jan 1, 2022

@navarasu I've just pushed a bugfix commit, please give another pull before checking

@navarasu
Copy link
Owner

navarasu commented Jan 8, 2022

I pulled it in local and verified. Legacy vim syntax works. But when I call lua option in the init.nvim, it is not enabling the scheme

lua <<EOF
require('onedark').setup {
  style = 'warmer'
  }
EOF

@navarasu navarasu merged commit c9a2bb0 into navarasu:master Jan 8, 2022
@navarasu
Copy link
Owner

navarasu commented Jan 8, 2022

We need to call M.colorscheme() at last in setup. But I called vim.api.nvim_command('colorscheme onedark') to fix #28

@xeluxee
Copy link
Contributor Author

xeluxee commented Jan 8, 2022

We need to call M.colorscheme() at last in setup. But I called vim.api.nvim_command('colorscheme onedark') to fix #28

@navarasu I don't agree, since setup function shouldn't load the colorscheme: other Neovim colorschemes uses setup only to configure theme options.
For example I don't always use onedark, but I want it to be configured in my init.lua trough setup(). So if later I want to switch to onedark I can simply :colo onedark without calling setup again with all the settings

Actually #28 can be solved only calling :colo onedark (or vim.api.nvim_command("colo onedark") from lua) since autocmd is triggered only on command :colorscheme. Indeed if we update highlight groups directly with M.colorscheme() everything will work except autocommands, that won't be triggered.

@navarasu
Copy link
Owner

navarasu commented Jan 8, 2022

@xeluxee Yes, I agree. There is some suggestion from one user #46

@xeluxee xeluxee deleted the setup_refactoring branch April 24, 2022 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setup() refactoring
2 participants