diff --git a/.config/nvim/lua/lazyvim/plugins/lsp/init.lua b/.config/nvim/lua/lazyvim/plugins/lsp/init.lua index ed9eb97..bd89978 100644 --- a/.config/nvim/lua/lazyvim/plugins/lsp/init.lua +++ b/.config/nvim/lua/lazyvim/plugins/lsp/init.lua @@ -33,7 +33,7 @@ return { }, config = function(plugin, opts) -- setup formatting and keymaps - require("lazyvim.functions").on_attach(function(client, buffer) + require("lazyvim.utils").on_attach(function(client, buffer) require("lazyvim.plugins.lsp.format").on_attach(client, buffer) require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer) require("lazyvim.plugins.lsp.misc").on_attach(client, buffer) diff --git a/.config/nvim/lua/lazyvim/plugins/neorg.lua b/.config/nvim/lua/lazyvim/plugins/neorg.lua index 5ee8227..5fb3255 100644 --- a/.config/nvim/lua/lazyvim/plugins/neorg.lua +++ b/.config/nvim/lua/lazyvim/plugins/neorg.lua @@ -1,7 +1,7 @@ return { "nvim-neorg/neorg", - cmd = "Neorg", - event = "BufEnter *.norg", + -- event = "BufEnter *.norg", + event = "VeryLazy", dependencies = "nvim-treesitter", build = ":Neorg sync-parsers", opts = { @@ -29,8 +29,12 @@ return { }, }, -- keys = { - -- { "nn", "Neorg", desc = "Open Neorg" }, - -- { "nj", "Neorg journal", desc = "Journal" }, - -- { "nw", "Neorg workspace", desc = "Workspace" }, + -- { + -- "nw", + -- function() + -- require("lazyvim.utils.neorg").workspace_switcher() + -- end, + -- desc = "Workspace", + -- }, -- }, } diff --git a/.config/nvim/lua/lazyvim/plugins/telescope.lua b/.config/nvim/lua/lazyvim/plugins/telescope.lua index 7b9f07c..04806fc 100644 --- a/.config/nvim/lua/lazyvim/plugins/telescope.lua +++ b/.config/nvim/lua/lazyvim/plugins/telescope.lua @@ -1,4 +1,4 @@ -local util = require("lazyvim.functions") +local util = require("lazyvim.utils") return { { diff --git a/.config/nvim/lua/lazyvim/plugins/utility.lua b/.config/nvim/lua/lazyvim/plugins/utility.lua index 542620e..1527dc9 100644 --- a/.config/nvim/lua/lazyvim/plugins/utility.lua +++ b/.config/nvim/lua/lazyvim/plugins/utility.lua @@ -220,7 +220,7 @@ return { "SmiteshP/nvim-navic", init = function() vim.g.navic_silence = true - require("lazyvim.functions").on_attach(function(client, buffer) + require("lazyvim.utils").on_attach(function(client, buffer) if client.server_capabilities.documentSymbolProvider then require("nvim-navic").attach(client, buffer) end diff --git a/.config/nvim/lua/lazyvim/plugins/whichkey.lua b/.config/nvim/lua/lazyvim/plugins/whichkey.lua index 1dc18af..a5ce65e 100644 --- a/.config/nvim/lua/lazyvim/plugins/whichkey.lua +++ b/.config/nvim/lua/lazyvim/plugins/whichkey.lua @@ -40,7 +40,7 @@ return { }, config = function(_, opts) local whichkey = require("which-key") - local Util = require("lazyvim.functions") + local utils = require("lazyvim.utils") whichkey.setup(opts) @@ -79,7 +79,12 @@ return { name = "+neorg", n = { "Neorg", "Open Neorg" }, j = { "Neorg journal", "Open Neorg Journal" }, - w = { "Neorg workspace", "Open Neorg Workspace" }, + w = { + function() + require("lazyvim.utils.neorg").workspace_switcher() + end, + "Workspace Switcher", + }, }, f = { @@ -87,13 +92,13 @@ return { n = { "enew", "New File" }, t = { function() - Util.float_term(nil, { cwd = Util.get_root() }) + utils.float_term(nil, { cwd = utils.get_root() }) end, "Terminal (rood dir)", }, T = { function() - Util.float_term() + utils.float_term() end, "Terminal (cwd)", }, @@ -136,33 +141,33 @@ return { }, s = { function() - Util.toggle("spell") + utils.toggle("spell") end, "Toggle spelling", }, w = { function() - Util.toggle("wrap") + utils.toggle("wrap") end, "Toggle word wrap", }, n = { function() - Util.toggle("relativenumber", true) - Util.toggle("number") + utils.toggle("relativenumber", true) + utils.toggle("number") end, "Toggle line numbers", }, d = { function() - Util.toggle_diagnostics() + utils.toggle_diagnostics() end, "Toggle Diagnostics", }, c = { function() local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 - Util.toggle("conceallevel", false, { 0, conceallevel }) + utils.toggle("conceallevel", false, { 0, conceallevel }) end, "Toggle conceal", }, @@ -172,13 +177,13 @@ return { name = "+git", g = { function() - Util.float_term({ "lazygit" }) + utils.float_term({ "lazygit" }) end, "Lazygit (cwd)", }, G = { function() - Util.float_term({ "lazygit" }, { cwd = Util.get_root() }) + utils.float_term({ "lazygit" }, { cwd = utils.get_root() }) end, "Lazygit (root dir)", }, diff --git a/.config/nvim/lua/lazyvim/functions.lua b/.config/nvim/lua/lazyvim/utils/init.lua similarity index 100% rename from .config/nvim/lua/lazyvim/functions.lua rename to .config/nvim/lua/lazyvim/utils/init.lua diff --git a/.config/nvim/lua/lazyvim/utils/neorg.lua b/.config/nvim/lua/lazyvim/utils/neorg.lua new file mode 100644 index 0000000..d9cc346 --- /dev/null +++ b/.config/nvim/lua/lazyvim/utils/neorg.lua @@ -0,0 +1,84 @@ +local themes = require("telescope.themes") +local pickers = require("telescope.pickers") +local finders = require("telescope.finders") +local actions = require("telescope.actions") +local action_set = require("telescope.actions.set") +local state = require("telescope.actions.state") +local conf = require("telescope.config").values +local previewers = require("telescope.previewers") + +local neorg_loaded, _ = pcall(require, "neorg.modules") + +assert(neorg_loaded, "Neorg is not loaded - please make sure to load Neorg first") + +local ns = vim.api.nvim_create_namespace("neorg-tele-workspace-preview") + +local workspaces + +local M = {} + +function M.workspace_switcher(options) + if not workspaces then + workspaces = {} + + local workspaces_raw = neorg.modules.get_module("core.norg.dirman").get_workspaces() + for name, path in pairs(workspaces_raw) do + table.insert(workspaces, { name = name, path = path }) + end + end + + local opts = options + or themes.get_dropdown({ + border = true, + layout_config = { + prompt_position = "top", + }, + }) + + pickers + .new(opts, { + prompt_title = "Switch Workspace", + preview_title = "Details", + results_title = "Workspaces", + finder = finders.new_table({ + results = workspaces, + entry_maker = function(ws) + return { + value = ws, + display = ws.name, + ordinal = ws.name, + } + end, + }), + sorter = conf.generic_sorter(opts), + previewer = previewers.new_buffer_previewer({ + define_preview = function(self, entry, status) + local workspace = entry.value + local lines = {} + table.insert(lines, "Path:") + table.insert(lines, workspace.path) + table.insert(lines, "Files:") + local files = neorg.modules.get_module("core.norg.dirman").get_norg_files(workspace.name) + for _, file in ipairs(files) do + table.insert(lines, file) + end + vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, lines) + vim.api.nvim_buf_add_highlight(self.state.bufnr, ns, "Special", 0, 0, -1) + vim.api.nvim_buf_add_highlight(self.state.bufnr, ns, "Special", 2, 0, -1) + end, + }), + attach_mappings = function(prompt_bufnr) + action_set.select:replace(function() + local entry = state.get_selected_entry() + actions.close(prompt_bufnr) + if entry then + neorg.modules.get_module("core.norg.dirman").open_workspace(entry.value.name) + end + end) + return true + end, + }) + :find() +end + +return M diff --git a/.config/nvim/lua/lazyvim/teletest.lua b/.config/nvim/lua/lazyvim/utils/teletest.lua similarity index 76% rename from .config/nvim/lua/lazyvim/teletest.lua rename to .config/nvim/lua/lazyvim/utils/teletest.lua index 937625c..de58253 100644 --- a/.config/nvim/lua/lazyvim/teletest.lua +++ b/.config/nvim/lua/lazyvim/utils/teletest.lua @@ -4,14 +4,14 @@ local actions = require("telescope.actions") local action_state = require("telescope.actions.state") local conf = require("telescope.config").values -local prompt = function(opts, prompt, options, callback) - opts = opts or {} +local prompt = function(opts, prompt, inputs, callback) + opts = opts or require("telescope.themes").get_dropdown({}) pickers .new(opts, { prompt_title = prompt, finder = finders.new_table({ - results = options, - entry_marker = function(entry) + results = inputs, + entry_maker = function(entry) return { value = entry, display = entry[1], @@ -24,7 +24,7 @@ local prompt = function(opts, prompt, options, callback) actions.select_default:replace(function() actions.close(promnt_bufnr) local selection = action_state.get_selected_entry() - vim.notify(selection[1]) + vim.notify(selection) end) return true end, @@ -32,7 +32,7 @@ local prompt = function(opts, prompt, options, callback) :find() end -prompt(require("telescope.themes").get_dropdown({}), "test", { +prompt(nil, "test", { { "one", "1" }, { "two", "2" }, }, nil)