From c9edb905d3296104535db5da695f6edf0a0a7127 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Wed, 13 Jul 2022 22:51:40 +0700 Subject: [PATCH 1/3] refactor(command): Remove vimscript --- lua/catppuccin/command.lua | 0 lua/catppuccin/main.lua | 22 ++++++++++++++++--- lua/catppuccin/utils/util.lua | 40 ++++++++++------------------------- plugin/catppuccin.vim | 16 -------------- 4 files changed, 30 insertions(+), 48 deletions(-) delete mode 100644 lua/catppuccin/command.lua delete mode 100644 plugin/catppuccin.vim diff --git a/lua/catppuccin/command.lua b/lua/catppuccin/command.lua deleted file mode 100644 index e69de29..0000000 diff --git a/lua/catppuccin/main.lua b/lua/catppuccin/main.lua index bcac01a..545bf6a 100644 --- a/lua/catppuccin/main.lua +++ b/lua/catppuccin/main.lua @@ -2,9 +2,25 @@ local M = {} local flavours = {"latte", "frappe", "macchiato", "mocha"} -function M.cli_flavour_completion() - return vim.tbl_keys(require("catppuccin.utils.data").set_of(flavours)) -end +local command = vim.api.nvim_create_user_command + +command("Catppuccin", function(inp) + vim.g.catppuccin_flavour = inp.args + vim.cmd "colorscheme catppuccin" +end, { + nargs = 1, + complete = function() + return flavours + end +}) + +command("CatppuccinCompile", function() + require("catppuccin.utils.util").compile() +end, {}) + +command("CatppuccinClean", function() + require("catppuccin.utils.util").clean() +end, {}) local function load() local catppuccin = require("catppuccin") diff --git a/lua/catppuccin/utils/util.lua b/lua/catppuccin/utils/util.lua index 2053e53..0459f3e 100644 --- a/lua/catppuccin/utils/util.lua +++ b/lua/catppuccin/utils/util.lua @@ -1,38 +1,20 @@ local g = vim.g local util = {} -local has_nvim07 = vim.fn.has("nvim-0.7") - function util.highlight(group, color) - if has_nvim07 then - if color.link then - vim.api.nvim_set_hl(0, group, { - link = color.link, - }) - else - if color.style then - for _, style in ipairs(color.style) do - color[style] = true - end - end - - color.style = nil - vim.api.nvim_set_hl(0, group, color) - end - else -- Doc: :h highlight-gui + if color.link then + vim.api.nvim_set_hl(0, group, { + link = color.link, + }) + else if color.style then - color.style = table.concat(color.style, ",") - end - local style = (color.style and color.style ~= "") and "gui=" .. color.style or "gui=NONE" - local fg = color.fg and "guifg=" .. color.fg or "guifg=NONE" - local bg = color.bg and "guibg=" .. color.bg or "guibg=NONE" - local sp = color.sp and "guisp=" .. color.sp or "" - local blend = color.blend and "blend=" .. color.blend or "" - local hl = "highlight " .. group .. " " .. style .. " " .. fg .. " " .. bg .. " " .. sp .. " " .. blend - vim.cmd(hl) - if color.link then - vim.cmd("highlight! link " .. group .. " " .. color.link) + for _, style in ipairs(color.style) do + color[style] = true + end end + + color.style = nil + vim.api.nvim_set_hl(0, group, color) end end diff --git a/plugin/catppuccin.vim b/plugin/catppuccin.vim deleted file mode 100644 index 7395b6b..0000000 --- a/plugin/catppuccin.vim +++ /dev/null @@ -1,16 +0,0 @@ -if exists('g:loaded_catppuccin') | finish | endif - -function! s:FlavourCompletion(...) abort - return join(sort(luaeval("require'catppuccin.main'.cli_flavour_completion()")), "\n") -endfunction - -function! s:ApplyFlavour(args) abort - let g:catppuccin_flavour = matchstr(a:args[0], "[a-z]*") - colorscheme catppuccin -endfunction - -command! -nargs=1 -complete=custom,s:FlavourCompletion Catppuccin call s:ApplyFlavour([]) -command! CatppuccinCompile lua require("catppuccin.utils.util").compile() -command! CatppuccinClean lua require("catppuccin.utils.util").clean() - -let g:loaded_catppuccin = 1 From b31738cd74c92892c6ffd3ce03201f3e879920a7 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Wed, 13 Jul 2022 22:54:25 +0700 Subject: [PATCH 2/3] refactor(command): Remove vimscript --- lua/catppuccin/utils/util.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/lua/catppuccin/utils/util.lua b/lua/catppuccin/utils/util.lua index 0459f3e..8515e32 100644 --- a/lua/catppuccin/utils/util.lua +++ b/lua/catppuccin/utils/util.lua @@ -88,9 +88,6 @@ local function inspect(t) end function util.compile() - if vim.fn.has "nvim-0.7" == 0 then - print "Compiling requires neovim 0.7" - end local theme = require("catppuccin.core.mapper").apply() local lines = { [[ -- This file is autogenerated by CATPPUCCIN. From 2c08d7b5906de7346183fca95d164709bf070954 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Wed, 13 Jul 2022 22:57:54 +0700 Subject: [PATCH 3/3] refactor(command): Add custom completion --- lua/catppuccin/main.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/catppuccin/main.lua b/lua/catppuccin/main.lua index 545bf6a..b9d532d 100644 --- a/lua/catppuccin/main.lua +++ b/lua/catppuccin/main.lua @@ -9,8 +9,11 @@ command("Catppuccin", function(inp) vim.cmd "colorscheme catppuccin" end, { nargs = 1, - complete = function() - return flavours + complete = function(line) + local builtin_list = flavours + return vim.tbl_filter(function(val) + return vim.startswith(val, line) + end, builtin_list) end })