diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2020-11-16 21:17:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-16 15:17:13 -0500 |
| commit | eaa7011f8499f2c8c473a5beb50100f1cae006cf (patch) | |
| tree | 6b004689f95f0cf93b476428f3543a29a3483559 /lua/telescope/previewers.lua | |
| parent | 81172630270325947d2c6b3afda5599e34b48499 (diff) | |
feat: Add tags (#219)
Diffstat (limited to 'lua/telescope/previewers.lua')
| -rw-r--r-- | lua/telescope/previewers.lua | 40 |
1 files changed, 40 insertions, 0 deletions
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 {} |
