diff options
| author | Mohammad Reza Karimi <m.r.karimi.j@gmail.com> | 2026-01-22 17:17:43 -0500 |
|---|---|---|
| committer | Mohammad Reza Karimi <m.r.karimi.j@gmail.com> | 2026-01-22 17:17:43 -0500 |
| commit | ddd2e6b1cce8d6b5ba29df453bb10a6b841df0fa (patch) | |
| tree | a4058148197ed67f082fc7feb6d2716675db9d9f | |
| parent | c6274ae49c9d6c42ab239f23313a5b72b3ba8d5c (diff) | |
| -rw-r--r-- | init.lua | 29 | ||||
| -rw-r--r-- | lua/mo/org-agenda.lua | 134 | ||||
| -rw-r--r-- | lua/mo/org.lua | 21 | ||||
| -rw-r--r-- | nvim-pack-lock.json | 18 | ||||
| -rw-r--r-- | plugin/11_keymaps.lua | 1 | ||||
| -rw-r--r-- | plugin/plugins/snacks.lua | 0 |
6 files changed, 200 insertions, 3 deletions
@@ -68,6 +68,19 @@ vim.pack.add({ }, { load = false }) vim.pack.add({ + "https://github.com/folke/snacks.nvim", -- just for vim.ui.input +}, { + load = function() + vim.cmd([[packadd! snacks.nvim]]) + require("snacks").setup({ + image = { enabled = false }, + input = { enabled = true }, + }) + vim.cmd([[packadd snacks.nvim]]) + end, +}) + +vim.pack.add({ "https://github.com/ibhagwan/fzf-lua", }, { load = function() @@ -87,6 +100,7 @@ vim.pack.add({ "https://github.com/tpope/vim-fugitive", "https://github.com/tpope/vim-surround", + "https://github.com/tpope/vim-sleuth", "https://github.com/lewis6991/gitsigns.nvim", @@ -100,6 +114,21 @@ vim.pack.add({ "https://github.com/lervag/vimtex", }) +vim.pack.add({ + "https://github.com/nvim-orgmode/orgmode", +}, { + load = function() + vim.api.nvim_create_autocmd("FileType", { + pattern = "org", + once = true, + callback = function() + vim.cmd("packadd orgmode") + require("mo.org") + end, + }) + end, +}) + vim.api.nvim_create_autocmd("ColorScheme", { group = vim.api.nvim_create_augroup("init_config", {}), callback = function() diff --git a/lua/mo/org-agenda.lua b/lua/mo/org-agenda.lua new file mode 100644 index 0000000..fd7ed63 --- /dev/null +++ b/lua/mo/org-agenda.lua @@ -0,0 +1,134 @@ +local Menu = {} + +local default_config = { + window = { + margin = { 1, 0, 1, 0 }, + padding = { 1, 1, 1, 1 }, + title_pos = "center", + border = { "", "-", "", "", "", "", "", "" }, + zindex = 1000, + }, + icons = { + separator = "➜", + }, +} + +function Menu:new(config) + config = vim.tbl_deep_extend("force", default_config, config or {}) + + local opts = {} + opts.window = config.window + opts.icons = config.icons + + setmetatable(opts, self) + self.__index = self + return opts +end + +function Menu:_get_window_margins() + local margins = {} + + for i, m in ipairs(self.window.margin) do + local _m = m + if m > 0 and m < 1 then + if i % 2 == 0 then + _m = math.floor(vim.o.columns * m) + else + _m = math.floor(vim.o.lines * m) + end + end + margins[i] = _m + end + + return margins +end + +local function add_vertical_padding(content, size) + for _ = 1, size do + table.insert(content, "") + end +end + +function Menu:_process_items(items) + local pad_top, pad_right, pad_bot, pad_left = unpack(self.window.padding) + + local content = {} + local keys = {} + + add_vertical_padding(content, pad_top) + + for _, item in ipairs(items) do + if item.key then + keys[item.key] = item + + table.insert(content, string.rep(" ", pad_left) .. vim.fn.join({ + item.key, + self.icons.separator, + item.label, + }) .. string.rep(" ", pad_right)) + end + end + + add_vertical_padding(content, pad_bot) + + return keys, content +end + +function Menu:_open_window(title, content) + local margins = self:_get_window_margins() + local wins = vim.tbl_filter( + function(w) + return vim.api.nvim_win_is_valid(w) + and vim.api.nvim_win_get_config(w).relative == "" + end, + vim.api.nvim_list_wins() + ) + + local line_lengths = vim.tbl_map(function(s) return #s end, content) + line_lengths[#line_lengths + 1] = #title + local pref_width = vim.fn.max(line_lengths) + + self.buffer = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(self.buffer, 0, -1, true, content) + + local window = vim.api.nvim_open_win(self.buffer, false, { + title = title, + title_pos = self.window.title_pos, + relative = "editor", + width = vim.fn.min({ vim.o.columns, pref_width }) + - margins[2] + - margins[4], + height = #content, + focusable = false, + anchor = "SW", + border = self.window.border, + row = vim.o.lines + - margins[3] + + ((vim.o.laststatus == 0 or vim.o.laststatus == 1 and #wins == 1) and 1 or 0) + - vim.o.cmdheight, + col = margins[4], + style = "minimal", + noautocmd = true, + } --[[@as vim.api.keyset.win_config]]) + vim.api.nvim__redraw({ win = window, valid = true }) + return window +end + +function Menu:_close() + vim.api.nvim_win_close(self.window, true) + vim.api.nvim_buf_delete(self.buffer, { force = true }) + vim.cmd.redraw() +end + +function Menu:open(data) + local keys, content = self:_process_items(data.items) + self.window = self:_open_window(data.title, content) + + local char = vim.fn.nr2char(vim.fn.getchar()) + self:_close() + + local entry = keys[char] + if entry and entry.action then return entry.action() end +end + +return Menu diff --git a/lua/mo/org.lua b/lua/mo/org.lua new file mode 100644 index 0000000..2218112 --- /dev/null +++ b/lua/mo/org.lua @@ -0,0 +1,21 @@ +--- @diagnostic disable: missing-fields + +if not package.loaded["fzf-lua"] then + vim.cmd([[packadd fzf-lua]]) +end + +require("orgmode").setup({ + org_agenda_files = "~/org/**/*", + org_default_notes_file = "~/org/refile.org", + + ui = { + input = { use_vim_ui = true }, + menu = { + handler = function(data) + require("mo.org-agenda"):new():open(data) + end + } + }, +} --[[@as OrgConfigOpts]]) + +vim.lsp.enable({ "org" }) diff --git a/nvim-pack-lock.json b/nvim-pack-lock.json index 20bb1a6..8da1f79 100644 --- a/nvim-pack-lock.json +++ b/nvim-pack-lock.json @@ -21,29 +21,41 @@ "src": "https://github.com/lewis6991/gitsigns.nvim" }, "mini.nvim": { - "rev": "c163117900c17d4abf30bc09452a261c8536060c", + "rev": "9b935c218ddba02e5dc75c94f90143bce1f7c646", "src": "https://github.com/nvim-mini/mini.nvim" }, "nvim-lspconfig": { - "rev": "dec357ee48ff7e2e5b76898fd7c67b61a627d3ac", + "rev": "419b082102fa813739588dd82e19a8b6b2442855", "src": "https://github.com/neovim/nvim-lspconfig" }, "nvim-treesitter": { - "rev": "ec034813775d7e2974c7551c8c34499a828963f8", + "rev": "511e5ccf404f8a96ee31866b079fca033a8a7c4e", "src": "https://github.com/nvim-treesitter/nvim-treesitter" }, "oil.nvim": { "rev": "f55b25e493a7df76371cfadd0ded5004cb9cd48a", "src": "https://github.com/stevearc/oil.nvim" }, + "orgmode": { + "rev": "0f8653283bb7af84ef75b3d664851584963c64a3", + "src": "https://github.com/nvim-orgmode/orgmode" + }, "quicker.nvim": { "rev": "fc041830fa7cf093786b0d5990d99cf3c7b0c129", "src": "https://github.com/stevearc/quicker.nvim" }, + "snacks.nvim": { + "rev": "fe7cfe9800a182274d0f868a74b7263b8c0c020b", + "src": "https://github.com/folke/snacks.nvim" + }, "vim-fugitive": { "rev": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4", "src": "https://github.com/tpope/vim-fugitive" }, + "vim-sleuth": { + "rev": "be69bff86754b1aa5adcbb527d7fcd1635a84080", + "src": "https://github.com/tpope/vim-sleuth" + }, "vim-surround": { "rev": "3d188ed2113431cf8dac77be61b842acb64433d9", "src": "https://github.com/tpope/vim-surround" diff --git a/plugin/11_keymaps.lua b/plugin/11_keymaps.lua index 9758fb3..2e07bee 100644 --- a/plugin/11_keymaps.lua +++ b/plugin/11_keymaps.lua @@ -56,6 +56,7 @@ nmap("<C-/>", "<Cmd>FzfLua oldfiles<CR>", "fzf: oldfiles") nmapleader("fg", "<Cmd>FzfLua live_grep<CR>", "fzf: grep") nmapleader("fc", "<Cmd>FzfLua files cwd=~/.config/nvim<CR>", "fzf: search config") nmapleader("fp", "<Cmd>FzfLua files cwd=~/.local/share/nvim/site/pack/core/opt<CR>", "fzf: search plugins") +nmapleader("fo", "<Cmd>FzfLua files cwd=~/org<CR>", "fzf: search org files") nmapleader("fh", "<Cmd>FzfLua helptags<CR>", "fzf: help tags") nmapleader("fk", "<Cmd>FzfLua keymaps<CR>", "fzf: keymaps") -- stylua: ignore end diff --git a/plugin/plugins/snacks.lua b/plugin/plugins/snacks.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugin/plugins/snacks.lua |
