diff options
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/50-follow.lua | 29 | ||||
| -rw-r--r-- | plugin/50-notes.lua | 8 |
2 files changed, 21 insertions, 16 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", { diff --git a/plugin/50-notes.lua b/plugin/50-notes.lua index 11a8aef..fa55743 100644 --- a/plugin/50-notes.lua +++ b/plugin/50-notes.lua @@ -27,11 +27,11 @@ -- `<Tab>` / `<S-Tab>` (in notes buffers): go to next/previous followable entity -- -if vim.env.NOTES_DIR == nil then - vim.notify("NOTES_DIR is not set", vim.log.levels.ERROR) +local notes_dir = require("dotfiles.notes").dir +if notes_dir == nil then + vim.notify("50-notes.lua: NOTES_DIR is not set, notes wiki disabled", vim.log.levels.WARN) return end -local notes_dir = vim.fs.normalize(vim.env.NOTES_DIR) local tagfile = vim.fs.joinpath(vim.fn.stdpath("state"), "notes-tags") local follow = require("dotfiles.follow") @@ -199,7 +199,7 @@ end -- Returns a note's path relative to the notes dir, without `.md`, or nil if not a note. local function note_rel_path(path) - local prefix = vim.fs.normalize(notes_dir) .. "/" + local prefix = notes_dir .. "/" path = vim.fs.normalize(path) if not vim.startswith(path, prefix) then return nil |
