Skip to content
Merged
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ require("dotmd").setup({
### Default Options

```lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction
---@alias DotMd.PickerType "telescope" | "fzf" | "snacks" | "mini" Picker type

---@class DotMd.Config
Expand Down Expand Up @@ -220,7 +220,7 @@ See the example below for how to configure **dotmd.nvim**.
---@type DotMd.Config
opts = {
root_dir = "~/dotmd" -- set it to your desired directory or remain at it is
default_split = "none" -- or "vertical" or "horizontal" based on your preference
default_split = "none" -- or "vertical" or "horizontal" or "float" based on your preference
rollover_todo = {
enabled = true, -- enable rollover
},
Expand Down Expand Up @@ -470,7 +470,7 @@ Prompt to create and open a new markdown note.
> To open a note, use the `pick` command instead.

```lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction

---@class DotMd.CreateFileOpts
---@field split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
Expand All @@ -487,7 +487,7 @@ Open/create today’s todo and roll over tasks.
> Can be used to open the current todo file, if it exists, else it creates a new one.

```lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction

---@class DotMd.CreateFileOpts
---@field split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
Expand All @@ -504,7 +504,7 @@ Open/create a journal entry for today.
> Can be used to open the current todo file, if it exists, else it creates a new one.

```lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction

---@class DotMd.CreateFileOpts
---@field split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
Expand All @@ -521,7 +521,7 @@ Open the central `inbox.md`.
> Inbox is a single file that won't be recreated if exists and meant to just be there for you to dump thoughts, tasks, and references.

```lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction

---@class DotMd.CreateFileOpts
---@field split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
Expand Down
14 changes: 7 additions & 7 deletions doc/dotmd.nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*dotmd.nvim.txt* For Neovim >= 0.10.0 Last change: 2025 April 13
*dotmd.nvim.txt* For Neovim >= 0.10.0 Last change: 2025 April 16

==============================================================================
Table of Contents *dotmd.nvim-table-of-contents*
Expand Down Expand Up @@ -83,7 +83,7 @@ below.
DEFAULT OPTIONS ~

>lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction
---@alias DotMd.PickerType "telescope" | "fzf" | "snacks" | "mini" Picker type

---@class DotMd.Config
Expand Down Expand Up @@ -204,7 +204,7 @@ See the example below for how to configure **dotmd.nvim**.
---@type DotMd.Config
opts = {
root_dir = "~/dotmd" -- set it to your desired directory or remain at it is
default_split = "none" -- or "vertical" or "horizontal" based on your preference
default_split = "none" -- or "vertical" or "horizontal" or "float" based on your preference
rollover_todo = {
enabled = true, -- enable rollover
},
Expand Down Expand Up @@ -466,7 +466,7 @@ Prompt to create and open a new markdown note.
[!note] This cannot be used to open a note, it will create a new file with
prefix if the file exists. To open a note, use the `pick` command instead.
>lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction

---@class DotMd.CreateFileOpts
---@field split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
Expand All @@ -484,7 +484,7 @@ Open/create today’s todo and roll over tasks.
[!note] Can be used to open the current todo file, if it exists, else it
creates a new one.
>lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction

---@class DotMd.CreateFileOpts
---@field split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
Expand All @@ -502,7 +502,7 @@ Open/create a journal entry for today.
[!note] Can be used to open the current todo file, if it exists, else it
creates a new one.
>lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction

---@class DotMd.CreateFileOpts
---@field split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
Expand All @@ -520,7 +520,7 @@ Open the central `inbox.md`.
[!note] Inbox is a single file that won’t be recreated if exists and meant to
just be there for you to dump thoughts, tasks, and references.
>lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction

---@class DotMd.CreateFileOpts
---@field split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
Expand Down
2 changes: 1 addition & 1 deletion lua/dotmd/types.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---@alias DotMd.Config.DirNameKeys "notes" | "todos" | "journals"
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.Split "vertical" | "horizontal" | "float" | "none" Split direction
---@alias DotMd.PickType "notes" | "todos" | "journals" | "all" Pick type
---@alias DotMd.PickerType "telescope" | "fzf" | "snacks" | "mini" Picker type

Expand Down
70 changes: 70 additions & 0 deletions lua/dotmd/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,80 @@ function M.get_unique_filepath(base_path, formatted_name)
return note_path
end

---@param note_path string The path to the file
function M.open_float(note_path)
if vim.fn.filereadable(note_path) == 0 then
vim.notify("File not found: " .. note_path, vim.log.levels.WARN)
return
end

local snacks_ok, snacks = pcall(require, "snacks")

local winborder = vim.api.nvim_get_option_value(
"winborder",
{ scope = "local" }
) or "none"

---@type vim.api.keyset.win_config
local win_opts = {
relative = "editor",
width = 0.8,
height = 0.8,
border = winborder,
footer = "Press q to close",
footer_pos = "center",
}

if not (snacks_ok and snacks and snacks.win) then
vim.cmd("badd " .. vim.fn.fnameescape(note_path))
local buf = vim.fn.bufnr(note_path)

vim.api.nvim_set_option_value(
"filetype",
"markdown",
{ scope = "local", buf = buf }
)

win_opts.width = math.floor(vim.o.columns * win_opts.width)
win_opts.height = math.floor(vim.o.lines * win_opts.height)
win_opts.row = math.floor((vim.o.lines - win_opts.height) / 2)
win_opts.col = math.floor((vim.o.columns - win_opts.width) / 2)

vim.api.nvim_open_win(buf, true, win_opts)

vim.api.nvim_buf_set_keymap(
buf,
"n",
"q",
":close<CR>",
{ noremap = true, silent = true }
)
else
local snacks_win_opts = vim.tbl_deep_extend("force", win_opts, {
minimal = false,
file = note_path,
bo = {
readonly = false,
modifiable = true,
},
keys = {
q = "close",
},
})

snacks.win(snacks_win_opts)
end
end

--- Open a file
---@param note_path string The path to the file
---@param split? DotMd.Split Split direction for new or existing files, default is based on `default_split` in config
function M.open_file(note_path, split)
if split == "float" then
M.open_float(note_path)
return
end

local cmd = ({
vertical = "vsplit",
horizontal = "split",
Expand Down