summaryrefslogtreecommitdiffstats
path: root/plugin/50-follow.lua
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-24 17:31:53 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-24 17:35:22 +0200
commitd21d7758dae1e80f2a50bcda580179bf12bf2bf1 (patch)
treed67b2f744f43554792700cbcd6138b9dd8660a6d /plugin/50-follow.lua
parentd08a3df4f5cbc8411d295e00bf8e42b0bf5c5355 (diff)
downloadnvim-config-d21d7758dae1e80f2a50bcda580179bf12bf2bf1.tar.gz
nvim-config-d21d7758dae1e80f2a50bcda580179bf12bf2bf1.zip
fix(nvim): check that NOTES_DIR exists before running code that depends on it
Diffstat (limited to 'plugin/50-follow.lua')
-rw-r--r--plugin/50-follow.lua29
1 files changed, 17 insertions, 12 deletions
diff --git a/plugin/50-follow.lua b/plugin/50-follow.lua
index da3bd62..4f7a3a9 100644
--- a/plugin/50-follow.lua
+++ b/plugin/50-follow.lua
@@ -13,11 +13,10 @@
-- `]u` / `[u` go to the next / previous followable entity
--
-if vim.env.NOTES_DIR == nil then
- vim.notify("NOTES_DIR is not set", vim.log.levels.ERROR)
- return
-end
-local notes_dir = vim.fs.normalize(vim.env.NOTES_DIR)
+-- `notes_dir` may be nil ($NOTES_DIR unset); only the wiki-link entity and the `notes://` scheme
+-- need it, so the rest of the engine (markdown links, URLs, <cfile>, `nvim-help://`) wires up
+-- regardless.
+local notes_dir = require("dotfiles.notes").dir
local df = require("dotfiles.follow")
@@ -73,7 +72,11 @@ local function open_wikilink(edit_cmd, inner)
end
end
-df.register("wikilink", wikilink_matches, open_wikilink)
+if notes_dir ~= nil then
+ df.register("wikilink", wikilink_matches, open_wikilink)
+else
+ vim.notify("50-follow.lua: NOTES_DIR is not set, wiki-link following disabled", vim.log.levels.WARN)
+end
----------------------------------------------------------------------------------------------------
-- Markdown links ----------------------------------------------------------------------------------
@@ -204,12 +207,14 @@ df.register("cfile", cfile_matches, open_cfile)
-- Schemes -----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
--- `notes://<path>` resolves to `<path>` relative to the notes dir.
-df.register_scheme("notes", {
- resolve = function(uri)
- return notes_dir .. "/" .. uri
- end,
-})
+-- `notes://<path>` resolves to `<path>` relative to the notes dir (only when $NOTES_DIR is set).
+if notes_dir ~= nil then
+ df.register_scheme("notes", {
+ resolve = function(uri)
+ return notes_dir .. "/" .. uri
+ end,
+ })
+end
-- `nvim-help://<tag>` — open Neovim help for <tag> in a scratch, read-only buffer.
df.register_scheme("nvim-help", {