From c6940df52e73443f28edd9f5309dfc61ba2c0a63 Mon Sep 17 00:00:00 2001 From: Jasha <8935917+Jasha10@users.noreply.github.com> Date: Tue, 12 Dec 2023 08:53:59 -0600 Subject: [PATCH] add edit_dirs option --- README.md | 6 ++++++ lua/mkdnflow.lua | 1 + lua/mkdnflow/paths.lua | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cdc6ed1..48458ad 100644 --- a/README.md +++ b/README.md @@ -400,6 +400,7 @@ require('mkdnflow').setup({ }, filetypes = {md = true, rmd = true, markdown = true}, create_dirs = true, + edit_dirs = false, perspective = { priority = 'first', fallback = 'current', @@ -515,6 +516,11 @@ require('mkdnflow').setup({ * `true` (default): Directories referenced in a link will be (recursively) created if they do not exist * `false` No action will be taken when directories referenced in a link do not exist. Neovim will open a new file, but you will get an error when you attempt to write the file. +#### `edit_dirs` (boolean) +* `false` (default): When following a link that points to a directory, prompt the user to pick a file within that directory. +* `true`: Call `:edit ` when following a link that points to a directory. +* `function(path)`: Call the supplied callback function when following a link that points to a directory. + #### `perspective` (dictionary-like table) * `perspective.priority` (string): Specifies the priority perspective to take when interpreting link paths * `'first'` (default): Links will be interpreted relative to the first-opened file (when the current instance of Neovim was started) diff --git a/lua/mkdnflow.lua b/lua/mkdnflow.lua index 790f044..ba7ddda 100644 --- a/lua/mkdnflow.lua +++ b/lua/mkdnflow.lua @@ -17,6 +17,7 @@ -- Default config table (where defaults and user-provided config will be combined) local default_config = { create_dirs = true, + edit_dirs = false, silent = false, wrap = false, modules = { diff --git a/lua/mkdnflow/paths.lua b/lua/mkdnflow/paths.lua index 9e2530f..c00b5f4 100644 --- a/lua/mkdnflow/paths.lua +++ b/lua/mkdnflow/paths.lua @@ -24,6 +24,7 @@ local this_os_err = '⬇️ Function unavailable for ' .. this_os .. '. Please f local sep = this_os:match('Windows') and '\\' or '/' -- Get config setting for whether to make missing directories or not local create_dirs = require('mkdnflow').config.create_dirs +local edit_dirs = require('mkdnflow').config.edit_dirs -- Get config setting for where links should be relative to local perspective = require('mkdnflow').config.perspective -- Get directory of first-opened file @@ -184,7 +185,13 @@ local internal_open = function(path, anchor) else path_w_ext = path end - if exists(path, 'd') and not exists(path_w_ext, 'f') then + if exists(path, 'd') and edit_dirs then + if edit_dirs == true then + vim.cmd(':e ' .. path) + else + edit_dirs(path) + end + elseif exists(path, 'd') and not exists(path_w_ext, 'f') then -- Looks like this links to a directory, possibly a notebook enter_internal_path(path) else