From dcebd33a88b8570f7645787ac854523d3a573457 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Sun, 6 Mar 2022 00:50:42 -0800 Subject: [PATCH] tags: added grep_cword|CWORD|visual --- README.md | 3 +++ doc/fzf-lua.txt | 3 +++ lua/fzf-lua/init.lua | 7 +++++-- lua/fzf-lua/providers/grep.lua | 5 +---- lua/fzf-lua/providers/tags.lua | 24 +++++++++++++++++++++--- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c20e8c9..eda9121 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,9 @@ vim.api.nvim_set_keymap('n', '', | `spell_suggest` | spelling suggestions | | `tags` | project tags | | `tags_grep` | grep project tags | +| `tags_grep_cword` | tag search word under cursor | +| `tags_grep_cWORD` | tag search WORD under cursor | +| `tags_grep_visual` | tag search visual selection | | `tags_live_grep` | live grep project tags | | `btags` | buffer tags | | `filetypes` | neovim filetypes | diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index d40d7da..e0a600b 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -233,6 +233,9 @@ MISC *fzf-lua-misc* | `spell_suggest` | spelling suggestions | | `tags` | project tags | | `tags_grep` | grep project tags | +| `tags_grep_cword` | tag search word under cursor | +| `tags_grep_cWORD` | tag search WORD under cursor | +| `tags_grep_visual` | tag search visual selection | | `tags_live_grep` | live grep project tags | | `btags` | buffer tags | | `filetypes` | neovim filetypes | diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index 6e10b55..c20c0a7 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -111,8 +111,11 @@ M.colorschemes = require'fzf-lua.providers.colorschemes'.colorschemes M.tags = require'fzf-lua.providers.tags'.tags M.btags = require'fzf-lua.providers.tags'.btags -M.tags_grep = require'fzf-lua.providers.tags'.tags_grep -M.tags_live_grep = require'fzf-lua.providers.tags'.tags_live_grep +M.tags_grep = require'fzf-lua.providers.tags'.grep +M.tags_grep_cword = require'fzf-lua.providers.tags'.grep_cword +M.tags_grep_CWORD = require'fzf-lua.providers.tags'.grep_cWORD +M.tags_grep_visual = require'fzf-lua.providers.tags'.grep_visual +M.tags_live_grep = require'fzf-lua.providers.tags'.live_grep M.tags_old = require'fzf-lua.providers.tags'.tags_old M.btags_old = require'fzf-lua.providers.tags'.btags_old M.jumps = require'fzf-lua.providers.nvim'.jumps diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index a73a553..0db3fa6 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -194,10 +194,7 @@ end -- multi threaded (multi-process actually) version M.live_grep_mt = function(opts) - -- do not normalize when called from 'tags_live_grep' - if not opts or not opts._normalized then - opts = config.normalize_opts(opts, config.globals.grep) - end + opts = config.normalize_opts(opts, config.globals.grep) if not opts then return end diff --git a/lua/fzf-lua/providers/tags.lua b/lua/fzf-lua/providers/tags.lua index b92d9bb..e30a101 100644 --- a/lua/fzf-lua/providers/tags.lua +++ b/lua/fzf-lua/providers/tags.lua @@ -224,7 +224,7 @@ local function tags(opts) path.relative(opts._curr_file, opts.cwd or vim.loop.cwd()) opts.cmd = opts.cmd or get_tags_cmd(opts) local contents = core.mt_cmd_wrapper(opts) - opts = core.set_header(opts, 2) + opts = core.set_header(opts) opts = core.set_fzf_field_index(opts) return core.fzf_files(opts, contents) end @@ -246,7 +246,7 @@ M.btags = function(opts) return tags(opts) end -M.tags_grep = function(opts) +M.grep = function(opts) opts = opts or {} if not opts.search then @@ -256,7 +256,7 @@ M.tags_grep = function(opts) return M.tags(opts) end -M.tags_live_grep = function(opts) +M.live_grep = function(opts) opts = config.normalize_opts(opts, config.globals.tags) if not opts then return end opts.lgrep = true @@ -264,4 +264,22 @@ M.tags_live_grep = function(opts) return tags(opts) end +M.grep_cword = function(opts) + if not opts then opts = {} end + opts.search = vim.fn.expand("") + return M.grep(opts) +end + +M.grep_cWORD = function(opts) + if not opts then opts = {} end + opts.search = vim.fn.expand("") + return M.grep(opts) +end + +M.grep_visual = function(opts) + if not opts then opts = {} end + opts.search = utils.get_visual_selection() + return M.grep(opts) +end + return M