|
1 | 1 | local M = {} |
2 | 2 |
|
| 3 | +-- default config |
| 4 | +local config = { |
| 5 | + height = 20, |
| 6 | + width = 80, |
| 7 | + relative_numbers = true, -- false for absolute |
| 8 | + notes_file_path = vim.fn.expand("$HOME") .. "/notes.md" -- default notes file path |
| 9 | +} |
| 10 | + |
| 11 | +-- overide default config |
| 12 | +function M.setup(user_config) |
| 13 | + user_config = user_config or {} |
| 14 | + config = vim.tbl_deep_extend("force", config, user_config) |
| 15 | +end |
| 16 | + |
3 | 17 | function M.open_notes() |
4 | | - local notes_file = vim.fn.expand("$HOME") .. "/notes.md" |
| 18 | + local notes_file = config.notes_file_path |
5 | 19 |
|
6 | 20 | if not vim.fn.filereadable(notes_file) then |
7 | 21 | vim.fn.writefile({}, notes_file) |
@@ -29,21 +43,23 @@ function M.open_notes() |
29 | 43 | vim.api.nvim_buf_set_option(buf, "filetype", "markdown") |
30 | 44 | vim.api.nvim_buf_set_option(buf, "buftype", "") |
31 | 45 |
|
32 | | - local width = 80 |
33 | | - local height = 20 |
34 | | - |
35 | 46 | local win = vim.api.nvim_open_win(buf, true, { |
36 | 47 | relative = 'editor', |
37 | 48 | row = math.floor((vim.o.lines - height) / 2), |
38 | 49 | col = math.floor((vim.o.columns - width) / 2), |
39 | | - width = width, |
40 | | - height = height, |
| 50 | + width = config.width, |
| 51 | + height = config.width, |
41 | 52 | style = 'minimal', |
42 | 53 | border = 'single', |
43 | 54 | }) |
44 | 55 |
|
45 | | - vim.api.nvim_buf_set_option(buf, 'number', true) |
46 | | - vim.api.nvim_buf_set_option(buf, 'relativenumber', true) |
| 56 | + if config.relative_numbers then |
| 57 | + vim.api.nvim_buf_set_option(buf, 'relativenumber', true) |
| 58 | + vim.api.nvim_buf_set_option(buf, 'number', true) |
| 59 | + else |
| 60 | + vim.api.nvim_buf_set_option(buf, 'number', true) |
| 61 | + vim.api.nvim_buf_set_option(buf, 'relativenumber', false) |
| 62 | + end |
47 | 63 |
|
48 | 64 | -- focus on floating window |
49 | 65 | vim.api.nvim_set_current_win(win) |
|
0 commit comments