From 72d8698ecb73409aaa1feef336a958d6a87c4411 Mon Sep 17 00:00:00 2001 From: cg8936 Date: Tue, 12 Aug 2025 08:51:16 -0400 Subject: [PATCH] fixing some issues --- lua/cargdev/core/init.lua | 29 +++++++++------- lua/cargdev/core/keymaps/general.lua | 50 ++++++++++++++++++++++------ lua/cargdev/plugins/ideaMap.lua | 3 +- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/lua/cargdev/core/init.lua b/lua/cargdev/core/init.lua index 37cf3cb..f641df9 100644 --- a/lua/cargdev/core/init.lua +++ b/lua/cargdev/core/init.lua @@ -1,40 +1,45 @@ --- Load compatibility layer first + +-- ============================================================================= +-- cargdev/core/init.lua +-- Main core initialization for cargdev Neovim config +-- ============================================================================= + +-- 1. Compatibility Layer require("cargdev.core.compatibility").setup() +-- 2. Core Options and Keymaps require("cargdev.core.options") require("cargdev.core.keymaps") --- Load all Lua files inside `cargdev/core/function/` AFTER plugins are loaded +-- 3. Utility: Load all Lua files inside `cargdev/core/function/` AFTER plugins are loaded local function load_functions() local function_path = vim.fn.stdpath("config") .. "/lua/cargdev/core/function" local scan = vim.fn.globpath(function_path, "*.lua", false, true) - for _, file in ipairs(scan) do local module_name = "cargdev.core.function." .. file:match("([^/]+)%.lua$") local success, err = pcall(require, module_name) - if not success then vim.notify("Error loading function module: " .. module_name .. "\n" .. err, vim.log.levels.ERROR) end end end --- Defer function loading until after plugins are loaded -vim.api.nvim_create_autocmd("User", { - pattern = "LazyDone", +-- 4. Fix: Force filetype detection on BufRead (fix for nvim-tree/plain text issue) +vim.api.nvim_create_autocmd("BufRead", { + pattern = "*", callback = function() - -- Load all functions - load_functions() + vim.cmd("filetype detect") end, - once = true, }) --- Fallback: also try to load on VimEnter if LazyDone doesn't fire +-- 5. Load functions immediately +load_functions() + +-- 6. Fallback: also try to load on VimEnter if LazyDone doesn't fire vim.api.nvim_create_autocmd("VimEnter", { callback = function() -- Wait a bit for plugins to load vim.defer_fn(function() - -- Load functions load_functions() end, 200) end, diff --git a/lua/cargdev/core/keymaps/general.lua b/lua/cargdev/core/keymaps/general.lua index 230102d..8e2c475 100644 --- a/lua/cargdev/core/keymaps/general.lua +++ b/lua/cargdev/core/keymaps/general.lua @@ -19,19 +19,49 @@ keymap.set("n", "x", '"_x', opts) -- Delete character without copying into regis keymap.set("n", "Q", ":qa!", { desc = "Quit all" }) -- Put this in your init.lua -local vault_path = "/Users/carlos/Nextcloud/ObsidianVault" +local vault_path = vim.env.IDEA_DIR + + local function follow_obsidian_link() - -- grab the token under cursor, clean obsidian syntax - local raw = vim.fn.expand("") - raw = raw:gsub("^!%[%[", "[[") -- strip leading ! from embeds - local link = raw:gsub("%[%[", ""):gsub("%]%]", "") + -- Extract the full [[...]] link from the current line under/around the cursor + local line = vim.api.nvim_get_current_line() + local col = vim.fn.col('.') + local start_idx, end_idx, raw + -- Search for all [[...]] in the line, pick the one under/around the cursor + local i = 1 + while true do + local s, e = line:find('%[%[.-%]%]', i) + if not s then break end + if col >= s and col <= e + 1 then + start_idx, end_idx = s, e + break + end + i = e + 1 + end + if not start_idx then + vim.notify('No [[link]] under cursor', vim.log.levels.WARN) + return + end + raw = line:sub(start_idx, end_idx) + raw = raw:gsub('^!%[%[', '[[') -- strip leading ! from embeds + local link = raw:gsub('%[%[', ''):gsub('%]%]', '') - -- split off alias and heading - local base, alias = link:match("^(.-)|(.+)$") - link = base or link - local fname, heading = link:match("^(.-)#(.+)$") - link = fname or link + -- split off alias (|) and heading (#) only after extracting the full link + local alias + local heading + -- first, split off alias if present + local pipe_idx = link:find("|", 1, true) + if pipe_idx then + alias = link:sub(pipe_idx + 1) + link = link:sub(1, pipe_idx - 1) + end + -- then, split off heading if present + local hash_idx = link:find("#", 1, true) + if hash_idx then + heading = link:sub(hash_idx + 1) + link = link:sub(1, hash_idx - 1) + end -- normalize spaces link = link:gsub("\\ ", " "):gsub("^%s+", ""):gsub("%s+$", "") diff --git a/lua/cargdev/plugins/ideaMap.lua b/lua/cargdev/plugins/ideaMap.lua index 8c47d7b..92cbba8 100644 --- a/lua/cargdev/plugins/ideaMap.lua +++ b/lua/cargdev/plugins/ideaMap.lua @@ -1,5 +1,4 @@ return { - --[[dir = "/Volumes/Carlos_SSD/Documents/projects/ideaDrop",]] "CarGDev/ideadrop.nvim", name = "ideaDrop", dependencies = { @@ -8,7 +7,7 @@ return { }, config = function() require("ideaDrop").setup({ - idea_dir = "/Users/carlos/Nextcloud/ObsidianVault", + idea_dir = vim.env.IDEA_DIR, }) -- Set up convenient keymaps for ideaDrop