Refactor colorscheme updating

Also add a util for plugin load checks
This commit is contained in:
ViViDboarder 2021-09-16 13:32:29 -07:00
parent 9bbe68013b
commit 7afc5f9903
5 changed files with 46 additions and 48 deletions

View File

@ -1,4 +1,3 @@
-- luacheck: globals packer_plugins
local utils = require("utils")
local map = vim.api.nvim_set_keymap
@ -48,9 +47,9 @@ map("v", "``", "<esc>", opt_default)
function _G.complete_space()
if vim.fn.pumvisible() == 1 then
return utils.t("<C-n>")
elseif packer_plugins["completion-nvim"] and packer_plugins["completion-nvim"].loaded then
elseif utils.is_plugin_loaded("completion-nvim") then
return utils.t("<Plug>(completion_trigger)")
elseif packer_plugins["nvim-compe"] and packer_plugins["nvim-compe"].loaded then
elseif utils.is_plugin_loaded("nvim-compe") then
return vim.fn["compe#complete"]()
else
return utils.t("<C-x><C-o>")

View File

@ -1,7 +1,4 @@
-- luacheck: globals packer_plugins
local utils = require("utils")
-- TODO: Determine if I want to keep this or remove it in favor of dark-notify
-- Update colors based on environment variables
function _G.update_colors()
local function maybe_set(scope, name, val)
if vim[scope][name] ~= val then
@ -12,12 +9,13 @@ function _G.update_colors()
end
-- Set colorscheme based on env
local utils = require("utils")
local default_color = "solarized"
local env_color = utils.env_default("VIM_COLOR", default_color)
env_color = utils.env_default("NVIM_COLOR", env_color)
-- Read dark mode
local mode = vim.env.IS_DARKMODE
local mode = utils.env_default("IS_DARKMODE", "dark")
if vim.g.is_mac == 1 then
local cmd = "defaults read -g AppleInterfaceStyle 2>/dev/null || echo Light"
mode = vim.fn.system(cmd):gsub("\n", ""):lower()
@ -38,21 +36,26 @@ function _G.update_colors()
end
-- Update status line theme
if change and vim.fn.exists(":AirlineRefresh") == 1 then
vim.cmd(":AirlineRefresh")
elseif (change and _G["packer_plugins"]
and packer_plugins["lualine"] and packer_plugins["lualine"].loaded) then
local lualine_theme = vim.g.colors_name
if lualine_theme == "solarized" then
lualine_theme = lualine_theme .. "_" .. mode
if change then
if vim.fn.exists(":AirlineRefresh") == 1 then
vim.cmd(":AirlineRefresh")
elseif utils.is_plugin_loaded("lualine.nvim") then
local lualine_theme = vim.g.colors_name
if lualine_theme == "solarized" then
lualine_theme = lualine_theme .. "_" .. mode
end
require("plugins.lualine").config_lualine(lualine_theme)
end
require("plugins.lualine").config_lualine(lualine_theme)
end
return change and "Changed color to " .. env_color .. " with mode " .. mode or "No change"
end
-- utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()")
-- Initial set of colors
-- TODO: if update_colors() is removed, use the env color fetching and set the colorscheme here
-- Don't need the autocommand when dark-notify is installed
local utils = require("utils")
if not utils.is_plugin_loaded("dark-notify") then
utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()")
end
-- Initial setting of colors
_G.update_colors()

View File

@ -1,4 +1,4 @@
-- Do all Packer stuff
-- Install packer
local install_path = vim.fn.stdpath("data").."/site/pack/packer/start/packer.nvim"
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
@ -6,24 +6,12 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
vim.cmd "packadd packer.nvim"
end
-- Requires :PackerCompile for "config" to be loaded
-- Configures dark-notify to use colors from my environment
local function config_dark_notify()
local default_color = "solarized"
local env_color = utils.env_default("VIM_COLOR", default_color)
require("dark_notify").run{
schemes = {
dark = utils.env_default("VIM_COLOR_DARK", env_color),
light = utils.env_default("VIM_COLOR_LIGHT", env_color),
},
onchange = function(mode)
-- Update lualine with new colors
local lualine_theme = vim.g.colors_name
if lualine_theme == "solarized" then
lualine_theme = lualine_theme .. "_" .. mode
end
require("plugins.lualine").config_lualine(lualine_theme)
require("dark_notify").run {
onchange = function(_)
-- Defined in _colors
_G.update_colors()
end,
}
end
@ -68,17 +56,21 @@ return require('packer').startup(function()
-- UI
use "~/workspace/ez-colors.nvim/wombat"
use {
"~/workspace/wombuddy",
requires = "tjdevries/colorbuddy.vim",
}
use "hoob3rt/lualine.nvim"
use "vim-scripts/wombat256.vim"
use "ishan9299/nvim-solarized-lua"
use {
"norcalli/nvim-colorizer.lua",
config = function() require("colorizer").setup() end,
}
use "folke/tokyonight.nvim"
use {
"folke/tokyonight.nvim",
run = "fish -c 'echo \"set --path --prepend fish_themes_path \"(pwd)\"/extras\" > ~/.config/fish/conf.d/tokyonight.fish' || true", -- luacheck: no max line length
}
use {
"~/workspace/wombuddy",
requires = "tjdevries/colorbuddy.vim",
}
--[[
use {
"shaunsingh/solarized.nvim",
@ -100,11 +92,6 @@ return require('packer').startup(function()
requires = { "vim-airline/vim-airline-themes", opt = true },
}
--]]
use {
"hoob3rt/lualine.nvim",
-- configured by dark-notify
-- config = function() require("plugins.lualine").config_lualine("solarized") end,
}
use {
"cormacrelf/dark-notify",
-- Download latest release on install
@ -184,7 +171,8 @@ return require('packer').startup(function()
-- Override key commands
-- vim.g.fzf_action = { ['ctrl-t'] = 'tab split', ['ctrl-s'] = 'split', ['ctrl-v'] = 'vsplit', }
-- Override git log to show authors
vim.g.fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h %an: %s%d %C(black)%C(bold)%cr"' -- luacheck: no max line length
vim.g.fzf_commits_log_options = --graph --color=always \z
--format="%C(auto)%h %an: %s%d %C(black)%C(bold)%cr"
vim.g.fzf_preview_window = {"right:50%", "ctrl-/"}
@ -240,7 +228,7 @@ return require('packer').startup(function()
-- Debuging nvim config
use {
"tweekmonster/startuptime.vim",
cmd = { "StartupTime" },
cmd = {"StartupTime"},
}
-- luacheck: pop

View File

@ -1,4 +1,5 @@
-- TODO: Determine if keeping this
--[[
local function config_compe()
require("compe").setup{
enabled = true,
@ -14,6 +15,7 @@ local function config_compe()
},
}
end
--]]
-- TODO: Some issue with tags completion maybe compe is better?
local function config_complete()

View File

@ -1,4 +1,5 @@
-- Utils taken from https://github.com/zzzeyez/dots/blob/master/nvim/lua/utils.lua
-- luacheck: globals packer_plugins
local M = {}
-- Key mapping
@ -89,4 +90,9 @@ function M.require_with_local(name)
return rmod
end
-- Returns whether or not packer plugin is loaded
function M.is_plugin_loaded(name)
return _G["packer_plugins"] and packer_plugins[name] and packer_plugins[name].loaded
end
return M