diff --git a/README.md b/README.md index 210aa7a..68f019a 100644 --- a/README.md +++ b/README.md @@ -612,6 +612,29 @@ require'fzf-lua'.setup { }, -- actions inherit from 'actions.buffers' }, + tags = { + prompt = 'Tags❯ ', + ctags_file = "tags", + multiprocess = true, + file_icons = true, + git_icons = true, + color_icons = true, + -- actions inherit from 'actions.files' + }, + btags = { + prompt = 'BTags❯ ', + ctags_file = "tags", + multiprocess = true, + file_icons = true, + git_icons = true, + color_icons = true, + fzf_opts = { + ['--delimiter'] = "'[\\]:]'", + ["--with-nth"] = '2..', + ["--tiebreak"] = 'index', + }, + -- actions inherit from 'actions.files' + }, colorschemes = { prompt = 'Colorschemes❯ ', live_preview = true, -- apply the colorscheme on preview? diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 357d175..7be6fa7 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -654,6 +654,29 @@ Consult the list below for available settings: }, -- actions inherit from 'actions.buffers' }, + tags = { + prompt = 'Tags❯ ', + ctags_file = "tags", + multiprocess = true, + file_icons = true, + git_icons = true, + color_icons = true, + -- actions inherit from 'actions.files' + }, + btags = { + prompt = 'BTags❯ ', + ctags_file = "tags", + multiprocess = true, + file_icons = true, + git_icons = true, + color_icons = true, + fzf_opts = { + ['--delimiter'] = "'[\\]:]'", + ["--with-nth"] = '2..', + ["--tiebreak"] = 'index', + }, + -- actions inherit from 'actions.files' + }, colorschemes = { prompt = 'Colorschemes❯ ', live_preview = true, -- apply the colorscheme on preview? diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index cdd937c..2dd9498 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -377,6 +377,7 @@ M.globals.tags = { previewer = { _ctor = previewers.builtin.tags }, prompt = 'Tags> ', ctags_file = "tags", + multiprocess = true, file_icons = true and M._has_devicons, git_icons = true, color_icons = true, @@ -386,9 +387,15 @@ M.globals.btags = { previewer = { _ctor = previewers.builtin.tags }, prompt = 'BTags> ', ctags_file = "tags", + multiprocess = true, file_icons = true and M._has_devicons, git_icons = true, color_icons = true, + fzf_opts = { + ['--delimiter'] = "'[\\]:]'", + ["--with-nth"] = '2..', + ["--tiebreak"] = 'index', + }, _actions = function() return M.globals.actions.files end, } M.globals.colorschemes = { diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index 7e25100..64e9b84 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -356,12 +356,13 @@ M.mt_cmd_wrapper = function(opts) end if not opts.force_multiprocess and + not opts.requires_processing and not opts.git_icons and not opts.file_icons then -- command does not require any processing return opts.cmd elseif opts.multiprocess or opts.force_multiprocess then - local fn_preprocess = [[return require("make_entry").preprocess]] - local fn_transform = [[return require("make_entry").file]] + local fn_preprocess = opts._fn_preprocess_str or [[return require("make_entry").preprocess]] + local fn_transform = opts._fn_transform_str or [[return require("make_entry").file]] -- replace all below 'fn.shellescape' with our version -- replacing the surrounding single quotes with double -- as this was causing resume to fail with fish shell @@ -390,11 +391,15 @@ M.mt_cmd_wrapper = function(opts) else return libuv.spawn_nvim_fzf_cmd(opts, function(x) - return make_entry.file(opts, x) + return opts._fn_transform + and opts._fn_transform(opts, x) + or make_entry.file(opts, x) end, function(o) -- setup opts.cwd and git diff files - return make_entry.preprocess(o) + return opts._fn_preprocess + and opts._fn_preprocess(o) + or make_entry.preprocess(o) end) end end diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index eaa32ac..227968b 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -111,6 +111,8 @@ 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_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 M.changes = require'fzf-lua.providers.nvim'.changes M.tagstack = require'fzf-lua.providers.nvim'.tagstack diff --git a/lua/fzf-lua/make_entry.lua b/lua/fzf-lua/make_entry.lua index c10e86d..c65321f 100644 --- a/lua/fzf-lua/make_entry.lua +++ b/lua/fzf-lua/make_entry.lua @@ -318,4 +318,15 @@ M.file = function(opts, x) return table.concat(ret) end +M.tag = function(opts, x) + local line = nil + local name, file, text = x:match("^(.*)\t(.*)\t(/.*/)") + if not file then return x end + return ("%s%s: %s %s"):format( + M.file(opts, file), + not line and "" or ":"..utils.ansi_codes.green(tostring(line)), + utils.ansi_codes.magenta(name), + utils.ansi_codes.green(text)) +end + return M diff --git a/lua/fzf-lua/providers/tags.lua b/lua/fzf-lua/providers/tags.lua index 60e8be9..168b87d 100644 --- a/lua/fzf-lua/providers/tags.lua +++ b/lua/fzf-lua/providers/tags.lua @@ -2,6 +2,7 @@ local core = require "fzf-lua.core" local path = require "fzf-lua.path" local utils = require "fzf-lua.utils" local config = require "fzf-lua.config" +local make_entry = require "fzf-lua.make_entry" local M = {} @@ -148,13 +149,13 @@ local fzf_tags = function(opts) return core.fzf_files(opts, contents) end -M.tags = function(opts) +M.tags_old = function(opts) opts = config.normalize_opts(opts, config.globals.tags) if not opts then return end return fzf_tags(opts) end -M.btags = function(opts) +M.btags_old = function(opts) opts = config.normalize_opts(opts, config.globals.btags) if not opts then return end opts.fzf_opts = vim.tbl_extend("keep", @@ -163,4 +164,52 @@ M.btags = function(opts) return fzf_tags(opts) end +local function get_tags_cmd(opts) + local post = opts._curr_file and #opts._curr_file>0 + and ("%s %s"):format(vim.fn.shellescape(opts._curr_file), opts._ctags_file) + or ("-v '^!_TAG_' %s"):format(opts._ctags_file) + if vim.fn.executable("rg") == 1 then + return ("rg %s"):format(post) + else + return ("grep %s"):format(post) + end +end + +local function tags(opts) + opts.ctags_file = opts.ctags_file and vim.fn.expand(opts.ctags_file) or "tags" + + if not vim.loop.fs_open(opts.ctags_file, "r", 438) then + utils.info("Tags file does not exists. Create one with ctags -R") + return + end + + opts._ctags_file = opts.cwd and path.join({opts.cwd, opts.ctags_file}) or opts.ctags_file + 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 + local contents = core.mt_cmd_wrapper(opts) + opts = core.set_header(opts, 2) + return core.fzf_files(opts, contents) +end + +M.tags = function(opts) + opts = config.normalize_opts(opts, config.globals.tags) + if not opts then return end + return tags(opts) +end + +M.btags = function(opts) + opts = config.normalize_opts(opts, config.globals.btags) + if not opts then return end + opts._curr_file = vim.api.nvim_buf_get_name(0) + if not opts._curr_file or #opts._curr_file==0 then + utils.info("'btags' is not available for unnamed buffers.") + return + end + return tags(opts) +end + return M