From cb98f5b89af54bc677886cc13e6b303ad863b9b5 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Wed, 18 Sep 2024 15:25:07 -0700 Subject: [PATCH 01/16] remove lazy-lock.json --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 005b535b606..8a192cab54d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ test.sh nvim spell/ -lazy-lock.json From cf5d940f8a140cf79cc51f7776a95858def8e71b Mon Sep 17 00:00:00 2001 From: root Date: Wed, 6 Nov 2024 13:03:36 -0800 Subject: [PATCH 02/16] clangd naitive --- init.lua | 3 +++ lazy-lock.json | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 lazy-lock.json diff --git a/init.lua b/init.lua index ea86b792abe..0feb197635a 100644 --- a/init.lua +++ b/init.lua @@ -662,6 +662,9 @@ require('lazy').setup({ end, }, } + require('lspconfig').clangd.setup{ + capabilities = capabilities, +} end, }, diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 00000000000..277cc5e158f --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,27 @@ +{ + "LuaSnip": { "branch": "master", "commit": "29417eea5b7c4b6beda105ced072855101d9680e" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "conform.nvim": { "branch": "master", "commit": "d28ccf945374edd9f1c34a82f6c22261dbd8ab98" }, + "fidget.nvim": { "branch": "main", "commit": "e2a175c2abe2d4f65357da1c98c59a5cfb2b543f" }, + "gitsigns.nvim": { "branch": "main", "commit": "4daf7022f1481edf1e8fb9947df13bb07c18e89a" }, + "lazy.nvim": { "branch": "main", "commit": "077102c5bfc578693f12377846d427f49bc50076" }, + "lazydev.nvim": { "branch": "main", "commit": "d5800897d9180cea800023f2429bce0a94ed6064" }, + "luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "4d0e5b49363cac187326998b96aa6a2884e0e89b" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, + "mini.nvim": { "branch": "main", "commit": "c8bc67a35e627908da644c5f8cd26b3f987f2627" }, + "nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" }, + "nvim-lspconfig": { "branch": "master", "commit": "bc6ada4b0892b7f10852c0b8ca7209fd39a6d754" }, + "nvim-treesitter": { "branch": "master", "commit": "7dc8aabe86db8c2f23520e8334f7584f83e84342" }, + "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, + "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, + "tokyonight.nvim": { "branch": "main", "commit": "ce91ba480070c95f40753e4663e32b4632ac6db3" }, + "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }, + "which-key.nvim": { "branch": "main", "commit": "8badb359f7ab8711e2575ef75dfe6fbbd87e4821" } +} From 390dadb7b6a5f34b031dd426d328b64eb104064d Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Tue, 18 Feb 2025 21:52:10 -0800 Subject: [PATCH 03/16] lets try this again --- init.lua | 4 +++- lazy-lock.json | 28 ++++++++++++++++++++++++++++ lua/custom/plugins/wiki.lua | 30 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 lazy-lock.json create mode 100644 lua/custom/plugins/wiki.lua diff --git a/init.lua b/init.lua index ea86b792abe..f8d47a18744 100644 --- a/init.lua +++ b/init.lua @@ -190,6 +190,8 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the right win vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) +vim.api.nvim_set_keymap('c', '%%', "=expand('%:h').'/'", { noremap = true, silent = true }) + -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` @@ -929,7 +931,7 @@ require('lazy').setup({ -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 00000000000..5ce91b0902d --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,28 @@ +{ + "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "conform.nvim": { "branch": "master", "commit": "a6f5bdb78caa305496357d17e962bbc4c0b392e2" }, + "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, + "gitsigns.nvim": { "branch": "main", "commit": "6668f379ca634c36b8e11453118590b91bf8b295" }, + "lazy.nvim": { "branch": "main", "commit": "e5e9bf48211a13d9ee6c1077c88327c49c1ab4a0" }, + "lazydev.nvim": { "branch": "main", "commit": "a1b78b2ac6f978c72e76ea90ae92a94edf380cfc" }, + "luvit-meta": { "branch": "main", "commit": "1df30b60b1b4aecfebc785aa98943db6c6989716" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "374c78d3ebb5c53f43ea6bd906b6587b5e899b9e" }, + "mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" }, + "mini.nvim": { "branch": "main", "commit": "a84b7e555fe382c1859e6ca46b4983c822a1f77f" }, + "nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" }, + "nvim-lspconfig": { "branch": "master", "commit": "1110787f1b464888c59a044c48c5119d14078044" }, + "nvim-treesitter": { "branch": "master", "commit": "1a6e42bb8c5c23d8e2c0acb842dcacac5ee06761" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "2a5ceff981501cff8f46871d5402cd3378a8ab6a" }, + "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" }, + "tokyonight.nvim": { "branch": "main", "commit": "057ef5d260c1931f1dffd0f052c685dcd14100a3" }, + "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }, + "vimwiki": { "branch": "dev", "commit": "72792615e739d0eb54a9c8f7e0a46a6e2407c9e8" }, + "which-key.nvim": { "branch": "main", "commit": "5bf7a73fe851896d5ac26d313db849bf00f45b78" } +} diff --git a/lua/custom/plugins/wiki.lua b/lua/custom/plugins/wiki.lua new file mode 100644 index 00000000000..16020c07429 --- /dev/null +++ b/lua/custom/plugins/wiki.lua @@ -0,0 +1,30 @@ +return { + 'vimwiki/vimwiki', + keys = { + -- "ww", + -- "wt", + -- { "wz", "Vimwiki2HTML", desc = "Vimwiki2HTML" }, + -- { "wx", "VimwikiAll2HTML", desc = "VimwikiAll2HTML" }, + }, + init = function() + vim.g.vimwiki_list = { + { + path = '~/cavelazquez8-wiki/', + syntax = 'markdown', + ext = '.md', + -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", + -- auto_diary_index = 1, + }, + } + -- vim.g.vimwiki_ext2syntax = { + -- [".md"] = "markdown", + -- [".markdown"] = "markdown", + -- [".mdown"] = "markdown", + -- } + -- prevent md files from being coverted to vimwiki files + vim.g.vimwiki_global_ext = 0 + -- Add extensions to link + -- vim.g.vimwiki_markdown_link_ext = 1 + -- vim.g.vimwiki_filetypes = { "markdown" } + end, +} From d249ac9f0a4a2c02e2eb82c2bcd610f8f6156ba1 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Tue, 18 Feb 2025 22:22:59 -0800 Subject: [PATCH 04/16] lazylock --- lazy-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lazy-lock.json b/lazy-lock.json index 5ce91b0902d..0fab4b6929d 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,6 +1,7 @@ { "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, + "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "conform.nvim": { "branch": "master", "commit": "a6f5bdb78caa305496357d17e962bbc4c0b392e2" }, @@ -8,7 +9,6 @@ "gitsigns.nvim": { "branch": "main", "commit": "6668f379ca634c36b8e11453118590b91bf8b295" }, "lazy.nvim": { "branch": "main", "commit": "e5e9bf48211a13d9ee6c1077c88327c49c1ab4a0" }, "lazydev.nvim": { "branch": "main", "commit": "a1b78b2ac6f978c72e76ea90ae92a94edf380cfc" }, - "luvit-meta": { "branch": "main", "commit": "1df30b60b1b4aecfebc785aa98943db6c6989716" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" }, "mason-tool-installer.nvim": { "branch": "main", "commit": "374c78d3ebb5c53f43ea6bd906b6587b5e899b9e" }, "mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" }, From 707eb0e1b3cdf293f4c5d7752bb93b91f6b139c8 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Wed, 19 Feb 2025 01:41:58 -0800 Subject: [PATCH 05/16] vimwiki comments --- lua/custom/plugins/wiki.lua | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lua/custom/plugins/wiki.lua b/lua/custom/plugins/wiki.lua index 16020c07429..8f8e9057346 100644 --- a/lua/custom/plugins/wiki.lua +++ b/lua/custom/plugins/wiki.lua @@ -1,7 +1,7 @@ return { 'vimwiki/vimwiki', keys = { - -- "ww", + 'ww', -- "wt", -- { "wz", "Vimwiki2HTML", desc = "Vimwiki2HTML" }, -- { "wx", "VimwikiAll2HTML", desc = "VimwikiAll2HTML" }, @@ -12,19 +12,22 @@ return { path = '~/cavelazquez8-wiki/', syntax = 'markdown', ext = '.md', + -- Custom Markdown to HTML converter -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", - -- auto_diary_index = 1, + -- Auto update diary index + auto_diary_index = 1, }, } + -- Treat markdown files as markdown files, not wiki files -- vim.g.vimwiki_ext2syntax = { - -- [".md"] = "markdown", - -- [".markdown"] = "markdown", - -- [".mdown"] = "markdown", - -- } + -- ['.md'] = 'markdown', + -- ['.markdown'] = 'markdown', + -- ['.mdown'] = 'markdown', + --} -- prevent md files from being coverted to vimwiki files vim.g.vimwiki_global_ext = 0 - -- Add extensions to link - -- vim.g.vimwiki_markdown_link_ext = 1 - -- vim.g.vimwiki_filetypes = { "markdown" } + -- Add .md extension to link + vim.g.vimwiki_markdown_link_ext = 1 + -- vim.g.vimwiki_filetypes = { 'markdown' } end, } From 78ebb23bacc7a74787e8f8aeb581abe7733c5a82 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Thu, 20 Feb 2025 23:18:44 -0800 Subject: [PATCH 06/16] Open markdown file in Obsidian from neovim. Diary template autocmd. Enable custom plugins. Wiki.lua modif 1. : --- init.lua | 116 +++++++++++++++++++++++++++++++++++- lua/custom/plugins/wiki.lua | 4 +- 2 files changed, 118 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index cd5cb5a9cf5..17fe6fa093a 100644 --- a/init.lua +++ b/init.lua @@ -190,6 +190,114 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the lower win vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) vim.api.nvim_set_keymap('c', '%%', "=expand('%:h').'/'", { noremap = true, silent = true }) +-- Opening markdown file from neovim to Obsidian +-- Default vault settings +local default_vault_name = 'cavelazquez8-wiki' +local default_vault_path = '/home/cavelazquez8/cavelazquez8-wiki/' + +-- Ensure the temp directory exists within your vault +local temp_dir = default_vault_path .. '_temp_preview/' +os.execute("mkdir -p '" .. temp_dir .. "'") + +-- Function to URL-encode strings +local function url_encode(str) + local handle = io.popen('python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))" ' .. "'" .. str .. "'") + local result = handle:read '*a' + handle:close() + return result:gsub('\n', '') +end + +-- Function to open any markdown file in Obsidian +local function open_in_obsidian() + local filepath = vim.fn.expand '%:p' + + if filepath == '' then + print 'No file to open!' + return + end + + -- Check if file is markdown + if not filepath:match '%.md$' then + print 'Not a markdown file. Only markdown files can be opened in Obsidian.' + return + end + + -- Determine if file is inside default vault or needs to be symlinked + local vault_name = default_vault_name + local relative_path + + if filepath:find('^' .. vim.pesc(default_vault_path)) then + -- File is inside the vault + relative_path = filepath:gsub('^' .. vim.pesc(default_vault_path), '') + else + -- File is outside the vault - create a symlink + local file_basename = vim.fn.fnamemodify(filepath, ':t') + local temp_link_name = '_temp_preview/' .. file_basename + local temp_link_path = default_vault_path .. temp_link_name + + -- Remove any existing link + os.execute("rm -f '" .. temp_link_path .. "'") + + -- Create the symlink + os.execute("ln -sf '" .. filepath .. "' '" .. temp_link_path .. "'") + + relative_path = temp_link_name + + -- Register autocmd to clean up the symlink when the buffer is closed + vim.api.nvim_create_autocmd({ 'BufDelete', 'BufWipeout' }, { + buffer = vim.api.nvim_get_current_buf(), + callback = function() + os.execute("rm -f '" .. temp_link_path .. "'") + end, + }) + end + + -- Create and open the Obsidian URI + local encoded_path = url_encode(relative_path) + local uri = 'obsidian://open?vault=' .. vault_name .. '&file=' .. encoded_path + + print('Opening in Obsidian: ' .. relative_path) + vim.fn.jobstart({ 'xdg-open', uri }, { detach = true }) +end + +-- Function to close Obsidian +local function close_obsidian() + os.execute 'pkill -9 -f obsidian' + print 'Closed Obsidian instance(s).' +end + +-- Create user commands and key mappings +vim.api.nvim_create_user_command('OpenInObsidian', open_in_obsidian, {}) +vim.api.nvim_create_user_command('CloseObsidian', close_obsidian, {}) +vim.keymap.set('n', 'o', open_in_obsidian, { noremap = true, silent = true }) +vim.keymap.set('n', 'co', close_obsidian, { noremap = true, silent = true }) + +-- Enable autoread so that if the file changes externally (or via Obsidian) Neovim reloads it +vim.o.autoread = true +vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { + callback = function() + vim.cmd 'checktime' + end, +}) + +-- Use a trap-based approach for VimLeave to ensure it runs before Neovim fully exits +vim.api.nvim_create_autocmd('UIEnter', { + once = true, + callback = function() + -- Get Neovim's PID + local nvim_pid = vim.fn.getpid() + + -- Create a trap in the parent shell that will kill Obsidian when Neovim exits + os.execute(string.format("trap 'pkill -9 -f obsidian' EXIT && " .. 'while kill -0 %d 2>/dev/null; do sleep 0.01; done & disown', nvim_pid)) + end, +}) + +-- Cleanup temp directory on exit +vim.api.nvim_create_autocmd('VimLeavePre', { + callback = function() + os.execute("rm -rf '" .. temp_dir .. "'/*") + end, +}) -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` @@ -205,6 +313,12 @@ vim.api.nvim_create_autocmd('TextYankPost', { end, }) +vim.api.nvim_exec( + [[ + autocmd BufNewFile ~/cavelazquez8-wiki/diary/*.md :silent 0r !~/.vim/autoload/vimwiki/generate-vimwiki-diary-template '%' + ]], + false +) -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' @@ -993,7 +1107,7 @@ require('lazy').setup({ -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! -- In normal mode type `sh` then write `lazy.nvim-plugin` diff --git a/lua/custom/plugins/wiki.lua b/lua/custom/plugins/wiki.lua index 8f8e9057346..1d80d68d9d3 100644 --- a/lua/custom/plugins/wiki.lua +++ b/lua/custom/plugins/wiki.lua @@ -6,6 +6,7 @@ return { -- { "wz", "Vimwiki2HTML", desc = "Vimwiki2HTML" }, -- { "wx", "VimwikiAll2HTML", desc = "VimwikiAll2HTML" }, }, + cmd = 'VimwikiIndex', -- Add this command to load Vimwiki init = function() vim.g.vimwiki_list = { { @@ -16,9 +17,10 @@ return { -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", -- Auto update diary index auto_diary_index = 1, + links_space_char = '-', -- Replace spaces with hyphens in links }, } - -- Treat markdown files as markdown files, not wiki files + -- Register markdown files -- vim.g.vimwiki_ext2syntax = { -- ['.md'] = 'markdown', -- ['.markdown'] = 'markdown', From 6a5d3c5870d7a59d09d268202b7c9d62981d5538 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Fri, 21 Feb 2025 00:25:40 -0800 Subject: [PATCH 07/16] feat: add Obsidian vault integration with persistent config Adds functionality to manage multiple Obsidian vaults in Neovim with: - JSON-based config persistence - Which-key integrated commands - Vault management (add/remove/list) - Auto-cleanup of temp files --- init.lua | 266 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 220 insertions(+), 46 deletions(-) diff --git a/init.lua b/init.lua index 17fe6fa093a..0492450b1e2 100644 --- a/init.lua +++ b/init.lua @@ -190,14 +190,65 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the lower win vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) vim.api.nvim_set_keymap('c', '%%', "=expand('%:h').'/'", { noremap = true, silent = true }) --- Opening markdown file from neovim to Obsidian --- Default vault settings -local default_vault_name = 'cavelazquez8-wiki' -local default_vault_path = '/home/cavelazquez8/cavelazquez8-wiki/' --- Ensure the temp directory exists within your vault -local temp_dir = default_vault_path .. '_temp_preview/' -os.execute("mkdir -p '" .. temp_dir .. "'") +-- Configuration file path +local config_path = vim.fn.expand '~/.config/nvim/obsidian_vaults.json' + +-- Initialize vaults table +local vaults = {} + +-- Pre-declare functions that are used before their definition +local save_vault_configs + +-- Function to save vault configurations +save_vault_configs = function() + local f = io.open(config_path, 'w') + if f then + f:write(vim.json.encode(vaults)) + f:close() + end +end + +-- Function to load vault configurations +local function load_vault_configs() + -- Check if config file exists + local f = io.open(config_path, 'r') + if f then + local content = f:read '*all' + f:close() + + -- Parse JSON content + local ok, parsed = pcall(vim.json.decode, content) + if ok then + vaults = parsed + end + end + + -- Ensure at least one default vault exists + if #vaults == 0 then + vaults = { + { + name = 'cavelazquez8-wiki', + path = '/home/cavelazquez8/cavelazquez8-wiki/', + }, + } + -- Save the default configuration + save_vault_configs() + end +end + +-- Load existing configurations at startup +load_vault_configs() + +-- Function to find which vault a file belongs to +local function find_containing_vault(filepath) + for _, vault in ipairs(vaults) do + if filepath:find('^' .. vim.pesc(vault.path)) then + return vault, filepath:gsub('^' .. vim.pesc(vault.path), '') + end + end + return nil, nil +end -- Function to URL-encode strings local function url_encode(str) @@ -207,6 +258,65 @@ local function url_encode(str) return result:gsub('\n', '') end +-- Function to close Obsidian +local function close_obsidian() + os.execute 'pkill -9 -f obsidian' + print 'Closed Obsidian instance(s).' +end + +-- Improved function to add a new vault configuration +function AddObsidianVault(name, path) + -- Ensure path ends with a slash + if not path:match '/$' then + path = path .. '/' + end + + -- Check if vault already exists + for _, vault in ipairs(vaults) do + if vault.name == name then + print("Vault with name '" .. name .. "' already exists!") + return + end + if vault.path == path then + print("Vault with path '" .. path .. "' already exists!") + return + end + end + + -- Add to vaults table + table.insert(vaults, { name = name, path = path }) + + -- Create temp directory + local temp_dir = path .. '_temp_preview/' + os.execute("mkdir -p '" .. temp_dir .. "'") + + -- Save updated configuration + save_vault_configs() + + print('Added Obsidian vault: ' .. name .. ' at ' .. path) +end + +-- Function to remove a vault configuration +function RemoveObsidianVault(name) + for i, vault in ipairs(vaults) do + if vault.name == name then + table.remove(vaults, i) + save_vault_configs() + print('Removed Obsidian vault: ' .. name) + return + end + end + print("Vault '" .. name .. "' not found!") +end + +-- Function to list all configured vaults +function ListObsidianVaults() + print 'Configured Obsidian vaults:' + for _, vault in ipairs(vaults) do + print(string.format('- %s: %s', vault.name, vault.path)) + end +end + -- Function to open any markdown file in Obsidian local function open_in_obsidian() local filepath = vim.fn.expand '%:p' @@ -222,18 +332,22 @@ local function open_in_obsidian() return end - -- Determine if file is inside default vault or needs to be symlinked - local vault_name = default_vault_name - local relative_path + -- Find if file belongs to a known vault + local containing_vault, relative_path = find_containing_vault(filepath) + + if containing_vault then + -- File is inside a known vault + local encoded_path = url_encode(relative_path) + local uri = 'obsidian://open?vault=' .. containing_vault.name .. '&file=' .. encoded_path - if filepath:find('^' .. vim.pesc(default_vault_path)) then - -- File is inside the vault - relative_path = filepath:gsub('^' .. vim.pesc(default_vault_path), '') + print("Opening in Obsidian vault '" .. containing_vault.name .. "': " .. relative_path) + vim.fn.jobstart({ 'xdg-open', uri }, { detach = true }) else - -- File is outside the vault - create a symlink + -- File is outside any known vault - create a symlink in the first vault + local default_vault = vaults[1] local file_basename = vim.fn.fnamemodify(filepath, ':t') local temp_link_name = '_temp_preview/' .. file_basename - local temp_link_path = default_vault_path .. temp_link_name + local temp_link_path = default_vault.path .. temp_link_name -- Remove any existing link os.execute("rm -f '" .. temp_link_path .. "'") @@ -241,8 +355,6 @@ local function open_in_obsidian() -- Create the symlink os.execute("ln -sf '" .. filepath .. "' '" .. temp_link_path .. "'") - relative_path = temp_link_name - -- Register autocmd to clean up the symlink when the buffer is closed vim.api.nvim_create_autocmd({ 'BufDelete', 'BufWipeout' }, { buffer = vim.api.nvim_get_current_buf(), @@ -250,29 +362,102 @@ local function open_in_obsidian() os.execute("rm -f '" .. temp_link_path .. "'") end, }) - end - -- Create and open the Obsidian URI - local encoded_path = url_encode(relative_path) - local uri = 'obsidian://open?vault=' .. vault_name .. '&file=' .. encoded_path + -- Open in default vault + local encoded_path = url_encode(temp_link_name) + local uri = 'obsidian://open?vault=' .. default_vault.name .. '&file=' .. encoded_path - print('Opening in Obsidian: ' .. relative_path) - vim.fn.jobstart({ 'xdg-open', uri }, { detach = true }) + print('Opening external file in default Obsidian vault: ' .. temp_link_name) + vim.fn.jobstart({ 'xdg-open', uri }, { detach = true }) + end end --- Function to close Obsidian -local function close_obsidian() - os.execute 'pkill -9 -f obsidian' - print 'Closed Obsidian instance(s).' +-- Create the which-key keymap group +local ok, wk = pcall(require, 'which-key') +if ok then + wk.register { + ['o'] = { + name = 'Obsidian', + o = { open_in_obsidian, 'Open in Obsidian' }, + c = { close_obsidian, 'Close Obsidian' }, + l = { ListObsidianVaults, 'List Vaults' }, + a = { + function() + vim.ui.input({ prompt = 'Vault name: ' }, function(name) + if name then + vim.ui.input({ prompt = 'Vault path: ' }, function(path) + if path then + AddObsidianVault(name, path) + end + end) + end + end) + end, + 'Add Vault', + }, + r = { + function() + vim.ui.input({ prompt = 'Vault name to remove: ' }, function(name) + if name then + RemoveObsidianVault(name) + end + end) + end, + 'Remove Vault', + }, + }, + } +else + -- Fallback keymaps if which-key is not available + local opts = { noremap = true, silent = true } + vim.keymap.set('n', 'oo', open_in_obsidian, opts) + vim.keymap.set('n', 'oc', close_obsidian, opts) + vim.keymap.set('n', 'ol', ListObsidianVaults, opts) + vim.keymap.set('n', 'oa', function() + vim.ui.input({ prompt = 'Vault name: ' }, function(name) + if name then + vim.ui.input({ prompt = 'Vault path: ' }, function(path) + if path then + AddObsidianVault(name, path) + end + end) + end + end) + end, opts) + vim.keymap.set('n', 'or', function() + vim.ui.input({ prompt = 'Vault name to remove: ' }, function(name) + if name then + RemoveObsidianVault(name) + end + end) + end, opts) end --- Create user commands and key mappings +-- Create user commands vim.api.nvim_create_user_command('OpenInObsidian', open_in_obsidian, {}) vim.api.nvim_create_user_command('CloseObsidian', close_obsidian, {}) -vim.keymap.set('n', 'o', open_in_obsidian, { noremap = true, silent = true }) -vim.keymap.set('n', 'co', close_obsidian, { noremap = true, silent = true }) +vim.api.nvim_create_user_command('AddObsidianVault', function(opts) + local args = opts.args + local parts = {} + for part in string.gmatch(args, '%S+') do + table.insert(parts, part) + end + + if #parts ~= 2 then + print 'Usage: AddObsidianVault ' + return + end + + AddObsidianVault(parts[1], parts[2]) +end, { nargs = '+' }) --- Enable autoread so that if the file changes externally (or via Obsidian) Neovim reloads it +vim.api.nvim_create_user_command('RemoveObsidianVault', function(opts) + RemoveObsidianVault(opts.args) +end, { nargs = 1 }) + +vim.api.nvim_create_user_command('ListObsidianVaults', ListObsidianVaults, {}) + +-- Enable autoread vim.o.autoread = true vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { callback = function() @@ -280,25 +465,14 @@ vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { end, }) --- Use a trap-based approach for VimLeave to ensure it runs before Neovim fully exits -vim.api.nvim_create_autocmd('UIEnter', { - once = true, - callback = function() - -- Get Neovim's PID - local nvim_pid = vim.fn.getpid() - - -- Create a trap in the parent shell that will kill Obsidian when Neovim exits - os.execute(string.format("trap 'pkill -9 -f obsidian' EXIT && " .. 'while kill -0 %d 2>/dev/null; do sleep 0.01; done & disown', nvim_pid)) - end, -}) - --- Cleanup temp directory on exit +-- Cleanup temp directories on exit vim.api.nvim_create_autocmd('VimLeavePre', { callback = function() - os.execute("rm -rf '" .. temp_dir .. "'/*") + for _, vault in ipairs(vaults) do + os.execute("rm -rf '" .. vault.path .. "_temp_preview/'*") + end end, }) - -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` From f05aec7bcf8be389067325a81f7e3e1384fa945b Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Fri, 21 Feb 2025 20:22:51 -0800 Subject: [PATCH 08/16] close obsidian when nvim closes --- init.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/init.lua b/init.lua index 0492450b1e2..2ac5a0bbc46 100644 --- a/init.lua +++ b/init.lua @@ -465,12 +465,26 @@ vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { end, }) +-- Use a trap-based approach for VimLeave to ensure it runs before Neovim fully exits +vim.api.nvim_create_autocmd('UIEnter', { + once = true, + callback = function() + -- Get Neovim's PID + local nvim_pid = vim.fn.getpid() + + -- Create a trap in the parent shell that will kill Obsidian when Neovim exits + os.execute(string.format("trap 'pkill -9 -f obsidian' EXIT && " .. 'while kill -0 %d 2>/dev/null; do sleep 0.01; done & disown', nvim_pid)) + end, +}) + -- Cleanup temp directories on exit vim.api.nvim_create_autocmd('VimLeavePre', { callback = function() for _, vault in ipairs(vaults) do os.execute("rm -rf '" .. vault.path .. "_temp_preview/'*") end + -- Also ensure Obsidian is closed + close_obsidian() end, }) -- [[ Basic Autocommands ]] From b046fce3d13a0d906eb78cea446d0f413a509483 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Fri, 21 Feb 2025 22:04:04 -0800 Subject: [PATCH 09/16] speed up closing --- init.lua | 409 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 237 insertions(+), 172 deletions(-) diff --git a/init.lua b/init.lua index e8512bd4f44..1cfc3579b19 100644 --- a/init.lua +++ b/init.lua @@ -190,204 +190,297 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the lower win vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) vim.api.nvim_set_keymap('c', '%%', "=expand('%:h').'/'", { noremap = true, silent = true }) - --- Configuration file path +-- Obsidian Integration +-- Configuration local config_path = vim.fn.expand '~/.config/nvim/obsidian_vaults.json' - --- Initialize vaults table local vaults = {} --- Pre-declare functions that are used before their definition -local save_vault_configs +-- Utility functions +local function is_executable(cmd) + return vim.fn.executable(cmd) == 1 +end + +local function ensure_dir_exists(path) + return vim.fn.mkdir(path, 'p') +end + +local function safe_path(path) + return path:gsub([[\]], [[/]]):gsub('/$', '') .. '/' +end + +-- URL encode a string using either Python or Lua +local function url_encode(str) + if is_executable 'python3' then + local handle = io.popen(string.format('python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))" %q', str)) + if handle then + local result = handle:read '*a' + handle:close() + return result:gsub('\n', '') + end + end + + -- Fallback to basic Lua URL encoding + return str:gsub('[^%w%-%.%_%~]', function(c) + return string.format('%%%02X', string.byte(c)) + end) +end --- Function to save vault configurations -save_vault_configs = function() +-- Vault management functions +local function save_vault_configs() local f = io.open(config_path, 'w') - if f then - f:write(vim.json.encode(vaults)) + if not f then + vim.notify('Failed to save vault configurations', vim.log.levels.ERROR) + return false + end + + local success, encoded = pcall(vim.json.encode, vaults) + if not success then f:close() + vim.notify('Failed to encode vault configurations', vim.log.levels.ERROR) + return false end + + f:write(encoded) + f:close() + return true end --- Function to load vault configurations local function load_vault_configs() - -- Check if config file exists local f = io.open(config_path, 'r') if f then local content = f:read '*all' f:close() - -- Parse JSON content - local ok, parsed = pcall(vim.json.decode, content) - if ok then + local success, parsed = pcall(vim.json.decode, content) + if success and type(parsed) == 'table' then vaults = parsed + return true end end - -- Ensure at least one default vault exists + -- Initialize with default vault if none exists if #vaults == 0 then - vaults = { - { - name = 'cavelazquez8-wiki', - path = '/home/cavelazquez8/cavelazquez8-wiki/', - }, - } - -- Save the default configuration + local default_path = vim.fn.expand '~/obsidian-vault/' + ensure_dir_exists(default_path) + vaults = { { + name = 'default', + path = default_path, + } } save_vault_configs() end + return false end --- Load existing configurations at startup -load_vault_configs() - --- Function to find which vault a file belongs to +-- Find which vault contains a given filepath local function find_containing_vault(filepath) + filepath = safe_path(filepath) for _, vault in ipairs(vaults) do - if filepath:find('^' .. vim.pesc(vault.path)) then - return vault, filepath:gsub('^' .. vim.pesc(vault.path), '') + local vault_path = safe_path(vault.path) + if filepath:find('^' .. vim.pesc(vault_path)) then + return vault, filepath:gsub('^' .. vim.pesc(vault_path), '') end end return nil, nil end --- Function to URL-encode strings -local function url_encode(str) - local handle = io.popen('python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))" ' .. "'" .. str .. "'") - local result = handle:read '*a' - handle:close() - return result:gsub('\n', '') -end - --- Function to close Obsidian -local function close_obsidian() - os.execute 'pkill -9 -f obsidian' - print 'Closed Obsidian instance(s).' -end - --- Improved function to add a new vault configuration -function AddObsidianVault(name, path) - -- Ensure path ends with a slash - if not path:match '/$' then - path = path .. '/' - end - - -- Check if vault already exists - for _, vault in ipairs(vaults) do - if vault.name == name then - print("Vault with name '" .. name .. "' already exists!") - return - end - if vault.path == path then - print("Vault with path '" .. path .. "' already exists!") - return - end - end - - -- Add to vaults table - table.insert(vaults, { name = name, path = path }) - - -- Create temp directory - local temp_dir = path .. '_temp_preview/' - os.execute("mkdir -p '" .. temp_dir .. "'") - - -- Save updated configuration - save_vault_configs() - - print('Added Obsidian vault: ' .. name .. ' at ' .. path) -end - --- Function to remove a vault configuration -function RemoveObsidianVault(name) - for i, vault in ipairs(vaults) do - if vault.name == name then - table.remove(vaults, i) - save_vault_configs() - print('Removed Obsidian vault: ' .. name) - return - end - end - print("Vault '" .. name .. "' not found!") -end - --- Function to list all configured vaults -function ListObsidianVaults() - print 'Configured Obsidian vaults:' - for _, vault in ipairs(vaults) do - print(string.format('- %s: %s', vault.name, vault.path)) - end -end - --- Function to open any markdown file in Obsidian +-- Obsidian interaction functions local function open_in_obsidian() local filepath = vim.fn.expand '%:p' if filepath == '' then - print 'No file to open!' + vim.notify('No file to open!', vim.log.levels.WARN) return end - -- Check if file is markdown if not filepath:match '%.md$' then - print 'Not a markdown file. Only markdown files can be opened in Obsidian.' + vim.notify('Not a markdown file', vim.log.levels.WARN) return end - -- Find if file belongs to a known vault local containing_vault, relative_path = find_containing_vault(filepath) if containing_vault then - -- File is inside a known vault local encoded_path = url_encode(relative_path) - local uri = 'obsidian://open?vault=' .. containing_vault.name .. '&file=' .. encoded_path + local uri = string.format('obsidian://open?vault=%s&file=%s', containing_vault.name, encoded_path) + + vim.notify(string.format("Opening in vault '%s': %s", containing_vault.name, relative_path)) - print("Opening in Obsidian vault '" .. containing_vault.name .. "': " .. relative_path) - vim.fn.jobstart({ 'xdg-open', uri }, { detach = true }) + vim.fn.jobstart({ 'xdg-open', uri }, { + detach = true, + on_exit = function(_, code) + if code ~= 0 then + vim.notify('Failed to open Obsidian', vim.log.levels.ERROR) + end + end, + }) else - -- File is outside any known vault - create a symlink in the first vault + -- Handle external files local default_vault = vaults[1] - local file_basename = vim.fn.fnamemodify(filepath, ':t') - local temp_link_name = '_temp_preview/' .. file_basename - local temp_link_path = default_vault.path .. temp_link_name + if not default_vault then + vim.notify('No default vault configured', vim.log.levels.ERROR) + return + end - -- Remove any existing link - os.execute("rm -f '" .. temp_link_path .. "'") + local temp_dir = safe_path(default_vault.path .. '_temp_preview') + ensure_dir_exists(temp_dir) - -- Create the symlink - os.execute("ln -sf '" .. filepath .. "' '" .. temp_link_path .. "'") + local file_basename = vim.fn.fnamemodify(filepath, ':t') + local temp_link_path = temp_dir .. file_basename - -- Register autocmd to clean up the symlink when the buffer is closed + os.remove(temp_link_path) + if not vim.loop.fs_symlink(filepath, temp_link_path) then + vim.notify('Failed to create symlink', vim.log.levels.ERROR) + return + end + + -- Register cleanup vim.api.nvim_create_autocmd({ 'BufDelete', 'BufWipeout' }, { buffer = vim.api.nvim_get_current_buf(), callback = function() - os.execute("rm -f '" .. temp_link_path .. "'") + os.remove(temp_link_path) end, }) - -- Open in default vault - local encoded_path = url_encode(temp_link_name) - local uri = 'obsidian://open?vault=' .. default_vault.name .. '&file=' .. encoded_path + local encoded_path = url_encode('_temp_preview/' .. file_basename) + local uri = string.format('obsidian://open?vault=%s&file=%s', default_vault.name, encoded_path) - print('Opening external file in default Obsidian vault: ' .. temp_link_name) - vim.fn.jobstart({ 'xdg-open', uri }, { detach = true }) + vim.fn.jobstart({ 'xdg-open', uri }, { + detach = true, + on_exit = function(_, code) + if code ~= 0 then + vim.notify('Failed to open Obsidian', vim.log.levels.ERROR) + end + end, + }) end end --- Create the which-key keymap group +local function close_obsidian(detach) + detach = detach or false + if is_executable 'pkill' then + local opts = { + on_exit = function(_, code) + if code == 0 then + vim.notify 'Closed Obsidian' + end + end, + } + + if detach then + opts.detach = true + opts.on_exit = nil -- No notifications when detached + end + + -- Force kill with SIGKILL (9) for immediate termination + vim.fn.jobstart({ 'pkill', '-9', '-f', 'obsidian' }, opts) + end +end + +-- Public functions for commands +function add_vault(name, path) + if type(name) ~= 'string' or type(path) ~= 'string' then + vim.notify('Invalid vault name or path', vim.log.levels.ERROR) + return false + end + + path = safe_path(vim.fn.expand(path)) + + -- Check for duplicates + for _, vault in ipairs(vaults) do + if vault.name == name then + vim.notify('Vault name already exists', vim.log.levels.WARN) + return false + end + if safe_path(vault.path) == path then + vim.notify('Vault path already exists', vim.log.levels.WARN) + return false + end + end + + -- Ensure directory exists + if ensure_dir_exists(path) ~= 1 then + vim.notify('Failed to create vault directory', vim.log.levels.ERROR) + return false + end + + table.insert(vaults, { name = name, path = path }) + if save_vault_configs() then + vim.notify(string.format('Added vault: %s at %s', name, path)) + return true + end + return false +end + +function remove_vault(name) + for i, vault in ipairs(vaults) do + if vault.name == name then + table.remove(vaults, i) + if save_vault_configs() then + vim.notify(string.format('Removed vault: %s', name)) + return true + end + break + end + end + vim.notify('Vault not found', vim.log.levels.WARN) + return false +end + +function list_vaults() + if #vaults == 0 then + vim.notify('No vaults configured', vim.log.levels.INFO) + return + end + + local lines = { 'Configured Obsidian vaults:' } + for _, vault in ipairs(vaults) do + table.insert(lines, string.format('- %s: %s', vault.name, vault.path)) + end + vim.notify(table.concat(lines, '\n')) +end + +-- Load configurations +load_vault_configs() + +-- Create commands +vim.api.nvim_create_user_command('OpenInObsidian', open_in_obsidian, {}) +vim.api.nvim_create_user_command('CloseObsidian', function() + close_obsidian(false) +end, {}) +vim.api.nvim_create_user_command('ListObsidianVaults', list_vaults, {}) +vim.api.nvim_create_user_command('AddObsidianVault', function(opts) + local args = vim.split(opts.args, '%s+', { trimempty = true }) + if #args ~= 2 then + vim.notify('Usage: AddObsidianVault ', vim.log.levels.WARN) + return + end + add_vault(args[1], args[2]) +end, { nargs = '+' }) +vim.api.nvim_create_user_command('RemoveObsidianVault', function(opts) + remove_vault(opts.args) +end, { nargs = 1 }) + +-- Set up keymaps local ok, wk = pcall(require, 'which-key') if ok then wk.register { ['o'] = { name = 'Obsidian', o = { open_in_obsidian, 'Open in Obsidian' }, - c = { close_obsidian, 'Close Obsidian' }, - l = { ListObsidianVaults, 'List Vaults' }, + c = { + function() + close_obsidian(false) + end, + 'Close Obsidian', + }, + l = { list_vaults, 'List Vaults' }, a = { function() vim.ui.input({ prompt = 'Vault name: ' }, function(name) if name then vim.ui.input({ prompt = 'Vault path: ' }, function(path) if path then - AddObsidianVault(name, path) + add_vault(name, path) end end) end @@ -399,7 +492,7 @@ if ok then function() vim.ui.input({ prompt = 'Vault name to remove: ' }, function(name) if name then - RemoveObsidianVault(name) + remove_vault(name) end end) end, @@ -408,17 +501,18 @@ if ok then }, } else - -- Fallback keymaps if which-key is not available local opts = { noremap = true, silent = true } vim.keymap.set('n', 'oo', open_in_obsidian, opts) - vim.keymap.set('n', 'oc', close_obsidian, opts) - vim.keymap.set('n', 'ol', ListObsidianVaults, opts) + vim.keymap.set('n', 'oc', function() + close_obsidian(false) + end, opts) + vim.keymap.set('n', 'ol', list_vaults, opts) vim.keymap.set('n', 'oa', function() vim.ui.input({ prompt = 'Vault name: ' }, function(name) if name then vim.ui.input({ prompt = 'Vault path: ' }, function(path) if path then - AddObsidianVault(name, path) + add_vault(name, path) end end) end @@ -427,64 +521,35 @@ else vim.keymap.set('n', 'or', function() vim.ui.input({ prompt = 'Vault name to remove: ' }, function(name) if name then - RemoveObsidianVault(name) + remove_vault(name) end end) end, opts) end --- Create user commands -vim.api.nvim_create_user_command('OpenInObsidian', open_in_obsidian, {}) -vim.api.nvim_create_user_command('CloseObsidian', close_obsidian, {}) -vim.api.nvim_create_user_command('AddObsidianVault', function(opts) - local args = opts.args - local parts = {} - for part in string.gmatch(args, '%S+') do - table.insert(parts, part) - end - - if #parts ~= 2 then - print 'Usage: AddObsidianVault ' - return - end - - AddObsidianVault(parts[1], parts[2]) -end, { nargs = '+' }) - -vim.api.nvim_create_user_command('RemoveObsidianVault', function(opts) - RemoveObsidianVault(opts.args) -end, { nargs = 1 }) - -vim.api.nvim_create_user_command('ListObsidianVaults', ListObsidianVaults, {}) +-- Set up autocommands +vim.api.nvim_create_augroup('obsidian_integration', { clear = true }) -- Enable autoread vim.o.autoread = true vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { + group = 'obsidian_integration', callback = function() vim.cmd 'checktime' end, }) --- Use a trap-based approach for VimLeave to ensure it runs before Neovim fully exits -vim.api.nvim_create_autocmd('UIEnter', { - once = true, - callback = function() - -- Get Neovim's PID - local nvim_pid = vim.fn.getpid() - - -- Create a trap in the parent shell that will kill Obsidian when Neovim exits - os.execute(string.format("trap 'pkill -9 -f obsidian' EXIT && " .. 'while kill -0 %d 2>/dev/null; do sleep 0.01; done & disown', nvim_pid)) - end, -}) - --- Cleanup temp directories on exit +-- Cleanup on exit vim.api.nvim_create_autocmd('VimLeavePre', { + group = 'obsidian_integration', callback = function() + -- Clean up temp directories for _, vault in ipairs(vaults) do - os.execute("rm -rf '" .. vault.path .. "_temp_preview/'*") + local temp_dir = safe_path(vault.path .. '_temp_preview') + os.execute(string.format('rm -rf %q', temp_dir)) end - -- Also ensure Obsidian is closed - close_obsidian() + -- Force close Obsidian immediately using detached process + close_obsidian(true) end, }) -- [[ Basic Autocommands ]] @@ -1022,9 +1087,9 @@ require('lazy').setup({ end, }, } - require('lspconfig').clangd.setup{ - capabilities = capabilities, -} + require('lspconfig').clangd.setup { + capabilities = capabilities, + } end, }, From c03096290d37ecb19abe31bb9595aca9dc387996 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Fri, 21 Feb 2025 22:34:43 -0800 Subject: [PATCH 10/16] optimzied obsidian --- init.lua | 499 ++++++++++++++++++++++++++----------------------------- 1 file changed, 238 insertions(+), 261 deletions(-) diff --git a/init.lua b/init.lua index 1cfc3579b19..60f0faafc51 100644 --- a/init.lua +++ b/init.lua @@ -190,28 +190,49 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the lower win vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) vim.api.nvim_set_keymap('c', '%%', "=expand('%:h').'/'", { noremap = true, silent = true }) --- Obsidian Integration --- Configuration -local config_path = vim.fn.expand '~/.config/nvim/obsidian_vaults.json' -local vaults = {} --- Utility functions -local function is_executable(cmd) +-- Obsidian Integration (Optimized) +local M = {} + +--[[ Module Design: +1. Encapsulated configuration +2. Separated concerns with dedicated modules +3. Strict local scoping +4. Error handling consistency +5. Documentation-ready structure +6. Reduced code duplication +]] + +-- Configuration Module -- +local Config = { + path = vim.fn.expand '~/.config/nvim/obsidian_vaults.json', + vaults = {}, + default_vault_name = 'default', + temp_dir_suffix = '_temp_preview', +} + +-- Utility Module -- +local Utils = {} + +function Utils.is_executable(cmd) return vim.fn.executable(cmd) == 1 end -local function ensure_dir_exists(path) - return vim.fn.mkdir(path, 'p') +function Utils.ensure_dir(path) + return vim.fn.mkdir(path, 'p') == 1 end -local function safe_path(path) - return path:gsub([[\]], [[/]]):gsub('/$', '') .. '/' +function Utils.safe_path(path) + return (path:gsub([[\]], [[/]]):gsub('/$', '') .. '/') end --- URL encode a string using either Python or Lua -local function url_encode(str) - if is_executable 'python3' then - local handle = io.popen(string.format('python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))" %q', str)) +function Utils.notify(msg, level) + vim.notify(msg, level or vim.log.levels.INFO) +end + +function Utils.url_encode(str) + if Utils.is_executable 'python3' then + local handle = io.popen(string.format('python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))" %q 2>/dev/null', str)) if handle then local result = handle:read '*a' handle:close() @@ -219,339 +240,295 @@ local function url_encode(str) end end - -- Fallback to basic Lua URL encoding return str:gsub('[^%w%-%.%_%~]', function(c) return string.format('%%%02X', string.byte(c)) end) end --- Vault management functions -local function save_vault_configs() - local f = io.open(config_path, 'w') - if not f then - vim.notify('Failed to save vault configurations', vim.log.levels.ERROR) - return false +-- If vim.pesc is not defined, define it to escape Lua patterns. +if not vim.pesc then + vim.pesc = function(str) + return str:gsub('([^%w])', '%%%1') end +end - local success, encoded = pcall(vim.json.encode, vaults) - if not success then - f:close() - vim.notify('Failed to encode vault configurations', vim.log.levels.ERROR) - return false - end +-- Vault Manager Module -- +local VaultManager = {} - f:write(encoded) - f:close() - return true -end +function VaultManager.load() + local file = io.open(Config.path, 'r') + if not file then + return VaultManager.create_default() + end -local function load_vault_configs() - local f = io.open(config_path, 'r') - if f then - local content = f:read '*all' - f:close() + local success, parsed = pcall(vim.json.decode, file:read '*a') + file:close() - local success, parsed = pcall(vim.json.decode, content) - if success and type(parsed) == 'table' then - vaults = parsed - return true - end + if success and type(parsed) == 'table' then + Config.vaults = parsed + return true end - -- Initialize with default vault if none exists - if #vaults == 0 then - local default_path = vim.fn.expand '~/obsidian-vault/' - ensure_dir_exists(default_path) - vaults = { { - name = 'default', + return VaultManager.create_default() +end + +function VaultManager.create_default() + local default_path = Utils.safe_path(vim.fn.expand '~/obsidian-vault/') + if Utils.ensure_dir(default_path) then + Config.vaults = { { + name = Config.default_vault_name, path = default_path, } } - save_vault_configs() + return VaultManager.save() end return false end --- Find which vault contains a given filepath -local function find_containing_vault(filepath) - filepath = safe_path(filepath) - for _, vault in ipairs(vaults) do - local vault_path = safe_path(vault.path) - if filepath:find('^' .. vim.pesc(vault_path)) then - return vault, filepath:gsub('^' .. vim.pesc(vault_path), '') +function VaultManager.save() + local file = io.open(Config.path, 'w') + if not file then + Utils.notify('Failed to save vault config', vim.log.levels.ERROR) + return false + end + + local success, encoded = pcall(vim.json.encode, Config.vaults) + if not success then + file:close() + Utils.notify('Config serialization failed', vim.log.levels.ERROR) + return false + end + + file:write(encoded) + file:close() + return true +end + +function VaultManager.find_containing(filepath) + local safe_path = Utils.safe_path(filepath) + for _, vault in ipairs(Config.vaults) do + local vault_path = Utils.safe_path(vault.path) + if safe_path:find('^' .. vim.pesc(vault_path)) then + return vault, safe_path:gsub('^' .. vim.pesc(vault_path), '') end end return nil, nil end --- Obsidian interaction functions -local function open_in_obsidian() - local filepath = vim.fn.expand '%:p' +-- Obsidian Core -- +local Obsidian = {} +function Obsidian.open() + local filepath = vim.fn.expand '%:p' if filepath == '' then - vim.notify('No file to open!', vim.log.levels.WARN) - return + return Utils.notify('No file to open', vim.log.levels.WARN) end - if not filepath:match '%.md$' then - vim.notify('Not a markdown file', vim.log.levels.WARN) - return + return Utils.notify('Not a markdown file', vim.log.levels.WARN) end - local containing_vault, relative_path = find_containing_vault(filepath) - - if containing_vault then - local encoded_path = url_encode(relative_path) - local uri = string.format('obsidian://open?vault=%s&file=%s', containing_vault.name, encoded_path) - - vim.notify(string.format("Opening in vault '%s': %s", containing_vault.name, relative_path)) - - vim.fn.jobstart({ 'xdg-open', uri }, { - detach = true, - on_exit = function(_, code) - if code ~= 0 then - vim.notify('Failed to open Obsidian', vim.log.levels.ERROR) - end - end, - }) + local vault, rel_path = VaultManager.find_containing(filepath) + if vault then + Obsidian.open_vault_file(vault, rel_path) else - -- Handle external files - local default_vault = vaults[1] - if not default_vault then - vim.notify('No default vault configured', vim.log.levels.ERROR) - return - end - - local temp_dir = safe_path(default_vault.path .. '_temp_preview') - ensure_dir_exists(temp_dir) + Obsidian.open_external_file(filepath) + end +end - local file_basename = vim.fn.fnamemodify(filepath, ':t') - local temp_link_path = temp_dir .. file_basename +function Obsidian.open_vault_file(vault, rel_path) + local encoded = Utils.url_encode(rel_path) + local uri = ('obsidian://open?vault=%s&file=%s'):format(vault.name, encoded) + Utils.notify(("Opening in '%s': %s"):format(vault.name, rel_path)) + Obsidian.execute({ 'xdg-open', uri }, true) +end - os.remove(temp_link_path) - if not vim.loop.fs_symlink(filepath, temp_link_path) then - vim.notify('Failed to create symlink', vim.log.levels.ERROR) - return - end +function Obsidian.open_external_file(filepath) + local default_vault = Config.vaults[1] + if not default_vault then + return Utils.notify('No default vault', vim.log.levels.ERROR) + end - -- Register cleanup - vim.api.nvim_create_autocmd({ 'BufDelete', 'BufWipeout' }, { - buffer = vim.api.nvim_get_current_buf(), - callback = function() - os.remove(temp_link_path) - end, - }) + local temp_dir = Utils.safe_path(default_vault.path .. Config.temp_dir_suffix) + if not Utils.ensure_dir(temp_dir) then + return + end - local encoded_path = url_encode('_temp_preview/' .. file_basename) - local uri = string.format('obsidian://open?vault=%s&file=%s', default_vault.name, encoded_path) + local basename = vim.fn.fnamemodify(filepath, ':t') + local symlink = temp_dir .. basename - vim.fn.jobstart({ 'xdg-open', uri }, { - detach = true, - on_exit = function(_, code) - if code ~= 0 then - vim.notify('Failed to open Obsidian', vim.log.levels.ERROR) - end - end, - }) + os.remove(symlink) + if not vim.loop.fs_symlink(filepath, symlink) then + return Utils.notify('Symlink failed', vim.log.levels.ERROR) end -end -local function close_obsidian(detach) - detach = detach or false - if is_executable 'pkill' then - local opts = { - on_exit = function(_, code) - if code == 0 then - vim.notify 'Closed Obsidian' - end - end, - } + vim.api.nvim_create_autocmd({ 'BufDelete', 'BufWipeout' }, { + buffer = vim.api.nvim_get_current_buf(), + callback = function() + os.remove(symlink) + end, + }) - if detach then - opts.detach = true - opts.on_exit = nil -- No notifications when detached - end + local encoded = Utils.url_encode(Config.temp_dir_suffix .. '/' .. basename) + local uri = ('obsidian://open?vault=%s&file=%s'):format(default_vault.name, encoded) + Obsidian.execute({ 'xdg-open', uri }, true) +end - -- Force kill with SIGKILL (9) for immediate termination - vim.fn.jobstart({ 'pkill', '-9', '-f', 'obsidian' }, opts) +function Obsidian.close(detach) + if not Utils.is_executable 'pkill' then + return end + + local opts = { + detach = detach or false, + on_exit = not detach and function(_, code) + if code == 0 then + Utils.notify 'Obsidian closed' + end + end, + } + + Obsidian.execute({ 'pkill', '-9', '-f', 'obsidian' }, opts.detach, opts.on_exit) end --- Public functions for commands -function add_vault(name, path) - if type(name) ~= 'string' or type(path) ~= 'string' then - vim.notify('Invalid vault name or path', vim.log.levels.ERROR) - return false - end +function Obsidian.execute(command, detach, callback) + vim.fn.jobstart(command, { + detach = detach, + on_exit = callback or function(_, code) + if code ~= 0 then + Utils.notify('Command failed', vim.log.levels.ERROR) + end + end, + }) +end - path = safe_path(vim.fn.expand(path)) +-- Public API -- +function M.add_vault(name, path) + path = Utils.safe_path(vim.fn.expand(path)) - -- Check for duplicates - for _, vault in ipairs(vaults) do + for _, vault in ipairs(Config.vaults) do if vault.name == name then - vim.notify('Vault name already exists', vim.log.levels.WARN) - return false + return Utils.notify('Vault name exists', vim.log.levels.WARN) end - if safe_path(vault.path) == path then - vim.notify('Vault path already exists', vim.log.levels.WARN) - return false + if Utils.safe_path(vault.path) == path then + return Utils.notify('Vault path exists', vim.log.levels.WARN) end end - -- Ensure directory exists - if ensure_dir_exists(path) ~= 1 then - vim.notify('Failed to create vault directory', vim.log.levels.ERROR) - return false + if not Utils.ensure_dir(path) then + return Utils.notify('Directory creation failed', vim.log.levels.ERROR) end - table.insert(vaults, { name = name, path = path }) - if save_vault_configs() then - vim.notify(string.format('Added vault: %s at %s', name, path)) - return true - end - return false + table.insert(Config.vaults, { name = name, path = path }) + return VaultManager.save() and Utils.notify(('Added vault: %s'):format(name)) end -function remove_vault(name) - for i, vault in ipairs(vaults) do +function M.remove_vault(name) + for i, vault in ipairs(Config.vaults) do if vault.name == name then - table.remove(vaults, i) - if save_vault_configs() then - vim.notify(string.format('Removed vault: %s', name)) - return true - end - break + table.remove(Config.vaults, i) + return VaultManager.save() and Utils.notify(('Removed vault: %s'):format(name)) end end - vim.notify('Vault not found', vim.log.levels.WARN) - return false + Utils.notify('Vault not found', vim.log.levels.WARN) end -function list_vaults() - if #vaults == 0 then - vim.notify('No vaults configured', vim.log.levels.INFO) - return - end - - local lines = { 'Configured Obsidian vaults:' } - for _, vault in ipairs(vaults) do - table.insert(lines, string.format('- %s: %s', vault.name, vault.path)) +function M.list_vaults() + local lines = { 'Configured Vaults:' } + for _, vault in ipairs(Config.vaults) do + table.insert(lines, ('- %s: %s'):format(vault.name, vault.path)) end - vim.notify(table.concat(lines, '\n')) + Utils.notify(table.concat(lines, '\n')) end --- Load configurations -load_vault_configs() +-- Initialization -- +VaultManager.load() --- Create commands -vim.api.nvim_create_user_command('OpenInObsidian', open_in_obsidian, {}) +-- Command Setup -- +vim.api.nvim_create_user_command('OpenInObsidian', Obsidian.open, {}) vim.api.nvim_create_user_command('CloseObsidian', function() - close_obsidian(false) + Obsidian.close() end, {}) -vim.api.nvim_create_user_command('ListObsidianVaults', list_vaults, {}) +vim.api.nvim_create_user_command('ListObsidianVaults', M.list_vaults, {}) vim.api.nvim_create_user_command('AddObsidianVault', function(opts) local args = vim.split(opts.args, '%s+', { trimempty = true }) - if #args ~= 2 then - vim.notify('Usage: AddObsidianVault ', vim.log.levels.WARN) - return + if #args == 2 then + M.add_vault(args[1], args[2]) end - add_vault(args[1], args[2]) end, { nargs = '+' }) + vim.api.nvim_create_user_command('RemoveObsidianVault', function(opts) - remove_vault(opts.args) + M.remove_vault(opts.args) end, { nargs = 1 }) --- Set up keymaps -local ok, wk = pcall(require, 'which-key') -if ok then - wk.register { - ['o'] = { - name = 'Obsidian', - o = { open_in_obsidian, 'Open in Obsidian' }, - c = { - function() - close_obsidian(false) - end, - 'Close Obsidian', - }, - l = { list_vaults, 'List Vaults' }, - a = { - function() - vim.ui.input({ prompt = 'Vault name: ' }, function(name) - if name then - vim.ui.input({ prompt = 'Vault path: ' }, function(path) - if path then - add_vault(name, path) - end - end) - end - end) - end, - 'Add Vault', - }, - r = { - function() - vim.ui.input({ prompt = 'Vault name to remove: ' }, function(name) - if name then - remove_vault(name) - end - end) - end, - 'Remove Vault', - }, +-- Keymaps -- +local wk_ok, wk = pcall(require, 'which-key') +local keymaps = { + ['o'] = { + name = 'Obsidian', + o = { Obsidian.open, 'Open' }, + c = { + function() + Obsidian.close() + end, + 'Close', }, - } -else - local opts = { noremap = true, silent = true } - vim.keymap.set('n', 'oo', open_in_obsidian, opts) - vim.keymap.set('n', 'oc', function() - close_obsidian(false) - end, opts) - vim.keymap.set('n', 'ol', list_vaults, opts) - vim.keymap.set('n', 'oa', function() - vim.ui.input({ prompt = 'Vault name: ' }, function(name) - if name then - vim.ui.input({ prompt = 'Vault path: ' }, function(path) - if path then - add_vault(name, path) + l = { M.list_vaults, 'List' }, + a = { + function() + vim.ui.input({ prompt = 'Vault name: ' }, function(name) + if name then + vim.ui.input({ prompt = 'Path: ' }, function(path) + if path then + M.add_vault(name, path) + end + end) end end) - end - end) - end, opts) - vim.keymap.set('n', 'or', function() - vim.ui.input({ prompt = 'Vault name to remove: ' }, function(name) - if name then - remove_vault(name) - end - end) - end, opts) + end, + 'Add Vault', + }, + r = { + function() + vim.ui.input({ prompt = 'Vault to remove: ' }, function(name) + if name then + M.remove_vault(name) + end + end) + end, + 'Remove Vault', + }, + }, +} + +if wk_ok then + wk.register(keymaps) +else + for lhs, rhs in pairs(keymaps['o']) do + if type(rhs) == 'table' then + vim.keymap.set('n', 'o' .. lhs, rhs[1], { desc = rhs[2] }) + end + end end --- Set up autocommands -vim.api.nvim_create_augroup('obsidian_integration', { clear = true }) +-- Autocommands -- +vim.api.nvim_create_augroup('ObsidianIntegration', { clear = true }) --- Enable autoread -vim.o.autoread = true vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { - group = 'obsidian_integration', - callback = function() + group = 'ObsidianIntegration', + callback = vim.schedule_wrap(function() vim.cmd 'checktime' - end, + end), }) --- Cleanup on exit vim.api.nvim_create_autocmd('VimLeavePre', { - group = 'obsidian_integration', + group = 'ObsidianIntegration', callback = function() - -- Clean up temp directories - for _, vault in ipairs(vaults) do - local temp_dir = safe_path(vault.path .. '_temp_preview') - os.execute(string.format('rm -rf %q', temp_dir)) + for _, vault in ipairs(Config.vaults) do + os.execute(('rm -rf %q'):format(vault.path .. Config.temp_dir_suffix)) end - -- Force close Obsidian immediately using detached process - close_obsidian(true) + Obsidian.close(true) end, }) + -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` From cff51c8f79a4e603033e61dc64572b222173f4f4 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Fri, 21 Feb 2025 22:47:59 -0800 Subject: [PATCH 11/16] edit external files nvim and obsidian: --- init.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/init.lua b/init.lua index 60f0faafc51..8d5af0810fa 100644 --- a/init.lua +++ b/init.lua @@ -360,6 +360,15 @@ function Obsidian.open_external_file(filepath) return Utils.notify('Symlink failed', vim.log.levels.ERROR) end + -- Add these lines to refresh Obsidian on save + vim.api.nvim_create_autocmd({ 'BufWritePost' }, { + buffer = vim.api.nvim_get_current_buf(), + callback = function() + -- Update symlink metadata to force Obsidian refresh + os.execute(string.format('touch -h %q', symlink)) -- -h flag affects symlink itself + end, + }) + vim.api.nvim_create_autocmd({ 'BufDelete', 'BufWipeout' }, { buffer = vim.api.nvim_get_current_buf(), callback = function() From ee3547bc248411fbad6773e2d2400d4bbf6c057d Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Tue, 28 Oct 2025 22:32:05 -0700 Subject: [PATCH 12/16] change index to main moc --- lua/custom/plugins/wiki.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/custom/plugins/wiki.lua b/lua/custom/plugins/wiki.lua index 1d80d68d9d3..cba44fa4f69 100644 --- a/lua/custom/plugins/wiki.lua +++ b/lua/custom/plugins/wiki.lua @@ -16,6 +16,17 @@ return { -- Custom Markdown to HTML converter -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", -- Auto update diary index + index = 'MOCs/Main MOC', + auto_diary_index = 1, + links_space_char = '-', -- Replace spaces with hyphens in links + }, + { + path = '~/personal-wiki/', + syntax = 'markdown', + ext = '.md', + -- Custom Markdown to HTML converter + -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", + -- Auto update diary index auto_diary_index = 1, links_space_char = '-', -- Replace spaces with hyphens in links }, From 66755993672a301a21ac9499d6f45a5cc877d259 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Tue, 28 Oct 2025 22:57:08 -0700 Subject: [PATCH 13/16] rename index --- lua/custom/plugins/wiki.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/custom/plugins/wiki.lua b/lua/custom/plugins/wiki.lua index cba44fa4f69..5d4791fc744 100644 --- a/lua/custom/plugins/wiki.lua +++ b/lua/custom/plugins/wiki.lua @@ -16,7 +16,7 @@ return { -- Custom Markdown to HTML converter -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", -- Auto update diary index - index = 'MOCs/Main MOC', + index = 'MOCs/main-moc', auto_diary_index = 1, links_space_char = '-', -- Replace spaces with hyphens in links }, From af97caf178258ffc1a2e88209f059c8f529a16ef Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Tue, 28 Oct 2025 23:11:51 -0700 Subject: [PATCH 14/16] fix previous --- lua/custom/plugins/wiki.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/custom/plugins/wiki.lua b/lua/custom/plugins/wiki.lua index 5d4791fc744..1c3aaf0228a 100644 --- a/lua/custom/plugins/wiki.lua +++ b/lua/custom/plugins/wiki.lua @@ -16,7 +16,7 @@ return { -- Custom Markdown to HTML converter -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", -- Auto update diary index - index = 'MOCs/main-moc', + index = 'mocs/main-moc', auto_diary_index = 1, links_space_char = '-', -- Replace spaces with hyphens in links }, From 7271253f23a004814bd72bc73219663f5e9185ad Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Wed, 29 Oct 2025 00:14:07 -0700 Subject: [PATCH 15/16] update index name personal wiki --- lua/custom/plugins/wiki.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/custom/plugins/wiki.lua b/lua/custom/plugins/wiki.lua index 1c3aaf0228a..67a21b5215a 100644 --- a/lua/custom/plugins/wiki.lua +++ b/lua/custom/plugins/wiki.lua @@ -24,6 +24,7 @@ return { path = '~/personal-wiki/', syntax = 'markdown', ext = '.md', + index = 'mocs/main-moc', -- Custom Markdown to HTML converter -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", -- Auto update diary index From 2ffc85be93e9a0ea367e14e061866620fd6a84d9 Mon Sep 17 00:00:00 2001 From: cavelazquez8 Date: Fri, 7 Nov 2025 20:12:54 -0800 Subject: [PATCH 16/16] up to date --- init.lua | 2 +- lazy-lock.json | 68 +++++++++++-------------------------- lua/custom/plugins/wiki.lua | 4 +-- 3 files changed, 23 insertions(+), 51 deletions(-) diff --git a/init.lua b/init.lua index 8d5af0810fa..79614e26637 100644 --- a/init.lua +++ b/init.lua @@ -534,7 +534,7 @@ vim.api.nvim_create_autocmd('VimLeavePre', { for _, vault in ipairs(Config.vaults) do os.execute(('rm -rf %q'):format(vault.path .. Config.temp_dir_suffix)) end - Obsidian.close(true) + -- Obsidian.close(true) end, }) diff --git a/lazy-lock.json b/lazy-lock.json index ed7e483da81..e60acdb43f2 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,56 +1,28 @@ { - "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, + "LuaSnip": { "branch": "master", "commit": "3732756842a2f7e0e76a7b0487e9692072857277" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7" }, - "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, - "conform.nvim": { "branch": "master", "commit": "d28ccf945374edd9f1c34a82f6c22261dbd8ab98" }, - "fidget.nvim": { "branch": "main", "commit": "e2a175c2abe2d4f65357da1c98c59a5cfb2b543f" }, - "gitsigns.nvim": { "branch": "main", "commit": "4daf7022f1481edf1e8fb9947df13bb07c18e89a" }, - "lazy.nvim": { "branch": "main", "commit": "077102c5bfc578693f12377846d427f49bc50076" }, - "lazydev.nvim": { "branch": "main", "commit": "d5800897d9180cea800023f2429bce0a94ed6064" }, - "luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "4d0e5b49363cac187326998b96aa6a2884e0e89b" }, - "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, - "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, - "mini.nvim": { "branch": "main", "commit": "c8bc67a35e627908da644c5f8cd26b3f987f2627" }, - "nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" }, - "nvim-lspconfig": { "branch": "master", "commit": "bc6ada4b0892b7f10852c0b8ca7209fd39a6d754" }, - "nvim-treesitter": { "branch": "master", "commit": "7dc8aabe86db8c2f23520e8334f7584f83e84342" }, - "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, + "conform.nvim": { "branch": "master", "commit": "cde4da5c1083d3527776fee69536107d98dae6c9" }, + "fidget.nvim": { "branch": "main", "commit": "e32b672d8fd343f9d6a76944fedb8c61d7d8111a" }, + "gitsigns.nvim": { "branch": "main", "commit": "20ad4419564d6e22b189f6738116b38871082332" }, + "lazy.nvim": { "branch": "main", "commit": "e6a8824858757ca9cd4f5ae1a72d845fa5c46a39" }, + "lazydev.nvim": { "branch": "main", "commit": "371cd7434cbf95606f1969c2c744da31b77fcfa6" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "d7b5feb6e769e995f7fcf44d92f49f811c51d10c" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "517ef5994ef9d6b738322664d5fdd948f0fdeb46" }, + "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, + "mini.nvim": { "branch": "main", "commit": "7d6fcfd879fe520aba187fe2bd25078fa2367d03" }, + "nvim-cmp": { "branch": "main", "commit": "106c4bcc053a5da783bf4a9d907b6f22485c2ea0" }, + "nvim-lspconfig": { "branch": "master", "commit": "2010fc6ec03e2da552b4886fceb2f7bc0fc2e9c0" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, - "tokyonight.nvim": { "branch": "main", "commit": "ce91ba480070c95f40753e4663e32b4632ac6db3" }, - "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }, - "which-key.nvim": { "branch": "main", "commit": "8badb359f7ab8711e2575ef75dfe6fbbd87e4821" } -======= - "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, - "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7" }, - "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, - "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, - "conform.nvim": { "branch": "master", "commit": "a6f5bdb78caa305496357d17e962bbc4c0b392e2" }, - "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, - "gitsigns.nvim": { "branch": "main", "commit": "6668f379ca634c36b8e11453118590b91bf8b295" }, - "lazy.nvim": { "branch": "main", "commit": "e5e9bf48211a13d9ee6c1077c88327c49c1ab4a0" }, - "lazydev.nvim": { "branch": "main", "commit": "a1b78b2ac6f978c72e76ea90ae92a94edf380cfc" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" }, - "mason-tool-installer.nvim": { "branch": "main", "commit": "374c78d3ebb5c53f43ea6bd906b6587b5e899b9e" }, - "mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" }, - "mini.nvim": { "branch": "main", "commit": "a84b7e555fe382c1859e6ca46b4983c822a1f77f" }, - "nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" }, - "nvim-lspconfig": { "branch": "master", "commit": "1110787f1b464888c59a044c48c5119d14078044" }, - "nvim-treesitter": { "branch": "master", "commit": "1a6e42bb8c5c23d8e2c0acb842dcacac5ee06761" }, - "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "2a5ceff981501cff8f46871d5402cd3378a8ab6a" }, - "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, - "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" }, - "tokyonight.nvim": { "branch": "main", "commit": "057ef5d260c1931f1dffd0f052c685dcd14100a3" }, + "todo-comments.nvim": { "branch": "main", "commit": "411503d3bedeff88484de572f2509c248e499b38" }, + "tokyonight.nvim": { "branch": "main", "commit": "b13cfc1286d2aa8bda6ce137b79e857d5a3d5739" }, "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }, "vimwiki": { "branch": "dev", "commit": "72792615e739d0eb54a9c8f7e0a46a6e2407c9e8" }, - "which-key.nvim": { "branch": "main", "commit": "5bf7a73fe851896d5ac26d313db849bf00f45b78" } ->>>>>>> 6a5d3c5870d7a59d09d268202b7c9d62981d5538 + "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" } } diff --git a/lua/custom/plugins/wiki.lua b/lua/custom/plugins/wiki.lua index 67a21b5215a..0acf1420b22 100644 --- a/lua/custom/plugins/wiki.lua +++ b/lua/custom/plugins/wiki.lua @@ -17,7 +17,7 @@ return { -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", -- Auto update diary index index = 'mocs/main-moc', - auto_diary_index = 1, + -- auto_diary_index = 1, links_space_char = '-', -- Replace spaces with hyphens in links }, { @@ -28,7 +28,7 @@ return { -- Custom Markdown to HTML converter -- custom_wiki2html = "~/.vim/autoload/vimwiki/convert.py", -- Auto update diary index - auto_diary_index = 1, + -- auto_diary_index = 1, links_space_char = '-', -- Replace spaces with hyphens in links }, }