diff --git a/README.md b/README.md index 9d1ce1d..27ced16 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,7 @@ vim.api.nvim_set_keymap('n', '', | `spell_suggest` | spelling suggestions | | `tags` | project tags | | `tags_grep` | grep project tags | +| `tags_live_grep` | live grep project tags | | `btags` | buffer tags | | `filetypes` | neovim filetypes | | `packadd` | :packadd | @@ -620,6 +621,9 @@ require'fzf-lua'.setup { file_icons = true, git_icons = true, color_icons = true, + -- 'tags_live_grep' options, `rg` prioritizes over `grep` + rg_opts = "--no-heading --color=always --smart-case", + grep_opts = "--color=auto --perl-regexp", -- actions inherit from 'actions.files' }, btags = { diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 1fd1f39..034d04c 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -233,6 +233,7 @@ MISC *fzf-lua-misc* | `spell_suggest` | spelling suggestions | | `tags` | project tags | | `tags_grep` | grep project tags | +| `tags_live_grep` | live grep project tags | | `btags` | buffer tags | | `filetypes` | neovim filetypes | | `packadd` | :packadd | @@ -662,6 +663,9 @@ Consult the list below for available settings: file_icons = true, git_icons = true, color_icons = true, + -- 'tags_live_grep' options, `rg` prioritizes over `grep` + rg_opts = "--no-heading --color=always --smart-case", + grep_opts = "--color=auto --perl-regexp", -- actions inherit from 'actions.files' }, btags = { diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 2dd9498..32f5910 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -377,6 +377,8 @@ M.globals.tags = { previewer = { _ctor = previewers.builtin.tags }, prompt = 'Tags> ', ctags_file = "tags", + rg_opts = "--no-heading --color=always --smart-case", + grep_opts = "--color=auto --perl-regexp", multiprocess = true, file_icons = true and M._has_devicons, git_icons = true, diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index 1fd6ae9..6e10b55 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -112,6 +112,7 @@ 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_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 5a59cb1..b1688cf 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -193,7 +193,11 @@ end -- multi threaded (multi-process actually) version M.live_grep_mt = function(opts) - opts = config.normalize_opts(opts, config.globals.grep) + -- 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 + if not opts then return end local no_esc = false diff --git a/lua/fzf-lua/providers/tags.lua b/lua/fzf-lua/providers/tags.lua index f92c773..49e03cf 100644 --- a/lua/fzf-lua/providers/tags.lua +++ b/lua/fzf-lua/providers/tags.lua @@ -167,7 +167,7 @@ end local function get_tags_cmd(opts) local query = nil local cmd = "grep" - if vim.fn.executable("rg") == 2 then + if vim.fn.executable("rg") == 1 then cmd = "rg" end if opts.search and #opts.search>0 then @@ -200,13 +200,20 @@ local function tags(opts) return end - opts._curr_file = opts._curr_file and - path.relative(opts._curr_file, opts.cwd or vim.loop.cwd()) - opts.cmd = opts.cmd or get_tags_cmd(opts) opts._fn_transform = make_entry.tag -- multiprocess=false opts._fn_transform_str = [[return require("make_entry").tag]] -- multiprocess=true -- prevents 'file|git_icons=false' from overriding processing opts.requires_processing = true + + if opts.lgrep then + opts.prompt = '*' .. opts.prompt + opts.filename = opts._ctags_file + return require'fzf-lua.providers.grep'.live_grep_mt(opts) + end + + opts._curr_file = opts._curr_file and + 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_fzf_field_index(opts) @@ -240,4 +247,12 @@ M.tags_grep = function(opts) return M.tags(opts) end +M.tags_live_grep = function(opts) + opts = config.normalize_opts(opts, config.globals.tags) + if not opts then return end + opts.lgrep = true + opts.__FNCREF__ = utils.__FNCREF__() + return tags(opts) +end + return M