From eeb62a10721b459374296cd0df8c6a9433ebb1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20L=C3=BCdecke?= Date: Thu, 26 Sep 2024 10:05:35 +0200 Subject: [PATCH] Added orgmode completion as cmp source --- lua/config/nvim-cmp.lua | 137 ++++++++++++++++++++-------------------- lua/plugins.lua | 2 +- 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index 5f4421f..617b4dd 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -1,80 +1,81 @@ local has_words_before = function() - unpack = unpack or table.unpack - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end local luasnip = require("luasnip") local cmp = require("cmp") cmp.setup({ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - end, - }, - mapping = cmp.mapping.preset.insert({ - -- Use to scroll the docs - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - -- Use to switch in items - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - -- Use (Enter) to confirm selection - -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [''] = cmp.mapping.confirm({ select = true }), + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = cmp.mapping.preset.insert({ + -- Use to scroll the docs + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + -- Use to switch in items + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Use (Enter) to confirm selection + -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.confirm({ select = true }), - -- A super tab - -- sourc: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip - [""] = cmp.mapping(function(fallback) - -- Hint: if the completion menu is visible select next one - if cmp.visible() then - cmp.select_next_item() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), -- i - insert mode; s - select mode - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - }), + -- A super tab + -- sourc: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip + [""] = cmp.mapping(function(fallback) + -- Hint: if the completion menu is visible select next one + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), -- i - insert mode; s - select mode + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), - -- Let's configure the item's appearance - -- source: https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance - formatting = { - -- Set order from left to right - -- kind: single letter indicating the type of completion - -- abbr: abbreviation of "word"; when not empty it is used in the menu instead of "word" - -- menu: extra text for the popup menu, displayed after "word" or "abbr" - fields = { 'abbr', 'menu' }, + -- Let's configure the item's appearance + -- source: https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance + formatting = { + -- Set order from left to right + -- kind: single letter indicating the type of completion + -- abbr: abbreviation of "word"; when not empty it is used in the menu instead of "word" + -- menu: extra text for the popup menu, displayed after "word" or "abbr" + fields = { 'abbr', 'menu' }, - -- customize the appearance of the completion menu - format = function(entry, vim_item) - vim_item.menu = ({ - nvim_lsp = '[Lsp]', - luasnip = '[Luasnip]', - buffer = '[File]', - path = '[Path]', - })[entry.source.name] - return vim_item - end, - }, + -- customize the appearance of the completion menu + format = function(entry, vim_item) + vim_item.menu = ({ + nvim_lsp = '[Lsp]', + luasnip = '[Luasnip]', + buffer = '[File]', + path = '[Path]', + })[entry.source.name] + return vim_item + end, + }, - -- Set source precedence - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, -- For nvim-lsp - { name = 'luasnip' }, -- For luasnip user - { name = 'buffer' }, -- For buffer word completion - { name = 'path' }, -- For path completion - { name = 'rpncalc' }, -- for RPN calculations - }) + -- Set source precedence + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, -- For nvim-lsp + { name = 'luasnip' }, -- For luasnip user + { name = 'buffer' }, -- For buffer word completion + { name = 'path' }, -- For path completion + { name = 'rpncalc' }, -- for RPN calculations + { name = 'orgmode' }, -- for nvim-orgmode + }) }) diff --git a/lua/plugins.lua b/lua/plugins.lua index d0b7248..9c621b6 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -234,7 +234,7 @@ require("lazy").setup({ "PhilRunninger/cmp-rpncalc", }, - -- comfortable table editing + -- comfortable table editing, esp. used in orgmode { 'dhruvasagar/vim-table-mode' }, -- TODO, WARN, HACK, PERF, NOTE, TEST and others highlighting and searching