From eaa7011f8499f2c8c473a5beb50100f1cae006cf Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Mon, 16 Nov 2020 21:17:13 +0100 Subject: feat: Add tags (#219) --- lua/telescope/previewers.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lua/telescope/previewers.lua') diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua index d85d149..29442fa 100644 --- a/lua/telescope/previewers.lua +++ b/lua/telescope/previewers.lua @@ -400,6 +400,46 @@ previewers.vimgrep = defaulter(function(opts) } end, {}) +previewers.ctags = defaulter(function(opts) + return previewers.new { + setup = function() + return {} + end, + + teardown = function(self) + if self.state and self.state.hl_id then + pcall(vim.fn.matchdelete, self.state.hl_id, self.state.hl_win) + self.state.hl_id = nil + end + end, + + preview_fn = function(self, entry, status) + with_preview_window(status, nil, function() + local scode = string.gsub(entry.scode, '[$]$', '') + scode = string.gsub(scode, [[\\]], [[\]]) + scode = string.gsub(scode, [[\/]], [[/]]) + scode = string.gsub(scode, '[*]', [[\*]]) + + local new_bufnr = vim.fn.bufnr(entry.filename, true) + vim.fn.bufload(new_bufnr) + + vim.api.nvim_win_set_buf(status.preview_win, new_bufnr) + vim.api.nvim_win_set_option(status.preview_win, 'wrap', false) + vim.api.nvim_win_set_option(status.preview_win, 'winhl', 'Normal:Normal') + vim.api.nvim_win_set_option(status.preview_win, 'signcolumn', 'no') + vim.api.nvim_win_set_option(status.preview_win, 'foldlevel', 100) + + pcall(vim.fn.matchdelete, self.state.hl_id, self.state.hl_win) + vim.fn.search(scode) + vim.cmd "norm zz" + + self.state.hl_win = status.preview_win + self.state.hl_id = vim.fn.matchadd('Search', scode) + end) + end + } +end, {}) + previewers.qflist = defaulter(function(opts) opts = opts or {} -- cgit v1.2.3