Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add edit_dirs option #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 <directory>` 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)
Expand Down
1 change: 1 addition & 0 deletions lua/mkdnflow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
9 changes: 8 additions & 1 deletion lua/mkdnflow/paths.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down