Skip to content

Commit 12809f9

Browse files
Add option to provide function for win_split_mode to allow using float windows
1 parent f5fd1e6 commit 12809f9

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

DOCS.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,41 @@ NOTE: Make sure fast access keys do not overlap. If that happens, first entry in
7575
Should error diagnostics be shown. If you are using Neovim 0.6.0 or higher, these will be shown via `vim.diagnostic`.<br />
7676

7777
#### **win_split_mode**
78-
*type*: `string`<br />
78+
*type*: `string|function`<br />
7979
*default value*: `horizontal`<br />
8080
Available options:
8181
* horizontal - Always split horizontally
8282
* vertical - Always split vertically
8383
* auto - Determine between horizontal and vertical split depending on the current window size
8484

8585
This option determines how to open agenda and capture window.<br />
86-
If none of the options above suit your needs, you can provide custom command (see `:help <mods>`). Here are few examples:<br />
86+
If none of the options above suit your needs, you can provide custom command string (see `:help <mods>`) or custom function:
87+
Here are few examples:<br />
88+
89+
Open in float window:
90+
```lua
91+
win_split_mode = function(name)
92+
local bufnr = vim.api.nvim_create_buf(false, true)
93+
--- Setting buffer name is required
94+
vim.api.nvim_buf_set_name(bufnr, name)
95+
96+
local fill = 0.8
97+
local width = math.floor((vim.o.columns * fill))
98+
local height = math.floor((vim.o.lines * fill))
99+
local row = math.floor((((vim.o.lines - height) / 2) - 1))
100+
local col = math.floor(((vim.o.columns - width) / 2))
101+
102+
vim.api.nvim_open_win(bufnr, true, {
103+
relative = "editor",
104+
width = width,
105+
height = height,
106+
row = row,
107+
col = col,
108+
style = "minimal",
109+
border = "rounded"
110+
})
111+
end
112+
```
87113

88114
Always open in tab:
89115
```
@@ -100,7 +126,6 @@ Always open horizontally with specific height of 20 lines:
100126
win_split_mode = '20split'
101127
```
102128

103-
104129
#### **org_todo_keyword_faces**
105130
*type*: `table<string, string>`<br />
106131
*default value*: `{}`<br />

lua/orgmode/utils/init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,11 @@ function utils.open_window(name, height, split_mode)
532532
vim.w.org_window_split_mode = 'horizontal'
533533
end
534534
else
535-
vim.cmd(string.format('%s %s', split_mode, name))
535+
if type(split_mode) == 'function' then
536+
split_mode(name)
537+
else
538+
vim.cmd(string.format('%s %s', split_mode, name))
539+
end
536540
end
537541
end
538542

0 commit comments

Comments
 (0)