From 631de5358af9aa035967bd68b9f3ae45f98ed591 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 22 Dec 2024 15:35:34 +0100 Subject: [PATCH] Small tweaks --- lua/taken/utils/on_attach.lua | 2 -- lua/taken/utils/themefuncs.lua | 15 ++++++++++++++- lua/taken/utils/themes.lua | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lua/taken/utils/on_attach.lua b/lua/taken/utils/on_attach.lua index 2473bf6..862c06d 100644 --- a/lua/taken/utils/on_attach.lua +++ b/lua/taken/utils/on_attach.lua @@ -1,5 +1,3 @@ ---- @param client string ---- @param bufnr number local on_attach = function(client, bufnr) local function opts(desc) if desc then diff --git a/lua/taken/utils/themefuncs.lua b/lua/taken/utils/themefuncs.lua index fe7d840..4316a6e 100644 --- a/lua/taken/utils/themefuncs.lua +++ b/lua/taken/utils/themefuncs.lua @@ -6,8 +6,9 @@ local prefsFile = configDir .. "/lua/taken/prefs.lua" local getAllThemes = function() vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false }) - local colors = vim.fn.globpath(vim.o.rtp, "colors/*", 1, 1) + local colors = vim.fn.globpath(vim.o.rtp, "colors/*", true, 1) local dataDir = vim.fn.stdpath("data") + ---@diagnostic disable-next-line: param-type-mismatch local newpath = string.gsub(dataDir, "%-", "%%-") local themes = {} @@ -35,10 +36,22 @@ end local change_theme = function(old, new) -- function from nvchad local file = io.open(prefsFile, "r") + + if file == nil then + vim.notify("Could not open " .. prefsFile, 4) + return + end + local added_pattern = string.gsub(old, "-", "%%-") local new_content = file:read("*all"):gsub(added_pattern, new) file = io.open(prefsFile, "w") + + if file == nil then + vim.notify("Could not open " .. prefsFile, 4) + return + end + file:write(new_content) file:close() end diff --git a/lua/taken/utils/themes.lua b/lua/taken/utils/themes.lua index ade70b1..29196ef 100644 --- a/lua/taken/utils/themes.lua +++ b/lua/taken/utils/themes.lua @@ -24,7 +24,7 @@ function M.themeselector(opts) actions.select_default:replace(function() actions.close(prompt_bufnr) local selection = action_state.get_selected_entry() - applytofile(selection.value, prefsFile) + applytofile(selection.value) end) -- action_set.shift_selection:enhance({ -- post = function()